akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#define HMAX 20
#define WMAX 20
using namespace std;
typedef pair<int,int> P;

int map[HMAX][WMAX];
int w,h;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int solve(int x,int y,int l)
{
  int sx,sy,mt = 11,t;
  if(l>=10)return -1;
  for(int i = 0;i < 4;i++)
  {
    sx = x;
    sy = y;
    while(true)
    {
      sx += dx[i];
      sy += dy[i];
      if(sx < 0 ||sx >= w||sy < 0||sy >= h)
        break;
      if(map[sy][sx] == 1)
      {
        if((sx - dx[i]) == x && (sy - dy[i]) == y)
          break;
        map[sy][sx] = 0;
        t = solve(sx - dx[i],sy - dy[i],l+1);
        if(t != -1 && t < mt)
          mt = t;
        map[sy][sx] = 1;
        break;
      }
      if(map[sy][sx] == 3)
        return (l + 1);
    }
  }
  if(mt > 10)
    return -1;
  return mt;
}

int main(void)
{
  int i,j,sx,sy;
  cin>>w>>h;
  while(w != 0)
  {
    for(i = 0;i < h;i++){
      for(j = 0;j < w;j++){
        cin>>map[i][j];
        if(map[i][j] == 2){
          sx = j;
          sy = i;
        }
      }
    }
    cout<<solve(sx,sy,0)<<endl;
    cin>>w>>h;
  }
  return 0;
}

Measured memory_bytes: 1160
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, a, b;
    scan(n, a, b);
    auto mx = min(a, b);
    auto mn = max(0, a + b - n);
    writeln(mx, " ", mn);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007
 
ll O[60];
 
int main(){
	int N; cin>>N;
	rp(i,0,N){ ll a; scanf("%lld",&a); for(int j=0; j<60 && a; ++j, a>>=1) O[j]+=a&1; }
	ll ans = 0;
	rp(i, 0, 60) ans = (ans + (O[i]*(N-O[i]) % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<< ans <<endl;
}

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

int main(){
	long long n,k;
	cin>>n>>k;
	
	if(n<k){
	    cout<<min(abs(k-n),n)<<endl;
	    return 0;
	}

	if(n==k){
	    cout<<0<<endl;
	    return 0;
	}
	
	if(n>k){
		cout<<min(k-n%k,n%k)<<endl;
		return 0;
	}
	
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m,k; cin >> n >> m >> k;
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= m; ++j){
      if(i*m+j*n-2*i*j == k){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

#define N 100005

int n;

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    cout << (n - 2) * 180;
    return 0;
}


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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int boss[200050];

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

	int N, ai;

	cin >> N;

	for(int i = 2; i <= N; i++){
		cin >> ai;
		boss[ai]++;
	}

	for(int i = 1; i <= N; i++){
		cout << boss[i] << "\n";
	}
	return 0;		
}



Measured memory_bytes: 4328
from sys import stdin
inf = 10**3
n = int(stdin.readline().rstrip())
k = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in li:
    if abs(i-k) >= i:
        point += 2*i
    else:
        point += abs(i-k)*2

print(point)


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

int main() {
    string ans = "YES";
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    int count = 0;
    rep(i, N) {
        if(p[i] != i + 1)
            count++;
    }
    if(count > 2)
        ans = "NO";

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int sum=0;
	int a[m+1];
	for(int i=1;i<=m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n){
		cout<<"-1"<<endl;
	}else{
		cout<<n-sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] S = in.nextLine().toCharArray();
		String result = "WA";
		if (S[0] == 'A') {
			if (hasC(S) && smallCheck(S)) {
				result = "AC";
			}
		}
		System.out.println(result);
		in.close();
	}

	public static boolean hasC(char[] C) {
		int count = 0;
		for (int i = 2; i < C.length - 1; ++i) {
			if (C[i] == 'C') {
				++count;
			}
		}
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean smallCheck(char[] C) {
		int count = 0;
		for (int i = 0; i < C.length; ++i) {
			if (Character.isUpperCase(C[i])) {
				++count;
			}
		}
		if (count == 2) {
			return true;
		} else {
			return false;
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	if (R < 1200) cout << "ABC" << endl;
	else if (R < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,a,sum;
  cin>>n>>k;
  sum=0;
  for(int i=0; i<n; i++){
    cin>>a;
    if(a<=k-a){
      sum+=2*a;
    } else {
      sum+=2*(k-a);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int S[1000000];
int n;

int bsearch(int key){
  int left=0;
  int right=n;
  int mid;

  while(left < right){
    mid = (left + right)/2;
    if(key==S[mid]) return 1;
    if(key>S[mid]) left=mid+1;
    else if(key<S[mid])right=mid;
    }
  return 0;
}

int main(){
  int q,C,key;
  int i,j;
  int count=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&key);
    if(bsearch(key)) count++;
  }

  int left=0;
  int right=n;
  int mid;



  printf("%d\n",count);

  return 0;

}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define mod 1000000000+7;
typedef long long ll;
using namespace std;

const int N = 1e7+5;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n; cin >> n;
    int ac{},wa{},tle{},re{};
    while(n--){
        string s; cin >> s;
        if(s=="AC") ++ac;
        else if(s=="TLE") ++tle;
        else if(s=="WA") ++wa;
       else ++re;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re<< "\n";
}


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

int main() {
  int h,w;
  cin>>h>>w;
  char c[h+2][w+2];
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
      cin>>c[i][j];
  bool ans=true;
  
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
      if(c[i][j]=='#')
        if(c[i-1][j]!='#' && c[i+1][j]!='#' && c[i][j-1]!='#' && c[i][j+1]!='#')
          ans=false;
  
  if(ans)
    cout<<"Yes";
  else cout<<"No";
        

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
void dfs(int a,int b)
{
  if(a==N)
  {
    puts(S.c_str());
    return ;
  }
  for(int i=0;i<=b+1;i++)
  {
    S[a]='a'+i;
    dfs(a+1,max(b,i));
  }
  return ;
}
int main()
{
  cin>>N;
  dfs(0,-1);
  return 0;
}

Measured memory_bytes: 1536
r, g, b, n = gets.split.map(&:to_i)
ans = 0

for i in 0 .. n
  for j in 0 .. n
    if i * r + j * g > n
      break
    elsif (n - i * r - j * g) % b == 0
      ans += 1
    end
  end
  if i * r > n
    break
  end
end

puts ans


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll ans=-1,l;    
    string s,s1,s2;
    cin>>l>>s;

    for(int i=1;i<l;i++)
    {
        int cnt=0;
        s1=s.substr(0,i);
        s2=s.substr(i,l-1);
        //cout<<s1<<" "<<s2<<endl;
        set<char>x,y;
        for(int i=0;i<s1.length();i++)
            x.insert(s1[i]);
        for(int i=0;i<s2.length();i++)
            y.insert(s2[i]);
        for(auto c: x)
        {
            cnt+=y.count(c);               //return 1 or 0 only
        }
        if(cnt>ans)
            ans=cnt;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         998244353
#define mode        1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 1e5+5;
ll n,a[N];

void solve()
{
       ll co=0,ce=0;
       cin>>n;
       ll x;
       rep(i,0,n)
       {
              cin>>x;
              if(x&1) co++;
              else ce++;
       }
       if(co&1) cout<<"NO";
       else cout<<"YES";
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
for(int i=0;i+2<n;i++)
{
if(s.substr(i,3)=="ABC")
{
ans++;
}
}
cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main()
{
    int c=0, i=0,flag=0;
    string s; cin>>s;
    if(s[0]!= 'A'){
            cout<<"WA";
    return 0;}

    for( i=2; i<=s.size()-2; ++i){
        if(s[i]=='C'){
            c=1;
            break;
        }

        }

     for(int j=1; j<s.size();++j){
            if(islower(s[j])){
               //flag=0;
               continue;

            }
            else if( isupper(s[i]) && i==j)
                continue;
            else
             {
            flag=1;
            break;}

    }
    if(c==0) {cout<<"WA"; return 0;}
    if(flag==1)
        cout<<"WA";
    else
        cout<<"AC";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h,x,y;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	scanf("%d",&f);
	scanf("%d",&g);
	scanf("%d",&h);
	x=a+b+c+d;
	y=e+f+g+h;
	if(x>=y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
	
	return 0;
}



Measured memory_bytes: 2692
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)cin >> B[i];
	for (int i = 0; i < N; i++)cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	vector<ll> b(N), b_(N+1, 0);
	for (int i = 0; i < N; i++) {
		b[i] = C.end() - upper_bound(C.begin(), C.end(), B[i]);
		//cout << b[i] << endl;
	}
	
	for (int i = 0; i < N; i++) {
		b_[i+1] = b_[i] + b[i];
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		int pos = upper_bound(B.begin(), B.end(), A[i]) - B.begin();
		if (pos == N)continue;
		//cout << b_[N] - b_[pos] << endl;
		ans += b_[N] - b_[pos];
	}
	cout << ans << endl;
}

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

int main(void){

    int c[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }

    int a[3], b[3];
    rep(i, 101){
        a[0] = i;
        b[0] = c[0][0] - a[0];
        b[1] = c[0][1] - a[0];
        b[2] = c[0][2] - a[0];
        a[1] = c[1][0] - b[0];
        a[2] = c[2][0] - b[0];

        bool check = true;
        rep(j, 3){
            rep(k, 3){
                if(c[j][k] != a[j] + b[k]){
                    check = false;
                }
            }
        }

        if(check == true){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
 
int main()
{
    int c,n,a;
    cin >>n>>c;
    int sum=0;
    for (int i = 1; i <= c; i++) {
        cin >> a;
        sum += a;
    }
    int ans = sum / (n + 1);
    if (sum - ans * (n + 1) > 0)ans++;
    cout << ans << endl;
     
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
  int N,cnt;
  cin >> N;
  cnt = N/7;
  for(int i = 0; i <= cnt;i++){
    if((N - 7*i)%4 == 0){
      cout << "Yes" << "\n";
      return 0;
    }
  }  
  cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MX=2e5+5;
int n,m,x,y,mx,a[MX];
int root(int i){
    return a[i]<0 ? i : (a[i]=root(a[i]));
}
void join(int x,int y){
    x=root(x),y=root(y);
    if(x==y) return;
    if(a[x]>a[y]) swap(x,y);
    a[x]+=a[y];
    a[y]=x; 
}
int main()
{
    cin >> n >> m;
    for(int i=0; i<=n; i++) a[i]=-1;
    for(int i=0; i<m; i++){
        cin >> x >> y;
        join(x,y);
    }
    for(int i=1; i<=n; i++){
        if(a[i]<0) mx=max(mx,-a[i]);
    }
    cout << mx;
    return 0;
}

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

int c[] = {100000, 200000, 300000};

int X, Y;
int main(){
	scanf("%d %d", &X, &Y);
	
	if(X == 1 && Y == 1)printf("1000000\n");
	else{
		int res = 0;
		if(X <= 3)res += c[3 - X];
		if(Y <= 3)res += c[3 - Y];
		
		printf("%d\n", res);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define endl '\n'
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 <<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* coma = strchr(names + 1, ',');cerr.write(names, coma - names) << " : " << arg1<<" | ";__f(coma+1, args...);
}
#else
#define trace(...)
#endif
 
void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}

const int MX = 1e5 + 5;

int n, w;

ll u[105], v[105], dp[105][MX];

ll solve(int idx, int sum)
{
    if(sum > w)return LLONG_MIN;
    if(idx == n)return 0;
    ll & ret = dp[idx][sum];
    if(~ret)return ret;
    ll c1 = solve(idx + 1, sum);
    ll c2 = solve(idx + 1, sum + u[idx]) + v[idx];
    return ret = max(c1, c2);
}

int main(int argc, char const *argv[])
{
    // file();
    fast();

    cin>>n>>w;

    for (int i = 0; i < n; ++i)
    {
        cin>>u[i]>>v[i];
    }
    clr(dp, -1);
    cout<<solve(0, 0);
  
}

Measured memory_bytes: 82304
sentinel = 1000000001

def merge(A, left, mid, right):
    """Merge the two sorted partial sequences A[left:mid] and A[mid:right].

    To count the number of inversions,
    make a global declaration for the variable cnt.
    """
    L = A[left:mid]
    n1 = len(L)
    L.append(sentinel)
    R = A[mid:right]
    R.append(sentinel)
    i = 0
    j = 0
    global cnt
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += (n1 - i)

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


n = int(input())
S = list(map(int, input().split()))

cnt = 0

mergeSort(S, 0, n)

print(cnt)

Measured memory_bytes: 30372
#include<stdio.h>

int main(void) {
int H,W;
int x,y;
int flagx = 0;
int flagy = 0;

while(scanf("%d %d", &H, &W), (H+W) != 0) {
  for (y = 0; y < H; y++) {
    if (flagy == 0) {
      flagy = 1;
    } else {
      flagy = 0;
    }
    for (x = 0; x < W; x++) {
      if (x == 0) {
        if (flagy == 1) {
          printf("#");
          flagx = 0;
        } else {
          printf(".");
          flagx = 1;
        }
      } else {
        if (flagx == 1) {
          printf("#");
          flagx = 0;
        } else {
          printf(".");
          flagx = 1;
        }
      }
    }
  printf("\n");
  }
  flagy=0;
  printf("\n");
}
  return (0);
}

Measured memory_bytes: 572
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 300005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int k,n,a[MN],cur,cnt;
int main()
{
	k=in();n=in();
	if (!(k&1)){
		printf("%d ",(k>>1));
		for (int i=2;i<=n;++i) printf("%d ",k);
	}else {
		for (int i=1;i<=n;++i) a[i]=(k>>1)+1,++cnt;cur=n;
		for (int j=1;j<=(cnt>>1);++j){
			--a[cur];if  (!a[cur]) --cur;
			else{
				for (int i=cur+1;i<=n;++i) a[i]=k;cur=n; 
			}		
		}
		for (int i=1;i<=cur;++i) printf("%d ",a[i]);
	}return 0;
}

Measured memory_bytes: 3328
n,T=map(int,input().split())
data=[input().split() for i in range(n)]
lc=[]
for row in data:
    if int(row[1]) <=T:
        lc.append(row[0])
ls=[int(j) for j in lc]

if not lc:
    print("TLE")
else:
    print(min(ls))

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

int main()
{
	auto start = steady_clock::now();

	int D;
	vector<int> cs(26);
	cin >> D;
	for (auto &&c : cs)
	{
		cin >> c;
	}
	vector<vector<int>> sss(D, vector<int>(26));
	for (auto &&ss : sss)
	{
		for (auto &&s : ss)
		{
			cin >> s;
		}
	}

	vector<int> ts(D, 0);

	auto calc_score = [&] {
		vector<int> last(26, -1);

		int s = 0;

		for (int d = 0; d < D; d++)
		{
			s += sss[d][ts[d]];

			last[ts[d]] = d;

			for (int i = 0; i < 26; i++)
			{
				s -= cs[i] * (d - last[i]);
			}
		}

		// return max(0, 1000000 + s);
		return s;
	};

	auto calc_diff = [&](int d, int q) {
		int p = ts[d];

		ts[d] = q;

		int ret = calc_score();

		ts[d] = p;

		return ret;
	};

	int score = calc_score();

	while (duration_cast<milliseconds>(steady_clock::now() - start).count() < 1960)
	{
		for (int d = 0; d < D; d++)
		{
			for (int q = 0; q < 26; q++)
			{
				if (ts[d] == q)
				{
					continue;
				}

				int next_score = calc_diff(d, q);

				if (score < next_score)
				{
					ts[d] = q;
					score = next_score;
				}
			}
		}
	}

	for (auto &&t : ts)
	{
		cout << t + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	ll H;
	cin >> H;
	ll ans=0, num=1, now=H;
	while(now>0){
		ans += num;
		num *= 2;
		now /= 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int p,m = 10e6;
	int ans=0;
	while(n)
	{
		cin>>p;
		if(p <= m)
		{
			ans++;
			m = p; 
		}
		n--;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        while (true) {
            int n = Integer.parseInt(sc.next())
               ,x = Integer.parseInt(sc.next());
            if (n == 0 && x == 0)   break;
            pw.println(answer(n,x));
        }
        pw.flush();
    }
    
    public static int answer(int n, int x) {
        int i, j, k, ans = 0;
        for (i = 1; i <= n; i++)
            for (j = i+1; j <= n; j++)
                for (k = j+1; k <= n; k++)
                    if (i + j + k == x) {
//                        System.out.print(i + " ");
//                        System.out.print(j + " ");
//                        System.out.println(k);
                        ++ans;
                    }
        return ans;
    }
}


Measured memory_bytes: 26504
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll K, A, B;
  cin>>K>>A>>B;
  if(B-A<=2 || K<A-1) cout<<1+K<<endl;
  else {
    K -= A-1;
    if(K%2==0) {
      cout<<A+K/2*(B-A)<<endl;
    }
    else {
      cout<<A+K/2*(B-A)+1<<endl;
    }
  }
}



Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t=(C+B-1)/B, a=(D+A-1)/D;
    cout << (t<=a ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	string a;
	int c=0;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='C')
			c++;
		if(c&&a[i]=='F')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

if n == 2:
    if a[0] > a[1]:
        print(a[0],a[1])
    else:
        print(a[1],a[0])
else:
    x = max(a)
    mid = x / 2
    a.remove(x)

    diff = abs(mid - a[0])
    ans = 0
    for i in range(len(a)):
        if diff > abs(mid - a[i]):
            diff = abs(mid - a[i])
            ans = i
    print(x,a[ans])


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	ll n;
	cin>>n;
	ll ans=((n*n)*(n+1))/2;
	ans-=((n-1)*n*(n+1))/3;
	int u,v;
	fr(i,0,n-1){
		cin>>u>>v;
		if(u>v)
			swap(u,v);
		ans-=(u*(n-v+1));
	}
	cout<<ans<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=1e4+10;
const int maxm=1e6+10;
const ll mod=1e9+7;

int n,a[maxn],mx[maxm];
bool p[maxm];
vector <pair<int,int> > g[maxn];

ll quickmod(ll a,ll b){
	ll sum=1;
	while(b){
		if(b&1)
		sum=(sum*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return sum;
}

void exgcd(ll a,ll b,ll& d,ll& x,ll& y){
    if(!b) { d=a; x=1ll; y=0ll; }
	else{ exgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
 
ll inv(ll a, ll p){
	ll d,x,y;	
	exgcd(a,p,d,x,y);
	return d == 1ll ? (x+p)%p : -1ll;
}

void get_int(int x,int id){
	for(int i=1;i*i<=x;i++){
		if(x%i!=0) continue;
		if(p[i]){
			int val=x,cnt=0;
			while(val%i==0){
				cnt++;
				val/=i;
			}
			mx[i]=max(mx[i],cnt);
			g[id].pb(mp(i,cnt));
		}
		if(i*i!=x&&p[x/i]){
			int val=x,cnt=0;
			while(val%(x/i)==0){
				cnt++;
				val/=(x/i);
			}
			mx[x/i]=max(mx[x/i],cnt);
			g[id].pb(mp(x/i,cnt));
		}
	}
}

int main(){
	for(int i=0;i<maxm;i++) p[i]=1;
	p[1]=0;
	for(int i=2;i*i<maxm;i++){
		if(p[i])
			for(int j=i*i;j<maxm;j+=i) p[j]=0; 
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		get_int(a[i],i);
	}
	ll o=1ll;
	for(int i=2;i<maxm;i++) o=(o*quickmod(i,mx[i]))%mod;
	ll ans=0ll;
	for(int i=0;i<n;i++){
		ll sum=o;
		for(int j=0;j<g[i].size();j++){
			sum=(sum*inv(quickmod(g[i][j].fst,g[i][j].snd),mod))%mod;
		}
		ans=(ans+sum)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5120
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long
#define all(v) v.begin(),v.end()
using namespace std;
int main () {
  int N,M ;cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> A(M);
  rep(i,M){
    cin >> k[i];
    rep(j,k[i]){
      int a; cin >>a;
      A[i].push_back(a-1);
    }
  }
  vector<int> p(M);
  rep(i,M) cin >> p[i];
  int count=0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<10> s(tmp);  // 最大10個なので10ビットのビット列として扱う
    bool ans=true;
    rep(i,M){ 
      int sum = 0;
      for (int j = 0; j < k[i]; j++) if(s.test(A[i][j])) sum++;
      if (sum%2 != p[i])ans=false;
    }
    if(ans)count++;
  }
  cout <<count<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> AC;
    AC.push_back(0);

    //入力
    vector<int> X(Q), Y(Q);
    for(int i=0; i<Q; i++) {
        int a,b;
        cin >> X[i] >> Y[i];
    }

    //Sの"AC"をカウントして存在した位置をvectorにpush_back
    int count = 0;
    for(int i=1; i<N; i++) {
        if(S[i-1] == 'A' && S[i] == 'C'){
            count++;
        }
        AC.push_back(count);
    }

    for(int i=0; i<Q; i++) {
        cout << AC[Y[i]-1] - AC[X[i]-1] << endl;
    }
}

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

using namespace std;

int main() {
	int N; string S;
	cin >> N >> S;
	
	if (N%2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i=0; i<N/2; i++) {
		if (S.at(i) != S.at(i+N/2)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static char[] c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        c = sc.next().toCharArray();
        char n = c[0];
        int count = 0;
        for (int i = 1; i < c.length; i++) {
            if (n != c[i]) {
                count++;
                n = c[i];
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 26576
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans = 0;
    if(n == 1) cout << 1 << endl;
    else if(n == 2) cout << 2 << endl;
    else{
        for(int i = 0; i < n; i++){
            if(pow(2,i) > n) {
            cout << pow(2,i-1) << endl;
            return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,x,x1,x2;

    scanf("%d%d",&a,&b);
    x=(a+b);

    if(x%2==0)
        {
            x1=x/2;
        printf("%d\n",x1);
    }
    else{
            x2=(x/2)+1;
        printf("%d\n",x2);
    }

    return 0;
}


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

 int main() {
   int n;
   cin >> n;
   vector<int> x(n);
   int ave = 0;
   for (int i = 0; i < n; i++) {
     cin >> x[i];
     ave += x[i];
   }
   ave = ave/n;
   int avd = ave+1;
   int sum = 0;
   int sud = 0;
   for (int i = 0; i < n; i++) {
     sum += (x[i] - ave)* (x[i] - ave);
   }
   
   for (int i = 0; i < n; i++) {
     sud += (x[i] - avd)* (x[i] - avd);
   }
   if (sud< sum) {
     sum = sud;
   }
   cout << sum << '\n';
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
void NK(lli& N, lli& K){
    while(true){
            if(abs(N-K)<N)N = abs(N-K);
            else break;
        }
}
int main(){
    lli N,K;
    cin>>N>>K;
    if(N<=K){
        NK(N,K);
    }
    else{
        lli rem = N%K;
        if(!rem)N = 0;
        else{
            N -= (N/K) * K;
            NK(N,K);
        }
    }
    cout<<N;
    return 0;
}

Measured memory_bytes: 256
#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)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int A,B,M;

    cin>>A>>B>>M;
    vector<ll> a(A);
    ll mina = INFLL;
    rep(i,A){
        cin>>a[i];
        chmin(mina, a[i]);
    }
    vector<ll> b(B);
    ll minb = INFLL;
    rep(i,B){
        cin>>b[i];
        chmin(minb, b[i]);
    }
    ll ans = mina+minb;
    rep(i,M){
        int x,y,c;
        cin>>x>>y>>c;
        x--;y--;
        chmin(ans, a[x] + b[y] - c);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
#include <map>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const int MAX_N = 100100;
 
ll H,W,N;
ll ans[10];
map<pair<int, int>, int> m;
int main(){
    cin >> H >> W >> N;
    REP(i,N){
        ll a,b;
        cin >> a >> b;
        a--, b--;
        for(int k = a-2; k <= a; k++){
            for(int l = b-2; l <= b; l++){
                if(0 <= k && k+2 < H && 0 <= l && l+2 < W){
                    m[make_pair(k,l)]++;
                }
            }
        }
    }

    int sum = 0;
    for(auto&& x : m){
        //printf("x:%d\n", x.second);
        ans[x.second]++;
        sum++;
    }

    ans[0] = (H-2)*(W-2) - sum;
    for(int i = 0; i < 10; i++){
        printf("%lld\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 56448
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if(a- 2*b <= 0)
		cout << 0;
	else
		cout << a -2*b;
	return 0;
}

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

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

  vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));

  rep(i, s.size()) {
    rep(j, t.size()) {
      if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
  }

  string lcs;

  // 復元
  int d = dp[s.size()][t.size()];
  int i = s.size();
  int j = t.size();
  while(true) {
    if(d==0) break;
    if(dp[i-1][j] == d) i--;
    else if(dp[i][j-1] == d) j--;
    else {
      lcs.push_back(s[i-1]);
      i--; j--; d--;
    }
  }

  reverse(lcs.begin(), lcs.end());

  cout << lcs << endl;
  return 0;
}


Measured memory_bytes: 38500
import Data.Char
import Data.List
import Data.Maybe

shiftChar :: Int -> Char -> Char
shiftChar n c
    | isLower c = chr $ ord 'a' + mod (ord c - ord 'a' + n) 26 
    | otherwise = c

caesar :: Int -> String -> String
caesar n = map (shiftChar n)

includeKey :: String -> Bool
includeKey s = any (\k -> isInfixOf k s) ["the", "this", "that"]

unceaser :: String -> String
unceaser s = fromJust $ find includeKey [caesar i s | i <- [1 .. 26]]

main :: IO ()
main = putStr . unlines . map unceaser . lines =<< getContents

Measured memory_bytes: 4060
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int max = 0;
		for(int i=0;i<=k;i++){
			for(int j=0;j<=k-i;j++){
				int x = a*(int)Math.pow(2,i) + b*(int)Math.pow(2,j) + c*(int)Math.pow(2,k-i-j);
				max = (int)Math.max(max, x);
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22996
#include<stdio.h>
int main()
{
    int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&a==c)
		printf("1");
	else if(a==b&&a!=c||a==c&&a!=b||b==c&&b!=a)
		printf("2");
	else
		printf("3");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;

namespace ConsoleApplication3
{


    class Program
    {



        static void Main(string[] args)
        {
            int S,T = 0;
            var result = new List<string>(); 
            
            String Data = Console.ReadLine();
            S = Int32.Parse(Data);
            string[] Smatrix ;
            Data = Console.ReadLine();
            Smatrix = Data.Split(' ');

            Data = Console.ReadLine();
            T = Int32.Parse(Data);
            string[] Qmatrix;
            Data = Console.ReadLine();
            Qmatrix = Data.Split(' ');

            if (S > T)
            {
                for (int i = 0;i < S ;i++)
                    for (int j = 0; j < T; j++)
                    {
                        if (Smatrix[i] == Qmatrix[j])
                        {
                            if(!result.Contains(Smatrix[i]))
                                result.Add(Smatrix[i]);
                        }
                    }
            }
            else
            {
                for (int i = 0;i < T ;i++)
                    for (int j = 0; j < S; j++)
                    {
                        if (Smatrix[i] == Qmatrix[j])
                        {
                            if (!result.Contains(Smatrix[i]))
                                result.Add(Smatrix[i]);
                        }
                    }
            }
            Console.WriteLine(result.Count);

        }
    }
}



Measured memory_bytes: 18012
def retm(a,b):
  if a%b>0:
    return 1
  else:
    return 0

th,ta,ah,aa=map(int,input().split())
if int(ah/ta)+retm(ah,ta)<=int(th/aa)+retm(th,aa):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9180
#include<iostream>

int min(int n, int m){
  if(n < m) return n;
  else return m;
}
int max(int n, int m){
  if(n < m) return m;
  else return n;
}

int main(){
  int d1, d2;
  std::cin >> d1 >> d2;
  while(d1 != 0 || d2 != 0){
    std::cout << min(d1, d2) << " " << max(d1, d2) << std::endl;
    std::cin >> d1 >> d2;
  }
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] blue = new String[n];
		for (int i = 0; i < blue.length; i++) {
			blue[i] = br.readLine();
		}
		int m = Integer.parseInt(br.readLine());
		String[] red = new String[m];
		for (int i = 0; i < red.length; i++) {
			red[i] = br.readLine();
		}

		int maxv = 0;
		for (String s : blue) {
			int cnt = 0;
			for (int i = 0; i < blue.length; i++) {
				if (s.equals(blue[i])) {
					cnt++;
				}
			}
			for (int j = 0; j < red.length; j++) {
				if (s.equals(red[j])) {
					cnt--;
				}
			}
			maxv = Math.max(maxv, cnt);
		}
		System.out.println(maxv);
	}
}


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

int main(){
    string a,b;
    cin >> a >> b ;
    if(a == "D" && b == "D"){
        cout << "H"<< endl;

    }
    if(a == "H" && b == "D"){
        cout << "D"<< endl;
    
    }
    if(a == "D" && b == "H"){
        cout << "D"<< endl;
    
    }
    if(a == "H" && b == "H"){
        cout << "H"<< endl;
    
    }

}

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

using namespace std;

int N, pos;
vector<int> pre, in, post;

void rec(int left, int right) {
  if (left >= right) {
    return;
  }
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(left, m);
  rec(m + 1, right);
  post.push_back(root);
}

void solve() {
  pos = 0;
  rec(0, pre.size());
  for (int i = 0; i < N; i++) {
    if (i) {
      cout << " ";
    }
    cout << post[i];
  }
  cout << endl;
}

int main() {
  cin >> N;

  int k;
  for (int i = 0; i < N; i++) {
    cin >> k;
    pre.push_back(k);
  }

  for (int i = 0; i < N; i++) {
    cin >> k;
    in.push_back(k);
  }

  solve();

  return 0;
}


Measured memory_bytes: 3164
N, M = (int(x) for x in input().split())
H = list(map(int, input().split()))

HT = [0 for i in range(N)]

for i in range(M):
    A, B = (int(x) for x in input().split())
    HT[A-1] = max(HT[A-1], H[B-1])
    HT[B-1] = max(HT[B-1], H[A-1])
    
count = 0

for i in range(N):
    count += H[i] > HT[i]

print(count)

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

int main() {
    int N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int j =1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  int64_t T;
  cin >> N >> T;
  vector<int64_t> A, B, C;
  for (int i = 0; i < N; i++) {
    int64_t a, b;
    cin >> a >> b;
    if (a == 0) {
      C.emplace_back(b + 1);
    } else {
      A.emplace_back(a);
      B.emplace_back(b);
    }
  }
  vector<int> idx(A.size());
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(),
       [&](int a, int b) { return A[b] * (B[a] + 1) < A[a] * (B[b] + 1); });
  vector<int64_t> dp(31, T + 1);
  dp[0] = 0;
  for (int i : idx) {
    for (int j = (int)dp.size() - 2; j > -1; j--) {
      if (dp[j] > T) continue;
      chmin(dp[j + 1], (A[i] + 1) * (dp[j] + 1) + B[i]);
    }
  }
  sort(C.begin(), C.end());
  for (int i = 0; i < (int)C.size() - 1; i++) {
    C[i + 1] += C[i];
  }
  int res = 0;
  for (int i = 0; i < (int)dp.size(); i++) {
    if (dp[i] > T) continue;
    int p = upper_bound(C.begin(), C.end(), T - dp[i]) - C.begin();
    res = max(res, i + p);
  }
  cout << res << '\n';
  return 0;
}


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

ab = [list(map(int, input().split())) for _ in range(M)]

ans = []
for n in range(1, N+1):
    count = 0
    for i in range(M):
        for j in range(2):
            if ab[i][j] == n:
                count += 1
    ans.append(count)


for a in ans:
    print(a)

Measured memory_bytes: 40048
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		int[] B = new int[n];
		int[] C = new int[n-1];
		for(int i = 0; i < n; i++) {
			A[i] = sc.nextInt()-1;
		}
		for(int i = 0; i < n; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++) {
			C[i] = sc.nextInt();
		}
		int res = 0;
		for(int i = 0; i < n; i++) {
			res += B[A[i]];
			if(i > 0 && A[i] == A[i-1]+1) {
				res += C[A[i-1]];
			}
		}
		System.out.println(res);
	}

}


Measured memory_bytes: 21716
function setUp(input) {
  input = input.split("\n");
  S = input[0];
  sList = S.split('');
  main();
}
function main() {
  var countOdd = 0;
  var countEven = 0;
  sList.forEach(function (d, i) {
    var target = i % 2;
    var oddTarget = target ? '0' : '1';
    var evenTarget = target ? '1' : '0';
    if (d != oddTarget) {
      countOdd++;
    }
    if (d != evenTarget) {
      countEven++;
    }
  })
  console.log(Math.min(countOdd, countEven));
}

setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
ll mod = 1000000007;



struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    int siz; //素集合の数

    UnionFind(int N) : par(N), siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        siz--;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};



void solve(){
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x,y);
    }
    cout << uf.siz << endl;
}

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

Measured memory_bytes: 640
c,d,t,u,sz;
long s;
char x[18],buf[5<<17];
main()
{
	read(0,buf,5<<17);
	c=*buf;
	while(c!=10)
	{
		++t;
		d=buf[++sz];
		if(c!=d)
		{
			s+=(long)t*(t+1)>>1;
			if(c=='>')s-=t<u?t:u;
			u=t;
			t=0;
			c=d;
		}
	}
	t=17;
	do{
		x[--t]=s%10+'0';
		s/=10;
	}while(s);
	write(1,x+t,17-t);
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define check printf("asd\n")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if( a<b ) {
		swap(a, b);
	}
	if( a<c ) {
		swap(a, c);
	}
	if( b<c ) {
		swap(b, c);
	}
	int cnt = a-b;
	c += cnt;
	if( c<a ) {
		int d = a-c;
		cnt += d/2;
		if( d%2!=0 ) {
			cnt += 2;
		}
	}
	pfd(cnt);
//	cout << a << b << c;
	return 0;
}

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

using pint = pair<int, int>;

int N;
vector<vector<pint>> v;

bool judge(int bit) {
    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {
        if ( !(bit & (1 << i)) ) continue;
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}

int main() {
    cin >> N;
    v.resize(N);
    rep(i, N) {
        int A; cin >> A;
        v[i].resize(A);
        rep(j, A) {
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }

    int res = 0;
    rep(bit, (1<<N)) {
        if(judge(bit)) {
            int count = 0;
            rep(i, N) {
                if (bit & (1<<i)) count++;
            }
            res = max(res, count);
        }
    }
    cout << res << endl;
}


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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  int i, j, k;
  for (i = 0; i * R <= N; i++) {
    for (j = 0; i * R + j * G <= N; j++) {
      k = (N - i * R - j * G);
      if (k % B == 0 && 0 <= k / B) ans++;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256