akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N; cin>>N;
    string s, t1, t2;
    cin>>s;
    if(N%2==1){
        cout << "No" << endl;
        return 0;
    }
    t1 = s.substr(0,N/2);
    t2 = s.substr(N/2);
    if(t1==t2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {

  int N;
  int count = 0;

  cin >> N;
  
  vector<int> H(N), Num(N-1);
  
  for (int i=0; i<N; i++) {
    cin >> H.at(i);
  }
  for (int j=0; j<N-1; j++) {
    Num.at(j) = H.at(j) - H.at(j+1);
  }

  int tmp = 0;
  for (int k=0; k<N-1; k++) {
    if (Num.at(k) >= 0) {
      tmp++;
    }
    else {
      tmp=0;
    }
    
    if (count < tmp) {
      count = tmp;
    }
  }

  // 結果の出力
  cout << count << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    for(ll i=0;i<n;i++)cin>>d[i];
      if(d[0]!=0)cout<<"0"<<endl;
  else{
    sort(d.begin(),d.end());
    ll ans=1,memo=1;
    vector<ll> m2(n-1,0);
	if(d[0]==0&&d[1]==0)cout<<"0"<<endl;
    else{
        for(ll i=1;i<n;i++){
            if(d[i]==memo)m2[memo-1]++;
            else{
                memo++;
              if(memo==d[i])m2[memo-1]++;
            }
        }
        bool m3=true;
        for(ll i=1;i<memo;i++){
			ll a=m2[i];
			while(a>0){
       			ans=(ans*m2[i-1])%998244353;
        		a--;
    		}
        }
        if(m3)cout<<ans<<endl;
    }
  }
}



Measured memory_bytes: 1792
N = int(input())
ABC = []
for i in range(N):
    ABC.append(list(map(int, input().split())))

dp = [[0]*3 for _ in range(N)]
dp[0] = ABC[0]
for i in range(N-1):
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + ABC[i+1][0]
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + ABC[i+1][1]
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + ABC[i+1][2]

print(max(dp[N-1]))

Measured memory_bytes: 74712
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  vector<int> A(s.size()),B(t.size());
  for(int i=0;i<s.size();i++){
    char x=s.at(i);
    A.at(i)=x;
  }
  for(int i=0;i<t.size();i++){
    char x=t.at(i);
    B.at(i)=x;
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  bool ans=true;
  if(A.size()<B.size()){
  for(int i=0;i<A.size();i++){
    if(A.at(i)<B.at(i)) break;
    if(A.at(i)>B.at(i)) ans=false;
  }
  }
  if(A.size()>=B.size()){
    for(int i=0;i<B.size();i++){
      if(A.at(i)<B.at(i)) break;
      if(A.at(i)>B.at(i)) ans=false;
      if(i==B.size()-1&&A.at(i)==B.at(i)) ans=false;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
def start():
    n, k = input().split()
    n = int(n)
    k = int(k)
    bs = [0 for i in range(n)]
    for j in range(k):
        di = input()
        ds = input().split()
        for d in ds:
            d = int(d)
            bs[d - 1] += 1
    n = bs.count(0)
    print(n)


if __name__ == '__main__':
    start()


Measured memory_bytes: 9188
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{	
		Scanner scan = new Scanner(System.in);
		String input;
		input = scan.next();
		int i , length = input.length();
		Map<Character , Integer> map = new HashMap<Character , Integer>();
		for (i = 0;i < length;i ++)
		{
			char ch = input.charAt(i);
			if (!map.containsKey(ch))
				map.put(ch , 1);
			else
				map.put(ch , map.get(ch) + 1);
		}
		boolean ok = true;
		for (Map.Entry<Character , Integer> entry : map.entrySet())
		{
			if (entry.getValue() % 2 == 1)
				ok = false;
		}
		
		if (ok)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> name(N);
    for(int i = 0; i < N; i++){
        cin >> name[i];
    }
    sort(name.begin(), name.end());
    int t = 1;
    int max = 0;;
    vector<int> count(N, 0);
    for(int i = 1; i < N; i++){
        if(name[i - 1] == name[i]) t++;
        else {
            count[i - 1] = t;
            if(max < t) max = t;
            t = 1;
        }
        if(max < t) max = t;
        count[N - 1] = t;
    }
    for(int i = 0; i < N; i++){
        if(count[i] == max) cout << name[i] << endl; 
    }
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k=2;
    cin>>n;
    int h[n];
    int dp[n];
    for (int i=0;i<n;++i)
    {
        cin>>h[i];
    }
    dp[0]=0;
    for (int i=1;i<n;++i)
    {
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for (int j=2;j<=k&&i-j>=0;++j)
        {
           dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]); 
        }
    }
    cout<<dp[n-1];
    return 0;
}

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

int min(int a, int b){
	return a < b ? a : b;
}

int main(void){
	int n, k, *h, *cost;
	scanf("%d %d", &n, &k);
	h = malloc(sizeof(int) * n);
	cost = malloc(sizeof(int) * n);
	for(int i = 0; i < n; i++)
		scanf("%d", h + i);
	cost[0] = 0;
	for(int i = 1; i < k; i++){
		cost[i] = abs(h[i] - h[0]);
		for(int j = 0; j < i; j++)
			cost[i] = min(cost[i], cost[j] + abs(h[j] - h[i]));
	}
	for(int i = k; i < n; i++){
		cost[i] = cost[i - k] + abs(h[i] - h[i - k]);
		for(int j = 1; j <= k; j++)
			cost[i] = min(cost[i], cost[i - j] + abs(h[i] - h[i - j]));
	}
	printf("%d\n", cost[n - 1]);
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005                                                                                //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair                                                     
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2!=0){
	cout<<"No";
	return 0;}
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n/2+i])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

const long long MOD = 998244353;
const int MAX = 300001;
long long fac[MAX], finv[MAX], inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod_comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    long long n, a, b, k;
    cin >> n >> a >> b >> k;
    comb_init();
    
    long long ans = 0;
    for (long long i = 0; i <= k / a; i++) {
        if ((k - a * i) % b == 0) {
            ans += mod_comb(n, i) * mod_comb(n, (k - a * i) / b) % MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  string s;
  cin>>s;
  string t=s;
  if(s[s.size()-1]!='s')
  	t+='s';
  if(s[s.size()-1]=='s')
    t+="es";
  cout<<t;
  return 0;   
}

Measured memory_bytes: 3624
#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: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int r;
    Scd(r);
    printf ("%d\n", r*r );

    return 0;
}





Measured memory_bytes: 256
# 参考：https://atcoder.jp/contests/abc060/submissions/3379570
# Nが高々100までなのでそれぞれ25個ずつある場合が一番場合の数が多いが25**4は10**5オーダーに収まるので問題ない

N, W = map(int, input().split())
# 物を格納
L = [list(map(int, input().split())) for _ in range(N)]

# 一つ目の物の重さが一番小さいので
w_min = L[0][0]

# 4種類の重さについて、価値を格納する
M = [[], [], [], []]
for w, v in L:
      M[w - w_min].append(v)

# それぞれについて価値の高い順に並べる
M0 = sorted(M[0], reverse=True)
M1 = sorted(M[1], reverse=True)
M2 = sorted(M[2], reverse=True)
M3 = sorted(M[3], reverse=True)

ans = 0
# それぞれをp,q,r,s個ずつ鞄に入れる時を考える
for p in range(len(M0)+1):
      for q in range(len(M1)+1):
            for r in range(len(M2)+1):
                  for s in range(len(M3)+1):
                        # 重さが制限を超えないならそれまでの最大価値と比較
                        w = p*(w_min) + q*(w_min+1) + r*(w_min+2) + s*(w_min+3)
                        if w <= W:
                              ans = max(ans, sum(M0[:p])+sum(M1[:q])+sum(M2[:r])+sum(M3[:s]))

print(ans)

Measured memory_bytes: 3064
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<double> vd;
typedef std::vector<std::string> vs;
typedef std::vector<pii> vpii;
typedef std::vector<vi> vvi;
typedef std::vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { rep(i,v.size()) is >> v[i]; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

class UFTree {
  std::vector<int> data, rank, _size;

public:
  UFTree(const int &n) : data(n), rank(n), _size(n, 1) { iota(all(data), 0); }

  int root(const int &x) { return data[x] == x ? x : data[x] = root(data[x]); }

  bool same(const int &a, const int &b) { return root(a) == root(b); }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rank[a] < rank[b]) std::swap(a, b);
    data[b] = a;
    _size[a] += _size[b];
    if (rank[a] == rank[b]) rank[a]++;
  }

  int sizeOf(int x) { return _size[root(x)]; }

  int size() { return data.size(); }
};

main {
  int n;
  while (cin >> n, n) {
    UFTree uf(n * n);
    vvpii v(n, vpii(n));
    cin >> v;
    rep(i, n) rep(j, n) uf.unite(i * n + j, v[i][j].second * n + v[i][j].first);
    int c = 0;
    rep(i, uf.size()) c += i == uf.root(i);
    cout << c << endl;
  }
}

Measured memory_bytes: 3372
import java.util.*;

public class Main {

	public static long total(int n) {
		return (long)n * (long)(n + 1) / 2;
	}
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		long ans = 0;
		ans = total(n);
		long rest = 3 * total(n / 3);
		ans -= rest;
		rest = 5 * total(n / 5);
		ans -= rest;
		rest = 15 * total(n / 15);
		ans += rest;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35636
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	char x, y;
	cin >> x >> y;
	if (x < y) {
		cout << "<" << endl;
	} else if (x > y) {
		cout << ">" << endl;
	} else {
		cout << "=" << endl;
	}
	return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>

using namespace std;

int main(void) {
    int n, m;
    cin >> n; // コマの数
    cin >> m; // 目標地点の数

    // 置くだけで終わるなら終わり
    if(n >= m) {
        cout << "0" << endl;
        return 0;
    }
    vector<int> x(m);
    for(int i = 0 ; i < m ; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    // 各区間の移動回数を求める
    vector<int> l(m-1);
    for(int i = 0 ; i < l.size() ; ++i) {
        l[i] = x[i + 1] - x[i];
    }
    sort(l.begin(), l.end(), greater<int>());
    // n=1だったときの最悪移動回数
    int max = x[x.size() - 1] - x[0];
    int diff = 0;
    for(int i = 0 ; i < n - 1 ; ++i) {
        diff += l[i];
    }
    int result = max - diff;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys

M = int(1e9 + 7)
n, k = map(int, sys.stdin.readline().strip().split())
xs = list(map(int, sys.stdin.readline().strip().split()))
x = 0
y = 0
for i in range(n):
    for j in range(n):
        if i < j and xs[i] > xs[j]:
            x += 1
        if i < j and xs[i] < xs[j]:
            y += 1

ans = ((x * k * (k + 1) // 2) % M) + ((y * k * (k - 1) // 2) % M)
print(ans % M)


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

int main() {
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
    int l,r,d,ans=0;
    scanf("%d%d%d",&l,&r,&d);
    int temp=d;
    while(temp<=r) {
        if(temp>=l) ans++;
        temp+=d;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int r=0, b=0;
    for(int i=0; i<n; i++){
        char tmp;
        cin >> tmp;
        if(tmp=='R'){
            r++;
        }else{
            b++;
        }
    }
    if(r>b){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}

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


int n, k;
string S;
int main() {
    cin >> n >> k;
    cin >> S;
    int l = 0, ans=0;
    rep(i, n) {
        if(S[i] == '0') {
            if(k<=0) {
                while(l<i && S[l]=='1') l++;
                k++;
                while(l<i && S[l]=='0') l++;
            }
            while(i+1<n && S[i+1]=='0') {
                i++;
            }
            k--;
        }
        ans = max(ans, i-l+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(c=1; c<=3; c++){
		if((a*b*c)%2==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
"""
"""

if __name__ == '__main__':
    N = int(input())
    S = input()

    wn = [0]
    en = [0]

    for i in range(N):
        if S[i] == "W":
            wn.append(wn[-1]+1)
            en.append(en[-1])
        if S[i] == "E":
            wn.append(wn[-1])
            en.append(en[-1]+1)

    m = N
    for i in range(len(S)):
        t = (wn[i] - wn[0]) + (en[N] - en[i+1])
        m = min(m, t)

    print(m)

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

using namespace std;

int main() {
  string S;
  cin >> S;
  set<char> C(S.begin(), S.end());
  if (C.count('7')) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
h, w = map(int, input().split())
s = ['?'*(w+2)]+['?'+input()+'?' for _ in range(h)]+['?'*(w+2)]

ans = [[[] for _ in range(w)] for _ in range(h)]

for i in range(1, h+1):
    for j in range(1, w+1):
        cnt = 0
        if s[i][j] == '.':
            if s[i-1][j-1] == '#':
                cnt += 1
            if s[i-1][j] == '#':
                cnt += 1
            if s[i-1][j+1] == '#':
                cnt += 1
            if s[i][j-1] == '#':
                cnt += 1
            if s[i][j+1] == '#':
                cnt += 1
            if s[i+1][j-1] == '#':
                cnt += 1
            if s[i+1][j] == '#':
                cnt += 1
            if s[i+1][j+1] == '#':
                cnt += 1

            ans[i-1][j-1] = cnt
        else:
            ans[i-1][j-1] = '#'

for x in ans:
    print(*x, sep='')


Measured memory_bytes: 44016
N = int(input())
a = [int(input())-1 for i in range(N)]

hist = set()
next_i = 0
ans = 0
for i in range(N):
    ans += 1
    hist.add(next_i)
    next_i = a[next_i]
    if next_i == 1:
        break
    elif next_i in hist:
        ans = -1
        break

print(ans)

Measured memory_bytes: 55896
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
t = rl()
sum_ = sum(t)
m = ri()
for _ in range(m):
    p, x = rm()
    p -= 1
    print(sum_ - t[p] + x)













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

int main() {
	char S[4];
	string T;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c;
	if (a < b) {
		n = a;
		a = b;
		b = n;
	}
	if (a < c) {
		n = a;
		a = c;
		c = n;
	}
	if (a == (b + c)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define hatena -1
using namespace std;

int qu(int n){
	if(1<=n && n<=6)return n+1;
	else return n-5;
}

int main(){
	char s;
	int data[12];
	for(int i=11;i>=0;i--){
		cin>>s;
		if(s=='?')data[i]=hatena;
		else data[i]=(int)(s-'0');
	}
	int tail=0,ans,check=0;
	if(data[0]==hatena){
		for(int i=1;i<12;i++){
			tail+=data[i]*qu(i);
		}
		if(tail%11<=1)ans=0;
		else ans=11-tail%11;
	}else{
		rep(i,10){
			tail=0;
			for(int j=11;j>=1;j--){
				if(data[j]==hatena)tail+=i*qu(j);
				else tail+=data[j]*qu(j);
			}
			if(tail%11<=1 && data[0]==0){
				ans=i;
				check++;
			}
			else if(11-tail%11==data[0]){
				check++;
				ans=i;
			}
		}
	}
	if(check>1)cout<<"MULTIPLE"<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1140
#include<stdio.h>

int main(){
   int a, b, c;
   scanf("%d %d %d", &a, &b, &c);
   if (a > b){
       int tmp = b;
       b = a;
       a = tmp;
   }
   if (b > c){
       int tmp = b;
       b = c;
       c = tmp;
   }
   if (a > b){
       int tmp = b;
       b = a;
       a = tmp;
   } 
   
   printf("%d %d %d\n", a, b, c);
    return 0;
    
    
    
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, sum = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }
    cout << sum << '\n';
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cout << setprecision(8) << setiosflags(ios::fixed); // printf("%.4f", x);

    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
    vector<vector<ll>> num(n + 1, vector<ll>(n + 1, 0));
    num[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (dp[i + 1][j] == dp[i][j])
                num[i + 1][j] += num[i][j];
            else if (dp[i + 1][j] < dp[i][j]) {
                dp[i + 1][j] = dp[i][j];
                num[i + 1][j] = num[i][j];
            }

            if (dp[i + 1][j + 1] == dp[i][j] + v[i])
                num[i + 1][j + 1] += num[i][j];
            else if (dp[i + 1][j + 1] < dp[i][j] + v[i]) {
                dp[i + 1][j + 1] = dp[i][j] + v[i];
                num[i + 1][j + 1] = num[i][j];
            }
        }
    }

    ll idx = -1, sum = 0;
    for (ll j = a; j <= b; ++j) {
        if (idx == -1 || j * dp[n][idx] < idx * dp[n][j]) {
            idx = j;
            sum = num[n][idx];
        }
        else if (j * dp[n][idx] == idx * dp[n][j]) {
            sum += num[n][j];
        }
    }

    cout << (double)dp[n][idx] / idx << endl;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
 
using namespace std;
     
    int main(){
      int H, W, N;
      cin >> H >> W >> N;
      int X = max(H, W);
      int b = 0, t = 0;
      while(b<N){
        b += X;
        t++;
      }
      cout << t << endl;
    }

Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long n,m,res;
  cin >> n >> m;
  if(n==1&&m==1)
    res=1;
  else if(n==1||m==1)
    res=max(n,m)-2;
  else
    res=(n-2)*(m-2);
  cout << res << endl;
  return 0;
}

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

int main(void){
    // Your code here!
    int n;
    cin>>n;
    vector<int>x(n);
    vector<int>y(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    for(int p=1;p<=3;p++){
        double z=0.00000000;
        for(int i=0;i<n;i++){
            z+=pow(fabs(x[i]-y[i]),p);
        }
        z=pow(z,1.0/p);
        cout<<fixed << setprecision(8)<<z<<endl;
    }
    double z=0.00000000;
    for(int i=0;i<n;i++){
        z=max(z,fabs(x[i]-y[i]));
    }
        cout<<fixed << setprecision(8)<<z<<endl;
}



Measured memory_bytes: 3476
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



struct Corr
{
	int to;
	double len;
	Corr(int to, double len)
		: to(to), len(len) { }
};
bool operator<(const Corr& a, const Corr& b)
{
	return a.len > b.len;
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		double x[128], y[128], z[128], r[128];
		for (int i = 0; i < n; ++i)
			cin >> x[i] >> y[i] >> z[i] >> r[i];

#define SQ(d, a, b) ((d[a] - d[b])*(d[a] - d[b]))
#define LEN(a, b) (max(0.0, sqrt(SQ(x, a, b) + SQ(y, a, b) + SQ(z, a, b)) - (r[a] + r[b])))
		vector<Corr> cor[128];
		for (int i = 0; i < n; ++i)
			for (int j = i + 1; j < n; ++j)
				cor[i].push_back(Corr(j, LEN(i, j))), cor[j].push_back(Corr(i, LEN(i, j)));

		bool used[128];
		clear(used, 0);
		priority_queue<Corr> q;
		used[0] = true;
		foreach (it, cor[0])
			q.push(*it);
		double res = 0;
		while (!q.empty())
		{
			Corr c = q.top(); q.pop();
			if (used[c.to])
				continue;

			res += c.len;
			used[c.to] = true;
			foreach (it, cor[c.to])
				q.push(*it);
		}
		printf("%.3f\n", res);
	}
}

Measured memory_bytes: 0
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

all_list = [A, B, C, D, E]
amari = [A%10, B%10, C%10, D%10, E%10]
amari = [ 10 if i == 0 else i for i in amari]
min_index = amari.index(min(amari))
amari = [ 0 if i == 10 else i for i in amari]
goukei = 0
for i, one in enumerate(all_list):
    if i != min_index:
        if one%10 > 0:
            goukei += one + (10-one%10)
        else:
            goukei += one
goukei += all_list[min_index]
print(goukei)

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

using namespace std;

int main()
{
  	int x, a, b;
  	cin >> x >> a >> b;
  	if(abs(x - a) > abs(x - b)){
      	cout << "B";
    }else{
      	cout << "A";
    }
  	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
  Scanner sc = new Scanner(System.in);	
 
  public void run(){
    int n = sc.nextInt();
    
    long MAX = 1234567891L;
    long posMax = -MAX;
    long posMin = MAX;
    long negMax = -MAX;
    long negMin = MAX;
    
    for(int i = 0 ;i < n ; i++){
      long x = sc.nextInt();
      long y = sc.nextInt();
      
      long pos = x+y;
      long neg = x-y;
      posMax = Math.max(posMax, pos);
      posMin = Math.min(posMin, pos);
      negMax = Math.max(negMax, neg);
      negMin = Math.min(negMin, neg);
    }
    
    System.out.println(Math.max(posMax-posMin, negMax-negMin));
  }
  public static void main(String[] args){
    Main m = new Main();
    m.run();
  }
}


Measured memory_bytes: 59908
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b;cin>>a>>b;
    ll cnt=1;ll sum=0;
    while(cnt<b){
        cnt+=(a-1);
        sum++;
    }
    cout<<sum<<"\n";
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())


int main(){
	int n;
	cin>>n;
	if(n==100000){
		cout<<90909<<endl;
	}
	else if (n>=10000){
		cout<<(n-10000+1)+909<<endl;
	}
	else if(n>999){
		cout<<909<<endl;
	}
	else if(n>=100){
		cout<<(n-100+1)+9<<endl;
	}
	else if(n>9){
		cout<<9<<endl;
	}
	else{
		cout<<n<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
bool b[1000001] = { false };
int main() {
	vector<int> prime;
	FOR(i, 2, 1000001){
		if (!b[i]){
			for (int j = i + i; j < 1001; j += i){
				b[j]=true;
			}
			prime.push_back(i);
		}
	}
	int n,m;
	while (cin >> n >> m, n){
		int count=0;
		vector<int> np;
		while (n!=1){
			if (n%prime[count] == 0){
				if (np.size() == 0||prime[count] != np[np.size() - 1]  )np.push_back(prime[count]);
				n /= prime[count];
			}
			else{
				count++;
			}
			
		}
		vector<int> mp;
		count=0;
		while (m != 1){
			if (m%prime[count] == 0){
				if (mp.size() == 0||prime[count] != mp[mp.size() - 1])mp.push_back(prime[count]);
				m /= prime[count];
			}
			else{
				count++;
			}	
		}
		int ansn = np[np.size()-1];
		int ansm = mp[mp.size() - 1];
		REP(i, np.size() - 1){
			ansn -= np[i];
		}
		REP(i, mp.size() - 1){
			ansm -= mp[i];
		}
		string anss = (ansn>ansm) ? "a" : "b";
		cout<< anss<<endl;
	}
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    size_t n;
    cin >> n;
    unordered_map<int, int> mp(n);
    for (size_t i = 0; i < n; ++i) {
        int a;
        cin >> a;
        mp[a] += 1;
    }
    int total = 0;
    for_each(mp.cbegin(), mp.cend(), [&total](auto p)
    {
        if (p.first < p.second) {
            total += p.second - p.first;
        } else if (p.first > p.second) {
            total += p.second;
        }
    }
             );
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 4096
(* O(n) *)
let kMax = 100000
let n = Scanf.scanf " %d" @@ (+) 0
let ns = Array.make (kMax + 10) 0
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    let a = Scanf.scanf " %d" @@ (+) 0 in
    ns.(a) <- ns.(a) + 1
  done;
  for i = 0 to kMax - 1 do
    ans := max !ans @@ ns.(i) + ns.(i + 1) + ns.(i + 2)
  done;
  Printf.printf "%d\n" !ans

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

int main() {

int N;
cin >> N;
string s;
int p;
vector<tuple<string,int,int>> vec;
for(int i=0;i<N;i++){
  cin >> s >> p;
  vec.push_back(make_tuple(s,100-p,i+1));
}
sort(vec.begin(),vec.end());
for(int i=0;i<N;i++){
  int rank;
  cout << get<2>(vec.at(i)) << endl;
}

  

}


Measured memory_bytes: 256
use num_bigint::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    if a.iter().any(|&ai| ai == 0) {
        println!("0");
        return;
    }
    let a = a
        .into_iter()
        .map(|ai| ai.to_bigint().unwrap())
        .collect::<Vec<_>>();
    let mut result = 1.to_bigint().unwrap();
    let limit = 10usize.pow(18).to_bigint().unwrap();
    for i in 0..n {
        result *= a[i].clone();
        if result > limit {
            println!("-1");
            return;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 11224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n, m; cin >> n >> m;
  vector<int> pref(n + 1);
  vector<pair<int, int>> data(m);
  map<int, int> cnt;
  rep (i, m) {
    int p, y; cin >> p >> y;
    data[i] = make_pair(p, y);
    cnt[y] = p;
  }
  for (auto v : cnt) {
    ++pref[v.second];
    ++cnt[v.first] = pref[v.second];
  }

  for (auto v : data) {
    printf("%06d%06d\n", v, cnt[v.second]);
  }
  return 0;
}


Measured memory_bytes: 9076
n=int(input())
F=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    F.append(sub_list)
P=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    P.append(sub_list)
Ans=-10**10
for i in range(1,1024):
    i_list=[]
    for j in range(10):
        i_list.append((i>>j)&1)
    ans=0
    for j in range(n):
        count=0
        for k in range(10):
            count+=F[j][k]*i_list[k]
        ans+=P[j][count]
    Ans=max(Ans,ans)
print(Ans)
        

    
    


Measured memory_bytes: 43372
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dic={}
for i in range(n):
    dic[a[i]]=i+1

# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

bi=BIT(n)
ans=0
# print(dic)
for i in range(n):
    lsum=bi.sum(dic[i+1])
    l,r=-1,dic[i+1]
    while r-l>1:
        half=(r+l)//2
        if bi.sum(half)>=lsum:
            r=half
        else:
            l=half
    ll=r
    rsum=bi.get(dic[i+1],n)
    l,r=dic[i+1],n+1
    while r-l>1:
        half=(r+l)//2
        if bi.get(half,n)>=rsum:
            l=half
        else:
            r=half
    rr=l
    ans+=(i+1)*(dic[i+1]-ll)*(rr-dic[i+1]+1)
    # print(ll,dic[i+1],rr)
    bi.add(dic[i+1],i+1)
    # print(ans)
    # print(bi.el)
print(ans)

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

int main(){
  char a,b,ans;
  cin >> a >> b;
  if(a=='H' && b=='H'){
    ans ='H';
  }
  else if(a=='H' && b=='D'){
    ans = 'D';
  }
  else if(a=='D' && b=='H'){
    ans = 'D';
  }
  else {
    ans='H';
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N, Y = [int(x) for x in input().strip().split()]
    
    for ni in range(N+1)[::-1]:
        sum = ni * 10000
        if sum > Y:
            continue

        M = N - ni

        for mi in range(M+1)[::-1]:
            sum = (ni*10000) + (mi*5000) + ((N-ni-mi) * 1000)
            if sum == Y:
                return "{} {} {}".format(ni, mi, N-ni-mi)
    return "-1 -1 -1"
    
if __name__ == '__main__':
    print(main())

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    std::cout<<std::fixed<<std::setprecision(10);

    int N;
    cin >> N;
    vi V(N);
    REP(i,N) cin >> V[i];

    sort(V.begin(),V.end());
    double prev = V[0];
    for(int i=1;i<N;i++){
        prev = (prev+V[i])/2;
    }

    cout << prev << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int);
void pop(void);
int k=0,q[100];
int main(){
  int x,i=0,a=0,flag1=0,flag2=0,flag3=0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      q[k-2]=q[k-1]+q[k-2];
    pop();
    } else if ( s[0] == '-' ){
     q[k-2]=q[k-2]-q[k-1];
     pop();
    } else if ( s[0] == '*' ){
     q[k-2]=q[k-1]*q[k-2];
     pop();
    }else if(s[0]==' ');
    else {
      x = atoi(s);
      push(x);
    }


 
  
  }
     printf("%d\n",q[0]);
  return 0;
}
  
void push(int x){
  q[k]=x;
  k++;
}
void pop(void){
  q[k-1]=0;
  k--;
}

Measured memory_bytes: 548
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
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 Per(i,sta,n) for(int i=n-1;i>=sta;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++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string n;
int k;
ll dp[110][4][2];

void solve(){
  cin >> n;
  cin >> k;
  int m=n.length();
  dp[0][0][0]=1;
  rep(i,m){
    ll s=n[i]-'0';
    //cout << s << endl;
    rep(l,k){
      dp[i+1][l+1][1]+=max((ll)0,(s-(ll)1))*dp[i][l][0];
      dp[i+1][l+1][1]+=(ll)9*dp[i][l][1];
      if(s!=0) dp[i+1][l+1][0]+=(ll)dp[i][l][0];
    }
    rep(l,k+1){
      if(s==0) {
        dp[i+1][l][0]+=dp[i][l][0];
        dp[i+1][l][1]+=dp[i][l][1];
      }
      else{
        //cout << i << " " << k << " " << endl;
        dp[i+1][l][1]+=dp[i][l][0]+dp[i][l][1];
        //cout << dp[i+1][l][1] << endl;
      }
    }
  }
  rep(i,m+1){
    rep(l,k+1){
      rep(flag,2){
        //cout << i << " " << l << " " << flag << " " << dp[i][l][flag] << endl;
      }
    }
  }
  cout << dp[m][k][0]+dp[m][k][1] << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

char a[10005], b[10005];
int main()
{
	int lena, lenb, flag = 1;
	scanf("%s",a);
	getchar();
	scanf("%s",b);
	lena = strlen(a);
	lenb = strlen(b);
	if(lena == lenb)
	{
		for(int i = 0; i != max(lena, lenb); i++)
		{
			if(a[i] > b[i])
			{
				printf("GREATER\n");
				break;
			}
			else if(a[i] < b[i])
			{
				printf("LESS\n");
				break;
			}
			else
			{
				flag = 0;
				continue;
			}
		}
		if(flag == 0)
		{
			printf("EQUAL\n");
		}
	}
	if(lena > lenb)
	{
		printf("GREATER\n");
	}
	if(lena < lenb)
	{
		printf("LESS\n");
	}
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    let m = v.iter().cloned().sum::<i64>() / n as i64;
    let a1 = v.iter().fold(0, |ac, x| ac + (x - m) * (x - m));
    let a2 = v.iter().fold(0, |ac, x| ac + (x - m - 1) * (x - m - 1));
    println!("{}", min(a1, a2));
}


Measured memory_bytes: 4352
a, b, k = list(map(int, input().split()))
# 公約数を入れておくリスト
common_divisor = []

# 1もカウントするので、少ない方の数まで1から数え上げる
# 数え上げて、いずれもその数であまりが0であれば公約数である
for i in range(1,min(a,b)+1):
    if a % i == 0 and b % i == 0:
        common_divisor.append(i)

# 公約数のうち、指定された番号の数を出力する。indexは0スタートなので-1してあわせる
copy_common_divisor = list(reversed(common_divisor))
print(copy_common_divisor[k - 1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, W;
    cin >> H >> W;
    string s[H+2];
    s[0] = "";
    rep(i, W+2) s[0] += "#";
    s[H+1] = s[0];
    rep2(i, 1, H){
        cin >> s[i];
        s[i] = "#"+s[i]+"#";
    }
    int ans = 0;
    rep2(i, 1, H) rep2(j, 1, W){
        if(s[i][j] == '#') continue;
        int d[H+2][W+2];
        rep(k, H+2) rep(l, W+2) d[k][l] = 100000;
        queue<P> que;
        que.push(P(i, j));
        d[i][j] = 0;
        while(!que.empty()){
            P p = que.front();
            que.pop();
            int a = p.first, b = p.second;
            if(a == 0 || a == H+1 || b == 0 || b == W+1) continue;
            if(s[a+1][b] == '.' && d[a+1][b] > d[a][b]+1){
                d[a+1][b] = d[a][b]+1;
                que.push(P(a+1, b));
            }
            if(s[a][b-1] == '.' && d[a][b-1] > d[a][b]+1){
                d[a][b-1] = d[a][b]+1;
                que.push(P(a, b-1));
            }
            if(s[a][b+1] == '.' && d[a][b+1] > d[a][b]+1){
                d[a][b+1] = d[a][b]+1;
                que.push(P(a, b+1));
            }
            if(s[a-1][b] == '.' && d[a-1][b] > d[a][b]+1){
                d[a-1][b] = d[a][b]+1;
                que.push(P(a-1, b));
            }
            rep2(i, 1, H) rep2(j, 1, W){
                if(d[i][j] == 100000) continue;
                else ans = max(ans, d[i][j]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256