akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const int mod = 1e5;
const int MAX = 1e7;

int main() {
    int n; cin >> n;
    int sum = 0;
    rep(i,n) {
        int a; cin >> a;
        sum += a-1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, x;
	cin >> a >> b >> x;
	bool ans = x >= a && x <= (a + b);
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
#define Puts(b) cout<<(b? "Yes":"No")<<endl
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  string s;
  cin >> s;
  rep(i, 0, 3) {
    if(s[i] == '1') cout << '9';
    else cout << '1';
  }
  cout << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> ans(4,0);
  for(int i=0; i<n; ++i){
    string s;
    cin >> s;
    if(s == "AC") ++ans[0];
    else if(s == "WA") ++ans[1];
    else if(s == "TLE") ++ans[2];
    else if(s == "RE") ++ans[3];
  }
  printf("AC x %d\n", ans[0]);
  printf("WA x %d\n", ans[1]);
  printf("TLE x %d\n", ans[2]);
  printf("RE x %d\n", ans[3]);
}

Measured memory_bytes: 3720
/*
  B - Good Distance
  D次元空間上にN個の点があります。
  i番目の点とj番目の点の距離が整数となるような
  組(i,j)(i<j)はいくつあるでしょうか？
 */

 import java.util.*;

 public class Main{
   public static void main(String[]args){
     Scanner sc=new Scanner(System.in);
     while(sc.hasNext()){
       int n=sc.nextInt();
       int d=sc.nextInt();
       int x[][]=new int[n][d];

       for(int s=0;s<n;s++){
         for(int k=0;k<d;k++){
           x[s][k]=sc.nextInt();
         }
       }

       int count=0;
       int total=0;
       int ans=0;
       double ans2=0;

       for(int k=0;k<n-1;k++){
         for(int l=k+1;l<n;l++){
            total=0;
           for(int s=0;s<d;s++){
             total+=Math.pow(x[k][s]-x[l][s],2);
           }
           ans=(int)Math.sqrt(total);
           ans2=Math.sqrt(total);
           if(ans==ans2){
             count++;
           }
         }
       }


       System.out.println(count);
     }
   }
 }


Measured memory_bytes: 21844
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d %d %.5lf\n", a / b, a%b, (double)a / b);
	return 0;
}

Measured memory_bytes: 2724
def myAnswer(N:int,A:list) -> int:
   Alice = 0
   Bob = 0
   A.sort(reverse=True)
   for n,a in enumerate(A):
      if (n%2 == 0):
         Alice += a
      else:
         Bob += a
   return Alice - Bob

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


void dfs(const vector<vector<P> >& g, vector<ll>& dist, ll k, ll sum){
        if(dist[k]!=-1){return;}
	dist[k]=sum;
	for(auto i : g[k]){
		dfs(g, dist, i.first , sum+i.second);
    }
}


int main(){
	int n; cin >> n;
	vector<vector<P> >g(n);
	for(int i = 0; i < n-1; ++i){
		ll a,b,c; cin >>a >>b>>c;
--a, --b;
                g[a].push_back({b,c});
		g[b].push_back({a,c});
    }
    
    ll q,k; cin >>q>>k; --k;
    vector<ll> dist(n, -1);
    dfs(g, dist, k, 0);
   
    for(int i = 0; i < q; ++i){
    	ll x,y;cin >>x>> y;
--x, --y;
        cout << dist[x]+dist[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 14336
from collections import deque
f=lambda:map(int,input().split())
r=range
n,m,k=f()
F=[deque([])for _ in r(n)]
A=[0]*n
B=[-1]*n
C=[-1]*n
Q=deque([])
for _ in r(m):a,b=f();a-=1;b-=1;F[a].append(b);F[b].append(a);A[a]+=1;A[b]+=1
for i in r(n):
  Q.append(x:=i)
  y=0
  while Q:
    z=Q.popleft()
    if B[z]>-1:continue
    B[z]=x
    Q.extend(F[z])
    y+=1
  C[x]=y
D=[[B[i],C[B[i]]-A[i]-1]for i in r(n)]
for _ in r(k):
  c,d=f()
  c,d=c-1,d-1
  if D[c][0]==D[d][0]:D[c][1]-=1;D[d][1]-=1
print(*[d[1] for d in D])
  

Measured memory_bytes: 96200
n=int(input())
s=[0,0]
for i in range(n):
    t, h = input().strip().split()
    if t>h:
        s[0] += 3
    elif t<h:
        s[1] += 3
    else:
        s[0] += 1
        s[1] += 1
print(*s)

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

int main() {
  int A,B,C,k; //A=1の枚数,B=0の枚数,C=-1の枚数,kは選ぶカードの枚数
  cin >> A >> B >> C >> k;
  
  if(k > A){ //1の計算
    A = A * 1;
    k = k - A;  
    //cout << "A " << A << endl;
    
    if(k > B){ //0の計算
      k = k - B;
      B = B * 0;
      
      if(k <= C){//－１の計算
        C = k*(-1);
        //cout << C << endl;
      }else if(k > C){
        C = C*(-1);
        //cout << "C " << C  << endl;
      }
      
    }else if(k <= B){
      B = B * 0;
      C = C * 0;
      //cout << B << endl;
    }
    
  }else if(k < A){
    A = k;
    B = B * 0;
    C = C * 0;
    //cout << A << endl;    
  }else if(k == A){
    //cout << A << endl;
    B = B * 0;
    C = C * 0;
  }else{
    A = A*0;B = B*0;C = C*0;
  }
  
  cout << A + B + C << endl;
  
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;

  vector<int> V(N);
  rep(i, N) cin >> V[i];
  vector<int> C(N);
  rep(i, N) cin >> C[i];

  int sum = 0;
  rep(i, N)
  {
    if (V[i] - C[i] > 0)
      sum += V[i] - C[i];
  }

  cout << sum << 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 n,s,count;
		int r[];
		while(true){
			n=sc.nextInt();
			s=sc.nextInt();
			if(n+s==0) break;
			count=0;
			r=new int[n];
			for(int i=0;i<n;i++){
				r[i]=sc.nextInt();
			}
			
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					if(r[i]+r[j]>s){
						count++;
					}
				}
			}
			System.out.println(count);
		}

	}

}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

const int limit=100010;
int num[limit];

int main(void){
	int n;
	cin >> n;

	rep(i,n){
		int in;
		cin >> in;
		num[in]++;
	}

	int ans=0,even=0;
	rep(i,limit){
		if(num[i]==0) continue;
		if(num[i]&1) 
			ans++;
		else
			even++;
	}

	ans+=even/2*2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N, K;
    cin >> N >> K;
    int x[100];
    int ans=0;
    rep(i,N) cin >> x[i];
    for(int i=0; i<N; i++){
        int tmpa = x[i]*2;
        int tmpb = (K-x[i])*2;
        if(tmpa<tmpb){
            ans += tmpa;
        }else{
            ans += tmpb;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>void reg(vector<T> &ary,const T &elem){ary.emplace_back(elem);}
template<class T>bool chmin(T &a, const T &b) {return (b<a)?(a=b,1):0;}
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}

using R=long double; // __float128
const R EPS = 1E-14; // [-1000:1000]->EPS=1e-8 [-10000:10000]->EPS=1e-7
const R INF = 1E40;
constexpr R PI = acos(R(-1));
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}
inline int sgn(const R& a, const R &b){ return sgn(a-b); }
inline R sq(R x){return sqrt(max<R>(x,0.0));}

using P=complex<R>;
using VP=vector<P>;
using L=struct{P s,t;};
using VL=vector<L>;

constexpr P O = P(0,0);
istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}


inline R dot(P o,P a,P b){a-=o,b-=o; return real(conj(a)*b);}
inline R det(P o,P a,P b){a-=o,b-=o; return imag(conj(a)*b);}

P cross(L a,L b){
	R s1=det(a.s,b.s,b.t);
	R s2=s1+det(a.t,b.t,b.s);
	return a.s+s1/s2*(a.t-a.s);
}

VP convex_cut(const VP& pol,const L& l) {
	VP res;
	int n=pol.size();
	rep(i,n){
		P a = pol[i],b=pol[(i+1)%n];
		if(det(l.s,l.t,a)>=0) reg(res,a);
		if(det(l.s,l.t,a)*det(l.s,l.t,b)<0) reg(res,cross({a,b},l));
	}
	return res;
}

R area(const VP& pol){
	int n=pol.size();
	R sum=0;
	rep(i,n) sum+=det(O,pol[i],pol[(i+1)%n]);
	return abs(sum/2.0);
}

bool check(VP pol,R len){
	int n=pol.size();
	VL lines(n);

	rep(i,n){
		P e=(pol[(i+1)%n]-pol[i])/abs(pol[(i+1)%n]-pol[i])*P(0,1);
		lines[i]=L({pol[i]+e*len,pol[(i+1)%n]+e*len});
	}

	VP cur=pol;
	rep(i,n) cur=convex_cut(cur,lines[i]);
	return sgn(area(cur));
}

int main(void){
	int n;
	while(cin >> n,n){
		VP pol(n);
		rep(i,n) cin >> pol[i];

		R lb=0.0,ub=20000.0;

		rep(loop,200){
			const R mid=(lb+ub)/2.0;
			if(check(pol,mid))
				lb=mid;
			else
				ub=mid;
		}

		cout.precision(20);
		cout << fixed << lb << endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  int vi = 1;
  for(int i=0; i<N; i++){
    if(A[i]%2==1){
      vi*=1;
    }else{
      vi*=2;
    }
  }
  cout << (int)pow(3,N)-vi << endl;
  return 0;
}

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

#define ll   long long int
#define PI 3.14159265358979
#define zig ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;


int main()
{
    zig
    int a, b, h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2;
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[100];
map<char,int>mp[100];
map<char,int>::iterator it;

int main()
{

    int n,c=0,d=0;
    char ch;
    string s,s1;
    cin>>n;

    for (int i=0; i<n; i++ )
    {
     cin>>s;
     if(i==0){s1=s;}
     for(int j=0;j<s.length();j++)
     {
         mp[i][s[j]]++;
     }

    }
    for(it=mp[0].begin();it!=mp[0].end();++it)
    {
       ch=it->first;
       d=it->second;
       for(int i=1;i<n;i++)
       {
           c=mp[i][ch];
           if(d>c){d=c;}

       }
       for(int j=0;j<d;j++)
       {
           cout<<ch;
       }
    }
}


Measured memory_bytes: 3516
def calc(s,num)
  if num == 0
    arr = s.split('+')
    sum = 0
    arr.each do |a|
      sum += a.to_i
    end
    
    return sum
    
  end
  
  return calc(s.clone.insert(num,'+'),num-1) + calc(s,num-1)
  
end

s = gets.chomp

num = s.size()

puts calc(s,num-1)

Measured memory_bytes: 3836
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < M; i++) {
            sum += sc.nextInt();
        }
        int result = N - sum;
        if (result < 0) {
            result = -1;
        }
        System.out.println(result);
        sc.close();
    }
}

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

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

	int q, com, i;
	bitset<64> bs;
	bs.reset();

	cin >> q;
	while (q--) {
		cin >> com;
		switch (com) {
			case 0:
				cin >> i;
				cout << bs.test(i) << endl;
				break;
			case 1:
				cin >> i;
				bs.set(i);
				break;
			case 2:
				cin >> i;
				bs.reset(i);
				break;
			case 3:
				cin >> i;
				bs.flip(i);
				break;
			case 4:
				cout << (bs.all() ? 1 : 0) << endl;
				break;
			case 5:
				cout << (bs.any() ? 1 : 0) << endl;
				break;
			case 6:
				cout << (bs.none() ? 1 : 0) << endl;
				break;
			case 7:
				cout << bs.count() << endl;
				break;
			case 8:
				cout << bs.to_ulong() << endl;
		}
	}
}


Measured memory_bytes: 3224
N, K = (int(i) for i in input().split())
N += 1
l1 = []
l2 = []
n_ma = 0
for i in range(1, N):
    j = (N-1)//(i+1) + 1
    if i > j:
        break
    elif i == j:
        l1.append(i)
        break
    l1.append(i)
    l2.append(j)
l2.reverse()
L = l1 + l2 + [N]
M = len(L) - 1
DP = [[0] * (M+1) for counter1 in range(K+1)]

def BIT_query(BIT, idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(BIT, idx, x):
    while idx <= M:
        BIT[idx] += x
        idx += idx&(-idx)
    return

def BIT_debug(BIT):
    return [BIT_query(BIT, i) - BIT_query(BIT, i-1) for i in range(1, M+1)]

MOD = 10**9 + 7
for i in range(M):
    BIT_update(DP[1], i+1, L[i+1]-L[i])
for i in range(1, K):
    for j in range(M):
        x = BIT_query(DP[i], M-j)
        x *= L[j+1]-L[j]
        x %= MOD
        BIT_update(DP[i+1], j+1, x)

print(BIT_query(DP[K], M)%MOD)

Measured memory_bytes: 93648
import java.util.*;
import java.io.*;
class Main {
    static long MOD = (long)(1e9+7);
    static long[][] multiply(long[][] a, long[][] b) {
        int n = a.length;
        long[][] res = new long[n][n];
        for(int i = 0; i<n; i++) {
            for(int j = 0; j<n; j++) {
                for(int k = 0; k<n; k++) {
                    res[i][k] = (res[i][k] + (a[i][j]%MOD * 1l * b[j][k]%MOD)%MOD)%MOD;
                }
            }
        }
        return res;
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[][] graph = new long[n][n];
        for(int i = 0; i<n; i++)
            for(int j = 0; j<n; j++)
                graph[i][j] = sc.nextLong();
        long[][] res = new long[n][n];
        for(int i = 0; i<n; i++)
            res[i][i] = 1l;
        while(k>0) {
            if(k%2==1)
                res = multiply(res, graph);
            graph = multiply(graph, graph);
            k/=2;
        }
        long ans = 0;
        for(int i = 0; i<n; i++) {
            for(int j = 0; j<n; j++)
                ans = (ans+res[i][j])%MOD;
        }
        System.out.println(ans);
    }
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<c;i++){
		if(i%2==0){
			a=a/2;
			b+=a;
		}else{
			b=b/2;
			a+=b;
		}
	
	}
	cout<<a<<' '<<b;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    char c;
    cin >> c;
    cout << (char)(c+1) << endl;


  
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

long long pow_m(ll x, ll a, ll mod){
	if(a == 0) return 1;
	ll res = pow_m(x*x%mod, a/2, mod);
	if(a % 2 == 1)
		res = res * x %  mod;
	return res;
}

int main(void){
	int n;
	int sz[100000];
	cin >> n;
	fill(sz, sz+100000, 0);
	REP(i, n){
		int a;
		cin >> a;
		sz[a/2]++;
	}
	if(n%2 == 1) sz[0]++;
	REP(i, n/2){
		if(sz[i] % 2){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << pow_m(2, n/2, 1000000007) << endl;
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    ios::sync_with_stdio(false);

    START:

    int n;
    int a = 0;
    int b = 0;
    cin >> n;
    if(n == 0) return 0;
    for(int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        if(x > y){
            a += x + y;
        }
        else if(x < y){
            b += x + y;
        }
        else{
            a += x;
            b += y;
        }
    }
    cout << a << " " << b << endl;

    goto START;

    return 0;
}



Measured memory_bytes: 3128
#abc097 b bekijousu
import math

def large_num(n):
    xx=x/n
    p=1
    while xx-n**p>=0:
        p+=1
    if p==1:
        return 0
    else:
        return n**p

x=int(input())
b_last=int(math.sqrt(1000))
num=[i for i in range(2,b_last+1)]

ans=0


if 4>x:
    ans=1
else:
    for i in num:
        ans=max(large_num(i),ans)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    map<int,int> e,o;
    REP(i,n) {
        int x; cin >> x;
        if (i % 2 == 0) e[x]++;
        else o[x]++;
    }

    int e1,e2,o1,o2;
    e1=e2=o1=o2 = 0;
    int eidx, oidx;

    for (auto m: e) {
        if (e1 < m.second) {
            e2 = e1;
            e1 = m.second;
            eidx = m.first;
        } else if (e2 < m.second){
            e2 = m.second;
        }
    }
    for (auto m: o) {
        if (o1 < m.second) {
            o2 = o1;
            o1 = m.second;
            oidx = m.first;
        } else if (o2 < m.second){
            o2 = m.second;
        }
    }

    if (eidx == oidx) {
        if (e1 == o1) {
            if (e2 < o2) o1 = o2;
            else e1 = e2;
        } else if (e1 < o1) e1 = e2;
        else o1 = o2;
    }

    int ans = n - o1 - e1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
	string in;
	for(;;){
		cin >> in;
		if(in.at(0)=='0'){
			break;
		}

		int sum = 0;
		for(int i=0; i<in.length(); i++){
			sum += (in.at(i)-'0');
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
n = int(input())
s = str(input())
r = 0
g = 0
b = 0

for i in range(n):
  if s[i] == 'R':
  	r += 1
  elif s[i] == 'G':
  	g += 1
  else:
  	b += 1

ans = r * g * b

for i in range(n):
  for j in range(n):
    if 2 * j + i < n and s[i] != s[i + j] and s[i] != s[2 * j + i] and s[i + j] != s[2 * j + i]:
      ans -= 1
print(ans)

Measured memory_bytes: 67924
#include <stdio.h>
#include <string.h>

void flip(int clm, int x, int row[][10000])
{
    int i;
    
    for (i = 0; i < x; i++){
        row[clm][i] ^= 1;
    }
}
int main(void)
{
    static int row[10][10000];
    static int temp[10][10000];
    int x, y;
    int i, j, k;
    int black, white, count, ans;
    
    while (1){
        scanf("%d%d", &y, &x);
        
        if (x + y == 0){
            break;
        }
        
        for (i = 0; i < y; i++){
            for (j = 0; j < x; j++){
                scanf("%d", &row[i][j]);
            }
        }
        
        ans = 0;
        for (i = 0; i < 1 << y; i++){
            memcpy(temp, row, sizeof(row));
            for (j = 0; j < y; j++){
                if ((i >> j) & 1 == 1){
                    flip(j, x, temp);
                }
            }
            
            count = 0;
            for (j = 0; j < x; j++){
                black = white = 0;
                for (k = 0; k < y; k++){
                    if (temp[k][j] == 1){
                        black++;
                    }
                    else {
                        white++;
                    }
                }
                count += (black > white) ? black : white;
            }
            
            ans = (ans > count) ? ans : count;
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 1196
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned int uint;

mt19937 rnd(random_device{}());

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));
    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= x) {
            x -= a[i];
            ++res;
        }
    }
    if (x != 0 && res == n) {
        --res;
    }
    cout << res << endl;
}

Measured memory_bytes: 892
n = int(input())
s= 0
not_10 = 100000
for _ in range(n):
    a = int(input())
    s+=a
    if a%10:
        not_10 = min(a,not_10)
if s%10:
    print(s)
else:
    print(max(0,s-not_10))

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;


int main(){
	
	int m;
	int n;
	
	cin>>m>>n;
	
	
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		
		a--;
		b--;
		
		
		int x = min(a,m-a-1);
		int y = min(b,m-b-1);
		
		int t = min(x,y)%3;
		
		printf("%d\n",t+1);
	}
	
}

Measured memory_bytes: 1144
package main

import "fmt"

func main() {
	var s string
	var t string

	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	count := 0
	for i := 0; i < 3; i++ {
		if s[i] == t[i] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string color;
  string result = "Three";
  for(int i = 0; i < N; i++){
    cin >> color;
    if(color == "Y"){
      result = "Four";
      break;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
	fastio;
	// #ifndef ONLINE_JUDGE 
	//     freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);
	// #endif
	ll n=0;
	cin>>n;
	ll ar[n][3]={0};
	for(ll i=0;i<n;++i){
		for(ll j=0;j<3;++j){
			cin>>ar[i][j];
		}
	}
	ll dp[n][3];
	dp[0][0]=ar[0][0];
	dp[0][1]=ar[0][1];
	dp[0][2]=ar[0][2];
	for(ll i=1;i<n;++i){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+ar[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+ar[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+ar[i][2];
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   return 0;
}

Measured memory_bytes: 4992
#include<cctype>
#include<cstdio>


using namespace std;

int main()
{
	char a;
	while (1)
	{
		a = getchar();
		if (islower(a))
		{
			putchar(toupper(a));
		}
		else
		{

			putchar(tolower(a));
		}
		if (a == '\n') break;
	}
	return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

long long dp[1001][1001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    char cur;
    int h, w; cin >> h >> w;

    dp[1][0] = 1;

    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j){
            cin >> cur;
            if(cur == '#') continue;
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
        }
    }

    cout << dp[h][w] << "\n";

    return 0;

}


Measured memory_bytes: 8064
package main

import "fmt"

func main() {
	var n, a, b, c int
	out := 0
	fmt.Scanf("%d", &n)
	A := make([]int, n)
	B := make([]int, n)
	C := make([]int, n-1)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		A[i] = a
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b)
		B[i] = b
	}
	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &c)
		C[i] = c
	}

	for i := 0; i < n; i++ {
		out += B[A[i]-1]
		if i < n-1 {
			if A[i+1] == A[i]+1 {
				out += C[A[i]-1]
			}

		}
	}

	fmt.Println(out)
}


Measured memory_bytes: 512
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A.sort()
_max = A[-1]
_min = A[0]
C = Counter(A)
odd = 0
even = 0
for v in C.values():
    if v % 2:
        odd += 1
    else:
        even += 1
ans = odd + (even//2)*2
print(ans)


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

using namespace std;

int main()
{
    //freopen("inp.in", "r", stdin);
    int A, B;
    scanf("%d %d", &A, &B);
    vector< vector<int> > constraints(A+1, vector<int>(B+1,-1));
    for(int i=1; i<=A; i++)
    {
        for(int j=1; j<=B; j++)
        {
            scanf("%d", &constraints[i][j]);
        }
    }
    int nb_nodes=202;
    vector< vector<int> > adjacency_matrix(nb_nodes, vector<int>(nb_nodes, -1));
    for(int i=1; i<=A; i++)
    {
        for(int j=1; j<=B; j++)
        {
            int use1=-1;
            int use2=-1;
            for(int k1=0; k1<=100 && use1==-1; k1++)
            {
                for(int k2=0; k2<=100 && i*k1+j*k2 <= constraints[i][j] && use1==-1; k2++)
                {
                    bool ok=true;
                    int t=constraints[i][j]-i*k1-j*k2;
                    for(int l=1; l<=A && ok; l++)
                    {
                        for(int m=1; m<=B && ok; m++)
                        {
                            if(!(k1*l+k2*m+t >= constraints[l][m])) ok=false;
                        }
                    }
                    if(!ok) continue;
                    use1=k1;
                    use2=k2;
                }
            }
            //cerr << use1 << " " << use2 << endl;
            if(use1==-1)
            {
                printf("Impossible\n");
                return 0;
            }
            int t=constraints[i][j]-i*use1-j*use2;
            adjacency_matrix[use1][201-use2]=t;
        }
    }
    int extra=0;
    for(int i=0; i<nb_nodes; i++)
    {
        for(int j=0; j<nb_nodes; j++)
        {
            if(adjacency_matrix[i][j] != -1) extra++;
        }
    }
    printf("Possible\n");
    printf("202 %d\n", 200+extra);
    for(int i=0; i<=99; i++)
    {
        printf("%d %d X\n", i+1, i+2);
    }
    for(int i=101; i<=200; i++)
    {
        printf("%d %d Y\n", i+1, i+2);
    }
    for(int i=0; i<nb_nodes; i++)
    {
        for(int j=0; j<nb_nodes; j++)
        {
            if(adjacency_matrix[i][j] != -1)
            {
                printf("%d %d %d\n", i+1, j+1, adjacency_matrix[i][j]);
            }
        }
    }
    printf("%d %d\n", 1, 202);
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int main(){
	int in;
	int h, m, s;
	scanf("%d", &in);

	h = in / 3600;
	in %= 3600;

	m = in / 60;
	in %= 60;

	s = in;

	printf("%d:%d:%d\n", h, m, s);
}




Measured memory_bytes: 2744
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int n, d;
int p[11][11], dp[11][111111];
int day;

int solve(int i, int j)
{
	if (dp[i][j] >= 0) return dp[i][j];
	if (i == n) return j;
	int res;
	if (p[day][i] > j) res = solve(i+1, j);
	else res = max({ solve(i + 1,j),solve(i + 1,j - p[day][i]) + p[day + 1][i],solve(i,j - p[day][i]) + p[day + 1][i] });
	return dp[i][j] = res;
}

int main()
{
	int x;
	cin >> n >> d >> x;
	MS(dp, 0);
	REP(i, d)REP(j, n) cin >> p[i][j];
	for (day = 0; day < d - 1;day++)
	{
		MS(dp, -1);
		x = solve(0, x);
	}
	cout << x << endl;
	return 0;
}

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

int p2[100005];
int p1[100005];

int main(){

    string s, t;
    cin >> s >> t;
    int n = s.size();
    for(int i=1; i<=n; i++){
        p1[i] = p1[i-1] + 1;
        if(s[i-1] == 'A') p1[i]++;
    }
    n = t.size();
    for(int i=1; i<=n; i++){
        p2[i] = p2[i-1] + 1;
        if(t[i-1] == 'A') p2[i]++;
    }
    int q;
    cin >> q;
    while(q--){
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int a = (p1[r1] - p1[l1-1])%3;
        int b = (p2[r2] - p2[l2-1])%3;
        if(a == b){
            cout << "YES\n";
        }
        else cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 1792
def main():
    n, k = map(int, input().split())
    a = [int(v) - 1 for v in input().split()]
    path_to_idx = {}
    path = []
    current_node = 0
    while True:
        path.append(current_node)
        path_to_idx[current_node] = len(path_to_idx)
        if path_to_idx.get(a[current_node]) is not None:
            cyclic = path_to_idx[a[current_node]]
            break
        current_node = a[current_node]

    if k < len(path):
        print(path[k]+1)
    else:
        k -= cyclic
        k %= (len(path) - cyclic)
        print(path[cyclic+k]+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39200
N, M = map(int, input().split())

es = []
for i in range(M):
    a,b,c = map(int, input().split())
    es.append((a-1, b-1, c))

INF = float("inf")
d = [INF] * N
d[0] = 0
"""
最大経路探索的な問題
よくあるベルマンフォード法なら、コストが正の値で、負の閉路が見つかったら失敗、という形で最小経路を求めることになる。
今回は最長経路なので、正の閉路が求まったら失敗にしたい。
なので
・コストを負の値でもつ。表示するときに正に変える
・コストを負にするので閉路を見つけられる
みたいな形にする
"""

def solve(start):
    for i in range(N):
        for a,b,c, in es:
            if d[a] != INF and d[a] + (-c) < d[b]:
                d[b] = d[a] + (-c)
                # 最後まで確認しても更新されたら閉路あり
                if i == N-1 and b == N-1:
                    return "inf"

    return -1*d[-1]

print(solve(0))

Measured memory_bytes: 3296
def back_and_forth(sx: int, sy: int, tx: int, ty: int)->int:
    dx, dy = tx - sx, ty - sy
    forth = ('U' * dy) + ('R' * dx)
    back = ('D' * dy) + ('L' * dx)
    first = forth + back
    second = 'LU' + forth + 'RD' + 'RD' + back + 'LU'

    return first + second


if __name__ == "__main__":
    sx, sy, tx, ty = map(int, input().split())
    ans = back_and_forth(sx, sy, tx, ty)
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <set>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong a,b; cin>>a>>b;
    string ans="Positive";
    if(a<0&&b>0) ans="Zero";
    else if(a>0) ans="Positive";
    else if(a<0&&b>0){
        if((0-a)%2!=0) ans="Negative";
        }
    else
        {
        if((b-a)%2==0) ans="Negative";
        }
    cout<<ans<<endl;
    return  0;
}


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

using namespace std;

int X, Y;
int MapData[15][15];
int DpCount[16][15];

void solve() {
	int col, sum;
	int dx[] = { -1,0,1 };

	memset(DpCount, 0, sizeof(DpCount));
	for (int j = 0; j < X; ++j) {
		if (MapData[Y - 1][j] == 1) {
			continue;
		}
		DpCount[Y - 1][j] = 1;
	}

	for (int i = Y - 2; i >= 0; --i) {
		for (int j = 0; j < X; ++j) {
			if (MapData[i][j] == 1) {
				continue;
			}

			if (MapData[i][j] == 2) {
				if (i == Y - 2) {
					DpCount[i][j] = 1;
				}
				else {
					DpCount[i][j] = DpCount[i + 2][j];
				}
				continue;
			}

			sum = 0;
			for (int k = 0; k < 3; ++k) {
				col = j + dx[k];
				if (col < 0 || col > X - 1) {
					continue;
				}
				if (k != 1 && MapData[i + 1][col] == 2) {
					continue;
				}
				sum += DpCount[i + 1][col];
			}
			DpCount[i][j] = sum;
		}
	}

	sum = 0;
	for (int j = 0; j < X; ++j) {
		sum += DpCount[0][j];
	}
	cout << sum << endl;
}

int main() {

	while (cin >> X >> Y, X) {
		for (int i = 0; i < Y; ++i) {
			for (int j = 0; j < X; ++j) {
				cin >> MapData[i][j];
			}
		}
		solve();
	}

	return 0;
}


Measured memory_bytes: 3012
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 3000;
char S[2*MAXN + 5];
int a[MAXN + 5], b[MAXN + 5], c[2*MAXN + 5];
int dp[MAXN + 5][MAXN + 5];
int N, A, B;
string fun(int num[]) {
	string ret = "";
	for(int i=1;i<=2*N;i++)
		if( num[c[i]] ) ret.insert(ret.end(), S[i]);
	return ret;
}
int main() {
	scanf("%d", &N);
	scanf("%s", S+1);
	for(int i=1;i<=2*N;i++) {
		if( S[i] == 'a' ) {
			a[++A] = i;
			c[i] = A;
		}
		else {
			b[++B] = i;
			c[i] = B;
		}
	}
	dp[N][N] = 1;
	for(int i=N-1;i>=1;i--) {
		dp[i][i] = 1;
		if( a[i] < b[i] ) {
			int Max = 0;
			for(int j=a[i];j<=b[i];j++) {
				if( c[j] < i ) continue;
				Max = max(Max, c[j]);
			}
			for(int j=b[i]+1;j<=2*N;j++)
				if( c[j] > Max )
					dp[i][c[j]] = dp[Max+1][c[j]];
		}
		else {
			int tot = 0, Max = 0;
			for(int j=b[i];j<=a[i];j++) {
				if( c[j] < i ) continue;
				if( c[j] != i ) tot++;
				Max = max(Max, c[j]);dp[i][c[j]] = 1;
			}
			for(int j=a[i]+1;j<=2*N;j++) {
				if( S[j] == 'b' ) {
					if( tot == 0 ) {
						dp[i][c[j]] = dp[Max+1][c[j]];
					}
					else {
						dp[i][c[j]] = 1;
						tot++;
					}
				}
				else {
					if( tot == 0 ) {
						dp[i][c[j]] = dp[Max+1][c[j]];
					}
					else {
						dp[i][c[j]] = 1;
						Max = max(Max, c[j]);
						tot--;
					}
				}
			}
		}
		if( fun(dp[i]) < fun(dp[i+1]) )
			memcpy(dp[i], dp[i+1], sizeof dp[i+1]);
	}
	cout << fun(dp[1]);
}

Measured memory_bytes: 35200
//IIT2019052
//Yukta Gopalani
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
     ll n;
     cin>>n;
     
    ll ans=(n%1000);
    
    if(ans==0)
    cout<<"0";
    else
    cout<<(1000-ans);
         
         
     
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#pragma 03
using namespace std;
int main(){ 
	string n;
	int b;
	cin >> b;
	cin >> n;
	if (b % 2 == 1){
		cout << "No" << endl;
		return 0;
 	}
	for (int i = 0; i<b/2; i++){
		if (n[i] != n[i+b/2]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
    return 0; 
} 

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

int main(){
    int n;
    cin>>n;
    int ninzuu=2;
    int tenn[ninzuu];
    string** str=new string*[ninzuu];
    for(int i=0;i<ninzuu;i++){
        str[i]=new string[n];
        tenn[i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<ninzuu;j++){
            cin>>str[j][i];
        }
        if(str[0][i]==str[1][i]){
            tenn[0]++;
            tenn[1]++;
            continue;
        }
        int mini;
        int dotch;
        if(str[0][i].length()>str[1][i].length()){
            mini=str[1][i].length();
            dotch=0;
        }else{
            mini=str[0][i].length();
            dotch=1;
        }
        for(int j=0;j<mini;j++){
            if(str[0][i][j]>str[1][i][j]){
                tenn[0]+=3;
                break;
            }
            if(str[0][i][j]<str[1][i][j]){
                tenn[1]+=3;
                break;
            }
            if(j==mini-1)tenn[dotch]+=3;
        }
    }
    cout<<tenn[0]<<" "<<tenn[1]<<endl;
    delete[] str[0];
    delete[] str[1];
    delete[] str;
    return 0;
}


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

using namespace std;

int main() {
   int N, A;
   cin >> N >> A;
   if (N % 500 <= A) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
long long mod = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int n;
	cin >> n;
	p point[53];
	for (int i = 0; i < n; i++) {
		cin >> point[i].first >> point[i].second;
	}
	int ans = INT_MAX;
	if (n == 1) {
		cout << 1;
		return 0;
	}
	sort(point, point + n);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int P = (point[j].first - point[i].first);
			int Q = (point[j].second - point[i].second);
			int used[53] = { 0 };
			int cnt = 0;
			for (int x = 0; x < n; x++) {
				if (used[x] == 0) {
					cnt += 1;
					int nextx = point[x].first;
					int nexty = point[x].second;
					int judge = 1;
					while (judge) {
						judge = 0;
						for (int y = 0; y < n; y++) {
							if (point[y].first == nextx&&point[y].second == nexty) {
								used[y] = 1;
								nextx += P;
								nexty += Q;
								judge = 1;
								break;
							}
						}
					}
				}
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a,b,c;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        
        if( a <= b && b <= c){
            System.out.println(a + " " + b + " " + c);
        }
        else if( a <= c && c <= b){
            System.out.println(a + " " + c + " " + b);
        }
        else if(b <= a && a <= c){
            System.out.println(b + " " + a + " " + c);
        }
        else if(b <= c && c <= a){
            System.out.println(b + " " + c + " " + a);
        }
        else if(c <= a && a <= b){
            System.out.println(c + " " + a + " " + b);
        }
        else if(c <= b && b <= a){
            System.out.println(c + " " + b + " " + a);
        }
    }
}


Measured memory_bytes: 26160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.LinkedList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner sn, PrintWriter out) {
            int n = sn.nextInt();
            LinkedList<Integer> lista = new LinkedList<>();
            for (int i = 1; i <= n; i++) {
                int x = sn.nextInt();
                if (i % 2 != 0) {
                    lista.addLast(x);
                } else {
                    lista.addFirst(x);
                }
            }
            if (n % 2 == 0) {
                for (int i = 0; lista.size() != 0; i++) {
                    out.print(lista.pollFirst());
                    out.print(" ");
                }
            } else {
                for (int i = 0; lista.size() != 0; i++) {
                    out.print(lista.pollLast());
                    out.print(" ");
                }

            }

            out.println();
        }

    }
}



Measured memory_bytes: 98452