akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
#define pw(a) (1ll<<(a))
int main(){
	ll A,B;read(A,B);
	int T=0;
	repd(i,60,0)
		if(pw(i)&B){
			if(pw(i)&A)A^=pw(i),B^=pw(i);else
				{T=i;break;}
		}
	if(A==B)return puts("1"),0;
	int k=-1;
	repd(i,T-1,0)if(B&pw(i)){k=i;break;}
	ll l1=A,r1=pw(T)+pw(k+1)-1;
	ll l2=pw(T)+A,r2=pw(T)*2-1;
	ll ans=0;
	if(l2>r1)ans=r1-l1+1+r2-l2+1;else
		ans=max(r2,r1)-min(l1,l2)+1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int dp[3005][3005];
int main()
{
    string s,t;
    cin>>s>>t;
    int a=s.length(),b=t.length(),i,j;
    for(i=1;i<=a;i++)
    {
        for(j=1;j<=b;j++)
        {
            if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
   // cout<<dp[a][b];
 
   int ind=dp[a][b];
     char ans[ind+1];
     ans[ind]='\0';
   while(a>0 && b>0)
   {
       if(s[a-1]==t[b-1])
       {
           ans[ind-1]=s[a-1];
           a--;
           b--;
           
           ind--;
       }
       else
       {
           if(dp[a-1][b]>dp[a][b-1]) a--;
           else b--;
       }
   }
   
   cout<<ans;
    return 0;
}

Measured memory_bytes: 35456
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    map<string, int> mp;
    while(q--) {
        int t;
        cin >> t;
        if(t == 0) {
            string key;
            int x;
            cin >> key >> x;
            mp[key] = x;
        } else if(t == 1) {
            string key;
            cin >> key;
            cout << (mp.count(key)?mp[key]:0) << '\n';
        } else if(t == 2) {
            string key;
            cin >> key;
            mp.erase(key);
        } else {
            string l, r;
            cin >> l >> r;
            for(auto itr = mp.lower_bound(l); itr != mp.upper_bound(r); itr = next(itr, 1)) {
                cout << *itr << '\n';
            }
        }
    }
}


Measured memory_bytes: 25764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int x;cin>>x;
	cout<<x*x*x<<endl;
	return 0;
}


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

int main() {
  string s, mx = "zyxwvutsrqponmlkjihgfedcba";
  cin >> s;

  if (s == mx) {
    cout << -1 << endl;
    return 0;
  }

  vector<bool> v(26);
  for (int i = 0; i < s.size(); ++i)
    v[s[i] - 'a'] = true;

  string ans = s;
  if (s.size() == 26) {
    for (int i = s.size() - 1; i >= 1; --i) {
      if (s[i - 1] < s[i]) {
        char c = s[i];
        for (int j = i; j < s.size(); ++j)
          if (s[i - 1] < s[j])
            c = min(c, s[j]);
        ans = ans.substr(0, i - 1) + c;
        break;
      }
    }

  } else {
    for (int i = 0; i < v.size(); ++i) {
      if (v[i])
        continue;
      ans.push_back(i + 'a');
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    x = int(input())

    depo = 100
    ans = 0

    while 1:
        ans += 1
        depo = int(depo * 1.01)

        if depo >= x:
            break

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """103"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1000000000000000000"""
        output = """3760"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1333333333"""
        output = """1706"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

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

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const int MAXN = 1e5;

int main()
{
    int n;

    cin >> n;
    vector<int> x(n),y(n) ,t(n);
    for(int i = 0; i < n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    vector<int> d(n),dt(n);

    d[0] = x[0] + y[0];
    dt[0] = t[0];

    for(int i = 1; i < n; i++)
    {
        d[i] = (x[i] - x[i-1]) + (y[i] - y[i-1]);
        dt[i] = t[i] - t[i-1];
    }

    for(int i = 0; i < n; i++)
    {
        if (d[i] > dt[i] || (d[i] <= dt[i] && (dt[i] - d[i]) % 2 != 0) )
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	
	int dig2 = n/100;		//cout << dig2 << endl;
	int dig1 = (n-100*dig2)/10;	//cout << dig1 << endl;
	int dig0 = n-100*dig2-10*dig1;	//cout << dig0 << endl;
	
	if(dig2==9)	dig2=1;
	else		dig2=9;
	if(dig1==9)	dig1=1;
	else		dig1=9;
	if(dig0==9)	dig0=1;
	else		dig0=9;
	
	
	cout << 100*dig2+10*dig1+dig0 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
char s[N];

int main() {
  int n;
  scanf("%d%s", &n, s);
  int tot = 0;
  for (int i = 0; i < n; ++i) tot += s[i] == 'W';
  int ret = tot;
  int sum = 0;
  for (int k = 1; k <= tot; ++k) {
    sum += s[n - k] == 'R';
    ret = min(ret, tot - k + sum);
  }
  printf("%d\n", ret);
  return 0;
}


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

int main()
{
  int n, x, i, sum, j, k;
   while(1){
  cin >> n >> x;
  if( n + x == 0) break;
  sum=0;

 for(i=1; i<= n-2;i++){
  for(j=1+i; j<= n-1; j++){
   for(k=1+j; k<= n; k++){
    if(i+j+k==x) 
     sum+=1;
    
    }
   }
  }
   cout << sum << endl;
  }
 }
  

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    int n; scanf("%d",&n);
    string s; cin>>s;
    if(n&1){
        printf("No\n"); return 0;
    }
    bool f=1;
    rep(i,0,n/2)if(s[i]!=s[i+n/2])f=0;
    printf(f?"Yes\n":"No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int D, T, S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> D >> T >> S;

	int x = T * S;
	if (D <= x) cout << "Yes" << endl;
	else cout << "No" << endl;
}







Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;
vector<vector<ll>> dp;
//G[i][j]は、iからjへの有向線分があればその長さ、なければ-1。i=jの場合は0。
vector<vector<ll>> G;

ll v;
//rec(b,u)は、bの元(bはbit)を全部通ってかつ最初が0で最後がuの場合の最小距離
ll rec(ll b,ll u){
  //探索済みなら良い
  if(dp[b][u]!=-1)return dp[b][u];

  //移動する必要はない
  if(b == (1<<u) )return dp[b][u]=0;

  ll res = inf;

  if(b==(1<<v)-1 && u==0){
    for(int i=1;i<v;i++){
      if(G[i][u]==-1){
        continue;  //iからuに向けて道がなければスキップ
      }
      res=min(res,rec(b,i)+G[i][u]);
    }
  }
  else if(u==0){
    ;
  }
  else{
    //bからuを除く
    ll pb = b & ~(1<<u);
    for(int i=0;i<v;i++){
      if(!(pb & ( 1<< i))){
        continue;  //pbにiが属さなければスキップ
      } 
      if(G[i][u]==-1){
        continue;  //iからuに向けて道がなければスキップ
      }
      res=min(res,rec(pb,i)+G[i][u]);
    }
  }

  return dp[b][u]=res;
}

int main(){

  ll e;
  cin >> v >> e;

  //Gの大きさを整える
  G.resize(v);
  for(int i=0;i<v;i++){
    G[i].resize(v);
  }

  //Gに数字を入れていく
  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      if(i!=j)G[i][j]=-1;
      else G[i][j]=0;
    }
  }

  //入力。
  for(int i=0;i<e;i++){
    ll s,t,d;
    cin >> s >> t >> d;
    G[s][t]=d;
  }
  
  //dpのサイズ
  dp.resize((1<<v) +1);
  for(int i=0;i<(1<<v) +1;i++){
    dp[i].resize(v+1);
  }

  //初期化
  for(int i=0;i<(1<<v) +1;i++){
    for(int j=0;j<v+1;j++){
      dp[i][j]=-1;
    }
  }

  dp[1<<0][0]=0;

  ll re = inf;

  //for(int i=0;i<v;i++){
    //if(G[i][0])
    re = min(re,rec((1<<v)-1,0));
  //}

  if(re==inf)re=-1;
  cout << re << endl;
}


Measured memory_bytes: 8048
#include <iostream>
using namespace std;
 
int main()
{
 int a[3],s=0,f=0;
 
 for(int i=0;i<3;i++)
 {
      cin>>a[i];
     if(a[i]==7){
        s++;
     }
     else if(a[i]==5){
        f++;
     }
 }
 if(s==1 && f==2){
    cout<<"YES";}
 else{
    cout<<"NO";
 }
}

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

#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

vector<int> friends[100005];
vector<int> groups[100005];

// union by size + path having
class UnionFind {
public:
  vector <ll> par;
  vector <ll> siz;

  // Constructor
  UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }
  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind tree1(n+1);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    friends[a].push_back(b);
    friends[b].push_back(a);
    tree1.merge(a, b);
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    groups[c].push_back(d);
    groups[d].push_back(c);
  }

  for (int i = 1; i <= n; i++) {
    long long cnt = tree1.size(i)-1; // 閾ｪ蛻��ｒ蠑輔￥
    vector<int> t;
    for (int j = 0; j < friends[i].size(); j++) {
      t.push_back(friends[i][j]);
    }
    for (int j = 0; j < groups[i].size(); j++) {
      if (tree1.issame(i, groups[i][j])) {
        t.push_back(groups[i][j]);
      }
    }
    sort(t.begin(), t.end());
    unique(t.begin(), t.end());
    int dif = t.size();
    cout << cnt-(dif);
    cout << ( (i == n) ? "\n" : " ");
  }

  return 0;
}


Measured memory_bytes: 13816
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))

# dp[n][k][s] : n枚目までからk枚選んで合計をsにする場合の数
dp = [[[0 for _ in range(2501)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for n in range(1,N+1):
    for k in range(n+1):
        for s in range(50*k+1):
            if n>=1 and s<X[n]:
                dp[n][k][s] = dp[n-1][k][s]
            elif n>=1 and k>=1 and s>=X[n]:
                dp[n][k][s] = dp[n-1][k][s] + dp[n-1][k-1][s-X[n]]

Ans = 0
for i in range(1,N+1):
    Ans += dp[N][i][i*A]

print(Ans)

Measured memory_bytes: 65520
#include <cstdio>
#include <queue>
#include <vector>
#include <utility>
using namespace std;

typedef pair<int,int> pii;

struct state{
	int v, d, c;
	bool operator< (const state &s) const{
		if(d != s.d){ return d > s.d; }
		return c > s.c;
	}
};

int main(){
	int n, m, u, v, d, c;
	while(scanf("%d%d", &n, &m), n){
		vector<vector<state> > G(n + 1);
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d%d", &u, &v, &d, &c);
			G[u].push_back((state){v, d, c});
			G[v].push_back((state){u, d, c});
		}

		vector<pii> t(n + 1, pii(1 << 30, 1 << 30));
		t[1] = pii();
		int ans = 0;
		priority_queue<state> pq;
		pq.push((state){1, 0, 0});
		while(!pq.empty()){
			state s = pq.top();
			pq.pop();
			if(pii(s.d, s.c) != t[s.v]){ continue; }
			ans += s.c;

			for(int i = 0; i < G[s.v].size(); ++i){
				v = G[s.v][i].v;
				d = G[s.v][i].d + s.d;
				pii p(d, G[s.v][i].c);
				if(t[v] > p){
					t[v] = p;
					pq.push((state){v, d, G[s.v][i].c});
				}
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 2228
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
  string S[100];
  int N, L;

  cin >> N >> L;

  for(int i = 0;i < N;i++){
    cin >> S[i];
  }
  
  sort(S, S+N);

  for(int i = 0;i < N;i++){
    cout << S[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int s = sc.nextInt();

		for (int d = 0; d < s; d++) {

			int e[] = new int[8];
			for (int i = 0; i < 8; i++) {
				e[i] =(int) sc.nextLong(16);
			}

			int z =(int) sc.nextLong(16);

			int cob[] = new int[32];
			int f = 1;
			int sum = 0;

			for (int i = 0; i < 32; i++) {
				cob[i] = -f * 4;
				for (int j = 0; j < 8; j++) {
					if ((e[j] & f) != 0) {
						cob[i] += f;
					}
				}
				cob[i] = cob[i] * 2;
				if ((z & f) != 0) {
					cob[i] -= f;
				} else {
					cob[i] += f;
				}
				f = f << 1;
			}
			for (int j = 0; j < 8; j++) {
				sum += e[j];
			}
			int diff = sum - z;
//			System.out.println(diff);
//			System.out.println(Arrays.toString(cob));
			f = 1;
			int ans = 0;
			for(int i = 0; i < 32; i++){
				if((diff & f) != 0){
					ans+=f;
					diff -= cob[i];
				}
				f = f<<1;
			}
			
			System.out.println(Integer.toHexString(ans) );
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int main(){
  int flag=0,a,i,c[5]={0,0,0,0};
  for(i=0;i<6;i++){
    scanf("%d",&a);
    c[a]++;
    if(c[a]>=3){
      flag=1;
    }
  }

  if(flag==0){
    printf("YES");
  }else{
    printf("NO");
  }
}


Measured memory_bytes: 128
def main():
    n = int(input())
    x1 = 1
    x2 = 2
    if n == 1:
        print(1)
    else:
        ans = 0
        for _ in range(n-1):
            ans = x1+x2
            t = x2
            x2 = x1
            x1 = x1 + t
        print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <string.h>
#include <stdio.h>
int main(void){
  char str[10];
  int mojisuu=0;
  while(mojisuu!=6){
    scanf("%s",&str);
    mojisuu=strlen(str);
  }
  if(str[2]==str[3] && str[4]==str[5])
    printf("Yes");
  else printf("No");
  return 0;
}


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

int main() {
	long n,m,i,j,cur,res;
	cin >> n >> m;
	vector<long> a(n),b(n),c(m),d(m);
	for(i=0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(i=0; i<m; i++){
		cin >> c[i] >> d[i];
	}
	for(i=0; i<n; i++){
		cur=0; res=1000000000;
		for(j=0; j<m; j++){
			if(res>abs(a[i]-c[j])+abs(b[i]-d[j])){
				cur=j;
				res=abs(a[i]-c[j])+abs(b[i]-d[j]);
			}
		}
		cout << cur+1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ok;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=9;i++){
        if(i<=n){
            if(n%i==0){
                if(n/i<=9){
                    ok=1;
                    break;
                }
            }
        }
    }

    if(ok==1)cout<<"Yes";
    else cout<<"No";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N,A[100000];
    cin >> N;
    for(int i = 0;i < N;i++)cin >> A[i];
    sort(A,A+N,greater<int>());
    ll a[2] = {};
    for(int i = 0,idx = 0;i < N-1;i++){
        if(A[i] == A[i+1]){
            a[idx++] = A[i];
            i++;
        }
    }
    cout << a[0] * a[1] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int lli;
#define MOD 1000000007	
using namespace std;



int main()
{
 	lli D,T,S;
 	cin>>D>>T>>S;

 	if(D<=S*T) cout<<"Yes";
 	else cout<<"No";
 	

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000000000000000000;
const char END = '\n';


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

	ll N, M, A, Ans = 0;
	cin >> N >> M;
	rep(i, M) {
		cin >> A;
		Ans += A;
	}
	if (N>= Ans)
		cout << N - Ans;
	else
		cout << -1;
	cout << END;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int f[1<<26],d[N];
char s[N];
int main()
{
	memset(f,0x3f,sizeof f);
	scanf("%s",s);
	int m=0,t;f[0]=0;
	for(int i=0;s[i];i++)
	{
		m^=1<<(s[i]-'a');
		t=f[m]+1;
		for(int j=0;j<26;j++) 
			t=min(t,f[m^(1<<j)]+1);
		f[m]=min(f[m],t);
	}
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 262656
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	double a,b,S;
	cin>>a>>b;
	S=a*b/3.305785;
	fcout(6)<<S<<endl;
}

Measured memory_bytes: 3248
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M = inpl()
ed = defaultdict(lambda:False)
for i in range(M):
	a,b = inpl()
	if a == 1:
		if ed[b]:
			print('POSSIBLE')
			sys.exit()
		else:
			ed[b] = True
	elif b == N:
		if ed[a]:
			print('POSSIBLE')
			sys.exit()
		else:
			ed[a] = True

print('IMPOSSIBLE')


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

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

int lcm(int a,int b){
  return a*b/ gcd(a,b);
}
string Encode(string s,int n,int m){
  string res = s;
  rep(i,s.size()){
    if(s[i] != ' '){
      s[i] = (n * (s[i]-'a')+m )%26+'a';
    }
  }
  return s;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector< pair<string,pair<int,int>>> list(0);
  REP(i,1,26){
    if(gcd(i,26) == 1){
      rep(j,26){
        list.pb(make_pair(Encode("this",i,j),make_pair(i,j)));
        list.pb(make_pair(Encode("that",i,j),make_pair(i,j)));
      }
    }
  }
  int n,a,b;
  string s;
  cin >> n;
  cin.ignore();
  rep(i,n){
    vary(string,vs,0,"");
    getline(cin,s);
    string tmp="";
    rep(i,s.size()){
      if(s[i] == ' '){
        vs.pb(tmp);
        tmp.clear();
      }
      else tmp+=s[i];
    }
    vs.pb(tmp);
    rep(i,list.size()){
      rep(j,vs.size()){
        if(list[i].fi == vs[j]){
          a = list[i].se.fi;
          b = list[i].se.se;
        }
      }
    }
    s.clear();
    map<char,char> m;
    rep(i,26){
      char c[1] = {char('a'+i)};
      string str = c;
      m[Encode(str,a,b)[0]] = char('a'+i);
    }
    rep(i,vs.size()){
      rep(j,vs[i].size()){
        vs[i][j] = m[vs[i][j]];
      }
      s += vs[i];
      s += " ";
    }
    s.resize(s.size()-1);
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3212
import sys
input = sys.stdin.readline

N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
MOD = 998244353

for i in range(N):
    for j in range(S):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        
        if j+A[i]<=S:
            if j==0:
                dp[i+1][j+A[i]] += dp[i][j]*(i+1)
            else:
                dp[i+1][j+A[i]] += dp[i][j]
            
            dp[i+1][j+A[i]] %= MOD

ans = 0

for i in range(1, N+1):
    ans += dp[i][S]*(N-i+1)
    ans %= MOD

print(ans)

Measured memory_bytes: 112732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MX = 200005, MOD = 1e9+7;
int n, a[2];
ll ans, d, x, y, t;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
void exgcd(ll a, ll b, ll &x, ll &y){
	if(b){
		exgcd(b, a%b, y, x);
		y -= a/b*x;
	}else{
		x = 1; y = 0; d = a;
	}
}
int main(){
	scanf("%d%d%d", &n, a, a+1);
	ans = exp(2,n) - 1;
	rep(i,2){
		t = 1;
		rep(j,a[i]){
			exgcd(j+1,MOD,x,y);
			(t *= (n-j) * x % MOD) %= MOD;
		}
		ans -= t;
	}
	ans %= MOD;
	if(ans < 0) ans += MOD;
	printf("%lld\n", ans);
}

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

int main() {
	ll n;
	cin >> n;
	vector <ll> arr(n-1);
	ll total=0;
	ll temp=0;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n-1; ++i)
	{
		if (i==0){
			temp=arr[i];
			total+=(2*(arr[i]));
		}
		else {
			if (arr[i]>=temp){
				temp=arr[i];
				total+=arr[i];
			}
			else {
				temp=arr[i];
				total-=arr[i-1];
				total+=(2*arr[i]);
			}
		}
	}
	cout << total;
}

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>  
#include <cstdlib>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int N;
    cin >> N;
    int p[110000];
    int cnt = 0;
    rep1(i,N) cin >> p[i];

    rep1(i,N) {
        if (i==p[i]) {
            swap(p[i], p[i+1]);
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;

}

Measured memory_bytes: 640
#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 A,B,C,D;
  cin >> A >> B >> C >> D;
  rep(i,100){
    C-=B;
    if(C<=0){
      cout << "Yes" << endl;
      break;
    }
    A-=D;
    if(A<=0){
      cout << "No" << endl;
      break;
    }
  }
    

}

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

int main()
{
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    int K = sc.nextInt();
    int X = sc.nextInt();


    for(int i = 1;i<K+K;i++){
      System.out.print(X-(K-i));
      System.out.print(" ");
    }

  }
}

Measured memory_bytes: 22100
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    int x=a/b;
    if(a%b)
        ++x;
    cout<<x;
    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int n;
    cin>>n;
    Vi v(n);
    REP(i,n) cin>>v[i];

    sort(ALL(v));

    double total = v[0]/1.0;
    REP2(i,1,n){
        total = (total+v[i])/2.0;
    }
    cout<<total<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int A[N], B[N];
  FOR(i,0,N) cin >> A[i] >> B[i];

  vector<PP> v(N);
  FOR(i,0,N) {
    v[i] = PP(A[i]+B[i], P(A[i], B[i]));
  }
  sort(v.rbegin(), v.rend());
  ll ans = 0;
  FOR(i,0,N) {
    if(i&1){
ans -= v[i].second.second;
    }
    
    else {
      ans += v[i].second.first;
    }
  }
  cout << ans << endl;

}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    ll x, k, d;
    cin >> x >> k >> d;
    
    ll ans = 1e18;
    ll ax = abs(x);
    ll hoge = min(ax / d, k);
    hoge -= (hoge % 2 != k % 2);
    if (hoge >= 0) ans = ax - hoge * d;
    if (hoge + 2 <= k) ans = min(ans, abs(ax - (hoge + 2) * d));
    cout << ans << newl;

    return 0;
}

Measured memory_bytes: 3596
# 2019-11-23 21:00:35(JST)
import sys
import itertools

def main():
    n, *A = map(int, sys.stdin.read().split())

    S = sum(A)
    l = 0
    for i in range(n):
        l += A[i]
        if l >= S // 2:
            if l == S / 2:
                ans = 0
                break
            else:
                if l == S // 2 - 1:
                    ans = 1
                    break
                else:
                    if l - A[i] >= S - l:
                        ans = A[i] + (S - l) - (l - A[i])
                    else:
                        ans = l - (S - l)
                    break

    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 25596
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (c - b == b - a) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  int a, b;cin >> a >> b;
  int res = 0;
  rep1(i,n) {
    int sum = 0;
    int x = i;
    while(x > 0) {
      sum += x % 10;
      x /= 10;
    }
    if(a <= sum && sum <= b) res += i;
  }
  cout << res << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector <ll> A(n);
    for (int i = 0; i < n; i++){
        ll a;
        cin >> a;
        A[i] = a;
    }
    
    sort(A.begin(), A.end());
    
    for(int j = 0; j < n-1; j++){
//        cout << A[j] << ":" << A[j+1] << endl;
        if(A[j] == A[j+1]){
            cout << "NO" << endl;
            return 0;
        }
        
    }
    
    cout << "YES" << endl;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

ll fact[6001];
ll ifact[6001];
constexpr ll MOD = 998244353;
// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll comb(ll n, ll k) {
  return fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}

int main() {
  fact[0] = 1;
  REP(i,6000) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  ifact[6000] = inv(fact[6000], MOD);
  REP(ri,6000) {
    int i = 6000 - ri;
    ifact[i-1] = ifact[i] * i % MOD;
  }
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll k,n;
  cin>>k>>n;
  FOR(i,2,2*k+1) {
    ll one = 0, many = 0;
    ll sel = 0;
    FOR(j,1,k+1) {
      int rev = i - j;
      if (rev >= 1 && rev <= k) {
        if (rev == j) ++one;
        else if (rev > j) {
          ++sel;
        }
      } else {
        ++many;
      }
    }
    ll ans = 0;
    REP(use,2) {
      if (use && !one) continue;
      ll m = n - use;
      ll p2 = 1;
      REP(j,min(sel,m)+1) {
        ans += comb(sel, j) * p2 % MOD * comb(m+many-1, m-j) % MOD;
        ans %= MOD;
        p2 *= 2;
        p2 %= MOD;
      }
    }
    cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>
 int main()
 { 
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
if(b-c>=0)printf("delicious\n");
else if(abs(b-c)<=a)printf("safe\n");
 else printf("dangerous\n");   }
    

Measured memory_bytes: 2088
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, m;
  cin >> n >> m;
  vector<pll> v;
  rep(i, n)
  {
    ll a;
    cin >> a;
    v.push_back(MP(a, 1));
  }
  rep(i, m)
  {
    ll b, c;
    cin >> b >> c;
    v.push_back(MP(c, b));
  }
  sort(all(v), greater<pll>());
  int i = 0;
  ll sum = 0;
  rep(j, v.size())
  {
    if (i + v[j].second >= n)
    {
      sum += v[j].first * (n - i);
      i = n;
      break;
    }
    else
    {
      sum += v[j].first * v[j].second;
      i += v[j].second;
    }
  }
  cout << sum << endl;
  return 0;
}


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

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

  string s;
  cin >> s;

  int ans = (1 << 28);
  for (int i = 0; i + 3 <= s.size(); i++) {
    int x = stoi(s.substr(i, 3));
    ans = min(ans, abs(x - 753));
  }
  cout << ans << endl;

  return 0;
}

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

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

    string n;
    cin >> n;


    int ans = 0;

    while(n.size() > 0) {
        int t = n.back() - '0';
        ans += t;
        n.pop_back();
    }

    if(ans % 9 == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 3716
import sys

def getInt():
	return int(sys.stdin.readline().rstrip())

def gcd(a, b):
	while b > 0:
		r = a % b
		a = b
		b = r
	return a

def lcm(a, b):
	return (a // gcd(a, b)) * b

N = getInt()

answer = 1

for i in range(N):
	answer = lcm(answer, getInt())

print(answer)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans;
int N, M, X, Y;

int main(void) {
    scanf("%d %d %d %d", &N, &M, &X, &Y);

    int x_max = X;
    int y_min = Y;

    REP(i, 0, N) {
    	int x;
    	scanf("%d", &x);
    	x_max = max(x_max, x);
    }

    REP(i, 0, M) {
    	int y;
    	scanf("%d", &y);
    	y_min = min(y_min, y);
    }

    if (x_max < y_min) puts("No War");
    else puts("War");
    
	return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

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

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

S=sum(A)
T=0

for i in range(N):
    SS=S-A[i]
    TT=T+A[i]
    if SS-TT<=0:
        if abs(SS-TT)<abs(S-T):
            ans=abs(SS-TT)
            #print(SS,TT)
            #print("a")
        else:
            ans=abs(S-T)
            #print("b")
        break
    T+=A[i]
    S-=A[i]

print(ans)

Measured memory_bytes: 26764
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int x,y;
  cin >> x >> y;
  int a,b;
  int animal,foot;
  bool flg;
  flg=false;
  for(ii=0;ii<=x;ii++){
    a = ii;
    b = x-ii;

    if(y == (2*a + 4*b)){
      flg = true;
    }
    
  }

  if(flg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3632
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val count = Array(10) { Array(10) { 0 } }
    for (i in 1..n) {
        val s = i.toString()
        val j = s.first().toString().toInt()
        val k = s.last().toString().toInt()
        count[j][k]++
    }
    var ans = 0L
    for (i in 1..9) {
        for (j in 1..9) {
            ans += count[i][j] * count[j][i]
        }
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, string> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
string s;
map<P,ll> cnt;

int main(){
  cin>>n;
  cin>>s;
  ll res=0;
  rep(S,1<<n){
    string s1,s2;
    rep(i,n){
      if((S>>i)&1LL)s1+=s[i];
      else s2+=s[i];
    }
    reverse(all(s2));
    cnt[P(s1,s2)]++;
  }
  rep(S,1<<n){
    string s1,s2;
    repl(i,n,n*2){
      if((S>>(i-n))&1LL)s1+=s[i];
      else s2+=s[i];
    }
    reverse(all(s2));
    res+=cnt[P(s2,s1)];
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 87040
#include<iostream>
using namespace std;
int main(){
	int week,kiri,kane=100000,i;
	cin>>week;
	for(i=0;i<week;i++){
		kane=(double)kane*1.05;
		kane=kane+999;
		kiri=kane%1000;
		kane=kane-kiri;
	}
	cout<<kane<<endl;
	return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int N, M;
vector<vector<P>> edge;
ll ischecked[100000];

bool flg = true;

void dfs(int pos) {

	for (int i = 0; i < edge[pos].size(); i++) {
		P next = edge[pos][i];
		if (ischecked[next.first] == -1145141919810) {
			ischecked[next.first] = ischecked[pos] + next.second;
			dfs(next.first);
		}
		else {
			if (ischecked[next.first] != ischecked[pos] + next.second) {
				flg = false;
				return;
			}
		}
	}
}

int main() {
	for (int i = 0; i < 100000; i++)ischecked[i] = -1145141919810;
	cin >> N >> M;
	edge.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		ll d;
		cin >> a >> b >> d;
		a--, b--;
		edge[a].push_back(make_pair(b, d));
		edge[b].push_back(make_pair(a, -d));
	}

	for (int i = 0; i < N; i++) {
		if (ischecked[i] == -1145141919810) {
			ischecked[i] = 0;
			dfs(i);
		}
	}

	if (!flg)cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,K;
ll A[100];
ll dp[100];
ll i, j, k;

void mxin(ll& a,ll b){
    if(a<b)
        a = b;
}

int main(){
    scanf("%lld", &N);
    rep(i,0,N){
        scanf("%lld", &A[i]);
    }
    
    dp[0] = 1000;
    rep(i,1,N+1){
        dp[i] = dp[i - 1];
        rep(j,0,i){
            ll a = dp[j] / A[j];
            a = dp[j] + a * (A[i] - A[j]);
            mxin(dp[i], a);
        }
    }
    printf("%lld\n", dp[N]);

    return 0;
}

Measured memory_bytes: 3828