akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc043/tasks/abc043_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n * (n + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

  ll ans = 1LL << 30;
  rep(i, n) {
    rep(j, n) {
      ll cnt = 0;
      rep(k, n) {
        rep(l, n) {
          if ((x[i]-x[j] != 0 || y[i]-y[j] != 0) && x[k] + (x[i]-x[j]) == x[l] && y[k] + (y[i]-y[j]) == y[l]) {
            cnt++;
          }
        }
      }
      cmin(ans, n-cnt);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int n, ans;
int a[101], b[101];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        b[i] += max(a[i], b[i - 1]);
    }
    cout << b[n] << endl;
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
abc=[list(map(int,input().split())) for _ in range(n-1)]
q,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(q)]

z=[[] for _ in range(n)]
for a,b,c in abc:
    z[a-1].append([b-1,c])
    z[b-1].append([a-1,c])

depth=[0 for _ in range(n)]
from collections import deque
que=deque([])
v,p,d=k-1,-1,0
que.append((v,p,d))
while que:
    v,p,d=que.pop()
    depth[v]=d
    for t in z[v]:
        if t[0]==p:
            continue
        que.append((t[0],v,d+t[1]))
for x,y in xy:
    print(depth[x-1]+depth[y-1])

Measured memory_bytes: 124248
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int r,d,x;
    cin >> r >> d >> x;
    REP(i,10){
        x = r * x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{

    public static class Program 
    {
        public static void Main() 
        {
           var a=Console.ReadLine();
           var b=Console.ReadLine();
           if(a.Length<b.Length){Console.WriteLine("LESS"); return;}
           if(a.Length>b.Length){Console.WriteLine("GREATER"); return;}
           
           for(var i=0; i<a.Length; i++)
           {
               if(a[i]<b[i]){Console.WriteLine("LESS"); return;}
               if(a[i]>b[i]){Console.WriteLine("GREATER"); return;}
           }
           
           Console.WriteLine("EQUAL");
        }
    }
}

Measured memory_bytes: 11092
def main():
  n, m = input_list()
  box = [False]*n
  box[0] = True
  nums = [1]*n
  for i in range(m):
    x, y = input_list()
    if box[x-1]:
      box[y-1] = True
    nums[x-1] = nums[x-1] - 1
    nums[y-1] = nums[y-1] + 1
    if nums[x-1] == 0:
      box[x-1] = False
  print(box.count(True))
    

def input_list():
  return map(int, input().split())

import math
main()

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;

  ll ans = 0;
  ll bcnt = 0;
  rep(i, s.size()) {
    if (s[i] == 'B')
      bcnt++;
    else
      ans += bcnt;
  }

  cout << ans << endl;
}


Measured memory_bytes: 644
if __name__ == '__main__':
    N = int(input())
    H = list(map(int, input().split()))
    max_move_count = 0
    move_count = 0
    for i in range(N):
        try:
            if H[i] >= H[i + 1]:
                move_count += 1
                if max_move_count < move_count:
                    max_move_count = move_count
            else:
                move_count = 0
        except:
            pass
    print(max_move_count)

Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int sum = accumulate(a, a+sizeof(a)/sizeof(a[0]), 0);
    stable_sort(a, a+sizeof(a)/sizeof(a[0]), greater<>());
    if (a[m-1] >= (double)sum/(4*m)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];

    sort(a.begin(), a.end());
    int ansN = a.back();
    int ansR = -1;

    double diff = INT_MAX;
    for (int i=0; i<n; i++) {
        if (chmin(diff, abs((double)a[i] - ansN/2.0))) {
            ansR = a[i];
        }
    }

    cout << ansN << " " << ansR << endl;
}


Measured memory_bytes: 3200
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

class water_node():
    def is_meltable(self):
        if self.sugar <= self.water * self.meltable/100:
            return True
        return False
    def __init__(self, water, sugar, meltable):
        self.water = water
        self.sugar = sugar
        self.mass = water + sugar
        self.meltable = meltable
        self.is_all_melt = self.is_meltable()
        if self.sugar + self.water > 0:
            self.concentration = self.sugar * 100.0 /float(self.sugar + self.water)
        else:
            self.concentration = -1.0


    def __eq__(self,other):
        return (self.water  == other.water) and (self.sugar  == other.sugar)

    def __hash__(self):

        return hash (self.water + self.sugar* 10000)


def BFS(A, B, C, D, E, F):
    n = water_node(0, 0, E)
    done_set = set([n])
    node_list = deque([n])
    max_concentration_node = n
    while len(node_list) > 0:
        n = node_list.popleft()
        #ope1
        new_node_list = []
        new_node_list.append(water_node(n.water + A * 100, n.sugar, E))
        new_node_list.append(water_node(n.water + B * 100, n.sugar, E))
        new_node_list.append(water_node(n.water, n.sugar + C, E))
        new_node_list.append(water_node(n.water, n.sugar + D, E))
        for new_node in new_node_list:
            if new_node.mass <= F:
                if new_node not in done_set:
                    done_set.add(new_node)
                    node_list.append(new_node)
                    if new_node.is_all_melt == True and new_node.concentration > max_concentration_node.concentration:
                        max_concentration_node = new_node
    return max_concentration_node


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C, D, E, F] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3]), int(input_raw[4]), int(input_raw[5])]
    max_c = BFS(A, B, C, D, E, F)
    print int(max_c.mass), int(max_c.sugar)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27372
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

typedef pair<int,int> P ;

int main(){

	int dx[4]={0,0,-1,1};
	int dy[4]={-1,1,0,0};

	
	while(1){
		int cnt=1;
		int w,h;
		int sx,sy;
		char c[21][21];

		cin >> w >> h ;
		if( h==0 && w==0) return 0;

		for(int y = 0; y < h; y++){
			scanf("%s", c[y]);
			for(int x = 0; x < w; x++){
				if( c[y][x] == '@' ){
					sx = x; 
					sy = y;
				 }
			}
		}

		queue<P> q;
		q.push(P(sx,sy));
		c[sy][sx] = '#';

		while(!q.empty()) {
			int x = q.front().first;
			int y = q.front().second;
			q.pop();
			
			for(int i=0;i<4;i++){
				int mx = x+dx[i] , my = y+dy[i];
				if( mx<0 || my<0 || w<=mx || h<=my || c[my][mx] == '#'||c[my][mx] =='@') continue;
				q.push(P(mx,my));	
				c[my][mx] = '#';	
				cnt++;			
			}
			
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

//けんちょんさんのやつ
//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
const int MAX = 1000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    int X, Y;
    cin >> X >> Y;
    if(X > 2*Y || Y > 2*X || (X+Y)%3) { cout << 0 << endl; return 0;}
    cout << COM((X+Y)/3, Y-(X+Y)/3) << endl;
    return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,a[N],ans;
inline int rd() {	int r;scanf("%d",&r);return r;}
bool cmp(int p1,int p2) {return p1 > p2;}
int main(){
	n = rd();
	for (int i=1;i<=n;i++) a[i] = rd();
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) if(i+1>a[i+1]) {
		for(int j=i+1;a[j]==i;j++) ans^=1;
		ans |= (a[i] - i) & 1;
        if (ans) puts("First"); else puts("Second");
		return 0;
    }
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

ll a[200000 +10];
int main2() {
  int N = nextInt();
  ll sum = 0;
  REP(i, N) { a[i] = nextInt(); sum += a[i]; }

  ll sum2 = 0;
  ll ans = (1LL << 58);
  REP(i, N-1) {
    sum2 += a[i];
    ans = min(ans, abs(sum2 - (sum - sum2)));
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 1792
#include <string.h>
#include <stdio.h>
int main(void){
  int a=0;
  int b=0;
  int c=0;
  int swap;
  while(a<1 || a>100){scanf("%d",&a);}
  while(b<1 || b>100){scanf("%d",&b);}
  while(c<1 || c>100){scanf("%d",&c);}
  swap=a; a=b; b=swap;
  swap=a; a=c; c=swap;
  printf("%d %d %d",a,b,c);
  return 0;
}

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

const int maxn = 100000 * 3 + 10;

int a[maxn];
long long g[maxn], f[maxn];

priority_queue<int> q2;
priority_queue<int, vector<int>, greater<int> > q1;

int main() {
    int n;
    //freopen("data.txt", "r", stdin);
    long long ans1 = 0, ans2 = 0;
    
    scanf("%d", &n);
    for(int i = 1; i <= 3*n; i++) {
        scanf("%d", &a[i]);
        if(i <= n) ans1 += a[i], q1.push(a[i]);
        if(i >= 2*n + 1) ans2 += a[i], q2.push(a[i]);
    }

    f[n] = ans1;
    for(int i = n + 1; i <= 2*n; i++) {
        if(a[i] > q1.top()) {
            f[i] = f[i-1] + a[i] - q1.top();
            q1.pop();
            q1.push(a[i]);
        }
        else f[i] = f[i-1];
    }
    g[2*n+1] = ans2;
    for(int i = 2*n; i >= n+1; i--) {
        if(a[i] < q2.top()) {
            g[i] = g[i+1] + a[i] - q2.top();
            q2.pop();
            q2.push(a[i]);
        }
        else g[i] = g[i+1];
    }

    long long ans = -LLONG_MAX;
    for(int i = n; i <= 2*n; i++) 
        ans = max(ans, f[i] - g[i+1]);
    
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5112
//Hey u r too far away to know this
//CHIRAGA196
#include <bits/stdc++.h>
using namespace std;
#define     ff                  first
#define     pb                  push_back
#define     ss                  second
#define     IOS                 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     all(v)              v.begin(), v.end()
#define     allr(v)             v.rbegin(), v.rend()
#define       int               long long
#define       endl             '\n'
const   int N = 1e6+5, Mod = 1e9 + 7;
int fact[N];
int powr(int a, int b){
	int res = 1;
	while(b){
		if(b&1)
			res *= a;
		res %= Mod;
		a *= a;
		a %= Mod;
		b /= 2;
	}

	return res%Mod;
}
int32_t main(){
        IOS;
     
        int n; cin >> n;
        fact[0] = 1;
        for(int i = 1; i < N; i++){
        	fact[i] = fact[i - 1]*i;
        	fact[i]%= Mod;
        }
        if(n < 2){
        	cout << "0";
        	return 0;
        }
        int ans = powr(10, n);
        int ans2 = 2*powr(9, n);
        ans -= ans2;
        ans += powr(8, n);
        ans%= Mod;
        ans += Mod;
        cout << ans%Mod << endl;
        return 0;
}

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


int main() {
	string s;
	cin >> s;
	int flag[12];
	for (int i = 0; i <= 11; i++) {
		flag[i] = 0;
	}
	int len = 0;
	while (s[len] != '\0') {
		len++;
	}
	len--;
	for (int i = 0; i <= len; i++) {
		if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') flag[i]++;
	}
	int ans = 0;
	for (int i = 0; i <= len; i++) {
		if (flag[i] == 1) {
			int pre = 1;
			int j = i+1;
			while (flag[j] == 1) {
				j++;
				pre++;
			}
			if (ans < pre)ans = pre;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
ans=0
for i in range(1,500):
  L.append(i**2)
for i in range(n):
  for j in range(i+1,n):
    ct=0
    for k in range(d):
      ct+=(l[i][k]-l[j][k])**2
    if ct in L:
      ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> A(n);
    for(int i=0; i<n; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    int sub;
    sub=k-A.back()+A.at(0);
    for(int i=0; i<n-1; i++){
        sub = max(sub, A.at(i+1) -A.at(i));
    }
    cout << k-sub << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 55;
const int M = N * N;
const int Mod = 1e9 + 7;

int Dp[2][N][N][2 * M];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

int add(int x, int y)
{
    return add_self(x, y), x;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

int main()
{
    int n, m;   cin >> n >> m;

    int nn = n * n;

    Dp[0][0][0][m + M] = 1;

    for(int i = 1; i <= n; i++)
    {
        for(int j1 = 0; i + j1 <= n; j1++)  /// empty cells after 'i'
        {
            for(int j2 = 0; i + j2 <= n; j2++)  /// values greater than 'i' need to be at 'i' before it
            {
                for(int k = -nn; k <= nn; k++)    /// current oddness
                {
                    Dp[i & 1][j1][j2][k + M] = 0;

                    add_self(Dp[i & 1][j1][j2][k + M], mul(j1 + 1, Dp[(i - 1) & 1][j1 + 1 - 1][j2][k + i - i + M]));
                    if(j1 > 0 && j2 > 0 && k - i - i >= -nn)
                    add_self(Dp[i & 1][j1][j2][k + M], mul(j1 * j2, Dp[(i - 1) & 1][j1 - 1][j2 - 1][k - i - i + M]));
                    if(k + i + i <= nn)
                    add_self(Dp[i & 1][j1][j2][k + M], Dp[(i - 1) & 1][j1 + 1][j2 + 1][k + i + i + M]);
                    add_self(Dp[i & 1][j1][j2][k + M], mul(j2, Dp[(i - 1) & 1][j1][j2 - 1 + 1][k - i + i + M]));
                }
            }
        }
    }

    cout << Dp[n & 1][0][0][0 + M] << endl;
}


Measured memory_bytes: 133248
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int n, m, c;
   cin >> n >> m >> c;
   int B[m];
   for (int i = 0; i < m; i++) {
      cin >> B[i];
   }
   int A[n][m];
   int ans = 0;
   for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j < m; j++) {
         cin >> A[i][j];
         sum += A[i][j] * B[j];
      }
      sum += c;
      if (sum > 0) ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static class Pos {
        int y;
        int x;
        int yy;
        int xx;

        public Pos(int y, int x, int yy, int xx) {
            this.y = y;
            this.x = x;
            this.yy = yy;
            this.xx = xx;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] a = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        List<Pos> list = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w - 1; j++) {
                if (a[i][j] % 2 == 0) {
                    continue;
                }
                a[i][j]--;
                a[i][j + 1]++;
                list.add(new Pos(i, j, i, j + 1));
            }
        }
        for (int i = 0; i < h - 1; i++) {
            if (a[i][w - 1] % 2 == 0) {
                continue;
            }
            a[i][w - 1]--;
            a[i + 1][w - 1]++;
            list.add(new Pos(i, w - 1, i + 1, w - 1));
        }
        System.out.println(list.size());
        for (int i = 0; i < list.size(); i++) {
            StringBuilder sb = new StringBuilder();
            Pos p = list.get(i);
            sb.append(p.y + 1);
            sb.append(" ");
            sb.append(p.x + 1);
            sb.append(" ");
            sb.append(p.yy + 1);
            sb.append(" ");
            sb.append(p.xx + 1);
            System.out.println(sb);
        }
    }
}


Measured memory_bytes: 70296
#include <cstdio>

int main()
{
  int n;
  scanf("%lld", &n);
  long long a[200000];
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
  }
  long long r = 0;
  long long sum = 0;
  long long eor = 0;
  long long ans = 0;
  for (long long l = 0; l < n; ++l)
  {
    while (r < n && (sum + a[r]) == (eor ^ a[r]))
    {
      sum += a[r];
      eor ^= a[r];
      ++r;
    }
    ans += r - l;
    if (r == l) ++r;
    else
    {
      sum -= a[l];
      eor ^= a[l];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int main()
{
	int n;cin >> n;
	ll ret = 1;
	
	REP(i,n)
	{
		ret = (ret*(i+1))%1000000007;
	}
	
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    string s;
    cin >> s;

    Yn(s[2] == s[3] && s[4] == s[5]);

    return 0;
}


Measured memory_bytes: 256
import sys


try:
    sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
    sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
    pass


x = int(input())

n = 100
t = 0
while n < x:
    n += (0.01 * n)
    n = int(n)
    t += 1
    # print(n, t)

print(t)

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

int n, k;

int main(void){
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = k; i < n; i++){
        if(a[i] > a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

using namespace std; 
 
#define int long long
#define M 1000000007
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0;i<s.length();i++){
		char ch=s[i];
		for(int j=0;j<n;j++){
			if(ch=='Z'){
				ch='A';
			}
			else{
				ch++;
			}
		}
		cout << ch;
	}
}


Measured memory_bytes: 3668
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  x <- getInt
  putStrLn $ ["1", "0"] !! x


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,h,w,a,b;
    int ans = 0;
    scanf("%d%d%d",&n,&h,&w);
    while(n--)
    {
        scanf("%d%d",&a,&b);
        if(a>=h&&b>=w)
            ans ++;
    }
    printf("%d",ans);
    return 0;

}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0 for j in range(M+1)]for i in range(N+1)]
for j in range(M+1):
    dp[0][j] = 1
for i in range(N+1):
    dp[i][0] = 1

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])%MOD
        else:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%MOD

print(dp[N][M])


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto& i : map)

int main()
{
    long long N, M; cin >> N >> M;
    vector<long long> H(N);
    rep (i, 0, N) cin >> H[i];
    vector<int> ok(N, 1);
    rep (i, 0, M) {
        int a, b; cin >> a >> b; --a, --b;
        if (H[a] < H[b]) ok[a] = 0;
        else if (H[a] > H[b]) ok[b] = 0;
        else ok[a] = ok[b] = 0;
    }

    cout << accumulate(ok.begin(), ok.end(), 0) << endl;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, M;

int check(int n) {
   int a = M - (n * (N-1));
   if (a > 0 && a % n == 0) {
      return n;
   }
   return -1;
}

signed main() {
   cin >> N >> M;

   int ans = 1;
   for (int i = 1; i*i <= M; i++) {
      if (M % i != 0) continue;

      int j = M / i;
      chmax(ans, check(i));
      chmax(ans, check(j));
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

const string target = "keyence";

int main() {
    string s;
    cin >> s;
    int l = s.size();
    
    rep(i, l) {
        rep(j, l) {
            string ans = "";
            rep(k, l) {
                if(i <= k && k <= j) continue;
                else ans.push_back(s[k]);
            }
            if(ans == target) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int stack[100];
int sp = 99;
int main() {
    int x = 0;
    while(scanf("%d", &x) != EOF) {
        if(x == 0) {
            //取り出し
            --sp;
            printf("%d\n", stack[sp]);
        } else {
            //格納
            stack[sp] = x;
            ++sp;
        }
    }
}


Measured memory_bytes: 1928
#include<stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a > b) {
		printf("a > b\n");
	}
	else if (a < b) {
		printf("a < b\n");
	}
	else {
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
 
	
	ll N;
	cin >> N;
	ll an = 0;
	vector<ll> vec(N);
	for (ll i = 0; i < N; i++) {
		cin >> vec.at(i);
		vec.at(i) -= (i + 1);
	}
	sort(vec.begin(), vec.end());
	ll h = vec.at(N / 2);
	for (ll i = 0; i < N; i++) {
		vec.at(i) -= h;
		an += abs(vec.at(i));
	}
	cout <<an<< endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b>=c)cout << "delicious" << endl;
	else if(a>=c-b) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int max(int [],int ,int );
int min(int [],int ,int );
int main(void){
    int a[1000],n,q,com,b,e;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d %d %d",&com,&b,&e);
        if(com==0) min(a,b,e);
        else max(a,b,e);
    }
    return 0;
}

int max(int a[],int b,int e){
    int i,max=a[b];
    for(i=b+1;i<e;i++){
        if(max<a[i]) max=a[i];
    }
    printf("%d\n",max);
    return 0;
}

int min(int a[],int b,int e){
    int i,min=a[b];
    for(i=b+1;i<e;i++){
        if(min>a[i]) min=a[i];
    }
    printf("%d\n",min);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int a;
  vector<int> vec_in(N);
  for(int i=0; i<N; i++){
    cin >> a;
    vec_in.at(i) = a;
  }
  
  //出力
  int x=0;//終了までの手数
  vector<int> vec_out(N);
  for(int i=0; i<N; i++){
    if(i==0){
      vec_out.at(i)=vec_in.at(i);
    }
    else{
      vec_out.at(i)=vec_in.at(vec_out.at(i-1)-1);
    }
    x++;
    if(vec_out.at(i)==2){
      cout << x << endl;
      break;
    }
    if(i==N-1){
      x=-1;
      cout << x << endl;
    }
  }
}

Measured memory_bytes: 1024
N = int(input())
a = [int(input())  for i in range(N)]
index = sorted(range(len(a)), key=lambda k: a[k])
count = 0
for i in range(N):
    if (index[i]+i)%2 ==1:
        count = count + 1
print('%s' % str(count//2))


Measured memory_bytes: 12640
package main

import (
	"fmt"
	//"strconv"

	// Reader
	"bufio"
	"os"
	"strings"
)

func main() {
	s := nextLine()
	t := nextLine()
	l := len(s[0])
	if t[0][:l] == s[0] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// Reader
var limit int = 1000
var rdr = bufio.NewReaderSize(os.Stdin, limit)

func nextLine() []string {
	return parseLine(readLine())
}

func readLine() string {
	buf := make([]byte, 0, limit)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func parseLine(s string) []string {
	slice := strings.Split(s, " ")
	return slice
}


Measured memory_bytes: 1760
/* author   : mpily :-()
title : Competing.cpp
time :Sun Nov 24 15:02:47 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	for(int i = 0; i < s.size(); i++){
		int k = s[i]-'A';
		k+=n;
		k%=26;
		s[i]= 'A'+k;
	}
	cout<<s<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	scanf("%d %d %d",&a,&b,&c);
	scanf("%d",&k);
	if(a<b&&b<c)
		printf("Yes");
	else 
	{
		while(k--)
		{
			if(b>=c)
			{
				c*=2;
				continue;
			}
			if(a>=b)
			{
				b*=2;
				continue;
			}
		}
		if(a<b&&b<c)
			printf("Yes");
		else
			printf("No");
	}
}

Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		System.out.println(paliNum(N));
	}
	
	static String paliNum(int N) {
		String n = Integer.toString(N);
		int len = n.length();
		for(int i=0; i<=len/2-1; i++) {
			if(n.charAt(i) != n.charAt(len-1-i)) return "No";
		}
		return "Yes";
	}
	
}


Measured memory_bytes: 22868
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var n = s.Count();
            var A = new Queue<Char>();
            
            foreach (var x in s)
            {
                A.Enqueue(x);
            }

            var IsMatched = false;
            for(int i=0;i<=n;i++)
            {
                if(new string(A.ToArray()) == t)
                {
                    IsMatched = true;
                }
                A.Enqueue(A.Dequeue());
            }

            Console.WriteLine(IsMatched? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11348
import java.io.*;
public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int i;
		int n;
		//int[] scores;
		int max;
		int min;
		int ave;
		int score;
		try{
			while(null != (line=reader.readLine())){
				n = Integer.parseInt(line);
				if(n==0)return;
				ave = 0;
				min = -1;
				max = -1;
				//scores = new int[n];
				for(i=0; i<n; i++){
					line = reader.readLine();
					score = Integer.parseInt(line);
					if(max < score){
						ave += (max<0)?0:max;
						if(max >= 0 && min < 0){
							min = max;
							ave -= max;
						}
						max = score;
					}else{
						if(min < 0){
							min = score;
						}else if(min > score){
							ave += (min<0)?0:min;
							min = score;
						}else{
							ave += score;
						}
					}
					//System.out.println("("+min+";"+max+")");
				}
				ave = ave/(n-2);
				System.out.println(ave);
			}
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
}

Measured memory_bytes: 16908
#include "bits/stdc++.h"
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define endl "\n"
#define umap unordered_map<int, int>
#define uset unordered_set<int>
#define MOD 1000000007
using namespace std;

int main()
{
	FAST_IO;
	int n, x, t;
	cin >> n >> x >> t;
	if (n < x)
	{
		cout << t;
	}
	else
	{
		t = t + (ceil((float)(n - x) / x)) * t;
		cout<<t;
	}
	return 0;
}

Measured memory_bytes: 3704
#include<stdio.h>
int main(void){
    char s[5],p[5];
    int i, count = 0;

    scanf("%s", s);
    scanf("%s", p);

    for(i = 0; i < 3; i++){
        if(s[i] == p[i]){
            count++;
        }
    }
    printf("%d",count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;

int main() {
    int num=100010;
    long long ans=0;
    int n;
    cin >> n;
    vector<vector<int>> x(num,vector<int>(0)),y(num,vector<int>(0));
    vector<int> xa(num),ya(num);
    rep(i,num) {xa.at(i)=0;ya.at(i)=0;}
    int itt,itr;
    rep(i,n){
        cin >> itt >> itr;
        x.at(itt).push_back(itr);
        y.at(itr).push_back(itt);
    }
    queue<pp> q;
    pp v;
    for (int i=1;i<num;i++){
        if (xa.at(i)==1) continue;
        ll xn=1,yn=0,line=0;
        v.first=i;v.second=0;
        q.push(v);
        xa.at(i)=1;
        while (!q.empty()){
            int e=q.front().first,u=q.front().second;
            q.pop();
            if (u==0){
                rep(j,x.at(e).size()){
                    line++;
                    if (ya.at(x.at(e).at(j))==0){
                        v.first=x.at(e).at(j);
                        v.second=1;
                        q.push(v);
                        yn++;
                        ya.at(x.at(e).at(j))=1;
                    }
                }
            }
            if (u==1){
                rep(j,y.at(e).size()){
                    line++;
                    if (xa.at(y.at(e).at(j))==0){
                        v.first=y.at(e).at(j);
                        v.second=0;
                        q.push(v);
                        xn++;
                        xa.at(y.at(e).at(j))=1;
                    }
                }
            }
        }
        ans+=(xn*yn-line/2)*1LL;
    }
    for (int i=1;i<num;i++){
        if (xa.at(i)==1) continue;
        int xn=0,yn=1,line=0;
        v.first=i;v.second=1;
        q.push(v);
        ya.at(i)=1;
        while (!q.empty()){
            int e=q.front().first,u=q.front().second;
            q.pop();
            if (u==0){
                rep(j,x.at(e).size()){
                    line++;
                    if (ya.at(x.at(e).at(j))==0){
                        v.first=x.at(e).at(j);
                        v.second=1;
                        q.push(v);
                        yn++;
                        ya.at(x.at(e).at(j))=1;
                    }
                }
            }
            if (u==1){
                rep(j,y.at(e).size()){
                    line++;
                    if (xa.at(y.at(e).at(j))==0){
                        v.first=y.at(e).at(j);
                        v.second=0;
                        q.push(v);
                        xn++;
                        xa.at(y.at(e).at(j))=1;
                    }
                }
            }
        }
        ans+=xn*yn-line/2;
    }
    cout << ans << endl;
}


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


int main(){
        string s, t; cin >> s >> t;

        int cnt = 0;
        for (int x = 0; x < s.length(); ++x){
            if (s[x] != t[x]){
                ++cnt;
            }
        }

        cout << cnt << endl;
    return 0;
}



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

using ll=long long;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int div1(ll x){
  return x%1000000007;
}

int xy(int x,int y){
    if (x ==1 && y== 1) return 400000;
    return 0;
}

main(){
    int h=in(),w=in(),k=in(),ans[h][w],pt[2];
    char s[h][w];
    for (int i=0;i<h;i++){
        for (int i2=0;i2<w;i2++) {
            cin >> s[i][i2];
            if (s[i][i2]=='#'){
                pt[0]=i;
                pt[1]=i2;
            }
            ans[i][i2]=0;
        } 
    }
    int n=0,fi;
    bool fl;
    for (int i=0;i<h;i++){
        fl=false;
        for (int i2=0;i2<w;i2++) if (s[i][i2]=='#') {
            fl=true;
            fi=i2;
            break;
        }
        if (!fl) {
            continue;
        }
        else{
            for (int i2=0;i2<fi;i2++){
                ans[i][i2]=n+1;
            }
            for (int i2=fi;i2<w;i2++){
                if (s[i][i2]=='#') n++;
                ans[i][i2]=n;
            }
        }
    }
    for (int i=0;i<pt[0]+1;i++){
        if (ans[i][0]!=0) continue;
        int p=0,l=i+1;
        while (p==0) {
            p=ans[l][0];
            l++;
        }
        for (int i2=0;i2<w;i2++) {
            ans[i][i2]=ans[l-1][i2];
        }
    }
    for (int i=pt[0]+1;i<h;i++){
        for (int i2=0;i2<w;i2++) {
            ans[i][i2]=ans[pt[0]][i2];
        }
    }
    for (int i=0;i<h;i++){
        for (int i2=0;i2<w;i2++) {
            cout << ans[i][i2] << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include<iostream>
#include<set>
using namespace std;
set<int> st;
set<int>::iterator it;
int main()
{
	int n,i,ans=0;
	cin>>n;
	while(n --)
	{
		cin>>i;
		it = st.find(i);
		if(it!=st.end()) 
			st.erase(i);
		else st.insert(i);
	}
	for(int j=0;j<st.size();j++) ans++;
	cout<<ans<<endl;
	return 0;
 }

Measured memory_bytes: 4864
from itertools import permutations

n = int(input())
n_ = 1
for i in range(n):
    n_ *= i+1
c = [tuple(map(int,input().split())) for _ in range(n)]
tot = 0

def dis(c,x,y):
  x1,y1 = c[x]
  x2,y2 = c[y]
  return ((x1-x2)**2 + (y1-y2)**2)**.5

for l in permutations(range(n)):
    d = 0
    cur = l[0]
    for x in l:
        d += dis(c,cur,x)
        cur = x
    tot += d/n_
print(tot)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n,x,ans;
  ans=1;
  cin>>n>>x;
  ll a[n],d;
  d=0;
  rep(i,n){
    cin>>a[i];
    d=d+a[i];
    if(d<=x){
      ans++;
    }
    else{
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    if(s.at(0)!='s'){
        reverse(s.begin(),s.end());
        s += 's';
    }
    if(s.at(0)=='s'){
        reverse(s.begin(),s.end());
        s += "es";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;

struct UnionFind {
private:
  vector<ll> child, tree;
  vector<vector<ll>> list;

public:
  //頂点数v
  UnionFind(ll v) {
    tree.resize(v);
    list.resize(v);
    for(ll i = 0; i < v; i++) {
      tree[i] = i;
      list[i].push_back(i);
    }
  }

  //木の根を求める
  ll root(ll x) {
    if(x == tree[x]) {
      for(ll i = 0; i < child.size(); i++) {
        tree[child[i]] = x;
      }
      child.clear();
      return x;
    } else {
      child.push_back(x);
      return x = root(tree[x]);
    }
  }
  //xの所属するグループの大きさ
  ll size(ll x) { return list[root(x)].size(); }

  vector<ll> nodes(ll no) { return list[root(no)]; }

  //xとyの集合を合わせる
  bool unit(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) {
      return false;
    }
    if(list[x].size() < list[y].size()) {
      swap(x, y);
    }
    for(int no : list[y]) {
      list[x].emplace_back(no);
    }
    tree[y] = x;
    return true;
  }

  //xとyが同じグループに所属するか
  bool isUnit(ll x, ll y) { return root(x) == root(y); }
};

int main(){
  int n, k, l;
  cin >> n >> k >> l;
  UnionFind road(n), train(n);
  for(int i = 0; i < k; i++) {
    int p[2];
    cin >> p[0] >> p[1];
    p[0]--;
    p[1]--;
    road.unit(p[0], p[1]);
  }
  
  
  for(int i = 0; i < l; i++) {
    int r[2];
    cin >> r[0] >> r[1];
    r[0]--;
    r[1]--;
    train.unit(r[0], r[1]);
  }
  
  /*
  for(int i = 0; i < k; i++) {
    cout << p[i][0] << " " << p[i][1] << '\n';
  }
  for(int i = 0; i < n; i++) {
    cout << road.root(i) << " ";
  }
  cout << '\n';
  for(int i = 0; i < n; i++) {
    cout << train.root(i) << " ";
  }
  cout << '\n';
  */
  
  map<pair<int, int>, int> root;
  for(int i = 0; i < n; i++) {
    pair<int, int> tmp;
    tmp = make_pair(road.root(i), train.root(i));
    root[tmp]++;
  }
  

  for(int i = 0; i < n; i++) {
    pair<int, int> tmp = make_pair(road.root(i), train.root(i));
    cout << root[tmp] << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 37128