akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string x;
    cin >> x;
    int n = x.size();
    stack<char> st;
    rep(i, n) {
        if (st.empty()) {
            st.push(x[i]);
        }
        else if (st.top() == 'S' && x[i] == 'T') {
            st.pop();
        }
        else {
            st.push(x[i]);
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vector<bool>used;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		used[v]=1;
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(used[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0,f;
		while(1){
			used=vector<bool>(n,false);
			f=dfs(s,t,inf);
			if(f==0)return flow;
			flow+=f;
		}
	}
};
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
signed main(){
	int n,m;
	while(cin>>n>>m,n){
		MF mf(n+m+2);
		int s=n+m,t=s+1;
		rep(i,n)mf.add_edge(s,i,1);
		rep(i,m)mf.add_edge(n+i,t,1);
		vi in1(n),in2(m);
		rep(i,n)cin>>in1[i];
		rep(i,m)cin>>in2[i];
		rep(i,n)rep(j,m)if(gcd(in1[i],in2[j])-1)mf.add_edge(i,n+j,1);
		cout<<mf.mf(s,t)<<endl;
	}
}

Measured memory_bytes: 7392
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
		int n1 = Integer.parseInt(s);
		int n2 = 0;
		for(int i=0; i<s.length(); ++i) {
			n2 += Integer.parseInt(s.charAt(i) + "");
		}
		
		if(n1%n2 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+5;
const ll mod =   1e9+7;
ll n;
ll arr[500];
int main()
{  fast
cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i];
ll prev=arr[1];ll s=1000/arr[1];ll mon=1000%arr[1];
for(int i=2;i<=n;i++) {
	if(arr[i]<prev) {

		mon+=s*prev;
		prev=arr[i];
		s=mon/arr[i];
		mon=(mon%arr[i]);
	}
	else if(arr[i]>prev){
	   mon+=s*arr[i];

	   s=mon/arr[i];
	   
	   prev=arr[i];
	   mon=mon%arr[i];

	}
//	cout<<mon<<" "<<s<<endl;
}
cout<<s*prev+mon<<endl;
}


Measured memory_bytes: 3544
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;
vector<pii> graph[2525];
int N;
vector<ll> a;
int main(){
	cin>>N;
	for(int i=0;i<3*N;i++){
		ll hoge;
		cin>>hoge;
		a.pb(hoge);
	}
	ll plmax[2*114514];
	ll plmin[2*114514];
	ll sum1=0,sum2=0;
	priority_queue<ll,vector<ll>,greater<ll> > hoge;
	priority_queue<ll> hoge2;
	for(int i=0;i<N;i++){
		sum1+=a[i];
		hoge.push(a[i]);
		sum2+=a[i+2*N];
		hoge2.push(a[i+2*N]);
	}
	plmax[0]=sum1;
	for(int i=N;i<2*N;i++){
		ll x=hoge.top();
		hoge.pop();
		if(x<a[i]){
			hoge.push(a[i]);
			sum1=sum1-x+a[i];
		}else{
			hoge.push(x);
		}
		plmax[i-N+1]=sum1;
		
	}
	plmin[N]=sum2;
	for(int i=2*N-1;i>=N;i--){
		ll x=hoge2.top();
		hoge2.pop();
		if(x>a[i]){
			hoge2.push(a[i]);
			sum2=sum2-x+a[i];
		}else{
			hoge2.push(x);
		}
		plmin[i-N]=sum2;
	}
	ll ans=plmax[0]-plmin[0];
	for(int i=0;i<=N;i++){
		ans=max(ans,plmax[i]-plmin[i]);
		//cout<<plmax[i]<<" "<<plmin[i]<<endl;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 10092
N,M = map(int,input().split())
*A, = map(int,input().split())
BC=[list(map(int,input().split())) for _ in [0]*M]
A.sort()
BC.sort(key=lambda x:-x[1])
i = 0
for B,C in BC:
    for j in range(i,min(N,i+B)):
        if A[j]<C:A[j]=C
    i = i+B
print(sum(A))


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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector< vector <pii> > g;
int n, m, p;
const int INF = 1000000000;
vector<int> d;

bool bf(int s){
  d.resize(n, INF);
  d[s] = 0;
  rep(i, n+1){
    bool update = false;
    rep(j, n){
      if(d[j] != INF){
        rep(k, g[j].size()){
          if(d[g[j][k].X] >  d[j] + g[j][k].Y){
            d[g[j][k].X] = d[j] + g[j][k].Y;
            update = true;
          }
        }
      }
    }
    if(!update) return true;
    if(i == n && update){
      return false;
    }
  }
  return true;
}

bool can_reach(int s, int t){
  vector<bool> used;
  queue<int> q;
  used.resize(n, false);
  q.push(s);
  used[s] = true;
  while(!q.empty()){
    int st = q.front();q.pop();
    used[st];
    rep(j, g[st].size()){
      int tar = g[st][j].X;
      if(used[tar])continue;
      q.push(tar);
      used[tar] = true;
    }
  }
  return used[t];
}

int main(void){
  cin >> n >> m >> p;
  g.resize(n);
  rep(i, m){
    int a;
    pii x;
    cin >> a >> x.X >> x.Y;
    a--;x.X--; // 0-index
    x.Y-=p;
    x.Y=-x.Y;
    g[a].eb(x);
  }
  rep(i,n){
    if(!can_reach(i, n-1)){
      g[i].resize(0);
    }
  }
  {
    vector<bool> used;
    queue<int> q;
    used.resize(n, false);
    q.push(0);
    used[0]=true;
    while(!q.empty()){
      int st = q.front();q.pop();
      used[st];
      rep(j, g[st].size()){
        int tar = g[st][j].X;
        if(used[tar])continue;
        q.push(tar);
        used[tar] = true;
      }
    }
    rep(i, n){
      if(!used[i]) g[i].resize(0);
    }
  }
  if(!bf(0)){
    cout << -1 << endl;
    return 0;
  }

  if(-d[n-1] < 0){
    cout << 0 << endl;
  }else{
    cout << -d[n-1] << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
  int H, W;
  string S[50], T[50];

  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
    T[i] = S[i];
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '.') {
        T[i][j] = '0';
        for(int k = -1; k <= 1; k++) {
          for(int l = -1; l <= 1; l++) {
            int ny = i + k, nx = j + l;
            if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
            if(S[ny][nx] == '#') ++T[i][j];
          }
        }
      }
    }
    cout << T[i] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main(){
  set<int>st;
  int a,b,c; 
  cin>>a>>b>>c; 
  st.insert(a);
  st.insert(b);
  st.insert(c);
  if(st.size()==2){
	cout<<"Yes\n";  
  }
  else{
    cout<<"No\n";
  }
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}



///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(1); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());


ll n,m; cin>>n>>m;
char mat[n][m]; for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin>>mat[i][j];
ll dp[n][m]; memset(dp, 0, sizeof(dp));
dp[0][0]=1;
for(int i=0;i<n;++i) for(int j=0;j<m;++j){ 
    if(mat[i][j]=='#') continue;
    if(i) dp[i][j]=dp[i-1][j];
    if(j) dp[i][j]=(dp[i][j]+ dp[i][j-1])%MOD;
}
cout<< dp[n-1][m-1] <<'\n'; 

return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  vector<int> a(S.length()-2);
  for(int i=0;i<S.length()-2;i++){
    a[i]=abs(753-stoi(S.substr(i,3)));
    }
  sort(a.begin(),a.end());
  cout << a[0] <<endl;
}



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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

    string s;
    cin>>s;

    string s1;
    for(int i=0;i<4;i++) s1+=s[i];
    s1+=' ';
    for(int i=4;i<12;i++) s1+=s[i];
    cout<<s1<<endl;


}



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

int compare(const void *a, const void *b)
{
    if (*(short*)a < *(short*)b) {
	return -1;
    } else if (*(short*)b < *(short*)a) {
	return 1;
    }
    return 0;
}

int main(void)
{
    int	n, k;
    short int	p[1001];

    if (fscanf(stdin, "%d %d", &n, &k) == EOF) {
	return 1;
    }

    for (int i = 0; i < n; i++) {
	if (fscanf(stdin, "%hd", p+i) == EOF) {
	    return 1;
	}
    }

    qsort(p, (size_t)n, sizeof(short int), compare);

    int	ans = 0;
    for (int i = 0; i < k; i++) {
	ans += p[i];
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1748
use std::collections::HashMap;
fn main() {
    input! {
        n: i64,
        a: [i64;n]
    }

    let primes = get_primes(1000);
    let mut is_pair = true;
    let mut is_set = true;
    let mut p_map: HashMap<i64, bool> = HashMap::new();
    let mut set_gcd = a[0];
    for i in a {
        let mut _i = i;
        set_gcd = gcd(set_gcd, _i);

        for p in &primes {
            if i % (*p as i64) == 0 {
                if p_map.contains_key(&p) && p_map[&p] {
                    is_pair = false;
                } else {
                    p_map.insert(*p, true);
                }

                _i /= (*p) as i64;
            }
        }
        if _i > 1000 {
            if p_map.contains_key(&_i) && p_map[&_i] {
                is_pair = false;
            } else {
                p_map.insert(_i, true);
            }
        }
    }

    is_set = set_gcd == 1;
    if is_pair {
        println!("pairwise coprime");
        return;
    }
    if is_set {
        println!("setwise coprime");
        return;
    }

    println!("not coprime")
}

fn get_primes(n: i64) -> Vec<i64> {
    let mut table: Vec<_> = (2..n + 1).collect();
    let mut primes = Vec::new();

    for i in 0..table.len() {
        if table[i] != 0 {
            primes.push(table[i]);
            for j in i..table.len() {
                if i != j {
                    if table[j] % table[i] == 0 {
                        table[j] = 0;
                    }
                }
            }
            table[i] = 0;
        }
    }
    primes
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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


Measured memory_bytes: 23156
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


n,m=map(int,input().split())
UnionFind=UnionFind(n)
AB=[list(map(int,input().split())) for _ in range(m)]
ans=[n*(n-1)//2]

for a,b in AB[::-1]:
    if UnionFind.isSameGroup(a-1,b-1):
        ans.append(ans[-1])
    else:
        s,t=UnionFind.size(a-1),UnionFind.size(b-1)
        ans.append(ans[-1]-s*t)
    UnionFind.Unite(a-1,b-1)

for i in ans[::-1][1:]:
    print(i)

Measured memory_bytes: 119512
n, k = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * (k+1)

for i in range(1, k+1):
    for a in A:
        if i - a < 0:
            break
        if dp[i-a] == 0:
            dp[i] = 1

if dp[k] == 1:
    print("First")
else:
    print("Second")

Measured memory_bytes: 44268
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	std::vector<int> best;
	long long neg = 0;
	int base = 0;
	for(int i = 0; i < n; i++) {
		std::cin >> b[i];
		if(a[i] < b[i]) {
			neg += b[i] - a[i];
			base++;
		} else {
			best.push_back(b[i] - a[i]);
		}
	}
	std::sort(best.begin(), best.end());
	int i = 0;
	while(neg > 0 && i < (int) best.size()) {
		neg += best[i++];
	}
	if(neg > 0) {
		std::cout << "-1\n";
	} else {
		std::cout << i + base << '\n';
	}
}

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

main()
{
  int n;
  cin>>n;
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
  
  int dp[n][3];
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}
  

Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}

signed main()
{
    #ifdef LOCAL_RUN
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int TTT; cin >> TTT; while(TTT--){
    #else
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    #endif // LOCAL_RUN

    int n, m;
    cin >> m;
    n = 2*m;
    string s;
    cin >> s;
    vector<int> A, B, index(n);
    for(int i=0;i<n;++i){
        if(s[i] == 'a'){
            index[i] = A.size();
            A.push_back(i);
        } else {
            index[i] = B.size();
            B.push_back(i);
        }
    }
    assert((int)A.size() == m && (int)B.size() == m);
    vector<string> suffs(n+1, string(""));
    for(int i=n-1;i>=0;--i){
        string &cand = suffs[i];
        cand = suffs[i+1];

        if(s[i] == 'a'){
            int b = B[index[i]];
            if(b < i) continue;
            string t = string("ab") + suffs[b+1];
            xmax(cand, t);
        } else {
            int a = A[index[i]];
            if(a < i) continue;
            string t = "b";
            for(int j=i+1;j<=a;++j){
                if(s[j] == 'a'){
                    if(i <= B[index[j]]){
                        assert(B[index[j]]<j);
                        t.push_back('a');
                    }
                } else {
                    assert(A[index[j]] > a);
                    a = A[index[j]];
                    t.push_back('b');
                }
            }
            t+=suffs[a+1];
            xmax(cand, t);
        }
        //cerr << i << " " << suffs[i] << "\n";
    }

    cout << suffs[0] << "\n";


    #ifdef LOCAL_RUN
    }
    #endif // LOCAL_RUN
    return 0;
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}

ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){ if(b==0) return a; return gcd(b, a%b);}

int counter(int x){
    if(x==0) return 0;
    return counter(x>>1)+(x&1);
}


int main(){
    fast_io

    int n;
    cin>>n;
    string s[n];
    int t[n];
    rep(i,n) cin>>s[i]>>t[i];
    string x;
    cin>>x;
    int ans=0;
    bool flag=false;
    rep(i,n){
        if(flag) ans+=t[i];
        if(s[i]==x) flag=true;
    }
    cout<<ans<<endl;
    
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

// dp[j][k][s] : j までから k 枚選んで合計が s になる選び方の総数
LL dp[100][100][5000];

void solve()
{
    int N;
    cin >> N;
    int A;
    cin >> A;
    vector<int> x(N + 1);
    int X = A;
    REP1(i, N)
    {
        cin >> x[i];
        X = max(X, x[i]);
    }

    dp[0][0][0] = 1;

    REP0(j, N + 1)
    {
        REP0(k, N + 1)
        {
            REP0(s, N * X + 1)
            {
                if (j < k) continue;
                if ((0 < j) and (s < x[j]))
                { // s が小さく j 番目を選べない場合, j-1 までの総数の引き継ぎ
                    dp[j][k][s] += dp[j - 1][k][s];
                    continue;
                }
                if ((0 < j) and (0 < k) and (x[j] <= s))
                { // j番目を選ばない総数 と j番目を選ぶ総数の和
                    dp[j][k][s] += dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
                    continue;
                }
            }
        }
    }

    unsigned long long ans = 0;
    REP1(i, N)
    {
        ans += dp[N][i][i * A];
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 151808
#include <stdio.h>
  
#define N 36
  
typedef struct{
  char a;
  int value;
}Card;
  
int main(){
  
  int i,j,n,min,flag=0;
  Card c[N],b[N],n1,n2;
    
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&c[i].a,&c[i].value);
    b[i].a=c[i].a;
    b[i].value=c[i].value;
  }
  
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(c[j].value<c[j-1].value){
 
    n1=c[j];
    n2=c[j-1];
      c[j]=n2;
    c[j-1]=n1;
      }
    }
  }
  
      
  
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(b[j].value<b[min].value){
    min=j;
      }
    }
 
 
    n1=b[i];
    n2=b[min];
    b[i]=n2;
    b[min]=n1;
  }
  
  
  for(i=0;i<n-1;i++){
    printf("%c%d ",c[i].a,c[i].value);
  }
  printf("%c%d\n",c[n-1].a,c[n-1].value);
  printf("Stable\n");
   
  for(i=0;i<n-1;i++){
    printf("%c%d ",b[i].a,b[i].value);
  }
  printf("%c%d\n",b[n-1].a,b[n-1].value);
     
  for(i=0;i<=n-1;i++){
    if(c[i].a!=b[i].a){
      flag=1;
    }
  }
   
  if(flag==1) printf("Not stable\n");
  else printf("Stable\n");
    
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int maxn = 0;
	int k, t, i;
	cin >> k >> t;
	for (i = 0; i < t; i++)
	{
		int temp;
		cin >> temp;
		maxn = max(maxn, temp);
	}
	k -= maxn;
	if (maxn < k)
		cout << 0 << endl;
	else
		cout << maxn - k - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define min(a,b) (a<b)?a:b
#define max(a,b) (a>b)?a:b
#define ll long long int
#define BIG 1e9
using namespace std;

int main() {
	ll dp[200000],h[200000],N,K;
	cin>>N>>K;
	for(int i=0; i<N; i++){
		cin>>h[i];
		dp[i] = BIG;
	}
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2; i<N; i++){
		for(int j=1; j<=K; j++){
			dp[i] = (i>=j)?min(dp[i],dp[i-j]+abs(h[i]-h[i-j])):dp[i];
		}
	}
	cout<<dp[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 3072
line = gets.chomp.split(" ").map(&:to_i)

k = line[0] + 1
a = line[1]
b = line[2]
diff = b - a

k = k - a

total = a
if diff <= 1
    total = k + a
elsif k % 2 == 0
    times = (k.to_f / 2).to_i
    total += diff * times
else
    times = ((k - 1).to_f / 2).to_i
    total += diff * times
    total += 1
end

puts total


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
struct Section{
	int l,r;
	bool operator<(const Section& rhs) const{
		return r-l+1<rhs.r-rhs.l+1;
	}
} sec[300005];
int N,M,bit[100005];
inline void modify(int pos,int add){
	for(;pos<=M+1;pos+=pos&-pos)
		bit[pos]+=add;
}
inline int query(int pos){
	int res=0;
	for(;pos;pos-=pos&-pos)
		res+=bit[pos];
	return res;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d%d",&sec[i].l,&sec[i].r);
	sort(sec,sec+N);
	int cur=0;
	for(int i=1;i<=M;i++){
		while(cur<N && sec[cur].r-sec[cur].l+1<i){
			modify(sec[cur].l,1);
			modify(sec[cur].r+1,-1);
			cur++;
		}
		int ans=N-cur;
		for(int j=i;j<=M;j+=i)
			ans+=query(j);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	string s;
	cin>>s;
	
	int ans=0;
	int tmp=0;
	REP(i,3){
		if(s[i]=='R') ans=max(ans,++tmp);
		else tmp=0;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int A[200100];
multiset<int> s;
vector<int> zip;
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		s.insert(A[i]);
		zip.pb(A[i]);
	}
	sort(all(zip));
	zip.erase(unique(all(zip)),zip.end());
	int ans = 0;
	for(int i=30;i>0;i--){
		for(int j=0;j<zip.size();j++){
			int a = zip[j];
			int b = (1<<i)-a;
			if(a==b){
				int cnt = s.count(a);
				ans += cnt/2;
				int del = (cnt/2)*2;
				for(int k=0;k<del;k++){
					auto it = s.find(a);
					s.erase(it);
				}
			}else{
				int cnta = s.count(a);
				int cntb = s.count(b);
				ans += min(cnta,cntb);
				for(int k=0;k<min(cnta,cntb);k++){
					auto ita = s.find(a);
					auto itb = s.find(b);
					s.erase(ita);
					s.erase(itb);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11124
n = int(input())
A = list(map(int,input().split()))
p = 0
ls = []
for i in range(n):
    ls.append(abs(A[i]-p))
    p = A[i]
ls.append(abs(A[-1]))
p = 0
ls2 = []
for i in range(1,n):
    ls2.append(abs(A[i] - p))
    p = A[i-1]
ls2.append(abs(A[n-2]))
s = sum(ls)

for i in range(n):
    print(s - ls[i] - ls[i+1] + ls2[i])


Measured memory_bytes: 16152
M, D = list(map(int, input().split()))

count = 0
for m in range(1, M+1):
    for d10d1 in range(1, D+1):
        d10 = d10d1 // 10
        d1 = d10d1 % 10
        
        if (m == d10 * d1) and (d10 >= 2) and (d1 >= 2):
            count += 1
            
print(count)

Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int r, d, x;
    cin >> r >> d >> x;

    REP(i, 10){
        x = r * x - d;
        P(x)
    }

    return 0;
}


Measured memory_bytes: 256
from functools import reduce

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


a_lcm = reduce(lambda x, y: (x * y) // gcd(x, y), a)
m = a_lcm - 1
a_mod = [m % ax for ax in a]

print(sum(a_mod))


Measured memory_bytes: 3812
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

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

  if (k > 2 * n) {
    k = 2 * n + (k % 2);
  }

  deque<int> dq;
  for (int i = 0; i < n; i++) {
    dq.pub(s[i] == 'A');
  }

  for (int i = 0; i < k; i++) {
    if (dq.front() ^ rev) {
      dq.pof();
      dq.puf(rev);
    } else {
      rev ^= 1;
      dq.pof();
      dq.pub(1 ^ rev);
    }
  }

  for (int i = 0; i < n; i++) {
    d(((rev ^ dq.front()) ? 'A' : 'B'));
    dq.pof();
  }

  return 0;
}


Measured memory_bytes: 1540
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct P{
	int k,w;
}a[505];
int n,m,b[505],ans[300005];
bool cmp(P a,P b){
	return a.w<b.w;
}
bool solve(){
	for(int i=1;i<=n;i++) ans[b[i]]=i,a[i].k=i,a[i].w=b[i];
	sort(a+1,a+n+1,cmp);
	for(int i=m,pos=n,rst=n-a[n].k;i;i--){
		while(!rst&&pos) pos--,rst=n-a[pos].k;
		if(!pos) break;
		if(ans[i]) continue;
		ans[i]=a[pos].k;rst--;
		if(i<a[pos].w)
			return 0;
	}
	for(int i=1,pos=1,rst=a[1].k-1;i<=m;i++){
		while(!rst&&pos<n) pos++,rst=a[pos].k-1;
		if(ans[i]) continue;
		ans[i]=a[pos].k;rst--;
		if(i>a[pos].w)
			return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	m=n*n;
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	if(solve()){
		puts("Yes");
		for(int i=1;i<=m;i++) printf((i==m)?"%d":"%d ",ans[i]);
	}
	else puts("No");
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    int N, M;
    scanf("%d", &N);
    int i;
    char s[N][10];
    char list[200][10];
    int index = 0, j;
    REP(i, N){
        scanf("%s", s[i]);
        if(index == 0){
            strcpy(list[index++], s[i]);
        }
        else{
            int flag = 1;
            REP(j, index){
                if(strcmp(list[j], s[i]) == 0){
                    flag = 0;
                    break;
                }
            }
            if(flag) strcpy(list[index++], s[i]);
        }
    }
    scanf("%d", &M);
    char t[M][10];
    REP(i, M){
        scanf("%s", t[i]);
        if(index == 0){
            strcpy(list[index++], t[i]);
        }
        else{
            int flag = 1;
            REP(j, index){
                if(strcmp(list[j], t[i]) == 0){
                    flag = 0;
                    break;
                }
            }
            if(flag) strcpy(list[index++], t[i]);
        }
    }
    int coin[index];
    REP(i, index){
        coin[i] = 0;
    }

    REP(i, index){
        REP(j, N){
            if(strcmp(list[i], s[j]) == 0){
                coin[i]++;
            }
        }
        REP(j, M){
            if(strcmp(list[i], t[j]) == 0){
                coin[i]--;
            }
        }
    }
    int ANS = 0;
    REP(i, index){
        if(ANS < coin[i]){
            ANS = coin[i];
        }
    }
    printf("%d\n", ANS);
    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll X;
    cin >> X;
    if(400 <= X && X <= 599) cout << 8;
    if(600 <= X && X <= 799) cout << 7;
    if(800 <= X && X <= 999) cout << 6;
    if(1000 <= X && X <= 1199) cout << 5;
    if(1200 <= X && X <= 1399) cout << 4;
    if(1400 <= X && X <= 1599) cout << 3;
    if(1600 <= X && X <= 1799) cout << 2;
    if(1800 <= X && X <= 1999) cout << 1;
}

Measured memory_bytes: 3632
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/

int a[100010] = {0};

int main()
{
	int n, x, s = 0, y;
	
	scanf("%d", &n);
	s = n;
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		a[x]++;
	} 
	x = 1, y = 100000;
	while (x <= y){
		while (a[x] < 2 && x <= y){
			x++;
		}
		while (a[y] < 2 && x <= y){
			y--;
		}
		if (x < y){
			a[x]--;
			a[y]--;
			s -= 2;
		} else if (x == y){
			while (a[x] >= 3){
				a[x] -= 2;
				s -= 2;
			}
			if (a[x] == 2){
				s -= 2;
			}
			break;
		}
	} 
	printf("%d\n", s);
}

Measured memory_bytes: 640
import bisect


def read():
    X = int(input())
    return X,

def sieve(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes

def solve(X):
    primes = sieve(2*X)
    idx = bisect.bisect_left(primes, X)
    return primes[idx]

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 5348
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
    ll n,s,l;
    cin>>n>>s;
    for(l=2;l*l<=n;l++) {
	ll sum=0,x=n;
	while(x) sum+=x%l,x/=l;
	if(sum==s) return cout<<l,0;
    }
    for(ll i=l,j;i<=n;i=j+1) {
	ll k=n/i,t=k+n-s;j=n/k;
	if(t%k==0&&t/k>=i&&t/k<=j) return cout<<t/k,0;
    }
    cout<<(n==s?n+1:-1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
	 int N,sum=0,go=0;
	 cin >> N;
	 int P[N+10];
	 for(int i=0; i<N; i++){
		 cin >> P[i];
		 sum=max(sum,P[i]);
		 go+=P[i];
	 }cout << go-sum/2 << endl;
 }

Measured memory_bytes: 256
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi // t), -(-aoki // a))
        # k = max(math.ceil(takahashi / t), math.ceil(aoki / a))
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 39280
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int g,b,r;
    cin >> r >> g >> b;
    int k; cin >> k;
    rep(i,k+1){
        if(r >= g){
            g *= 2;
            continue;
        }
        else{
            if(g >= b){
                b *= 2;
                continue;
            }
            else{
                dunk("Yes");
                return 0;
            }
        }
    }
    dunk("No");
    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int x1,y1,x2,y2,x3,y3,x4,y4;
	int a,b;
	int ans;
	
	
	//データの読み込み
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");


	//実際の処理
	
	a=x2-x1;
	b=y2-y1;
	x3=x2-b;
	y3=y2+a;
	x4=x3-a;
	y4=y3-b;
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d %d %d %d",x3,y3,x4,y4);
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using lli = long long int;

void ABC080C()
{
	int N;
	cin >> N;
	vector<vector<int> > F(N, vector<int>(10));
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < 10; ++j)
			cin >> F[i][j];
	vector<vector<int> > P(N, vector<int>(11));
	for (int i = 0; i < N; ++i)
		for (int j = 0; j <= 10; ++j)
			cin >> P[i][j];

	lli maxPt = -100000000000;
	for (int i = 1; i < (1 << 10); ++i)
	{
		vector<int> c(N);
		for (int j = 0; j < 10; ++j)
		{
			int isOpen = i & 1 << j;
			if (isOpen == 0)
				continue;
			for (int k = 0; k < N; ++k)
			{
				if (F[k][j] == 1) // both open
					++c[k];
			}
		}
		lli pt = 0;
		for (int k = 0; k < N; ++k)
		{
			pt += P[k][c[k]];
		}
		maxPt = max(pt, maxPt);
	}
	cout << maxPt << endl;
}

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

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

struct Ans{
    uint_fast64_t val[100000];
    constexpr Ans() : val(){
        for(int i = 1; i < 1000; ++i)
            if(i % 10)
                ++val[i + (i % 10) * 10000 + ((i / 10) % 10) * 1000];
        for(int i = 1; i < 100000; ++i)
            val[i] += val[i - 1];
    }
};

constexpr Ans a = Ans();
uint_fast64_t A, B;

int main(){
    cin >> A >> B;
    cout << a.val[B] - a.val[A - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,X = [int(input()) for _ in range(4)]
count = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if X == i * 500 + j * 100 + k * 50:
                count += 1
print(count)

Measured memory_bytes: 2940
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int zMIN(int a,int b){return a*b?MIN(a,b):a+b;}
int main(){
  int n,m,a,b,v,s,t,min,i,j;
  while(scanf("%d %d",&m,&n),m||n){
    int d[110][110][2]={0};
    while(m--){
      scanf("%d %d %d %d",&a,&b,&v,&t);
      d[a][b][0]=d[b][a][0]=v;
      d[a][b][1]=d[b][a][1]=t;
    }
    scanf("%d",&m);
    while(m--){
      scanf("%d %d %d",&s,&t,&v);
      int c[110]={0};
      int f[110]={0};
      for(j=0;j<n;j++){
	f[s]=1;
	for(i=1;i<=n;i++){
	  if(d[s][i][v]==0)continue;
	  c[i]=zMIN(c[i],c[s]+d[s][i][v]);
	}
	min=210000000;
	for(i=1;i<=n;i++){
	  if(f[i]||c[i]==0)continue;
	  if(min>c[i])min=c[s=i];
	}
	//printf("%d %d\n",min,s);
	//for(i=0;i<=n;i++)printf("%d ",c[i]);printf("\n");
     }
      //for(i=0;i<=n;i++)printf("%d ",c[i]);printf("\n");
      printf("%d\n",c[t]);
    }
  }
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  ll n, a, b;
  cin >> n >> a >> b;
  if((b - a) % 2 == 0){
    cout << (b - a) / 2 << '\n'; return;
  }
  ll t = a;
  ll nb = b - t;
  if(nb != 1){
    t += (nb - 1) / 2;
  }
  ll ans = t;
  t = n - b + 1;
  ll na = a + t;
  if(na != n){
    t += (n - na) / 2;
  }
  ans = min(ans, t);
  cout << ans << '\n';
}

int main(){
  fastio

  pre();

  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  ktj();
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
char bomb[8][8];

void printData(int i){
    cout << "Data " << i+1 << ':' << endl;
}
 
void dfs(int x,int y){
    bomb[y][x] = '0';
    for(int i = x-3 ; i <= x+3 ; i++){
        if(0 <= i && i <= 7 && bomb[y][i] == '1') dfs(i,y);
    }
    for(int j = y-3 ; j <= y+3 ; j++){
        if(0 <= j && j <= 7 && bomb[j][x] == '1') dfs(x,j);
    }
}
 
int main(){
    int n,x,y;
    string str;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        string tmp;
        for(int j = 0 ; j < 8 ; j++){
            cin >> str;
            for(int k = 0 ; k < 8 ; k++){
                bomb[j][k] = str[k];
            }
        } 
        cin >> x >> y;
        printData(i);
        dfs(x-1,y-1);
        for(int j = 0 ; j < 8 ; j++){
            for(int k = 0 ; k < 8 ; k++){
                cout << bomb[j][k];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1204