akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;
struct edge{
    int flow,to,rev;LL cost;
};
typedef vector<edge> E;
typedef vector<E> FlowGraph;
 
void addedge(FlowGraph &g,int from,int to,int f,LL cost){
    int n=g[from].size();
    int m=g[to].size();
    g[from].push_back(edge{f,to,m,cost});
    g[to].push_back(edge{0,from,n,-cost});
}

namespace _ssc{
#define SZ 4000
    LL h[SZ];
    LL d[SZ];
    int pV[SZ];
    int pE[SZ];
};
struct ssc{
    LL *h,*d;int *pV,*pE;
    ssc(int V):h(_ssc::h),d(_ssc::d),pV(_ssc::pV),pE(_ssc::pE){
        fill(h,h+V,0);
    }     
};
const LL INF=1e12;
LL min_cost_flow(int s,int t,int f,FlowGraph &g,ssc& info){
    using P=tuple<LL,int>;
    LL *h=info.h;
    LL *d=info.d;
    int *pV=info.pV;
    int *pE=info.pE;
    
    const int V=g.size();
    LL res=0;
    while(f>0){
        // cout<<f<<endl;
        priority_queue<P> que;
        fill(d,d+V,INF);
        d[s]=0;
        que.push(P(0,s));
        while(que.size()){
            auto p=que.top();que.pop();
            LL cost;int v;
            tie(cost,v)=p;cost=-cost;
            if(d[v]<cost)continue;
            for(int i=0,sz=g[v].size();i<sz;i++){
                auto &e=g[v][i];
                if(e.flow>0&&d[e.to]>d[v]+e.cost+h[v]-h[e.to]){
                    d[e.to]=d[v]+e.cost+h[v]-h[e.to];
                    pV[e.to]=v;
                    pE[e.to]=i;
                    que.push(P(-d[e.to],e.to));
                }
            }
        }
        if(d[t]==INF)return -1;
     
        for(int v=0;v<V;v++)h[v]+=d[v];
        int d=f;
        for(int v=t;v!=s;v=pV[v])
            d=min(d,g[pV[v]][pE[v]].flow);
        f-=d;
        res+=d*h[t];
        for(int v=t;v!=s;v=pV[v]){
            auto &e=g[pV[v]][pE[v]];
            e.flow-=d;
            g[v][e.rev].flow+=d;
        }
    }
    return res;
}
typedef vector<int> V;
int main(){
    int N;
    cin>>N;
    map<int,int> m;
    LL sum=0;
    V A(N),B(N);
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
        if(B[i]<A[i])swap(A[i],B[i]);
        sum+=B[i];
        m[A[i]]=0;
        m[B[i]]=0;
    }
    int cnt=N;
    for(auto &it:m)it.second=cnt++;
    int S=cnt++;
    int G=cnt++;
    FlowGraph fg(cnt);
    for(int i=0;i<N;i++){
        addedge(fg,S,i,1,0);
        addedge(fg,i,G,1,B[i]);
        addedge(fg,i,m[A[i]],1,0);
        addedge(fg,i,m[B[i]],1,B[i]-A[i]);
    }
    for(auto &it:m)addedge(fg,it.second,G,1,0);
    ssc info(cnt);
    LL dec=min_cost_flow(S,G,N,fg,info);
    cout<<sum-dec<<endl;
    return 0;
}

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

int h, w;
vector<string> v;
template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}
int a[30];
int x, y, z;
bool f;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> h >> w;
	readVector(h, v);
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j)
			++a[v[i][j]-'a'];
	for(int i=0; i<26; ++i){
		x += a[i] / 4;
		a[i] -= a[i] / 4 * 4;
		y += a[i] / 2;
		a[i] -= a[i] / 2 * 2;
		z += a[i];
	}
//	cout << x << " " << y << " " << z << "\n";
	if(x > (h/2)*(w/2)){
		y += 2 * (x - (h/2)*(w/2));
		x = (h/2) * (w/2);
	}
	cout << ((x == (h/2)*(w/2) && y == (h-(h/2*2))*w/2 + (w-(w/2*2))*h/2 && z == (h % 2 == 1 && w % 2 == 1 ? 1 : 0)) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	cin >> str;
	if (str[0] == str[1] && str[1] == str[2]) puts("Yes"), exit(0);
	if (str[3] == str[2] && str[1] == str[2]) puts("Yes"), exit(0);
	puts("No");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
Cij = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1,N+1):
  a, b = int(str(i)[0]), int(str(i)[-1])
  Cij[a][b] += 1
print(sum(Cij[i][j]*Cij[j][i] for i in range(10) for j in range(10)))

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

map<ll,ll>f;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,b,x=0,y=0;
    cin>>a>>b;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i==a && s[i]=='-')x++;
        if(s[i]>='0' && s[i]<='9')y++;
    }
    if(x==1&&y==a+b)cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(void) {
  int a, b, c, x;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  int r = 0;
  for(int i = 0; i < a+1; ++i){
    for(int j = 0; j < b+1; ++j){
      for(int k = 0; k < c+1; ++k){
        if( (500*i+100*j+50*k) == x) {
          r += 1;
        }
      }
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 256
D,G=map(int,input().split())
pl=[0]*D
cl=[0]*D
for i in range(D):
  pl[i],cl[i]=map(int,input().split())
ans=[]
for bit in range(2**D):
  compl=[]
  count=0
  score=0
  for i in range(D):
    if bit&(1<<i):
      score+=pl[i]*100*(i+1)+cl[i]
      count+=pl[i]
      compl.append(i)
  if score>=G:
    ans.append(count)
  else:
    n=max(set(range(D))-set(compl))
    for i in range(pl[n]):
      score+=100*(n+1)
      count+=1
      if score>=G:
        ans.append(count)
        break
print(min(ans))

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

int main() {
  int N,calN,Sum=0;
  cin >> N;
  calN = N;
  
  rep(i,9){
  Sum += calN % 10;
  calN /= 10;
  }
  
  if (N % Sum == 0){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
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 <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

//next_combination
void nexc(ll*a,int n,int r){
	int t=r,s=r;
	ll temp;
	while(--t>=0)if(a[t]<a[n-1])break;
	if(t<0){sortup(a,n);return;}
	while(a[s]<a[t])s++;
	temp=a[t];a[t]=a[s];a[s]=temp;
	rep(k,1,min(n-s,r-t)){temp=a[r-k];a[r-k]=a[s+k];a[s+k]=temp;}
	sortup(a,r);sortup(a+r,n-r);
}


ll a[128];
ll c[5]={'M','A','R','C','H'};
ll n;

int main(){
	scanf("%lld\n",&n);
	rep(i,0,n){
		char s[99];
		scanf("%s",s);
		a[*s]++;
	}
	ll ans=0;
	rep(i,0,10){
		ans+=a[c[0]]*a[c[1]]*a[c[2]];
		nexc(c,5,3);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#define ll long long
using namespace std;
const int maxn=500010;
int n, x, num;
int cnt[maxn], tree[maxn], pos[26][maxn];
ll ans;
char s[maxn];
bool v[maxn];
inline void add(int x, int delta){for(;x<=n;x+=x&-x) tree[x]+=delta;}
inline int query(int x){int sum=0; for(;x;x-=x&-x) sum+=tree[x]; return sum;}
int main()
{
    scanf("%s", s+1); n=strlen(s+1);
    for(int i=1;i<=n;i++) cnt[x=s[i]-'a']++, pos[x][++pos[x][0]]=i, tree[i]=i&-i;
    for(int i=0;i<26;i++) if(cnt[i]&1) num++;
    if(num>1) return puts("-1"), 0;
    for(int i=1;i<=n;i++)
    if(!v[i])
    {
        int x=s[i]-'a', nxt=pos[x][pos[x][0]--];
        if(i==nxt) ans+=(query(n)-query(i))>>1;
        else ans+=query(n)-query(nxt);
        add(i, -1); add(nxt, -1); v[i]=v[nxt]=1;
    }
    printf("%lld\n", ans);
}

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

bool close(string s1,string s2){
    bool in_db_quo=false;
    int index1=0;
    int index2=0;
    int times=0;//一致していない二重引用符
    int l_of_sen1=s1.length(),l_of_sen2=s2.length();
    while(true){
        if(!in_db_quo){
           if(s1[index1]=='"' && s2[index2]=='"')in_db_quo=true;
           if(!(s1[index1] == s2[index2]))return false;//different
        }
        else{
           int index1_s=index1,index2_s=index2;//二重引用符の中の始まりの添字
           bool end_quo1=false,end_quo2=false;//終わりの方の二重引用符にいるかを表す
           while(!end_quo1 || !end_quo2){
               if(!end_quo1){
                   if(s1[index1] == '"')end_quo1 = true;
                   if(!end_quo1)index1++;
               }
               if(!end_quo2){
                   if(s2[index2] == '"')end_quo2 = true;
                   if(!end_quo2)index2++;
               }
           }
           if(!(s1.substr(index1_s,index1-index1_s) == s2.substr(index2_s,index2-index2_s))){
               times++;
               if(times>=2)return false;//different
           }
           in_db_quo=false;
        }
        if(index1==l_of_sen1-1 || index2==l_of_sen2-1){
             if(index1==l_of_sen1-1 && index2==l_of_sen2-1)return true;
             else return false;
        }
        index1++;index2++;
    }
}
int main(){
    string s1,s2;
    while(true){
        cin>>s1;
        if(s1==".")break;
        cin>>s2;
        if(s1==s2)cout<<"IDENTICAL"<<endl;
        else if(close(s1,s2))cout<<"CLOSE"<<endl;
        else cout<<"DIFFERENT"<<endl;
    }
}


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

public class Main {
    

	public static void main(String[] args) {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = null;
		try {
			x = br.readLine();

			br.close();

		} catch (IOException e) {
		}
		int x1 = Integer.parseInt(x);
		System.out.println(x1 * x1 * x1);
	}
}



Measured memory_bytes: 24320
N = int(input())
Ds = [int(i) for i in input().split(' ')]
M = int(input())
Ts = [int(i) for i in input().split(' ')]

if M > N:
     print('NO')
else:
    dic = {}
    for d in Ds:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    for t in Ts:
        flag = 0
        if t in dic:#存在しているならば
            dic[t] -= 1
            if dic[t] < 0:
                flag = 1
                break
        else:#存在していないならば
            flag = 1
            break
    if flag == 1:
        print('NO')
    else:
        print('YES')

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

long result = 0;
int n;

long Calc(string str)
{
    int n = str.size();
    long res = 0;
    long now = 0;

    for (int i = 0; i < n; i++)
    {
        char c = str.at(i);
        if (c == '+')
        {
            res += now;
            now = 0;
        }
        else
        {
            int number = (int)c - 48;
            now = now * 10 + (number);
            if (i == n - 1)
                res += now;
        }   
    }
    return res;
}

void Make(char c[], string& str, int i)
{
    if (i == n)
    {
        result += Calc(str);
        return;
    }
  
    if (i == 0)
    {
        str.push_back(c[i]);
        Make(c, str, i + 1);
    }
    else
    {
        for (int j = 0; j < 2; j++)
        {
            if (j == 0)
            {
                str.push_back(c[i]);
                Make(c, str, i + 1);
                str.pop_back();
            }
            else
            {
                str.push_back('+');
                str.push_back(c[i]);
                Make(c, str, i + 1);
                str.pop_back();
                str.pop_back();
            }
        }
    }
}


int main()
{
    string s;
    cin >> s;
    n = s.size();
    char* c = new char[n];
    for (int i = 0; i < n; i++)
        c[i] = { ' ' };

    for (int i = 0; i < n; i++)
    {
        c[i] = s.at(i);
    }

    string str;
    Make(c, str, 0);

    cout << result << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    while(1){
        int N,M,P,save,sum=0,x;
        cin >> N >> M >> P;
        if(N==0&&M==0&&P==0)    break;
        for(int i=0;i<N;i++){
               cin >> x;
               if((M-1)==i) save = x;
               sum += x;
        }
        if(save!=0)
            cout << sum*(100-P)/save << endl;
        else
            cout << 0 << endl;
    }
} 


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int n, y;
    cin >> n >> y;
    bool flag = false;
    for(int a = 0; a <= n; a++) {
        for(int b = 0; b <= n - a; b++) {
            int c = n - a - b;
            if(a*10000 + b*5000 + c*1000 == y and !flag) {
                flag = true;
                cout << a << " " << b << " " << c << endl;
                break;
            }
        }
    }

    if(!flag) cout << -1 << " " << -1 << " " << -1 << endl;
 }



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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = Integer.parseInt(in.nextLine());
        List<Integer> bits = new ArrayList<>();
        List<Boolean> isPut = new ArrayList<>();
        for (int i = 0; i < num; i++) {
             bits.add(in.nextInt());
             isPut.add(false);
        }
        in.close();
        int snukeWork = 0;
        for (int i = num - 1; i >= 0; i--) {
            int count = 0;
            for(int j = 1; i + (i + 1) * j < num; j++) {
                if(isPut.get(i + (i + 1) * j) ) {
                    count++;
                }
            }
            isPut.set(i, count % 2 != bits.get(i));
            if (isPut.get(i)) {
                snukeWork++;
            }
        }
        System.out.println(snukeWork);
        StringBuilder sb = new StringBuilder(snukeWork * 5);
        for (int i = 0; i < num; i++) {
            if (isPut.get(i)) {
                sb.append(i + 1);
                sb.append(" ");
            }
        }
        if (snukeWork != 0) System.out.println(sb.substring(0, sb.length()-1));

    }

}


Measured memory_bytes: 65760
L, R = [int(x) for x in input().split()]

min = 1000000000000000000000000000

if R - L > 2019:
    print(0)
    exit()

for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        if min > i * j % 2019:
            min = i * j % 2019
        if min == 0:
            break

print(min)



Measured memory_bytes: 2940
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif




#define int long long
#define rng(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i,n) rng(i,0,n)
#define gnr(i,l,r) for(size_t i=(r)-1;i>=(l);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()   //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend()//...,3,2,1

using namespace std;


//constant
const int MOD = 1000000007;
const int INF = 1e18;


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

void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,x; cin >> n >> x;
    int town[n]; rep(i,n) cin >> town[i];
    
    int ans = abs(x-town[0]);
    for (int i = 0; i < n; i++) ans = gcd(ans, abs(town[i] - x));
    
    cout << ans << endl;
    
}





signed main() {
    solve();
    return 0;
}




Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a,b,v,w;
int t;
int main()
{
	scanf("%d%d",&a,&v);
	scanf("%d%d",&b,&w);
	scanf("%d",&t);
	if(v<=w) printf("NO");
	else if(ceil((double)abs(a-b)/(v-w))>t) printf("NO");
	else printf("YES");
	return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<stack>

using namespace std;
int main(void) {
  int N, M;
  while(cin >> N >> M) {
    bool stom[200001] = {};
    bool mtog[200001] = {};
    int i;
    for(i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      if(a > b) swap(a, b);
      
      if(a == 1) {
	stom[b] = 1;
      }
      if(a == N) {
	mtog[b] = 1;
      }
      else if(b == N) {
	mtog[a] = 1;
      }
    }

    int j, goal;
    goal = 0;
    for(i = 2; i <= M && !goal; i++) {
      if(stom[i] && mtog[i]) {
	goal = 1;
      }
    }
    if(goal) {
      cout << "POSSIBLE" << endl;
    }
    else {
      cout << "IMPOSSIBLE" << endl;
    }
  }
  return 0;
}
    
	


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    
    int price = 700;
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    for(int i = 0;i < 3;i++){
      if(s.charAt(i) == 'o') price += 100;
    }
    
    System.out.println(price);
  }
}


Measured memory_bytes: 35592
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define Iter(c) __typeof__((c).begin())
#define foreach(i,c) for(Iter(c) i = (c).begin();i != (c).end();++i)
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[] = {+1,+0,-1,-2,-2,-2,+1,+0,-1,+2,+2,+2}; // frog
const int dy[] = {-2,-2,-2,+1,+0,-1,+2,+2,+2,+1,+0,-1}; // frog
const int ddx[] = {0,+0,-1,-1,-1,+0,+1,+1,+1};
const int ddy[] = {0,-1,-1,+0,+1,+1,+1,+0,-1};

int main(){

  while(true)
    {
      int n;
      vector<P> points;
      P phoy;

      cin >> phoy.F >> phoy.S;
      if(!(phoy.F|phoy.S))break;

      map<P,bool> used;

      cin >> n;

      rep(i,n)
	{
	  int xx,yy;
	  cin >> xx >> yy;
	  points.pb(P(xx,yy));
	}

      deque<P> deq;
      deq.push_front(phoy);

      bool fin = true;

      for(int i=0;i<=n;i++)
	{
	  int Size = deq.size();
	  map<P,bool> exist;

	  if(!Size)
	    {
	      cout << "NA" << endl;
	      fin = false;
	      break;
	    }

	  for(int j=0;j<9;j++)
	    {
	      int nx = points[i].F + ddx[j], ny = points[i].S + ddy[j];
	      exist[P(nx,ny)] = true;
	    }
	 
	  used.clear();
	  
	  for(int j=0;j<Size;j++)
	    {
	      P p = deq.front(); deq.pop_front();
		      
	      for(int k=0;k<12;k++)
		{
		  int nx = p.F + dx[k], ny = p.S + dy[k];
		  
		  if(exist[P(nx,ny)] && !used[P(nx,ny)])
		    {
		      used[P(nx,ny)] = true;
		      deq.push_back(P(nx,ny));
		    }

		}

	    }

	}



      if(fin)
	{
	  cout << "OK" << endl;
	}

    }
return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int a;
	set<int>s;
	rep(i, 3) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size();
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

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

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

#define ll int

int a[N], sum[N];

vector <int> g[N];

void dfs(int v, int cur, int pr) {
	a[v] = cur + sum[v];
	for (auto to : g[v]) {
		if (to == pr)
			continue;
		dfs(to, cur + sum[v], v);
	}
	cur -= sum[v];
}

int main () {
    to_pray();

    int n, q;
    cin >> n >> q;
    
    for (int i = 1; i < n; ++ i) {
    	int x, y;
    	cin >> x >> y;
    	g[x].eb(y);
    	g[y].eb(x);
    }
    
    while(q--) {
    	int x, y;
    	cin >> x >> y;
    	sum[x] += y;
    }
    
    dfs(1, 0, -1);
    
    for (int i = 1; i <= n; ++ i)
    	cout << a[i] << " ";
    
    cout << '\n';
    return 0;
}

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

int main(void) {

    int N; cin >> N;
    bool is_Y = false; 
    for (int i = 0; i < N; i++) {
        char S; cin >> S;
        if (S == 'Y') is_Y = true;
    }

    cout << (is_Y ? "Four" : "Three") << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N % 2 == 0:
    B = [i for i in range(1, N, 2)]
    B = B + B
    B = sorted(B)
else:
    B = [i for i in range(2, N, 2)]
    B = B + [0] + B
    B = sorted(B)

if A != B:
    print(0)
else:
    print(2 ** (len(B) // 2) % (10 ** 9 + 7))





Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素数判定O(√n)
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

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

    vector<int> ans;
    for(int i=2;i<=55555;i++){
        if(!is_prime(i)) continue;
        if(i%5==2){
            ans.push_back(i);
            if(ans.size()==n){
                rep(j,n) cout<<ans[j]<<" ";
                cout<<endl;
                return 0;
            }
        }
    }
}

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

int main(void){
    int n;
    cin >> n;
    vector<pair<int,int>> vec(n);

    for(int i=0;i<n;i++){
        cin >> vec[i].first;
        vec[i].second = i;
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());

    for(int i=0;i<n;i++){
        if(i!=vec[0].second) cout << vec[0].first << endl;
        else cout << vec[1].first << endl;
    }
}

Measured memory_bytes: 3200
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const b = arg[1].split(" ").map(n=>~~n);
    
    let answer = [];
    
    if(N % 2 === 0) {
        for(let i=N-1; i>0; i -= 2) {
            answer.push(b[i]);
        }
        
        for(let i=0; i<N; i += 2) {
            answer.push(b[i]);
        }
    } else {
        for(let i=N-1; i>=0; i -= 2) {
            answer.push(b[i]);
        }
        
        for(let i=1; i<N; i += 2) {
            answer.push(b[i]);
        }
    }
    
    console.log(answer.join(" "));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 57776
#include "bits/stdc++.h"

using namespace std;

vector<int> parents;
vector<int> ranks;

// Union-Find
// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_A

void init(int n) { // initialization
    parents = vector<int>(n, 0);
    ranks = vector<int>(n, 0);
    for (int i = 0; i < n; ++i) {
        parents[i] = i;
        ranks[i] = 0;
    }
}

int find(int x) { // find root of x
    if (parents[x] == x) {
        return x;
    }
    else {
        parents[x] = find(parents[x]);
        return parents[x];
    }
}

void unite(int x, int y) { // unite group of x and group of y
    x = find(x);
    y = find(y);
    if (x == y) { // if x and y has already the same root, do nothing. (no need to do anything)
        return;
    }

    if (ranks[x] < ranks[y]) {
        parents[x] = y; // direct connection of y to the root of x. i.e. connect the shorter's root to the longer's root.
    }
    else if (ranks[x] > ranks[y]) {
        parents[y] = x; // as above, connect the shorter's root (root of x) to the longer's root (root of y).
    }
    else {
        parents[y] = x; // if same rank, do the below increment
        ++ranks[x];
    }
}

bool same(int x, int y) { // judge if x and y are in the same group <==> x and y shares the same root.
    return find(x) == find(y);
}

void Main() {
    int n, q;
    cin >> n >> q;

    init(n);
    for (int i = 0; i < q; ++i) {
        int query, x, y;
        cin >> query >> x >> y;

        if (query == 0) { // unite
            unite(x, y);
        }
        else { // query to check if same
            cout << (same(x, y) ? 1 : 0) << endl;
        }
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3152
#include<stdio.h>
int main(void)
{
	int S;
	int h,m,s,t;
	scanf("%d",&S);
	h = S/3600;
	t = S%3600;
	m = t / 60;
	s = t%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a, b, c, ans;
    
    cin >> a >> b >> c;
    
    ans = min(a+b, a+c);
    ans = min(ans, b+c);
    
    cout << ans << endl;
    
    return 0;
    
}

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

int main() {
	int n, a[110], sum = 0, ans = 1000000;
  	cin >> n;
  	for (int i = 0; i < n; i++) cin >> a[i];
	sort (a, a + n);
  
  	for (int i = -100; i <= 100; i++) {
      	sum = 0;
    	for (int j = 0; j < n; j++) {
    		sum += (a[j] - i) * (a[j] - i);
    	}
      	ans = min(ans, sum);
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 #define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	int n,count=0;
	cin>>n;
    int a[n];
	for(int i=0;i<n;i++)
      cin>>a[i];
    sort(a,a+n);
    for(int j=0;j<n-1;j++)
        if(a[j]==a[j+1]){
          count=1;
          break;
        }
    if(count==1)
      cout<<"NO";
      else
        cout<<"YES";
     return 0;
}

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

int main(){
	int n;
	long long cnt, itmp, tmp;
	cin >> n;
	string st;
	vector<string> s(n);
	for(int i=0; i<n; i++){
		cin >> st;
		sort(st.begin(), st.end());
		s[i] = st;
	}
	sort(s.begin(), s.end());
	//for(int i=0; i<n; i++){
	//	cout << s[i] << endl;
	//}
	cnt = 0;
	itmp = 0;
	tmp = 0;
	for(int i=0; i<n-1; i++){
		if(s[i] == s[i+1]){
			itmp++;
			tmp += itmp;
		}else{
			cnt += tmp;
			itmp = 0;
			tmp = 0;
		}
	}
	cnt += tmp;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 5760
def myAnswer(S:str) -> str:
   if(S == "keyence"):return "YES"
   for i in range(len(S)-1):
      for j in range(i+1,len(S)):
         if(S[:i]+S[j:] == "keyence"):
            return "YES"
   return "NO"

def modelAnswer():
   return
def main():
   S = (input())
   print(myAnswer(S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        boolean[] b = new boolean[101];
        for (int i = 0;i < 3;i++) {
            b[sc.nextInt()] = true;
        }
        int ret = 0;
        for (int i = 1;i <= 100;i++) {
            if (b[i]) ret++;
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 9808
#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-6
#define infi 1e9
#define infll 1e18
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

string a,b,c;

int main(){
    cin>>a>>b>>c;
    cout<<(char)toupper(a[0])<<(char)toupper(b[0])<<(char)toupper(c[0])<<endl;
    return 0;
}
/*
 abcda
 
 */

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int S,h,m,s;
    cin>>S;
    h=S/3600;
    m=(S-3600*h)/60;
    s=S-3600*h-60*m;
    cout<<h<<":"<<m<<":"<<s<<endl;
return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,c,d,x,y,tmp;
bool ans;
int main() {
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
	ans=0;
	for (x=0;x<n;x++) {
		y=n-1-x;
		tmp=b-a+y*d-x*c;
		if (0LL<=tmp&&tmp<=(n-1)*(d-c)) {
			ans=1;
			break;
		}
	}
	if (ans)
		printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
using namespace std;

int main()
{
	int x, y;
	string str;
	int i;

	cin >> x >> y;

	if (x < y) {
		for (i = 0; i < y; i++) {
			printf("%d", x);
		}
	} else {
		for (i = 0; i < x; i++) {
			printf("%d", y);
		}
	}

	return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    st s ;
    st t ;
    int counter = 0 ;

    cin >> s >> t ;

    if (s[0] == t[0])
        counter ++ ;
    if (s[1] == t[1])
        counter ++ ;
    if (s[2] == t[2])
        counter ++ ;

    cout << counter << endl;

    return 0 ;
}


Measured memory_bytes: 256
r=lambda x:x if u[x]<0else r(u[x])
(n,m),_,*e=[map(int,t.split())for t in open(0).readlines()]
u=[-1]*-~n
a=[n*~-n//2]
for x,y in e[::-1]:
 t=a[-1];x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a.append(t)
print(*a[::-1],sep='\n')

Measured memory_bytes: 55916
package main

import (
	"bufio"
	"fmt"
	"os"
)

var h, w, n int
var blocks map[int]int

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &h, &w, &n)

	blocks = make(map[int]int)

	for ; n > 0; n-- {
		var x, y int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &x, &y)
		if yy, e := blocks[x]; e {
			if y < yy {
				blocks[x] = y
			}
		} else {
			blocks[x] = y
		}
	}

	right := 1
	for i := 1; i <= h; i++ {
		if v, e := blocks[i+1]; e {
			if v <= right {
				fmt.Println(i)
				return
			}
			if right+1 < v {
				right++
			}
		} else {
			right++
		}
	}
	fmt.Println(h)
}


Measured memory_bytes: 13056
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    long long ans=k;
    n--;
    if(n>0){
        for(int i=0;i<n;i++){
            ans*=k-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Restaurant {
  int id;
  string s;
  int p;
};

int main() {
  int n;
  cin >> n;
  vector<Restaurant> restaurants;
  for (int i = 0; i < n; i++) {
    string s;
    int p;
    cin >> s >> p;
    restaurants.push_back({ i + 1, s, p });
  }

  sort(
    restaurants.begin(),
    restaurants.end(),
    [](auto a, auto b) -> bool {
      if (a.s != b.s) {
        return a.s < b.s;
      }
      return a.p > b.p;
    }
  );

  for (auto i: restaurants) {
    cout << i.id << endl;
  }
  return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k;
ll r, s, p;
string t;
ll ans;
bool win[100010];

int main() {
    cin >> n >> k >> r >> s >> p >> t;
    rep(i, n) {
        if (i - k >= 0 && t[i] == t[i-k] && win[i-k]) continue;
        else {
            if (t[i] == 'r') ans += p;
            if (t[i] == 's') ans += r;
            if (t[i] == 'p') ans += s;
            win[i] = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(input())
ans=[0]*(m+1)
ans[1]=1
for i in range(n):
  for j in range(m):
    if a[i][j]==".":
      ans[j+1]+=ans[j]
      ans[j+1]%=1000000007
    else :
      ans[j+1]=0
print(ans[m])


Measured memory_bytes: 4084
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    S = input()
    N = len(S)+1
    ll = []
    j = 0
    ans = 0
    for i in range(N-1):
        if S[i:i+2] == "><":
            ll.append(S[j:i+1])
            j = i+1
    ll.append(S[j:i+1])
    for i in ll:
        p = i.count("<")
        q = i.count(">")
        if p > q:
            ans += (p*(p+1)//2+q*(q-1)//2)
        else:
            ans += (p*(p-1)//2+q*(q+1)//2)
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

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

int main(){
    int A, B; cin >> A >> B;

    if(A > 8 || B > 8){
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n,x,i,m[100],min=1000,c=0;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&m[i]);
	}
	for(i=0;i<n;i++){
		x-=m[i];
		c++;
		if(m[i]<min) min=m[i];
	}
	c=c+(x/min);
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007

ll dp[22][(1<<22)];
ll solve(vector<vector<int> >&v, int i,int womenset,int n)
{
   if(i==n+1)
   {
       if(womenset==0)
         return 1;
       return 0;
   }
   if(dp[i][womenset]!=-1)
   return dp[i][womenset];
   ll ans=0;
   for(int woman=0;woman<n;woman++)
   {
       bool available=(1<<woman)&(womenset);
       if(available==1 && v[i][woman+1]==1)
       {
           ans=(ans+solve(v,i+1,((1<<woman)^womenset),n))%mod;
       }
   }
   dp[i][womenset]=ans;
   return dp[i][womenset];
}
int main() {
    int n;
	cin>>n;
	vector<vector<int> >v(n+1,vector<int>(n+1));
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=n;j++)
	    {
	        cin>>v[i][j];
	    }
	}
	cout<<solve(v,1,((1<<n)-1),n)<<"\n";
	return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int a;
  int counter = 0;

  for(int i = 0 ; i < N ; ++i){
    cin >> a;
    if(a < abs(K - a))counter += a;
    else counter += abs(K - a);
  }

  counter *= 2;
  cout << counter << endl;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let l: u64 = sc.read();
    let t: u64 = sc.read();
    let xw: Vec<_> = (0..n)
        .map(|_| (sc.read::<u64>(), sc.read::<u32>() == 1))
        .collect();

    let n = n as u64;
    let mut clock_count = 0;
    let mut clock_on = 0;
    let mut counter_count = 0;
    let mut counter_on = 0;
    for &(x, clockwise) in xw.iter() {
        if clockwise {
            clock_count += (x + t) / l;
            if (x + t) % l == 0 {
                clock_on += 1;
            }
        } else {
            counter_count += (l - x + t - 1) / l;
            if (l - x + t) % l == 0 {
                counter_on += 1;
            }
        }
    }

    clock_count %= n;
    counter_count %= n;
    let mut end_state = xw
        .iter()
        .map(|&(x, clockwise)| {
            if clockwise {
                ((x + t) % l, clockwise)
            } else {
                ((l - (l - x + t) % l) % l, clockwise)
            }
        })
        .collect::<Vec<_>>();
    end_state.sort();
    let first = (clock_count - counter_count + n) % n;
    for i in 0..n {
        //        eprintln!("{:?}", end_state[((first + i) % n) as usize]);
        println!("{}", end_state[((first + i) % n) as usize].0);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 9340
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(string& s, string& t) {
        int n = s.length();
        int m = t.length();

        const int A = 26;
        string S = s + s;
        int N = S.length();
        vector<vector<int>> next(N + 1, vector<int>(A, -1));
        for (int i = N - 1; i >= 0; --i) {
            next[i] = next[i + 1];
            next[i][S[i] - 'a'] = i;
        }

        long long res = 0;
        for (int i = 0; i < m; ++i) {
            int u = res % n;
            int v = next[u][t[i] - 'a'];
            if (v == -1) {
                return -1;
            }
            res += v - u + 1;
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;
    Solution sol;

    cout << sol.solve(s, t) << "\n";

    return 0;
}

Measured memory_bytes: 27344
#include<stdio.h>
#include<stdlib.h>
long long c[100000];

int cmp(const void *a,const void *b){
	return *(long long*)a- *(long long*)b;
}

int main(int argc, char const *argv[]){
	long long n,i,sum=0,lim=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&c[i]);
	}
	qsort(c,n,sizeof(long long),cmp);
	for(i=0;i<n-1;i++){
		sum+=c[i];
		if(c[i+1]>sum*2) lim=i+1;
	}
	printf("%lld\n",n-lim);
	return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <functional>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <cstdio>

using namespace std;

int main(){
    int n,k, a;
    cin >> n;
    cin >> k;
for (int i = 0; i < n; i++){
        cin >> a;
    }
    if ((n - 1) % (k - 1))
        cout << (n - 1) / (k - 1) + 1<< endl;
    else
        cout << (n - 1) / (k - 1) << endl;
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1[0]) << (char) toupper(s2[0]) << (char)toupper(s3[0]) << endl;
}

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

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int M = Integer.parseInt(scan.next());

	Map<Integer, Node> nodes = new HashMap<Integer, Node>();
	nodes.put(1, new Node(0));
	for (int i = 2; i <= N; i++) {
	    nodes.put(i, new Node(N * 1000000000L));
	}

	List<Edge> edges = new ArrayList<Edge>(M);
	for (int i = 0; i < M; i++) {
	    int a = Integer.parseInt(scan.next());
	    int b = Integer.parseInt(scan.next());
	    long c = Long.parseLong(scan.next());

	    edges.add(new Edge(nodes.get(a), nodes.get(b), -c));
	}

	for (int i = 0; i < N-1; i++) {
	    for(Edge edge: edges) {
		Node s = edge.source;
		Node d = edge.destination;
		long tmp = s.distance + edge.weight;
		d.distance = tmp < d.distance ? tmp : d.distance;
	    }
	}
	String ans = String.valueOf(-nodes.get(N).distance);

	for (int i = 0; i < N; i++) for(Edge edge: edges) {
	    Node s = edge.source;
	    Node d = edge.destination;
	    long tmp = s.distance + edge.weight;
	    if(tmp < d.distance) {
		d.distance = tmp;
		d.negative = true;
	    }
	}
	ans = nodes.get(N).negative ? "inf" : ans;
	System.out.println(ans);
	scan.close();
    }
}

class Node {
    long distance;
    boolean negative = false;

    Node(long d) {
	distance = d;
    }
}

class Edge {
    Node source;
    Node destination;
    long weight;

    Edge(Node s, Node d, long w) {
	source = s;
	destination = d;
	weight = w;
    }
}


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

int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int l[n], r[n];
  rep(i, n){
    if(i == 0){
      l[i] = a[0], r[n-1] = a[n-1];
    } else {
      l[i] = gcd(a[i], l[i-1]), r[n-1-i] = gcd(a[n-i-1], r[n-i]);
    }
  }
  int ans = 0;
  rep(i,n){
    int c = 0;
    if(!i) c = r[1];
    else if(i == n-1) c = l[n-2];
    else c = gcd(l[i-1], r[i+1]);
    ans = max(ans,c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408