akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <map>
using namespace std;

int n;
int s;

int main() {
  while (1) {
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0) return 0;

    int lim = 1 << 10;
    int ans = 0;
    for (int i=0; i<lim; i++) {
      int sum = 0;
      int cnt = 0;

      for (int j=0; j<10; j++) {
        if (i >> j & 1) {
          sum += j;
          cnt++;
        }
      }

      if (sum == s && cnt == n) ans++;
    }

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

Measured memory_bytes: 2556
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int n;
	cin>>n;
	ll ans=0;
	int a[n];
	rep(i,n){
		cin>>a[i];
	}
	for(int i=1;i<n;++i){
		if(a[i]<a[i-1]){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

int main(){ 
  ll a, b, n;
  cin >> a >> b >> n;
  //b未満のx
  ll aa = b - 1;
  //cout << aa << endl;
  ll d = (a * aa / b) - a * (aa / b);
  if (b > n) {
    cout << a * n / b << endl;
  } else {
    cout << d << endl;
   
  } 
  /*
  for (int i = 1; i <= n; i++) {
    cout << i << ":  ";
    cout << (a * i / b) - a * (i / b) << endl;
  }*/
  return 0;
} 

Measured memory_bytes: 3608
sx, sy, tx, ty = map(int,input().split())

Answer = []

firstgo = 'R'*(tx - sx) + 'U'*(ty - sy)
firstcome = 'L'*(tx-sx) + 'D'*(ty - sy)
secondgo = 'D'+'R'*(tx-sx+1) + 'U'*(ty-sy+1) + 'L'
secondcome = 'U' + 'L'*(tx-sx+1) + 'D'*(ty-sy+1) + 'R'
print(firstgo+firstcome+secondgo + secondcome)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int main()
{
    fastio();
    int a,b,c,d,k,t;
    cin>>a>>b>>c>>d>>k;
    if(d>=b){
        t = (c-a)*60+(d-b);
    }else {
        t = (c-a-1)*60+60-b+d;
    }
    if(t<k) cout<<0<<endl;
    else cout<<t-k<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair
const ll INF = 1e18 + 18;
vector< vector< ll > > cost;
vector< ll > dp, pre;

void grp(ll i, ll taken, ll group, ll score, vector< ll > &available){
	if( i == (int)available.size() ){
		dp[taken] = max(dp[taken], score + pre[group]);
		return;
	}
	grp(i + 1, taken, group, score, available);
	grp(i + 1, taken | (1 << available[i]), group | (1 << available[i]), score, available);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    cost.resize(n, vector< ll > (n));
    dp.resize((1 << n), -INF);
    pre.resize((1 << n), 0);

    for(int i = 0 ; i < n ; i++)
    	for(int j = 0 ; j < n ; j++)
    		cin >> cost[i][j];
    for(int mask = 0 ; mask < (1 << n) ; mask++)
    	for(int i = 0 ; i < n ; i++)
    		if( mask & (1 << i) )
    			for(int j = i + 1 ; j < n ; j++)
    				if( mask & (1 << j) )
	    				pre[mask] += cost[i][j];
    dp[0] = 0;
    for(int mask = 0 ; mask < (1 << n) ; mask++){
    	vector<ll> available;
    	for(int i = 0 ; i < n ; i++)
    		if( (mask & (1 << i)) == 0 )
    			available.pb(i);
    	grp(0, mask, 0, dp[mask], available);
    }
    cout << dp[(1 << n) - 1] << endl;
	return(0);
}

Measured memory_bytes: 6612
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
        
nn,mm = map(int,input().split());
a = [input().split() for l in range(mm)]
uf = UnionFind(nn)

for ii in range(mm):
    uf.union(int(a[ii][0]), int(a[ii][1]))

b = [0]*nn
for r in range(1,nn+1):
    b[uf.find(r)-1] += 1
 
con = 0
for vv in range(nn):
    if b[vv] != 0:
        con += 1
print(con-1)

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

signed main(){
 lint N; cin >> N;
 vector<lint> v(N), c(N), data(N);
 for(int i = 0; i < N; i++) cin >> v[i];
 for(int i = 0; i < N; i++) cin >> c[i], data[i] = v[i] - c[i];
 lint ans = 0;
 for(lint i = 0; i < N; i++){
   if(data[i] > 0) ans += data[i];
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    T = []
    for _ in range(N):
        T.append(int(input()))

    if N == 1: return T[0]

    g = T[0]
    ans = T[0]
    for t in T[1:]:
        gc = gcd(t, g)
        g = g*t//gc
    return g

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0: return b
    else: return gcd(b%a, a)




if __name__ == '__main__':
    print(main())

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

int main() {
    vector<int> array(3);
    for(int i = 0; i < 3; i++){
        cin >> array[i];
    }
    sort(array.begin(),array.end());
    reverse(array.begin(), array.end());
    
    cout << array[0] * 10 + array[1] + array[2] << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> n = new ArrayList<Integer>();
		n.add(sc.nextInt());
		n.add(sc.nextInt());
		n.add(sc.nextInt());
		Collections.sort(n);

		System.out.println(Math.abs(n.get(2)-n.get(1))+Math.abs(n.get(1)-n.get(0)));
		sc.close();
	}

}


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

#define YOKO 4
#define TATE 4

int DFS(int P[TATE][YOKO],int,int);
int koukanmae(int,int,int);
void koukan(int P[TATE][YOKO],int irekae2[TATE][YOKO],int,int,int);
int Heuristic(int s[TATE][YOKO]);

int Ans[TATE][YOKO]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0};//答
int puzzle[TATE][YOKO];//問題
int irekae[TATE][YOKO];//仮puzzle

int clear=100000;
int limit;//深さの限度

int x[4]={0,1,0,-1},y[4]={-1,0,1,0};

/*

＊＊＊x[4],y[4]について＊＊＊

x[4]とy[4]はマスとマスを入れ替える時にセットで用いる。
なぜ配列に入れるかというと、for文でまとめて入替作業ができるからである。

くわしくは関数をみよ。

*/


int main()
{
  int i,j;

  /*問題のパズルを代入*/
  
  for(i=0;i<TATE;i++)
    {
      for(j=0;j<YOKO;j++)
	{
	  scanf("%d",&puzzle[i][j]);
	}
    }

  while(1)
    {
      if(DFS(puzzle,-1,0)==1)break;
      limit++;
    }

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

  return 0;
}

int DFS(int P[TATE][YOKO],int not,int hukasa)
{

  int i,j,a,b;
  int zx,zy;//０の位置特定
  int hantei=1;
  int OK;
  int irekae2[TATE][YOKO];
  int H;
  int hata=0;
  
  /*puzzleがAnsとあっているか判定*/

  for(i=0;i<TATE;i++)
    {
      for(j=0;j<YOKO;j++)
	{
	  if(P[i][j]!=Ans[i][j])
	    {
	      hantei=0;
	    }
	   if(P[i][j]==0)
		{
		  zy=i;
		  zx=j;
		}
	}
    }

  if(hantei==1)
    {
      clear=hukasa;
      return 1;//あっていたら1返す。
    }
  else
    {
      for(i=0;i<4;i++)
	{
	  if((i+2)%4==not)continue;
	  
	  if(koukanmae(zx,zy,i)==1)
	    {
	      koukan(P,irekae2,zx,zy,i);
		  
	      H=Heuristic(irekae2);

	      if(hukasa+H<=limit)
		{		
		  hata=DFS(irekae2,i,hukasa+1);
		  if(hata==1)return 1;
		}
	    }
	  
	}
    }
  return 0;
}


int koukanmae(int zx,int zy,int i)
{
  if( zx+x[i]>=YOKO || zx+x[i]<0
      || zy+y[i]>=TATE || zy+y[i]<0 )
    {
      return 0;
    }
  else
    {
      return 1;
    }
}


void koukan(int P[TATE][YOKO],int irekae2[TATE][YOKO],int zx,int zy,int i)
{
  int j,k,koukan;
  
  for(j=0;j<TATE;j++)
    {
      for(k=0;k<YOKO;k++)
	{
	  irekae2[j][k]=P[j][k];
	}
    }
  
  koukan = irekae2[ zy +y[i] ][ zx+x[i] ];
  irekae2[zy][zx]=koukan;
  irekae2[ zy +y[i] ][ zx+x[i] ]=0;

  }


int Heuristic(int s[TATE][YOKO])
{
  int i,j,k=0,H2=0,cell[16],kyori=0;

  for(i=0;i<TATE;i++)
    {
      for(j=0;j<YOKO;j++)
	{
	  cell[k]=s[i][j];
	  k++;
	}
    }
  for(i=0;i<16;i++)
    {
      if(cell[i]!=0)
	{
	  kyori+=abs((cell[i]-1)%4-i%4);
	  kyori+=abs((cell[i]-1)/4-i/4);
	}
    }
  

  return kyori;
}



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

int N;
vector<ll> A;

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

bool check(){
	ll S = 0;
	for(int i = 0; i < N; i++){
		S += A[i];
	}
	for(int i = 0; i < N; i++){
		ll g = gcd(A[i], S - A[i]);
		if(g == 1) return false;
	}
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	cin >> N;

	if(N == 3){
		cout << "2 5 63" << endl;
		return 0;
	}

	vector<int> v0, v2, v3, v4;
	int cnt = 0;
	for(int i = 4; i <= 30000; i++){
		if(i % 2 != 0 && i % 3 != 0) continue;
		if(i % 6 == 0) v0.push_back(i);
		if(i % 6 == 2) v2.push_back(i);
		if(i % 6 == 3) v3.push_back(i);
		if(i % 6 == 4) v4.push_back(i);
	}

	int rem = N - 2;
	int X0 = -1, X2 = -1, X3 = -1, X4 = -1;
	for(int x0 = rem / 4 - 10; x0 <= rem / 4 + 10; x0++){
		for(int x2 = rem / 4 - 10; x2 <= rem / 4 + 10; x2++){
			for(int x3 = rem / 4 - 10; x3 <= rem / 4 + 10; x3++){
				for(int x4 = rem / 4 - 10; x4 <= rem / 4 + 10; x4++){
					if(x0 < 0 || x0 > v0.size()) continue;
					if(x2 < 0 || x2 > v2.size()) continue;
					if(x3 < 0 || x3 > v3.size()) continue;
					if(x4 < 0 || x4 > v4.size()) continue;
					if(x0 + x2 + x3 + x4 != rem) continue;
					ll s = (5 + x2 * 2 + x3 * 3 + x4 * 4) % 6;
					if(s == 0){
						X0 = x0, X2 = x2, X3 = x3, X4 = x4;
					}
				}
			}
		}
	}

	A.push_back(2);
	A.push_back(3);
	for(int i = 0; i < X0; i++){
		A.push_back(v0[i]);
	}
	for(int i = 0; i < X2; i++){
		A.push_back(v2[i]);
	}
	for(int i = 0; i < X3; i++){
		A.push_back(v3[i]);
	}
	for(int i = 0; i < X4; i++){
		A.push_back(v4[i]);
	}
	sort(A.begin(), A.end());
	assert(check());

	for(int i = 0; i < N; i++){
		cout << A[i];
		if(i != N - 1) cout << " ";
	}
	cout << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define cout (cout << setprecision(12))

int combination(int n, int r) {
    int bunbo = 1, bunshi = 1;
    for (int i = 0; i < r; i++) {
        bunshi *= n - i;
        bunbo *= r - i;
    }
    return bunshi / bunbo;
}

int main() {
    int N, M;
    cin >> N >> M;
    cout << combination(N, 2) + combination(M, 2) << endl;
}

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

int main(){
    char st;
    cin >> st;

    if(st=='a' || st=='b' || st=='c' || st=='d' || st=='e' || st=='f' || st=='g' || st=='h' || st=='i' || st=='j' || st=='k' || st=='l' || st=='m' || st=='n' | st=='o' || st=='p' || st=='q' || st=='r' || st=='s' || st=='t' || st=='u' || st=='v' || st=='w' || st=='x' || st=='y' || st=='z'){
        cout << 'a' << endl;
    }else{
        cout << 'A' << endl;
    }
}

Measured memory_bytes: 3564
M = 10**9+7
import sys
input = sys.stdin.readline
 
N,K = map(int, input().split())
A = list(map(int, input().split()))
A_ = sorted(A, reverse = True)
ans = 0
ans_ = 0
for i in range(0,N-1):
        for j in range(i+1,N):
            if A[i] > A[j]:
                ans += 1
            if A_[i] > A_[j]:
                ans_ += 1
 
print(((int((K*(K-1))//2)%M)*ans_+ans*K)%M)

Measured memory_bytes: 41708
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    char c;
    cin>>c;
    int r = c - 'a';
    if(0<=r&&r<26) cout<<'a'<<endl;
    else cout<<'A'<<endl;
}


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

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

    float d,t,s;
    cin >> d >> t >> s;

    if(t >= d/s) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3728
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
data = [0]*n
one = 0
for i in range(n):
  if i%2 == 0:
    one += A[i]
  else:
    one -= A[i]
data[0] = one
for i in range(1,n):
  data[i] = (A[i-1]-data[i-1]//2)*2
print(*data)

Measured memory_bytes: 14664
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ds <- replicateM n $ do
        [a,b] <- getIntList
        return (a+b, b)
    let ans = sum $ zipWith (\k (x,y) -> k*x-y) (cycle [1,0]) $ sortOn Down ds
    print ans

Measured memory_bytes: 52696
#include <stdio.h>
#define Max 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[Max][Max];

void dijkstra(){
  int minv,i,u,v;
  int d[Max],color[Max];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n", i, (d[i] == INFTY ? -1 : d[i]));
  }
}

int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra();
   return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  int n,m;
  int l[100000],r[100000];
  cin >>n>>m;

  int max = 0, min = n;
  for(int i=0; i<m;i++){
      cin >> l[i] >> r[i];
      if(max < l[i]) max = l[i];
      if(min > r[i]) min = r[i];
  }
  if(min>=max){
      cout << (min-max+1);
  }else{
      cout << 0;
  }


  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];
    cout << *max_element(all(a)) - *min_element(all(a)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long

ll A, V, B, W, T;

void YES()
{
	printf("YES");
	exit(0);
}

void NO()
{
	printf("NO");
	exit(0);
}

int main()
{
	scanf("%lld %lld %lld %lld %lld", &A, &V, &B, &W, &T);
	if (A == B) YES();
	if (V < W) NO();
	ll D = abs(A-B);
	ll S = abs(V-W);
	if (D <= T*S) YES();
	else NO();
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)
 
 
int main() {
    int a, b;
    cin >> a >> b;
    int count = 0;
    rep(i, 2) {
        if (a > b) {
            count += a;
            a--;
        } else {
            count += b;
            b--;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,a;
    cin>>N;
    for(int i=0;i<=10000; i += 1000){
        if(i>=N){
            a=i-N;
            cout<<a<<endl;
            break;
        }
    }
    
    return 0;
}

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

using namespace std;
 
int main() {
    int n;cin>>n;
    int a[n];
    for(int i = 0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    cout<<abs(a[0]-a[n-1]);
    return 0;
}

Measured memory_bytes: 3132
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    sum=0
    h=a[0]
    for i in range(1,n):
        if h>a[i]:
            sum+=h-a[i]
        else:
            h=a[i]
    return sum

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)


Measured memory_bytes: 32228
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;


int main()
{
	string S, result, frontR = "", end = "";
	int Q;
	bool reverseFlag = false;

	cin >> S;
	cin >> Q;

	for(int i=0; i<Q; i++){
		int T;
		cin >> T;
		if(T == 1){
			reverseFlag = !reverseFlag;
		}
		else if(T == 2){
			int F;
			string C;
			cin >> F >> C;
			if(reverseFlag == false){
				if(F == 1){
					reverse(C.begin(), C.end());
					frontR += C;
				}
				else if(F == 2){
					end += C;
				}
			}else if(reverseFlag == true){
				if(F == 1){
					reverse(C.begin(), C.end());
					end += C;
				}
				else if(F == 2){
					frontR += C;
				}
			}
		}
	}


	if(reverseFlag == false){
		reverse(frontR.begin(), frontR.end());
		result = frontR + S + end;
	}else if(reverseFlag == true){
		reverse(end.begin(), end.end());
		reverse(S.begin(), S.end());
		result = end + S + frontR;
	}

	cout << result;
	 
	return 0;
	
}

Measured memory_bytes: 1348
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int mod=1000000007,INF=1099999999999999999;



string str,str2;
long long int stralpha[30]={},str2alpha[30]={},now=0;
long long int alpha[30][200005],alphanow[30]={},res=0;
int main() {
	cout << fixed << setprecision(10);
    cin>>str>>str2;
    //cout<<1;
    for(int i=0;i<str.length();i++){
        stralpha[str[i]-'a']++;
    }
    //cout<<2;
    for(int i=0;i<26;i++){
        alphanow[i]=INF;
    }
    for(int i=str.length()-1;i>=0;i--){
        
        alphanow[str[i]-'a']=i;
        for(int j=0;j<26;j++){
            alpha[j][i]=alphanow[j];
        }
    }
    //cout<<3;
    for(int i=0;i<str2.length();i++){
        str2alpha[str2[i]-'a']++;
    }
    for(int i=0;i<=25;i++){
        if(stralpha[i]==0&&str2alpha[i]!=0){
            cout<<-1;
            return 0;
        }
    }
    now=-1;
    for(int i=0;i<str2.length();i++){
        if(alpha[str2[i]-'a'][now+1]==INF||now==str.length()-1){
            res+=str.length();
            now=-1;
        }
        now=alpha[str2[i]-'a'][now+1];
        
    }
    cout<<res+now+1<<endl;
} 


Measured memory_bytes: 40704
#include <bits/stdc++.h>
#define pb push_back
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  string s, za = "zyxwvutsrqponmlkjihgfedcba";
  cin >> s;
  if (s == za) {
    cout << -1 << endl;
    return 0;
  }
  string karis = s;
  for (int i = s.size() - 1; i > 0; i--) {
    if (s[i] > s[i - 1]) {
      ll j;
      for (int k = i; k < s.size(); k++) {
        if (s[k] > s[i - 1])
          j = k;
      }
      swap(karis[j], karis[i - 1]);
      break;
    }
  }
  if (karis == s)
    karis = za;
  for (char i = 'a'; i <= 'z'; i++) {
    bool f = 1;
    for (auto &ss : s) {
      if (ss == i) {
        f = 0;
        break;
      }
    }
    if (!f)
      continue;
    if (karis > s + i)
      karis = s + i;
  }
  for (int i = karis.size() - 1; i > 0; i--) {
    if (karis.substr(0, i) > s) {
      karis = karis.substr(0, i);
    } else
      break;
  }
  cout << karis << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(a,j,n) for(ll i=a;i<j;i=i+n )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    string S;
    cin>>S;
    ll t=S.length();
    bool ans=true;
    if(t%2!=0)cout<<"No";
    else{
        rep(0,t,1){
            if(i%2==0){
                if(S.at(i)!='h'){
                    ans=false;
                    break;
                }
            }
            else if(i%2!=0){
                if(S.at(i)!='i'){
                    ans=false;
                    break;
                }
            }
        }
        if(ans)cout<<"Yes";
        else cout<<"No";
    }
    cout<<endl;


}


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

typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  ll a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a, a+n, greater<int>());
  ll ma=0, mi=0;
  for(int i=1; i<n; i++){
    if(a[i-1]==a[i]){
      if(ma==0){
        ma = a[i];
        i++;
      }
      else if(mi==0){
        mi = a[i];
        break;
      }
    }
  }
  cout << ma*mi << endl;
       
       
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;
#define def 0

int main() {
  //
  ll n, c, k;
  cin >> n >> c >> k;
  vl t(n);
  rep(i, n) cin >> t[i];
  sort(ALL(t));
  ll cnt = 1;
  ll start = t[0];
  ll next = 1;
  while (true) {
    // ride first passenger
    ll tmp = 1;
    while (next < n && t[next] <= start + k && tmp < c) {
      tmp++;
      next++;
    }
    if (next < n) {
      // passenger remains
      start = t[next++];
      cnt++;
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

double calc_dist(pair<double, double> current, pair<double, double> nxt){
    return pow((nxt.first - current.first) * (nxt.first - current.first) + (nxt.second - current.second) * (nxt.second - current.second), 0.5);
}

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

    int n;
    cin >> n;

    vector<pair<double, double>> xy(n);
    for(int i = 0; i < n; ++i){
        double x, y;
        cin >> x >> y;
        xy[i] = make_pair(x, y);
    }
    sort(xy.begin(), xy.end());

    int n_fact = 1;
    for(int i = 1; i <= n; ++i) n_fact *= i;
    
    double sum = 0.0;
     
    do{
        pair<double, double> current = xy[0];
        double dist = 0.0;
        rep1(i, n){
            pair<double, double> nxt = xy[i];
            dist += calc_dist(current, nxt);
            current = nxt;
        }

        sum += dist;

    } while(next_permutation(xy.begin(), xy.end()));

    printf("%.10f\n", sum / n_fact);


    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());

    String s = sc.nextLine();
    String[] a = s.split(" ", 0);

    int min = getMin(a);
    int max = getMax(a);

    int d = max - min;
    System.out.println(d);
  }

  public static int getMin(String[] a){
    int min = 10000;
    for(int i = 0; i < a.length; i++) {
        int t = Integer.parseInt(a[i]);
        if(min > t) {
            min = t;
        }
    }
    return min;
  }

  public static int getMax(String[] a){
    int max = -1;
    for(int i = 0; i < a.length; i++) {
        int t = Integer.parseInt(a[i]);
        if(max < t) {
            max = t;
        }
    }
    return max;
  }
}



Measured memory_bytes: 21204
unittest
{
	assert( [ "4 2", "1 1 3 4" ].solve == 11 );
	assert( [ "6 3", "10 10 10 -10 -10 -10" ].solve == 360 );
	assert( [ "3 1", "1 1 1" ].solve == 0 );
	assert( [ "10 6", "1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0" ].solve == 999998537 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as.sort;
	
	// maxの合計を計算
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( 0L );
	foreach( i; k - 1 .. n )
	{
		ans += as[ i ] * i.combination!M( k - 1 );
	}
	
	// minの合計を計算してmaxの合計から引く
	foreach( i; 0L .. n - k + 1 )
	{
		ans -= as[ i ] * ( n - 1 - i.signed ).combination!M( k - 1 );
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	this( long n ){ this.n = n % M; }
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	auto opEquals( ModWorld r ){ return this.n == r.n; }
	
	void opAssign( long r ){ this.n = r % M; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}

// 階乗
auto factorial( long M )( long n )
{
	static memo = [ ModWorld!M( 1L ) ];
	if( memo.length <= n )
	{
		auto i = memo.length.signed;
		memo.length = n + 1;
		for( ; i <= n; i++ ) memo[ i ] = memo[ i - 1 ] * i;
	}
	return memo[ n ];
}

// 組み合わせ数
auto combination( long M )( long n, long k )
{
	if( n < k ) return ModWorld!M( 0L );
	else        return n.factorial!M / ( k.factorial!M * ( n - k ).factorial!M );
}


Measured memory_bytes: 8340
X = int(input())

if 400<=X<=599:
  print('8')
elif 600<=X<=799:
  print('7')
elif 800<=X<=999:
  print('6')
elif 1000<=X<=1199:
  print('5')
elif 1200<=X<=1399:
  print('4')
elif 1400<=X<=1599:
  print('3')
elif 1600<=X<=1799:
  print('2')
elif 1800<=X<=1999:
  print('1')

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

int main() {
  int N,t=0;
  long B=0;
  cin >> N;
  vector<long> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  for(int i=0; i<N; i++){
    if(A.at(i)<0){
      A.at(i)=(-1)*A.at(i);
      t++;
    }
  }
  sort(A.begin(),A.end());
  for(int i=1; i<N; i++){
    B+=A.at(i);
  }
  if(t%2==1){
    cout << B-A.at(0) << endl;
  }
  else{
    cout << B+A.at(0) << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>


int main()
{
    int q,ope;
    long long num;
    std::cin>>q;
    std::set<long long> S;
    
    for(int i = 0; i < q; i++)
    {
        std::cin>>ope>>num;
        if(ope==1){std::cout<<S.count(num)<<std::endl;}
        else if(ope==0){S.insert(num);std::cout<<S.size()<<std::endl;}
        else{S.erase(num);}
    } 
    return 0;
}



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

using namespace std;

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


int main()
{
  vector<int> v(3,0);
  cin >> v[0] >> v[1] >> v[2];
  int d;
  cin >> d;
  if ((abs(v[1] - v[0]) <= d && abs(v[2] - v[1]) <= d) || abs(v[2] - v[0]) <= d) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

long long D = 365, type = 26, inf = 1001001001;
vector<long long> C(type);
vector<vector<long long>> S(D,vector<long long>(type));

struct STR{
  long long score;
  vector<long long> ans;
  vector<long long> last;
};
bool operator<(const STR &left, const STR &right) {
  if(left.score<right.score) return true;
  else return false;
}

void input(){
  cin >> D;
  for(int i=0;i<type;i++) cin >> C[i];
  for(int i=0;i<D;i++){
    for(int j=0;j<type;j++){
      cin >> S[i][j];
    }
  }
  return;
}

long long calc(long long day, long long t, vector<long long> &last){
  long long score = S[day][t];
  for(int i=0;i<type;i++){
    score -= C[i] * (day - last[i]);
  }
  return score;
}

int main(){
  input();
  
  long long score = 0;
  vector<long long> last(type,-1), V(0);
  vector<priority_queue<STR>> Q(D+1);
  STR s = {score,V,last};
  Q[0].push(s);
  for(int i=0;i<D;i++){
    for(int j=0;j<10;j++){
      if(Q[i].empty()) break;
      STR str = Q[i].top();
      Q[i].pop();
      
      for(int k=0;k<type;k++){
        long long x = calc(i,k,str.last);
        vector<long long> y = str.last, z = str.ans;
        y[k] = i;
        z.push_back(k);
        STR str2 = {x,z,y};
        Q[i+1].push(str2);
      }
    }
  }
  
  vector<long long> ans = Q[D].top().ans;
  for(int i=0;i<D;i++) cout << ans[i]+1 << endl;
  return 0;
}


Measured memory_bytes: 162144
s_input = input()                                                                   
s = list(s_input)                                                                   
s_reverse = list((reversed(s_input)))                                               
                                                                                    
count = 0                                                                           
for i in range(int(len(s)/2)):                                                      
    if s[i] != s_reverse[i]:                                                        
        count += 1                                                                  
                                                                                    
print(count)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int count(int counter, int in) {
	if (in == 0) return counter;
	counter += in % 10;
	in /= 10;
	int c = count(counter, in);
}
int main() {
	int N;
	int A[200];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] & 1 == 1) {
			cout << 0 << endl;
			return 0;
		}
		else {
			A[i] = A[i] >> 1;
		}
	}
	int count = 1;
	while (1) {
		for (int i = 0; i < N; i++) {
			if (A[i] & 1 == 1) {
				cout << count << endl;
				return 0;
			}
			else {
				A[i] = A[i] >> 1;
			}
		}
		count++;
	}
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        av: [Usize1; n - 1],
    };
    let mut cv = vec![0_usize; n];
    for a in av {
        cv[a] += 1;
    }
    for c in cv {
        println!("{}", c);
    }
}


Measured memory_bytes: 6304
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int main()
{
	string s;
	cin>>s;
	int ans=9*s.size()+s[0]-'0'-10,sum=0;
	for(int i=0;i<(int)s.size();i++)sum+=s[i]-'0';
	cout<<max(ans,sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k, d, t, r = 0;
    cin >> n >> k;
    vector<bool> s(n + 1,false);

    while (k--) {
        cin >> d;
        while (d--) {
            cin >> t;
            s[t] = true;
        }
    }

    for (vector<bool>::iterator it = s.begin() + 1; it < s.end(); ++it)
        if (!*it) ++r;

    cout << r;

    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,n,i,j,k,x,y;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0<<endl;
    }
    else
    {
        k=n/1000;
        k+=1;
        j=k*1000-n;
        cout<<j<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	char a;
	cin>>a;
	if(a=='A')
		cout<<'T'<<endl;
	else if(a=='T')
		cout<<'A'<<endl;
	else if(a=='G')
		cout<<'C'<<endl;
	else
		cout<<'G'<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string x;cin>>x;
    bool kurisagari=false;
    int ans=0;
    for(int i=0;i<x.size();i++){
        if(i==0)ans+=x[i]-'0';
        else{
            if(x[i]!='9'){
                if(kurisagari)ans+=9;
                else{
                    kurisagari=true;
                    ans+=8;
                }
            }
            else ans+=9;
        }
    }
    cout<<ans<<endl;
}


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

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

int main() {
    int n; ll x;
    cin >> n >> x;
    vector<ll> p;
    for(int i=0; i<n; i++){
        ll px;
        cin >> px;
        if(x-px < 0) {
            p.push_back(-(x-px));
        }
        else if(x-px > 0){
            p.push_back(x-px);
        }
        else{
            continue;
        }
    }
    if(p.size() == 0) {
        cout << 0 << endl; 
        return 0;
    }
    else if(p.size() == 1){
        cout << p.at(0) << endl;
        return 0;
    }
    else{
        ll ans;
        for(int i=0; i<p.size()-1; i++){
            ans = gcd(p.at(i),p.at(i+1));
            p.at(i+1) = ans;
        }
        cout << ans << endl;
        return 0;
    }
}

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int sum_keta(int n){
  if(n==0) return 0;
  return n%10 + sum_keta(n/10);
}
int main(void){
  int N,X; cin >> N >> X;
  
  int localmin = 1001;
  for(int i=0;i<N;i++){
  	int m; cin >> m;
    X -= m;
    localmin = min(localmin,m);
  }
  cout << N + X/localmin << endl;
}

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

int main(){
    ll N;
    cin >> N;
    vector<pair<ll,ll>> a(N);
    rep(i, 0, N){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    ll neg = a[0].first;
    ll pos = a[N-1].first;
    vector<ll> ans;
    rep(i, 1, N-1){
        if(a[i].first < 0){
            ans.push_back(pos);
            pos -= a[i].first;
        }else{
            ans.push_back(neg);
            neg -= a[i].first;
        }
    }
    cout << pos - neg << endl;
    rep(i, 1, N-1){
        cout << ans[i-1] << " " << a[i].first << endl;
    }
    cout << pos << " " << neg << endl;
    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;

int main(){
    lint N,ans=0;
    cin>>N;
    vector <lint> A;
    rep(i,N){
        lint s;
        cin>>s;
        A.push_back(s);
    }
    rep(i,N){
        lint x;
        if(i==0){
            x=A[i]/2;
            ans+=x;
            A[i]-=x*2;
        } else{
            if(A[i-1]>0&&A[i]>0){
                    ans++;
                    A[i]-=1;
            }
            x=A[i]/2;
            ans+=x;
            A[i]-=x*2;
        }

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1400
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

odd_1st = Counter(v_odd).most_common()[0][1]
even_1st = Counter(v_even).most_common()[0][1]
if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - odd_1st
    number_of_rewrites += len(v_even) - even_1st
else:
    odd_2nd = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
    even_2nd = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0

    if odd_2nd >= even_2nd:
        number_of_rewrites = len(v_odd) - odd_2nd + len(v_even) - even_1st
    else:
        number_of_rewrites = len(v_odd) - odd_1st + len(v_even) - even_2nd
    # number_of_rewrites = min(
    #     len(v_odd) - odd_1st + len(v_even) - even_2nd,
    #     len(v_odd) - odd_2nd + len(v_even) - even_1st,
    # )

print(number_of_rewrites)


Measured memory_bytes: 17548
using System;
using System.Collections.Generic;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var goal = IOUtils.ReadNums().First();

            long n = 1;
            long sum = 0;

            while(n <= goal)
            {
                if (n % 3 != 0 && n % 5 != 0)
                {
                    sum += n;
                }
                n++;
            }

            Console.WriteLine(sum);
        }
    }

    static class IOUtils
    {
        public static IEnumerable<int> ReadNums()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v));
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


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

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

int main() {
  int64_t a,b,c,d,cd,ans=0,i;
  cin >> a >> b>> c >>d;
  cd=gcd(c,d);
  cd=c*d/cd;
  ans+=b-a+1;
  ans-=-(a-1)/c+b/c;
  ans-=-(a-1)/d+b/d;
  ans+=-(a-1)/cd+b/cd;
  cout << ans << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;  
  	int k,a,b;
  	cin>>k>>a>>b;
  	for(int i=a;i<=b;++i)
    {
      if(i%k==0)
      {
        cout<<"OK";
        return 0;
      }
    }
      cout<<"NG";
}

Measured memory_bytes: 3592
import sys
def input():
    return sys.stdin.readline()[:-1]

S = input()
L = len(S)
if not L%2==0:
    print('No')
    exit()
i = 0
while i<L:
    if not S[i:i+2]=='hi':
        print('No')
        exit()
    i+=2
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int arr[5];
    int ans;
    rep(i,0,5){
        cin>>arr[i];
        if(arr[i]==0)ans=i+1;
    }
    cout<<ans;


 
return 0;
}

Measured memory_bytes: 3648
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    d, x = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(n):
        a = int(input().rstrip('\n'))
        cnt += ((d + a - 1) // a)
    print(cnt + x)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string l;

    static ll dp[100010][2];

    dp[0][0] = 1;

    cin >> l;

    for (int i = 0; i < l.size(); i++)
    {
        ll d = l[i] - '0';

        if (d == 1)
        {
            dp[i + 1][1] = ((dp[i][1] * 3) % MOD + dp[i][0]) % MOD;
            dp[i + 1][0] = (dp[i][0] * 2) % MOD;
        }
        else
        {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = (dp[i][1] * 3) % MOD;
        }

        dp[i][0] %= MOD;
        dp[i][1] %= MOD;
    }

    cout << (dp[l.size()][0] + dp[l.size()][1]) % MOD << endl;
}

Measured memory_bytes: 2048
import fractions

N,M=map(int,input().split())
A=list(map(int,input().split()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def kn(h):
  l=0
  while h%2==0:
    h=h//2
    l+=1
  return l
  
k=1
flag=kn(A[0]//2)
for a in A:
  a//=2
  k=lcm(k,a)
  if flag != kn(a):
    print(0);exit()
  
print(int(M//k//2+M//k%2))



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

bool solve(int k, string s) {
    vector<int> v(s.size() + 1, 0);
    int n = s.size();
    for (int i = n - k; i < k; i++) {
        v[i] = i ? v[i - 1] + v[i] : 0;
        int x = s[i] - '0';
        if ((x + v[i]) % 2 != 0) {
            if (i + k - 1 < s.size())
                v[i]++, v[i + k]--;
            else
                return false;
        }
    }
    return true;
}

int binary_search(int ok, int ng, string s) {
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (solve(mid, s)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

int main() {
    string s;
    cin >> s;
    cout << binary_search(1, s.size() + 1, s) << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}

const ll INF = 1LL<<60;

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

    ll ans = INF;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ll a, b;
            a = i;
            b = n / i;
            ans = min(ans, a + b - 2);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256