akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	ll k, t;
	cin >> k >> t;
	vector<ll> a(t);
	rep(i, t) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll p = a[t - 1];
	cout << max(p - 1 - (k - p), (ll)0) << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
s = 10**19
B = sorted(A,key=lambda x:x[0])
for i in range(N-K+1):
    for j in range(K,N-i+1):
        xmin = B[i][0]
        xmax = B[i+j-1][0]
        By = sorted(B[i:i+j],key=lambda x:x[1])
        for k in range(len(By)-K+1):
            ymin = By[k][1]
            ymax = By[k+K-1][1]
            s = min(s,(xmax-xmin)*(ymax-ymin))
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

int n;
ll a[100010];

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  ll ans=1;
  int flag=0;
  rep(i,n-1){
    if(a[i]==a[i+1]){
      ans*=a[i];
      flag++;
      i++;
    }
    if(flag==2)break;
  }
  if(flag==2)cout<<ans<<endl;
  else cout<<"0"<<endl;
}


Measured memory_bytes: 1024
loop.with_index {|_, i|
    n = gets.to_i
    break if n == 0
    points = (1..n).map{ gets.split.map(&:to_i) }

    area = 0
    (points + [points[0]]).each_cons(2){|u, v|
        x1, y1 = u
        x2, y2 = v
        area += x1 * y2 - x2 * y1
    }
    printf("%d %.1f\n", i + 1, area.abs / 2.0)

    gets
}

Measured memory_bytes: 6168
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int main(){
  ll h, w, n;
  cin >> h >> w >> n;
  ll a[n], b[n];
  map<pi, int> mp;
  REP(i,n){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    REP(j,min(a[i],2ll)+1){
      REP(k,min(b[i],2ll)+1){
        if(a[i]-j >= h-2 || b[i]-k >= w-2)continue;
        mp[pi(a[i]-j, b[i]-k)]++;
      }
    }
  }
  ll ans[10];
  REP(i,10) ans[i] = 0;
  ans[0] = (h-2) * (w-2);
  for(auto &p:mp){
    ans[p.second]++;
    ans[0]--;
    // cout << p.first.first << ", " << p.first.second << endl;
  }

  REP(i,10){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 58112
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long Q,H,S,D,N; cin>>Q>>H>>S>>D>>N;
  cout<<min(min(min(min(min(Q*4*N,H*2*N),S*N),D*(N/2)+S*(N%2)),D*(N/2)+H*(N%2)*2),D*(N/2)+(N%2)*4*Q)<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++) cin >> C[i];

    sort(A.begin(), A.end());
    sort(C.begin(), C.end());

    ll ans = 0;

    for(int i=0; i<N; i++) {
        ll pre = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll over = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += pre * over;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4576
#include<bits/stdc++.h>
/*
*/

using namespace std;

int main() {
	long long int N;
	cin >> N;
	vector<long long int>ans(26, LLONG_MAX / 6);
	for (size_t i = 0; i < N; i++)
	{
		string S;
		cin >> S;
		vector<long long int>count(26);
		for (size_t j = 0; j < S.length(); j++)
		{
			count[S[j] - 'a']++;
		}
		for (size_t j = 0; j < 26; j++)
		{
			ans[j] = min(ans[j], count[j]);
		}
	}
	for (size_t i = 0; i < 26; i++)
	{
		for (size_t j = 0; j < ans[i]; j++)
		{
			cout << (char)('a' + i);
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int N;
int partition(int *A,int p,int r){
    int x = A[r];
    int tmp;
    int i = p -1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
        i++;
        tmp = A[i];A[i] = A[j]; A[j] = tmp;
        }
    }
    i++;
    tmp = A[i];A[i] = A[r];A[r] =tmp;
    return i;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;

    int A[100000];

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int q = partition(A,0,N - 1);
    for (int i = 0; i < N; i++) {
        if (i>0) {
            cout << " ";
        }
        if (i == q) {
            cout << "[";
        }
        cout << A[i];
        if (i == q) {
            cout << "]";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3544
import java.io.*; 
import java.util.*; 
  
class Graph { 
    ArrayList<Integer> adjArr[];
  
    @SuppressWarnings("unchecked")
	Graph(int v) {
        adjArr = new ArrayList[v]; 
        for (int i=0; i < v; ++i) 
            adjArr[i] = new ArrayList<Integer>(); 
    } 
  
    // Add directed pair to graph
    void addToGraph(int id, int neighbor) { 
    	adjArr[id].add(neighbor); 
    	}
    
    // Topologically sorts adjacency list graph into a stack
    void topsort(int v, boolean visited[], Stack<Integer> stack) {  
        // Mark current as visited
    	visited[v] = true; 
        int i; 

        Iterator<Integer> it = adjArr[v].iterator(); 
        while (it.hasNext()) { 
            i = it.next(); 
            // Topsort through all unvisited adjacent vertices before adding to stack
            if (!visited[i]) 
                topsort(i, visited, stack); 
        } 
        stack.push(v); 
    }
}

public class Main {
  
    public static void main(String args[]) 
    { 
    	Scanner in = new  Scanner(System.in);

		int totalVertex = in.nextInt();
		Graph adj = new Graph(totalVertex);
		
		int totalConnections = in.nextInt();
		
		int id, neighbor;
		
		for (int i = 0; i < totalConnections; i++) {
			id = in.nextInt();
			neighbor = in.nextInt();
			adj.addToGraph(id, neighbor);
		}
		
		Stack<Integer> stack = new Stack<Integer>();
		
		boolean[] visited = new boolean[totalVertex];
		// Initialize visited array with false
		for(int i = 0; i < totalVertex; i++){
			visited[i] = false;
		}
		
		for(int i = 0; i < totalVertex; i++) {
			if(!visited[i]) {
				adj.topsort(i, visited, stack);
			}
		}
		
		while(!stack.isEmpty()) {
			System.out.println(stack.pop());
		}
    }
}


Measured memory_bytes: 69452
import java.util.Scanner;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		int plus = D - A;
		int zero = plus - B;

		int sum = 0;

		if (plus > 0) {
			sum += A;
			if (zero > 0) {
				sum -= zero;
				System.out.print(sum);
			} else {
				System.out.print(sum);
			}
		} else {
			sum += D;
			System.out.print(sum);
		}

		return;

	}
}


Measured memory_bytes: 27004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String[] args){
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    String str;
    int i=0;
        try {
            str = br.readLine();
            br.close();
		    i=Integer.parseInt(str);
        } catch (IOException e) {
            e.printStackTrace();
        }    
    System.out.println(i+i*i+i*i*i);
  }
}

Measured memory_bytes: 32028
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod=998244353;
int n;
ll pw[210],ans=0;
struct node{int x,y;
}p[210];
bool check(node a,node b,node c)
{ return (b.x-a.x)*(c.y-a.y)==(b.y-a.y)*(c.x-a.x);}
void link(int x,int y){x+=y;}
int main()
{
    link(0,1);
    scanf("%d",&n);
    pw[0]=1;
    for (int i=1;i<=n;i++) pw[i]=(pw[i-1]<<1)%mod;    
    for (int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
    
    ans=(pw[n]-n-1+mod)%mod;bool _is;int cnt;
    for (int i=1;i<n;i++) 
        for (int j=i+1;j<=n;j++)
        {
            _is=1;
            for (int k=1;k<i;k++) if (check(p[k],p[i],p[j])) {_is=0;break;}
            for (int k=i+1;k<j;k++) if (check(p[k],p[i],p[j])) {_is=0;break;}
            if (!_is) continue;
            cnt=2;
            for (int k=j+1;k<=n;k++) if (check(p[k],p[i],p[j])) cnt++;
            ans=(ans-pw[cnt]+cnt+1+mod)%mod;
        }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  string S,Ans="Yes";
  cin>>N>>S;
  
  if(N%2==1){Ans="No";}
  else{rep(i,N/2){if(S.at(i)!=S.at(i+N/2)){Ans="No";break;}}}
  
  cout<<Ans<<endl;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    map<int, int> m;
    int n;
    cin >> n;

    fo(i, n) {
        int a;
        cin >> a;
        m[a]++;
        m[a - 1]++;
        m[a + 1]++;
    }

    int maior = 0;
    for ( auto it : m ) {
        maior = max(it.ss, maior);
    }
    cout << maior << endl;

    return 0;
}

Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, s;
  cin >> n;
  vector<int> v;
  v.push_back(0);
  int sm = 0;
  REP(i,n){
    cin >> s;
    v.push_back(s);
    sm += s;
  }
  SORT(v);
  REP(i,n+1){
    if ((sm-v[i])%10!=0){
      cout << sm - v[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> a(n);
    map<ll, ll> mp;
    mp[0] = 1;
    ll cur = 0, ans = 0;
    rep(i,n){
        cin >> a[i];
        cur = (cur + a[i]) % m;
        ans += mp[cur]++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

int main() {
    cin>>S;
    rep(i,3) cout<<S[i];
    cout<<endl;
}

Measured memory_bytes: 3588
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	static int w;
	static int h;
	static int dx[]={-1,0,1,0};
	static int dy[]={0,-1,0,1};
	static char map[][];
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		int n = sc.nextInt();
		
		int ch[][] = new int[n+1][2];
		
		map =new char[h][];
		for(int i = 0;i<h;i++){
			map[i] = sc.next().toCharArray();
			for(int j=0;j<w;j++){
				if(map[i][j]=='S'){
					ch[0][0]=j;
					ch[0][1]=i;
				}
				if('1'<=map[i][j] && map[i][j]<='9'){
					ch[map[i][j]-'0'][0] = j;
					ch[map[i][j]-'0'][1] = i;
				}
			}
		}
		int total = 0;
		for(int i=0;i<n;i++){
			total+=search(ch[i][0],ch[i][1],ch[i+1][0],ch[i+1][1]);
		}
		System.out.println(total);
	}
	
	static int search(int x,int y,int tox,int toy){
		boolean visited[][] = new boolean[h][w];
		Deque<int[]> q = new ArrayDeque<>();
		q.offer(new int[]{x,y,0});
		while(!q.isEmpty()){
			int now[]=q.poll();
			if(now[0]==tox && now[1]==toy)return now[2];
			for (int i = 0; i < 4; i++) {
                int nx = now[0] + dx[i];
                int ny = now[1] + dy[i];
                if ((0 <= ny && ny < h) && (0 <= nx && nx < w) && !visited[ny][nx] && map[ny][nx] != 'X') {
                    visited[ny][nx] = true;
                    q.offer(new int[] { nx, ny, now[2] + 1 });
                }
			}
		}
		return 0;
	}
}

Measured memory_bytes: 68012
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  // a,bを宣言
  	cin >> a >> b;
  	// 入力結果をa,bに代入
  	cout << a + b - (a + b)/2 << endl;
  	// 平均値を出力
}

Measured memory_bytes: 256
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
A = np.array([lr() for _ in range(H)])
B = np.array([lr() for _ in range(H)])
diff = np.abs(A - B).tolist()

X = (H+W) * 80
L = X + X + 1 #真ん中を0とする、最後に-X
dp = [[None] * W for _ in range(H)]
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X+diff[0][0]] = 1; dp[0][0][X-diff[0][0]] = 1 #非負整数のみでも良い
for h in range(H):
    for w in range(W):
        if h == 0 and w == 0:
            continue
        di = diff[h][w]
        x = np.zeros(L, np.bool)
        if h > 0:
            x[di:] |= dp[h-1][w][:L-di]
            x[:L-di] |= dp[h-1][w][di:]
        if w > 0:
            x[di:] |= dp[h][w-1][:L-di]
            x[:L-di] |= dp[h][w-1][di:]
        dp[h][w] = x

dp = dp[-1][-1][X:]
possible = np.where(dp==1)[0]
answer = possible.min()
print(answer)
#


Measured memory_bytes: 173488
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
#include <atcoder/all>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using namespace atcoder;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;
using mint = modint998244353;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 2e5+1;
int n, m, k;
vector<mint> mod1(maxn);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

struct S {
    mint a;
    int s, t;
};
struct F {
    mint a, b;
};
vector<S> a;
S op (S l, S r) {
    if (l.a == -1) return r;
    if (r.a == -1) return l;
    return S{l.a+r.a, l.s, r.t};
}
S e () {
    return S{-1, 0, 0};
}
// segTree の親に書き込む値を決める(加算のときは自分の子の数だけ定数加算をしないといけない)
S mapping (F l, S r) {
    return S{l.a*(mod1[r.s]-mod1[r.t+1]) + l.b*r.a, r.s, r.t};
}
// 複数回連続で書き込むときに使う
F composition (F f, F g) {
    if (f.b == 1) return g;
    return f;
}
F id () {
    return F{0, 1};
}

signed main () {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    cin >> n >> k;
    mod1[n-1] = 1;
    for(int i = n-2; i >= 0; i--) {
        mod1[i] = mod1[i+1]*10;
    }
    for(int i = n-2; i >= 0; i--) {
        mod1[i] += mod1[i+1];
    }
    
    vector<S> a(n);
    REP(i, n) {
        a[i] = S{1, i, i};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);

    seg.apply(0, n, F{1, 0});
    REP(i, k) {
        int l, r, d; cin >> l >> r >> d;
        seg.apply(l-1, r, F{d, 0});
        print1(seg.all_prod().a.val());
    }
    
}

Measured memory_bytes: 23076
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N+1);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> S(N+1);
  S[0] = 0;
  for (ll i = 0; i < N; i++) {
    S[i+1] = (S[i] + A[i]) % M;
  }
  // 自分より左に同じ余りのやつが何個あるか
  map<ll, ll> m;
  ll ans = 0;
  for (ll i = 0; i < S.size(); i++) {
    ans += m[S[i]];
    m[S[i]]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void Main() {
  double a, b, x; cin >> a >> b >> x;
  double res;
  if(x >= a * a * b / 2.0) res = atan(2.0 * (a * a * b - x) / (a * a * a));
  else res = atan(a * b * b / (2.0 * x));
  cout << res * 180.0 / 3.141592 << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int sum =0;
	int tmp = n;
	while (tmp>0)
		{
			sum+=tmp%10;
			tmp/=10;
		}
		if (n % sum == 0)
		{
			printf("Yes");
		}
		else {
			printf("No");
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll lcm(ll a, ll b) {
	return a*b/gcd(a,b);
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return -1LL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	string s; cin>>s;
	int q; cin>>q;
	int t,total=0,f;
	string c;

	for(int i=0; i<q; i++) {
		cin>>t;
		if(t==1) {
			total++;
		}
		else {
			cin>>f>>c;
			if(f==2) {
				if(total%2) s.insert(0,c);
				else        s.append(c);
			}
			else {
				if(total%2) s.append(c);
				else        s.insert(0,c);
			}
		}
	}
	if(total%2) reverse(s.begin(),s.end());

	cout<<s<<endl;
}


Measured memory_bytes: 900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class MainClass
    {
        static void Main()
        {
            var xn = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = xn[0], n = xn[1];
            if (n == 0)
            {
                Console.WriteLine(x);return;
            }
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var nums = Enumerable.Range(0, 102).ToList();
            for (int i = 0; i < n; i++)
            {
                nums.Remove(p[i]);
            }

            nums.Sort((_x, _y) => Math.Abs(_x - x).CompareTo(Math.Abs(_y - x)));
            Console.WriteLine(nums[0]);
        }
    }
}


Measured memory_bytes: 28340
#include <cstdio>
#include <iostream>
#define MAXN 3050
using namespace std;
string s, t;
int a[MAXN][MAXN];
int press[MAXN][30];
pair<int, int> from[MAXN][MAXN];
int main(){
    cin >> s >> t;
    for (int i = 1; i <= s.size(); i++){
        for (int j = 1; j <= 26; j++){
            if (press[i-1][j] != 0) press[i][j] = press[i-1][j] + 1;
        }
        press[i][ s[s.size()-i] - 'a'+1] = 1;
    }
    if (s[s.size() - 1] == t[t.size()-1]){
       a[s.size()][t.size()] = 1;
       from[s.size()][t.size()] = {s.size() + 1, t.size() + 1};
    }
    for (int i = s.size(); i > 0; i--){
        for (int j = t.size(); j > 0; j--){
            if (i*j == s.size() * t.size()) continue;
            if (press[s.size()-i+1][t[j-1] - 'a' + 1] != 0){
               //a[i][j] = max(a[i][j+1], 1 + a[i + press[s.size()-i+1][t[j-1] - 'a' + 1]][j+1]);
               if (a[i][j+1] >  1 + a[i + press[s.size()-i+1][t[j-1] - 'a' + 1]][j+1]){
                  a[i][j] = a[i][j+1];
                  from[i][j] = {i, j + 1};
               }else{
                  a[i][j] = 1 + a[i + press[s.size()-i+1][t[j-1] - 'a' + 1]][j+1];
                  from[i][j] = {i + press[s.size()-i+1][t[j-1] - 'a' + 1], j+1};
               }
            }else{
               a[i][j] = a[i][j+1];
               from[i][j] = {i, j + 1};
            }
        }
    }
    //cout << a[1][1] << endl;

    int x, y;
    x = 1;
    y = 1;
    while (x <= s.size() || y <= t.size() ){
          //cout << x << ' ' << y << endl;
          if (x + y == 0) return 0;
          if ( !(from[x][y].first == x && from[x][y].second == y+1) && from[x][y].first != 0 && from[x][y].second != 0){
             cout << t[y-1];
          }
          int nx = from[x][y].first;
          int ny = from[x][y].second;
          x = nx;
          y = ny;
    }
    return 0;
}

Measured memory_bytes: 109056
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T &b) {
    if(a >= b) {
        return false;
    }
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T &b) {
    if(a <= b) {
        return false;
    }
    a = b;
    return true;
}

/*-------------------------------------------*/

vector<ll> fact, fact_inv;

template <typename T> T mpow(T x, T n) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n = n >> 1;
    }
    return ret;
}

void COMinit(ll MAX) {
    fact.resize(MAX + 1);
    fact_inv.resize(MAX + 1);
    fact[0] = fact_inv[0] = 1;
    rep(i, MAX) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        fact_inv[i + 1] = mpow(fact[i + 1], mod - 2ll);
    }
}

ll COM(ll n, ll k) {
    if(n < k || k < 0) return 0;
    return (fact[n] * fact_inv[k] % mod) * fact_inv[n - k] % mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    COMinit(n + 3);
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll A = 0, b = 0;
    rep(i, n) {
        (A += (mod + a[i]) * COM(n - i - 1, k - 1)) %= mod;
        (b += (mod + a[n - i - 1]) * COM(n - i - 1, k - 1)) %= mod;
    }
    cout << (b + mod - A) % mod << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
using namespace std;

int main(){
    int count[4][3][10]={};
    int n,b,f,r,v;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        count[b-1][f-1][r-1]+=v;
    }
    for(int c=0;c<4;c++){
        for(int a=0;a<3;a++){
            for(int b=0;b<10;b++){
                if(0<=count[c][a][b]&&count[c][a][b]<=9){
                    printf(" %d",count[c][a][b]);
                }else{
                    printf(" 0");
                }
            }printf("\n");
        }
        if(c!=3){
        for(int i=0;i<20;i++){
            printf("#");
        }printf("\n");
        }
    }
}



Measured memory_bytes: 2700
N = int(input())
P = list(map(float, input().split()))

dp = [[1] + [0]*N for i in range(N+1)]
for i in range(1, N+1):
  for j in range(1, i+1):
    dp[i][j] = dp[i-1][j-1]*(P[i-1]) + dp[i-1][j]*(1-P[i-1])

print(dp[-1][(N+1)//2])

Measured memory_bytes: 264328
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
struct S
{
    //double a;
    int x,y;
};
vector<S> v[1010];

int a,b,c,i,k,d,n,m,e,dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};
int l[13011];
int o[211111];
//int dx[10]={1,0,1,-1,-1,0},dy[10]={0,1,1,1,-1,-1};

long long x,y,z[1554];
P u[1020222];
int j[5][112111];
priority_queue<long long, vector<long long>,greater<long long> > q,q1;
stack<int> s,s1;


//deque<int> de;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int, int > p;
string r,r1;
//char r[10010];

bool as(P a,P b)
{

    return a.y>b.y;
}

int f(int n,int m)
{
    if(n<m) swap(n,m);
    for(;m;)
    {
        int h=m;
        m=n%m;
        n=h;
    }
    return n;
}

int main()
{
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&d);
        o[d]++;
        if(o[d]==1) i++;
    }

        for(int t=1;t<=200000;t++)
           if(o[t]) q.push(o[t]);
        for(;q.size()>b;q.pop())
            x+=q.top();
        printf("%lld",x);
        return 0;

}


Measured memory_bytes: 5240
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"strings"
)

const BufSize = 200100
var read = bufio.NewReaderSize(os.Stdin, BufSize)

func readLine() string {
	var buf []byte
	l,_,_ := read.ReadLine()
	buf = append(buf,l...)
	return string(buf)
}

func readInt(r ...*int64) {
	l := strings.Fields(readLine())
	for i,v := range l {
		*r[i],_ = strconv.ParseInt(v,10,64)
	}
	return
}
func readIntArray() []int64 {
	l := strings.Fields(readLine())
	ret := make([]int64,len(l))
	for i,v := range l {
		ret[i],_ = strconv.ParseInt(v,10,64)
	}
	return ret
}
func main() {
	var n int64
	readInt(&n)
	a := readIntArray()
	b := readIntArray()
	c := readIntArray()
	prev := int64(-1)
	ans := int64(0)
	for _,v := range a {
		ans += b[v-1]
		if prev == v-1 {
			ans += c[prev-1]
		}
		prev = v
	}
	fmt.Printf("%d\n",ans)
}

Measured memory_bytes: 640
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	long long N, ans = 0, tmp = 0, i, a;
	cin >> N;
	for (i = 0; i<N; ++i){
		cin >> a;
		tmp += a;
		if (a == 0 || i == N - 1){
			ans += tmp / 2;
			tmp = 0;
		}
	}
	cout << ans << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char s[10];
  if(scanf("%s",s)==1){}
  if(s[5]=='1'){
    printf("TBD");
  }else{
    switch(s[6]){
      case '1':
        printf("Heisei");break;
      case '2':
        printf("Heisei");break;
      case '3':
        printf("Heisei");break;
      case '4':
        printf("Heisei");break;  
      default:
        printf("TBD");
    }
  }
  return 0;
}

Measured memory_bytes: 128
def resolve():
    n, m = map(int, input().split())
    adj = [[] for i in range(n+1)]
    for i in range(m):
        A, B = map(int, input().split())
        adj[A].append(B)
        adj[B].append(A)
    from collections import deque
    q = deque([1])
    ans = [-1 for i in range(n+1)]
    while q:
        v = q.popleft()
        for u in adj[v]:
            if ans[u] == -1:
                ans[u] = v
                q.append(u)
    print("Yes")
    for i in range(2, n+1):
        print(ans[i])

resolve()


Measured memory_bytes: 33952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int n;
vector<int> a(400);
vector<vector<int>> dp(400,vector<int>(400,-1));

int dfs(int l,int r){
	if(dp[l][r]!=-1) return dp[l][r];
	if(r-l==1){
		dp[l][r]=1;
		return dp[l][r];
	}
	if(r-l==2){
		if(abs(a[l]-a[l+1])<=1) dp[l][r]=0;
		else dp[l][r]=2;
		return dp[l][r];
	}
	int ret=INF;
	FOR(k,l+1,r){
		chmin(ret,dfs(l,k)+dfs(k,r));
	}
	if(dp[l+1][r-1]==0){
		if(abs(a[l]-a[r-1])<=1){
			chmin(ret,0);
		}else{
			chmin(ret,2);
		}
	}
	return dp[l][r]=ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(true){
		cin>>n;
		if(!n) break;
		rep(i,n){
			cin>>a[i];
		}
		rep(i,400)rep(j,400) dp[i][j]=-1;
		cout<<n-dfs(0,n)<<endl;
	}
}


Measured memory_bytes: 3804
#include <iostream>
using namespace std;

int main(void) {
	int N, T;
	cin >> N >> T;
	int minimum = 1001;

	for(int i=1; i<=N; i++) {
		int cost, time;
		cin >> cost >> time;
		if (time <= T)
			minimum = min(minimum, cost);
	}

	if (minimum == 1001) {
		cout << "TLE\n";
	} else {
		cout << minimum << "\n";
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int md=1000000007;
const int mxn=200005;
int n,m,mx,ans,dp[mxn],f[mxn];
char s[mxn];
inline void add(int&x,int y){
	x+=y;
	if(x>=md)x-=md;
}
signed main(){
	int i,j,t;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(i=1;i<=m;++i)if(s[i]!=s[1])break;mx=i-1;
	if(mx==m){
		dp[0]=f[i]=ans=1;
		for(int i=0;i<=n;++i){
			if(i>=2)dp[i]=f[i-2];
			f[i]=(f[i-1]+dp[i])%md;
			if(n-i>1)add(ans,(ll)dp[i]*(n-i)%md);
		}
		printf("%d\n",ans);
		return 0;
	}
	if(n&1)return 0*puts("0");
	if(!(mx&1))++mx;
	for(t=0;i<=m;++i){
		if(s[i]==s[1])++t;
		else{
			if(t&1)mx=min(mx,t);
			t=0;
		}
	}
	n>>=1,mx=mx+1>>1;
	dp[0]=f[0]=1;
	for(i=0;i<=n;++i){
		if(i)dp[i]=(md+f[i-1]-(i-mx-1>=0?f[i-mx-1]:0))%md,f[i]=(f[i-1]+dp[i])%md;
		if(n-i<=mx) add(ans,(ll)(n-i)*dp[i]*2ll%md);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 2048
import sys
input=sys.stdin.readline

def main():
    n=int(input())
    XY=[[] for _ in range(n)]
    for i in range(n):
        a=int(input())
        for _ in range(a):
            x,y=map(int,input().split())
            x-=1
            XY[i].append((x,y))
    ans=0
    for i in range(1<<n):
        tmp=0
        flag=True
        for j in range(n):
            if (i>>j)&1==0:
                continue
            tmp+=1
            for x,y in XY[j]:
                if (i>>x)&1!=y:
                    flag=False
        if flag:
            ans=max(ans,tmp)
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 42476
import scala.io.StdIn.{readInt,readLine}

object Main {
  def cross(x0:Double, y0:Double, x1:Double, y1:Double) = x0*y1-x1*y0
  def inner(x0:Double, y0:Double, x1:Double, y1:Double) = x0*x1+y0*y1
  def norm(x:Double, y:Double) = x*x+y*y

  def dir(x0:Double,y0:Double,x1:Double,y1:Double) =
    if(cross(x0,y0,x1,y1) > (1e-10)) (-1)
    else if(cross(x0,y0,x1,y1) < -(1e-10)) 1
    else if(inner(x0,y0,x1,y1) < -(1e-10)) 1
    else if(norm(x0,y0) < norm(x1,y1)) 0
    else 0

  def intersect(x0:Double,y0:Double,x1:Double,y1:Double,x2:Double,y2:Double,x3:Double,y3:Double) = {
   (dir(x2-x0,y2-y0,x1-x0,y1-y0) * dir(x3-x0,y3-y0,x1-x0,y1-y0) <= 0) &&
    (dir(x1-x2,y1-y2,x3-x2,y3-y2) * dir(x0-x2,y0-y2,x3-x2,y3-y2) <= 0)
  }

  def main(args:Array[String]) = {
    val n = readInt
    for(i<-0 until n) {
      val s = readLine.split(" ").map(_.toDouble)
      if(intersect(s(0),s(1),s(2),s(3),s(4),s(5),s(6),s(7))) println(1)
      else println(0)
    }
  }
}

Measured memory_bytes: 48332
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n;
    cin >> n;
    
    vector<ll> a(n), b(n + 1);
    REP(i, n){
        cin >> a[i];
        b[i + 1] = b[i] + a[i];
    }
    
    ll ans = INF, c1 = 1, c2 = 2;
    for(ll i = 2; i < n - 1; i++){
        while(abs(b[i] - b[c1] - b[c1]) > abs(b[i] - b[c1 + 1] - b[c1 + 1])){
            c1++;
        }
        while(abs(b[n] - b[c2] - (b[c2] - b[i])) > abs(b[n] - b[c2 + 1] - (b[c2 + 1] - b[i]))){
            c2++;
        }
        
        ll t1 = b[c1], t2 = b[i] - b[c1], t3 = b[c2] - b[i], t4 = b[n] - b[c2];
        ans = min(ans, max({t1, t2, t3, t4}) - min({t1, t2, t3, t4}));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define nax 101010
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
int arr[200];
int fix[10];
void func(int x)
{
    int w = x/400;
    fix[w]++;
}
int main(int argc, char const *argv[])
{
 // freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n;
  sd(n);
  int nut = 0;
  for (int i = 0; i < n; ++i)
  {
    sd(arr[i]);
    if(arr[i] < 3200)
      func(arr[i]);
      else
    nut++;
  }
  if(nut == n)
  {
      printf("1 %d\n",n);
      return 0;
  }
  int mi;
  mi =  0;
  for (int i = 0; i < 8; ++i)
  {
    if(fix[i] > 0)
      ++mi;
  }
  cout << mi << ' ';
  for (int i = 0; i < 8; ++i)
  {
     if(fix[i] == 0 && nut > 0)
      {
        ++mi;
        nut--;
      }
  }
  cout << mi+nut << '\n';
  return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);
struct edge{ll to,cost;};

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

const int MAX_V=100010;

ll N,M,S,T;
vector<vector<edge>> G(MAX_V);
vector<ll> d(MAX_V,IINF),cnt(MAX_V,0);

void Dijkstra(int s){
    priority_queue<Pll,vector<Pll>,greater<Pll>> pq;
    d[s]=0;
    cnt[s]=1;
    pq.push(Pll(0,s));
    while(!pq.empty()){
        Pll p=pq.top();
        pq.pop();
        int v=p.second;
        if (d[v]<p.first) continue;
        for (auto e:G[v]){
            if (d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                pq.push(Pll(d[e.to],e.to));
                cnt[e.to]=cnt[v];
            }
            else if (d[e.to]==d[v]+e.cost) cnt[e.to]=(cnt[e.to]+cnt[v])%MOD;
        }
    }
}

int main(){
    cin >> N >> M >> S >> T;
    --S,--T;
    rep(i,M){
        ll u,v,d;
        cin >> u >> v >> d;
        --u,--v;
        G[u].push_back(edge{v,d});
        G[v].push_back(edge{u,d});
    }
    Dijkstra(S);
    vector<ll> ds=d,cnts=cnt;
    ll distance=d[T],all=cnt[T];
    rep(i,N) d[i]=IINF,cnt[i]=0;
    Dijkstra(T);
    vector<ll> dt=d,cntt=cnt;
    ll ans=all*all%MOD;
    rep(i,N){
        if (ds[i]+dt[i]==distance){
            if (ds[i]==dt[i]) ans=(ans-cnts[i]*cntt[i]%MOD*cntt[i]%MOD*cnts[i]%MOD+MOD)%MOD;
            else {
                for (auto e:G[i]){
                    ll t=e.to;
                    if (ds[t]+dt[t]!=distance||ds[i]+e.cost!=ds[t]) continue;
                    if (ds[i]*2<distance&&dt[t]*2<distance){
                        ans=(ans-cnts[i]*cntt[t]%MOD*cntt[t]%MOD*cnts[i]%MOD+MOD)%MOD;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 18772
#include <iostream>
#include <vector>
using namespace std;

void how_many_two(int &a , int &count){
  while (a % 2 == 0) {
    a /= 2;
    count ++;
  }
}

int main(){
  int n , a , count;
  cin >> n;
  for (int i = 0 ; i < n ; i ++) {
    cin >> a;
    how_many_two(a , count);
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
s=input()
count=0
for i in range(n-1):
    k=s[i:i+1]
    l=s[i+1:i+2]
    if k==l:
        count+=1
ans=n-count
print(ans)

Measured memory_bytes: 3188
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    string INF = "|";
    string[] input;
    while(true) {
        input = readln.split;
        if (input == ["0", "0", "0", "0"]) break;

        int n = input[0].to!int;
        int a = input[1].to!int;
        int s = input[2].to!int;
        int g = input[3].to!int;

        string[] vertices = new string[n];
        vertices[] = INF;
        Edge[] edges = new Edge[a];
        foreach(int i; 0..a) {
            input = readln.split;
            int from = input[1].to!int;
            int to = input[0].to!int;
            string cost = input[2];
            if (from == to) {
                edges[i] = Edge(from, vertices.length.to!int, cost);
                edges ~= Edge(vertices.length.to!int, to, "");
                vertices ~= INF;
            } else {
                edges[i] = Edge(from, to, cost);
            }
        }

        vertices[g] = "";
        bool flg = false;
        for (int count=0; count<6*vertices.length; count++) {
            for (int i=0; i<edges.length; i++) {
                string value = edges[i].cost~vertices[edges[i].from];
                if (value < vertices[edges[i].to] && vertices[edges[i].from]!=INF) {
                    vertices[edges[i].to] = value;
                    if (count>=vertices.length-1 && edges[i].to==s) {
                        flg = true;
                    }
                }
            }
        }

        writeln(vertices[s] == INF || flg ? "NO":vertices[s]);
    }
}
struct Edge {
    int from, to;
    string cost;
    this(int from, int to, string cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
}

Measured memory_bytes: 7280
#include <stdio.h>

int main(void)
{
    unsigned char s[2*10*10*10*10*10+1], t[2*10*10*10*10*10+1];
    scanf("%s", s);
    scanf("%s", t);
    int count = 0;
    for(int i = 0; s[i] != '\0'; i++) {
        if(s[i] != t[i]) count++;
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const int N=200010;
ull a[N],b[N];
ll n,m,k,ans=0;

int main(){
    scanf("%lld%lld%lld",&n,&m,&k);
    for(ll i=1;i<=n;i++) {
        scanf("%lld",&a[i]);
        a[i]+=a[i-1];
    }
    for(ll j=1;j<=m;j++){
        scanf("%lld",&b[j]);
        b[j]+=b[j-1];
    }

    for(ll i=0;i<=n;i++){
        if(a[i]<=k) {
            ll tmp=upper_bound(b,b+m+1,k-a[i])-b-1+i;
            ans=max(ans,tmp);
        }
    }

    printf("%d",ans);
}


Measured memory_bytes: 6868