akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER)
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define EPS 1e-9
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

const int MOD = 1000000007;

int n, m;
int x[1001], y[1001];
struct Edge {
	int a, b, i;
	Edge(int a_, int b_, int i_): a(a_), b(b_), i(i_) {}
};
vector<Edge> a[1001];

bool vis[1001];
int dfs(int prev, int i) {
	if(vis[i]) return 0;
	vis[i] = 1;
	int r = i;
	each(j, a[i]) if(j->i != prev) {
		r = dfs(j->i, abs(j->b));
	}
	return r;
}
int dp[1001][2][2][2];
int rec(int prev, int i, bool assign, int first, bool firstassign) {
	if(dp[i][assign][first == 0][firstassign] != -1)
		return dp[i][assign][first == 0][firstassign];
	int r = 0;
	int current, next = 0, edge;
	each(j, a[i]) if(j->i != prev)
		current = j->a, next = j->b, edge = j->i;
	if(i == first) {
		if(assign == firstassign) r = 1;
	}else if(next == 0) {
		r = 1;
	}else {
		bool ff = first == 0;
		int nfirst = ff ? i : first;
		if(assign == (current > 0)) {	//この項が既に満たされている
			r = rec(edge, abs(next), false, nfirst, ff ? assign : firstassign);
			if((r += rec(edge, abs(next), true, nfirst, ff ? assign : firstassign)) >= MOD) r -= MOD;
		}else {	//assign == (next > 0)にして満たす必要がある
			r = rec(edge, abs(next), next > 0, nfirst, ff ? assign : firstassign);
		}
	}
	return dp[i][assign][first == 0][firstassign] = r;
}
int main() {
	while(~scanf("%d%d", &n, &m)) {
	rep(i, m)
		scanf("%d%d", &x[i], &y[i]);
	rer(i, 1, n) a[i].clear();
	rep(i, m) {
		a[abs(x[i])].pb(Edge(x[i], y[i], i));
		a[abs(y[i])].pb(Edge(y[i], x[i], i));
	}
	mset(vis, 0);
	mset(dp, -1);
	ll r = 1;
	rer(i, 1, n) if(!vis[i]) {
		unsigned x = 0;
		if(int last = dfs(-1, i)) {
			//line
			x += rec(-1, last, false, 0, 0);
			x += rec(-1, last, true, 0, 0);
		}else {
			//cycle
			x += rec(-1, i, false, 0, 0);
			x += rec(-1, i, true, 0, 0);
		}
		x %= MOD;
		(r *= x) %= MOD;
	}
	printf("%d\n", (int)r);
	}
	return 0;
}

Measured memory_bytes: 1384
//Burn It Dowwwnnnnn.....................
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define pi acos(-1)
using namespace std;
long long int MX=1e18;
long long int MN=-MX;
long long int vv[1000001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,b,c,d,q,s,n,m,o,p,tc=1,jj,z,aa,r;
//    cin>>tc;
    for(jj=0; jj<tc; jj++)
    {
        p=0;
        z=0;
        map<long long int,long long int>uu;
        stack<char>ss;
        k=0;
        string a;
        cin>>p>>q>>o;
        k=q*o;
        if(k>=p)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }

    }
}




Measured memory_bytes: 3660
n = gets.to_i
arr = gets.split(" ").map(&:to_i)
count = 0
for i in 0...n
  for j in 1..(n - i - 1)
    if arr[n - j] < arr[n - j - 1]
      arr[n - j], arr[n - j - 1] = arr[n - j - 1], arr[n - j]
      count += 1
    end
  end
end
puts arr.join(" "), count

Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int A, B;
    cin >> A >> B;
    if (A <= 8 && B <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  long x,m = 100;
  cin >> x;
  for(long i = 1; ; i++) {
    m += m/100;
    if(x <= m) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int N;
	bool ans = false;
	cin >> N;
	while(N){
		if(N%10 == 7) ans = true;
		N /= 10;
	}
	cout << (ans ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 3640
program AGC013A
    implicit none
    integer(8)::N,flg,i,ans
    integer(8),allocatable,dimension(:)::A
    read*,N
    allocate(A(N))
    read*,A
    ans=1
    flg=0

    do i=2,N
        if(flg==0)then
            if(A(i)>A(i-1))flg=1
            if(A(i)<A(i-1))flg=-1
        else
            if(flg==1.and.A(i)<A(i-1))then
                ans=ans+1
                flg=0
            else if(flg==-1.and.A(i)>A(i-1))then
                ans=ans+1
                flg=0
            end if
        end if
    end do
    print'(i0)',ans
end program AGC013A

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp(ll var)
{
	if(var==1)
	 return 1;
	return 1+2*dp(var/2);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll num;
    cin>>num;
    ll ans=dp(num);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3616
W, H, N = map(int,input().split())

x = []
y = []
a = []

area  = [[True for _ in range(W)] for _ in range(H)]

for i in range(N):
    x_tmp, y_tmp ,a_tmp = map(int,input().split())
    x.append(x_tmp)
    y.append(y_tmp)
    a.append(a_tmp)

w1 = 0
h1 = 0
w2 = W
h2 = H

for i in range(N):
    if a[i] == 1:
        w1 = max(w1, x[i])
    if a[i] == 2:
        w2 = min(w2, x[i])
    if a[i] == 3:
        h1 = max(h1, y[i])
    if a[i] == 4:
        h2 = min(h2, y[i])

# 負になった場合は0にする
if w2 - w1  < 0 or h2 - h1 < 0:
    S = 0
else:
    S = (w2-w1)*(h2-h1)

print(S)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) -= (step))
#define FOREACH(it, v) for (auto (it) : (v))

using namespace std;

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

template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}

int n, k, result;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("1.in", "r", stdin);
    cin >> n >> k;
    for (int i = 1, x; i <= n; i++) {
        cin >> x;
        k -= x;
        if (k >= 0) result++;
    }
    cout << result + 1;

}

Measured memory_bytes: 256
import sys
from copy import deepcopy

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(x):
        B = deepcopy(A)
        total = m * v
        target = B[x] + m
        for i in range(n):
            if i <= x:
                B[i] += m
                total -= m
            else:
                if n - (p - 1) <= i:
                    B[i] += m
                    total -= m
                else:
                    if B[i] > target:
                        return False
                    else:
                        total -= target - B[i]
                        B[i] = target
        return total <= 0

    n, m, v, p = map(int, input().split())
    A = sorted(list(map(int, input().split())))
    ng, ok = n, -1
    res = meguru_bisect(ng, ok)
    print(n - res)


if __name__ == '__main__':
    resolve()


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

vector<char> v;


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  int K;
  cin >> S;
  cin >> K;
  ll N = S.size();  

  set<string> C;
  rep(i, N){
    for(int len=1;len<=min(5LL, N-i);len++){
      C.insert(S.substr(i, len));
    }
  }

  auto iter = C.begin();
  rep(i, K-1){
    //cout<<*iter<<endl;
    iter++;
  }

  cout << *iter;
  
  /*
  for(int len=1;len<=5;len++){
    if(N-len<0)break;
    rep(i, N-len){
      C[len-1].insert(S.substr(i,len));
    }
  }
  rep(i, 5){
    cout << i << " " << C[i].size() << endl;
    if(C[i].size()>K){
      auto iter = C[i].begin();
      rep(i, K-1){
        iter++;
        cout << *iter;
        return 0;
      }
    }else{
      K = K-C[i].size();
    }
    }
*/
  
  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y;
}


Measured memory_bytes: 256
def s_expand(s, i, sum)
  if s.size-1 <= i then
    nums = s.split('+')
    cal = 0
    nums.each do |tmp|
      cal += tmp.to_i
    end 
    return cal + sum
  end
  return s_expand(s.clone.insert(i+1, '+'), i+2, sum) + s_expand(s.clone, i+1, sum) 
end

s = gets.chop
sum = s_expand(s, 0, 0)
puts sum

Measured memory_bytes: 1788
n=int(input())
a=list(map(int,input().split()))
i4=0
i2=0
i0=0
for x in a:
    if x%4==0:i4+=1
    elif x%2==0:i2+=1
    else:i0+=1
if i4>=i0:print("Yes")
elif i4+1==i0 and i2==0:print("Yes")
elif i0==0:print("yes")
else:print("No")

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

  int n;
  cin >> n;
  vi A(n);
  rep(i, 0, n) {
    cin >> A[i];
  }
  int ans = 0;
  rep(i, 0, n-1) {
    if (A[i] == i+1) {
      swap(A[i], A[i+1]);
      ans++;
    }
  }

  if (A[n-1] == n) {
    swap(A[n-1], A[n-2]);
    ans++;
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 768
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
//#pragma GCC optimize(3)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define ll long long
#define ull unsigned long long
#define mn 500020
#define mod (int)(1e9+7)
#define inf (1<<30)
#define FOR(a,b,c) for (register ll a=b;a<=c;a++)
#define FORD(a,b,c) for (register ll a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline void writeln(ll a){
    if(a==0){puts("0");return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    int h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    FORD(i,h,1)putchar(c1[i]);putchar('\n');
    return;
}
inline ll Max(ll a,ll b){return (a>b)?a:b;}
inline ll Min(ll a,ll b){return (a<b)?a:b;}
inline ll Abs(ll x){return (x<0)?-x:x;}
inline void Swap(ll &x,ll &y){ll t=x;x=y;y=t;}
int a[5];
int main(){
	a[1]=read(),a[2]=read(),a[3]=read();
	sort(a+1,a+4);
	writeln(a[3]*10+a[2]+a[1]);
	return 0;
}


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

int min(int a, int b)
{
    return a < b ? a : b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    int dp[n];
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
import sys
k = int(input()) 
ls = [[] for _ in range(10**4)] 
i = 0
ls[0] = [e for e in range(1,10)]
di = [0]*(10**4)
di[0] = 9
if k <= 9:
    print(k)
    sys.exit()
while True:
    for j in ls[i]:
        p = str(j)[-1]
        q = int(p)
        if p == "0":
            ls[i+1].append(10*j)
            ls[i+1].append(10*j+1)
        elif p == "9":
            ls[i+1].append(10*j+8)
            ls[i+1].append(10*j+9)
        else:
            ls[i+1].append(10*j+q-1)
            ls[i+1].append(10*j+q)
            ls[i+1].append(10*j+q+1)
    di[i+1] = di[i] + len(ls[i+1])
    if di[i+1] >= k:
        print(ls[i+1][k-di[i]-1])
        break
    i += 1

Measured memory_bytes: 19224
#include  <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
 
vector<pii> ans;
 
int main(){
      while(1){
       
            int N,M; cin >> N >> M;
            if(!N) break;
            ans.clear();
            for(int i=0; i<N; i++){
                  int d,p; cin >> d >> p;
                  ans.push_back(pii(p,d));
            }
            sort(ans.begin(),ans.end());
            reverse(ans.begin(),ans.end());
            long long sum=0;
            for(int i=0; i<ans.size(); i++){
                  if(M >= ans[i].second){
                        M -= ans[i].second;
						continue;
                  }
                  else{
                        ans[i].second -= M;
                        M = 0;
                        sum += ans[i].first * ans[i].second;
                  }
 
            }
 
            cout << sum << endl;
       
       
      }
}

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

int main(void){
  string s;

  cin >> s;

  if(s.find('a') != string::npos && s.find('b') != string::npos && s.find('c') != string::npos)
    cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]

s = sorted(p + q + r, reverse=True)
print(sum(s[:X + Y]))


Measured memory_bytes: 114796
#include <iostream>

using namespace std;

int main()
{
	int n, x;
	cin >> n;
	while(n--)
	{
		cin >> x;
		if (x % 2 == 0 && x % 3 != 0 && x % 5 != 0)
		{
			cout << "DENIED\n";
			return 0;
		}
	}
	cout << "APPROVED\n";
	return 0;
	
}



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

int main(){
  string n;
  cin >> n;
  for (int i=0;i<3;i++){
    if (n.at(i)=='1'){
      n.at(i)='9';
    }
    else if (n.at(i)=='9'){
      n.at(i)='1';
    }
  }
  cout << n << endl;
}

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

typedef long long ll;
 
int main(){
  string s,t;
  cin >> s >> t;
  reverse(s.begin(), s.end());
  string ans;
  if(s==t) ans = "YES";
  else ans = "NO";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int ALPHABET = 26;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(),greater<ll>());

	ll sum = 0;
	
	sum += a[0];

	for (int i = 1; i < n - 1; i++) {
		sum += a[(i + 1) / 2];
	}
	cout << sum << endl;

}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        string S;
        cin >> S;
        if (len(S) == 2) {
                cout << S << endl;
        } else {
                reverse(all(S));
                cout << S << endl;
        }
}


Measured memory_bytes: 3588
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,j;
	h=0;
	scanf("%d %d %d %d %d %d",&a,&s,&d,&f,&g,&j);
	h=(a*1)+(s*5)+(d*10)+(f*50)+(g*100)+(j*500);
	if(1000<=h){
		printf("1\n");
		}
	else{
		printf("0\n");
		}
	return 0;
}

Measured memory_bytes: 1012
n = int(input())
s = list(input())

if n%2!=0:
  print("No")
  exit()

l = int(len(s)/2)
a = ""
b = ""

for i in range(l):
  a += s[i]
  b += s[i+l]
  
if a==b:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
fun main(args: Array<String>) = yorukatsu15c()

fun yorukatsu15c() {
    val (n, q) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!
    val lrList = (1..q).map {
        readLine()!!.split(' ').map { it.toInt() }.let { it[0] to it[1] }
    }

    val cSum = IntArray(n + 1)

    for (i in 1..s.lastIndex) {
        cSum[i] = if (s[i - 1] == 'A' && s[i] == 'C') 1 else 0
    }
    for (i in 0 until n) cSum[i + 1] += cSum[i]

    val answer = lrList.map {
        val (left, right) = it
        cSum[right - 1] - cSum[left - 1]
    }.joinToString(System.lineSeparator())

    println(answer)
}


Measured memory_bytes: 68276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	ll x, y;
	cin >> x >> y;
	int ans = 1;
	while(x * 2 <= y){
		x *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int 
const int N = (int)1e6 + 10;
const int MOD = (int) 1e9 + 7;

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


void solve(){
    //THink in reverse..
    // we want to find contribution of each gcd to happen
    // consider we have k places _ , _ , _ , _ , __ ,n.
    // gcd = 1 -> k^n ways;
    // gcd = 2 -> total multiples of 2 are k/2 -> (k/2)^n ways
    // so on until gcd = n;
    // but we need to take care of overcounting
    int n, k;
    cin >> n >> k;
    vector<int> dp(k + 1, 0);
    for(int gd = k; gd >= 1; --gd){
        int total_multiples = k/gd;
        int temp = fastpower(total_multiples, n);
        temp %= MOD;
        temp %= MOD;
        int extra = 0;
        for(int j = gd * 2; j <= k; j += gd){
            extra = (extra + dp[j]) % MOD;
        }
        dp[gd] = (temp - extra + MOD) % MOD;
    }

    int ans = 0;
    for(int i = 1; i <= k; ++i){
        int add = ( dp[i] % MOD * i % MOD ) % MOD;
        ans += add, ans %= MOD;
    }

    cout << ans << '\n';
   
    
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}
/*
Sample inp
*/


Measured memory_bytes: 3952
n, m, x0, y0 = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(x0)
y.append(y0)

x.sort()
y.sort()

if x[-1] < y[0]:
    print('No War')
else:
    print('War')

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

#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)

using namespace std;
typedef long long ll;

namespace Main{

const int N=105,P=1e9+7;

inline int fpow(int a,int t){
	static int r;
	for(r=1;t;t>>=1,a=(ll)a*a%P)if(t&1)r=(ll)r*a%P;
	return r;
}

int f[N][N],v[N][N];
int Solve1D(int a,int A){return a;}
int Solve2D(int a,int A,int b,int B){
	return (((ll)a*fpow(Solve1D(b,B),A/a)+(ll)b*fpow(Solve1D(a,A),B/b)-(ll)a*b)%P+P)%P;
}
int Solve3D(int a,int A,int b,int B,int c,int C){
	if(A%a||B%b||C%c)return 0;
	// trival cases
	int ae=A/a,be=B/b,ce=C/c;
	int ret=(
	((ll)a*fpow(Solve2D(b,B,c,C),ae)
	+(ll)b*fpow(Solve2D(a,A,c,C),be)
	+(ll)c*fpow(Solve2D(a,A,b,B),ce)
	-(ll)a*b*fpow(Solve1D(c,C),ae*be)
	-(ll)a*c*fpow(Solve1D(b,B),ae*ce)
	-(ll)b*c*fpow(Solve1D(a,A),be*ce)
	+(ll)a*b*c)%P+P)%P;
	// non-trival cases
	fo(i,**v=1,max(ae,be))fo(j,*v[i]=1,i)v[i][j]=(v[i-1][j-1]+v[i-1][j])%P;
	fd(i,ae,1)fd(j,be,1){
		f[i][j]=(ll)v[ae][i]*v[be][j]%P*fpow(c,(ae-i)*(be-j))%P;
		fo(k,i,ae)fo(t,j,be)if(k>i||t>j)f[i][j]=(f[i][j]-(ll)f[k][t]*v[k][i]%P*v[t][j]%P+P)%P;
		int p=fpow(b,i),q=fpow(a,j),w=((fpow(p+q-1,ce)-fpow(p,ce)-fpow(q,ce)+1)%P+P)%P;
		if(i<ae||j<be)ret=(ret+(ll)a*b*c*f[i][j]%P*w)%P;
	}
	return ret;
}

}

int a,b,c,A,B,C;

int main(){
	cin>>a>>b>>c>>A>>B>>C;
	cout<<Main::Solve3D(a,A,b,B,c,C);
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
dp = [1e9 for _ in range(n)]
#dp[i]...コストの最小
dp[0] = 0
dp[1] = abs(a[1] - a[0])
for i in range(n-2):
  dp[i+2] = min(dp[i+1] + abs(a[i+2] - a[i+1]), dp[i] + abs(a[i+2] - a[i]))
print(dp[n-1])


Measured memory_bytes: 13980
import sys
N = int(input())
A, B = [], []
for _ in range(N):                                                                                                                                                                                          
    a, b = (int(x) for x in input().split())                                                                                                                                                                
    A.append(a)                                                                                                                                                                                             
    B.append(b)                                                                                                                                                                                             

B_ = sorted(B)
B_id = sorted(range(len(B)), key=lambda k:B[k])

time = 0
for i in range(N):                                                                                                                                                                                          
    time += A[B_id[i]]                                                                                                                                                                                      
    if time > B_[i]:                                                                                                                                                                                        
        print('No')                                                                                                                                                                                         
        sys.exit()                                                                                                                                                                                          

print('Yes')


Measured memory_bytes: 30408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)


Measured memory_bytes: 285828
#include<bits/stdc++.h>
#define task "MAXFRAME"

#define nguyen_dz the_best
#define ll long long
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define Yes cout <<"Yes"<<endl;
#define No cout<<"No" <<endl;


using namespace std;
const ll  maxn= 4e6+100;

ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    ll n;
     cin>> n;
     for (int i=1;i<=n;i++)
     {
         cin>>a[i];

     }
     sort(a+1,a+n+1);
     ll t=1;
     const ll p= 1e18;
     for (int i=1;i<=n;i++)
     {
         if (a[i]==0)
         {
             cout <<0;
             return 0;
         }
         if (p/a[i]<t)
         {
             cout <<-1;
             return 0;
         }
         t*=a[i];
     }
     cout <<t;


}



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

int main(){
    
    int n, t;
    cin >> n >> t;
    vector<int>a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    
    vector<int>idx(n);
    for(int i = 0; i < n; i++){
        idx[i] = i;
    }
    sort(idx.begin(), idx.end(), [&](int i, int j){
            return a[i] < a[j];
        });
        
        
    int dp[n+1][t+1];
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n; i++){
        int k = idx[i];
        for(int tt = 0; tt <= t; tt++){
            dp[i+1][tt] = max(dp[i+1][tt], dp[i][tt]);
            if(tt >= t)continue;
            if(tt + a[k] > t - 1){
                dp[i+1][t] = max(dp[i][t], b[k] + dp[i][tt]);
            }else{
                dp[i+1][tt + a[k]] = max(dp[i+1][tt + a[k]], b[k] + dp[i][tt]);
            }
        }
    }
    
    cout << dp[n][t] << endl;
     
}


Measured memory_bytes: 38796
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  ll S;
  cin >> S;

  //|x1y2-x2y1|=S

  ll x1 = 1e9;
  ll x2 = 1;
  
  ll y2 = (S+x1-1)/x1;
  ll y1 = x1 * y2 - S;

  printf("0 0 %ld %ld %ld %ld\n",x1,x2,y1,y2); 
}

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

ll solve(ll a) {
  ll ans = a - 1;
  for (int i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      ans = min(ans, i - 1 + (a / i) - 1);
    } 
  }
  return ans;
}

int main() {
  ll a;
  cin >> a;
  cout << solve(a) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  string s;
  cin >> s;
  int res = 700;
  FOR(i,0,2)
    if (s[i] == 'o') res += 100;
  cout << res;
    return 0;
}

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

using namespace std;

long long expression1(vector<string>);
long long expression2(vector<string>);

string to_string(char c)
{
	string S; S = c;

	return S;
}

vector<string> to_expression(string S)
{
	vector<string> v; int sum = 0;

	for (int i = 0; i < S.size(); i++)
	{
		if (isdigit(S[i]))
		{
			sum *= 10; sum += (S[i] - 48);
		}
		else
		{
			v.push_back(to_string(sum)); sum = 0; v.push_back(to_string(S[i]));
		}
	}

	v.push_back(to_string(sum));

	return v;
}

long long expression1(vector<string> v)
{
	vector<string> v2;

	long long sum = stoi(v[0]);

	for (int i = 1; i < v.size(); i += 2)
	{
		if (v[i] == "+")
		{
			v2.push_back(to_string(sum)); v2.push_back("+"); sum = stoll(v[i + 1]);
		}
		else
		{
			sum *= stoll(v[i + 1]);
		}
	}

	v2.push_back(to_string(sum));

	return expression2(v2);
}

long long expression2(vector<string> v)
{
	long long sum = stoi(v[0]);

	for (int i = 1; i < v.size(); i += 2)
	{
		if (v[i] == "+")
		{
			sum += stoll(v[i + 1]);
		}
		else
		{
			sum *= stoll(v[i + 1]);
		}
	}

	return sum;
}

int main()
{
	string S; int N;

	cin >> S >> N;

	long long res1 = expression1(to_expression(S));
	long long res2 = expression2(to_expression(S));

	int ret = (res1 == N ? 2 : 0) + (res2 == N ? 1 : 0);

	switch (ret)
	{
		case 3: cout << "U" << endl; break;
		case 2: cout << "M" << endl; break;
		case 1: cout << "L" << endl; break;
		case 0: cout << "I" << endl; break;
	}

	return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <vector>

using namespace std;

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

long long lcm(long long x, long long y) {
	return x / gcd(x, y) * y;
}

int main() {
	int n, m; cin >> n >> m;
	vector<int> a(n);
	for (auto& e : a) cin >> e;
	int f = a[0] & (-a[0]);
	for (int i = 0; i < n; ++i) {
		if ((f != (a[i] & (-a[i]))) || (a[i] & 1)) {
			cout << 0 << endl;
			return 0;
		}
	}
	long long lc = a[0];
	for (int i = 1; i < n; ++i) lc = lcm(lc, a[i]);
	long long fi = lc / 2;
	if (fi > m) cout << 0 << endl;
	else cout << (m / fi + 1) / 2 << endl;

	return 0;
}

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

int main() {
 int h,w; cin >> h >> w;
  vector<string> line(h);
  for(int i=0;i<h;i++){
   cin >> line[i];
  }
  vector<string> ans(2*h);
  for(int i=0;i<2*h;i++){
   if(i%2==0)ans[i]=line[i/2];
   else if(i%2==1) ans[i]=line[(i-1)/2];
  }

  for(int i=0;i<2*h;i++){
   cout << ans[i] << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
bool cmp(ll x,ll y)
{
   return x>y;
}
int main(void)
{
   optimize
   long long int t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair <ll,ll> >p,p1,p2;
   set<ll> st;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair <ll,ll> > > plpq;
   string s;
   //cin>>t;
   //while(t--)
   //{
      cin>>n;
      for(ll i=0;i<n;i++)
      {
         cin>>a[i];
      }
      sort(a,a+n);
      ll ans=0,sum=0;
      for(ll i=0;i<n-1;i++)
      {
         sum=modAdd(sum,a[i]);
         ans=modAdd(ans,modMul(sum,a[i+1]));
      }
      cout<<ans<<endl;
   //}
   return 0;
}


Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(a,b) for(int i=a; i<b; i++)
#define loopr(a,b) for(int i=a;i>=b;i--)
void solve()
{
	int a,b;cin>>a>>b;
	cout<<a*b;
	return;
}
int32_t main() 
{ 
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0; 
}

Measured memory_bytes: 3652
n=int(input())
xy=[]
for i in range(n):
  xy_=list(map(int,input().split()))
  xy.append(xy_)
  
from itertools import permutations
import math
s=list(permutations(range(n)))
ans=0
for i in s:
  sum_r=0
  for j in range(n-1):
    r=math.sqrt((xy[i[j+1]][0]-xy[i[j]][0])**2+(xy[i[j+1]][1]-xy[i[j]][1])**2)
    sum_r+=r
    
  ans+=sum_r
  
  
print(ans/len(s))
    
    
    

Measured memory_bytes: 13944
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    cout << (A + B) % 24 << endl;

    return 0;
}

Measured memory_bytes: 3616
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ls := make([]int, n+1)
	ls[0] = 2
	ls[1] = 1
	for i := 2; i < len(ls); i++ {
		ls[i] = ls[i-1] + ls[i-2]
	}
	fmt.Println(ls[n])
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int match[10] = {0,2,5,5,4,5,6,3,7,6};

	int n,m;
	cin>>n>>m;
	vector<int> a(m);
	for(int i = 0; i < m; i++){
		cin >> a[i];
	}

	vector<pair<int,int> > ma(m);
	for(int i = 0; i < m; i++){
		ma[i].first = a[i];
		ma[i].second = match[a[i]];
	}
	sort(all(ma));
	reverse(all(ma));
	// vector<vector<int> > cnt(n+1,vector<int>(10,0));
	// vector<int> flag(n+1,0);
	// flag[0]++;
	// for(int x = 2; x <= n; x++){
	// 	if(flag[x]==0){
	// 		for(int i = 0; i < m; i++){
	// 			if(x-ma[i].first >= 0 && flag[x-ma[i].first]>0){
	// 				flag[x]++;
	// 				cnt[x] = cnt[x-ma[i].first];
	// 				cnt[x][ma[i].second]++;
	// 				break;
	// 			}
	// 		}
	// 	}
	// }

	vector<int> dp(n+1,-1);
	dp[0] = 0;
	for(int i = 0; i <= n; i++){
		int max_digit=-1;
		for(int j = 0; j < m; j++){
			if(i-ma[j].second>=0 && dp[i-ma[j].second]>=0) max_digit = max(max_digit,dp[i-ma[j].second]);
		}
		if(max_digit>=0) dp[i] = max_digit+1;
	}

	// for(int i = 0; i <= n; i++){
	// 	cout << dp[i] << " ";
	// }printf("\n");

	vector<int> ans;
	// for(int i = dp[n]; i >0; i--){
	// 	for(int j = 0; j < m; j++){
	// 		if(dp[i-ma[j].second] == dp[i]-1)
	// 	}
	// }
	int digit = n;
	// int cnt = 0;
	while(digit>0){
		for(int j = 0; j < m; j++){
			if(digit-ma[j].second >= 0 && dp[digit-ma[j].second] == dp[digit]-1){
				digit = digit-ma[j].second;
				//cout << digit << " "<< dp[digit] <<endl;
				ans.push_back(ma[j].first);
				break;
			}
		}
	}

	// printf("\n");
	// cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i];
	}printf("\n");


	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    rep(i, N) cin >> A[i], sum += A[i];
    ll index = 0;
    ll mini = numeric_limits<ll>::max();
    rep(i, N) {
        ll temp = abs(N * A[i] - sum);
        if(temp < mini) {
            mini = temp;
            index = i;
        }
    }
    cout << index << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

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

  if (B%A == 0) {
    cout << A+B << endl;
  } else {
    cout << B-A << endl;
  }

  return 0;
}


Measured memory_bytes: 256
use std::cmp::max;

fn main() {
    let n: usize = read_line();
    let v: Vec<i64> = read_vec();

    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            ans = max(ans, (v[i]-v[j]).abs());
        }
    }

    println!("{}", ans);
}

fn read_line<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|e|
        e.parse().ok().unwrap()
    ).collect()
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		System.out.println(x + (y/2));
		sc.close();
	}

}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int N,M;
  cin >> N >> M ;
  vi H(N);
  for (int &x:H) cin >> x ;
  //vvi P(N,vi(N,-1));
  vi T(N,1);
  rep(i,M){
    int x,y;
    cin >>x>>y;
    if(H.at(x-1)>=H.at(y-1)) T.at(y-1)=0;
    if(H.at(x-1)<=H.at(y-1)) T.at(x-1)=0;
  }
  //for(int x:H)cout << x << endl;
  cout << count(T.begin(),T.end(),1) <<endl;
    

  
}

Measured memory_bytes: 4052
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int trees[1000][1000];
int main(){
  int H, W;
  cin>>H>>W;
  int row[1000] = {};
  int col[1000] = {};
  REP(y, H) REP(x, W) {
    cin>>trees[y][x];
    row[y] ^= trees[y][x];
    col[x] ^= trees[y][x];
  }
  REP(y, H){
    REP(x, W){
      cout<< (row[y] ^ col[x] ^ trees[y][x] ^ 1);
      if(x == W - 1) cout<<endl;
      else cout<<" ";
    }
  }
  return 0;
}

Measured memory_bytes: 5072
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 10 (getl toInt) <*> replicateM 10 (getl toInt) >>= putStrLn . unwords . map show

solve :: [Int] -> [Int] -> [Int]
solve xs ys = map f [xs, ys]
  where
    f = sum . take 3 . sortBy (flip compare)

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3688
//8:15
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  static bool comp[250000];
  vector<int> prime;
  for(int i=2;i<250000;i++){
    if(!comp[i]){
      for(int j=2;i*j<250000;j++){
	comp[i*j]=true;
      }
      prime.push_back(i);
    }
  }
  for(int n;cin>>n,n;){
    cout<<lower_bound(prime.begin(),prime.end(),2*n+1)-lower_bound(prime.begin(),prime.end(),n+1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
   };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
} 

fn main() {
    input!{
        n: usize,
        m: usize,
    }
    println!("{}", if n == m {"Yes"} else {"No"});
}



Measured memory_bytes: 4352