akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

template<class T> inline bool chmax(T &a, T b) {
	if (a < b) { a = b; return true; }
	return false;
}

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) { a = b; return true; }
	return false;
}

const int INF = 1e8;

int main() {
	vector<int> v;
	for (int i = 1; ; i++) {
		int t = (i * (i + 1) * (i + 2)) / 6;
		if (t >= 1e6) break;
		v.push_back(t);
	}
	vector<int> dp1(1000005, INF);
	vector<int> dp2(1000005, INF);
	dp1[0] = 0;
	dp2[0] = 0;
	rep(i, 1000005) {
		rep(j, (int)v.size()) {
			if (i < v[j]) continue;
			chmin(dp1[i], dp1[i - v[j]] + 1);
			if (v[j] % 2 == 1) chmin(dp2[i], dp2[i - v[j]] + 1); 
		}
	}
	int n;
	while (cin >> n) {
		if (n == 0) break;
		cout << dp1[n] << " " << dp2[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 10468
import java.util.*;
 
public class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] weight = new int[n];
        int[] value = new int[n];
        int val_sum = 0;
        for(int i = 0; i < n; i++) {weight[i] = sc.nextInt(); value[i] = sc.nextInt(); val_sum += value[i];}
        long[][] dp = new long[n + 1][val_sum + 1];
        for(int i = 1; i <= val_sum; i++) dp[0][i] = 1000000000001L;

        for(int i = 1; i <= n; i++){
            int cweight = weight[i - 1];
            int cvalue = value[i - 1];
            for(int j = 1; j <= val_sum; j++){
                if(j < cvalue){
                    dp[i][j] = dp[i - 1][j];
                }else{
                    dp[i][j] = Math.min(dp[i - 1][j], dp[i - 1][j - cvalue] + cweight);
                }
            }
        }
        for(int i = val_sum; i >= 0; i--){
            if(dp[n][i] <= w){
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 125904
Day = list(map(int,input().split()))

work = list(map(int,input().split()))

for i in range(Day[1]):
  Day[0] = Day[0] - work[i]
  
if(Day[0] >= 0):
  print(Day[0])
elif(Day[0] < 0):
  print("-1")
  

Measured memory_bytes: 9788
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

char f(char c) {
	char res = c + ('A' - 'a');
	return res;
}

signed main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << f(s1[0]) << f(s2[0]) << f(s3[0]) << endl;
}

Measured memory_bytes: 256
n = int(input())

max_count = 0
ans = 1

for i in range(1,n+1):
    count = 0
    tmp = i
    for j in range(1,i+1):
        if tmp % 2 == 0:
            tmp /= 2
            count += 1
        else:
            if count > max_count:
                ans = i
                max_count = count
            break
print(ans)


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

#define MAX 10000

int top,S[MAX];

void push(int);
int pop();

int main(){
  int a,b;
  int top=0;
  char s[100];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]=='-'){
      //順序注意!
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else push(atoi(s));

  }
  printf("%d\n",pop());

  return 0;
}

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2104
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
	int A,B,C,X,Y;
	cin>>A>>B>>C>>X>>Y;
	int res=0;
	if(A+B>2*C){
		if(X>Y){
			res+=Y*2*C;
			if(A>2*C){
				res+=(X-Y)*2*C;
			}else{
				res+=(X-Y)*A;
			}
		}else{
			res+=X*2*C;
			if(B>2*C){
				res+=(Y-X)*2*C;
			}else{
				res+=(Y-X)*B;
			}
		}
	}else{
		res+=A*X+B*Y;
	}
	cout<<res;
	return 0;
} 

Measured memory_bytes: 256
import numpy as np
from itertools import product
import sys
read = sys.stdin.buffer.read


C = np.array(read().split(), np.int32).reshape(3, 3)

a, b, c = np.max(C + 1, axis=1)
N = []
for i, j in product(range(a), range(b)):
    x = C[0, :] - i
    y = C[1, :] - j

    if np.all(x == y):
        N.append(x)

flag = 0
z = C[2, :]
for n in N:
    for k in range(c):
        if np.all(z - k == n):
            flag = 1
            break
    
    if flag:
        break

print(['No', 'Yes'][flag])

Measured memory_bytes: 21388
local s = io.read()
local n = #s
local ret = true
for i = 1, n do
  if i % 2 == 0 then
    if s:sub(i, i) == "R" then
      ret = false
      break
    end
  else
    if s:sub(i, i) == "L" then
      ret = false
      break
    end
  end
end
print(ret and "Yes" or "No")


Measured memory_bytes: 760
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// 基本テンプレート
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// Effective std
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }


// グラフテンプレート
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
  int N, K;
  cin >> N >> K;
  vi v;
  rep(i, K) {
    int d;
    cin >> d;
    v.push_back(d);
  }

  int ans = N;
  int b;
  while(true) {
    string s = to_string(ans);
    b = 0;
    rep(i, K) {
      std::string::size_type index = s.find(to_string(v[i]));
      if(index!=std::string::npos) {
        b++;
      }
    }
    if(b==0) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}



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

typedef long long ll;

char str[300010];
ll mod1[300010], mod2[300010];//c+1, c-1

ll popcount(ll num){
    ll ret=0;
    while(num){
        ret += num&1;
        num>>=1;
    }
    return ret;
}

int main()
{
    int n, c=0;
    scanf("%d", &n);
    scanf("%s", str);
    for(int i=0; i<n; ++i) c += str[i]-'0';
    if(c==0){
        for(int i=0; i<n; ++i) printf("1\n");
        return 0;
    }
    for(ll i=0,x=1,y=1; i<n; ++i){
        mod1[i] = x;
        mod2[i] = y;
        x*=2; y*=2;
        x%=c+1;
        if(c<=1) y=0;
        else y%=c-1;
    }
    ll A1=0, A2=0;
    for(int i=0; i<n; ++i){
        A1 += mod1[i]*(str[n-i-1]-'0');
        A1 %= c+1;
        A2 += mod2[i]*(str[n-i-1]-'0');
        if(c<=1) A2 = 0;
        else A2 %= c-1;
    }
    for(int i=0; i<n; ++i){
        int ans = 0;
        if(c==1 && str[i]=='1'){
            printf("0\n");
            continue;
        }
        ll mod = 0;
        if(str[i]=='0'){
            //A1
            mod = A1;
            mod += mod1[n-i-1];
            mod %= c+1;
            ans ++;
            while(mod){
                ll pc = popcount(mod);
                mod %= pc;
                ++ans;
            }
        }
        else{
            //A2
            mod = A2;
            mod -= mod2[n-i-1];
            mod %= c-1;
            mod = (mod+c-1)%(c-1);
            ans ++;
            while(mod){
                ll pc = popcount(mod);
                mod %= pc;
                ++ans;
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 7140
#include <stdio.h>

int main(){

  int x,y,i,d;

  while(1){
    scanf("%d %d", &x,&y);
    if(x>=1 && y<=1000000000)break;
    }

  if(x>y){
    d=x%y;
    for(i=d ; i>0 ; i--){
      if(y%i==0 && d%i==0)break;
    }
  }
  else if(x<y){
    d=y%x;
    for(i=d ; i>0 ; i--){
      if(x%i==0 && d%i==0) break;
    }
  }
  else i=x;

  printf("%d\n", i);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define UNIQUE(X) X.erase( unique( X.begin(), X.end() ), X.end() )


typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef vector<int> VI;
typedef vector<LL> VL;


// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
PII,
null_type,
less<PII>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

/*end of header*/

string s1,s2;

struct data
{
    int cnt[26];

    bool operator < (const data& b) const
    {
        REP(i,0,25)
        {
            if(this->cnt[i]<b.cnt[i])return 1;
            else if(this->cnt[i]>b.cnt[i])return 0;
        }
        return 0;
    }

};

bool ispossible(int len)
{
    set<data>s;
    data a;
    MEM(a.cnt,0);
    REP(i,0,len-1)a.cnt[s1[i]-'a']++;
    s.insert(a);
    REP(i,len,s1.size()-1)
    {
        a.cnt[s1[i-len]-'a']--;
        a.cnt[s1[i]-'a']++;
        s.insert(a);
    }
    MEM(a.cnt,0);
    REP(i,0,len-1)a.cnt[s2[i]-'a']++;
    if(s.find(a)!=s.end())return 1;
    REP(i,len,s2.size()-1)
    {
        a.cnt[s2[i-len]-'a']--;
        a.cnt[s2[i]-'a']++;
        if(s.find(a)!=s.end())return 1;
    }
    return 0;
}

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
    
    cin>>s1>>s2;
    int ans=0;
    REP(i,1,min(s1.size(),s2.size()))if(ispossible(i))ans=i;
    print(ans);
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void A_Poor(void) {

	int num[3];
	int counter = 0;

	cin >> num[0] >> num[1] >> num[2];

	for (int loop1 = 0; loop1 < 3; loop1++) {
		for (int loop2 = loop1 + 1; loop2 < 3; loop2++) {
			
			if (num[loop1] == num[loop2]) counter++;
		}
	}

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

	return;
}

void B_Papers_Please(void) {

	int N;
	cin >> N;

	int A;
	for (int loop = 0; loop < N; loop++) {
		cin >> A;
		if (A % 2 == 0 && A % 3 > 0 && A % 5 > 0) {
			cout << "DENIED";
			return;
		}
	}

	cout << "APPROVED";
	return;
}

int main(void) {

	//A_Poor();
	B_Papers_Please();
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc123/tasks/abc123_b

import math
orders = sorted([int(input()) for _ in range(5)], key=lambda x: (x - 1) % 10)
last_order = orders.pop(0)
orders = [math.ceil(x / 10) * 10 for x in orders]
print(sum(orders) + last_order)


Measured memory_bytes: 2940
#include <cstdio>
#include <utility>
using namespace std;

int *A, n;

int partition(int p, int r) {
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main() {
    scanf("%d", &n);

    A = new int[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    int q = partition(0, n - 1);

    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        if (i == q) printf("[");
        printf("%d", A[i]);
        if (i == q) printf("]");
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a, b;
    int cnt=0;
    string s;
    cin>> a >> b;
    for(int i=a; i <=b; i++){
        s = to_string(i);
        //cout << s << endl;
        if(s[0]==s[4] and s[1]==s[3]) cnt+=1;
    }
    cout << cnt << endl;
}

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


using namespace std;

string s, t;

int main() {
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    
    if(s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,ii,jj;
ll n,m,sum,num=INF;
ll ans;
ll a,b,c,d,e;
ll x[100005],y[100005],z[100005];
ll xa[100005],ya[100005],za[100005];
ll dp[100005];
string s;
 
int main(){
	cin>>n>>m;
    for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>s;
			if(s=="snuke"){
				char sa[10];
				sa[10]=j+'A';
				cout<<sa[10]<<i+1<<endl;
				return 0;
			}
		}
	}
 
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

int d[301][301];
int save[301][301];
int N;

int main(void) {
    cin>>N;
    for(int i = 1;i <= N;i++) {
        for(int j = 1;j <= N;j++) {
            int a;
            cin>>a;
            d[i][j] = a;
            save[i][j] = a;
        }
    }

    for(int i = 1;i <= N;i++) {
        for(int s = 1;s <= N;s++) {
            for(int e = 1;e <= N;e++) {
                d[s][e] = min(d[s][e],d[s][i]+d[i][e]);
            }
        }
    }

    Int sum = 0;
    for(int i = 1;i <= N;i++) {
        for(int j = i;j <= N;j++) {
            if(d[i][j] != save[i][j]) {
                cout<<-1<<endl;

                return 0;
            }
        }
    }

    for(int s = 1;s <= N-1;s++) {
        for(int e = s+1;e <= N;e++) {
            bool flag = false;
            for(int i = 1;i <= N;i++) {
                if(i == s || i == e)
                    continue;
                if(save[s][e] == save[s][i]+save[i][e])
                    flag = true;
            }
            if(!flag)
                sum += save[s][e];
        }
    }

    cout<<sum<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    string s;
    cin>>s;
    int ans=0,cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R')cnt++;
        else {
            chmax(ans,cnt);
            cnt=0;
        }
    }
    chmax(ans,cnt);
    cout<<ans<<"\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

char xx[] = {'.', '#', '.', '#'};
char yy[] = {'.', '.', '#', '#'};

int main() {
    int n; cin >> n; cin.ignore();
    string s1 = "", s2 = "", q;
    string t1 = "", t2 = "";
    bool back = true;
    while(1) {
        rep(i,0,4) {
            t1 = s1; t2 = s2;
            if(back) {t1 += xx[i]; t2 += yy[i];}
            else {t1 = xx[i] + t1; t2 = yy[i] + t2;}
            cout << t1 << endl << t2 << endl; fflush(stdout);
            cin >> q;
            if(q == "end") return 0;
            else if(q == "T") {
                s1 = t1;
                s2 = t2;
                break;
            }
            else if(i == 3) back = false;
        }
    }
    return 0;
}

Measured memory_bytes: 596
fun main(args: Array<String>?): Unit {
    while(true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0){
            return
        }
        val groupDefinition = List(n){
            val line = readLine()!!.trim('.').split(':')
            line.first() to line.last().split(',')
        }
        println(findGroup(groupDefinition.first().first, groupDefinition.toMap(), mutableMapOf())!!.size)
    }
}
fun findGroup(name: String, definition: Map<String, List<String>>, cache: MutableMap<String, Set<String>>): Set<String>? {
    val define = definition[name]
    return when(define){
        null -> null
        else -> cache.getOrPut(name){
            define.flatMap{member -> findGroup(member, definition, cache) ?: listOf(member)}.toSet()
        }
    }
}



Measured memory_bytes: 43968
a = int(input(""))
if a <= 1000:
    print(1000-a)
elif a <= 2000:
    print(2000-a)
elif a <= 3000:
    print(3000-a)
elif a <= 4000:
    print(4000-a)
elif a <= 5000:
    print(5000-a)
elif a <= 6000:
    print(6000-a)
elif a <= 7000:
    print(7000-a)
elif a <= 8000:
    print(8000-a)
elif a <= 9000:
    print(9000-a)
else:
    print(10000-a)


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

int main()
{
  int r,D,x_2000,keep,i,x;
  cin >> r >> D >> x_2000;
  keep = x_2000;
  for( i = 0; i < 10; i++ )
  {
    x = r * keep - D;
    cout << x << endl;
    keep = x;
  }
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int len;
    char s[100+1]={0};
    scanf("%s", s);
    len = strlen(s);

    for(int i=0; i<len/2; i++){
        if( s[i] != s[len-i-1] ){ printf("No\n"); return 0; }
    }

    for(int i=0; i<(len/2)/2; i++){
        if( s[i] != s[len/2-i-1] ){ printf("No\n"); return 0; }
    }

    for(int i=0; i<(len/2)/2; i++){
        if( s[(len+1)/2+i] != s[len-i-1] ){ printf("No\n"); return 0; }
    }

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける

int main(){
  int N;
  string S;
  bool flag=true;
  cin >> N >> S;
  int j=0;
  for (int i = 0; i < N/2; i++)
  {
      if (S.at(i) != S.at(N/2+j))
      {
        flag = false;
      }
      j++;
  }
 if (flag == true && fmod(N,2)==0)
 {
 cout << "Yes" << endl;
 }
 else
 {
  cout << "No" << endl;
 }
}

Measured memory_bytes: 384
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			int m=sc.nextInt();
			if(n==0&&m==0)
				break;
			int h=m-1-m;
			boolean[] f=new boolean[n];
			for(int i=0; i<n; i++){
				for(int k=0; k<m; k++)
					while(f[h=(h+1)%n]);
				f[h]=true;
			}
			println(h+1+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    string ans = "";
    rep(i, s.length()) {
        if ( s[i] == '0' ) ans += '0';
        if ( s[i] == '1' ) ans += '1';
        if ( s[i] == 'B' ) ans = ans.substr(0, ans.length()-1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def lscan; gets.split.map(&:to_i); end

n,m,x = lscan

bb = n.times.map{ c, *a = lscan; [c, a]}
best = 2e18
(1..n).each do |nn|
  bb.combination(nn) do |li|
    total = li.reduce do |s, e|
      r,v = s[0].clone,s[1].clone
      r += e[0]
      m.times{|i| v[i] += e[1][i]}
      [r,v]
    end
    next unless total[1].all?{|y| y >= x}
    best = [best, total[0]].min
  end
end

p best > 1e18 ? -1 : best

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (S == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    int H[N];
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int h; cin >> h;
        H[i] = h;
    }
    int p = H[0];
    int temp = 0;
    for (int i = 1; i < N; i++) {
        if (p < H[i]) {
            if (ans < temp) {
                ans = temp;
            }
            temp = 0;
        } else {
            temp++;
        }
        p = H[i];
    }
    if (ans < temp) {
        ans = temp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険                                   // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll k, x; cin >> k >> x;
    cout << (500*k >= x ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
N = int(input())
X = sorted(map(int,input().split()))
countermin = 0
for j in range(N):
        countermin += (X[j]-X[0])**2
        
for i in range(X[0],X[-1]+1):
    counter = 0
    for j in range(N):
        counter += (X[j]-i)**2
    if counter < countermin:
        countermin = counter
print(countermin)

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

int main(){
     int K;
     while(cin>>K,K){
	  int sum=0;
	  for(int i=0;i<K*(K-1)/2;i++){
	       int ci;
	       cin>>ci;
	       sum+=ci;
	  }
	  cout<<sum/(K-1)<<endl;
     }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ucin() ios :: sync_with_stdio(0)
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
typedef double db;
const db pi = acos(-1.0);
const int N = 1e5 + 10;
db Ag(db x) {
	const db pi2 = acos(-1.0);
	return x / pi2 * 180;
}
int main() {
	int aa, bb, xx;
	db a, b, x;
	scanf("%d%d%d", &aa, &bb, &xx);
	a = aa; b = bb; x = xx; x /= a;
	if(2 * x <= a * b) { //< half
		db t = 2 * x / b;
		printf("%.8f\n", Ag(atan2(b, t)));
	} else {
		db t = 2 * (a * b - x) / a, qwq = atan2(t, a);
//		printf("qwq ! %f\n", qwq);
		printf("%.8f\n", Ag(qwq));
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cmath>
#include<memory.h>
#include<cctype>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<list>
#include<stack>
#include<utility>
#include<iomanip>
#include<bitset>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<cstring>
using namespace std;
typedef long long int ll;
typedef long double ld;
int dx[]={0,0,1,-1,1,1,-1,-1};
int dy[]={1,-1,0,0,1,-1,-1,1};
int main(){
	//freopen("a.txt","r",stdin);
	string s,sol="";
	cin >>s;
	for(int i=0;i<(int)s.size();i+=2)sol+=s[i];
	printf("%s\n",sol.c_str());
	return 0;
}

Measured memory_bytes: 512
#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;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int x,y;
    cin>>x>>y;
    int ans;
    for(int i=1;i<=x;i++)
    {
        ans = i*2;
        ans+=abs((x-i))*4;
        if(ans == y)
        {
            cout<<"Yes";
            return 0;
        }
    }
    if((x*2) == y || (x*4) == y)
        cout<<"Yes";
    else
        cout<<"No";
 
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[200005];

int comp(int a, int b)
{
	return a > b;
}

int main()
{
	cio;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> arr[i];

	sort(arr, arr + n, comp);

	ll ans = 0;
	for (int i = 1; i < n; i++)
		ans += arr[i / 2];

	cout << ans;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int n, siz[200005];
vector <int> edge[200005];
long long fact[200005], inv[200005], ans[200005], down[200005];

long long mypow(long long x, long long y) {
	long long tot = 1LL;
	while (y) {
		if (y & 1) tot = tot * x % MOD;
		y >>= 1;
		x = x * x % MOD;
	}
	return tot;
}

long long ncr(long long x, long long y) {
	return fact[x] * inv[y] % MOD * inv[x - y] % MOD;
}

long long f(long long x, int siz_x, long long y, int siz_y) {
	return ncr(siz_x + siz_y, siz_x) * x % MOD * y % MOD;
}

void pre(int id, int p) {
	siz[id] = 1;
	vector <pair<long long, int> > child;
	
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		pre(to, id);
		siz[id] += siz[to];
		child.push_back(make_pair(down[to], siz[to]));
	}
	
	down[id] = 1LL;
	int cur_siz = 0;
	
	for (int i = 0; i < child.size(); i++) {
		down[id] = f(down[id], cur_siz, child[i].first, child[i].second);
		cur_siz += child[i].second;
	}
}

void solve(int id, int p, long long up) {
	// calc answer
	int up_siz = n - siz[id];
	ans[id] = f(down[id], siz[id] - 1, up, up_siz);
	
	vector <int> child;
	vector <pair<long long, int> > l, r;
	
	for (int i = 0; i < edge[id].size(); i++) {
		int to = edge[id][i];
		if (to == p) continue;
		child.push_back(to);
	}
	
	long long cur = 1LL;
	int cur_siz = 0;
	
	for (int i = 0; i < child.size(); i++) {
		int to = child[i];
		cur = f(cur, cur_siz, down[to], siz[to]);
		cur_siz += siz[to];
		l.push_back(make_pair(cur, cur_siz));
	}
	
	cur = 1LL;
	cur_siz = 0;
	
	for (int i = child.size() - 1; i >= 0; i--) {
		int to = child[i];
		cur = f(cur, cur_siz, down[to], siz[to]);
		cur_siz += siz[to];
		r.push_back(make_pair(cur, cur_siz));
	}
	
	reverse(r.begin(), r.end());
	
	for (int i = 0; i < child.size(); i++) {
		int to = child[i];
		
		long long tot = up;
		int tmp_siz = up_siz;
		
		if (i - 1 >= 0) {
			tot = f(tot, tmp_siz, l[i - 1].first, l[i - 1].second);
			tmp_siz += l[i - 1].second;
		}
		
		if (i + 1 < child.size()) {
			tot = f(tot, tmp_siz, r[i + 1].first, r[i + 1].second);
			tmp_siz += r[i + 1].second;
		}
		
		solve(to, id, tot);
	}
}

int main() {
	scanf("%d", &n);
	
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	fact[0] = 1LL;
	for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
	inv[n] = mypow(fact[n], MOD - 2);
	for (int i = n - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
	
	pre(1, -1);
	solve(1, -1, 1);
	
	for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
}


Measured memory_bytes: 33120
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;

int n, q;
ll dp[maxn], result;

struct qry {
public:
    int l, r;
    ll value;
};

vector<qry>openings[maxn];
vector<qry>closings[maxn];

ll tree[4*maxn], lazy[4*maxn];

void push_update(int li, int ri, int index) {
    if(lazy[index] != 0) {
        tree[index] += lazy[index];
        if(li != ri) {
            lazy[2*index] += lazy[index];
            lazy[2*index+1] += lazy[index];
        }
        lazy[index] = 0;
    }
}

void update(int ul, int ur, ll uval, int li=0, int ri=n, int index=1) {
    push_update(li, ri, index);
    if(li > ur || ri< ul) return;
    else if(li >= ul && ri <= ur) {
        lazy[index] = uval;
        push_update(li, ri, index);
    }
    else {
        int mid = (li+ri)/2;
        update(ul,ur,uval,li,mid,2*index);
        update(ul,ur,uval,mid+1,ri,2*index+1);
        tree[index] = max(tree[2*index], tree[2*index+1]);
    }
}

ll query(int ql, int qr, int li=0, int ri=n, int index=1) {
    push_update(li, ri, index);
    if(li > qr || ri < ql) return LLONG_MIN;
    else if(li >= ql && ri <= qr) return tree[index];
    else {
        int mid = (li+ri)/2;
        ll a = query(ql,qr,li,mid,2*index);
        ll b = query(ql,qr,mid+1,ri,2*index+1);
        tree[index] = max(tree[2*index], tree[2*index+1]);
        return max(a, b);
    }
}

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

    cin>>n>>q;
    qry x;
    for(int i=1;i<=q;i++) {
        cin>>x.l>>x.r>>x.value;
        openings[x.l].pb(x);
        closings[x.r].pb(x);
    }

    for(int i=1;i<=n;i++) {
        for(auto x:openings[i]) {
            update(0, x.l-1, x.value);
        }

        dp[i] = query(0, i-1);
        update(i, i, dp[i]);

        result = max(result, dp[i]);

        for(auto x:closings[i]) {
            update(0, x.l-1, -x.value);
        }
    }
    cout<<result<<"\n";
    return 0;
}

Measured memory_bytes: 36224
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int A, B, C;
    cin >> A >> B >> C;
    if (A>=C) {
        cout << ( ( A >= C && C >= B ) ? "Yes" : "No" ) << endl;
    }
    else {
        cout << ( ( A <= C && C <= B ) ? "Yes" : "No" ) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int N, D, c = 0;
  double d;
  cin >> N >> D;
  vector<vector<double>> X(N, vector<double>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      d = 0.0;
      for (int dim = 0; dim < D; dim++) {
        d += pow(X[i][dim] - X[j][dim], 2.0);
      }
      d = sqrt(d);
      if (d == floor(d)) c++;
    }
  }
  cout << c << endl;
}


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

int main() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int res = 0;
    for(int i = 0; i<=a; ++i) {
        for(int j = 0; j<=b; ++j) {
            for(int k = 0; k<=c; ++k) {
                int tmp = 500 * i + 100 * j + 50 * k;
                if( tmp == x) res += 1;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using pint = tuple<int64_t, int64_t>;
using vint = vector<int64_t>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<(itr==--v.end())?"\n":" ";}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    int64_t d, n; cin >> d >> n;
    int ans = n * pow(100, d);
    if(n == 100) ans += pow(100, d);
    println(ans);
    return 0;
}


Measured memory_bytes: 384
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(N):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(N):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(N-2):
  gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[N-i-3])
  if gcd > ans:
    ans = gcd
    
gcd = gcd_from_the_left[-2]
if gcd > ans:
  ans = gcd
gcd = gcd_from_the_right[-2]
if gcd > ans:
  ans = gcd
print(ans)

Measured memory_bytes: 16124
# i番目の重みws[i], 価値vs[i]
def solve(N, W, ws, vs):
    dp = [float("inf")] * (W + 1)
    dp[0] = 0
    for i in range(N):
        # 価値v, 重さw
        v = vs[i]
        w = ws[i]
        for j in range(w, W + 1):
            dp[j] = min(dp[j - w] + v, dp[j])
    return dp


h, n = map(int, input().split())

ws = []
vs = []
for _ in range(n):
    a, b = map(int, input().split())
    ws.append(a)
    vs.append(b)


dp = solve(n, h+10**4+1, ws, vs)

print(min(dp[h:]))


Measured memory_bytes: 51804
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n,m,i,sum:Integer;
  t,p,x:array of Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);

    SetLength(t,n);
    sum:=0;
    for i := 0 to n - 1 do begin
      Read(t[i]);
      sum:=sum+t[i];
    end;

    Readln(m);
    SetLength(p,m);
    SetLength(x,m);
    for i := 0 to m - 1 do begin
      Read(p[i]);
      Readln(x[i]);
    end;

    for i := 0 to m - 1 do
      Writeln(sum-t[p[i]-1]+x[i]);

      
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
H,W = map(int,input().split())
S = []
def count(i,j):
    res = 0
    dx = [1,0,-1]
    dy = [1,0,-1]
    for k in range(3):
        for l in range(3):
            if 0 <= i + dy[k] <= H-1 and 0 <= j + dx[l] <= W-1:
                if S[i+dy[k]][j+dx[l]] == "#":
                    res += 1
    return res

for i in range(H):
    S.append(list(input()))
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i][j] = str(count(i,j))
for i in range(H):
    print("".join(S[i]))

Measured memory_bytes: 3188
#include<stdio.h>

int main(void)
{
	int i, j, r, c, x[100][100], sumr[100], sumc[100],sum;
	sum = 0;
	scanf("%d%d", &r, &c);
	for (i = 0;i < r;i++)
	{
		sumr[i]= 0;
		for (j = 0;j < c;j++)
		{
			scanf("%d", &x[i][j]);
			printf("%d ", x[i][j]);
			sumr[i] = sumr[i] + x[i][j];
		}
		printf("%d\n",sumr[i]);
	}
	for (j = 0;j < c;j++)
	{
		sumc[j] = 0;
		for (i = 0;i < r;i++)
			sumc[j] = sumc[j] + x[i][j];
		printf("%d ", sumc[j]);
		sum = sum + sumc[j];
	}
	printf("%d\n", sum);
	return 0;
}


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


def main():
    integer = {"1","2","3","4","5","6","7","8","9","0"}
    a,b = [int(i) for i in input().strip().split()]
    s = input().strip()
    if len(s) != a + b + 1:
        print("No")
        return
    
    for n in s[:a]:
        if n not in integer:
            print("No")
            return
    if s[a] != "-":
        print("No")
        return
    for n in s[a + 2:]:
        if n not in integer:
            print("No")
            return
    
    print("Yes")
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 61980
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n;

vector<int> a;

const int MAXS = 4000005;
bitset<MAXS> dp;

int main() {
    GI(n);
    a.resize(n);

    dp[0] = 1;

    int s = 0;

    FORN(i, n)
    {
        GI(a[i]);
        s += a[i];

        bitset<MAXS> newsums = dp;
        newsums <<= a[i];
        dp |= newsums;
    }

    for (int i = (s+1) / 2; i <= s; i++)
    {
        if (dp[i])
        {
            cout << i << "\n";
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1280
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
#if l[i] == l[j]: continue
n = input()
ans = 0

for i in range(len(n)):
    ans += int(n[i])

if ans % 9 == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9316
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long  ll;
const int N = 3e3 + 4;

int n;
double p[N] , memo[N][N];

double solve(int indx , int heads){
    if(indx == n)
        return heads * 2 > n;
    double &ret = memo[indx][heads];
    if(ret == ret)
        return ret;

    ret = 0.0;
    ret += p[indx] * solve(indx + 1 , heads + 1);
    ret += (1 - p[indx]) * solve(indx + 1 , heads);

    return ret;
}

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

    for(int i = 0 ; i < n ; ++i)
        cin >> p[i];

    memset(memo , -1 , sizeof memo);

    cout << fixed << setprecision(10) << solve(0 , 0) << '\n';
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=998244353;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int dp[222222][3][4];

signed main(){
    string S;
    cin>>S;

    rep(i,3)dp[1][i][i]=1;
    for(int i=1;i<S.size();i++){
        rep(j,3){
            rep(k,4){
                rep(l,3){
                    if(k==3){
                        add(dp[i+1][(j+l)%3][3],dp[i][j][k]);
                    }
                    else{
                        if(k==l)add(dp[i+1][(j+l)%3][3],dp[i][j][k]);
                        else add(dp[i+1][(j+l)%3][l],dp[i][j][k]);
                    }
                }
            }
        }
    }

    int m=0;
    rep(i,S.size())m=(m+S[i]-'a')%3;

    if(count(all(S),S[0])==S.size()){
        cout<<1<<endl;
        return 0;
    }

    if(S.size()==3&&m==0){
        cout<<3<<endl;
        return 0;
    }

    bool flag=true;
    rep(i,S.size())if(S[i+1]==S[i])flag=false;

    int ans=dp[S.size()][m][3];
    if(flag)ans=(ans+1)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 20996