akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    static long MOD = 1000000007L;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        char[] str = scanner.next().toCharArray();
        long[] dp = new long[13];
        dp[0] = 1;
        int N = str.length;
//        for(int i = N-1; i >= 0; i--) {
        for(int i =0; i < N; i++) {
            long[] newdp = new long[13];
            if (str[i] == '?') {
                for(int j = 0; j < 10; j++) {
                    for(int k = 0; k < 13; k++) {
                        int ind = (10*k + j) % 13;
                        newdp[ind] = (newdp[ind] + dp[k]) % MOD;
                    }
                }
            }
            else {
                int curVal = (str[i]-'0');
                for(int k = 0; k < 13; k++) {
                    int ind = (10*k + curVal) % 13;
                    newdp[ind] = (newdp[ind] + dp[k]) % MOD;
                }
            }
            dp = newdp;
        }
        out.println(dp[5]);
        out.flush();
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 35360
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 1000
#define maxw 10000

using namespace std;

struct yes { int w, s, p; };

yes v[maxn+5];
ll d[2*maxw+5]; ///d[w]=profit maxim pt un turn de greutate w

void umax (ll &a, ll b) { a = max(a,b); }

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int i, j, z;
  for (i = 1; i <= n; i++) cin >> v[i].w >> v[i].s >> v[i].p;
  sort (v+1,v+n+1, [](yes a, yes b) { return a.w+a.s < b.w+b.s; } );
  ///^^^vreau sa pun bucatile cu o greuate potentiala a turnului mai mare
  ///mai aproape de fund
  fill(all(d), -infl); d[0] = 0;
  for (i = 1; i <= n; i++)
    for (z = v[i].s; z >= 0; z--) umax(d[z+v[i].w], d[z] + 1LL*v[i].p);
  cout << (*max_element(all(d)));
  return 0;
}


Measured memory_bytes: 384
def main():
  num = list(map(int,input().split()))
  n=num[0]
  m=num[1]
  a = [input() for i in range(n)]
  b = [input() for i in range(m)]

  flg=0
  
  for i in range(0 , n):
    if m==1 and a[i].find(b[0])!=-1:
      flg=1
      break
    while n-i >= m and a[i].find(b[0])!=-1:
      start=a[i].find(b[0])
      for j in range(1 , m):
        if a[i+j][start:start+m]!=b[j]:
          break
        if j==m-1:
          flg=1
      if flg==1:
        break
      a[i]=a[i][a[i].find(b[0])+1:]
    if flg==1:
        break
        
  if flg==1:
    print("Yes")
  else:
    print("No")

main()

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

int main()
{

    int n;
    string s;
    cin >> n;
    cin >> s;

    REP(i, s.size())
    {
        int c = s[i] - 'A';
        c = (c + n) % 26;
        s[i] = c + 'A';
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  int n;
  cin >> n;
  int d[n];
  rep(i,n){
    cin >> d[i];
  }
  sort(d,d+n);
  cout << d[n/2]-d[n/2-1];
  
 
 return 0;
}

Measured memory_bytes: 640
/**
 * A - Harmony
 * https://atcoder.jp/contests/abc135/tasks/abc135_a
 **/
#include<iostream>

using namespace std;

int A, B;

void solve() {
    int diff = abs(A-B);
    if (diff%2 == 0) {
        int k;
        if (A > B) {
            k = B + diff / 2;
        } else {
            k = A + diff / 2;
        }
        cout << k << endl;
    } else {
        cout << "IMPOSSIBLE";
    }
}

int main() {
    cin >> A >> B;
    solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int h, w;
    sc(h) sc(w)
    vector<string> s;
    string x;
    REP(i, h){
        cin >> x;
        s.push_back(x);
    }
    REP(i, h){
        cout << s[i] << endl;
        cout << s[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
struct cxk{int a,b,c;}s[100010];
ll L[100010],R[100010];
std::priority_queue<int,std::vector<int>,std::greater<int>>que;
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int X=gi(),Y=gi(),Z=gi(),_a,_b,_c,n=X+Y+Z;
	ll sumc=0;
	for(int i=1;i<=n;++i)_a=gi(),_b=gi(),_c=gi(),s[i]={_a-_c,_b-_c,_b-_a},sumc+=_c;
	std::sort(s+1,s+n+1,[](cxk a,cxk b){return a.c<b.c;});
	for(int i=1;i<=n;++i){
		L[i]=L[i-1]+s[i].a;que.push(s[i].a);
		if(i>X)L[i]-=que.top(),que.pop();
	}
	while(!que.empty())que.pop();
	for(int i=n;i;--i){
		R[i]=R[i+1]+s[i].b;que.push(s[i].b);
		if(n-i+1>Y)R[i]-=que.top(),que.pop();
	}
	ll ans=-9e18;
	for(int i=X;i<=n-Y;++i)ans=std::max(ans,L[i]+R[i+1]);
	printf("%lld\n",ans+sumc);
	return 0;
}



Measured memory_bytes: 3448
import sys
input = sys.stdin.buffer.readline

def main():
    N,C = map(int,input().split())
    susi = [tuple(map(int,input().split())) for _ in range(N)]
    csusi = list(reversed(susi))
    
    cal,ccal = 0,0
    now,cnow = 0,0
    eat,ceat = [(0,0)],[(0,0)]
    for i,j in zip(susi,csusi):
        x,v = i
        cal += v
        if cal-x > eat[-1][0]:
            now = x
            eat.append((cal-x,now))
        else:
            eat.append((eat[-1][0],now))
        cx,cv = j
        ccal += cv
        if ccal-(C-cx) > ceat[-1][0]:
            cnow = C-cx
            ceat.append((ccal-(C-cx),cnow))
        else:
            ceat.append((ceat[-1][0],cnow))
    
    ceat.reverse()
    ans = 0
    for i,j in zip(eat,ceat):
        eat,x = i
        ceat,cx = j
        ans = max(ans,eat+ceat-min(x,cx))

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 41124
a, b = gets.split.map(&:to_i)
if a.odd?
    if b.odd?
        p ((b-a)/2).odd? ? 1^a : a
    else
        p ((b-a-1)/2).odd? ? a^1^b : a^b
    end
else
    if b.odd?
        p ((b-a+1)/2).odd? ? 1 : 0
    else
        p ((b-a)/2).odd? ? 1^b : b
    end
end

Measured memory_bytes: 1788
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
dp = [[0, 0, 0] for _ in range(N + 1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])

print(max(dp[N]))


Measured memory_bytes: 47328
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		int c=0,f=0;
		int[] p = new int[2];
		int n=Integer.parseInt(bf.readLine());
		while(n-->0){
			String[] d=bf.readLine().split(" ");p[0]=p[1]=0;
			for(int i=0;i<10;i++){
				c=Integer.parseInt(d[i]);
				f=(p[0]<p[1])?1:0;
				if(p[f]<c){
					p[f]=c;
				}else if(p[(f==1?0:1)]<c){
					p[(f==1?0:1)]=c;
				}else{
					System.out.println("NO");
					break;
				}
				if(i==9)System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 9168
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
    fio;
        ll a,b;
        cin>>a>>b;
        cout<<a*b<<endl;
}

Measured memory_bytes: 3652
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

def gcd(lhs, rhs)
  l = [lhs, rhs].max
  s = [lhs, rhs].min
  r = l % s
  return s if r.zero?
  gcd(s, r)
end

def mgcd(ary)
  v = ary.first
  1.upto(ary.length - 1) do |i|
    v = gcd(v, ary[i])
  end
  v
end

def solve(ary)
  result = []
  v = ary.first
  1.upto(ary.length - 1) do |i|
    ks = gcd(v, ary[i])
    result << { idx: i, ks: ks }
    v = ks
  end
  result.sort_by! { |r| [r[:ks], r[:idx]] }
  i = result.first[:idx]
  a1 = ary.dup
  a1[i - 1] = a1[i]
  a2 = ary.dup
  a2[i] = a2[i - 1]
  [mgcd(a1), mgcd(a2)].max
end

puts solve(a.sort.reverse)


Measured memory_bytes: 42604
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll gcd(ll a, ll b) {
	//cout << a << " " << b << endl;
	if (b%a == 0)return a;
	return gcd(b%a, a);
}
ll x, y,sz;
int main(){
	cin >> x >> y;
	sz = gcd(x, y);
	x /= sz, y /= sz;
	//cout << sz << endl;
	cout << (x + y)*sz - (sz - 1) << endl;
	return 0;
}


Measured memory_bytes: 3124
def main():
    H, W = map(int, input().split())
    c_matrix = [input() for _ in range(H)]
    ans = []
    for c_row in c_matrix:
        ans.append(c_row)
        ans.append(c_row)
    print("\n".join(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
h, w, d = gets.split.map(&:to_i)

xy = Array.new(h * w + 1)
h.times do |i|
    gets.split.each_with_index {|e, j| xy[e.to_i] = [i, j]}
end

memo = Array.new(h * w + 1, 0)
(d+1).upto(h*w) do |i|
    j = i - d
    dis = (xy[i][0] - xy[j][0]).abs + (xy[i][1] - xy[j][1]).abs
    memo[i] = memo[i - d] + dis
end

gets.to_i.times do
    l, r = gets.split.map(&:to_i)
    p memo[r] - memo[l]
end

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> x(n, vector<int>());
  for (int j = 0; j < m; j++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    x[a].push_back(b);
    x[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    for (int j = 0; j < x[i].size(); j++) {
      if (h[i] <= h[x[i][j]]) flag = false;
    }
    if (flag) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

 
int main() {

    int64_t n;
    cin>>n;


    vector<int> L(2*n);
    for(int i=0;i<2*n;i++){
        cin>>L.at(i);
    }

    sort(L.begin(),L.end());

    int64_t sum=0;
    for(int i=0;i<2*n;i++){
        if(i%2==1)
            sum+=min(L.at(i),L.at(i-1));
    }

    cout<<sum<<endl;

 	return 0;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;


int main() {

	
	int a, b, x;
	cin >> a >> b >> x;

	vector<long long int>s(a), t(b);

	for (int i = 0; i < a; i++)cin >> s[i];
	for (int i = 0; i < b; i++)cin >> t[i];
	s.push_back(9999999999999999);
	s.push_back(-999999999999999);

	t.push_back(9999999999999999);
	t.push_back(-999999999999999);

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());

	for (int i = 0; i < x; i++) {

		long long int z;
		cin >> z;
		auto ss = lower_bound(s.begin(), s.end(), z);
		auto tt = lower_bound(t.begin(), t.end(), z);

		vector<long long int>aa = { *ss,*prev(ss) };
		vector<long long int>bb = { *tt,*prev(tt) };

		long long int ans = 999999999999999;

		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if (z < aa[j] && z < bb[k]) {
					ans = min(ans, max(aa[j], bb[k]) - z);
				}
				else if (aa[j] < z&&bb[k] < z) {
					ans = min(ans, z - min(aa[j], bb[k]));
				}
				else {
					ans = min(ans, abs(bb[k] - aa[j]) + min(abs(z - aa[j]), abs(z - bb[k])));
				}
			}
		}

		cout << ans << endl;
	}

	return 0;


}

Measured memory_bytes: 2912
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
const lint mod = 1e9 + 7;

int s[210];
lint dp[210][100010];

lint solve(int i, int j){
    if(dp[i][j] >= 0) return dp[i][j];
    return dp[i][j] = ((lint)(i-1)*solve(i-1, j) + solve(i-1, j%s[i-1])) % mod;
}

int main(){
    int n, x;
    scanf("%d%d", &n, &x);
    rep(i, n) scanf("%d", &s[i]);
    sort(s, s+n);
    rep(i, n+1)rep(j, x+1) dp[i][j] = -1;
    rep(j, x+1) dp[0][j] = j;
    printf("%lld\n", solve(n, x));
}

Measured memory_bytes: 157952
from collections import *

N = int(input())
s = list(input())
cnt = defaultdict(lambda : defaultdict(int))

for S in range(2**N):
    red, blue = [], []
    
    for i in range(N):
        if (S>>i)&1:
            red.append(s[i])
        else:
            blue.append(s[i])
    
    cnt[''.join(red)][''.join(blue)] += 1

s.reverse()
ans = 0

for S in range(2**N):
    red, blue = [], []
    
    for i in range(N):
        if (S>>i)&1:
            red.append(s[i])
        else:
            blue.append(s[i])
    
    ans += cnt[''.join(blue)][''.join(red)]

print(ans)

Measured memory_bytes: 245628
/*
QUESTION    :

RULE        :

INPUT       :

OUTPUT      :
*/
/*
    int     :10^9
long long   :10^19
*/
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(n);++i)
#define repeq(i,a,n) for(int i=a;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    if(n>=1000){
        int a=0;
        if(n%1000==0){
            n=0;
        }else{
            a=n/1000+1;
        }
        
        cout << (a*1000)-n << endl;
    }else {
        cout << (1000-n) << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;
typedef long long ll;

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) {
        cin >> c.at(i);
    }
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s.at(i).at(j);
        }
    }
    vector<int> t(D);
    for (int i = 0; i < D; i++) {
        cin >> t.at(i);
    }
    int M;
    cin >> M;
    vector<vector<int>> queri(M, vector<int>(2));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> queri.at(i).at(j);
        }
    }
    int ans;
    vector<int> v(26, 0);
    vector<int> last;
    for (int k = 0; k < M; k++) {
        ans = 0;
        last = v;
        t.at(queri.at(k).at(0) - 1) = queri.at(k).at(1);
        for (int i = 0; i < D; i++) {
            last.at(t.at(i) - 1) = i + 1;
            for (int j = 0; j < 26; j++) {
                if (t.at(i) == j + 1) {
                    ans += s.at(i).at(t.at(i) - 1);
                }
                else {
                    ans -= (i + 1 - last.at(j)) * c.at(j);
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 8596
import numpy as np
import math

n = int(input())
max = 1e+18
is_zero = False
ans = 1
a = input().split()

for i in range(n):
    if (int(a[i]) == 0):
        ans = 0
        is_zero = True
        break

if not is_zero:
    for i in range(n):
        ans *= int(a[i])
        if ans > max:
            ans = -1
            break

print(ans)


Measured memory_bytes: 37900
import sys
sys.setrecursionlimit(10**4)
def input():
	return sys.stdin.readline()[:-1]

n, m = map(int, input().split())
adj = [[] for _ in range(n)]
edges = []
for i in range(m):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	edges.append((a-1, b-1))

seen = [False for _ in range(n)]
visited = [False for _ in range(n)]
begin = -1
hist = []

def dfs(x):
	global begin, hist
	if begin >= 0:
		return
	seen[x] = True
	hist.append(x)
	for v in adj[x]:
		if visited[v]:
			continue
		if seen[v] == True and visited[v] == False:
			begin = v
			return
		dfs(v)
		if begin >= 0:
			return
	visited[x] = True
	hist.pop()
	return

for i in range(n):
	if begin < 0:
		dfs(i)
	if begin >= 0:
		break

if begin < 0:
	print(-1)
	sys.exit()
else:
	cycle = []
	included = [False for _ in range(n)]
	included[begin] = True
	while hist and hist[-1] != begin:
		cycle.append(hist[-1])
		included[hist[-1]] = True
		hist.pop()
	cycle.append(begin)
	hist.pop()

	while True:
		meets = True
		l = len(cycle)
		ind = [-1 for _ in range(n)]
		for i in range(l):
			ind[cycle[i]] = i
		for i in range(l):
			if meets == False:
				break
			for v in adj[cycle[(i+1)%l]]:
				if included[v] == True and v != cycle[i]:
					meets = False
					new_start_id, new_end_id = ind[v], (i+1)%l
					break

		if meets:
			print(len(cycle))
			print(*[c+1 for c in cycle], sep="\n")
			break
		else:
			new_cycle = []
			included = [False for _ in range(n)]
			cur = new_end_id
			while cur != new_start_id:
				new_cycle.append(cycle[cur])
				included[cycle[cur]] = True
				cur = (cur+1)%l
			new_cycle.append(cycle[new_start_id])
			cycle = new_cycle

Measured memory_bytes: 4212
n = int(input())
x = 0

for i in range(1,n+1):
    if i%3 == 0:
        print(" %d"%i,end = "")
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()


Measured memory_bytes: 5868
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  vector<Int> as(q),bs(q);
  for(Int i=0;i<q;i++) cin>>as[i]>>bs[i];

  vector<Int> vs(n+2,0);
  vs[1]=2;
  Int cur=1;
  for(Int i=0;i<q;i++){
    vs[cur-1]=vs[cur+1]=1;
    swap(vs[as[i]],vs[bs[i]]);
    if(vs[as[i]]==2) cur=as[i];
    if(vs[bs[i]]==2) cur=bs[i];
    vs[cur-1]=vs[cur+1]=1;
  }


  Int ans=0;
  for(Int i=1;i<=n;i++)
    ans+=vs[i]>=1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C;
  str S;
  cin>>A>>B>>C;
  if(C-A<=B&&C-A>=0){
    cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
while True:
  a, op, b =map(str,input().split())
  a = int(a)
  b = int(b)
  if op == "?":
    break
  if op == '+':
    print(a+b)
  if op == "-":
    print(a-b)
  if op == "*":
    print(a*b)
  if op == "/":
    print(a//b)
  


Measured memory_bytes: 5592
import math

a, b = input().split()
a = int(a)
bi = int(b.split('.')[0])
bf1 = int(b.split('.')[1][0])
bf2 = int(b.split('.')[1][1])

ans = [0] * 18

c1 = list(str(a * bi))
idx = 2
while c1:
    ans[idx] += int(c1.pop())
    idx += 1

c2 = list(str(a * bf1))
idx = 1
while c2:
    ans[idx] += int(c2.pop())
    idx += 1

c3 = list(str(a * bf2))
idx = 0
while c3:
    ans[idx] += int(c3.pop())
    idx += 1

for i in range(18):
    if ans[i] >= 10:
        ans[i + 1] += ans[i] // 10
        ans[i] = int(str(ans[i])[-1])

ans = ans[2:]
while ans:
    if ans[-1] == 0:
        ans.pop()
    else:
        break

ans = [str(x) for x in ans]

if len(ans) == 0:
    print(0)
else:
    print(''.join(reversed(ans)))


Measured memory_bytes: 9228
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  a.sort();
  auto m = a[$-1], r = 0;
  foreach (i; 0..n-1)
    if ((m.to!real/2-a[i]).abs < (m.to!real/2-r).abs)
      r = a[i];

  writeln(m, " ", r);
}


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

int main()
{
    map<string,int> mp;
    int n;
    cin>>n;
    int cmax=0;
    while(n--)
    {
        string g;
        cin>>g;
        mp[g]++;
        if(mp[g]>cmax)
            cmax=mp[g];
    }
    for(auto it:mp)
        if(it.second==cmax)
            cout<<it.first<<"\n";
}

Measured memory_bytes: 25216
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;
typedef std::pair<int, int> ipair;
const int MAX_V = 100010;
const int MAX_LOG_V = 17;
vector<ipair> G[MAX_V];
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];
vector<int> eulerT;
 
template<class T> class TREE {
 
   public:
      int k = 0;
      T distance[MAX_V];
      int begin[MAX_V * 2];
      int end[MAX_V * 2];
 
      // vertex, parent, depth, distance
      void dfs(int v, int p, int d, T l) {
         parent[0][v] = p;
         depth[v] = d;
         distance[v] = l;
         begin[v] = k;
         eulerT.push_back(v);
         k++;
         for (auto& g : G[v]) {
            if (g.first != p) {
               dfs(g.first, v, d + 1, l + g.second);
               eulerT.push_back(v);
               k++;
            }
         }
         end[v] = k;
      }
 
      void init(int V, int root) {
         dfs(root, -1, 0, 0);
         for (int k = 0; k + 1 < MAX_LOG_V; k++) {
            for (int v = 0; v < V; v++) {
               if (parent[k][v] < 0) parent[k + 1][v] = -1;
               else parent[k + 1][v] = parent[k][parent[k][v]];
            }
         }
      }
 
      int lca(int u, int v) {
         if (depth[u] > depth[v]) swap(u, v);
         for (int k = 0; k < MAX_LOG_V; k++) {
            // if k th digit of depth[v] - depth[u] is 1
            if ((depth[v] - depth[u]) >> k & 1) {
               v = parent[k][v];
            }
         }
         if (u == v) return u;
         for (int k = MAX_LOG_V - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
               u = parent[k][u];
               v = parent[k][v];
            }
         }
         return parent[0][u];
      }

      T dist2(int u, int v) {
         return distance[u] + distance[v] - 2 * distance[lca(u, v)];
      }
};


int main() {
   int N;
   cin >> N;
   int a, b;
   for (int i = 0; i < N - 1; i++) {
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(ipair(b, 1));
      G[b].push_back(ipair(a, 1));
   }

   TREE<int> tree;
   tree.init(N, 0);
   
   int cnt = 0;
   for (int i = 0; i < N; i++) {
      int from1 = tree.dist2(i, 0);
      int fromN = tree.dist2(i, N - 1);
      if (from1 <= fromN) cnt++;
   }
   if (cnt > N - cnt) cout << "Fennec" << endl;
   else cout << "Snuke" << endl;
   return 0;
}


Measured memory_bytes: 18292
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


int main() {
  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> point(N,K-Q);

  for (ll q = 0; q < Q; q++){
    ll indx;
    cin >> indx;
    indx -= 1;
    point[indx] +=1;
  }

  for (ll n = 0; n < N; n++){
    if (point[n] > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	set<int> s;
	rep(i,n) {
		int a; cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  double n; cin >> n;
  printf("%.7lf",  pow(n/3, 3));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    long long price = 0, n, m, a;
    cin >> n >> m;
    vector<long long>as(n);
    vector<long long>bs(n);
    map<long long, long long>re;
    map<long long, long long>used;
    for (int i = 0; i < n; i++){
        cin >> as[i] >> bs[i];
        re[as[i]] += bs[i];
    }
    sort(as.begin(), as.end());
    for (int i = 0; i < n; i++){
        if (used[as[i]] == 0) {
            if (0 < m - re[as[i]]){
                m = m - re[as[i]];
                price = price + as[i] * re[as[i]];
                used[as[i]]++;
            }else{
                cout << price + as[i] * m << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 14336
var
  a, now: array [1..15] of longint;
  p, s: array [1..15, 1..14] of longint;
  n, i, j, cnt, ans: longint;
function max(x, y: longint): longint; inline;
begin
  if x > y then exit(x) else exit(y);
end;
function check: boolean; inline;
var
  i, j, unkind: longint;
begin
  for i := 1 to n do
  begin
    unkind := 1;
    for j := 1 to a[i] do
      if now[p[i, j]] <> s[i, j] then
      begin
        unkind := 0;
        break;
      end;
    if now[i] <> unkind then exit(false);
  end;
  exit(true);
end;
procedure dfs(d: longint);
begin
  if d = n + 1 then
  begin
    if check then ans := max(ans, cnt);
    exit;
  end;
  now[d] := 0;
  dfs(d + 1);
  now[d] := 1;
  inc(cnt);
  dfs(d + 1);
  dec(cnt);
end;
begin
  read(n);
  for i := 1 to n do
  begin
    read(a[i]);
    for j := 1 to a[i] do read(p[i, j], s[i, j]);
  end;
  dfs(1);
  writeln(ans);
end.


Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N*A, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<math.h>
#include <cstdio>
#include<iomanip>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 10e9 + 7;
int a[105];
int b[8] = {};
signed main() {
	int n;
	cin >> n;
	int sum = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 3200)b[a[i] / 400]++;
		else sum++;
	}
	int cnt = 0;
	rep(i, 8) {
		if (b[i] > 0)cnt++;
	}
	if (cnt == 0)cout << 1 <<' '<< sum << endl;
	else cout << cnt << ' '<<cnt + sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,a,b,c;
	cin>>n>>m;
	vector<tlll> e;
	rep(i,m){
		cin>>a>>b>>c;
		a--;b--;
		e.push_back(tlll(a,b,c));
	}
	vl dist(n,-LINF);
	dist[0]=0;
	ll ans1=-LINF,ans2=-LINF;
	rep(i,2*n){
		rep(j,m){
			ll to,from,cost;
			tie(from,to,cost)=e[j];
			if(dist[to]<dist[from]+cost){
				dist[to]=dist[from]+cost;
			}
		}
		if(i==n-1)ans1=dist[n-1];
		if(i==n*2-1)ans2=dist[n-1];
	}
	if(ans1<ans2)cout<<"inf"<<endl;
	else cout<<ans1<<endl;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(),b = scanner.nextInt(),c = scanner.nextInt();
		int[] x = {a,b,c};
		Arrays.sort(x);
		System.out.println(x[0]+x[1]);
	}

}


Measured memory_bytes: 20820
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int main() {
	int N=0;
	cin >> N;
	int a = 0, ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> a;
		ans += (a - 1);
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

int memo[10][10];

int d1(int n) {
    int v = 0;
    while (n) {
        v = n % 10;
        n /= 10;
    }
    return v;
}

int d2(int n) {
    return n % 10;
}

void solve(long long N) {

    for (int i = 1; i <= N; i++) {
        memo[d1(i)][d2(i)]++;
    }

    long long ans = 0;
    for(int i = 0 ; i < 10 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            ans += 1ll * memo[i][j] * memo[j][i];
        }
    }
    cout << ans << endl;

}

int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextInt()
    val b = scanner.nextInt()
    val sum = a+b
    val sub = a-b
    val mul = a*b
    val max = Math.max(sum,sub)
    println(Math.max(max,mul))

}

Measured memory_bytes: 31388
import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int, input().split())
root = [-1] * n

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]
    

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
    

def size(x):
    x = r(x)
    return -root[x]


for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x,y)


max_size = 0
for i in range(n):
    max_size = max(size(i), max_size)


print(max_size)

Measured memory_bytes: 35884
(defun br()
        (princ '#\newline))

(defun solve()
        (let ((a (read)) (b (read)))
                (cond ((< a b)
                        (princ 'LESS))
                      ((> a b)
                        (princ 'GREATER))
                      (t
                        (princ 'EQUAL)))
                (br)))

(solve)

Measured memory_bytes: 3304
k1,k2 = [int(x) for x in input().split(' ')]
k3,k4 = [int(x) for x in input().split(' ')]
k5,k6 = [int(x) for x in input().split(' ')]
K = [k1,k2,k3,k4,k5,k6]
ss = [0,0,0,0]
for k in K:
    ss[k-1] += 1

ans = 'YES'
for s in ss:
    if s == 0:
        ans = 'NO'
    if s >= 3:
        ans = 'NO'
print(ans)

Measured memory_bytes: 3064
H,W = map(int,input().split(" "))
b = [list(input()) for x in range(H)]
n = [[0]*(W+2) for x in range(H+2)]

for i in range(H):
    for j in range(W):
        if b[i][j] == '#':
            n[i][j] += 1
            n[i+1][j] += 1
            n[i+2][j] += 1
            n[i][j+1] += 1
            n[i][j+2] += 1
            n[i+2][j+1] += 1
            n[i+2][j+2] += 1
            n[i+1][j+2] += 1

for i in range(H):
    for j in range(W):
        if b[i][j] == ".":
            b[i][j] = str(n[i+1][j+1])

print('\n'.join(map(lambda x : ''.join(x),b)))


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(count(S.begin(), S.end(), 'A') == 3 || count(S.begin(), S.end(), 'B') == 3){
        cout<<NO<<endl;
    }else{
        cout<<YES<<endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1)
#define MAXS 1e(18)
#define MOD 1000000007
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int node, tx, ax, acost[100005], tcost[100005];
bool vis[100005];
vector<int>graph[100005];

void bfs(int sx){
    memset(vis,0,sizeof(vis));
    acost[sx]=0;
    vis[sx]=1;
    queue<int>q;
    q.push(sx);
    while(q.size()>0){
        int xx = q.front(); q.pop();
        for(int i=0; i<graph[xx].size(); i++){
            int yy = graph[xx][i];
            if(!vis[yy]){
                acost[yy] = 1 + acost[xx];
                vis[yy]=1;
                q.push(yy);
            }
        }
    }
    return;
}
void bfs2(int sx){
    memset(vis,0,sizeof(vis));
    vis[sx]=1;
    tcost[sx]=0;
    queue<int>q;
    q.push(sx);
    while(q.size()>0){
        int xx = q.front(); q.pop();
        for(int i=0; i<graph[xx].size(); i++){
            int yy = graph[xx][i];
            if(!vis[yy]){
                tcost[yy] = 1 + tcost[xx];
                vis[yy]=1;
                q.push(yy);
            }
        }
    }
    return;
}


int main()
{

    _fastIO;

    int x,y;
    cin>>node>>tx>>ax;
    for(int i=1; i<node; i++){
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int ans=0;
    bfs(ax);
    bfs2(tx);
    for(int i=1; i<=node; i++){
        if(tcost[i]<acost[i]){
            ans = max(ans, acost[i]-1);
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 6784
d,n = map(int,input().split())
ans = 0
if d == 0:
  ans = n
elif d == 1:
  ans = 100 * n
else:
  ans = 10000 * n
if n == 100:
  if d == 0:
    ans += 1
  elif d == 1:
    ans += 100
  else:
    ans += 10000
print(ans)

Measured memory_bytes: 3060
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for i in range(m)]
s = sum(t)
for i in px:
    p, x = i[0], i[1]
    print(s + (x - t[p - 1]))

Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main(){
    string s;
    cin>>s;

    if(s[0]==s[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll factorial(ll n,ll mod = mod){
  static ll dp[e5];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1))%mod;
}

ll powl(ll x,ll r,ll mod = mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll inverse(ll x,ll mod = mod){
  return powl(x,mod-2,mod);
}

ll combination(ll n,ll m,ll mod = mod){
  if(n < m) return 0;
  return (((factorial(n)*inverse(factorial(m)))%mod)*inverse(factorial(n-m)))%mod;
}


ll n;
ll ans = 0;

ll solve(ll k){
  return (((combination(k-1,n-1-k)*factorial(k))%mod)*factorial(n-1-k))%mod;
}


int main(){
  cin >> n;
  if(n == 2){
    cout << 1 << endl;
    return 0;
  }
  for(ll i = 2;i <= n-1;i++){
    ans += ((((solve(i)-solve(i-1)+mod)%mod)*i)%mod);
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 39680
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int64_t X; std::cin >> X;
  int64_t a = 100;
  for(int i = 1;; ++i) {
    a += a/100;
    if(a >= X) fin(i);
  }
  return 0;
}


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

int N,M;
int taro[100];
int hana[100];

int main(){
  while(cin>>N>>M,N||M){
    for(int i=0;i<N;i++){
      cin>>taro[i];
    }
    for(int i=0;i<M;i++){
      cin>>hana[i];
    }
    int tsum=0,hsum=0;
    for(int i=0;i<N;i++)tsum+=taro[i];
    for(int i=0;i<M;i++)hsum+=hana[i];

    int a,b;
    int ansa,ansb;
    int anssum=100000;
  
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
	a=taro[i];
	b=hana[j];
	if(tsum-a+b==hsum-b+a){
	  if(a+b<anssum){
	    //cout<<"a:"<<a<<"b:"<<b<<endl;
	    ansa=a;
	    ansb=b;
	    anssum=a+b;
	  }
	}
      }
    }
    if(anssum==100000)cout<<-1<<endl;
    else cout<<ansa<<" "<<ansb<<endl;
  }
}
      

Measured memory_bytes: 0
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
char S[300002];
int main(){
  int a=0, b=0, i, res=1073709056;
  rd(N);
  rd(S);
  for(i=0;i<(N);i++){
    if(S[i]=='E'){
      b++;
    }
  }
  for(i=0;i<(N);i++){
    if(S[i]=='E'){
      b--;
    }
    chmin(res, a + b);
    if(S[i]=='W'){
      a++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190827-1

// --- original code ---
// int N; char S[300002];
// {
//   int i, a = 0, b = 0, res = int_inf;
//   rd(N,S);
//   rep(i,N) if(S[i]=='E') b++;
//   rep(i,N){
//     if(S[i]=='E') b--;
//     res <?= a + b;
//     if(S[i]=='W') a++;
//   }
//   wt(res);
// }


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

// as + bt = GCD(a,b) a,b:const s,t:var(any)
// return GCD(a,b)
long long extGCD(long long a, long long b, long long& s,
                 long long& t) {
  s = 1, t = 0;
  long long u = 0, v = 1;
  while(b) {
    long long tmp = a / b;
    a -= b * tmp;
    s -= u * tmp;
    t -= v * tmp;
    swap(s, u);
    swap(t, v);
    swap(a, b);
  }
  return a;
}

// (mod)x+ay=1, calculate y -> a^-1 (mod m) (a,m : coprime)
long long calcinv(long long a, long long m) {
  long long s, t;
  extGCD(a, m, s, t);
  return (s + m) % m;
}

long long M = 0;

// x=b_i(mod m_i) calc min x,lcm(m_i).
// if not exist, return (-1,-1)
pair<long long, long long> ChineseRem(
    const vector<long long>& b,
    const vector<long long>& m) {
  long long r = 0, lcm = 1;
  assert(b.size() == m.size());
  long long bsize = b.size();
  for(int i = 0; i < bsize; ++i) {
    long long p, q, d, now;
    d = extGCD(lcm, m[i], p, q);
    if((b[i] - r) % d != 0) return make_pair(-1, -1);
    now = (b[i] - r) / d * p % (m[i] / d);
    r += lcm * now;
    if(r > M) return make_pair(-1, -1);
    lcm *= m[i] / d;
  }
  return make_pair((r + lcm) % lcm, lcm);
}

long long n, m;
vector<long long> a, b;

long long solve();

int main() {
  cin >> n >> m;
  M = m;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; i < n; ++i) b.push_back(a[i] / 2);
  pair<long long, long long> res = ChineseRem(b, a);
  if(res == make_pair(-1LL, -1LL) || res.first > m)
    return 0;
  return (m - res.first) / res.second + 1;
}


Measured memory_bytes: 2168
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

/*******************************************************************/

var a, b, k int

func main() {
	tmp := NextIntsLine()
	a, b, k = tmp[0], tmp[1], tmp[2]

	for i := 0; i < k; i++ {
		if i%2 == 0 {
			// 高橋くん
			if a%2 == 1 {
				// 奇数なら1枚食べる
				a -= 1
			}
			b += a / 2
			a /= 2
		} else {
			// 青木くん
			if b%2 == 1 {
				// 奇数なら1枚食べる
				b -= 1
			}
			a += b / 2
			b /= 2
		}
	}
	fmt.Println(a, b)
}


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

int main()
{
    int A1,A2,A3;
    scanf("%d%d%d",&A1,&A2,&A3);
    if(A1>=1&&A2>=1&&A3>=1&&A1<=13&&A2<=13&&A3<=13){
    if(A1+A2+A3>=22)
    {
        printf("bust");
    }
    else
        printf("win");
    }
    return 0;
}


Measured memory_bytes: 128
n = gets.chomp.to_i
v = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

ans = 0
n.times{ |i|
  vc = v[i] - c[i]
  if vc > 0
    ans += vc
  end
}
puts(ans)

Measured memory_bytes: 1788
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-03 18:04:59
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');
using namespace std;

int t;       //test cases
ll  n=0, k,m; //variables
long long w,x;
ll  a, b, d;
ll c;
ll p=100.0;
string s;
set<string>st;
ll i;
int main() {
	cin>>s;
	putchar(s[0]);
	if(s[1]=='B')putchar('R');
	else putchar('B');
	putchar(s[2]);
	puts("");
	

	return 0;
}


Measured memory_bytes: 3624