akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("trapv")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
const int maxn = 2e6 + 55, mod = 1000000007;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vi a(n), b(n);
	for(auto &i : a) cin >> i;
	for(auto &i : b) cin >> i;
	if(a>b) swap(a, b);
	int ans = 0;
	while(a!=b) {
		ans++;
		next_permutation(all(a));
	}
	cout << ans;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		sc.close();
		int mod = 2019;
		
		for(int i=L;i<=R;i++) {
			if(i%2019==0) {
				System.out.println(0);
				return;
			}
		}
		
		L%=mod;
		R%=mod;
		
		int ans = Integer.MAX_VALUE;
		for(int i=L;i<R;i++) {
			for(int j=L+1;j<=R;j++) {
				int tmp = i*j;
				tmp %= mod;
				ans = Math.min(ans, tmp);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int a,b,c;
    a=0;
    int j=0;
    while(1){
        if(j>=7){
            break;
        }
        cin>>b>>c;
        a=b-c;
        cout<<a<<endl;
        j++;
    }
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int n;
	cin >> n;
	vector<int> l(n);
	rep (i, n) cin >> l[i];

	sort(rng(l));

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int a = l[i];
			int b = l[j];
			int id = (lower_bound(rng(l), a + b) - l.begin()) - 1;
			ans += max(0, id - j);
		}
	}

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

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

int main()
{
    int n, m, l;
    long A[100][100] = { 0 }, B[100][100] = { 0 }, C[100][100] = { 0 };
    cin >> n >> m >> l;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> B[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if (j != 0)cout << ' ';
            cout << C[i][j];
        }cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1404
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, x;
	int m[100];
	cin >> n >> x;
	rep(i, n) cin >> m[i];
	sort(m, m + n);
	int ans = 0;
	rep(i, n) {
		x -= m[i];
		ans++;
	}
	while (x >= m[0]) {
		ans++;
		x -= m[0];
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

typedef long long ll;

char str[500005];
int lmax[500005],rmax[500005];

int main() {
  scanf("%s",str+1);
  int n=strlen(str+1)+1;
  for(int i=2;i<=n;i++) lmax[i]=((str[i-1]=='<')?lmax[i-1]+1:0);
  for(int i=n-1;i>0;i--) rmax[i]=((str[i]=='>')?rmax[i+1]+1:0);
  ll ans=0;
  for(int i=1;i<=n;i++) ans+=max(lmax[i],rmax[i]);
  printf("%lld\n",ans);
  return 0;
} 

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

const int maxn = 1e5 + 1;
long long a[maxn];

int main()
{
    for(int i=0; i<maxn; i++) a[i] = 0LL;
    long long sum = 0LL;
    int n;
    cin >> n;
    long long x;
    for(int i=0; i<n; i++) {
        cin >> x;
        sum += x;
        a[x]++;
    }

    int q, b, c;
    long long total;
    cin >> q;
    
    while(q--) {
        cin >> b >> c;
        total = a[b];
        a[b] = 0;
        sum -= (long long)(b*total);
        a[c] += total;
        sum += (long long) (c*total);

        cout << sum << "\n";
    }

    return 0;
}

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

int main(){
	int A,B,ans=0;
	cin >> A >> B;
	while(ans<99999){
		ans++;
		if(ans*8/100==A && ans*10/100==B){
			cout << ans << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {
	int n;
	scanf("%d", &n);
	vector<ll> v(n + 1);
	unordered_map<ll, ll> mp;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &v[i]);
		mp[v[i]]++;
	}
	ll ans = 0;
	for (auto c : mp)
		ans += c.second * (c.second - 1) / 2;
	for (int i = 1; i <= n; i++) {
		ans -= mp[v[i]] * (mp[v[i]] - 1) / 2;
		mp[v[i]]--;
		ans += mp[v[i]] * (mp[v[i]] - 1) / 2;
		printf("%lld\n", ans);
		ans -= mp[v[i]] * (mp[v[i]] - 1) / 2;
		mp[v[i]]++;
		ans += mp[v[i]] * (mp[v[i]] - 1) / 2;
	}
}


Measured memory_bytes: 11864
#include <stdio.h>

int main(void)
{
    int C, D;
    int TAKA, AOKI;

    scanf("%d %d %d %d", &TAKA, &C, &AOKI,&D);

    while(TAKA > 0 && AOKI > 0){
        AOKI -= C;
        TAKA -= D;
    }

    if (AOKI <= 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

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

int main()
{
 bool prime[1000000];
 for(int i=0; i<1000000; i++) prime[i] = true;

 prime[0] = prime[1] = false;
 for(int i=0; i<1000000; i++)
  if(prime[i]){
   for(int j=i+i; j<1000000; j += i)
    prime[j] = false;
  }

 int n;
 while(cin >> n){
  int c = 0;
  for(int i=0; i<=n; i++)
   if(prime[i]) c++;
  
  cout << c << '\n';
 }

 return 0;
}

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

int main()
{
  int W, H, N;
  cin >> W >> H >> N;
  int x[N], y[N], a[N];
  rep(i,N) cin >> x[i] >> y[i] >> a[i];
  
  bool map[W][H];
  rep(i,W){
    rep(j,H){
      map[i][j] = false;
    }
  }
  
  //coloring
  rep(i,N)
  {
    if(a[i] == 1)
    {
      rep(j,x[i]){
        rep(k,H){
          map[j][k] = true;
        }
      }
    }
    if(a[i] == 2)
    {
      for(int j = x[i]; j < W; j++){
        rep(k,H){
          map[j][k] = true;
        }
      }
    }
    if(a[i] == 3)
    {
      rep(j,W){
        rep(k,y[i]){
          map[j][k] = true;
        }
      }
    }
    if(a[i] == 4)
    {
      rep(j,W){
        for(int k = y[i]; k < H; k++){
          map[j][k] = true;
        }
      }
    }
  }
  
  //calculate the white area
  int count = 0;
  rep(i, W)
  {
    rep(j, H)
    {
      if(map[i][j] == false) count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int MOD=MOD2;

bool check(const string& s)
{
      int len=s.length();
      rep(i,0,len)if(s[i]!=s[len-1-i])return false;
      return true;
}
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
           string s;
           cin>>s;
           int n=s.length();
           int len1=(n-1)/2;
           int len2=n-((n+3)/2)+1;
           if(check(s) && check(s.substr(0,len1)) && check(s.substr((n+3)/2-1,len2)))
           cout<<"Yes"<<endl;
           else
           cout<<"No"<<endl;
      } 
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

int main()
{
   int N, K;
   cin >> N >> K;
   int p[N];
   REP(i, N) cin >> p[i];
   qsort(p, N, sizeof(int), compare_int);
   int ans=0;
   REP(i, K){
       ans+=p[i];
   }
   cout << ans << endl;
}

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

long long int lucas(int n) {
  if (n == 0) return 2;
  if (n == 1) return 1;
  long long int sum, pp_t, p_t;
  pp_t = 2;  p_t = 1;
  for (int i = 2; i <= n; i++) {
    sum = p_t + pp_t;
    pp_t = p_t;
    p_t = sum;
  }
  return sum;
}
int main() {
  int N; cin >> N;
  cout << lucas(N) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, ll> pii;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const ll MOD = 998244353;

int main() {
    FastIO
    ll n, a, b;
    cin >> n >> a >> b;
    if (a < b)swap(a, b);
    if (a % 2 == b % 2) {
        cout << (a - b) / 2 << "\n";
    }
    else {
        cout << min(n - a + 1 + (n - b - n + a - 1) / 2, b + (a - b - 1) / 2) << "\n";
    }
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t x, y;
    cin >> x >> y;

    if (abs(x - y) >= 2) {
        cout << "Alice" << endl;
    } else {
        cout << "Brown" << endl;
    }
}

Measured memory_bytes: 256
//mOzis_
/////*31022618*/////
//****//MONU KUMAR\****//
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define p1(x) cout <<x <<"\n"
#define p2(x,y) cout <<x <<" " <<y <<"\n"
#define p3(x,y,z) cout <<x <<" " <<y <<" " <<z <<"\n"
#define nL cout<<"\n"
#define lp(i,l,r) for (long long int i = l; i < r; i++)
#define mem(a,x) memset(a,x,sizeof(a))              //set elements of array to some value
#define pi 3.1415926535897932384626
#define mod 1000000007
#define pb(x) push_back(x)
#define ff first
#define ss second
#define siz 256                        //characters are stored using 8 bit and there can be
bool anagram(char *s1, char *s2)     //256 possible characters only in lowercase alphabet
{
	ll count[siz];
    mem(count,0) ;
    ll i;
    for (i = 0; s1[i] && s2[i];  i++)
    {
        count[s1[i]]++;
        count[s2[i]]--;
    }
    if (s1[i] || s2[i])
    {
      return false;
    }
    lp(i,0,siz)
    {
    	 if (count[i])
    	 {
    	 	 return false;
    	 }
    }
     return true;

}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll t;
	//cin>>t;
	clock_t launch=clock();
	ll a,b;
	cin>>a>>b;
	if (abs(a-b)%2==0)
	{
		cout<<(a+b)/2<<"\n";
	}
	else
	{
		cout<<"IMPOSSIBLE"<<"\n";
	}

	clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
	return 0;
}
//////////*********************end of program*********************//////////




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100
int n;
int a[N+5];
int main()
{
	int num=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	if(a[i]==a[i+1]) num++,a[i+1]=-1;
	printf("%d",num);
 } 

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

int main() {
  int n;
  cin >> n;
  cout << 800 * n - 200 * (n / 15);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll S[1<<18];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,1<<N) cin>>S[i];
	sort(S,S+(1<<N));
	int M=(1<<N)-1;
	multiset<int> T;
	FOR(i,M) T.insert(S[i]);
	
	vector<int> V;
	V.push_back(S[M]);
	FOR(i,N) {
		vector<int> W=V;
		
		FORR(v,V) {
			auto it=T.lower_bound(v);
			if(it==T.begin()) return _P("No\n");
			it--;
			W.push_back(*it);
			T.erase(it);
		}
		
		sort(ALL(W));
		reverse(ALL(W));
		swap(V,W);
	}
	_P("Yes\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 14592
#include <iostream>

using namespace std;

int main(void) {
  int n, in, minv, maxv = -1000000000;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> in;

    if (i == 0) {
      minv = in;
      continue;
    }

    if (in - minv > maxv) maxv = in - minv;
    if (in < minv) minv = in;
  }

  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 3084
using System;

class Program
{
    static void Main()
    {
        String[] arr = Console.ReadLine().Split();
        string S = arr[0], T = arr[1];
        arr = Console.ReadLine().Split();
        int A = int.Parse(arr[0]), B = int.Parse(arr[1]);
        string U = Console.ReadLine();
        if (U == S) A--;
        else B--;
        Console.WriteLine(A + " " + B);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, m; cin >> n >> m;
    vint a(n), b(n), c(m), d(m);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    rep(i,n) {
        int mn = inf;
        int id;
        rep(j,m) {
            int dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if (chmin(mn,dis)) id = j+1;
        }
        cout << id << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
weights = {}

roots = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = LI()
    a -= 1
    b -= 1
    roots[a].append(b)
    roots[b].append(a)
    weights[(a,b)] = c
    weights[(b,a)] = c

Q, K = LI()
K -= 1
xy = [0 for i in range(Q)]
for i in range(Q):
    x, y = LI()
    x -= 1
    y -= 1
    xy[i] = [x, y]
"""
xyzで全部の通りを見つけるとN ** 3で無理
なので今回は木構造に注目してBFS or DFSで解いたらいいのでは？
重みを単純にグラフに持つと10**5 ** 2になってしまうので注意
"""

visited = [-1 for i in range(N)]
queue = collections.deque()
queue.append(K)
visited[K] = 0

while len(queue)> 0:
    node = queue.popleft()
    cnt = visited[node]
    for n_node in roots[node]:
        if visited[n_node] == -1:
            visited[n_node] = cnt + weights[(node, n_node)]
            queue.append(n_node)

for x, y in xy:
    print(visited[x] + visited[y])


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int dp[1 << 16];
int f[100005];
int g[1 << 16];
int main(){
    for(int i = 1; i < (1 << 16); i++)
    for(int j = 0; j < 16; j++) if(i >> j & 1) g[i] ^= j;
    for(int i = 1; i < (1 << 16); i++){
        dp[i] = 1 << 29;
        for(int mask = i; mask; mask = (mask - 1) & i)
            dp[i] = min(dp[i], (g[mask] == 0 ? __builtin_popcount(mask) - 1 : (1 << 29)) + dp[i ^ mask]);
    }
    int n; sd(n);
    for(int i = 0; i < n - 1; i++){
        int u, v, a; sd(u); sd(v); sd(a);
        f[u] ^= a;
        f[v] ^= a;
    }
    int mask = 0, ans = 0;
    vector<int> cnt(16);
    for(int i = 0; i < n; i++) cnt[f[i]]++;
    for(int i = 1; i < 16; i++){
        ans += cnt[i] / 2;
        if(cnt[i] & 1) mask |= 1 << i;
    }
    ans += dp[mask];
    printf("%d\n", ans);
}

Measured memory_bytes: 1152
using System;
using System.Linq;

namespace atcoder_BegginerContest89_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var hwd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var H = hwd[0];
            var W = hwd[1];
            var D = hwd[2];
            var ah = new int[90001];
            var aw = new int[90001];
            var d = new int[90001];
            var tmp = new int[hwd[0]][];

            for (int i = 0; i < H; i++)
            {
                tmp[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < W; j++)
                {
                    ah[tmp[i][j]] = i;
                    aw[tmp[i][j]] = j;
                }
            }

            for (int i = D + 1; i <= H * W; i++)
            {
                d[i] = d[i - D] + Math.Abs(ah[i] - ah[i - D]) + Math.Abs(aw[i] - aw[i - D]);
            }

            var q = int.Parse(Console.ReadLine());
            var lr = new int[2];

            for (int i = 0; i < q; i++)
            {
                lr = Console.ReadLine().Split().Select(int.Parse).ToArray();
                Console.WriteLine(d[lr[1]] - d[lr[0]]);
            }
        }
    }
}


Measured memory_bytes: 18420
#include<iostream>
using namespace std;
int main(){
  int a,b,ans;
  for(int i=0;i<4;i++){
    cin >> a >> b;
    if(a==1)ans=6000*b;
    else if(a==2)ans=4000*b;
    else if(a==3)ans=3000*b;
    else if(a==4)ans=2000*b;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
while 1:
	n,p = map(int,raw_input().split())
	if n == 0: break
	have = [0]*n
	stone = p
	i = count = 0
	while 1:
		count += 1
		if stone > 0:
			have[i] += 1
			stone -= 1
		else:
			stone += have[i]
			have[i] = 0
		if have[i] == p:
			break
		i = (i+1)%n
	print i

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;

/*long C(long n, long r){
    if(n < r) return 0;
    long p[n+1][n+1];
    p[0][0] = 1;
    for(int i = 1; i <= n; i++){
        p[i][0] = 1;
        p[i][i] = 1;
        for(int j = 1; j <= i-1; j++){
            p[i][j] = p[i-1][j] + p[i-1][j-1];
        }
    }
    return p[n][r];
}*/

void solve()
{
    int N;
    cin >> N;
    vector<long long> a(N);
    long long sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    long long ans = 1000000000000000000LL;
    long long x = 0;
    for(int i = 0; i < N-1; i++){
        x += a[i];
        ans = min(ans, abs(sum - 2*x));
    }
    cout << ans << endl;
    return;
}

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

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

int main(){
	int g=0,p=0;
	int w=0,l=0;
	string s;

	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g'){
			if(p<g){p++;w++;}
			else{g++;}
		}
		else{
			if(p<g){p++;}
			else{g++;l++;}
		}
	}
	cout<<w-l<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,n;
  cin>>x>>n;
  set<int>s;
  if(n==0)
  {
    cout<<x<<"\n";
    return 0;
  }
  for(int i=0;i<n;i++)
  {
    int a;
    cin>>a;
    s.insert(a);
  }
  if(s.find(x)==s.end())
  {
    cout<<x<<"\n";
    return 0;
  }
  int i=x-1,j=x+1;
  bool flag=false;
  while(i>=0 && j<=101)
  {
    if(s.find(i)==s.end())
    {
      cout<<i<<"\n";
      flag=true;
      break;
    }
    if(s.find(j)==s.end())
    {
      cout<<j<<"\n";
      flag=true;
      break;
    }
    i--;j++;
  }
}


Measured memory_bytes: 3636
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<stack>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define rrep(f,i,n) for(int (i)=0;(i) < (f); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define mset(a,x) memset(a,x,sizeof(a))

#define MAX 101
#define MAX_V 15
int a[1000000];
int main()
{
	int n;
	cin >> n;
	int m, c = 0;
	if (n % 2 == 0) {
		m = n / 2;
		rep(i, n) {
			if (i)
				c = i / 2;
			if (i % 2 == 0) {
				cin >> a[m + c];
			}
			else {
				cin >> a[m - c - 1];
			}
		}

	}
	else {
		m = n / 2;
		rep(i, n) {
			if (i)
				c = i / 2;
			if (i % 2 == 0) {
				cin >> a[m - c];
			}
			else {
				cin >> a[m + c + 1];
			}
		}
	}
	rep(i, n) {
		if (i) cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define inf -10000000000

long long calc(long long K, vector<int> G, vector<long long> C){
	long long ans = inf;
	long long L = (long long)G.size();
	long long SUM[2 * L + 1];
	SUM[0] = 0;
	for(int i=1;i<=L;i++){
		SUM[i] = SUM[i-1] + C[G[i-1]];
	}
	for(int i=1;i<=L;i++){
		SUM[L+i] = SUM[L+i-1] + C[G[i-1]];
	}
	if(SUM[L] > 0 && K >= L){
		long long sub = SUM[L] * (K / L);
		long long subK = K % L;
		for(int i=0;i<L;i++){
			for(long long t=0;t<=min(subK, L);t++){
				long long tmp = SUM[i + t] - SUM[i];
				// cout << sub + tmp << endl;
				// cout << subK << ":" << sub << ":" << tmp << endl;
				ans = max(sub + tmp, ans);
			}
		}
	}
	if(SUM[L] > 0 && K >= L){
		long long sub = SUM[L] * ((K / L) - 1);
		for(int i=0;i<L;i++){
			for(long long t=0;t<=L;t++){
				long long tmp = SUM[i + t] - SUM[i];
				// cout << sub + tmp << endl;
				// cout << subK << ":" << sub << ":" << tmp << endl;
				ans = max(sub + tmp, ans);
			}
		}
	}
	for(int i=0;i<L;i++){
		for(long long t=1;t<=min(K, L);t++){
			long long tmp = SUM[i + t] - SUM[i];
			// cout << sub + tmp << endl;
			// cout << subK << ":" << sub << ":" << tmp << endl;
			ans = max(tmp, ans);
		}
	}
	return ans;
}

int main(){
	long long N;
	long long K;
	cin >> N >> K;
	long long P[N];
	vector<long long> C;  
	for(int i=0;i<N;i++){
		cin >> P[i];
		P[i]--;
	}
	for(int i=0;i<N;i++){
		long long x;
		cin >> x;
		C.push_back(x);
	}
	vector<vector<int>> G(N);
	int D[N];
	for(int i=0;i<N;i++){
		D[i] = -1;
	}
	int num = 0;
	for(int i=0;i<N;i++){
		if(D[i] >= 0)continue;
		int tmp = i;
		while(D[tmp] < 0){
			D[tmp] = num;
			G[num].push_back(tmp);
			tmp = P[tmp];
		}
		num++;
	}
	long long SUM[num];
	for(int i=0;i<num;i++){
		// for(int j=0;j<(int)G[i].size();j++){
		// 	cout << G[i][j] << ":";
		// }
		// cout << endl;
		SUM[i] = calc(K, G[i], C);
	}
	long long ans = SUM[0];
	for(int i=1;i<num;i++){
		ans = max(ans, SUM[i]);
	}
	cout << ans << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  
  ll a, b, c; cin >> a >> b >> c;
  if (a % b) {
    cout << (a / b + 1) * c<< endl; 
  } else {
    cout << (a / b) * c<< endl;
  }
}

Measured memory_bytes: 3660
x, y = map(int,input().split())
if x*4 < y:
    print("No")
elif y % 2 ==1:
    print("No")
elif x*2 > y:
    print("No")
else:
    y = y / 2
    if x <= y <= x*2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9164
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <cctype>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--) 
#define pi             acos(-1)         
 
using namespace std;
 
ll i,j,temp;

 
int main()
{_
    
   string s,t;
   int lens=0,lent=0;
   bool valid;
   cin>>s>>t;
   while(s[lens]!='\0')
   	lens++;
   while(t[lent]!='\0')
   	lent++;

   if((lens+1)==lent){
   	for(i=0;i<lens;i++){
   		if(s[i]==t[i])
   			valid = true;
   		else{
   			valid = false;
   			break;
   		}
   	}
   	if(valid){
   		cout<<"Yes"<<endl;
   	}
   	else{
   		cout<<"No"<<endl;
   	}
   }
   else{
   	cout<<"No"<<endl;
   }
   
 
return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node {
  int p,l,r;
};

void setdep(int,int);
int setheight(int);
int sibling(int);
void print(int);


struct Node A[MAX];
int n,B[MAX],C[MAX];

int main(){
  int i,a,b,c,root;
  root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    A[a].l = b;
    A[a].r=c;
    if(b != NIL){
      A[b].p=a;
    }
    if(c != NIL){
      A[c].p = a;
    }
  }
 for(i=0;i<n;i++){
      if(A[i].p == NIL){
        root = i;
      }
    }
    setdep(root,0);
    setheight(root);
    for(i=0;i<n;i++){
      print(i);
    }
 return 0;
  }


void setdep(int p,int q){
  if(p == NIL){
    return;
  }
  B[p]=q;
  setdep(A[p].l,q+1);
  setdep(A[p].r,q+1);
}
int setheight(int r){
  int l,m;
  l=0;
  m=0;
  if(A[r].l != NIL){
    l = setheight(A[r].l) + 1;
}
  if( A[r].r != NIL){
    m = setheight(A[r].r) + 1;
  }
  return C[r] = (l > m ? l : m);
}

int sibling(int s){
  if(A[s].p == NIL)return NIL;
  if(A[A[s].p].l != s && A[A[s].p].l != NIL)return A[A[s].p].l;
  if(A[A[s].p].r != s && A[A[s].p].r != NIL)return A[A[s].p].r;
  return NIL;
}
void print(int t){
  int d;
  d=0;
  printf("node %d: ", t);
  printf("parent = %d, ", A[t].p);
  printf("sibling = %d, ",sibling(t));
  if(A[t].l != NIL)d++;
  if(A[t].r != NIL)d++;
  printf("degree = %d, ", d);
  printf("depth = %d, ", B[t]);
  printf("height = %d, ", C[t]);
  if(A[t].p == NIL){
 printf("root\n");
  }  else if(A[t].l == NIL && A[t].r == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}


Measured memory_bytes: 2072
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	queue< pair<string, int> > Q;

	int n, q; cin >> n >> q;
	for (int i = 0; i < n; i++) {
		string name;
		int time;
		cin >> name >> time;
		Q.push(make_pair(name, time));
	}

	int elaps = 0, a;
	for (pair<string, int>u; !Q.empty();) {
		u = Q.front(); Q.pop();
		a = min(u.second, q);
		u.second -= a;
		elaps += a;
		if (u.second > 0) {
			Q.push(u);
		}
		else {
			cout << u.first << " " << elaps << endl;
		}
	}
	return 0;
}

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

using namespace std;
int main()
{
	char a;
	cin >> a;
	if (a == 'A')
		cout << "T" << endl;
	if (a == 'T')
		cout << 'A' << endl;
	if (a == 'C')
		cout << 'G' << endl;
	if(a == 'G')
		cout << 'C' << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	
	int i, n, flag[10000001] = {};
	for (i = 1; i * (i + 1) < N * 2; i++);
	for (n = N; n > 0; i--) {
		if (i <= n) {
			flag[i] = 1;
			n -= i;
		}
	}
	for (i = 1; i <= N; i++) if (flag[i] == 1) printf("%d\n", i);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 39296
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
bool ok(string s){
	int N=s.size();
	if(N%2) return 0;
	return s.substr(0,N/2)==s.substr(N/2,N/2);
}
int count(string s){
	int N=s.size();
	int cnt=0;
	rep(b,1<<N){
		string t;
		rep(i,N) if((b>>i)&1) t+=s[i];
		if(ok(t)) cnt++;
	}
	return cnt;
}
int main(){
	// while(true){
	// 	string s;
	// 	cin>>s;
	// 	cout<<count(s)<<endl;
	// }
	long long N;
	cin>>N;
	N++;
	vector<int> vc;
	while(N){
		vc.pb(N%2);
		N/=2;
	}
	vc.pop_back();
	reverse(all(vc));
	int K=vc.size();
	vector<int> s,t;
	rep(i,K){
		s.pb(i*2);
		t.pb(i*2);
		if(vc[i]==1){
			s.pb(i*2+1);
			t.insert(t.begin(),i*2+1);
		}
	}
	for(int v:t) s.pb(v);
	cout<<s.size()<<endl;
	for(int v:s) cout<<v+1<<" ";
	puts("");
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  vector<ll> v(5);
  rep(i,0,5)
    cin>>v[i];
  ll k;
  cin>>k;
  if (v[4]-v[0] > k)
    cout<<":("<<endl;
  else
    cout<<"Yay!"<<endl;
  return 0;
}


Measured memory_bytes: 256
w = str(input())
W = str.lower(w)

T_list=[]
while True:
  t = list(map(str, input().split()))
  if 'END_OF_TEXT' in t:
      break
  for i in t:
    T_list.append(str.lower(i))

a = 0
for i in T_list:
  if W == i:
    a = a + 1

print(a)



Measured memory_bytes: 5560
N = int(input())
txy = [[0, 0, 0]]
for i in range(N):
    txy.append(list(map(int, input().split())))
flag = False
for i in range(N):
    t_tmp = txy[i+1][0] - txy[i][0]
    x_diff = txy[i+1][1] - txy[i][1]
    y_diff = txy[i+1][2] - txy[i][2]
    if t_tmp >= (x_diff + y_diff) and (t_tmp - (x_diff + y_diff)) % 2 == 0:
        flag = True
    else:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27380
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1000000000LL;
const ll MOD=1000000007LL;
const ll MAX=100010;
int main(){
	int n;
	while(cin>>n,n){
		int ma=0;
		int mi=INF;
		int sum=0;
		for(int i=0;i<n;i++){
			int s;
			cin>>s;
			sum+=s;
			ma=max(s,ma);
			mi=min(s,mi);
		}
		cout<<(sum-ma-mi)/(n-2)<<endl;
	}
	return 0;
}



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

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

  string result = "APPROVED";
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;

    if (x % 2 == 0) {
      if (!(x % 3 == 0 || x % 5 == 0)) {
        result = "DENIED";
        break;
      }
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

string s;

int main(){
    cin>>s;

    rep(i,s.size()-1){
        if(s[i]==s[i+1]){
            cout<<i+1<<' '<<i+2<<endl;
            return 0;
        }
    }
    rep(i,s.size()-2){
        if(s[i]==s[i+2]){
            cout<<i+1<<' '<<i+3<<endl;
            return 0;
        }
    }

    cout<<-1<<' '<<-1<<endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> t(n+1),x(n+1),y(n+1);
  t.at(0) = 0, x.at(0) = 0, y.at(0) = 0;
  for(int i=1;i<n+1;i++){
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }
  bool ans = 1;
  for(int i=0;i<n;i++){
    int ta,xa,ya;
    ta = t.at(i+1)-t.at(i);
    xa = max(x.at(i+1)-x.at(i),x.at(i)-x.at(i+1));
    ya = max(y.at(i+1)-y.at(i),y.at(i)-y.at(i+1));
    if(ta >= xa+ya && (ta-xa-ya)%2 == 0){
      continue;
    }
    else{
      ans = 0;
      break;
    }
  }
  if(ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner reader=new Scanner(System.in);
	
		int a= reader.nextInt();
		int b= reader.nextInt();
		int c= reader.nextInt();
		Set<Integer>s=new HashSet<Integer>();
		s.add(a);
		s.add(b);
		s.add(c);
		System.out.print(s.size());
	}
	
	

}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a + b + c >= 22) cout << "bust" << "\n";
  else cout << "win" << "\n";
}

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

typedef long long ll;
typedef int ii;
//typedef vector<ll> vi;

#define INF 1000000007

#define pi 3.141592654

#define T while(t--)
#define for2(i,a,b) for(i=a;i>=b;i--)
#define for3(i,a,b) for(i=a;i<=b;i=i+2)
#define for1(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair

#include<sstream>

#define si set<ll>
#define se multiset<ll>

typedef long double ld;

typedef vector<ll> vi;

#define bb(arr,nn,xx) upper_bound(arr,arr+nn,xx)-arr
#define aa(arra,nna,xxa) lower_bound(arra,arra+nna,xxa)-arra

#define all(v) sort(v.begin(),v.end())
 
#define all1(v) sort(v.rbegin(),v.rend())

ii main()
{

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

    
    ll a,b,c,d; cin>>a>>b>>c>>d; ll f=0; vi v;
    
    v.pb(min(a,b)*min(c,d));
    
    v.pb(max(a,b)*max(c,d));
    
    v.pb(max(a,b)*min(c,d));
    
    v.pb(min(a,b)*max(c,d));
    
    all1(v);
    
    cout<<v[0]<<"\n";
    
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
    public static void main(String args[]){
     Scanner sc = new Scanner(System.in);
     
     int x = sc.nextInt();
     
     int happiness = (x/500) * 1000;
     x = x%500;
     happiness += (x/5)*5;
     
     System.out.println(happiness);
     
     
   }
}

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

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

using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x == 7 || x == 5 || x == 3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
import collections

N = int(sys.stdin.readline())

monster = [int(a) for a in sys.stdin.readline().strip().split()]
monster.sort()

while len(monster)>1:
    for i in range(1,len(monster)):
        monster[i] %= monster[0]
    monster.sort()
    while monster[0]==0:
        monster.pop(0)
    


print(monster[0])

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

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

    ll ans = 0;
    ll m = 100;
    while(m<X){
        m = m*1.01;
        ++ans;
    }

    cout<<ans<<"\n";


	
	return 0;
}


Measured memory_bytes: 3640
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int Q; cin>>Q;
    rep(i,Q){
        int c,a,n; cin>>c>>a>>n;
        ll ans=0;
        while(c>=1&&a>=1&&n>=1){
            ans++;
            c-=1; a-=1;n-=1;
        }
        while(c>=2&&a>=1){
            ans++;
            c-=2,a-=1;
        }
        while(c>=3){
            ans++;
            c-=3;
        }
        cout<<ans<<endl;
    }
}

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

using namespace std;
bool ard(string a,string b){
    int c=0;
    for(int i=0;i<a.length();i++){
        int f=b.find(a[i]);
        if(f!=string::npos){
            c++;
            b.erase(f,1);
        }
    }
    return (c==10);
}
int main()
{
    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++){
        string t;
        cin>>t;
        sort(t.begin(),t.end());
        v.push_back(t);
    }
    sort(v.begin(),v.end());
    long long ans=0;
    int fn=1;
    for(int i=1;i<v.size();i++){
        if(v[i]==v[i-1]){
            ans+=fn;
            fn++;
        }
        else
            fn=1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int n;
    string s;
    cin >> n >> s;

    ll sumr[5000]{}, sumb[5000]{}, sumg[5000]{};
    rep(i, n) {
        if(s[i] == 'R') sumr[i]++;
        if(s[i] == 'G') sumg[i]++;
        if(s[i] == 'B') sumb[i]++;
        sumr[i + 1] += sumr[i];
        sumg[i + 1] += sumg[i];
        sumb[i + 1] += sumb[i];
    }
    ll ans = 0;
    FOR(i, 1, n) {
        if(s[i] == 'G') {
            ans += sumr[i] * (sumb[n] - sumb[i]);
            ans += sumb[i] * (sumr[n] - sumr[i]);
        }
        if(s[i] == 'R') {
            ans += sumg[i] * (sumb[n] - sumb[i]);
            ans += sumb[i] * (sumg[n] - sumg[i]);
        }
        if(s[i] == 'B') {
            ans += sumr[i] * (sumg[n] - sumg[i]);
            ans += sumg[i] * (sumr[n] - sumr[i]);
        }
    }
    rep(i, n) {
        for(int l = i, r = i; l >= 0 && r < n; l--, r++) {
            if(s[l] != s[i] && s[i] != s[r] && s[l] != s[r]) ans--;
        }
    }
    cout << ans << endl;

    return 0;
}

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

struct UnionFind{
    vector<int> par;

    UnionFind(int N):par(N,-1){}

    int root(int x){
        if(par[x]<0) return x;
        return par[x]=root(par[x]);
    }

    bool unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return false;
        if(par[rx]>par[ry]) swap(rx,ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind UN(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        UN.unite(a,b);
    }
    set<int> s;
    int count = 0;
    rep(i,n){
        if(!s.count(UN.root(i))){
            s.insert(UN.root(i));
            count++;
        }
    }
    cout << count-1 << endl;
}

Measured memory_bytes: 7744
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <math.h>
#include <vector>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    int k, n;
    cin >> k >> n;
    int a[n], max_dist = 0;
    cin >> a[0];
    REP1(i, n) {
        cin >> a[i];
        max_dist = max(max_dist, a[i] - a[i - 1]);
    }
    max_dist = max(max_dist, a[0] + k - a[n - 1]);
    cout << k - max_dist << endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))

T = [0 for i in range(n)]
T[0] = t[0]
for i in range(n-1):
    T[i+1] = T[i] + t[i+1]

INF = float('inf')
V = [INF for i in range(2*T[n-1]+1)]

for i in range(2*T[n-1]+1):
    V[i] = min(V[i], 0.5 * i)
    V[i] = min(V[i], T[n-1] - 0.5 * i)

for vi in range(n):
    for ti in range(2*T[n-1]+1):
        if vi == 0:
            if ti <= T[0] * 2:
                V[ti] = min(V[ti], v[0])
            else:
                V[ti] = min(V[ti], v[0] + ti * 0.5 - T[0])
        else:
            if ti <= T[vi-1] * 2:
                V[ti] = min(V[ti], v[vi] + T[vi-1] - ti * 0.5)
            elif (T[vi-1] * 2 <= ti) and (ti <= T[vi] * 2):
                V[ti] = min(V[ti], v[vi])
            else:
                V[ti] = min(V[ti], v[vi] + (ti * 0.5 - T[vi]))

ans = 0
for i in range(2*T[n-1]):
    ans += (V[i] + V[i+1]) * 0.5 * 0.5

print(ans)

Measured memory_bytes: 51804
package main

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

func main() {
    H := nextInt()
    W := nextInt()
    A := nextInt()
    B := nextInt()

    w0 := make([]int, H)
    w1 := make([]int, H)

    mat := make([][]int, H)
    for i := 0; i < H; i++ {
        mat[i] = make([]int, W)
    }
    for w := 0; w < W; w++ {
        h1 := 0

        for h := 0; h < H; h++ {
            if w0[h] == A && w1[h] == A {
                if h1 == B {
                    // fmt.Println("fill 0")
                    mat[h][w] = 0
                    w0[h]++
                } else {
                    // fmt.Println("fill 1")
                    mat[h][w] = 1
                    w1[h]++
                    h1++
                }
            } else if w0[h] == A {
                // fmt.Println("add 1")
                mat[h][w] = 1
                w1[h]++
                h1++
            } else if w1[h] == A {
                // fmt.Println("add 0")
                mat[h][w] = 0
                w0[h]++
            } else if h1 < B {
                // fmt.Println("add2 1")
                mat[h][w] = 1
                w1[h]++
                h1++
            } else {
                // fmt.Println("add2 0")
                mat[h][w] = 0
                w0[h]++
            }
        }
    }
    for i := 0; i < H; i++ {
        for j := 0; j < W; j++ {
            fmt.Print(mat[i][j])
        }
        fmt.Println()
    }
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
    bufsize := 1 * 1024 * 1024 // 1 MB
    var stdin = bufio.NewScanner(os.Stdin)
    stdin.Buffer(make([]byte, bufsize), bufsize)
    stdin.Split(bufio.ScanWords)
    return stdin
}

func nextString() string {
    stdin.Scan()
    return stdin.Text()
}

func nextBytes() []byte {
    stdin.Scan()
    return stdin.Bytes()
}

func nextInt() int {
    i, _ := strconv.Atoi(nextString())
    return i
}

func nextInt64() int64 {
    i, _ := strconv.ParseInt(nextString(), 10, 64)
    return i
}


Measured memory_bytes: 19340
n = int(input())
inf = float("inf")
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    tree[a].append([b, c])
    tree[b].append([a, c])
q, k = map(int, input().split())

depth = [inf] * (n+1)
visited = [False] * (n+1)
depth[k] = 0
stack = [k]
while stack:
    now = stack.pop()
    visited[now] = True
    for i, v in tree[now]:
        if visited[i]:
            pass
        else:
            stack.append(i)
            depth[i] = min(depth[i], depth[now] + v)
for _ in range(q):
    x, y = map(int, input().split())
    ans = depth[x] + depth[y]
    print(ans)

Measured memory_bytes: 50380
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  string ans;
  int A,B;
  cin>>A>>B;
  if (A==1) A=14;
  if (B==1) B=14;
  if (A>B) ans="Alice";
  if (A==B) ans="Draw";
  if (A<B) ans="Bob";
  cout<< ans <<endl;
}

Measured memory_bytes: 256