akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)



int main() {
	int N, M, MD, K;
	cin >> N >> M >> MD >> K;
	vector<vector<pair<int, long long int>>>rev_edge(N + 1);
	for (int i = 0; i < M; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		rev_edge[r].push_back({ l,k });
	}
	vector<vector<long long int>>dis(MD, vector<long long int>(N + 1,MOD*MOD));
	for (int i = 0; i < MD; i++) {
		for (int j = i; j <= N; j += MD) {
			dis[i][j] = 0;
		}
		priority_queue<pair<long long int, int>, vector<pair<long long int, int>>, greater<pair<long long int, int>>>PQ;
		for (int j = 0; j <= N; j++) {
			if (dis[i][j] == MOD*MOD) continue;
			PQ.push({ dis[i][j],j });
		}
		while (!PQ.empty()) {
			int cn = PQ.top().second;
			long long int c = PQ.top().first;
			PQ.pop();
			for (auto j : rev_edge[cn]) {
				if (dis[i][j.first]>c + j.second) {
					dis[i][j.first] = c + j.second;
					PQ.push({ dis[i][j.first],j.first });
				}
			}
		}
	}
	long long int ans = 0;
	for (int i = 0; i < K; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		long long int add = 0;
		for (int j = 0; j < MD; j++) {
			add = max(add, c - dis[j][a] - dis[j][b]);
		}
		ans += add;
	}
	cout << ans << endl;
}



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

void print(vector<int> v){
    for(const auto& i : v)
        cout << i << " ";
    cout << "\n";
}
const int INF = 1e9 + 5;
int main(int argc, char ** argv){
    int n;
    cin >> n;
    vector<int> s(n);
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    for(int i = 0;i < dp.size();++i){
        for(int j : {i+1,i+2}){
            if(j < n)
                dp[j] = min(abs(s[i] - s[j]) + dp[i], dp[j]);
        }
    }
    printf("%d\n", dp[n-1]);
    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N, M = map(int, input().split()) # 頂点の数、辺の数
    H=list(map(int,input().split()))
    edge = [[] * N for i in range(N)]
    for i in range(M):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x) # 有向ならコメントアウト

    cnt=0
    for i in range(N):
        val=H[i]
        if not edge[i]:
            cnt+=1
        else:
            if all(val>H[j] for j in edge[i]):
                cnt+=1

    print(cnt)



resolve()

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

signed main(void){
  int N; cin >> N;
  vector<int>id(N),P(N),Q(N);
  for(int i = 0; i < N; i++){ id[i] = i;}
  for(int i = 0; i < N; i++){ cin >> P[i];}
  for(int i = 0; i < N; i++){ cin >> Q[i];}
  int cnt = 0;
  int a,b;
  do{
    cnt++;
    bool p = true,q = true;
    for(int i = 0; i < N; i++){
      if( id[i] != P[i]-1 ){ p = false;}
    }
    for(int i = 0; i < N; i++){
      if( id[i] != Q[i]-1 ){ q = false;}
    }
    
    if(p){ a = cnt;}
    if(q){ b = cnt;}
    
  }while(next_permutation(id.begin(),id.end()));
  
  cout << abs(b-a) << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(input())
s = [int(i) for i in s]

former = s[0] * 10 + s[1]
latter = s[2] * 10 + s[3]

formflg = 0
lattflg = 0


if former <= 12 and former != 0:
	formflg = 1
	
if latter <= 12 and latter != 0:
	lattflg = 1
	

if formflg + lattflg == 0:
	print("NA")
elif formflg + lattflg == 2:
	print("AMBIGUOUS")
elif formflg == 1:
	print("MMYY")
elif lattflg == 1:
	print("YYMM")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int judge(int n) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            // cout << i << endl;
        }
    }
    return cnt;
}

int main(void) {

    int n; cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i+=2){
        int ans = judge(i);
        if (ans == 8) cnt++;
    }
    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<int> s(n);
    for (int i=0; i<n; i++) {
        cin >> s.at(i);
    }
    ll sum = 0;
    for (int i=0; i<n; i++) {
        sum += s.at(i);
    }
    if (sum%10 != 0) {
        cout << sum << endl;
    }
    else {
        sort(s.begin(), s.end());
        for (int i=0; i<n; i++) {
            if (s.at(i)%10 != 0) {
                cout << sum - s.at(i) << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int n;
  cin>>n;
  int N=n;
  string ans="No";
  int sum=0;
  while(N>0){
    sum+=N%10;
    N/=10;
    }
  if(n%sum==0)
    ans="Yes";
  cout<<ans;
  }


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

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buf = new byte[1024];
    private int p = 0;
    private int len = 0;
    private boolean hasNextByte() {
        if (p >= len) {
            p = 0;
            try {
                len = in.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return len >= 1;
    }
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buf[p])) p++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        while (hasNextByte() && isPrintableChar(buf[p])) {
            sb.appendCodePoint(buf[p++]);
        }
        return sb.toString();
    }
}

public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        Integer[][] a = new Integer[62][n + 1];
        int t = 1;
        for (int i = 1; i <= n; i++) a[0][i] = Integer.parseInt(sc.next());
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + 1][j] = a[i][a[i][j]];
            }
            if ((k >> i & 1) == 1) t = a[i][t];
        }
        out.println(t);
        out.flush();
    }
}

Measured memory_bytes: 104536
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(p,n);

  sortall(p);

  p[n-1] /= 2;

  prt(f_sum(p));
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define INF 1<<25

using namespace std;

int n,sum,out;

int main()
{
	while( cin >> n, !cin.eof())
	{
		out = 0;
		
		FOR(a,0,10)
			FOR(b,0,10)
				FOR(c,0,10)
					FOR(d,0,10)
					{
						if( n == a+b+c+d )
						{
							out++;
						}
					}
		
		
		cout << out << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 100100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n+1);
  ll cnt[111111]={};
  ll dist;
  for(int i=0;i<n+1;i++){
    ll a;cin>>a;
    if(cnt[a])
      dist=n-(i+1-cnt[a]);
    cnt[a]=i+1;
  }
  
  //  cout<<dist<<endl;
  for(int i=0;i<n+1;i++){
    cout<<(combination(n+1,i+1)-combination(dist,i)+MOD)%MOD<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 3712
def power(x, n):
    y = 1
    while n > 0:
        if n % 2 == 0:
            x = (x * x) % (10 ** 9 + 7)
            n = n // 2
        else:
            y = (y * x) % (10 ** 9 + 7)
            n = n - 1
    return y


MOD = 10 ** 9 + 7

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

fact = [1] * (n + 2)
inv = [1] * (n + 3)

for i in range(1, n + 2):
    fact[i] = (i * fact[i - 1]) % MOD
    inv[i] = power(fact[i], MOD - 2) % MOD


def nCm(n, m):
    global fact
    global inv
    return fact[n] * inv[m] % MOD * inv[n - m] % MOD


saw = [-1] * n
left = 0
right = 0
for i in range(n):
    if saw[a[i] - 1] == -1:
        saw[a[i] - 1] = i
    else:
        left, right = saw[a[i] - 1], n - i
        break

for i in range(1, n + 2):
    if i == 1:
        print(n)
    elif left + right >= i - 1:
        print((nCm(n + 1, i) - nCm(left + right, i - 1)) % MOD)
    else:
        print(nCm(n + 1, i))


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

void solve(int H, int W) {
  vector<string> table;
  set<pair<int, int>> prevs;
  string temp;
  rep(i, H){
    cin >> temp;
    table.push_back(temp);
  }
  auto x = 0;
  auto y = 0;
  while(table[y][x] != '.') {
    if (prevs.count(make_pair(x, y))) {
      cout << "LOOP" <<endl;
      return;
    } else {
      prevs.insert(make_pair(x, y));
    }
    if (table[y][x] == '>') {
      ++x;
    } else if (table[y][x] == 'v') {
      ++y;
    } else if (table[y][x] == '^') {
      --y;
    } else if (table[y][x] == '<') {
      --x;
    }
  }
  cout << x << " " << y << endl;
  return;
}

int main() {
  int H, W;
  while(true) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    } else {
      solve(H, W);
    }
  }

}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

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

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    set<ii> seen;
    int rez = 0;
    ll ta,tb,tc;
    while(!seen.count(make_pair(a,b))) {
        if((a&1) || (b&1) || (c&1))
        {
            cout<<rez;
            return 0;
        }
        seen.insert(make_pair(a,b));
        ta = (b + c)/2;
        tb = (a + c)/2;
        tc = (b + a)/2;
        a = ta, b = tb, c = tc;
        rez++;
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
M=10**9+7
H=Hash.new{_1[_2]=0,0}
$<.drop(o=1).map{a,b=_1.split.map &:to_r
b==0?a==0?o-=1:H[b][1]+=1:a*b<0?H[-b/a][1]+=1:H[a/b][0]+=1}
p (H.inject(1){|s,v|v[t=-1].map{t+=2.pow _1,M}
s*t%M}-o)%M

Measured memory_bytes: 74620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n ;
    cin >> n ;
    pair<int,int>arr[n+5]{};
    for(int i = 0 ; i < n ; i++){
        cin >> arr[i].first >> arr[i].second;
    }
    bool tr = false;
    for(int i = 0; i < n-2 ; i++){
        int ans = 0 ;
        for(int j = i ; j < i+3 ; j++){
            if(arr[j].first == arr[j].second)
                ans++;
        }
        if(ans == 3){
            tr = true;
            break;
        }
    }
    if(tr)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

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

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin>>N>>S;
    int ans = 1;
    rep(i,N-1){
        if(S[i]!=S[i+1])ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 512
import sys

def resolve():
    X = int(input())
    cands = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000]
    for i in range(len(cands)):
        if cands[i] > X:
            print(cands[i-1])
            return
    print(cands[-1])

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>

using namespace std;

const ll N = 1e5+5;
const ll MOD = 1e9+7;
ll dp[N][5];
// 0 for r
// 1 for p
// 2 for s

ll ii(char x){
	if(x == 'r')return 0;
	if(x=='p') return 1;
	return 2;
}

int main()
{

	ll n,k;
	cin>>n>>k;
	ll r,s,p;
	cin>>r>>s>>p;

	string x;
	cin>>x;
	char arr[n+1];
	for(int i =1;i<=n;i++)arr[i] = x[i-1];
	for(int i =1;i<=k;i++){
		dp[i][0] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		dp[i][1] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		dp[i][2] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		if(arr[i] == 's')
			dp[i][0] += r;
		if(arr[i] == 'p')
			dp[i][2] += s;
		if(arr[i] == 'r')
			dp[i][1] += p;
	}


	for(int i =k+1;i<=n;i++){
		if(arr[i] == arr[i-k])
		{
			if(arr[i] == 's')
				dp[i][0] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
			if(arr[i]=='p')
				dp[i][2] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
			if(arr[i]=='r')
				dp[i][1] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
			arr[i]='@';
		}
		else{
			dp[i][0] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		dp[i][1] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		dp[i][2] = max({dp[i-1][1],dp[i-1][0],dp[i-1][2]});
		if(arr[i] == 's')
			dp[i][0] += r;
		if(arr[i] == 'p')
			dp[i][2] += s;
		if(arr[i] == 'r')
			dp[i][1] += p;
		}
	}

	cout << max({dp[n][0],dp[n][1],dp[n][2]})<<"\n";
	
	return 0;
}

Measured memory_bytes: 4480
n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]
cntList = []
for i in range(n):
    cnt = 0
    for j in range(i + 1):
        cnt += a[0][j]

    for k in range(i, n):
        cnt += a[1][k]

    cntList.append(cnt)

print(max(cntList))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public Long[] nextLongArray(int n) {
      Long[] a = new Long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    Long[] h = sc.nextLongArray(n);
    Arrays.sort(h, Collections.reverseOrder());
    long sum = 0;
    for (int i = k; i < n; i++) {
      sum += h[i];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 61992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, L;
	cin >> N >> L;
	int a[N];
	for(int i = 0; i < N; i++) cin >> a[i];

	int t = -1;
	for(int i = 0; i < N - 1; i++)
		if(a[i] + a[i + 1] >= L) {
			t = i;
			break;
		}
	if(t == -1) {
		cout << "Impossible";
		return 0;
	}
	cout << "Possible\n";
	for(int i = 0; i < N - 1; i++) {
		if(i == t) break;
		cout << i + 1 << "\n";
	}
	for(int i = N - 2; i >= 0; i--) {
		if(i == t) break;
		cout << i + 1 << "\n";
	}
	cout << t + 1 << "\n";
	return 0;
}

Measured memory_bytes: 4028
//RMQ and RAQ
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_H
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

ll *min_data,*max_data,*add_data;
int N = 1;

void init(ll first_N){
	while(N < first_N)N *= 2;
}

void add(int left,int right,ll value,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right) return;
	else if(left <= node_left && right >= node_right){
		add_data[node_id] += value;
		while(node_id != 0){
			node_id = (node_id-1)/2;
			min_data[node_id] = min(min_data[2*node_id+1]+add_data[2*node_id+1],min_data[2*node_id+2]+add_data[2*node_id+2]);
			max_data[node_id] = max(max_data[2*node_id+1]+add_data[2*node_id+1],max_data[2*node_id+2]+add_data[2*node_id+2]);
		}
	}else{
		add(left,right,value,2*node_id+1,node_left,(node_left+node_right)/2);
		add(left,right,value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}
//getMin(s,t)で[s,t]に対する最小
ll getMin(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return BIG_NUM;
	else if(left <= node_left && right >= node_right) return min_data[node_id]+add_data[node_id];
	else{
		ll  left_min  = getMin(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_min = getMin(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return min(left_min,right_min)+add_data[node_id];
	}
}

//getMin(s,t)で[s,t]に対する最大
ll getMax(int left,int right,int node_id,int node_left,int node_right){
	if(right < node_left || left > node_right)return -BIG_NUM;
	else if(left <= node_left && right >= node_right) return max_data[node_id]+add_data[node_id];
	else{
		ll  left_max  = getMax(left,right,2*node_id+1,node_left,(node_left+node_right)/2);
		ll  right_max = getMax(left,right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left_max,right_max)+add_data[node_id];
	}
}

//問題は0-indexedで与えられている
int main(){
	int n,q; cin >> n >> q;
	init(n);

	min_data = new ll[2*N-1];
	max_data = new ll[2*N-1];
	add_data = new ll[2*N-1];

	for(ll i = 0; i <= 2*N-2; i++){
		min_data[i] = 0;
		max_data[i] = 0;
		add_data[i] = 0;
	}

	int command,left,right;
	ll value;
	for(int loop = 0; loop < q; loop++){
		cin >> command;
		if(command == 0){
			cin >> left >> right >> value;
			add(left,right,value,0,0,N-1);
		}else{
			cin >> left >> right;
			cout << getMin(left,right,0,0,N-1) << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
int n,a[400001],b[400001],ta[400001],tb[400001],l=1,r=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),ta[a[i]]++;
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),tb[b[i]]++;
	for(int i=1;i<=n;i++)if(ta[i]+tb[i]>n)puts("No"),exit(0);
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=tb[i];j++)
		{
			while(b[l])++l;
			while(a[r]<=a[l]&&r<=n)++r;
			while(b[r])++r;
			if(a[l]!=i)b[l++]=i;
			else b[r++]=i;
		}
	}
	l=1;
	for(int i=n+1;b[i];i++)
	{
		while(b[l])++l;
		if(a[l]!=b[i])a[l]=b[i];
		else 
		{
			while(a[r=(rand()%n+1)]==b[i]||b[r]==a[l]);
			b[l]=b[r],b[r]=b[i];
		}
	}
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d ",b[i]);
	return 0;
}

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

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N,K,M,L;
v_ll A,A2,B,B1,B2;
int main(){
  cin >> N>>K;
  ll range = 60000;
  A.assign(range,0);
  A2.assign(range*2,0);
  B.assign(range*2,0);
  B1.assign(range*2,0);
  B2.assign(range*2,0);
  MOD=1000000007;
  ll M=0,L=0;
  for (ll i=1;i*i<=N;i++){
    M=i;
    A[i]=N/i;
  }
  if (M*M!=N){
    L=2*M;
  }else{
    L=2*M-1;
  }
  for (ll i=0;i<=M;i++){
    A2[i]=i;
  }
  for (ll i=L;i>=M+1;i--){
    ll j=L+1-i;
    A2[i]=N/j;
  }
  /*
  for (ll i=1;i<=M;i++){
    B[i]=1;
  }
  for (ll i=M+2;i<=L;i++){
  //B[M+1]=(N/M)-M;
  for (ll i=M+2;i<=L;i++){
    ll j=L+1-i;
    B[i]=N/j-N/(j+1);
  }
  */
  for (ll i=1;i<=L;i++){
    B[i]=A2[i]-A2[i-1];
  }
  //TEST=true;
  //show(B);
  for (ll i=L;i>=1;i--){
    B1[i]=B[i];
  }
  for (ll k=2;k<=K;k++){
    ll sum=0;
    for (ll i=L;i>=1;i--){
      sum+=B1[L+1-i];
      sum%=MOD;
      B2[i]=sum*B[i];
      B2[i]%=MOD;
    }
    for (ll i=L;i>=1;i--){
      B1[i]=B2[i];
    }
    //show(B1);
  }
  ll ans=0;
  for (ll i=L;i>=1;i--){
    ans+=B1[i];
    ans%=MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4480
fun main(args: Array<String>) {
    val tmpLine = readLine()
    val tmps = tmpLine!!.split("\\s+".toRegex())
    val a = tmps[0].toInt()
    val b = tmps[1].toInt()
    val result = experiment(a, b)

    println("${result}")
}

fun experiment(a : Int, b: Int) : Int {
    return a * b
}

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

int a[200000],sum[200000];

struct node{
	node*nx[2];
	int sum;
}pool[4000000];
node*root=&pool[0];
int pointer=1;

void add(int x){
	node*n=root;
	for(int i=20;i>=0;i--){
		int d=x>>i&1;
		if(n->nx[d]==NULL){
			n->nx[d]=&pool[pointer++];
		}
		n=n->nx[d];
		n->sum++;
	}
}

int query(int x,int y){
	node*n=root;
	int res=0;
	for(int i=20;i>=0;i--){
		if(y>>i&1){
			int d=!(x>>i&1);
			if(n->nx[d]==NULL)return res;
			n=n->nx[d];
		}
		else{
			int d=!(x>>i&1);
			if(n->nx[d]!=NULL)res+=n->nx[d]->sum;
			if(n->nx[!d]==NULL)return res;
			n=n->nx[!d];
		}
	}
	res+=n->sum;
	return res;
}

int main(){
	int n;ll K;cin>>n>>K;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	sum[0]=0;
	rep(i,n)sum[i+1]=sum[i]^a[i];
	int ok=0,ng=(1<<20)+1;
	while(ng-ok>1){
		int t=(ok+ng)/2;
		rep(i,pointer)pool[i]={{NULL,NULL},0};
		pointer=1;
		ll cnt=0;
		for(int i=n;i>=0;i--){
			cnt+=query(sum[i],t);
			add(sum[i]);
		}
		if(cnt>=K)ok=t;
		else ng=t;
	}
	cout<<ok<<endl;
}


Measured memory_bytes: 14604
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    int N;
    double ans=0, x;
    string s;
    cin >> N;
    for(int i = 1; i<=N; ++i){
        x = 0, s = "";
        cin >> x >> s;
        if(s == "BTC"){
            x *= 380000.;
        }
        ans += x;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;
 
public class Main{
    public static void main(String[] args){
 
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
      
        
        System.out.println(c+" "+ a+" "+b+" ");
        
      
      
      
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}

ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 200100;
int dp[N];
int pre[N];
int a[N],b[N];

const int M = 1e9 + 7;

int inv(int x){
  return exp(x,M-2,M);
}

pii opo(pii x){
  swap(x.ff,x.ss);
  x.ff*=-1;
  if(x.ff<0){
    x.ff*=-1;
    x.ss*=-1;
  }
  return x;
}
int pot[N];
  map<pii,int> mp;

int valor(pii x){
  return pot[mp[x]];
}

int grupo(pii x){
  int a1 = pot[mp[x]] + pot[mp[opo(x)]] - 1;
  return a1;
}

int32_t main(){
  fastio;
  dp[0] = 1;
  pot[0] = 1;
  for(int i=1;i<N;i++){
    pot[i] = (pot[i-1]*2)%M;
  }
  int n;
  cin>>n;
  pre[0] = 0;
  int acu = 1;
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
    if(a[i]==0 and b[i]==0){
      dp[i] = 1;
      pre[i] = (pre[i-1] + dp[i])%M;
      continue;
    }  
    ll g = gcd(a[i],b[i]);

    a[i]/=g;b[i]/=g;
    if(a[i]<0)b[i]*=-1,a[i]*=-1;


    pii now = pii(a[i],b[i]);
    pii other = opo(now);

    
    int cur = mod(acu*inv(grupo(now)),M);
    int salva = cur;

    cur = mod(cur*valor(now),M);
    dp[i] = cur;
   // cout << i<<" "<<now.ff<<" "<<now.ss<<" "<<grupo(now)<<" "<<valor(now) << endl;
 //  cout << i <<" "<<cur << " "<<grupo(now)<<" "<<valor(now)<<" "<<dp[i]<<endl;

    pre[i] = (pre[i-1] + dp[i])%M;
    mp[now]++;

    acu = mod(salva*grupo(now),M);
  }



  cout << mod(pre[n],M) << endl;


  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 36412
#include <stdio.h>

int main(void){
    int N,card[100],i,temp,frag=1,sum_alice=0,sum_bob=0,ans=0;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&card[i]);
    }
    
    while(frag==1){
        frag = 0;
        for(i=0;i<N-1;i++){
            if(card[i]<card[i+1]){
                temp = card[i];
                card[i] = card[i+1];
                card[i+1] = temp;
                frag = 1;
            }
        }
    }
    
    for(i=0;i<N;i++){
        if(i%2==0){
            sum_alice += card[i];
        }else{
            sum_bob += card[i];
        }
    }
    ans = sum_alice - sum_bob;
    printf("%d\n",ans);
    return 0;
}

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

const ll INF = 1LL << 60;

ll N;
vector<ll> a, b, c;
int main() {
    cin >> N;
    a.resize(N);
    b.resize(N);
    c.resize(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    // 中心座標決め打ち
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            set<ll> set_h;
            bool lim = false;
            // h が 1以上のケース
            for (int k = 0; k < N; k++) {
                if (c[k] <= 0) continue;
                ll tmp_h = c[k] + abs(a[k] - i) + abs(b[k] - j);
                if (tmp_h < 1) {
                    lim = true;
                }
                set_h.insert(tmp_h);
            }
            if (lim) continue;
            if (set_h.size() != 1) continue;

            ll h = *set_h.begin();
            ll cont = false;
            // h が 0のケース
            for (int k = 0; k < N; k++) {
                if (c[k] > 0) continue;
                ll tmp_h = max(h - abs(a[k] - i) - abs(b[k] - j), 0LL); 
                if (tmp_h != 0) {
                    cont = true;
                }
            }
            if (cont) continue;
            // if (i == 2 && j == 2) {
            //     cout << lim << endl;
            //     cout << set_h.size() << " " << *set_h.begin() << endl;
            // }
            // cout << *set_h.begin() << endl;
             cout << i << " " << j << " " << *set_h.begin() << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main() {
  long long N, Q;
  cin >> N >> Q;
  long long S[N], T[N], X[N];
  for (long long i = 0; i < N; i++){
    cin >> S[i] >> T[i] >> X[i];
  }
  long long D[Q];
  for (int i = 0; i < Q; i++) cin >> D[i];
  
  pair<long long, long long> a[2 * N];
  for (long long i = 0; i < N; i++){
    a[i].first = S[i] - X[i];
   	a[i].second = X[i];
    a[N + i].first = T[i] - X[i];
   	a[N + i].second = 0 - X[i];
  }
  
  sort(a, a + 2 * N);
  set<long long> Set;
  long long sum_a = 0;
  long long res[Q];
  for (long long i = 0; i < Q; i++){
    while (a[sum_a].first <= D[i]){
      if (sum_a == N * 2) break;
      if (a[sum_a].second > 0) Set.insert(a[sum_a].second);
      if (a[sum_a].second < 0) Set.erase(0 - a[sum_a].second);
      sum_a++;
    }
    if (Set.empty()) res[i] = -1;
    else {
      auto itr = Set.begin();
      res[i] = (*itr);
    }
  }
  
  for (int i = 0; i < Q; i++) cout << res[i] << endl;
}

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

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	
	int ans = 0;
	int count = 0;
	for (int i = 1; i < n; i++) {
		if (h[i-1] >= h[i]) {
			count++;
		} else {
			ans = max(ans, count);
			count = 0;
		}
	}
	ans = max(ans, count);
	count = 0;
	
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int n;scanf("%d",&n);
    vector<double> dp(n+1);dp[0]=1;
    for(int coin=0;coin<n;coin++){
        double p_heads;
        scanf("%lf",&p_heads);
        for(int i=coin+1;i>=0;i--){
            dp[i] = (i==0 ? 0: dp[i-1]*p_heads)+dp[i]*(1-p_heads);
        }
    }
    double ans=0;
    for(int i=0;i<=n;i++){
        int tails=n-i;
        if(i>tails)ans+=dp[i];
    }
    printf("%.10lf",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int r;
    cin >>r;

    if(r<1200){
        cout <<"ABC" <<endl;
    }
    else if(r<2800&&r>=1200){
        cout <<"ARC" <<endl;
    }
    else {
        cout <<"AGC" <<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

int len,ans;
string s,t;

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> s >> t;
    len = s.length();
    rep(i,1,len) if(s[i-1] != t[i-1]) ++ans;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
using namespace std;
struct hehe{
	int c,t;
}a[101];
int main()
{
	int n,T;
	cin>>n>>T;
	int mi=0;
	a[0].c=987654321;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].c>>a[i].t;
		if(a[i].t<=T&&a[i].c<=a[mi].c) mi=i;
	}
	if(a[mi].c==987654321)
	{
		cout<<"TLE";
		return 0;
	}
	cout<<a[mi].c;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		for (int i = 0; i < Math.max(a, b); i++) {
			System.out.print(Math.min(a, b));
		}
		System.out.println();
	}
}


Measured memory_bytes: 21844
import numpy as np

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for _ in range(N)])
ans = 0
Dist = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        Dist = np.sum((X[i] - X[j]) ** 2)
        for k in range(1, Dist // 2 + 2):
            if k ** 2 == Dist:
                ans += 1
print(ans)

Measured memory_bytes: 21524
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b, x) = (v[0], v[1], v[2]);
    println!("{}", (b + x) / x - (a - 1 + x) / x);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String n = br.readLine();
            if (n.charAt(0) == n.charAt(2)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


Measured memory_bytes: 22868
#include <stdio.h>
#include<string.h>

int main(int argc, const char * argv[]) {
    int n, i=0, p1=0, p2=0;
    char s1[10], s2[10];
    
    scanf("%d", &n);
    
    while(i<n){
        scanf("%s %s", s1, s2);
        if ( strcmp(s1, s2) == 0 ) {
            p1+=1;
            p2+=1;
        }
        else if ( strcmp(s1, s2) > 0 ) {
            p1+=3;
        }
        else if ( strcmp(s1, s2) < 0 ){
            p2+=3;
        }
        i++;
    }
    printf("%d %d\n", p1, p2);
    
    return 0;
}


Measured memory_bytes: 2048
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

// A[i] : S と S[i:] の先頭が何文字共通しているか
long long int A[1000000];

// O(|S|)
void Z_algorithm(vector<long long int> S){
	A[0] = S.size();
	int i = 1, j = 0;
	while (i < S.size()) {
		while (i + j < S.size() && S[j] == S[i + j]){
			j += 1;
		}
		A[i] = j;
		if (j == 0) {
			++i;
			continue;
		}
		int k = 1;
		while (i + k < S.size() && k + A[k] < j){
			A[i + k] = A[k];
			k += 1;
		}
		i += k; j -= k;
	}
}

long long int a[210000], b[210000];
vector<long long int> v;

int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	a[N] = a[0];
	for(int i = 0; i < N; i++){
		cin >> b[i];
	}
	b[N] = b[0];
	for(int i = 0; i < N; i++){
		v.push_back(b[i] ^ b[i + 1]);
	}
	v.push_back(-1);
	for(int i = 0; i < N; i++){
		v.push_back(a[i] ^ a[i + 1]);
	}
	for(int i = 0; i < N; i++){
		v.push_back(a[i] ^ a[i + 1]);
	}
	Z_algorithm(v);
	for(int i = N + 1; i <= 2 * N; i++){
		if(A[i] >= N){
			int pos = i - (N + 1);
			cout << pos << " " << (b[0] ^ a[pos]) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	int n,count=0,tmp,cheng;
	cin >> n;
	int t[n];
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}
	int m;
	cin >> m;
	int p[m],x[m];
	for(int j = 0; j < m; j++){
		cin >> p[j] >> x[j];
	}

	for(int l = 0; l < m; l++){
		tmp = t[p[l]-1];
		t[p[l]-1] = x[l];
		for(int k = 0; k < n; k++){
			count += t[k];
		}
		cout << count << endl;
		count = 0;
		t[p[l]-1] = tmp;
	}

	return 0;
}

Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)
a = (1..n).map { gets.chomp }.sort
head = ""
tail = ""
deleted = {}
(0..n-1).each do |i|
    next if deleted[i]
    s = a[i]
    r = s.reverse
    j = nil
    (i+1..n-1).each do |k|
        next if deleted[k]
        if a[k] == r
            j = k
            break
        end
    end
    next if !j
    deleted[i] = 1
    head += s
    deleted[j] = 1
    tail = s.reverse + tail
end
c = nil
a.each.with_index do |s, i|
    next if deleted[i]
    next unless s == s.reverse
    c = s if !c || s < c
end
c ||= ""
puts head + c + tail



Measured memory_bytes: 7200
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define eb emplace_back
int main()
{
   //freopen("input.txt","r",stdin);
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - probility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin)
    {
        double p_heads;
        scanf("%lf", &p_heads);
        for(int i = coin + 1; i >= 0; --i)
        {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
        //for(int i=0;i<=n;i++)
          //  cout<<dp[i]<<"\t";cout<<"\n";
    }
    double answer = 0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
    //return 0;
}


Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

#include<bitset>

int n, k;
char buf[(1<<20)+10];
int dp[1<<21][21];

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> k;
  for(int i = 0; i <= n; i++) {
    cin >> buf;
    for(int j = 0; j < (1 << i); j++) {
      if(buf[j] == '1') {
        int x = (1 << i) | j;
        dp[x][0] = 1;
      }
    }
  }

  for(int L = n; L > 0; --L) {
    for(int i = 0; i < (1 << L); i++) {
      int x = (1 << L) | i;
      int next0[21], next1[21];
      // dump(bitset<8>());
      // dump(bitset<8>(x));
      next0[L] = next1[L] = L;
      for(int h = L - 1; h >= 0; h--) {
        int f = (i >> (L - h - 1)) & 1;
        next0[h] = f == 0 ? h : next0[h+1];
        next1[h] = f == 1 ? h : next1[h+1];
      }
      for(int h = 0; h < L; h++) {
        int nx = x >> (L - h);
        // dump(h);
        // dump(dp[x][h]);
        // dump(bitset<8>(nx));
        // dump(h, next0[h+1], next1[h+1]);
        dp[nx][h] += dp[x][h];
        if(next0[h] < L) {
          int j0 = (i >> (L - h) << (L - next0[h])) | (i & ((1 << (L - next0[h])) - 1));
          int x0 = (1 << (L - next0[h] + h)) | j0;
          dp[x0][h+1] += dp[x][h];
        }
        if(next1[h] < L) {
          int j0 = (i >> (L - h) << (L - next1[h])) | (i & ((1 << (L - next1[h])) - 1));
          int x0 = (1 << (L - next1[h] + h)) | j0;
          dp[x0][h+1] += dp[x][h];
        }
      }
    }
  }
  for(int L = n; L >= 0; --L) {
    for(int i = 0; i < (1 << L); i++) {
      int x = (1 << L) | i;
      if(dp[x][L] >= k) {
        for(int h = L - 1; h >= 0; h--) {
          cout << ((i >> h) & 1);
        }
        cout << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 173312
sa = gets.chomp.split(//)

def add(s, sa)
  if sa.size == 0
    return s.split.map(&:to_i).sum
  end
  sa_new = sa.clone
  s1 = sa_new.shift
  add(s + s1, sa_new) + add(s + ' ' + s1, sa_new)
end

s0 = sa.shift
puts add(s0, sa)


Measured memory_bytes: 14224
#include<cstdio>

int n,m,a[101],sum,i,p,x;

int main(){
    scanf("%d",&n);
    for(i=1;i<=n;++i){
        scanf("%d",a+i);
        sum+=a[i];
    }
    scanf("%d",&m);
    while(m--){
        scanf("%d%d",&p,&x);
        printf("%d\n",sum-a[p]+x);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X, Y, Z, K;
  cin>>X>>Y>>Z>>K;
  vector<ll> A(X), B(Y), C(Z);
  for(int i=0;i<X;++i) cin>>A[i];
  for(int i=0;i<Y;++i) cin>>B[i];
  for(int i=0;i<Z;++i) cin>>C[i];
  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  
  priority_queue<tuple<ll, int, int, int> > que;
  que.push(make_tuple(A[0]+B[0]+C[0], 0, 0, 0));
  tuple<ll, int, int, int> state;
  ll score;
  int aindex, bindex, cindex;
  ll ans[K];
  map<tuple<int, int, int>, int> amap;
  for(int i=0;i<K;++i) {
    state = que.top();que.pop();
    score = get<0>(state);
    ans[i] = score;
    aindex = get<1>(state);
    bindex = get<2>(state);
    cindex = get<3>(state);
    if(aindex+1<X && amap[make_tuple(aindex+1, bindex, cindex)]==0) {
      que.push(make_tuple(score-A[aindex]+A[aindex+1], aindex+1, bindex, cindex));
      amap[make_tuple(aindex+1, bindex, cindex)]++;
    }
    if(bindex+1<Y && amap[make_tuple(aindex, bindex+1, cindex)]==0) {
      que.push(make_tuple(score-B[bindex]+B[bindex+1], aindex, bindex+1, cindex));
      amap[make_tuple(aindex, bindex+1, cindex)]++;
    }
    if(cindex+1<Z && amap[make_tuple(aindex, bindex, cindex+1)]==0) {
      que.push(make_tuple(score-C[cindex]+C[cindex+1], aindex, bindex, cindex+1));
      amap[make_tuple(aindex, bindex, cindex+1)]++;
    }
  }
  for(int i=0;i<K;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 4160
lst_1 = (input().split())

N = int(lst_1[0])
M = int(lst_1[1])
C = int(lst_1[2])

lst_A = []
lst_B = []
total = 0
ans = 0

lst_B = (input().split())

for n in range(0, N):
    lst_A.append(input().split())


for n in range(0, N):

    for m in range(0, M):

        a = int(lst_A[n][m])
        b = int(lst_B[m])
        total += (a * b)

    if total + C > 0:
        ans += 1

    total = 0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n+k==0) break;
		vi a(n);
		rep(i,0,n) cin>>a[i];
		int sum=0;
		rep(i,0,k) sum+=a[i];
		int MAX=sum;
		rep(i,k,n){
			sum=sum+a[i]-a[i-k];
			MAX=max(MAX,sum);
		}
		o(MAX);
	}
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int result = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        while (a%2 == 0) {
            a /= 2;
            result++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3620