akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint a(n),b(n),c(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    REP(i,n-1) cin >> c[i];
    int ans = 0;
    for(int i=0;i<n-1;i++){
        ans+=b[i];
        if(a[i+1]==a[i]+1){
            ans+=c[a[i]-1];
        }
    }
    ans+=b[n-1];
    cout << ans << endl;

    return 0;
}

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

#define each(i, c) for (auto& i : c)

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9+7;

int main() {
  ll a, b;
  cin >> a >> b;

  ll aa = 0;
  for (ll i = 0; i < b; ++i) {
    aa += (a * ll(pow(10, i)));
  }
  ll bb = 0;
  for (ll i = 0; i < a; ++i) {
    bb += (b * ll(pow(10, i)));
  }

  vector<string> s(2);
  s[0] = to_string(aa);
  s[1] = to_string(bb);
  sort(s.begin(), s.end());

  cout << s[0] << endl;

  return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]

ans=[]
for i in range(n):
    time=0
    for j in range(i,n-1):
        c,s,f=csf[j][0],csf[j][1],csf[j][2]
        if time>s:
            time=s -(-(time-s)//f)*f
        else:
            time=s
        time+=c

        #print(i,j,c,s,f,time)
    ans.append(time)
for i in ans:
    print(i)


Measured memory_bytes: 39664
// Vicfred
// https://atcoder.jp/contests/abc159/tasks/abc159_c
// math
import std.stdio;
import std.string;
import std.conv;

void main() {
    real L = readln.chomp.to!real;
    real ans = (L/3.0)^^3;
    writefln("%.9f", ans);
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define mp make_pair
vector<pair<int,int> >nei[100005];
int col[100005];
void dfs(int v,int dis,int pa){
	if(dis&1) col[v]=0; else col[v]=1;
	for(int i=0;i<nei[v].size();i++){
		int u=nei[v][i].first,w=nei[v][i].second;
		if(u==pa) continue;
		dfs(u,dis+w,v);
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--;v--;w&=1;
		nei[u].push_back(mp(v,w));
		nei[v].push_back(mp(u,w));
	}
	dfs(0,0,-1);
	for(int i=0;i<n;i++){
		cout<<col[i]<<endl;
	}
}

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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define all(v) begin(v),end(v)
#define allr(v) v.rbegin(),v.rend()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define cases int t; cin >> t; while(t--)
#define fast_cin() ios_base::sync_with_stdio(0) 

const int mod = 1e9+7;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main()
{
	fast_cin();
	int N,M;
	cin >> N >> M;
	int A[N+1][M+1];
	for(int i=1;i<=N;i++)
		for(int j=1;j<=M;j++)
			cin >> A[i][j];

	int minans = 1e8;
	bool is[M+1];
	for(int i=1;i<=M;i++)
		is[i] = true;
	for(int i=1;i<=M;i++)
	{
		int ct[M+1];
		make0(ct);
		for(int j=1;j<=N;j++)
		{
			for(int k=1;k<=M;k++)
			{
				if(is[A[j][k]] == true)
				{
					ct[A[j][k]] ++;
					break;
				}
			}
		}
		int max_idx = 0;
		int mx = -1;
		for(int j=1;j<=M;j++)
		{
			// cerr << ct[j] << ' ';
			if(mx < ct[j])
			{
				mx = ct[j];
				max_idx = j;
			}
		}
		// cerr << endl;	
		is[max_idx] = false;
		minans = min(minans, *max_element(ct+1, ct+1+M));
	}
	cout << minans << endl;


	return 0;
}

Measured memory_bytes: 640
from collections import Counter


MOD = 10 ** 9 + 7


def isOK(last3, s):
    for i in range(len(last3 + s)):
        t = list(last3 + s)
        if i >= 1:
            t[i], t[i - 1] = t[i - 1], t[i]
        if ''.join(t).count('AGC'):
            return False
    return True


S = 'ACGT'
N = int(input())
dp = [None] * (N + 1)

dp[1] = Counter()
for s1 in S:
    dp[1][s1] += 1

dp[2] = Counter()
for s1 in S:
    for s2 in S:
        dp[2][s1 + s2] += dp[1][s1]

dp[3] = Counter()
for s1 in S:
    for s2 in S:
        for s3 in S:
            if isOK(s1 + s2, s3):
                dp[3][s1 + s2 + s3] += dp[2][s1 + s2]

for i in range(4, N + 1):
    dp[i] = Counter()
    for s1 in S:
        for s2 in S:
            for s3 in S:
                for s4 in S:
                    if isOK(s1 + s2 + s3, s4):
                        dp[i][s2 + s3 + s4] += dp[i - 1][s1 + s2 + s3]
                        dp[i][s2 + s3 + s4] %= MOD

print(sum(dp[N].values()) % MOD)


Measured memory_bytes: 44888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;

int N;
vector<vector<P>> g;
vector<int> ans;
void dfs(int p,int v){
    for(P x:g[v]){
        int u=x.first,w=x.second;
        if(u==p)continue;
        if(w%2==0){ans[u]=ans[v];}
        else{ans[u]=ans[v]*(-1);}
        dfs(v,u);
    }
    return;
}

int main() {
    cin>>N;
    g.resize(N);
    ans.resize(N);
    rep(i,N-1){
        int u,v,w;
        cin>>u>>v>>w;
        --u;--v;
        g[u].pb({v,w});
        g[v].pb({u,w});
    }
    ans[0]=1;
    dfs(-1,0);
    rep(i,N){
        if(ans[i]==-1){
            ans[i]=0;
        }
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 8192
n = int(input())
a = [i for i in range(1,10)]
b = 0
for j in range(9):
    if n%int(a[j]) == 0 and 1 <= n//int(a[j]) <= 9:
        b += 1
if b == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = false;

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

  int n, m;
  cin >> n >> m;
  vector<int> pathlen(n, -1);
  vector<vector<int>> aisle(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    aisle[a].emplace_back(b);
    aisle[b].emplace_back(a);
  }

  queue<int> que;
  que.push(0);
  pathlen[0] = 0;
  while (!que.empty()) {
    int q = que.front();
    que.pop();
    for (int nx: aisle[q]) {
      if (pathlen[nx] == -1) {
        pathlen[nx] = q;
        que.push(nx);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (pathlen[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << pathlen[i] + 1 << endl;
  }
}


Measured memory_bytes: 10272
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;


#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

int n , m ;

bool chk ( int mid ) {
	int needS = mid - n ;
	smax ( needS , 0LL ) ;
	needS = abs ( needS ) ;
	int M = m ;
	M -= ( needS * 2 ) ;
	return M / 2 >= mid ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m ;
	int lo = -1 , hi = 2e18 ;
	while ( hi - lo > 1 ) {
		int mid = ( hi + lo ) >> 1 ;
		if ( chk ( mid ) )
			lo = mid ;
		else
			hi = mid ; 
	}
	cout << lo << '\n' ; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n+5] = {0};
	for(int i = 0; i < n-1; i++){
		int x;
		cin >> x;
		a[x]++;
	}
	for(int i = 1; i <= n; i++){
		cout << a[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >>b;
  if( a == 1){
    a  =14;
  }
  if( b == 1){
    b = 14;
  }
  if(a == b){
    cout << "Draw";
  }
  else if (a>b){
    cout << "Alice";
  }
  else {
    cout << "Bob";
  }
}

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

double a;

int main() {
  while (1) {
    if (scanf("%lf", &a) != 1) return 0;
  
    double ans = a;
    for (int i=0; i<9; i++) {
      if (i%2 == 0) a *= 2;
      else a /= 3;
      ans += a;
    }
    printf("%f\n", ans);
  }
}

Measured memory_bytes: 2644
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;


int main(){
  vector<string> table(305);
  int n;cin >> n;
  rep(i,n) cin >> table[i];
  int ans = 0;
  rep(t,n){
    if(t > 0){ 
      rep(i,n){
        table[n-i] = table[n-1-i];
      }
      table[0] = table[n];
    }
    bool flag = true;
    rep(i,n)rep(j,n){
      if(table[i][j] != table[j][i]){
        flag = false;
        break;
      }
    }
    if(flag) ans += n;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================


int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A+3);
  cout << (A[0] * A[1]) / 2 << "\n";
  return 0;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int main() {
    int n,q;
    cin >> n >> q;
    vector<ll> a(n,0),sums(100010,0),psums(100010,0);
    for (int i = 0;i < n;++i) {
        cin >> a[i];
        sums[i+1] = sums[i]+a[i];
        psums[i+1] = a[i];
    }
    for (int i = 1;i < n;++i) psums[i+1] += psums[i-1];
    //p_ary(a,0,n,i);
    //p_ary(sums,0,n+1,i);
    //p_ary(psums,0,n+1,i);
    for (int z = 0;z < q;++z) {
        ll x;
        cin >> x;
        int mx = n,mn = 1;
        while (mx-mn > 1) {
            int md = mn+(mx-mn)/2;
            int it = lower_bound(a.begin(),--a.end(),x-a[n-md]+x)-a.begin();
            //cout << n-md-it <<" " << md << endl;
            if (n-md-it+1 >= md) mn = md;
            else mx = md;
        }
        //cout << mn << endl << endl;
        ll ans = sums[n]-sums[n-mn];
        //cout << ans << endl;
        if (mn*2 <= n) ans += psums[n-2*mn];
        cout << ans << endl;
    }
}

Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 110
#define N 30
#define INF 0x3fffffff

int n, m, cn, start, dest, ans;
int len[N][MAX], fax[N][MAX], faxn[N];
int distc[MAX][MAX][N], dist[MAX][MAX];

inline int find_cost(int val, int c){
	if(val == INF) return INF;
	int res = 0, i;
	for(i = 1; i < faxn[c] && val >= len[c][i]; i++)
	    res += fax[c][i] * (len[c][i] - len[c][i - 1]);
	return res + (val - len[c][i - 1]) * fax[c][i];
}

int main(){
	int a, b, c, d;
	while(scanf("%d%d%d%d%d", &n, &m, &cn, &start, &dest) == 5 && (n || m || cn || start || dest)){
		memset(len, 0, sizeof(len));
		
		for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
		for(int c = 1; c <= cn; c++) distc[i][j][c] = INF;
		
		for(int i = 1; i <= n; i++)
		for(int c = 1; c <= cn; c++) distc[i][i][c] = 0;
		
		for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) dist[i][j] = INF;
		
		for(int i = 1; i <= n; i++) dist[i][i] = 0;
		
		for(int i = 1; i <= m; i++){
			scanf("%d%d%d%d", &a, &b, &d, &c);
			if(distc[a][b][c] > d) distc[a][b][c] = distc[b][a][c] = d;
		}
		
		for(int i = 1; i <= cn; i++) scanf("%d", faxn + i);
		for(int i = 1; i <= cn; i++){
		    for(int j = 1; j < faxn[i]; j++) scanf("%d", &len[i][j]);
		    for(int j = 1; j <= faxn[i]; j++) scanf("%d", &fax[i][j]);
		}
		
		for(int c = 1; c <= cn; c++)
		for(int i = 1; i <= n; i++)
		for(int u = 1; u <= n; u++)
		for(int v = u + 1; v <= n; v++) distc[u][v][c] = distc[v][u][c] = min(distc[u][v][c], distc[u][i][c] + distc[i][v][c]);
		
		for(int c = 1; c <= cn; c++)
		for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) dist[i][j] = min(dist[i][j], find_cost(distc[i][j][c], c));
		
		for(int i = 1; i <= n; i++)
		for(int u = 1; u <= n; u++)
		for(int v = 1; v <= n; v++) dist[u][v] = min(dist[u][v], dist[u][i] + dist[i][v]);
		
		if(dist[start][dest] == INF) puts("-1");
		else printf("%d\n", dist[start][dest]);
	}
	return 0;
}

Measured memory_bytes: 2412
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
78786    print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}
#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[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 solve() {
    let n: usize = read();
    let mut vec: Vec<i64> = read_vec();
    let mut res: Vec<i64> = vec![];

    for i in (0..n) {
        for j in (0..(n - i)).rev() {
            if j + 1 == vec[j] as usize {
                res.push((j + 1) as i64);
                vec.remove(j);
                // p!(vec);
                break;
            }
        }
    }
    res.reverse();
    if res.len() != n {
        println!("{:?}", -1);
    } else {
        for i in 0..n {
            println!("{}", res[i]);
        }
    }
    return;
}
fn main() {
    solve()
}


Measured memory_bytes: 2100
#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 <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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 main(){
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    set<char> se;
    for(int i=0; i<N; i++){
        char c;
        cin >> c;
        se.insert(c);
    }
    if(se.size() == 3){
        cout << "Three\n";
    }else{
        cout << "Four\n";
    }
    return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	for (int i = 0; i < 105; i++) {
		if (i * a % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp;
  auto t = readln.chomp;
  int cnt;
  foreach (i; 0..3) {
    if (s[i] == t[i]) {
      cnt++;
    }
  }
  cnt.writeln;
}


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

int main(){
  int N,M; cin>>N>>M;
  vector<bool> stair(N+1,true);
  for(int i=0;i<M;i++){
    int a; cin>>a;
    stair[a]=false;
  }
  vector<long long> dp(N+1,0);
  dp[0]=1;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<=min(N,i+2);j++){
      if(stair[j]){
        dp[j]+=dp[i];
        dp[j]%=1000000007;
      }
    }
  }cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  x = int(input())
  ans = 0
  ans += (x//500) *1000
  x %= 500
  ans += (x//5)*5
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 5716
#include "iostream"
using namespace std;const int N=2e5+5;int64_t a[N],d[N],s[N],n,i;main(){cin>>n;for(;i<n;++i)cin>>a[i],s[i]=(i>1?s[i-2]:0)+a[i];for(i=1;i<n;++i)d[i]=max((i&1?s:d)[i-1],d[i-2]+a[i]);cout<<d[n-1];}

Measured memory_bytes: 8320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int x = in.nextInt(), t = in.nextInt();
			out.println(Math.max(x-t, 0));

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes\n";
    }
    else cout <<"No\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool is_valid(int x, int n) {
  bool f[3] = { false, false, false };
  int t = x;
  while (t != 0) {
    int a = t%10;
    if ( a == 7 ) { f[0] = true; }
    if ( a == 5 ) { f[1] = true; }
    if ( a == 3 ) { f[2] = true; }
    t /= 10;
  }
  if ( x <= n && f[0] && f[1] && f[2]) {
    return true;
  } else {
    return false;
  }
}

int main () {
  int pow3[10] = {1};
  int a[] = {7, 5, 3};
  int n, ans = 0;

  cin >> n;

  for (int i = 1; i <= 9; i++) {
    pow3[i] = pow3[i-1]*3;
  }

  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < pow3[i]; j++){
      int t = 0;
      for (int k = 0; k < i; k++) {
        t *= 10;
        t += a[(j/pow3[k]) % 3];
      }
      if ( is_valid(t, n) ) { ans++; }
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  vector<int> W(N);
  for (int j = 0; j < N; j++)
    W.at(j) = V.at(j);
  
  sort(W.begin(),W.end());
  int count = 0;
  
  for (int k = 0; k < N; k++) {
    if (W.at(k) != V.at(k))
      count++;
  }
  if (count <= 2) 
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
}


Measured memory_bytes: 3580
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int array[] = new int[w];
        for (int i = 0; i < w; i++) array[i] = i+1;
        for (int i = 0; i < n; i++){
            String str = sc.next();
            String ab[] = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            int tmp = array[a];
            array[a] = array[b];
            array[b] = tmp;
        }
        for (int i = 0; i < w; i++){
            System.out.println(array[i]);
        }
    }
}


Measured memory_bytes: 25768
//abc124_d.cpp
//Fri Apr 19 21:23:45 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;

	vector<int> nums;

	if (s[0] == '0'){
		nums.push_back(0);
	}

	int cur = 1;
	for (int i=1;i<n;i++){
		if (s[i]==s[i-1]){
			cur++;
		}else {
			nums.push_back(cur);
			cur = 1;
		}
	}
	nums.push_back(cur);

	int ans = 0;
	for (int i=0;i<nums.size();i=i+2){
		int temp = 0;
		for (int j=i;j<=i+2*k;j++){
			if (j>nums.size()-1){
				ans = max(temp,ans);
				break;
			}else {
				temp += nums[j];
			}
			ans = max(temp,ans);
		}
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 1020
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if ans[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)


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

	int a[100000];

int main(){
	int n,i,j,s=0,max=0,min=1e9;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]>max)
			max=a[i];
		if(a[i]<min)
			min=a[i];
	}
	s=max-min;
	cout << s;
			
		
}


Measured memory_bytes: 256
n = int(input())
A = tuple(map(lambda x:int(x)-1, input().split()))

paired = [0] * n
c = 0
for i in range(n-1):
    if paired[i]:
        continue

    if A[A[i]] == i:
        c += 1
        paired[A[i]] = 1

print(c)


Measured memory_bytes: 14068
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    ll n, m, k; cin >> n >> m >> k;
    vll a(n), b(m);
    for (auto &x : a) cin >> x;
    for (auto &x : b) cin >> x;
    ll p = 0, t = 0;
    while (p < a.size() && t + a[p] <= k) t += a[p++];
    int p2 = 0;
    while (p2 < b.size() && t + b[p2] <= k) t += b[p2++];
    int ans = p + p2;
    ROF(i, p - 1, 0) {
        t -= a[i];
        while (p2 < b.size() && t + b[p2] <= k) t += b[p2++];
        ans = max(ans, i + p2);
    }
    cout << ans << endl;
}

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

int main()
{
    long long n, m, a, b, ans = 0, num = 0;
    cin >> n >> m;

    vector<pair<long long, long long>> Q(n);
    

    for(long long i=0;i<n;i++){
        cin >> a >> b;
        Q[i] = make_pair(a,b);
    }
    sort(Q.begin(), Q.end());
  	long long i=0;
    while(i<m){
        for(long long j=0;j<Q[num].second;j++){
            ans += Q[num].first;
            i++;
          	if(i==m){
              break;
            }
        }
        num++;
    }
  	cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    bool st=true, pr=true;
    
    sort(all(a));
    int i=2;
    int num=a[0];
    vector<int> p;
    while(i*i<=num){
        if(num%i==0){
            while(true){
                num/=i;
                if(num%i!=0) break;
            }
            p.push_back(i);
        }
        i++;
    }
    if(num!=1) p.push_back(num);
    sort(all(p));
    num=p.size();
    vector<bool> pp(num);

    for(int i=1; i<n; i++){
        for(int j=0; j<num; j++){
            if(pp[j]) continue;
            if(a[i]%p[j]!=0) pp[j]=true;
        }
    }
    rep(i,num) if(!pp[i]) st=false;

    num=0;
    rep(i,n) if(a[i]==1) num++;
    
    if(n-num>79000) pr=false;
    else{
        vector<int> vv(10000000);
        for(int i=0; i<n; i++){
            int j=2;
            while(j*j<=a[i]){
                if(a[i]%j==0){
                    while(true){
                        a[i]/=j;
                        if(a[i]%j!=0) break;
                    }
                    if(vv[j]){
                        pr=false;
                        break;
                    }
                    vv[j]=true;
                }
                j++;
            }
            if(a[i]!=1){
                if(vv[a[i]]){
                    pr=false;
                    break;
                }
                vv[a[i]]=true;
            }
        }
    }

    if(a[n-1]==1) pr-true;
    if(pr) cout << "pairwise coprime" << endl;
    else if(st) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  map<char, int> m;
  rep(i, 4) m[s[i]]++;
  for(auto x: m){
    if(x.second != 2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int t[N], v[N];
    rep(i, N) cin >> t[i];
    rep(i, N) cin >> v[i];

    int spd[80010] = {};
    int tmpT = 0;
    int tmpspd = 0;
    rep(i, N) {
        rep(j, t[i]*2) {
            spd[j+tmpT*2] = tmpspd;
            tmpspd++;
            tmpspd = min(tmpspd, v[i]*2);
        }
        tmpT += t[i];
    }
    tmpspd = 0;
    for (int i = N-1; i >= 0; i--) {
        tmpT -= t[i];
        for (int j = t[i]*2; j > 0; j--) {
            spd[j+tmpT*2] = min(spd[j+tmpT*2], tmpspd);
            tmpspd++;
            tmpspd = min(tmpspd, v[i]*2);
        }
    }
    double ans = 0;
    rep(i, 80010) {
        ans += spd[i];
        if (spd[i] != 0) {
            //cout << "spd[" << i/(2.0) << "] = " << spd[i]/2.0 << endl;
        }
    }
    printf("%.5f\n", ans/4.0);
    //cout << ans/4.0 << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const int inf=0x3f3f3f3f;
char s[N];
int dp[N][30],n,nxt[N][30];
vector<int> v;
int main()
{
	while(scanf("%s",s+1)!=EOF)
	{
		memset(nxt,-1,sizeof(nxt));
		memset(dp,inf,sizeof(dp));
		int n=strlen(s+1);
		for(int j=0;j<26;j++)
			dp[n][j]=1;
		dp[n][s[n]-'a']=2;
		nxt[n][s[n]-'a']=0;
		for(int i=n-1;i>=1;i--)
		{
			for(int j=0;j<26;j++)
			{
				if(s[i]-'a'==j)
				{
					for(int k=0;k<26;k++)
					{
						if(dp[i+1][k]+1<dp[i][j])
						{
							dp[i][j]=dp[i+1][k]+1;
							nxt[i][j]=k;
						}
					}
				}
				else
				{
				
						dp[i][j]=dp[i+1][j];
						nxt[i][j]=j;
					
				}
			}
		}
		int mn=inf,cur=0;
		for(int j=0;j<26;j++)
		{
			if(mn>dp[1][j])
				mn=dp[1][j],cur=j;
		}
		v.clear();
		v.push_back(cur);
		for(int i=1;i<=n;i++)
		{
			if(i+1<=n)
			{
				if(dp[i][cur]>dp[i+1][nxt[i][cur]])
					v.push_back(nxt[i][cur]);
			}
			else
			{
				if(nxt[i][cur]!=-1)	
					v.push_back(cur);	
			}
			cur=nxt[i][cur];
		}
		for(int i=0;i<v.size();i++)
			printf("%c",v[i]+'a');
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 47360
#include <iostream>
#include <stdio.h>

using namespace std;

const int MAX_K = 201;
int mem[MAX_K][MAX_K][MAX_K];

int gcd(int a, int b)
{
    if(a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

void solve(long long K){
    long long result = 0;

    for(int i = 1; i <= (int)K; i++) {
        for(int j = 1; j <= (int)K; j++) {
            for(int k = 1; k <= (int)K; k++) {
                int ans_r = gcd(i, j);
                int ans = gcd(ans_r, k);
                result += ans;
            }
        }
    }

    cout << result << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3256
a,b = map(int,input().split())
def baseN(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
    return((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])
print(len(baseN(a, b)))

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

int main(){
    int n;
    cin >> n;

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

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

    int cou_1 = 0;
    int cou_2 = 0;
    int cou_3 = 0;
    for(int i = 0; i < n; i++){
        if(p[i] <= a){
            cou_1++;
        }else if(p[i] > b){
            cou_3++;
        }else{
            cou_2++;
        }
    }

    int ans = cou_1;
    if(ans > cou_2){
        ans = cou_2;
    }
    if(ans > cou_3){
        ans = cou_3;
    }

    cout << ans << endl;
}

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

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repr(i,a,b) for(int i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> P;
const ll INF=1LL<<50;

int N,K;
ll h[100010];

int main(){
    cin>>N>>K;
    rep(i,0,N){
        cin>>h[i];
    }
    //最大値を最小値の差を最小化したい
    //最小値の決め打ち→しゃくとり法
    sort(h,h+N);
    ll res=INF;
    int right=K;
    rep(left,0,N-K+1){
        res=min(res,h[right-1]-h[left]);
        right++;
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val all: MutableList<Int> = mutableListOf()
    for (i in 0 until n) {
        all.add(sc.nextInt())
    }
    var a = 0
    var b = 0
    for (i in 0 until n) {
        val max = all.max()!!.toInt()
        if (i % 2 == 0) {
            a += max
        } else {
            b += max
        }
        all.remove(max)
    }
    if (a >= b) {
        println(a - b)
    } else {
        println(b - a)
    }
}

Measured memory_bytes: 29868
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,n,a,b,c,k,l;
  char str[1001],mei[8],p[1001],x;
  scanf("%s %d",str,&n);
  for(i=0;i<n;i++){
    c=0;
    k=0;
    scanf("%s",mei);
    if(mei[2]=='i'){
      scanf("%d %d",&a,&b);
      for(j=a;j<=b;j++){
    printf("%c",str[j]);
    c=1;
      }
    }
      if(c!=0)printf("\n");
    else if(mei[2]=='v'){
      scanf("%d %d",&a,&b);
      c=b;
      for(j=a;j<=(a+b)/2;j++){
    x=str[j];
    str[j]=str[c];
    str[c]=x;
    c--;
      }
    }
    else if(mei[2]=='p'){
      scanf("%d %d %s",&a,&b,p);
      for(j=a;j<=b;j++){
    str[j]=p[k];
    k++;
      }
    }
  }
      return 0;
}
    

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <queue>
#include <map>

std::map< std::string, unsigned long int > mp;
std::map< std::string, std::queue< std::string > > recipe;

int n, m;
std::string t;

unsigned long int wrought(std::string s) {
    if ( recipe.find(s) == recipe.end() ) {
        return mp[s];
    } else {
        std::queue< std::string > q = recipe[s];
        unsigned long int res = 0;
        while (!q.empty()) {
            std::string t = q.front();
            q.pop();
            res += wrought( t );
        }
        return std::min(res, mp[s]);
    }
}

void solve(std::string t) {
    unsigned long int res = std::min(mp[t], wrought( t ));
    std::cout << res << std::endl;
}

int main() {
    while (std::cin >> n, n) {
        // initialize map
        mp.clear();
        recipe.clear();

        // get input
        for (int i=0; i<n; i++) {
            std::string s;
            unsigned long int price;
            std::cin >> s >> price;
            mp[s] = price;
        }
        std::cin >> m;
        for (int i=0; i<m; i++) {
            std::string obj;
            int k;
            std::cin >> obj >> k;
            for (int j=0; j<k; j++) {
                std::string q;
                std::cin >> q;
                recipe[obj].push( q );
            }
        }
        std::string t;
        std::cin >> t;
        solve( t );
    }
    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
const ll mod = 1e9 + 7;
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{
  //GCD Blackboard
    ll n, ans = 0;
    cin >> n;
    ll a[n+1], x[n+1], y[n+1];
    x[0] = 0; y[0] = 0;
    loop(i, 1, n+1){
        cin >> a[i];
        x[i] = __gcd(a[i], x[i-1]);
        //cout << x[i] << endl;
    }
    y[n] = a[n];
    rloop(i, n-1, 1) y[i] = __gcd(a[i], y[i+1]);
    loop(i, 1, n+1){
        if(i == 1) ans = max(ans, y[i+1]);
        if(i == n) ans = max(ans, x[i-1]);
        ans = max(ans, __gcd(x[i-1], y[i+1]));
    }
    cout << ans << endl;

}

Measured memory_bytes: 2560
import scala.io.StdIn._

object Main extends App {

  def isLeftSmall(c1: String, c2: String): Boolean = {
    if (c1.takeRight(1).toInt < c2.takeRight(1).toInt) true else false
  }
  
  def bubbleSort(c: Array[String], n: Int) {
    for(i <- (0 to n - 1)) {
      for (j <- (n - 1 until i by -1)) {
        if (isLeftSmall(c(j), c(j - 1))) {
          val tmp_v = c(j)
          c(j) = c(j - 1)
          c(j - 1) = tmp_v
        }
      }
    }
    println(c.mkString(" "))
    println("Stable")
  }

  def selectionSort(c: Array[String], n: Int) {
    for (i <- (0 to n - 1)) {
      var min_j = i
      for (j <- (i to n - 1)) {
        if (isLeftSmall(c(j), c(min_j))) {
          min_j = j
        }
      }
      val tmp_v = c(i)
      c(i) = c(min_j)
      c(min_j) = tmp_v
    }
    println(c.mkString(" "))
  }
  
  val n = readLine.toInt
  val c = readLine.split(" ").toArray
  val c1 = c.clone
  val c2 = c.clone
  bubbleSort(c1, n)
  selectionSort(c2, n)
  if (c1 sameElements c2) println("Stable") else println("Not stable")
}


Measured memory_bytes: 44196
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=1e5+10;
char a[N];
int main()
{
    while(~scanf("%s",a))
    {
        int n=strlen(a);
        int c=n-2;
        if(a[0]==a[n-1]) c++;
        if(c%2==0) puts("Second");
        else puts("First");
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int N,M,X;
int C[12],A[12][12];
main()
{
	cin>>N>>M>>X;
	for(int i=0;i<N;i++)
	{
		cin>>C[i];
		for(int j=0;j<M;j++)cin>>A[i][j];
	}
	int ans=1e8;
	for(int i=0;i<1<<N;i++)
	{
		int now[12]={};
		int sum=0;
		for(int j=0;j<N;j++)if(i>>j&1)
		{
			sum+=C[j];
			for(int k=0;k<M;k++)now[k]+=A[j][k];
		}
		bool flag=true;
		for(int j=0;j<M;j++)if(now[j]<X)flag=false;
		if(flag&&ans>sum)ans=sum;
	}
	cout<<(ans>1e7?-1:ans)<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int const nax = 2e5 + 10;

vector<int> a[nax];
int node[2][nax];
int top[2];

int n , ct[3], c[3], col[nax];
int  ptr1 = -2, ptr2 = -1, ptr3  = 0;

void dfs (int nod,  int pa, int lv) {
    ct[lv % 2] ++;
    node[lv % 2][top[lv % 2] ++] = nod;
    for (int i : a[nod])
        if (i != pa)
            dfs(i, nod, lv + 1);
}

int main () {
    scanf("%d", &n);
    for (int i = 1 ; i < n ; ++ i) {
        int u, v;
        scanf("%d %d", &u, &v);
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }

    c[0] = n / 3 ;
    c[1] = n / 3 + (n % 3 > 0);
    c[2] = n / 3 + (n % 3 > 1);

    dfs(1, 0, 0);

    if (max(ct[0], ct[1]) >= c[1] + c[2]) {
        int toCol = ct[0] >= ct[1] ? 0 : 1;
        for (int i = 0 ;i < c[1] ; ++ i)
            col[node[toCol][i]] = (ptr1 += 3);

        for (int i = 0 ; i < c[2] ; ++ i)
            col[node[toCol][i + c[1]]] = (ptr2 += 3);
    }
    else if (max(ct[0], ct[1]) >= c[1] && min(ct[0], ct[1]) >= c[2]) {
        int maxCol = ct[0] >= ct[1] ? 0 : 1;
        int minCol = (maxCol ^ 1);
        for (int i = 0 ; i < c[1] ; ++ i)
            col[node[maxCol][i]] = (ptr1 += 3);

        for (int i = 0 ; i < c[2] ; ++ i)
            col[node[minCol][i]] = (ptr2 += 3);
    }

    for (int i = 1 ; i <= n ; ++ i)
        printf("%d ", col[i] ? col[i] : ptr3 += 3);


}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 19072
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
change = []
for i in range(q):
  change.append(list(map(int, input().split())))
dict = Counter(a)
ans = sum(a)
ans_list = []
for b, c in change:
  if b in dict.keys():
    if c in dict.keys():
      dict[c] += dict[b]
      ans = ans + (c-b)*dict[b]
      dict[b] = 0
      ans_list.append(ans)
    else:
      dict[c] = dict[b]
      ans = ans + (c-b)*dict[b]
      dict[b] = 0
      ans_list.append(ans)
  else:
    ans_list.append(ans)
for i in ans_list:
  print(i)

Measured memory_bytes: 38352
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int x;
	int N;
	string S;
	int maxValue;

	x = 0;

	cin >> N;
	cin >> S;

	maxValue = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'I') {
			x += 1;
		}
		else {
			x -= 1;
		}

		if (maxValue > x) {
			maxValue = maxValue;
		}
		else {
			maxValue = x;
		}
	}

	cout << maxValue << endl;

}







Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
int k;
string str;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[2000005],R[2000005];
void make(){
	F[0] = 1;
	for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<2000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int main(){
	cin>>k>>str;
	int n = str.size();
	make();
	ll ans = 0;
	for(int i=n;i<=n+k;i++){
		ans += C(i-1, n-1) * modpow(25LL, i-n) % mod * modpow(26LL, n+k-i) % mod;
	}
	cout << (ans%mod) << endl;
}

Measured memory_bytes: 35600
#include<bits/stdc++.h>
using namespace std;
/*********ANISH***********ANISH*************ANISH***********ANISH******/
#define pb push_back
#define ll long long
#define ff first
#define ss second
ll max(ll a,ll b)
{
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b)
{
    if(a<b) return a;
    return b;
}
int lcm(int a, int b)  
{  
    return (a*b)/__gcd(a, b);  
}  
/********ANISH************ANISH*************ANISH**********ANISH*********/
int main()
{
  int test;
  test=1;
  while(test--)
  {
     int n,d;
     cin>>n>>d;
     int x,y,ans=0;
     while(n--)
     {
         cin>>x>>y;
         x=abs(x),y=abs(y);
         double xx=x,yy=y;
         double dist=sqrt(xx*xx+yy*yy);
         if(double(dist)<=double(d)) ++ans; 
     }
     cout<<ans;
  }
}


Measured memory_bytes: 3648