akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int first = sc.nextInt();
		int last = sc.nextInt();
		boolean bit[] = new boolean[num];
		int index[] = new int[num];
		int sum = 0;
		for(int i = 0; i < num; i ++) {
			bit[i] = (first & (1 << i)) != (last & (1 << i));
			sum += bit[i] ? 1 : 0;
			index[bit[i] ? sum - 1 : num - (i - sum) - 1] = i;
		}
		if(sum % 2 == 0) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
			int max = (int)Math.pow(2, num);
			int tmp = first;
			int change[] = new int[num];
			System.out.print(tmp+" ");
			for(int i = 1; i < max; i ++) {
				int crtIndex = 0;
				for(; crtIndex < num; crtIndex ++) {
					if((i & (1 << crtIndex)) != 0) {
						break;
					}
				}
				crtIndex = num - crtIndex - 1;
				if(bit[index[crtIndex]] && crtIndex != 0) {
					if(crtIndex % 2 == 0) {
						if(change[crtIndex] < 2) {
							change[crtIndex] ++;
							crtIndex --;
						}
					}else {
						if(change[crtIndex] < 1) {
							change[crtIndex] ++;
							crtIndex ++;
						}
					}
				}
				int crtDigit = 1 << index[crtIndex];
				tmp = (tmp & crtDigit) != 0 ? tmp - crtDigit : tmp + crtDigit;
				System.out.print(tmp+" ");
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 44092
#include <bits/stdc++.h>
using namespace std;
/*
 
int n, int k will be given.
 the number of jumps can be i+1, i+2, i+3, i+4,...i+k;
 initially at stone 1.
 n >= 2given value,
 
 
 */
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i =0; i < n; i++) {
        cin >> h[i];
    }
    // we will now build a dp vector.
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    // we now need to write a nested loop.
    for(int i = 1; i < n; i++){
        // if we are coming from some place.
        // the previous part in the dp array , we need to add it.
        for(int j = 1; j <= k; j++){
            // now if j = 1,
            // we add the number from past dp and the difference of two numbes.
            if(i < j) {break;}
            else {
                dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
                
            }
        }
        
    }
    cout << dp[n-1] << endl;
    return 0;

}













Measured memory_bytes: 1024
ALPHABET = range(ord('A'), ord('Z') + 1)


def enc(k, m):
    # """enc(秘密鍵 k, 平文 m) = 暗号文 c"""
    hira = list(m.encode("ascii"))  # 文字列から文字コードの配列へ変換
    ango = hira.copy()  # 暗号文（のコード）格納用配列
    for i, code in enumerate(hira):
        offset = code - ALPHABET[0]  # 文字 a からの差分
        if 0 <= offset <= ALPHABET[-1]-ALPHABET[0]:  # 英小文字ならば …
            offset += k
            offset %= len(ALPHABET)
        ango[i] = offset + ALPHABET[0]  # 暗号文用のコードの格納
    c = bytes(ango).decode("ascii")  # コードの配列を文字列に直す
    return c


n = int(input())
s = input()
angobun = enc(n, s)
print(angobun)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define LOG 19
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less< i64 >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int dis[105][105] ;

char s[105][105] ;

int n , m ;

bool isValid(int x, int y)
{
    if( x>n || x<1 || y>m || y<1 ) return 0 ;
    return 1 ;
}

int cost(int x1, int y1, int x2, int y2)
{
    if( s[x1][y1] =='.' && s[x2][y2] == '#' ) return 1 ;
    return 0 ;
}

int dx[] = {0,1} ;
int dy[] = {1,0} ;

int bfs()
{
    for(int i=1 ; i<=n ; i++) for(int j=1 ; j<=m ; j++) dis[i][j] = n*m + 5 ;

    deque< pair<int,int> > dq ;
    if( s[1][1] == '#' ) dis[1][1] = 1 ;
    else dis[1][1] = 0 ;
    dq.push_front(mp(1,1)) ;

    while( !dq.empty() )
    {
        pair<int,int> p = dq.front() ;
        dq.pop_front() ;
        for(int i=0 ; i<2 ; i++)
        {
            int x = p.xx+dx[i] , y = p.yy+dy[i] ;
            if( !isValid(x,y) ) continue ;
          //  if( dis[x][y] != -1 ) continue ;

            if( dis[x][y] <= dis[p.xx][p.yy] + cost(p.xx,p.yy,x,y) ) continue ;

            if( cost(p.xx,p.yy,x,y) == 1 )
            {
                dq.push_back(mp(x,y)) ;
                dis[x][y] = dis[p.xx][p.yy] + 1;
            }
            else
            {
                dq.push_front(mp(x,y) ) ;
                dis[x][y] = dis[p.xx][p.yy] ;
            }
        }
    }
    return dis[n][m] ;
}

int main()
{
    scanf("%d %d",&n,&m) ;

    for(int i=1;  i<=n ; i++)
    {
        scanf("%s",s[i]+1) ;
    }

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

    return 0 ;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
class matrix {
	int n;
	vector<vector<int>> vec;
	void letMeasure() {
		rep(i, n) {
			rep(j, n) {
				if (i != j)vec[i][j] = 0;
				else vec[i][j] = 1;
			}
		}
	}
public:
	matrix(int n) {
		this->n = n;
		vec.resize(n, vector<int>(n));
	}
	matrix(int n, vector<int> vec) {
		if (vec.size() != n * n) {
			cerr << "Invalid construct of matrix" << endl;
			exit(1);
		}
		this->n = n;
		this->vec.resize(n, vector<int>(n));
		rep(i, n) {
			rep(j, n)this->vec[i][j] = vec[i * n + j];
		}
	}
	int operator[](int a) {
		return vec[a / n][a % n];
	}
	unsigned int size() {return n;}
	matrix operator*(const matrix a) {
		if (this->n != a.n) {
			cerr << "Invalid maltiply of matrix" << endl;
			exit(1);
		}
		vector<int> memo(n);
		rep(i, n) {
			rep(j, n) {
				rep(k, n) {
					memo[j] += vec[i][k] * a.vec[k][j];
				}
			}
			vec[i] = memo;
			memo.clear();
			memo.resize(n);
		}
		return *this;
	}
	matrix letmod(int m) {
		rep(i, n) {
			rep(j, n)vec[i][j] %= m;
		}
		return *this;
	}
	static matrix measure(int n) {
		matrix res(n);
		res.letMeasure();
		return res;
	}
};
matrix mypow(matrix a, int b, int m) {
	a.letmod(m);
	if (!b)return matrix::measure(a.size());
	if (b % 2)return (mypow(a, b - 1, m) * a).letmod(m);
	matrix memo = mypow(a, b / 2, m);
	return (memo * memo).letmod(m);
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b % 2)return mypow(a, b - 1)* a;
	int memo = mypow(a, b / 2);
	return memo * memo;
}
int l, a, b, m;
signed main() {
	cin >> l >> a >> b >> m;
	int c = a + b * (l - 1);
	int ans[3] = { 0,a % m,1 };
	for (int i = 1; i <= 18; i++) {
		if (mypow(10, i) <= a)continue;
		int cnt;
		if (mypow(10, i) > c) {
			if (mypow(10, i - 1) >= a)cnt = (c - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
			else cnt = (c - a + b) / b;
		}
		else {
			if (mypow(10, i - 1) >= a)cnt = (mypow(10, i) - 1 - a + b) / b - (mypow(10, i - 1) - 1 - a + b) / b;
			else cnt = (mypow(10, i) - 1 - a + b) / b;
		}
		if (cnt < 0)break;
		vector<int> vec{ mypow(10,i) % m,0,0,1,1,0,0,b % m,1 };
		matrix mat(3, vec);
		mat = mypow(mat, cnt, m);
		int memo[3] = { ans[0],ans[1],ans[2] };
		ans[0] = (memo[0] * mat[0] % m + memo[1] * mat[3] % m + memo[2] * mat[6] % m) % m;
		ans[1] = (memo[0] * mat[1] % m + memo[1] * mat[4] % m + memo[2] * mat[7] % m) % m;
	}
	cout << ans[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    map<int,vector<P>> a;
    rep(i,n) {
        int b; cin>>b;
        rep(j,b) {
            int x,y; cin>>x>>y;
            --x;
            a[i].emplace_back(x,y);
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1<<n); ++bit) {
        // 0 = unkind, 1 = honest
        bool ok = true;
        int v = bit;
        vector<int> t(n,2);
        rep(i,n) {
            if (bit&(1<<i)) t[i] = 1;
            else t[i] = 0;
        }
        rep(i,n) {
            if (bit&(1<<i)) {
                for (auto &&e: a[i]) {
                    int x = e.first; int y = e.second;
                    if (t[x]!=y) ok = false; 
                }
            }
        }
        rep(i,n) {
            if (bit&(1<<i)) {
                for (auto &&e: a[i]) {
                    int x = e.first; int y = e.second;
                    if (t[x]==2) {
                        t[x] = y;
                    }
                    else if (t[x]!=y) ok = false;
                }
            }
        }

        if (ok) {
            int tmp = __builtin_popcount(bit);
            chmax(ans,tmp);
        }
    }

    cout << ans << endl;
    return 0;
}

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

int x;
int dp[101000];
vector<int> cost = {100,101,102,103,104,105};
// -1 not checked yet

bool dfs(int sum){
    if(dp[x] == 1) return true;
    if(dp[sum] == 0) return false;

    if(sum == x) return dp[sum] = 1;
    if(sum > x) return dp[sum] = 0;
    
    for(int i = 0; i < 6; i++){
        if(dfs(sum + cost[i])) return true;
        else dp[sum] = 0;
    }
    return false;
}


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

    cin >> x;
    rep(i,101000) dp[i] = -1;
    
    bool ans = false;
    for(int i = 0; i < 6; i++){
        if(dfs(0)){
            ans = true;
            break;
        }
    }
    
    if(ans) cout << 1 << endl;
    else cout << 0 << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>  
#define xx first  
#define yy second  
#define mp make_pair  
#define pb push_back  
#define fill( x, y ) memset( x, y, sizeof x )  
#define copy( x, y ) memcpy( x, y, sizeof x )  
using namespace std;  
  
typedef long long LL;  
typedef pair < int, int > pa;  
  
const int MAXN = 100010;  
  
int n, x[MAXN], a[MAXN], w[MAXN], L, T;  
LL cur;  
  
int main()  
{  
#ifdef wxh010910  
 //   freopen( "data.in", "r", stdin );  
#endif  
    scanf( "%d%d%d", &n, &L, &T );  
    for( int i = 0 ; i < n ; i++ )  
    {  
        scanf( "%d%d", &a[ i ], &w[ i ] );  
        if( w[ i ] == 1 )  
        {  
            x[ i ] = ( a[ i ] + T ) % L;  
            cur += ( a[ i ] + T ) / L;  
        }  
        else  
        {  
            x[ i ] = ( a[ i ] - T ) % L;  
            cur += ( a[ i ] - T ) / L;  
            if( x[ i ] < 0 ) x[ i ] += L, cur--;  
        }  
    }  
    cur = ( cur % n + n ) % n;  
    sort( x, x + n );  
    for( int i = cur ; i < n ; i++ ) printf( "%d\n", x[ i ] );  
    for( int i = 0 ; i < cur ; i++ ) printf( "%d\n", x[ i ] );  
}  

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N,Q;
int A[2<<17],B[2<<17];
main()
{
	cin>>N>>Q;
	N*=2;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	int bc=0;
	long sum=0;
	vector<int>init(N);
	for(int i=0;i<N;i++)
	{
		if(i==0||i==N-1||A[i]>=B[i])
		{
			sum+=A[i];
			init[i]=A[i]-B[i];
		}
		else
		{
			sum+=B[i];
			init[i]=B[i]-A[i];
			bc++;
		}
	}
	segtree<int>P(N);
	P.copy(init);
	for(;Q--;)
	{
		int p,x,y;cin>>p>>x>>y;p--;
		if(p==0||p==N-1||A[p]>=B[p])
		{
			sum-=A[p];
		}
		else
		{
			sum-=B[p];
			bc--;
		}
		A[p]=x;B[p]=y;
		if(p==0||p==N-1||A[p]>=B[p])
		{
			sum+=A[p];
			P.update(p,A[p]-B[p]);
		}
		else
		{
			sum+=B[p];
			P.update(p,B[p]-A[p]);
			bc++;
		}
		long now=sum;
		if(bc%2)now-=P.query(1,N-1);
		cout<<now<<endl;
	}
}


Measured memory_bytes: 6144
#include<cstdio>
#include<cstring>
char s[1005];
bool S, E, N, W;
bool a, b;
int main() {
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'S') S = true;
		if (s[i] == 'E') E = true;
		if (s[i] == 'N') N = true;
		if (s[i] == 'W') W = true;
	}
	if (S) a = !a;
	if (E) b = !b;
	if (N) a = !a;
	if (W) b = !b;
	if (a || b) printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
public class Main {
	
	public static void main(String[] args) throws IOException {
		int a, b, c, sum = 0;

		String[] str = new BufferedReader(new InputStreamReader(System.in)).readLine().split(" ");
		
		a = Integer.parseInt(str[0]);
		b = Integer.parseInt(str[1]);
		c = Integer.parseInt(str[2]);
				
		for (int i = a; i <= b; i++) sum += c %i == 0 ? 1 : 0;
				
		System.out.println(sum);
	}
}

Measured memory_bytes: 24476
# coding: utf-8
import time
import re
import math
import fractions

def main():
    N,D=map(int,input().split())
    points=[]
    for a in range(N):
        points.append(list(map(int,input().split())))
        count=0
    for a in range(N):
        for b in range(a+1,N):
            if getD(points[a],points[b])%1==0:
                count+=1
    print(count)
def getD(xarr,yarr):
    d=0
    for a in range(len(xarr)):
        d+=(xarr[a]-yarr[a])**2
    return math.sqrt(d)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#N=int(input())



Measured memory_bytes: 5300
#include<iostream>
using namespace std;
int main(){
	int temp,a,b,w,c1,c2;
	cin>>w>>a>>b;
	 c1=a-b;
	 if(c1<0)
	 c1=-c1;
	 if(c1>w)
	 c1-=w;
	 else
	 c1=0;
	cout<<c1;
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let N: i64 = read_line().parse().unwrap();
    let mut min_load: i64 = read_line().parse().unwrap();
    for i in 0..4 {
        min_load = std::cmp::min(min_load, read_line().parse().unwrap());
    }
    let ans = (N+min_load-1) / min_load + 4;
    println!("{}", ans);
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    lint ans = 0;
    for_(i,1,N+1) {
        if (i % 3 != 0 and i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;

int gcd(int a, int b) {return a%b == 0 ? b : gcd(b,a%b);}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    queue<int> q;
    for (int i=0;i<N;i++){
        cin >> a[i];
        q.push(a[i]);
    }
    // a[i] = 1から順に処理していく
    int num = 1;
    int brk = 0;
    while (!q.empty()) {
        int t = q.front();q.pop();
        if (t != num) {
            brk++;
        } else {
            num++;
        }
    }
    if (num == 1) cout << -1 << endl;
    else cout << brk << endl;

    return 0;
}

Measured memory_bytes: 1792
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#endif
using namespace std;

template <typename T>
void print(T& seq) {
  for (auto it = seq.begin(); it != seq.end(); ++it) {
    cout << *it;
    if (distance(it, seq.end()) != 1) {
      cout << " ";
    }
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  list<int> seq;
  for (int t, i = 0; i < n; ++i) {
    cin >> t;
    seq.push_back(t);
  }

  print(seq);
  for (auto it = next(seq.begin()); it != seq.end();) {
    auto it2 = find_if(seq.begin(), it, [&](int v) { return v > *it; });
    seq.insert(it2, *it);
    it = seq.erase(it);
    print(seq);
  }
}

Measured memory_bytes: 3072
import math
s = input()
n = len(s)
ans = [0] * n
i = 0
while i < n:
    r = 0
    while s[i] == 'R':
        r += 1
        i += 1
    ans[i-1] += math.ceil(r / 2)
    ans[i] += math.floor(r / 2)
    l = 0
    while i < n and s[i] == 'L':
        l += 1
        i += 1
    ans[i-l-1] += math.floor(l / 2)
    ans[i-l] += math.ceil(l / 2)
print(' '.join([str(x) for x in ans]))

Measured memory_bytes: 10484
#include <cstdio>
struct Istream {
	template <class T>
	Istream &operator >>(T &x) {
		static char ch;static bool neg;
		for(neg=0,ch=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
		for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
		x=neg?-x:x;
		return *this;
	}
}is;
struct Ostream {
	template <class T>
	Ostream &operator <<(T x) {
		x<0 && (putchar('-'),x=-x);
		static char stack[233];static int top;
		for(top=0;x;stack[++top]=x%10+'0',x/=10);
		for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
		return *this;
	}
	Ostream &operator <<(char ch) {
		putchar(ch);
		return *this;
	}
}os;
#include <algorithm>
#define int64 long long
int main() {
	//freopen("input","r",stdin);
	int64 n,a,b;is>>n>>a>>b;
	int64 Ans=((n-1)*b+a)-((n-1)*a+b)+1;
	os<<std::max(Ans,0ll)<<'\n';
	return 0;
}




Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};


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

	int n;
	cin >> n;

	vector<int> a(n+1);
	vector<vector<int> > bits(n+1, vector<int>(62));

	reps(i,n){
		cin >> a[i];
		bits[i] = bits[i-1];
		rep(j,62){
			if(1LL << j & a[i]){
				bits[i][j]++;
			}
		}
	}

	int res = 0;

	reps(i,n-1){
		rep(j,62){
			if(1LL << j & a[i]){
				(res += (1LL << j) % mod1 * ((n-i) - (bits[n][j] - bits[i][j])) % mod1) %= mod1;
			}else{
				(res += (1LL << j) % mod1 * (bits[n][j] - bits[i][j]) % mod1) %= mod1;
			}
		}
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 159616
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var l : MutableList<Long> = mutableListOf(2,1)
    var L = 0L
    (2..N).map{i->
        L = l[i-1] + l[i-2]
        l.add(L)
    }
    println(l[l.size-1])
}


Measured memory_bytes: 33788
n = gets.to_i

f = [nil]

for i in 1..n do
  f.push(gets.chomp.split(' ').map(&:to_i).unshift(nil))
end

p = [nil]
for i in 1..n do
  p.push(gets.chomp.split(' ').map(&:to_i))
end


pkiroku = []
nums = [1,2,3,4,5,6,7,8,9,10]
for i in 1..10 do
  nums.combination(i).to_a.each do |c|
    misetasu = []
    for j in 1..n do
      count = 0
      c.each{|k|
        count +=1 if f[j][k] == 1
      }
      misetasu.push(p[j][count])
    end
    pkiroku.push(misetasu.inject(:+))
  end
end

puts pkiroku.max

Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int):
    result_list = []
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            result_list.append(i - 1 + N // i - 1)
        else:
            pass
    print(min(result_list))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12404
#include <iostream>
using namespace std;
int a, b, c, d, e, f, answ, anss;
double mx = -1;
bool vsd[3001][3001];
void g(int w, int s){
    if(w+s > f || 100*s > w*e || vsd[w][s]) return;
    vsd[w][s] = true;
    g(w+100*a, s);
    g(w+100*b, s);
    g(w, s+c);
    g(w, s+d);
    
    if(w + s  <= 0)return;
    double res = 100 * s / (double)(w+s);
    if(res > mx){
        answ = w;
        anss = s;
        mx = res;
    }
}
int main(void){
    cin >> a >> b >> c >> d >> e >> f;
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            vsd[i][j] = false;
        }
    }
    g(0, 0);
    cout << answ+anss << " " << anss << endl;
}


Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

#define FOR(i,k,n) for(ll (i)=(k);(i)<(n);(i)++)
#define REP(i,n) FOR((i),0,(n))

ll N, Q;
vector<vector<ll>> edges;
vector<pair<ll, ll>> query;


void input() {
	ll a, b;
	cin >> N;
	edges.resize(N);

	REP(i, N) {
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	cin >> Q;
	REP(i, Q) {
		cin >> a >> b;
		a--; b--;
		query.push_back({ a,b });
	}
}

bool search(vector<bool>& went, vector<int>& route)
{
	int now = route.back();
	for (auto next : edges[now]) {
		if (route.size() > 1 && route[route.size() - 2] == next)continue;
		if (went[next]) {
			route.push_back(next);
			return true;
		}
		went[next] = true;
		route.push_back(next);
		if (search(went, route))return true;

		went[next] = false;
		route.pop_back();
	}
	return false;
}

void output(const vector<int>& route) {
	for (auto q : query) {
		if (binary_search(route.begin(), route.end(), q.first) &&
			binary_search(route.begin(), route.end(), q.second)) {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
}

int main() {	
	input();
	vector<bool> went(N, false);
	vector<int> subroute, route;

	subroute.push_back(0);
	search(went, subroute);
	int id = 0;
	while (subroute[id] != subroute.back())id++;
	FOR(i, id + 1, subroute.size())route.push_back(subroute[i]);
	sort(route.begin(), route.end());
	/*
	for (auto tmp : subroute)cout << tmp << " ";
	cout << endl;
	for (auto tmp : route)cout << tmp << " ";
	cout << endl;
	*/
	output(route);
	cin >> N;
	return 0;
}


Measured memory_bytes: 18796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            int num = i + (N - 1 - j);
            if (num > K) continue;
            vector<ll> a;
            for (int n = 0; n < i; n++) {
                a.emplace_back(v[n]);
            }
            for (int m = j + 1; m < N; m++) {
                a.emplace_back(v[m]);
            }
            sort(a.begin(), a.end());
            ll sum = accumulate(a.begin(), a.end(), 0);
            for (int k = 0; k < K - num && k < a.size(); k++) {
                if (a[k] < 0) sum += abs(a[k]);
            }
            ans = max(sum, ans);
        }
    }

    if (K >= N) {
        ll sum = accumulate(v.begin(), v.end(), 0);
        sort(v.begin(), v.end());
        for (int i = 0; i < K - N && i < N; i++) {
            if (v[i] < 0) sum += abs(v[i]);
        }
        ans = max(ans, sum);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import *
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
a=[]
for i in range(n):
  for j in range(n):
    if i==j:continue
    a+=[(x[i]-x[j],y[i]-y[j])]
c=list(Counter(a).values())
print(n-max(c) if c else n)

Measured memory_bytes: 72024
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;
const int maxn=200+10;
int vis[maxn][maxn];
struct Node
{
    int x,y;
    Node(){}
    Node(int a,int b):x(a),y(b){}
};
vector<Node >G;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    if(n==0)
    {
         printf("-1\n");
        return 0;
    }
    int m=n-1;
    int sum=(m)*(m-1)/2;
    if(k>sum)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=m;i++)
    {
        G.push_back(Node(i,n));
    }

    int i=1,j=2;
    while(sum!=k)
    {
        sum--;
        G.push_back(Node(i,j));
        j++;
        if(j==m+1) i++,j=i+1;
    }

    printf("%d\n",G.size());
    for(int i=0;i<G.size();i++)
    {
        printf("%d %d\n",G[i].x,G[i].y);
    }
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();
		int ans = 0;
		int box[] = new int[n];
		for(int i = n - 1; i >= 0; --i) {
			int tmp = 0;
			int b = i + 1;
			for(int j = b - 1; j < n; j += b) 
				tmp += box[j];
			if(tmp % 2 != a[i]) {
				ans++;
				box[i] = 1;
			}
		}
		System.out.println(ans);
		int s = 0;
		int tmp = 0;
		for(int i = 0; i < n; ++i) {
			if(box[i] == 1 && s != 0) {
				tmp = i + 1;
				System.out.print(" " + tmp);
			}
			if(box[i] == 1 && s == 0) {
				tmp = i + 1;
				System.out.print(tmp);
				s++;
			}
		}
	}
}


Measured memory_bytes: 66612
n = int(input())
A = list(map(int, input().split()))
SUM = sum(A)

dp = [0]*n
dp[0] = cnt = 0
for i in range(1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]

init = SUM-cnt
dp = [0]*n
dp[0] = cnt = init
for i in range(1, n):
    dp[i] = 2*A[i-1]-dp[i-1]
    cnt += dp[i]

print(*dp)

Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
vector<ll> d;
ll K, Q;

void solve() {
    ll n, x, m;
    cin >> n >> x >> m;
    x %= m;
    ll zero = 0;
    ll sum = x;
    for(int i = 0; i < K; i++) {
        ll val = d[i] % m;
        ll timer = (n - 1) / K; 
        if((n-1) % K > i) timer++;
        if(val == 0) {
            zero += timer;
        } else {
            sum += timer * val;
        }
    }
    ll out = (sum / m) - (x / m);
    cout << (n - 1) - (out + zero) << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> K >> Q;
    d.resize(K);
    for(int i = 0; i < K; i++) cin >> d[i];
    while(Q--) solve();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k,s;
    cin>>n>>k>>s;
    int a[n];
    for(int i=0;i<k;i++){
        a[i]=s;
    }
    if((n-k)>0){
        for(int y=k;y<n;y++){
            if(s<3){
                a[y]=(s+1);
            }
            else{
                a[y]=(s-1);
            }
        }
    }
    for(int p=0;p<n;p++)cout<<a[p]<<' ';
}


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

int main () {
  string S;
  cin >> S;
  string ans = "Good";
  
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == S.at(i+1)) {
      ans = "Bad";
      break;
    }
  }
  cout << ans << endl;
}

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

int main(){
	char S[100];
	int K;
	cin >> S;
	cin >> K;
	int i;
	for(i = 0; i < K - 1; i++){
		if(S[i] != '1'){
			cout << S[i] << endl;
			return 0;
		}
	}
	cout << S[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

void dfs(const vector<vecint>& g, vecint& veo, int i, int eo, int p) {
  veo[i] = eo;
  for (auto&& to:g[i]) {
    if(to == p) continue;
    dfs(g, veo, to, 1-eo, i);
  }
}

int main()
{
  int n;
  cin>>n;
  vector<vecint> g(n);
  for(auto&& i:irange(0,n-1)) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vecint veo(n);
  dfs(g, veo, 0, 0, -1);
  int zero = n / 3;
  int two = (n+1) / 3;
  int one = (n+2) / 3;
  int even = 0;
  for(auto&& e:veo) {
    if (e == 0) ++even;
  }
  int odd = n - even;
  vecint res(n);
  if (min(even, odd) <= zero) {
    int flg = even > odd ? 1 : 0;
    int cnt = 1;
    set<int> pool;
    for(auto&& i:irange(0,n)) {
      pool.insert(i+1);
    }
    for (auto&& i:irange(0,n)) {
      if (veo[i] == flg) {
        res[i] = 3 * cnt;
        pool.erase(3*cnt);
        ++cnt;
      }
    }
    for (auto&& i:irange(0,n)) {
      if (veo[i] != flg) {
        res[i] = *begin(pool);
        pool.erase(begin(pool));
      }
    }
  } else {
    int flg = even > odd ? 1 : 0;
    vecint cnt(3, 0);
    cnt[0] = 1;
    for (auto&& i:irange(0,n)) {
      if (veo[i] == flg) {
        if (cnt[2] < two) {
          res[i] = 3 * cnt[2] + 2;
          ++cnt[2];
        } else {
          res[i] = 3 * cnt[0];
          ++cnt[0];
        }
      } else {
        if (cnt[1] < one) {
          res[i] = 3 * cnt[1] + 1;
          ++cnt[1];
        } else {
          res[i] = 3 * cnt[0];
          ++cnt[0];
        }
      }
    }
  }
  for (auto&& i:irange(0,n)) {
    if(i) cout<<' ';
    cout<<res[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 22656
N = int(input())
qol = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * (3) for i in range(N + 1)]

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

print(max(dp[N]))



Measured memory_bytes: 47316
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int n,m,q ;
vector<int> a,b,c,d ;
int ans  ;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now = 0 ;
        for (int i = 0; i < q; i++)
        {
            if(A[b[i]]-A[a[i]]==c[i]) now += d[i] ;
        }
        ans = max(ans,now) ;        
        return ;
    }

    A.push_back(A.back()) ;
    while (A.back()<=m){
        dfs(A) ;
        A.back()++ ;
    }
}



int main() {

    cin >> n >> m >> q  ;
    a = b = c = d =  vector<int>(q) ;
  
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i] ;
    }

   dfs(vector<int>(1,1)) ;
   cout << ans << endl ;

 return 0 ;
}  


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

int main() {
    ll n;
    cin >> n;
    string res = "";
    while (n) {
        --n;
        res += (char)('a' + (n % 26));
        n /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

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


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;



int main() {
    string s; cin >> s;
    int ans=0;
    int cnt=0;
    rep(i,SZ(s)){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            cnt++;
        }
        else{
            cnt=0;
        }
        chmax(ans,cnt);
    }
    COUT(ans);
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    X,Y,a,b,c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    i,j,k = 0,0,0
    p.sort(reverse=1)
    q.sort(reverse=1)
    r.sort(reverse=1)
    res = 0
    #[値, 種類, インデックス]
    hq = [[-p[0], 0, 0], [-q[0], 1, 0], [-r[0], 2, 0]]
    heapify(hq)
    n = 0
    while X+Y>n:
        x,y,z = heappop(hq)
        res += -x
        n += 1
        if y==0 and z+1<X:
            heappush(hq, [-p[z+1], 0, z+1])
        if y==1 and z+1<Y:
            heappush(hq, [-q[z+1], 1, z+1])
        if y==2 and z+1<c:
            heappush(hq, [-r[z+1], 2, z+1])
    print(res)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 98540
N = int(input())
a = list(map(int, input().split()))

ta = []
S = 0
for ai in a:
    S += ai
    ta.append(S)
ans = 10 ** 16
for i in range(len(ta) - 1):
    ans = min(ans, abs(S - 2 * ta[i]))

print(ans)


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Input in = new Input(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		CHAndV solver = new CHAndV();
		solver.solve(1, in, out);
		out.close();
	}
	static class CHAndV {
		public void solve(int testNumber, Input in, PrintWriter pw) {
			int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
			int[][] arr = new int[n][m];
			for(int i = 0; i<n; i++) {
				String s = in.next();
				for(int j = 0; j<m; j++) {
					arr[i][j] = s.charAt(j)=='.' ? 0 : 1;
				}
			}
			int ans = 0;
			for(int rows = 0; rows<1<<n; rows++) {
				for(int cols = 0; cols<1<<m; cols++) {
					int sum = 0;
					for(int i = 0; i<n; i++) {
						for(int j = 0; j<m; j++) {
							if((rows&(1<<i))==0&&(cols&(1<<j))==0&&arr[i][j]==1) {
								sum++;
							}
						}
					}
					if(sum==k) {
						ans++;
					}
				}
			}
			pw.println(ans);
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
			try {
				st = new StringTokenizer(br.readLine());
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public boolean hasNext() {
			try {
				while(!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken("\r\n\t\f ");
		}

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

	}
}



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

int main()
{
  int A, B;
  cin >> A >> B;
  if (B==1) cout << 0 << endl;
  else{
  for (int i=1; i<=20; i++){
    if (A*i-(i-1)>=B){
      cout << i << endl;
      break;
    }
  }
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int max(int a, int b)
{
	if (a >= b)return a;
	else return b;
}

int main()
{
	int n, r[2], maxv, min;
	cin >> n;
	cin >> r[0] >> r[1];
	maxv = r[1] - r[0];
	min = -max(-r[0], -r[1]);
	for (int i = 2; i < n; i++)
	{
		cin >> r[0];
		maxv = max(maxv, r[0] - min);
		min = -max(-min, -r[0]);
	}
	cout << maxv << endl;
    return 0;
}

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

using namespace std;

int main(){
    long long sum = 0;
    int n; cin >> n;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0) sum+=i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3592
import math
N, M = map(int, input().split())
if(N>=2):
    n = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
else:
    n = 0

if(M>=2):
    m = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
else:
    m = 0
print(n+m)


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
	defer w.Flush()

	var s string
	fmt.Fscanf(r, "%s\n", &s)

	var q int
	fmt.Fscanf(r, "%d\n", &q)

	type query struct {
		Q int
		F int
		C string
	}

	first := make([]rune, 0, 100000)
	last := make([]rune, 0, 100000)

	rev := false
	for i := 0; i < q; i++ {
		q := query{}
		fmt.Fscanf(r, "%d %d %s\n", &(q.Q), &(q.F), &(q.C))
		if q.Q == 1 {
			rev = !rev
		}
		if q.Q == 2 {
			if q.F == 1 {
				if !rev {
					first = append(first, []rune(q.C)...)
				} else {
					last = append(last, []rune(q.C)...)
				}
			}
			if q.F == 2 {
				if !rev {
					last = append(last, []rune(q.C)...)
				} else {
					first = append(first, []rune(q.C)...)
				}
			}
		}
	}

	if rev {
		first, last = last, first
		s = string(reverse([]rune(s)))
	}

	ans := strings.Join([]string{string(reverse(first)), s, string(last)}, "")
	fmt.Fprintln(w, string(ans))
}

func reverse(s []rune) []rune {
	ret := make([]rune, len(s))
	for i := range s {
		ret[i] = s[len(s)-1-i]
	}
	return ret
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
int n,a,b,s[maxn],sg,big,id;
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for (int i=0;i<n;++i) {
        scanf("%d",&s[i]);
        sg^=s[i]%(min(a,b)+1);
        if (s[i]>min(a,b)) ++big,id=i;
    }
    if (a==b) puts(sg?"Hanako":"Jiro");
    else if (a>b) puts((sg||big)?"Hanako":"Jiro");
    else {
        if (!sg||big>1) puts("Jiro");
        else if (big==1) {
            int x=sg^(s[id]%(a+1));
            if (x<=a&&s[id]-x<=a) puts("Hanako");
            else puts("Jiro");
        } else puts("Hanako");
    }
    return 0;
}


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

int main()
{
	int a[5];
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	sort(a,a+5);
	
	cout<<a[4]<<' '<<a[3]<<' '<<a[2]<<' '<<a[1]<<' '<<a[0]<<endl;
		
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    long long int a,b,c,k,ans;
    string s,t,temp;
    cin>>a>>b>>c>>k;
    if((a+b)>=k)
    {
        if(a>=k)
            cout<<k<<endl;
        else
            cout<<a<<endl;
        return 0;
    }
    else
    {
        long long int tool=k-a-b;
        cout<<a-tool<<endl;
        return 0;
    }
    //cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main () {
  string word;
  string part_word;
  cin >> word;
  cin >> part_word;

  int length_word = word.size();
  int length_part_word = part_word.size();

  int num_mod[length_word-length_part_word + 1] = {};

  for (int i=0; i<length_word - length_part_word + 1; i++){
    for (int j=0; j<length_part_word; j++){
      if (word[i+j] != part_word[j]) {
        num_mod[i]++;
      }
    }
  }

  int min_num = length_part_word;
  for (int i=0; i<length_word-length_part_word+1; i++) {
    min_num = min(min_num, num_mod[i]);
  }

  cout << min_num << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int n,k; cin >> n >> k;
    vector<ll> As(n);
    rep(i,n) cin >> As.at(i);
    ll pre = 0;
    rep(i,k){
        pre += As.at(i);
    }
    for(int i = k; i < n; i++){
        ll dif = As.at(i) - As.at(i - k);
        if(dif > 0){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        pre += dif;
    }
    return 0;
}

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


int main() {
  int h,w;
  cin >> h >> w;
  string picture[2*h];
  for(int i = 0; i < h; ++i){
    cin >> picture[2*i];
    picture[2*i+1] = picture[2*i];
  }
  for(int i = 0 ; i < 2*h; ++i) cout << picture[i] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		long max = 0;
		long ans = 0;
		
		for(int i = 0; i < n; i++) {
			int height = sc.nextInt();
			if(max < height) {
				max = height;
			}
			ans += max - height;
		}
		
		System.out.println(ans);
		sc.close();
	}
}




Measured memory_bytes: 58980
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

vector< bool > prime_table(int n) {
    vector< bool > prime(n + 1, true);
    if(n >= 0) prime[0] = false;
    if(n >= 1) prime[1] = false;
    for(int i = 2; i * i <= n; i++) {
        if(!prime[i]) continue;
        for(int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}


signed main() {
    auto prime = prime_table(100000);
    vector<int> ans;
    for (int i = 5; i * 2 + 1 <= 55555; i+= 5) {
        if (prime[i * 2 + 1]) ans.push_back(i * 2 + 1);
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cout << ans[i] << (i == N - 1 ? '\n' : ' ');
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " "  << y << endl;
}


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

int main(){
    int x,y;
    
    while(1){
        cin >> x >> y;
        if (x == 0 && y == 0) { break; }
        
        if (x < y){
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
use std::io;

fn main() {
    let n = read_one::<usize>();
    if n % 2 == 0 {
        println!("{}", n);
    } else {
        println!("{}", n * 2);
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

#define NMAX 5001

using namespace std;

int dp[NMAX][NMAX];
int n, ans, lim;
char str[NMAX];

int solve(int l1, int l2)
{
    if(l1 > lim) return 0;
    if(l2 >= n) return 0;

    if(dp[l1][l2] != -1)
        return dp[l1][l2];

    if(str[l1] != str[l2])
    {
        dp[l1][l2] = 0;
        return 0;
    }

    int res = 1 + solve(l1 + 1, l2 + 1);
    dp[l1][l2] = res;
    
    return res;
}

int main()
{
    memset(dp, -1, sizeof(dp));

    cin >> n;

    cin.get();
    cin.getline(str, n + 1);

    for(int i = 0; i < n - 1; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            lim = j - 1;
            ans = max(ans, solve(i, j));
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 97920
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <regex>
using namespace std;
int main(void){
    int ans2 = 0;
    string s;
    cin >> s;
    int l = s.size();
    for(int i = 0;i < l;i++){
        int cnt = 0;
        string t;
        t += s[i];
        if(s[i] == 'A' ||s[i] == 'T' ||s[i] == 'G' ||s[i] == 'C') cnt++;
        for(int j = i+1;j < l;j++){
            t += s[j];
            if(s[j] != 'A' &&s[j] != 'T' &&s[j] != 'G' &&s[j] != 'C') break;
            if(s[j] == 'A' ||s[j] == 'T' ||s[j] == 'G' ||s[j] == 'C') cnt++;
        }
        ans2 = max(cnt,ans2);
    }
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 256