akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 310
#define M 3
ll n, m;
vector<PP> v;
int t[1<<M];
ll dp[N][N][N];
int d[M];
int main(){
	rep(i, 1<<M) t[i] = __builtin_popcount(i);
	cin>>n>>m;
	rep(i, m){
		int a, b, c;
		cin>>a>>b>>c;
		v.push_back(PP(P(a, b), c));
		if(b==1 && c>1){
			cout<<0<<endl;
			return 0;
		}
	}
	sort(all(v));
	dp[1][0][0] = dp[0][1][0] = dp[0][0][1] = 1;
	ll res = 0;
	int p = 0;
	for(int ii = 1; ii < n; ii++){
		while(p<m && v[p].fst.fst<=ii+1) p++;
		rep(jj, max(1, ii)) rep(kk, max(1, ii)){
			if(jj && jj==kk) continue;
			d[0] = ii; d[1] = jj; d[2] = kk;
			rep(_, M){
				rotate(d, d+1, d+M);
				if(dp[d[0]][d[1]][d[2]]==0) continue;
				int d2[3];
				memcpy(d2, d, sizeof(d));
				int x = ii+1;
				rep(i, M){
					swap(x, d[i]);
					bool ok = true;
					rep(j, p){
						if(d[i]!=v[j].fst.snd){
							if(d[i]>v[j].fst.snd){
								for(int k = j; k < m-1; k++) v[k] = v[k+1];
								m--;
								p--;
								j--;
							}
							continue;
						}
						int cnt = 0;
						rep(k, M) if(v[j].fst.fst<=d[k] && d[k]<=v[j].fst.snd) cnt++;
						//if(cnt>v[j].snd || (d[i]==v[j].fst.snd&&cnt!=v[j].snd)){
						if(cnt!=v[j].snd){
							ok = false;
							break;
						}
					}
					if(ok) {
						if(ii+1==n){
							(res += dp[d2[0]][d2[1]][d2[2]]);
							if(res>mod) res -= mod;
						} else {
							dp[d[0]][d[1]][d[2]]+=dp[d2[0]][d2[1]][d2[2]];
							if(dp[d[0]][d[1]][d[2]]>mod) dp[d[0]][d[1]][d[2]] -= mod;
						}
					}
					swap(x, d[i]);
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 225536
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] input = new int[5];
    input[0] = sc.nextInt();
    input[1] = sc.nextInt();
    input[2] = sc.nextInt();
    input[3] = sc.nextInt();
    input[4] = sc.nextInt();
    int lastIdx = 0;
    int answer = 0;
    for (int i = 1; i < 5; i++){
        if (input[i] % 10 != 0 && input[lastIdx] % 10 > input[i] % 10) {
            lastIdx = i;
        }
    }
    for (int i = 0; i < 5; i++){
        if (i != lastIdx) {
            answer += floor(input[i],10);
        }
    }
    answer += input[lastIdx];
    System.out.println(answer);

  }
  
  private static int floor(int src, int unit){
      if ((src % unit) == 0) {
          return src;
      } else {
          return ((src / unit) + 1) * unit;
      }
  }
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;

	bool flag=false;
	if(x==w/2&&y==h/2)flag=true;
	double ans;
	ans=w*h/2;

	if(flag){
		cout<<fixed<<setprecision(9)<<ans<<" "<<1<<endl;
	}else{
		cout<<fixed<<setprecision(9)<<ans<<" "<<0<<endl;
	}

}


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

int findSumOfDigits(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    int total=0;
        for(int i;i<=N;++i){
            int sum=findSumOfDigits(i);
            if(sum<=B&&sum>=A)total+=i;
        }
    cout<<total;
}

Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
#include<stack>
#include<math.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<=(n);i++)
#define LL long long int
 
 
using namespace std;
 
LL lcm(LL n, LL m)
{
	LL u;
	LL ansl = 0;
	for(u=m; u>=m; u++){
		if(u%n == 0){
			if(u%m == 0){
				ansl = u;
				break;
			}
		}
	}
	return ansl;
}
 
int main(void){
    int n;
    cin >>n;
    vector<string>s(n);
    string w;
    rep(i,n){
        cin >>w;
        sort(w.begin(),w.end());
        s[i]=w;
    }
    sort(s.begin(),s.end());
    w="";
    LL ans=0;
    int flag=1;
    LL wa=1;

    vector<LL>aa(n+1);
    aa[0]=0;
    aa[1]=0;
    for (int i=2;i<n+1;i++){
        aa[i]=i-1+aa[i-1];
        
    }


    rep(i,n){
        if (s[i]==w){
            wa++; 
        }

        if (s[i]!=w){
            w=s[i];
            ans+=aa[wa];
            wa=1;
        }
    }
   
            w=s[n-1];
            ans+=aa[wa];
            wa=1;
        
    cout <<ans<<endl;
    return 0;

}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair

signed main (){	
	int nn;
	cin >> nn;
	li a[nn];
	rep(i,nn){
		cin >> a[i];
	}
	li ans = 0;

	rep(i,nn){
		ans = ans + (a[i] - (a[i]%2))/2;
		if(a[i]%2 == 1 && i != nn-1){
			if(a[i+1] > 0){
				ans ++;
				a[i+1]--;
			}
		}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	ll bal=100,x;
	ll yr=0;
	cin>>x;
	while(bal<x)
	{
		bal+=bal/100;yr++;
	}
	cout<<yr;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3652
n, k = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j <= n-1:
            dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]), dp[i+j])
print(dp[n-1])

Measured memory_bytes: 55392
// 154 A

#include <iostream>
#include <string>

using namespace std;

int main(){
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(s == u) a--;
    else if(t == u) b--;
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

const int INF = 1001001001;

std::vector<int> A, B;
int dp[2][1000001], dp2[2][1000001];

void DP(int (&dp)[2][1000001], std::vector<int> &v){
    for(int i=0;i<=1000000;i++){
        dp[0][i] = INF;
    }
    dp[0][0] = 0;

    int L = v.size();
    int prev = 0, next = 1;
    for(int i=0;i<L;i++){
        for(int j=0;j<=1000000;j++){
            dp[next][j] = dp[prev][j];
            if(j-v[i] >= 0){
                dp[next][j] = std::min(dp[next][j], dp[next][j-v[i]] + 1);
            }
        }

        prev = !prev;
        next = !next;
    }
}

int main(){
    for(int i=1;;i++){
        long long x = 1ll * i * (i+1) * (i+2) / 6;
        if(x <= 1000000ll){
            A.push_back(x);
            if(x & 1){B.push_back(x);}
        }else{
            break;
        }
    }
    
    DP(dp, A);
    DP(dp2, B);
    
    int N;
    while(scanf("%d", &N), N){
        printf("%d %d\n", dp[0][N], dp2[0][N]);
    }
}

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

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll num;
    bool flag = false;
    cin >> num;
    std::vector<bool> v(1001001001,false);
    for(int i = 0; i < num; i++){
        ll x;
        cin >> x;
        if(v[x]){
            cout <<"NO";
            flag  = true;
            break;
        }
        else v[x] = true;
    }
    if(!flag) cout << "YES";
    return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________

*/


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


int main(void) {
  ll a,b,x;
  cin >> a >> b >> x;
  ll ans = b/x - a/x;
  if (a%x == 0) ans++;
    
  
  
  cout << ans << endl;
               
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define fi first
#define se second
 
#define mp make_pair
#define pb push_back
 
#define all(x) (x).begin(), (x).end()
 
#define F return
#define skip continue

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)

typedef long long ll;

using namespace std;                             

typedef pair<int, int> pii;
typedef pair<ll, ll> pll; 

 
const int MAXN = 3e5 + 500;
const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;

int n, a[105];

void solve() {                        
    cin >> n;
    int sum = 0, mn = INF;
    rep(i,1,n) {cin >> a[i], sum += a[i];if (a[i] % 10 != 0) mn = min(mn, 
    a[i]);}
    if (sum % 10 != 0) cout << sum;
    else {
        cout << max(sum - mn, 0); 
    }
}

int main() {                
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tt = 1;
     
    while (tt--) {
        solve();
        cout << '\n';
    }
 
    return 0;
    // you should actually read the stuff at the bottom
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
*/	

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
typedef long long LL;
const int N = 1e6+7 , INF = 0x3f3f3f3f , mz = 1e9+7;
const double PI = acos(0.0) * 2;
template<typename T1>
T1 gcd(T1 a , T1 b){ return b ? gcd(b,a%b) : a;}

int main(){
#ifdef LOCAL
    freopen("F:\\c++\\in.txt", "r", stdin);
//  freopen("F:\\c++\\out1.txt","w",stdout);
#endif
    int t;
    cin>>t;
    if( t%10 == int(t/100) )    puts("Yes");
    else    puts("No");
    return 0;
}

Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0].split(" ")[0];
let _k = BigInt(input[0].split(" ")[1]);
const a = input[1].split(" ").map((x: string): number => (+x) - 1);

let current = 0;
const visited = new Map();
let count = 0;
while (!visited.has(current)) {
	visited.set(current, count);
	current = a[current];
	count++;
}
const d = BigInt(visited.get(current)!);
const loop_length = BigInt(count) - d;
const k = _k < d + loop_length ? Number(_k) : Number(d + ((_k - d) % loop_length));
current = 0;
for (let i = 0; i < k; i++) {
	current = a[current];
}
console.log(current + 1);


Measured memory_bytes: 61564
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// 間隔gを指定した挿入ソート（Insertion Sort）
void insertionSort(int A[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 and A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    for (int h = 1; ; ) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    // 逆順にGを指定
    for (int i = G.size()-1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    } 
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if ( i ) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for (int i = 0; i < n; i++) printf("%d\n", A[i]);

    return 0;
}


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

bool palin(int x) {
  string s = to_string(x);
  string s2 = s;
  reverse(s2.begin(), s2.end());
  return s2 == s;
}

int main() {
  int a, b;
  cin >> a >> b;
  int c = 0;
  for (int i = a; i <= b; i++)
    if (palin(i))
      c++;
  cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define MAXA 1000000
using namespace std;
int main(){
	int cnt[MAXA+1] = {0};
	int N, A, ans;
	cin >> N;
	for(ans = N; N; N--){
		cin >> A;
		cnt[A]++;
	}
	for(int i=1; i<=MAXA; i++){
		if(cnt[i] > 1)
			ans -= cnt[i];
		if(cnt[i])
			for(int j=i+i; j<=MAXA; j+=i)
				if(cnt[j]){
					ans -= cnt[j];
					cnt[j] = 0;
				}
	}
	cout << ans << endl;
}


	



Measured memory_bytes: 7548
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	int n, p, a[50], x[2]={0};
	cin >> n >> p;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]%2==0){
			x[0]++;
		} else {
			x[1]++;
		}
	}
	if(x[1]==0){
		if(p==0){
			ll ans=pow(2, n);
			cout << ans << endl;
		} else {
			cout << 0 << endl;
		}
	} else {
		ll ans=pow(2, n-1);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n, i, j, temp = 0;
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();		
		int a[] = new int[1000];
		for (i = 0; i < n; i++) {
			a[i] = stdin.nextInt();
		}
		j = i - 1;
		i = 0;
		while (i < j) {
			temp = a[i];
			a[i] = a[j];
			a[j] = temp;
			i++;
			j--;
		}
		for (i = 0; i < n; i++) {
			if(i == n-1) {
				System.out.println(a[i]);
			}else {
				System.out.print(a[i]+" ");
			}
		}
	}
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = (res*n)%MOD;
    n = (n*n)%MOD;
    r >>= 1;
  }
  return res;
}

int main(){

  int n,a,b;
  cin >> n >> a >> b;
  ll res = modpow(2,n)-1;
  ll aa = a,bb = b;
  REPD(i,a)if(i)aa = i*aa%MOD;
  REPD(i,b)if(i)bb = i*bb%MOD;
  ll amod = modpow(aa,MOD-2);
  ll bmod = modpow(bb,MOD-2);
  aa = bb = n;
  for(int i = n-1;i > n-a;i--)aa = aa*i%MOD;
  for(int i = n-1;i > n-b;i--)bb = bb*i%MOD;
  res = (res-amod*aa)%MOD;
  res = (res-bmod*bb)%MOD;
  res = (res+MOD)%MOD;
  cout << res << endl;

  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a,c;
int n,tot;
int main()
{
	cin>>n;
	cin>>c;
	for(int i=1;i<n;++i)
	{
		cin>>a;
		if(a!=c)
		{
			tot++;
			c=a;
		}
	}
	cout<<tot+1;
}

Measured memory_bytes: 256
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]

ans = []
for i in range(n):
    command = s[i]
    if command == 'AB':
        if a < b:
            ans.append('A')
            a += 1
            b -= 1
        elif a*b == 1 and i != n-1:
            c_tmp = s[i+1]
            if c_tmp == 'AC':
                ans.append('A')
                a += 1
                b -= 1
            else:
                ans.append('B')
                b += 1
                a -= 1
        else:
            ans.append('B')
            b += 1
            a -= 1

    elif command == 'AC':
        if a < c:
            ans.append('A')
            a += 1
            c -= 1
        elif a*c == 1 and i != n-1:
            c_tmp = s[i+1]
            if c_tmp == 'AB':
                ans.append('A')
                a += 1
                c -= 1
            else:
                ans.append('C')
                c += 1
                a -= 1
        else:
            ans.append('C')
            c += 1
            a -= 1
    else:
        if b < c:
            ans.append('B')
            b += 1
            c -= 1
        elif b*c == 1 and i != n-1:
            c_tmp = s[i+1]
            if c_tmp == 'AB':
                ans.append('B')
                b += 1
                c -= 1
            else:
                ans.append('C')
                c += 1
                b -= 1
        else:
            ans.append('C')
            c += 1
            b -= 1
    if a < 0 or b < 0 or c < 0:
        print('No')
        exit()
print('Yes')
for i in range(n):
    print(ans[i])


Measured memory_bytes: 17112
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int X, N;
  cin >> X >> N;
  vector<int> vec(N);
  vector<int> seq(101, 0);
  REP(i, N) {
    int x;
    cin >> x;
    seq[x]++;
  }
  int ans = 0;
  int dif = pow(10, 5);
  REP(i, 1000) {
    if (seq[i]) {
      continue;
    }
    if (dif > abs(X + i)) {
      dif = abs(X + i);
      ans = i;
    }
    if (dif > abs(X - i)) {
      dif = abs(X - i);
      ans = i;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

struct edge {int to, w, rev;};


int main()
{
  int n, q; cin >> n >> q;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> ans(q);
  rep(I, q) {
    ll k; cin >> k;
    ll res = 0;
    ll sum = 0;
    
    int r = 0;
    rep(l, n) {
      while(r < n && sum + a[r] <= k) {
        sum += a[r];
        ++r;
      }
      res += r-l;
      if(r==l) ++r;
      else sum -= a[l];
    }
    ans[I] = res;
  }
  for(auto x : ans) cout << x << endl;
}


Measured memory_bytes: 3536
import scala.io.StdIn._

object Main {
    def main(args: Array[String]): Unit = {
        val n = readLine.toInt
        
        val b = (0 until n).map(_ => readLine.split(" ").map(_.toInt)).forall { r =>
            if (r(0) < r(1) + r(2)) {
                false
            } else {
                r(0) % 2 match {
                    case 0 => (r(1) + r(2)) % 2 == 0
                    case 1 => (r(1) + r(2)) % 2 == 1
                }
            }
        }
        
        if (b) {
            println("Yes")
        } else {
            println("No")
        }
    }
}

Measured memory_bytes: 50988
[a,b] = [int(i) for i in input().split()]
if a > 0:
    print("Positive")
elif (a <= 0 and b >= 0):
    print("Zero")
else:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")


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

#define N 10

int main() {
    
    int list[N];
    
    for (int i = 0; i < N; i++) {
        cin>>list[i];
    }
    
    sort(list, list+N);
    
    for (int i = 9; i > 6; i--) {
        cout<<list[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3156
#!/usr/bin/env python3
import sys
from itertools import chain


def solve(K: int, A: int, B: int):
    n = (A + K - 1) // K
    l = n * K
    if l <= B:
        return "OK"
    return "NG"


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    K = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    answer = solve(K, A, B)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int main()
{
    int a,b,c; cin >> a >> b >> c;
    if(a*c<b){
        cout << c << endl;
    }else{
        cout << int(b/a) << endl;
    }

    return 0;
}


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

int main() {
  int N ; 
  cin >> N ; 
  double T = 0 ; 
  
  for(int i = 0 ; i < N ; i++){
    double x ;
    string u  ;
    cin >> x >> u ; 
    
    if(u == "BTC"){
      x = 380000*x ; 
    }
    
    T  += x ; 
    
  }
  

  cout << T << endl ; 


}



Measured memory_bytes: 3752
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define VEC(kata, num) (kata*)malloc(num * sizeof(kata))
#define DB puts("ok")
#define SENTINEL 1000000007
typedef long long lli;

int main()
{
    int ans=0, x[20], y[20], i, n;
    scanf("%d",&n);
    for(i=0; i<n; i++) {
        scanf("%d",x+i);
    }
    for(i=0; i<n; i++) {
        scanf("%d",y+i);
        if(x[i]>y[i]) {
            ans += (x[i] - y[i]);
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int a[100500];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(a[i] > i && a[a[i]] == i) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			String s = sc.next();
			String t = sc.next();
			
			if ( s.length() + 1 == t.length() && 
					t.substring(0, s.length()).contentEquals(s)) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
				
		}
	}

}

Measured memory_bytes: 35636
n_ten, n_r = map(int, input().split())
H = list(map(int, input().split()))
R = [list(map(int, input().split())) for i in range(n_r)]

bad=set()

for r in R:
    if H[r[0]-1]<=H[r[1]-1]:
        bad.add(r[0])
    if H[r[1]-1]<=H[r[0]-1]:
        bad.add(r[1])

print(n_ten-len(bad))

Measured memory_bytes: 33900
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>

int main(){
    using namespace std;
    constexpr double pi = boost::math::constants::pi<double>();
    unsigned long N, L;
    cin >> N >> L;
    vector<unsigned long> T(N);
    copy_n(istream_iterator<unsigned long>(cin), N, T.begin());
    double x{0}, y{0};
    vector<double> C(N), S(N);
    transform(T.begin(), T.end(), C.begin(), [&pi, &L](auto t){return cos(pi * t / L);});
    transform(T.begin(), T.end(), S.begin(), [&pi, &L](auto t){return sin(pi * t / L);});
    for(long i = 1; i < N; ++i)for(long j = 0; j < i; ++j){
        long t = N + 2 * (j - i);
        x += t * (C[i] * C[j] - S[i] * S[j]);
        y += t * (C[i] * S[j] + C[j] * S[i]);
    }
    unsigned long t = N * (N - 1) * (N - 2) / 6;
    x /= t;
    y /= t;
    cout << setprecision(15) << fixed << endl;
    cout << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();

		String s = "";

		// forth
		for (int ny = sy; ny < ty; ny++) {
			s += "U";
		}
		for (int nx = sx; nx < tx; nx++) {
			s += "R";
		}

		// back
		for (int ny = ty; ny > sy; ny--) {
			s += "D";
		}
		for (int nx = tx; nx > sx; nx--) {
			s += "L";
		}

		// forth again
		s += "L";
		for (int ny = sy; ny < ty + 1; ny++) {
			s += "U";
		}
		for (int nx = sx - 1; nx < tx; nx++) {
			s += "R";
		}
		s += "D";

		// back again
		s += "R";
		for (int ny = ty; ny > sy - 1; ny--) {
			s += "D";
		}
		for (int nx = tx + 1; nx > sx; nx--) {
			s += "L";
		}
		s += "U";

		System.out.println(s);
	}

}


Measured memory_bytes: 207044
n, m = map(int, input().split())
lst = [input() for _ in range(n)]

def check(lst, i, j, n, m):
    if n == 1:
        row_lst = [0]
    elif i == 0:
        row_lst = [i, i+1]
    elif i == n-1:
        row_lst = [i-1, i]
    else:
        row_lst = [i-1, i, i+1]
    if m == 1:
        col_lst = [0]
    elif j == 0:
        col_lst = [j, j+1]
    elif j == m-1:
        col_lst = [j-1, j]
    else:
        col_lst = [j-1, j, j+1]
    count = 0
    for a in row_lst:
        for b in col_lst:
            if lst[a][b] == '#':
                count += 1
    return count


for i in range(n):
    ans = ''
    for j in range(m):
        if lst[i][j] == '#':
            ans += '#'
        else:
            ans += str(check(lst, i, j, n, m))
    print(ans)            

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

int main()
{
  int abc[3], ma_p = 0, ma = 0;
  for (int i = 0; i < 3; i++) {
    cin >> abc[i];
    if (abc[i] > ma) {
      ma_p = i;
      ma   = abc[i];
    }
  }

  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (i == ma_p)
      ans += abc[i] * 10;
    else
      ans += abc[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	int a=n%10;
	if(a==2||a==4||a==5||a==7||a==9)
	{
		cout<<"hon";
	}
	if(a==0||a==1||a==6||a==8)
	{
		cout<<"pon";
	}
	if(a==3)
	{
		cout<<"bon";
	}
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include <string.h>



int main() {
	int i, j, k, l = 0;
	int m, g, n, q;
	int f = 0;
	int point[110000] = { 0 };
	int a;
	char we[100];


	scanf("%s", we);




	if (we[0]=='S') {
		printf("Cloudy");
	}
	else if(we[0] == 'C') {
		printf("Rainy");
	}
	else {
		printf("Sunny");
	}





//	printf("%d", f);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

using namespace std;

char kalimat[55];

int main(){
   int k,banyak,isi,i;
   scanf("%d", &k);
   getchar();
   scanf("%s", kalimat);
   getchar();
   isi=0;
   for(i=0;i<k;i++){
     // cout<<i<<endl;
   if(kalimat[i]=='A'){
      i++;
      if(kalimat[i]=='B'){
         i++;
         if(kalimat[i]=='C'){
            isi++;
         }
         else{
            i--;
         }
      }
      else{
         i--;
      }
   }
}
cout<<isi<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;


int main(){
	char buf[11];
	int array1[10],array2[10];

	while(scanf("%s",buf)!=EOF){
		for(int i=0;buf[i]!='\0';i++)array1[i] = buf[i] - '0';

		for(int i = 9; i >= 1; i--){
			if(i %2 == 1){
				for(int k = 0; k < i; k++){
					array2[k] = (array1[k] + array1[k+1])%10;
				}
			}else{
				for(int k = 0; k < i; k++){
					array1[k] = (array2[k] + array2[k+1])%10;
				}
			}
		}

		printf("%d\n",array2[0]);
	}

    return 0;
}

Measured memory_bytes: 2684
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<bits/stdc++.h>
/*#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>*/
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
 
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	 
	ll n , m ;
	cin >> n >> m ;
	ll ans = (n)*(n-1) ;
	ans /= 2 ;
	ans += (((m)*(m-1))/2 );
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str>>str2>>str3;
	cout<<(char)(str[0]-32)<<(char)(str2[0]-32)<<(char)(str3[0]-32);





	cout<<endl;
} 


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		
        int r = sc.nextInt();
        int d = sc.nextInt();
		int ans = 0;
        for(int i=l;i<=r;i++){if(i%d==0){ans++;
                                                 }
                            }
        
		System.out.println(ans);
	}
}


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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(double n){cout << n << endl;}

//main------------------------------------------------------------------------------------------


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

    int n, m; cin >> n >> m;
    vector<vector<int> > edges(n,vector<int>());

    rep(i,0,m){
        int f,t; cin >> f >> t; f--; t--;
        edges[f].push_back(t);
        edges[t].push_back(f);
    }

    rep(i,0,n){
        cout << edges[i].size() << endl;
    }
    
    
}

Measured memory_bytes: 256
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

Measured memory_bytes: 107108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long m = sc.NextLong();

        List<Tuple<long, long>>[] citys = new List<Tuple<long, long>>[n];
        long[] pref = new long[m];
        long[] year = new long[m];
        long[] order = new long[m];
        for (long i = 0; i < n; i++)
        {
            citys[i] = new List<Tuple<long, long>>();
        }
        for (long i = 0; i < m; i++)
        {
            long p = sc.NextLong();
            long y = sc.NextLong();
            citys[p - 1].Add(Tuple.Create(i, y));
            pref[i] = p - 1;
            year[i] = y;
        }
        for (long i = 0; i < n; i++)
        {
            List<Tuple<long, long>> sortedList = citys[i].OrderBy(item => item.Item2).ToList();
            for (int j = 0; j < sortedList.Count; j++)
            {
                var item = sortedList[j];
                order[item.Item1] = j;
            }
        }

        for (long i = 0; i < m; i++)
        {
            var p = pref[i];
            var o = order[i];

            string answer = (p + 1).ToString().PadLeft(6, '0') + (o + 1).ToString().PadLeft(6, '0');
            Console.WriteLine(answer);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 61164
a = []
i = 0

d = 0

s = int(input())

a.append(s)

while d != 1:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(i + 2)
            d = 1
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(i + 2)
            d = 1
        a.append(anss)

    i += 1

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	int C, N; cin >> C >> N; C--;
	vector<string> p(N);
	for (int i = 0; i < N; ++i) cin >> p[i];
	vector<vector<bool> > ch(N / 2, vector<bool>(N / 2));
	int cnt = 0, ans = 0;
	for (int i = 0; i < N / 2; ++i)
		for (int j = 0; j < N / 2; ++j)
			if (p[i][j] == p[N - i - 1][N - j - 1] && p[i][j] == p[N - i - 1][j] && p[i][j] == p[i][N - j - 1])
				ch[i][j] = true, cnt++;
	if (N * N / 4 == cnt) ans++;
	while (C--) {
		int d; cin >> d;
		while (d--) {
			int r, c; cin >> r >> c; r--, c--;
			p[r][c] = (p[r][c] == '1' ? '0' : '1');
			if (r >= N / 2) r = N - r - 1;
			if (c >= N / 2) c = N - c - 1;
			if (p[r][c] == p[N - r - 1][N - c - 1] && p[r][c] == p[N - r - 1][c] && p[r][c] == p[r][N - c - 1]) {
				if (!ch[r][c]) ch[r][c] = true, cnt++;
			} else if (ch[r][c]) ch[r][c] = false, cnt--;
		}
		if (N * N / 4 == cnt) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4000
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a;
	map<int,int> mp;
	for(int i = 0;i<n; i++)
	{
		 cin>>a;
		 mp[a]++;
	}
	ll cnt = 0;
	for(int i =0 ;i <=100001; i++)
		cnt = max(cnt,(ll)(mp[i-1]+mp[i]+mp[i+1]));
	cout<<cnt<<endl;	
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<ll> x(n), y(n), z(n);
    for (auto i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    
    ll maxScore = 0;
    for (auto k = 0; k < 8; k++) {
        vector<ll> sums(n, 0);
        for (auto i = 0; i < n; i++) {
            if (k % 2 == 0) {
                sums[i] += x[i];
            } else {
                sums[i] -= x[i];
            }
            if (k % 4 < 2) {
                sums[i] += y[i];
            } else {
                sums[i] -= y[i];
            }
            if (k < 4) {
                sums[i] += z[i];
            } else {
                sums[i] -= z[i];
            }
        }
        sort(sums.begin(), sums.end());
        ll score = 0;
        for (auto i = 0; i < m; i++)
            score += sums[n - i - 1];
        maxScore = max(maxScore, score);
    }
    cout << maxScore << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int f[1111];
int g[2][5005];
int fa[1111];
int x[1111];
struct edge
{
	int to;
	int next;
}e[2222];
int pe=1111;
void insert(int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
}
int main()
{
	//freopen("E.in","r",stdin);
	//freopen("E.out","w",stdout);
	int n=io::F();
	for(register int i=2;i<=n;++i)fa[i]=io::F(),insert(fa[i],i);
	for(register int i=1;i<=n;++i)x[i]=io::F();
	for(register int i=n;i;--i)
	{
		memset(g,63,sizeof(g));
		g[0][0]=0;
		int *X=g[0],*Y=g[1];
		for(register int p=e[i].next;p;p=e[p].next,std::swap(X,Y),memset(Y,63,sizeof(g[0])))
			for(register int j=0;j<=5000;++j)
			{
				if(j>=x[e[p].to])cmin(Y[j],X[j-x[e[p].to]]+f[e[p].to]);
				if(j>=f[e[p].to])cmin(Y[j],X[j-f[e[p].to]]+x[e[p].to]);
			}
		f[i]=0x3f3f3f3f;
		for(register int j=0;j<=x[i];++j)cmin(f[i],X[j]);
		if(f[i]==0x3f3f3f3f){puts("IMPOSSIBLE");return 0;}
	}
	puts("POSSIBLE");
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, BufWriter, Read, Write};
use std::usize;
use std::fmt::Write as _Write;

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}


fn count_components_unordered(g: &[Vec<usize>]) -> usize {
    let mut seen = HashSet::new();
    let mut ret = 0;
    let mut stack = vec![0];
    let n = g.len();
    for i in 0..n {
        if seen.contains(&i) {
            continue;
        }
        stack.clear();
        stack.push(i);
        while let Some(i) = stack.pop() {
            for &c in &g[i] {
                if !seen.contains(&c) {
                    stack.push(c);
                    seen.insert(c);
                }
            }
        }
        ret += 1;
    }
    ret
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize);
    let mut g = vec![vec![];n];
    for _ in 0..m {
        parse!(it, x: u1, y:u1);
        g[x].push(y);
        g[y].push(x);
    }
    let c = count_components_unordered(&g);
    println!("{}", c-1);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}
trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}



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

#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;
ll B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;

signed main() {

    std::cin >> N >> K;
    std::vector<int> A(N);
    std::vector<int> S(N);

    for (ll i = 0; i < N; i++) {
        std::cin >> A[i];
        S[i] = 0;
    }
    ll counter = 1;
    ll now = 0;
    ll k = 0;
    while (k == 0) {
        now = A[now] - 1;
        if (S[now] != 0) {
            k = counter - S[now];
        } else {
            S[now] = counter;
            counter++;
        }
    }
    ll noww = 0;
    while (noww != now) {
        noww = A[noww] - 1;
        K--;
        if (K == 0) {
            cout << noww + 1 << endl;
            return 0;
        }
    }
    K = K % k;
    if (K != 0) {
        for (ll i = 0; i < K; i++) {
            now = A[now] - 1;
        }
    }
    if (A[0] == 1)
        std::cout << "1" << std::endl;
    else
        std::cout << now + 1 << std::endl;
}


Measured memory_bytes: 4844