akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

template<int Mod> struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll sig) { int sigt = sig % Mod; if(sigt < 0) sigt += Mod; x = sigt; }
    int get() const { return (int)x; }

    ModInt &operator+=(ModInt that) { if((x += that.x) >= Mod) x -= Mod; return *this; }
    ModInt &operator-=(ModInt that) { if((x += Mod - that.x) >= Mod) x -= Mod; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % Mod; return *this; }

    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    friend ostream &operator<<(ostream& stream, const ModInt &that) { return stream << that.x; }
};
typedef ModInt<MOD> mint;

int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N){
        cin >> A[i];
    }
    mint ans;
    REP(i, 62){
        ll i0 = 0;
        ll i1 = 0;
        REP(j, N){
            if(A[j]&(1LL<<i)) i1++;
            else i0++;
        }
        mint tmp((1LL<<i));
        ans += mint(i0 * i1) * mint(1LL<<i);
    }
    pr(ans);
}

Measured memory_bytes: 2560
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

mod = 10**9 + 7

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
    if a == 0:
        return 1
    elif a == 1:
        return x
    elif a % 2 == 0:
        return power(x, a//2) **2 % mod
    else:
        return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
    return power(x, mod-2)

def binomial_coefficients(n, k):
    numera = 1  # 分子
    denomi = 1  # 分母

    for i in range(k):
        numera *= n-i
        numera %= mod
        denomi *= i+1
        denomi %= mod
    return numera * modinv(denomi) % mod

ans=0
n,m,k=mp()
for i in range(n):
    for j in range(m):
        if i!=0 or j!=0:
            if i==0 or j==0:
                ans+=(n-i)*(m-j)*(i+j)%mod
            else:
                ans+=2*(n-i)*(m-j)*(i+j)%mod
            ans%=mod
print(ans*binomial_coefficients(n*m-2, k-2)%mod)    

Measured memory_bytes: 77784
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = s()

min_diff = 999
for i in range(len(S)-2):
    diff = abs(753 - int(S[i:i+3]))
    if diff < min_diff:
        min_diff = diff
print(min_diff)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  int A=a+b,B=b+c,C=c+a;
  if(A<=B&&A<=C)cout<<A<<endl;
  else if(B<=A&&B<=C)cout<<B<<endl;
  else cout<<C<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define PI      	        2*acos(0.0)
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define trace(...)          __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " , ";
    __f(comma + 1, args...);
}

const int INF = 1e9+9;

const int nax = 2e5+5;
struct data{
    int a, b;
}ara[nax];
int n;

bool cmp(data &x, data &y)
{
    if (x.b == y.b){
        return x.a < y.a;
    }
    return x.b < y.b;
}

int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> ara[i].a >> ara[i].b;
    }
    sort(ara, ara+n, cmp);
    int time = 0;
    bool flag = true;
    for (int i = 0; i < n; i++){
        if (time + ara[i].a <= ara[i].b){
            time += ara[i].a;
        }
        else{
            flag = false;
            break;
        }
    }
    if (flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 1792
N = int(input())
dic={}
for i in range(N):
    s = [x for x in str(input())]
    s.sort()
    _key="".join(s)
    if _key not in dic:
        dic[_key] = 1
    else:
        dic[_key] += 1
result=0      
for m in list(dic.values()):
  if m>1:
  	result+=m*(m-1)/2
print(int(result))

Measured memory_bytes: 17852
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int A, B;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> A >> B;
  if (A%3 == 0 || B%3==0 || (A+B)%3==0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


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




void dfs(vector<set<int>> data, vector<int> &seen, int x, int a, int b){

  seen.at(x)=1;
  
  for (int xnode:data.at(x)){
    if (seen.at(xnode)==0 and (x!=a or xnode!=b) and (x!=b or xnode!=a)){
      dfs(data,seen,xnode,a,b);
    }
  }
  
}




int main(){
  

  int n,m;
  cin>>n>>m;
  
  vector<set<int>> data(n+1);
  
  vector<pair<int,int>> edges(m);
  
  
  for (int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    pair<int,int> tmp=make_pair(a,b);
    edges.at(i)=tmp;
  }

  for (int i=0;i<m;i++){   
    int tmp1,tmp2;
    tmp1=edges.at(i).first;
    tmp2=edges.at(i).second;
    
    data.at(tmp1).insert(tmp2);
    data.at(tmp2).insert(tmp1);    
  }
  
  
  int answer=0;
  
  for (int i=0;i<m;i++){
    int ai,bi;
    ai=edges.at(i).first;
    bi=edges.at(i).second;
    
    vector<int> seen(n+1,0);
    
    dfs(data,seen,1,ai,bi);
    
    int count=0;
    
    for (int j=1;j<=n;j++){
      if (seen.at(j)==0){
        count=1;
        break;
      }
    }
    
    answer+=count;
  }
  
  cout<<answer<<endl;
    

  
  
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define MAX 100000
#define NIL -1

struct node{
    int p;
    int l;
    int r;
};
node T[MAX];
int n, D[MAX];
void print(int u){
    int C;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";
    cout << "[";

    for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]\n";
}
int rec(int u, int p){
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main(int argc, char* argv[]) {
    int d, v, c, l, r;
    cin >> n;
    for (int i = 0; i < n; i ++) T[i].p = T[i].l = T[i].r = NIL;

    for (int i = 0; i < n; i++){
        cin >> v >> d;
        for (int j = 0; j < d; j++){
            cin >> c;
            if (j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for (int i = 0; i < n; i++){
        if (T[i].p == NIL) r = i;
    }
    rec(r, 0);
    for (int i = 0; i < n; i++) print(i);
    return 0;
}



Measured memory_bytes: 7780
def myAnswer(s:list) -> int:
   setS = set(s)
   if(len(setS) == 1): return 0
   ans = 10**9
   while len(setS) != 0:
      target = setS.pop()
      counter = 0
      tmp = s[:]
      while True:
         pre = tmp.pop(0)
         N = len(tmp)
         for i in range(N):
            now = tmp.pop(0)
            if(pre == target or now==target):
               tmp.append(target)
            else:
               tmp.append(now)
            pre = now
         counter += 1
         if(len(set(tmp))==1):
            break
      ans = min(ans,counter)
   return ans



def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s[:]))
if __name__ == '__main__':
   main()

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

namespace Atcoder
{   
   class A
   { 
     static void Main(string[] args)
     {  
       int N = int.Parse(Console.ReadLine());
       int A = int.Parse(Console.ReadLine());
       
       if(N%500>A || N==0){
         Console.WriteLine("No");
       }else{
         Console.WriteLine("Yes");
       }
     }
   }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	string S;

	cin >> N >> S;

	int same = 0;
	for(int i = 0; i < N-1; i++){
		if(S[i] == S[i+1]) same++;
	}

	cout << N - same << endl;

	Never To return 0;
}


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

int64_t Q=998244353;

int MAX_N=262144;
vector<int64_t> seg(MAX_N*2-1,2147483647);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 2147483647;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return min(X,Y);
  }
}
void chmin(int64_t a,int b){
  int D=MAX_N-1+b;
  seg[D]=a;
  while(D>0){
    D--;
    D/=2;
    seg[D]=min(seg[2*D+1],seg[2*D+2]);
  }
}

int main() {
  int N;
  cin>>N;
  vector<pair<int,int>> p(N);
  vector<int> q(N);
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    a*=-1;
    b*=-1;
    p[i]=make_pair(a,a+b);
    q[i]=a;
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  vector<int> dp(N+1);
  vector<int> rui(N+1);
  dp[0]=1;
  rui[0]=1;
  chmin(0,0);
  for(int64_t i=0;i<N;i++){
    int a=p[i].second;
    int b=lower_bound(q.begin(),q.end(),a+1)-q.begin();
    int c=min(i,qu(b+1,i+1,0,0,MAX_N));
    chmin(c,i+1);
    dp[i+1]=rui[c];
    rui[i+1]=(rui[i]+dp[i+1])%Q;
  }
  cout<<rui[N]<<endl;
}

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


int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    for(int i = 0; i < N; i++){
        cout << S.at(i) << T.at(i);
    }

    cout << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char s[26];
  int i=0, j, d;
  scanf("%s", s);
  while(s[i] != '\0'){
    j = i+1;
    while(s[j] != '\0'){
      if(s[i] == s[j]){
  	printf("no\n");
  	return 0;
      }
      ++j;
    }
    ++i;
  }
  printf("yes\n");
  return 0;
}

Measured memory_bytes: 128
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(int i = 0;i < n; i++)
        cin>>vec[i];
    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(vec[i] < vec[i-1]){
            ans += vec[i-1]-vec[i];
            vec[i] = vec[i-1];
        }
    }
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define pb push_back
typedef pair<int, int> Pi;
typedef pair<int, Pi > Ti;
#define fi first
#define se second
const int LLINF = 1LL << 60;

struct Edge {
  int to, cost;
};

int N, M, X;
int V[10005], mc[10005][2][205];
vector < Edge > G[10005];

int Dijkstra()
{
  priority_queue< Ti , vector < Ti >, greater < Ti > > pq;
  fill_n(**mc, 10005 * 2 * 205, LLINF); mc[0][0][X] = 0;
  pq.push(Ti(0, Pi(0, X)));

  while(!pq.empty()) {
    int v = pq.top().se.fi, w = pq.top().fi, p = pq.top().se.se; pq.pop();
    int h = p / 1000, x = p % 1000;
    if(w > mc[v][h][x]) continue;
    Rep(i, G[v].size()) {
      int u = G[v][i].to, nw = w + G[v][i].cost, nx = max(0LL, x - G[v][i].cost), nh;
      if(h && !V[u] && nx > 0 || !h && V[u] == 2 && nx > 0) continue;
      if(!V[u]) nx = X, nh = 0;
      else if(V[u] == 2) nx = X, nh = 1;
      else nh = h;
      if(nw < mc[u][nh][nx]) {
	mc[u][nh][nx] = nw; pq.push(Ti(nw, Pi(u, nh * 1000 + nx)));
      }
    }
  }
  int ret = LLINF;
  Rep(i, 2) Rep(j, 205) {
    ret = min(ret, mc[N - 1][i][j]);
  }
  return ret;
}
  
signed main()
{
  int A, B, C;
  cin >> N >> M >> X;
  
  Rep(i, N) cin >> V[i];

  while(M--) {
    cin >> A >> B >> C; --A, --B;
    G[A].pb((Edge) { B, C });
    G[B].pb((Edge) { A, C });
  }

  cout << Dijkstra() << endl;

  return 0;
}

Measured memory_bytes: 36512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	vint A;
	for(int i=0;i<3;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	sort(A.begin(),A.end());
	int ans=0;
	for(int i=1;i<3;i++){
		ans+=abs(A[i]-A[i-1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m;
	cin>>n>>m;
	int ans=1,step=0;
	vector<int>a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		step+=a[i];
		if(step<=m){
			ans++;
			//step+=a[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

void solve1() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B) {
		cout << C << endl;
	}
	else if (A == C)
	{
		cout << B << endl;
	}
	else
	{
		cout << A << endl;
	}
}

void solve2() {

}

void solve3() {

}

void solve4() {

}

int main() {
	solve1();
	//solve2();
	//solve3();
	//solve4();

	return 0;
}

Measured memory_bytes: 256
abcd = list(map(int, input().split()))
saki=0
while abcd[0]>0 and abcd[2]>0:
    abcd[2]-=abcd[1]
    if abcd[2]<=0:
        saki=1
    abcd[0]-=abcd[3]


if saki==1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[100005]={0};
const int mod=1000000007;
int main(){
  int n,m;
  cin>>n>>m;
  queue<int> out;
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    out.push(a);
  }
  dp[0]=1;
  for(int i=0;i<n;i++){
    if(!out.empty()){
      if(out.front()==i){
        while(out.front()==i&&!out.empty()) out.pop();
        continue;
      }
    }
    dp[i+1]+=dp[i];
    dp[i+1]%=mod;
    dp[i+2]+=dp[i];
    dp[i+2]%=mod;
  }
  cout<<dp[n]<<endl;
}


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

int H,W,N;
int field[1000][1000];	//東0,南1
int DP[1001][1001];
bool done[1001][1001] = {false};
//N-1回の散歩で通った回数を考える
void makeroot(int y,int x){
	if(y == H || x == W || done[y][x] == true)
		return;
	if((x==0&&y==0)||(x==0&&done[y-1][x])||(y==0&&done[y][x-1])||(x>0&&y>0&&done[y][x-1]&&done[y-1][x]))
		done[y][x] = true;
	else
		return;
	if(field[y][x]){
		DP[y][x+1] += (DP[y][x]+1)/2;
		DP[y+1][x] += DP[y][x]/2;
	}
	else{
		DP[y][x+1] += DP[y][x]/2;
		DP[y+1][x] += (DP[y][x]+1)/2;
	}
	makeroot(y,x+1);
	makeroot(y+1,x);
}
pair<int,int> walk(int y,int x){
	if(y == H || x == W){
		pair<int,int> p;
		p.first = y;
		p.second = x;
		return p;
	}
	if((field[y][x]+DP[y][x])%2)
		return walk(y,x+1);
	else
		return walk(y+1,x);
}
int main(){
	int i,j;
	pair<int,int> pos[200];
	int pcor = 0;
	while(1){
		cin>>H>>W>>N;
		if(H==0&&W==0&&N==0)
			break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				cin>>field[i][j];
			}
		}
		for(i=0;i<=H;i++){
			for(j=0;j<=W;j++){
				DP[i][j]=0;
				done[i][j] = false;
			}
		}
		DP[0][0] = N-1;
		makeroot(0,0);
		pos[pcor] = walk(0,0);
		pcor++;
	}
	for(i = 0;i < pcor;i++)
		cout << pos[i].first+1 << " " << pos[i].second+1 << endl;
	return 0;
}

Measured memory_bytes: 10056
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a+b+c == 17){
    if(a*b==25 || b*c==25){
	cout << "YES" << endl;
    }else if(a*c==25){
    cout << "YES" << endl;
    }
  }else{
    cout << "NO" << endl;
  }  
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll a[2005];
void pre(){
    a[0]=a[1]=a[2]=1;
    for(int i=3;i<=2000;i++) a[i]=(a[i-3]+a[i-1])%mod;
}
int main()
{
    pre();
    int n;
    cin>>n;
    if(n<3) cout<<0;
    else cout<<a[n-3];
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n), b, c(n);
  for (int i = 0; i < n; ++i) cin >> a.at(i);
  for (int i = n-1; i >= 0; --i) {
    int x = 0;
    int ii = i + 1;
    for (int j = ii; j <= n; j += ii) {
      x += c.at(j-1);
    }
    if (x % 2 != a.at(i)) {
      c.at(i) = 1;
      ++m;
    }
  }
  cout << m << endl;
  for (int i = 0; i < n; ++i) {
    if (c.at(i) == 1) cout << i + 1 << " ";
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define f(i,x,n) for(int i=x;i<n;++i)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b;
    cin>>n>>a>>b;
    int diff=a-b;
    if(abs(a-b)%2==0){
        cout<<abs(a-b)/2;
    }else{
        if(a>b)
            swap(a,b);
        int d1=a-1;
        int d2=n-b;
        int t=min(d1,d2);
        t++;
        int dx=abs(a-b);
        t+=dx/2;
        cout<<t;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String args[]) {
    String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    String S = sc.next();
    sc.close();
    
    String ans = "";
    for (int i = 0; i < S.length(); i++) {
      for (int j = 0; j < alphabet.length(); j++) {
        if (S.substring(i, i+1).equals(alphabet.substring(j, j+1))) {
			ans += alphabet.substring((j + N) % alphabet.length(), ((j + N) % alphabet.length())+1);
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 149696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		for(int i = N - 2 ; i >= 0 ; i--) {
			if(check(S.substring(0, i))) {
				System.out.println(i);
				return;
			}
		}
	}

	public static boolean check(String s) {
		int N = s.length();
		for(int i = 0 ; i < N ; i++) {
			if(s.substring(0, N / 2).equals(s.substring(N / 2))) {
				return true;
			}
		}
		return false;
	}
}


Measured memory_bytes: 27476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

ll fastPow(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll fac[1123456];
void combInit(int mx)
{
    fac[0] = 0;
    fac[1] = 1;
    for (int i = 2; i <= mx; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
}

ll modDiv(ll a, ll b)
{
    return a * fastPow(b, MOD - 2) % MOD;
}

ll comb(ll a, ll b)
{
    if (b == 0)
        return 1;
    if (a < b)
        return 0;
    if (a <= 0 || b < 0)
        return 0;
    if (a == b)
        return 1;

    ll p, c;

    c = modDiv(fac[a], fac[a - b]);
    p = fac[b];

    ll res = modDiv(c, p);

    return res;
}

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

    ll n, m;
    ll k;
    cin >> n >> m >> k;

    ll t = comb(n * m - 2, k - 2);

    ll res = 0;
    for (int i = 1; i < n; i++)
    {
        ll s = 0;

        (s += (n - i) * m % MOD * m % MOD * i % MOD) %= MOD;

        (res += s) %= MOD;
    }
    for (int i = 1; i < m; i++)
    {
        ll s = 0;

        (s += (m - i) * n % MOD * n % MOD * i % MOD) %= MOD;

        (res += s) %= MOD;
    }

    (res *= t) %= MOD;

    cout << res << endl;

    return 0;
}


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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string  s;
	int w;
	cin >> s >> w;
	for(int i = 0; i < s.size(); i += w) cout << s[i];
	cout << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=55;
char s[N];
int main() {
	int n,ans=0;
	scanf("%d%s",&n,s);
	for(int i=0;i<n-2;i++) {
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

const ll MOD = 1000000007;
ll mod_pow(ll n, ll k) {
  ll ret = 1;
  for(; k>0; k>>=1) {
    if(k & 1) (ret *= n) %= MOD;
    (n *= n) %= MOD;
  }
  return ret;
}

const int S = 100010;
struct UnionFind {
  vector<int> node;
  int size_;
  UnionFind(int n) {
    node.resize(n, -1);
    size_ = n;
  }
  void reset() {
    fill(node.begin(), node.end(), -1);
  }
  int find(int x) {
    return node[x] < 0 ? x : node[x] = find(node[x]);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    size_--;
    node[x] += node[y];
    node[y] = x;
    return true;
  }
  int size() {
    return size_;
  }
};
  
int main() {
  ll N, M;
  while(cin >> N >> M, N || M) {
    UnionFind uf(N);
    for(int i=0; i<M; i++) {
      int a, b; cin >> a >> b;
      a--; b--;
      uf.unite(a, b);
    }

    int ans = mod_pow(2, uf.size());
    if(uf.size() != N) ans++;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int a, b;
    cin >> a >> b;
    double x = 1.0 * a / b;
    cout << a / b << " " << a % b << " ";
    cout << fixed << setprecision(10) << x << endl;
}



Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const ll N = 100000 + 10;
const ll MOD = 1000000000 + 7;
ll n, a[N], num[N];

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

int main() {
    cin >> n;
    memset(num, 0, sizeof(num));
    for (ll i = 0; i < n; ++ i) {
        cin >> a[i];
        num[a[i]]++;
    }
    ll ans = 0;
    for (ll i = 0; i < n; ++ i) if(num[i]!=1) ans++;
    if (n%2 && num[0]!=1) {cout << 0 << endl;return 0;}
    if(ans != n/2*2) {cout << 0 << endl;return 0;}
    cout << quick_mod(2, n/2) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

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


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a.begin(),a.end());
	vector<int> b;
	int cnt=0;
	int bef=-1;
	for(int i=0;i<n;i++)
	{
		if(bef==a[i])
			cnt++;
		else
		{
			if(cnt!=0)
				b.push_back(cnt);
			cnt=1;
		}
		bef=a[i];
	}
	b.push_back(cnt);
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	cnt=0;
	for(int i=0;i<min(k,(int)b.size());i++)
	{
		cnt+=b[i];
		//cout << i << " " << b[i] << endl;
	}
	
	cout << n-cnt << endl;

}

Measured memory_bytes: 2168
// B - YYMM or MMYY
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int n1 = (s[0] - '0') * 10 + s[1] - '0';
	int n2 = (s[2] - '0') * 10 + s[3] - '0';
	bool b1 = n2 >= 1 && n2 <= 12;
	bool b2 = n1 >= 1 && n1 <= 12;
	if (b1 && b2)
		cout << "AMBIGUOUS" << endl;
	else if (b1)
		cout << "YYMM" << endl;
	else if (b2)
		cout << "MMYY" << endl;
	else
		cout << "NA" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

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

  ll sum = 0;
  repp(i, 1, (int)1e+6) {
    sum += i;
    if (sum >= X) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int N,M;
vector<vector<int>> G;

int dp[100100];
int rec(int v){
    if(dp[v] != -1) return dp[v];

    int res = 0;
    for(auto nv:G[v]){
        chmax(res, rec(nv)+1);
    }

    return dp[v] = res;
}

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

    cin >> N  >> M;
    G.assign(N, vector<int>());
    for(int i=0; i<M; ++i){
        int x,y; cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
    }

    for(int v=0; v<N; ++v) dp[v] = -1;
    int res = 0;
    for(int v=0; v<N; ++v) chmax(res, rec(v));
    cout << res << endl;

	return 0;
}


Measured memory_bytes: 8192
#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 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 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int n;
  cin>>n;
  vector<int> v;
  REP(i,n){
    int x;
    cin>>x;
    v.pb(x-i-1);
  }

  VSORT(v);
  int p = v[v.size()/2];
  llong ans = 0;
  REP(i,n){
    ans += abs(v[i] - p);
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define lowbit(i) i&-i
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	ull ans=0; For(i,0,5)ans=ans<<15^rand(); return ans;
}
const int N=3005;
int ans,a[N];
vector<int> v[N];
int dfs(int p,int fa){
	for(auto i:v[p])if(i!=fa){
		if(a[i]<a[p]&&!dfs(i,p))return 1;
	}
	return 0;
}
int main(){
	int n=read();
	For(i,1,n)a[i]=read();
	For(i,1,n-1){
		int s=read(),t=read();
		v[s].pb(t); v[t].pb(s);
	}
	For(i,1,n){
		if(dfs(i,0))wri(i);
	}
}

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

int main(){
string S,T;
cin>>S>>T;
int ans=10000;
for(int start=0;start<=(S.size()-T.size());start++){
    int diff=0;
    for(int i=0;i<T.size();i++){
        if(S[start+i]!=T[i]){
            diff++;
            //cout<<diff<<endl;
        }
    }
    ans = min(ans,diff);
}
cout<<ans<<endl;
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))

A_sum = 0
for Ai in A:
  A_sum += Ai

s1 = 0
i = 0
while s1 < A_sum / 2:
  s1 += A[i]
  i += 1

s2 = s1 - A[i - 1]
ans = min(abs(A_sum - s1 * 2), abs(A_sum - s2 * 2))
print(ans)

Measured memory_bytes: 26060
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    string s; cin >> s;
    ll ans = 0;
    REP(i, n-1) if (s[i] == s[i+1]) ans++;
    cout << min(ans+2*k, n-1) << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N, R;
    cin >> N >> R;
    if (N>=10) cout << R << endl;
    else {
        cout << R + (100 * (10-N)) << endl;
    }



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  string S;
  cin >> S;

  int L = (S[0] - '0') * 10 + (S[1] - '0');
  int R = (S[2] - '0') * 10 + (S[3] - '0');

  if (L >= 1 && L <= 12){
    if (R >= 1 && R <= 12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }else{
    if (R >= 1 && R <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
}


Measured memory_bytes: 3596
p=print
b=0
for e in iter(input,'0 0'):
 if b:p()
 b=u=1;s,t=map(int,e.split())
 for y in range(s,t+1):
  if((y%4==0)*(y%100!=0)or y%400==0):p(y);u=0
 if u:p('NA')


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

void swap(int &a, int &b)
{
  int t;
  t = a;
  a = b;
  b = t;
};

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

  int a, b, c;
  cin >> a >> b >> c;

  swap(a, b);
  swap(a, c);

  cout << a << " " << b << " " << c << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 5e15;
int main(){
    ll N;
    cin >> N;
    set<ll> s, sm;
    map<ll, ll> m;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        s.insert(i + 1);
        sm.insert(-(i + 1));
        m[a] = i + 1;
    }
    s.insert(0);
    s.insert(N + 1);
    sm.insert(0);
    sm.insert(-(N + 1));
    ll ans = 0;
    for(ll i = N; i >= 1; i--){
        s.erase(m[i]);
        sm.erase(-m[i]);
        ll right = *s.lower_bound(m[i]);
        ll left = *sm.lower_bound(-m[i]);
        left *= -1;
        ans += i * (m[i] - left) * (right - m[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
const int N=20;
int n,ans;
int A[N];
int p[N][N],v[N][N];
int countbit1(int x) {
    int cnt=0;
    while(x) {
        x&=x-1;
        cnt++;
    }
    return cnt;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>A[i];
        for(int j=1;j<=A[i];j++)
            cin>>p[i][j]>>v[i][j];
    }
    for(int plan=1;plan<(1<<n);plan++) {
        bool ok=true;
        for(int i=1;i<=n;i++) {
            if(!(plan&(1<<(i-1)))) continue;
            for(int j=1;j<=A[i];j++)
                if(((plan>>(p[i][j]-1))&1)^v[i][j]) ok=false;
        }
        if(ok) ans=max(ans,countbit1(plan));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  vll csum(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    csum[i + 1] = csum[i] + a;
  }

  vll bs;
  repLRE(i, 0, n - 1) {
    repLRE(j, i + 1, n) { bs.push_back(csum[j] - csum[i]); }
  }

  ll const blmax = 50;

  ll ans = 0;
  rrepLRE(i, blmax, 0) {
    ll cnt = 0;
    rep(j, (ll)bs.size()) {


      ll v = ans | (1LL << i);
      if ((bs[j] & v) == v) cnt++;

      //if ((bs[j] >= ans)) if (bs[j] >> i & 1) cnt++;


    }
    if (k <= cnt) ans += (1LL << i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6256
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;

class DICE {

public:

	static int dice(int a, int b, int c, int d, int e, int f, int s, string order) {
		int N[100] = { a, b, c, d, e, f };
		for (int i = 0; i < s; i++) {
			if (order[i] == 'S') {
				swap(N[0], N[4]);
				swap(N[4], N[5]);
				swap(N[1], N[5]);

			}
			else if (order[i] == 'E') {
				swap(N[0], N[3]);
				swap(N[3], N[5]);
				swap(N[5], N[2]);

			}
			else if (order[i] == 'W') {
				swap(N[0], N[2]);
				swap(N[2], N[5]);
				swap(N[5], N[3]);

			}
			else if (order[i] == 'N') {
				swap(N[0], N[1]);
				swap(N[1], N[5]);
				swap(N[5], N[4]);

			}
		}
		return N[0];

	}
	static int dice2(int a, int b, int c, int d, int e, int f, int order, int order2) {
		int N[100] = { a, b, c, d, e, f };
		int A = 0, j = 0;
		for (int x = 0; x < 8; x++) {

			if (N[0] == order) {

				for (int y = 0; y < 5; y++) {

					if (N[1] == order2) {

						j += 1;
						break;
					}

					swap(N[1], N[2]);
					swap(N[2], N[4]);
					swap(N[4], N[3]);

				}
			}
			if (j == 1) {
				break;
			}

			if (x < 4) {
				swap(N[0], N[1]);
				swap(N[1], N[5]);
				swap(N[5], N[4]);
			}
			else if (x > 3) {
				swap(N[0], N[2]);
				swap(N[2], N[5]);
				swap(N[5], N[3]);
			}

		}

		return N[2];
	}


};

int main() {
	int a, b, c, d, e, f, s, N;
	int q;
	int order, order2;

	cin >> a >> b >> c >> d >> e >> f;
	cin >> q;

	for (int x = 0; x < q; x++) {
		cin >> order >> order2;
		DICE dice2;
		N = dice2.dice2(a, b, c, d, e, f, order, order2);
		cout << N << endl;
	}


	return 0;
}




Measured memory_bytes: 3084
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (10)
#define MOD (1000000007)

ll x[MAXN][MAXN];
int main(void)
{
    ll n,d;
    scanf("%ld %ld",&n,&d);
    for(int i=0;i<n;i++) for(int j=0;j<d;j++)
    {
        scanf("%ld",&(x[i][j]));
    }
    
    ll ans=0;
    for(int i=0;i<n;i++) for(int j=i+1;j<n;j++)
    {
        ll sum = 0;
        for(int k=0;k<d;k++) sum += abs(x[i][k]-x[j][k]) * abs(x[i][k]-x[j][k]);
        for(int k=0;;k++)
        {
            if(k*k==sum)
            {
               ans++;
               break;
            }
            if(k*k>sum) break;
        }
    }

    printf("%ld\n", ans);
    return 0;
}


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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0;i < (int)s.length();i++){
    if(s.at(i) != t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3908
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func minimum(xs []int) int {
	n := xs[0]
	for _, x := range xs {
		if x < n {
			n = x
		}
	}
	return n
}

func main() {
	var l int
	fmt.Scanf("%d\n", &l)

	as := make([]int, l)
	for i := range as {
		fmt.Scanf("%d\n", &as[i])
	}

	DP := make([][]int, l+1)
	for i := range DP {
		DP[i] = make([]int, 5)
	}

	for i := 1; i < len(DP); i++ {
		even := as[i-1] % 2
		if as[i-1] == 0 {
			even = 2
		}
		odd := (as[i-1] + 1) % 2
		DP[i][0] = DP[i-1][0] + as[i-1]
		DP[i][1] = min(DP[i-1][0], DP[i-1][1]) + even
		DP[i][2] = min(DP[i-1][0], min(DP[i-1][1], DP[i-1][2])) + odd
		DP[i][3] = min(DP[i-1][0], min(DP[i-1][1], min(DP[i-1][2], DP[i-1][3]))) + even
		DP[i][4] = min(DP[i-1][1], min(DP[i-1][1], min(DP[i-1][2], min(DP[i-1][3], DP[i-1][4])))) + as[i-1]
	}
	fmt.Println(minimum(DP[l]))
}

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


using ll = long long;
const int Mod = 1e9+7;
const int MaxN = 1e4+10;
const int MaxP = 1e6;
int n;
int a[MaxN];
int lpf[MaxP+1], vpe[MaxP+1];


void exgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0) {x = 1, y = 0; return;}
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}


ll invmod(ll a, ll m) {
    ll x, y;
    exgcd(a, m, x, y);
    return (x % m + m) % m;
}


void init()
{
    for (int i = 1; i <= MaxP; i++) lpf[i] = i;
    for (int i = 2; i <= MaxP; i++) {
        if (lpf[i] == i) {
            for (int j = i * 2; j <= MaxP; j += i) lpf[j] = i;
        }
    }
}


void solve()
{
    for (int i = 0; i < n; i++) {
        int x = a[i], p, pe;
        while (x > 1) {
            p = lpf[x]; pe = 1;
            while (x % p == 0) {
                x /= p; pe *= p;
            }
            vpe[p] = max(vpe[p], pe);
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) ans += invmod(a[i], Mod);
    ans %= Mod;
    for (int i = 2; i <= MaxP; i++) {
        if (vpe[i] > 0) ans = ans * vpe[i] % Mod;
    }
    cout << ans << endl;
}


int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    init();
    solve();
    return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<cmath>
#include<limits.h>

using namespace std;

long long max(long long a, long long b) {
	if (a < b)return b;
	else return a;
}

int main() {

	long long N, K;

	cin >> N >> K;

	long long *A = new long long[N];

	for (int n = 0; n < N; n++) {
		cin >> A[n];
	}

	int maxbit = 40;
	//if (K == 0) maxbit = 1;
	//else maxbit = log2(K) + 1;

	long long dp[41][2];
	long long dpX[41][2];

	for (int i = 0; i < maxbit; i++) {
		dp[i][0] = dp[i][1] = -1;
	}

	dp[0][0] = 0;


	
	long long mask = 1;
	long long X = 0;


	mask = mask << (maxbit - 1);

	long long res[2];
	long long maskres;
	for (int i = 0; i < maxbit; i++) {

		res[0] = res[1] = 0;

		for (int n = 0; n < N; n++) {
			maskres = A[n] & mask;

			res[0] += maskres ^ 0;
			res[1] += maskres ^ mask;
		}

		

		if (dp[i][0] != -1) {
			if (mask & K) {
				dp[i + 1][0] = dp[i][0] + res[1];
				dp[i + 1][1] = dp[i][0] + res[0];
			}
			else {
				dp[i + 1][0] = dp[i][0] + res[0];
			}
		}

		if (dp[i][1] != -1) {
			dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + max(res[1], res[0]));
		}

		mask = mask >> 1;
		//mask = mask << 1;



	}

	//cout << ret;
	cout << dec << max(dp[maxbit][0], dp[maxbit][1]);



	return 0;
}

Measured memory_bytes: 1024