akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int main(){
FASTIO;
int n,m,i,x,penalty=0,ac=0;
cin>>n>>m;
int a[n+1];
string verdict;
memset(a,0,sizeof(a));
for(i=0;i<m;i++){
    cin>>x>>verdict;
    if(a[x]==-1)
        continue;
    if(verdict=="AC"){
        penalty+=a[x];
        a[x]=-1;
        ac++;
    }
    else a[x]++;
}
cout<<ac<<" "<<penalty<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
  public static void main(String [] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt();
    int max=a, min=a, mid=a;
    if((b==c)||(a==b)||(a==c)){
      if(b==c){
        if(a>b){
          System.out.println(c+" "+b+" "+a);
        }
        else{
          System.out.println(a+" "+c+" "+b);
        }
      }
      else if(a==b){
        if(a<c){
          System.out.println(b+" "+a+" "+c);
        }
        else{
          System.out.println(c+" "+b+" "+a);
        }
      }
      else if(a==c){
        if(b>c){
          System.out.println(a+" "+c+" "+b);
        }
        else{
          System.out.println(b+" "+c+" "+a);
        }
      }
    }
    else{
      if(b>c){
        if(b>max){
          max=b;
        }
      }
      else{
        if((c>b)&&(c>max)){
          max=c;
        }
      }
      //System.out.println(max);
      if(b<c){
        if(b<min){
          min=b;
        }
      }
      else{
        if((c<b)&&(c<min))
          min=c;
      }
      //System.out.println(min);
      if((b>min)&&(b<max)){
        mid=b;
      }
      else if((c>min)&&(c<max)){
        mid=c;
      }
      //System.out.println(mid);
      System.out.println(min+" "+mid+" "+max);
    }
  }
}


Measured memory_bytes: 26208
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long ll;
mt19937 rdf(time(0));
int rd(int s, int e) { return rdf() % (e-s+1) + s; }

const int MOD = 1000009399;
const int MAXN = 250055;

ll pw(ll n, ll k) {
	ll r = 1; for(; k; k >>= 1) {
		if(k & 1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

struct NOD {
	NOD(int a = 1, int b = 0) : a(a), b(b) {}
	int a, b;

	int operator () (int t) const {
		return (ll(a)*t + b) % MOD;
	}
	NOD operator * (const NOD &t) const {
		return NOD(ll(a)*t.a % MOD, (ll(a)*t.b + b) % MOD);
	}
} nod[6][MAXN], gma[6][4];

map<vector<int>, int> MP;

int X[6], RX[6], C[6];

char A[MAXN];

ll Ans;
int N;

int f(char c) {
	if('+' == c) return 0;
	if('-' == c) return 1;
	return '>' == c ? 2 : 3;
}

int main() {
	scanf("%d %s", &N, A+1);

	for(int i = 0; i < 6; i++) {
		X[i] = rd(40148, 957370123);
		RX[i] = inv(X[i]);

		gma[i][0] = NOD(1, MOD-1);
		gma[i][1] = NOD(1, 1);
		gma[i][2] = NOD(RX[i], 0);
		gma[i][3] = NOD(X[i], 0);

		for(int j = N; j; j--) {
			nod[i][j] = nod[i][j+1] * gma[i][f(A[j])];
			C[i] = gma[i][f(A[j])^1](C[i]);
		}
	}

	for(int i = N; i; i--) {
		vector<int> V(6);
		for(int j = 0; j < 6; j++) V[j] = nod[j][i+1](0);
		MP[V]++;
		for(int j = 0; j < 6; j++) V[j] = nod[j][i](C[j]);
		auto it = MP.find(V);
		if(MP.end() != it) Ans += it -> second;
	}

	cout << Ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> dp(h + 1, vector<int>(w, 0));
    dp[0][0] = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < (1 << (w - 1)); j++) {
            bool invalid = false;
            for (int k = 0; k < w - 2; k++) {
                if ((j & (1 << k)) > 0 && (j & (1 << (k + 1))) > 0) {
                    invalid = true;
                }
            }

            if (invalid) {
                continue;
            }

            for (int k = 0; k < w; k++) {
                if (k > 0 && (j & (1 << (k - 1))) > 0) {
                    dp[i + 1][k - 1] = (dp[i + 1][k - 1] + dp[i][k]) % 1000000007;
                } else if ((j & (1 << k)) > 0) {
                    dp[i + 1][k + 1] = (dp[i + 1][k + 1] + dp[i][k]) % 1000000007;
                } else {
                    dp[i + 1][k] = (dp[i + 1][k] + dp[i][k]) % 1000000007;
                }
            }
        }
    }

    cout << dp[h][k - 1] << endl;
}


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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 13;
const long long Q = 100000001;
const long long mod = 1e9 + 7;
const long long MAGIC = 30;

using namespace std;

int n;
int m;
int r[N];
string s[N];
string t[N];
char c[N][N];
bool used[N];

void make()
{
        for(int i = 1; i <= m; i++){
                s[i] = "";
                used[i] = false;
                for(int j = 1; j <= n; j++){
                        s[i] += c[r[j]][i];
                }
                t[i] = s[i];
                reverse(t[i].begin(), t[i].end());
        }
        bool P = false;
        for(int i = 1; i <= m; i++){
                if(used[i]){
                        continue;
                }
                used[i] = 1;
                bool found = false;
                for(int j = 1; j <= m; j++){
                        if(used[j]){
                                continue;
                        }
                        if(t[j] == s[i]){
                                used[j] = 1;
                                found = 1;
                                break;
                        }
                }
                if(found == false){
                        if(m % 2 == 0 || P == true){
                                return;
                        }
                        P = true;
                }
        }
        cout << "YES" << "\n";
        exit(0);
}

bool usedR[N];

void rec(int l)
{
        if(l + n % 2 == n){
                make();
                return;
        }
        for(int i = 1; i <= n; i++){
                if(usedR[i] == false){
                        usedR[i] = true;
                        if(l % 2){
                                r[n - l / 2] = i;
                        }
                        else{
                                r[l / 2 + 1] = i;
                        }
                        rec(l + 1);
                        usedR[i] = false;
                        if(l % 2 == 0){
                                break;
                        }
                }
        }
}

void solve()
{
        cin >> n >> m;
        for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                        cin >> c[i][j];
                }
        }
        if(n % 2){
                for(int i = 1; i <= n; i++){
                        r[n / 2 + 1] = i;
                        usedR[i] = true;
                        rec(0);
                        usedR[i] = false;
                }
        }
        else{
                rec(0);
        }
        cout << "NO" << "\n";
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("maze.in");
        //fout("maze.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    a, b = list(map(int, input().split()))
    ans = []

    if a + b == 15:
        ans.append('+')
    if a * b == 15:
        ans.append('*')
    if len(ans) == 0:
        ans.append('x')

    print(''.join(ans))


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;

typedef tree<int, null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> new_data;


int main()
{
   int n,m;
   cin>>n>>m;
   cout<<ceil(n*1.0/m)<<endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  string s;
  cin>>s;
  char pc=s[0];
  int ans=0;
  rep(i,s.size()-1){
    if(s[i+1]!=pc){
      ans++;
      pc=s[i+1];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
from math import ceil

H, W, D = [int(i) for i in input().split()]
N = H*W
A = [[int(i) for i in input().split()] for _ in range(H)]

M = [0] * (N+1)
for h in range(H):
    for w in range(W):
        M[A[h][w]] = (h, w)

def f(s, t):
    if s==0: return 0
    return abs(s[0]-t[0])+abs(s[1]-t[1])


cumsum = [[0] for _ in range(D)]
for s in range(1, D+1):
    for i in range(s, N+1, D):
        if i <= D: cumsum[s-1].append(0)
        else: cumsum[s-1].append(cumsum[s-1][-1]+f(M[i-D], M[i]))

Q = int(input())
for _ in range(Q):
    L, R = [int(i) for i in input().split()]
    i = (L%D)-1
    if i==-1:
        print(cumsum[i][R//D] - cumsum[i][L//D])
    else:
        print(cumsum[i][ceil(R/D)] - cumsum[i][ceil(L/D)])

Measured memory_bytes: 24308
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	int x=3;
	if(a==b&&b==c){
		cout<<1<<endl;
	}
	else{
		if(a==b) x--;
	if(b==c) x--;
	if(a==c) x--;
	cout<<x<<endl;
	}

return 0;
}



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


ll N, M, K;

void solve() {
    cin >> N >> M >> K;
    ll res = 0;
    Rep1(i, 0, K){
         res = modint(modint(res) + comb(N-1, i)*modint(M)*modint(mod_pow(M-1, N-1-i, mod)));
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7760
#include <iostream>

using namespace std;

int main(){
  int t1, t2; cin >> t1 >> t2;
  double d = 360;
  if(t1 > t2){
    int tmp = t1;
    t1 = t2;
    t2 = tmp;
  }
  double res;
  if((double)(t2-(t1+t2)/2.0) < (double)-(t2-(360+t1+t2)/2.0))
    res = (t1+t2)/2.0;
  else{
    res = (360+t1+t2)/2.0;
    if(res > 360) res -= 360;
  }
  cout << res << endl;
  return 0;
}

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

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

  int H, W, N;
  cin >> H >> W >> N;
  int mx = 0;
  vector<int> cnt(N + 1); cnt[0] = N;
  vector<int> freq(W);
  auto Update = [&]() {
    while (mx < N && cnt[mx + 1] > 0) mx++;
    while (mx > 0 && cnt[mx] == 0) mx--;
  };
  vector<vector<int>> ls(H);
  for (int i = 0; i < N; i++) {
    int h, w;
    cin >> h >> w;
    h--, w--;
    ls[h].emplace_back(w);
    freq[w]++;
    cnt[freq[w]]++;
    Update();
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (auto j : ls[i]) {
      cnt[freq[j]]--;
      freq[j]--;
      Update();
    }
    ans = max(ans, mx + (int) ls[i].size());
    for (auto j : ls[i]) {
      freq[j]++;
      cnt[freq[j]]++;
      Update();
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 21936
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>


#

using namespace std;

#define ll long long

int n;
ll a[2005];

ll f[2005][2005];
int idx[2005];

ll absolute(ll val)
{
    return val < 0LL ? -val : val;
}

bool cmp(int A, int b)
{
    return a[A] > a[b];
}

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", a + i); idx[i] = i;
    }
    sort(idx + 1, idx + n + 1, cmp);
    for (int i = 0; i < n; i++) {
        ll curactive = a[idx[i+1]];
        ll curpos = idx[i+1];
        for (int l = 0; l <= i; l++) {
            int r = i - l;
            f[i+1][l+1] = max(f[i+1][l+1], f[i][l] + curactive * absolute(curpos - (l + 1)));
            f[i+1][l] = max(f[i+1][l], f[i][l] + curactive * absolute(curpos - (n - r)));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++) ans = max(ans, f[n][i]);
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 26500
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,a[5010],x[5010][210],w[5010],u;
L f[5010][5010],p;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	L k;
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++)
	  scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	    scanf("%d",&x[i][j]);
	for(i=1;i<=m;i++)
	  {
	   u=0;
	   for(j=1;j<=n;j++)
	     {
		  f[j][j]+=x[j][i];
		  f[j][j+1]-=x[j][i];
		  while(u && x[j][i]>x[w[u]][i])
		    {
			 f[j][w[u]+1]-=x[j][i]-x[w[u]][i];
			 f[j][w[u-1]+1]+=x[j][i]-x[w[u]][i];
			 u--;
			}
		  w[++u]=j;
		 }
	  }
	for(i=1;i<=n;i++)
	  for(j=1;j<=n;j++)
	    f[i][j]+=f[i][j-1];
	for(i=1;i<=n;i++)
	  for(j=i,k=f[i][i];j<=n;k-=a[j],j++,k+=f[j][i])
	    p=max(p,k);
	printf("%lld\n",p);
	return 0;
}


Measured memory_bytes: 200448
from math import factorial, ceil, floor # 階乗/切り上げ/切り捨て
from operator import itemgetter as ig
from collections import defaultdict as dd
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    x = sum(A[::2]) - sum(A[1::2])
    r = [x]
    for n in range(N - 1):
        r += [A[n] * 2 - r[-1]]
    print(*r)

main()


Measured memory_bytes: 15812
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int h, w;
  cin >> h >> w;
  vecstr s(h);
  REP(i,h){
    cin >> s[i];
  }
  REP(i,h){
    s[i] = "#" + s[i] + "#";
  }

  REP(i, w + 2){
    cout << "#" ;
  }
  cout << endl;
  REP(i,h){
    cout << s[i] << endl;
  }
  REP(i, w + 2){
    cout << "#" ;
  }
  cout << endl;
} 


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    int x=(n/a)*b;
    if(n%a)x+=b;
    int y=(n/c)*d;
    if(n%c)y+=d;
    cout << min(x,y) << endl;
}



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

using namespace std;

#define sp << " " <<

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a[4];
    for(int i=0;i<4;i++)
        cin >> a[i];
    sort(a,a+4);
    if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin>>A;
  cin>>B;
  if(A==1 && B==2){
  cout<<"3"<<endl;
  }
  if(A==1 && B==3){
  cout<<"2"<<endl;
  }
  if(A==3 && B==2){
  cout<<"1"<<endl;
  }
  if(A==3 && B==1){
  cout<<"2"<<endl;
  }
  if(A==2 && B==1){
  cout<<"3"<<endl;
  }
  if(A==2 && B==3){
  cout<<"1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let (x, y) = {
        let s = {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_owned()
        };
        let mut integers = s.split_whitespace();
        let p: i32 = integers.next().unwrap().parse().unwrap();
        let q: i32 = integers.next().unwrap().parse().unwrap();
        (p, q)
    };

    println!("{}", x+y/2);
}


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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const int MOD = 998244353;
const int mxN = 2e5+7;

ll f[mxN+7];

ll expo(ll x, ll y){
	ll res=1;
	while(y){
		if(y&1) res=(res*x)%MOD;
		x = (x*x)%MOD;
		y>>=1;
	}
	return res%MOD;
}

void fact(){
	f[0]=1;
	for(ll i=1;i<=mxN;i++)
		f[i]=(f[i-1]*i)%MOD;
}

ll com(ll n, ll r){
	return (((f[n]*expo(f[n-r],MOD-2))%MOD)*expo(f[r], MOD-2))%MOD;
}

int main(){
	setIO();
	fact();
	ll n, m, k,ans=0;
	cin>>n>>m>>k;
	for(ll i=0;i<=k;i++){
		ans=(ans+(com(n-1,i)*expo(m-1,n-1-i))%MOD)%MOD;
	}
	cout<<(ans*m)%MOD<<endl;
}

Measured memory_bytes: 5216
#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <utility>
#include <boost/foreach.hpp>
#include <cmath>

std::vector<long long int> ans;
long long int N, Q, sum;
long long int A[100000 + 1], B[100000 + 1], C[100000 + 1];
long long int count[100000 + 1];

void func() {
  for (int i = 1; i <= N; i++) {
    sum += A[i];
    count[A[i]]++;
  }
}

int main() {
  std::cin >> N;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }
  std::cin >> Q;
  for (int i = 1; i <= Q; i++) {
    std::cin >> B[i] >> C[i];
  }

  func();

  for (int i = 1; i <= Q; i++) {
    long long int tmp = count[B[i]];
    count[B[i]] = 0;
    count[C[i]] += tmp;
    sum = sum + tmp * (C[i] - B[i]);
    ans.push_back(sum);
  }

  for (std::size_t i = 0; i < ans.size(); i++) {
    std::cout << ans[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 7360
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int N,T,A; cin >> N >> T >> A;
  double dif;
  int res = 1;
  rep(i, N) {
    int H; cin >> H;
    double dif2 = abs(T-H*0.006 - A);
    if(i==0) dif = dif2;
    if(dif2 < dif) {
      dif = dif2;
      res = i+1;   // 1-origin
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int INF = 0xFFFFFFF;
	static long[][] hash = new long[32][32];
	static int[][][] buf = new int[2][8192][32];
	static long finish;

	public static void main(String[] args) {
		Random rnd = new Random();
		for (int i = 0; i < 32; ++i) {
			for (int j = 0; j < 32; ++j) {
				hash[i][j] = rnd.nextLong();
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 2; j <= 7; ++j) {
				finish ^= hash[(j - 1) * 4 + i][i * 8 + j];
			}
		}
		int T = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < T; ++i) {
			sb.append(solve() + "\n");
			//			System.out.println(solve());
		}
		System.out.print(sb);
	}

	static int solve() {
		ArrayList<Board> cur = new ArrayList<Board>();
		HashSet<Long> hashes = new HashSet<Long>(30000);
		cur.add(new Board(buf[0][0]));
		if (cur.get(0).h == finish) return 0;
		hashes.add(cur.get(0).h);
		int i = 1;
		for (; !cur.isEmpty(); ++i) {
			//			System.out.println("turn:" + i + " size:" + cur.size());
			ArrayList<Board> next = new ArrayList<Board>(cur.size());
			for (Board b : cur) {
				for (int j = b.fix * 4; j < 32; ++j) {
					if (b.f[j] == INF && (b.f[j - 4] & 7) != 7) {
						Board created = new Board(buf[i & 1][next.size()], b, j);
						if (hashes.contains(created.h)) continue;
						if (created.h == finish) return i;
						hashes.add(created.h);
						next.add(created);
						created.setFix();
					}
				}
			}
			cur = next;
		}
		return -1;
	}

	static class Board {
		int[] f;
		long h;
		int fix = 1;

		Board(int[] buf) {
			f = buf;
			for (int i = 0; i < 4; ++i) {
				for (int j = 1; j <= 7; ++j) {
					String v = sc.next();
					int suit = v.charAt(0) - '1';
					int num = v.charAt(1) - '0';
					int card = suit * 8 + num;
					if (num == 1) {
						f[j * 4 + i] = INF;
						f[suit] = card;
					} else {
						f[j * 4 + i] = card;
						h ^= hash[j * 4 + i][card];
					}
				}
			}
		}

		Board(int[] buf, Board orig, int pos) {
			this.f = buf;
			this.fix = orig.fix;
			System.arraycopy(orig.f, 0, this.f, 0, 32);
			this.h = orig.h;
			final int target = orig.f[pos - 4] + 1;
			for (int i = fix * 4; i < 32; ++i) {
				if (orig.f[i] == target) {
					this.f[i] = INF;
					this.h ^= hash[i][target];
					break;
				}
			}
			this.f[pos] = target;
			this.h ^= hash[pos][target];
		}

		void setFix() {
			boolean ok = true;
			while (ok && this.fix < 6) {
				for (int i = 0; i < 4; ++i) {
					if ((f[this.fix * 4 + i] & 7) != this.fix + 1) {
						ok = false;
						break;
					}
				}
				if (ok) this.fix++;
			}
		}
	}
}

Measured memory_bytes: 68556
n = int(input())
s = []
for i in range(n):
  s.append(input())
s.sort()
k = 0
f = s
maxk = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    k = k+1
    if k == maxk :
      maxk = k
      f.append(s[i])
    elif k > maxk :
      maxk = k
      f = [s[i]]
  else:
    k = 0
for i in range(len(f)):
  print(f[i])

Measured memory_bytes: 18628
import fractions
def lcm(a, N):
  ans = a[0]
  for i in range(1, N):
      ans = ans * a[i] // fractions.gcd(ans, a[i])
  return ans
 
def main():
  N = int(input())
  A = list(map(int,input().split()))
  num = lcm(A, N) - 1
  answer = 0
  for i in A:
    answer += num % i
  print(answer)

if __name__=='__main__':
    main()

Measured memory_bytes: 10940
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
struct point
{
	long double x, y;
}pos[105];
int Quadrant(point a)//象限排序，注意包含四个坐标轴
{
    if(a.x>0&&a.y>=0)  return 1;
    if(a.x<=0&&a.y>0)  return 2;
    if(a.x<0&&a.y<=0)  return 3;
    if(a.x>=0&&a.y<0)  return 4;
}
long double cross(long double x1, long double y1, long double x2, long double y2)  //计算叉积
{
	return (x1 * y2 - x2 * y1);
}
long double compare(point a, point b, point c)//计算极角
{
	return cross((b.x - a.x), (b.y - a.y), (c.x - a.x), (c.y - a.y));
}
bool cmp1(point a, point b)
{
  	point c;//原点
	c.x = 0;
	c.y = 0;
	if (compare(c, a, b) == 0)//计算叉积，函数在上面有介绍，如果叉积相等，按照X从小到大排序
		return a.x < b.x;
	else return compare(c, a, b) > 0;
}
bool cmp(point a,point b)  //先按象限从小到大排序 再按极角从小到大排序
{
    if(Quadrant(a)==Quadrant(b))//返回值就是象限
        return cmp1(a,b);
    else return Quadrant(a)<Quadrant(b);
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> pos[i].x >> pos[i].y;
	sort(pos, pos + n, cmp);
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		long long x = 0, y = 0;
		for (int j = 0; j < n; j++)	//注意可能构成环的情况
		{
			x += pos[(i + j) % n].x, y += pos[(i + j) % n].y;
			ans = max(ans, x * x + y * y);
		}
	}
	cout << fixed << setprecision(30) << sqrt(ans) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
#define inf 0x3f3f3f3f


int main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
		ll a,b;
		scanf("%lld%lld",&a,&b);
		if(a>b)
		swap(a,b);
		ll x=sqrt(a*b)+1;
		while(x*x>=a*b)x--;
		ll ans=2*x;
		if(x>=a)ans--;
		if(x!=0&&x==(a*b-1)/x)
		ans--;
		cout<<ans<<endl;
	}
	
	
	return 0;
}

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

int main() {
	double D, N;
	cin >> D >> N;
	if (100.0 == N) {
		if (0.0 == D) cout << 101;
		else if (1.0 == D) cout << 10100;
		else cout << 1010000;
	}
	else printf("%.f", N * pow(100.0, D));
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int N = sc.nextInt();
		for (int i = 0; i < N; ++i) {
			String t = sc.next();
			HashSet<String> set = new HashSet<String>();
			set.add(t);
			for (int j = 1; j < t.length(); ++j) {
				String t1 = t.substring(0, j);
				String t2 = t.substring(j);
				set.add(t2 + t1);
				set.add(reverse(t1) + t2);
				set.add(reverse(t2) + t1);
				set.add(t1 + reverse(t2));
				set.add(t2 + reverse(t1));
				set.add(reverse(t1) + reverse(t2));
				set.add(reverse(t2) + reverse(t1));
			}
			System.out.println(set.size());
		}
	}

	static String reverse(String s) {
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); ++i) {
			c[s.length() - 1 - i] = s.charAt(i);
		}
		return String.valueOf(c);
	}

}

Measured memory_bytes: 52872
#include<iostream>
#include<vector>
#include<numeric>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n,m;
    float threshold=0;
    cin>>n>>m;
    vector<int> vote(n,0);
    rep(i,n) cin>>vote[i];
    threshold=accumulate(vote.begin(),vote.end(),0);
    threshold=threshold/(4*m);
    int count=0;
    rep(i,n) if(vote[i]>=threshold)count++;
    if(count>=m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int n;
  cin >> n;
  cout << (n <= 999?"ABC":"ABD")  << endl;
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  deque<int> d;
  rep(i,n) {
    int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (p == 0) {
      d.push_front(a[i]);
    } else {
      d[p-1] = a[i];
    }
  }
  int ans = d.size();
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, x=0, y=1;
  cin >> N;
  for(int i=0; i<8; i++){
    y *= 10;
    x = N % y / (y/10) + x;
  }
  if(N % x ==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const int INF = 1e9;
const int _N = 2e5;

int k;
string s;

template <typename T>
struct SegmentTree{
	T data[_N*4 + 1];
	T def;
	int m;
	void init(int n, T def){
		m = 1;
		this->def = def;
		while(m<n)m*=2;
		REP(i, m)data[i] = def;
	}
	void update(int i, T x){
		i += m - 1;
		data[i] = x;
		while(i >= 1){
			i = (i - 1)/2;
			data[i] = min(data[i*2 + 1], data[i*2 + 2]);
		}
	}
	T query(int a, int b){
		return _query(a, b, 0, 0, m);
	}
	T _query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return def;
		if(a <= l && r <= b) return data[k];
		T left = _query(a, b, k*2 + 1, l, (l + r) / 2);
		T right = _query(a, b, k*2 + 2, (l + r) / 2, r);
		return min(left, right);
	}
};

template <typename T>
struct BIT{
	int data[_N+1];
	int n;
	void init(int n, T def){
		this->n = n;
		REP(i, n+1)data[i] = def;
	}
	void add(int i, T x){
		i++;
		while(i <= n){
			data[i] += x;
			i += i&-i;
		}
	}
	T sum(int i){
		i++;
		int s = 0;
		while(i >= 1){
			s += data[i];
			i -= i&-i;
		}
		return s;
	}
	T get(int i){
		int s = sum(i);
		if(i>0) s -= sum(i-1);
		return s;
	}
};

SegmentTree<P> seg;
BIT<int> amount;
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> s >> k;
	int n = s.size();
	seg.init(n, {INF, INF});
	REP(i, n)seg.update(i, {s[i] - 'a', i});

	amount.init(n, 0);

	string ans;

	REP(i, n){
		if(k<1){
			REP(i, n)if(!amount.get(i))
				ans += s[i];
			break;
		}
		int target = min(k + 1, n - i);
		int end = 0;
		int low = 0, high = n - 1;
		// serch RANGE whose LENGTH is (target)
		// Binary Search
		while(low < high){
			int mid = (low + high + 1) / 2;
			if(mid + 1 - amount.sum(mid) <= target)
				low = mid;
			else
				high = mid - 1;
		}
		end = low;

		int t = seg.query(0, end + 1).second;
		ans += s[t];
		k -= t - amount.sum(t);
		assert(k>=0);
		seg.update(t, {INF, INF});
		amount.add(t, 1);
	}
	cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i=0;i<n;i++){
		cin >> vec.at(i);
	}
	int ans = vec.at(1)-vec.at(0);
	int min = vec.at(0);
	for (int i=1;i<n;i++){
		if (vec.at(i)-min>ans){
			ans = vec.at(i)-min;
		}
		if (vec.at(i)<min){
			min = vec.at(i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    const MOD: usize = 1_000_000_000 + 7;
    let N: usize = read();
    let mut primes = vec![];
    use std::collections::HashMap;
    let mut factors = HashMap::new();
    for i in 2..N + 1 {
        let mut is_composite = false;
        for p in &primes {
            if i % p == 0 {
                is_composite = true;
                let mut i = i;
                let mut add = 0;
                while i % p == 0 {
                    add += 1;
                    i /= *p;
                }
                let entry = factors.entry(p.clone()).or_insert(0);
                *entry += add;
            }
        }
        if is_composite {
            continue;
        }
        factors.entry(i).or_insert(1);
        primes.push(i);
    }

    let ans = factors
        .iter()
        .fold(1, |acc, (&_key, &value)| acc * (value + 1) % MOD);
    println!("{}", ans);
}


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

const int MAXN = 1e5+5;

int n, m;
vector<int> lan[MAXN];
vector<int> g[MAXN];
bool vis[MAXN];

int ct = 0;

void dfs(int v) {
	vis[v] = 1;
	ct++;

	for (int u : g[v])
		if (!vis[u])
			dfs(u);
}

int main() {
	cin >> n >> m;
	
	for (int i = 0; i < n; ++i) {
		int k; cin >> k;
		for (int j = 0; j < k; ++j) {
			int t; cin >> t;
			lan[t].push_back(i);
		}
	}

	for (int i = 0; i <= m; ++i) {
		for (int j = 0; j < (int)lan[i].size() - 1; ++j) {
			g[lan[i][j]].push_back(lan[i][j+1]);
			g[lan[i][j+1]].push_back(lan[i][j]);
		}
	}

	dfs(0);
	if (ct == n) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

Measured memory_bytes: 11640
#pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, MAXN); \
                 auto rnd = bind(__dis, __gen);

const int MAXN = 1E6;

int32_t main() {
    fastIO();
    
    int n, m, si, ci;
    cin >> n >> m;
    
    string ans(n, '*');
    
    while (m--) {
        cin >> si >> ci, --si;
        if (ans[si] == '*' or ans[si] == (ci + '0')) ans[si] = (ci + '0');
        else return cout << -1 << "\n", 0;
    }
    
    if (n > 1) ans[0] = (ans[0] == '*' ? '1' : ans[0]);
    for (auto &c : ans) c = (c == '*' ? '0' : c);
    return cout << (n > 1 and ans[0] == '0' ? "-1" : ans) << "\n", 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1<<20;
const int mod=1e9+7;
inline int Add(int x,int y)
{
    return (x+=y)>=mod?x-mod:x;
}
int n,a[max_n];
vector<int> v[max_n];
int cnt[max_n];
int dp[max_n][2];
int solve(int x)
{
    dp[0][0]=1;dp[0][1]=1;
    for(int i=1;i<v[x].size();i++)
    {
        int c=cnt[v[x][i]-1]-cnt[v[x][i-1]];
        dp[i][0]=Add(dp[i-1][0],1ll*c*dp[i-1][1]%mod);
        dp[i][1]=Add(dp[i-1][1],dp[i][0]);
    }
    return dp[v[x].size()-1][1];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)a[i]^=a[i-1];
    for(int i=1;i<=n;i++)v[a[i]].push_back(i);
    for(int i=1;i<=n;i++)cnt[i]=cnt[i-1]+(a[i]==0);
    if(a[n])
    {
        solve(a[n]);
        int ans=dp[v[a[n]].size()-1][1];
        if(v[a[n]].size()>1)ans=Add(ans,mod-dp[v[a[n]].size()-2][1]);
        printf("%d\n",ans);
    }
    else
    {
        int ans=1;
        for(int i=1;i<=cnt[n]-1;i++)ans=Add(ans,ans);
        for(int i=1;i<max_n;i++)
        {
            if(!v[i].empty())ans=Add(ans,solve(i));
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 38516
#include <iostream>
#include <cmath>

using namespace std;
int main (){
    int n,k;
    cin >> n >> k;
    int m=1;
    for (int i = 0; i < n; i++)
    {
        if(m>k) m+=k;
        else m+=m;
    }
    cout << m <<"\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if((100*a+10*b+c) % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, k; cin >> n >> k;
    map<int, int> m;
    for (int i=0; i<k; i++) {
        int d;
        cin >> d;
        m[d]++;
    }

    while(true) {
        int t=n;
        bool b=true;
        while(t>0) {
            if(m[t%10]>0) b=false;
            t /=10;
        }
        if (b)break;
        n++;
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
 
judgement = []
while True:
  try:
    judgement.append(input())
  except:
    break
 
counter = collections.Counter(judgement)
 
n_ac = counter.get('AC', 0)
n_wa = counter.get('WA', 0)
n_tle = counter.get('TLE', 0)
n_re = counter.get('RE', 0)
 
print('AC x {}'.format(n_ac))
print('WA x {}'.format(n_wa))
print('TLE x {}'.format(n_tle))
print('RE x {}'.format(n_re))

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int m = min(A, B), n = min(C, D);
	int x = m + n;
	cout << x << endl;
	return 0;
}

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

using namespace std;

const int maxn = 510;

int a[maxn][maxn],h,w,H,W;
long long total;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>H>>W>>h>>w;
    for (int i=1;i<=H;i++)
        for (int j=1;j<=W;j++)
            a[i][j]=3999;
    for (int i=h;i<=H;i+=h)
        for (int j=w;j<=W;j+=w)
            a[i][j]=-3999*(h*w-1)-1;
    for (int i=1;i<=H;i++)
        for (int j=1;j<=W;j++)
            total += a[i][j];
    if (total<0) cout<<"No"<<endl;
    else {
        cout<<"Yes"<<endl;
        for (int i=1;i<=H;i++) {
            for (int j=1;j<=W;j++) cout<<a[i][j]<<" ";
            cout<<endl;
        }
    }
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define int ll
int N,K,M;


int dp[2010][2010];
int memo[3001];
int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) power(int a,int b,int M){ //returns a^b % M, O(logb)
  	 if (b==0) return 1;
    
   	int half = b/2;
   	int halfval;
    
   	halfval = (power(a,half,M))%M;
   	if (b%2 == 0) return (halfval * halfval) % M;
   	else return (((halfval * halfval) % M) * (a % M)) % M;
}


int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) modinv(int A,int B,int M){
	A %= M;
	B = power(B,M-2,M);
	A *= B;
	A %= M;
	return A;
}


int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) nchoosek(int n,int k){
	
	bool pos = 0;
	if (n >= 0 && k >= 0) pos = 1;
	
	if (pos) if (dp[n][k] != -1) return dp[n][k];
	
	
	
	if (n == k || k == 0){
		if (pos) return dp[n][k] = 1;
		else return 1;
	}
	//if (k > n) return 0;
	//if (k == 0) return 1;
	
	ll ans = 1;
	
	if (memo[n] != -1) ans = memo[n];
	else{
		FOR(i,1,n){
			ans = (ans * i) % MOD;
		}
		memo[n] = ans;
	}
	
	
	
	int amt = 1;
	
	if (memo[k] != -1) amt = memo[k];
	else{
		FOR(i,1,k){
			amt = (amt * i) % MOD;
		}
		memo[k] = amt;
	}
	
	int amt2 = 1;
	
	if (memo[n - k] != -1) amt2 = memo[n-k];
	else{
		FOR(i,1,n-k){
			amt2 = (amt2 * i) % MOD;
		}
		memo[n-k] = amt2;
	}
	
	
	int legit_ans = modinv(ans,amt,MOD);
	legit_ans = modinv(legit_ans,amt2,MOD);
	if (pos) return dp[n][k] = legit_ans;
	else return legit_ans;
		

}

int32_t __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main(){
	fast;
	
	mem(dp,-1);
	memo[0] = memo[1] = 1;
	
	FOR(i,2,2000){
		memo[i] = (memo[i-1] * i) % MOD;
	}
	cin>>N>>K;
	FOR(I,1,K){
		
		
		M = N - K;
		
		
		if (I == 1){
			cout<<M+1<<'\n';
			continue;
		}
		
		int ans = 1;
		
		ans *= nchoosek(K-1,I-1);
		ans %= MOD;
		int num = 0;
		
		FOR(sm,0,M){
			if (M - sm < I-1) continue;
			num += (nchoosek(M - sm - 1,I-2) * ((sm+1)%MOD))%MOD;
			num %= MOD;
		}
			
		/*	
		FOR(i,0,M){
			FOR(j,0,M - i){
				if (I - 1 == 0 && M - i - j != 0) continue;
				
				if (M - i - j >= I-1){
					num += nchoosek(M - i - j - 1,I-2);
					num %= MOD;
				}
			}
		}
		*/
		
		
		//if (M % 2 == 0) num--;
		cout<<(ans*num) % MOD<<'\n';
	}
}



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

int main(int argc, const char * argv[]) {
    int k;
    int a[5] = {0};
    
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for (int i = 0; i < 5 - 1; i++) {
        for (int j = i + 1; j < 5; j++) {
            int sub = abs(a[i] - a[j]);
            if (sub > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	int x,n,y,i;
	do{ i =0;
		cin >>n >>x;
		if(n ==0 && x == 0) break;
	
		else{
		for(int a=1;a <n-1;a++){
			for(int b =a+1;b<n;b++){
				for(int c =b+1;c<n+1;c++){
					y =a + b + c;
					if(y == x){
						i++;
					}
				}
			}
		}
		cout <<i<<"\n";
		}}while(n !=0 || x !=0);

	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,p;
  cin >> n;
  vector <pair<int,int>> a(n);
  for(int i=0;i<n;i++){
    cin >> p ;
    a.at(i) = make_pair(p,i+1);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout << a.at(i).second << " ";
  }
  cout << endl;
}
  
  
  
  





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

int N;
const double EPS = 1e-10;

struct state{
  string name;
  double k;
  state(){}
  state(int P,int A,int B,int C,int D, int E,int F,int S,int M){
    int time = A + B + C + (D + E)*M;
    int num = M * F;
    int mon = num * S;
    int s = mon - P;
    k = (double)s/(double)time;
  }
  bool operator<(const state& st) const {
    return abs(k-st.k) < EPS ? name < st.name : k > st.k;
  }
};

state st[111];
int main(){
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      string L;int P,A,B,C,D,E,F,S,M;
      cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      st[i] = state(P,A,B,C,D,E,F,S,M);
      st[i].name = L;
   
    }
    sort(st,st+N);
    for(int i=0;i<N;i++)
      cout << st[i].name << endl;
    cout << "#" << endl;
  }
}

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

/*
 * G - LP
 */
public class Main
{
private Map< Integer, List< Integer >> m;
private Set< Integer > fromSet;
private Map< Integer, Integer > cache;

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

public void run() throws Exception
{
	final Scanner sc = new Scanner( getInputStream() );
	final int N = sc.nextInt();
	final int M = sc.nextInt();
	
	m = new HashMap<>(N*2);
	fromSet = new HashSet<>(N*2);
	cache = new HashMap<>(N*2);

	for( int i = 0; i < M; ++i )
	{
		int from = sc.nextInt();
		int to = sc.nextInt();

		List< Integer > list = m.get( to );
		if( list == null )
		{
			list = new ArrayList<>();
			m.put( to, list );
		}
		list.add( from );
		fromSet.add( from );
	}
	//p( fromSet );
	Set< Integer > toSet = new HashSet<>( m.keySet() );
	toSet.removeAll( fromSet );
	//p( toSet );
	//p( m );

	//全ての最終ノード候補についてループ
	int max = 0;
	for( final Integer lastNode : toSet )
	{
		int lp = getLP( lastNode );
		if( max < lp )
		{
			max = lp;
		}
	}
	p( max );
}

public int getLP( final int to )
{
	Integer cachedValue = cache.get( to );
	if( cachedValue != null )
	{
		return cachedValue.intValue();
	}
	else
	{
		int max = 0;
		final List< Integer > list = m.get( to );
		if( list != null )
		{
			for( Integer i : list )
			{
				int lp = getLP( i );
				if( max < lp )
				{
					max = lp;
				}
			}
			max += 1;
		}
		cache.put( to, max );
		return max;
	}
}

public static void p( Object o )
{
	System.out.println( o );
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

}


Measured memory_bytes: 127032
#include <iostream>
#include <unordered_map>
#include <algorithm>

#define ll long long

using namespace std;
int x, k, q, t, a, low, up, add, delta, now, ans, r[100007];
bool flag;

int cal(int tt, int lower = 0, int upper = x) {
    if (tt < lower) return lower;
    if (tt > upper) return upper;
    return tt;
}

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

    scanf("%d %d", &x, &k);
    for (int i = 1; i <= k; i++) scanf("%d", &r[i]);
    scanf("%d", &q);

    low = x, now = 1;
    while (q--) {
        scanf("%d %d", &t, &a);
        while (t >= r[now] && now <= k) {
            delta = (flag ? 1 : -1) * (r[now] - r[now - 1]), add += delta;
            up = cal(delta + up), low = cal(delta + low);
            flag = !flag, now++;
        }
        ans = cal((flag ? 1 : -1) * (t - r[now - 1]) + cal(a + add, up, low));
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)
#define num  1000000

using namespace std;




int main(void){

int innum,i;

char Find[num]; // 探索リスト
	for(int i = 2; i <= num; i++){
		Find[i] = '0';
		if(i%2==0) Find[i] = '1';
	}
	for(int i = 2; i*i < num; i++){
    	if(Find[i] > '0') continue; // すでに除いた数は飛ばす
    	for(int j = i * 2; j< num; j += i) {
        	if(Find[j]=='0') Find[j] = '1';
    	}
	}
	Find[2]='0';
	while(cin >> innum){
		int cnt=0;
		rep(i,innum+1) if(Find[i]=='0') { 
		//	cout << i << " ";
			cnt++;
		}

		cout << cnt <<endl;
	}
	return 0;
}

Measured memory_bytes: 2136