akhauriyash/Code-Regression huggingface dataset:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, q = list(map(int,ipti().split()))
    s = input()
    ls = len(s)
    ac = [0] * ls

    for i in range(ls-1):
        if s[i] == 'A':
            if s[i+1] == 'C':
                ac[i+1] += 1

    cs = list(itertools.accumulate(ac))

    for i in range(q):
        left, right = list(map(int,ipti().split()))
        print(cs[right-1] - cs[left-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 54560
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
constexpr long INF = 1L << 62;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    long n, k; cin >> n;
    vector<long> a(n); for(int i = 0; i < n; ++i) cin >> a[i], a[i] *= -1;

    vector<long> ans(n * 2, INF);

    for(int i = 0; i < n; ++i) 
        *lower_bound(ans.begin(), ans.end(), a[i] + 1) = a[i];

    cout << lower_bound(ans.begin(), ans.end(), INF) - ans.begin() << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ///{}
    int n,z,w;
    cin>>n>>z>>w;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    vector<int>bdis(n);
    for(int i=0;i<n-1;i++){
        int mn=INT_MAX;
        for(int j=i+1;j<n-1;j++){
            mn=min(mn,abs(v[j]-v[n-1]));
        }
        mn=min(mn,abs(v[n-1]-v[i]));
        bdis[i]=mn;
    }
    int ans=abs(v[n-1]-w);
    for(int i=0;i<n-1;i++)
        ans=max(ans,bdis[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int N,T,c,t,ANS;
	vector<int> Cost;
	vector<int> Time;
	cin >> N >> T;

	for(int i=0;i<N;i++)
	{
		cin >> c;
		cin >> t;
		if(t<=T)
		{
			Cost.push_back(c);
			Time.push_back(t);
		}
	}
	if(Cost.size()==0)
	{
		cout << "TLE" << endl;
	}
	else
	{
		ANS = *min_element( Cost.begin(), Cost.end() );
		cout << ANS << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

int main() {

	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
	vector<double> sugar, water;

	std::cin >> a >> b >> c >> d >> e >> f;

	for (int i = 0; i <= f; i++) {
		for (int j = 0; j <= f; j++) {
			int y = i * c + j * d;
			if (y <= f) {
				sugar.push_back(y);
			}
		}
	}

	for (int i = 0; i <= f; i++) {
		for (int j = 0; j <= f; j++) {
			int x = (100 * i * a) + (100 * j * b);
			if (x <= f) {
				water.push_back(x);
			}
		}
	}

	double kako = -1, nodo = 0;
	int ans_sugar = 0, ans_water = 0;

	rep(i, water.size()) {
		rep(j, sugar.size()) {

			if (water[i] + sugar[j] <= f) {
				if (sugar[j] <= e * (water[i] / 100.0)) {

					nodo = (100 * sugar[j]) / (water[i] + sugar[j]);

					if (nodo > kako) {
						kako = nodo;
						ans_sugar = sugar[j];
						ans_water = water[i];
					
					}
				}
			}
		}
	}

	cout << ans_sugar + ans_water << " " << ans_sugar << endl;

	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,(n)*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
char s[100001];
int main()
{
	scanf("%s",s);
	putchar(s[0]),putchar(s[1]),putchar(s[2]),puts("");
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/

Measured memory_bytes: 3684
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
 
 
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//int Q = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		Scanner sc = new Scanner(System.in);
		
		
		char[] S = sc.next().toCharArray();
		int N = S.length;
		if(N<3){
			System.out.println("0");
			return;
		}
		
		long[] count = new long[N];
		
		for(int i=N-1; i>1; i--){
			if(S[i-1] == 'A')count[i-2] = count[i-1];
			if(S[i] == 'C' && S[i-1] == 'B')count[i-2] = count[i] + 1;
		}
		
		long ans = 0;
		for(int i=0; i<N; i++){
			if(S[i] == 'A'){
				ans += count[i];
			}
		}
		
		System.out.println(ans);
		
		

	}
	

	
}



Measured memory_bytes: 28624
def factorization(n):
    if n==1:
        return []
    arr = []
    temp = n
    cand = [2]+list(range(3, int(-(-n**0.5//1))+1, 2))
    for i in cand:
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

max_N=1000
s = [i for i in range(1, max_N)]
sums = [sum(s[:i]) for i in range(1,max_N)]
def comb(a):
    for i in range(max_N):
        if a<sums[i]:
            return i

N = int(input())
fac = factorization(N) 
res = 0
for a in [el[1] for el in fac]:
    res += comb(a)
print(res)

Measured memory_bytes: 32780
# a, b, c = readline.strip.split.map(&:to_i)
n = readline.strip.to_i

def f(x)
  x.to_s.size % 2 == 1
end

c = 0
x = 1
while x <= n
  c += 1 if f(x)
  x += 1
end
puts c


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  string s;
  ll K;
  cin>>K>>s;
  
  if(s.size()>K){
    cout<<s.substr(0,K)<<"...";
  }
  else{
    cout<<s;
  }
    
}

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

int memo[100010][4];
int n, a[100010], b[100010], c[100010];
int dp(int D, int C) {
    if (D == n) return 0;
    if (memo[D][C] != -1) return memo[D][C];
    int x = -(1 << 30), y = -(1 << 30), z = -(1 << 30);
    if (C != 0) x = a[D] + dp(D + 1, 0);
    if (C != 1) y = b[D] + dp(D + 1, 1);
    if (C != 2) z = c[D] + dp(D + 1, 2);
    return memo[D][C] = max(x, max(y, z));
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    memset(memo, -1, sizeof(memo));
    cout << dp(0,3) << "\n";
    return 0;
}


Measured memory_bytes: 9216
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Integral Rectangles
// 2013/08/13
public class Main{
	Scanner sc=new Scanner(System.in);

	int nTeams, nProblems, nTick;
	int[] ticks, teams, problems, results;

	void run(){
		for(;;){
			int M=sc.nextInt();
			nTeams=sc.nextInt();
			nProblems=sc.nextInt();
			nTick=sc.nextInt();
			if((M|nTeams|nProblems|nTick)==0){
				break;
			}
			ticks=new int[nTick];
			teams=new int[nTick];
			problems=new int[nTick];
			results=new int[nTick];
			for(int i=0; i<nTick; i++){
				ticks[i]=sc.nextInt();
				teams[i]=sc.nextInt()-1;
				problems[i]=sc.nextInt()-1;
				results[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		int[][] states=new int[nTeams][nProblems];
		int[][] times=new int[nTeams][nProblems];
		for(int i=0; i<nTick; i++){
			if(results[i]==0){
				states[teams[i]][problems[i]]=1;
				times[teams[i]][problems[i]]+=ticks[i];
			}else{
				times[teams[i]][problems[i]]+=20;
			}
		}
		int[] ACs=new int[nTeams];
		int[] penalties=new int[nTeams];
		for(int j=0; j<nTeams; j++){
			for(int i=0; i<nProblems; i++){
				ACs[j]+=states[j][i];
				penalties[j]+=states[j][i]*times[j][i];
			}
		}
		int[] _=new int[nTeams];
		for(int i=0; i<nTeams; i++){
			_[i]=i;
		}
		for(int i=0; i<nTeams; i++){
			for(int j=i+1; j<nTeams; j++){
				if(comp(ACs[_[i]], penalties[_[i]], _[i], ACs[_[j]],
						penalties[_[j]], _[j])>0){
					int t=_[i];
					_[i]=_[j];
					_[j]=t;
				}
			}
		}
		for(int i=0; i<nTeams; i++){
			print(1+_[i]+"");
			if(i<nTeams-1){
				print(comp(ACs[_[i]], penalties[_[i]], ACs[_[i+1]],
						penalties[_[i+1]])==0?"=":",");
			}
		}
		println("");
	}

	int comp(int ac1, int time1, int ac2, int time2){
		if(ac1!=ac2){
			return -(ac1-ac2);
		}else{
			return time1-time2;
		}
	}

	int comp(int ac1, int time1, int id1, int ac2, int time2, int id2){
		if(comp(ac1, time1, ac2, time2)!=0){
			return comp(ac1, time1, ac2, time2);
		}else{
			return -(id1-id2);
		}
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 62468
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


string sol(string s){
    string ret="";
    
    rep(i,s.size()){
        if(i!=0 && isupper(s[i]) && s[i]!='_'){
            ret+='_';
            ret+=tolower(s[i]);
        }
        else{
            ret+=tolower(s[i]);
        }
    }
    return ret;
}





int main() {
    string s;
    char type;
    
    while(cin>>s>>type){
        if(type=='X')break;
        
        s=sol(s);
        
        if(type=='D')cout<<s<<endl;
        else if(type=='L'){
            string ans="";
            rep(i,s.size()){
                if(s[i]=='_'){
                    ans+=toupper(s[i+1]);
                    i++;
                }
                else ans+=tolower(s[i]);
            }
            cout<<ans<<endl;
            
        }
        else if(type=='U'){
            string ans="";
            rep(i,s.size()){
                if(i==0){
                    ans+=toupper(s[i]);
                }
                else if(s[i]=='_'){
                    ans+=toupper(s[i+1]);
                    i++;
                }
                else ans+=tolower(s[i]);
            }
            cout<<ans<<endl;
            
        }
    }
    
    return 0;
}

Measured memory_bytes: 1200
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int n;
    cin >> n;
    vector<unsigned long long> a(n, 0);
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<vl> memo(60, vl(n, 0));
    unsigned long long compare = 1;
    rep(i, 60){
        rep(j, n)
        {
            if(j == 0){
                if(compare & a[j]){
                    memo[i][j] = 1;
                }
            }else{
                memo[i][j] = memo[i][j - 1];
                if (compare & a[j])
                {
                    memo[i][j] = memo[i][j - 1] + 1;
                }
            }
        }
        compare = compare << 1;
    }
    unsigned long long result = 0;
    unsigned long long mod = 1e9 + 7;
    compare = 1;
    rep(i, 60){
        rep(j, n){
            unsigned long long  count = memo[i][n - 1] - memo[i][j];
            if(compare & a[j]){
                count = (n - j - 1) - count;
            }
            unsigned long long temp = ((compare % mod) * count) % mod;
            result = (result + temp) % mod;
        }
        compare = compare << 1;
    }
    cout << result << endl;
}

Measured memory_bytes: 145536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()

for i in range(1, 1001):
	if i*8//100 == A and i*10//100 == B:
		print(i)
		break
else:
	print(-1)


Measured memory_bytes: 5696
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<> string read<string>() {
	string s;
	getline(cin, s);
	return s;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	vector<sint> Bs;
	for (sint i = 0; i < N - 1; ++i) {
		Bs.push_back(read<sint>());
	}
	sint sum = 0;
	sum += Bs[0];
	for (sint i = 1; i < N - 1; ++i) {
		sum += min(Bs[i - 1], Bs[i]);
	}
	sum += Bs[N - 2];

	writeln(sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
typedef long long int ll;
using namespace std;


int main()
{
    ll n , m;
    cin >> n >> m;
    ll ans = 0;
    if(n >= 2) ans += n * (n - 1) / 2;
    if(m >= 2) ans += m * (m - 1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void start(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("input.txt","r")){
        freopen ("input.txt" , "r" , stdin);
        freopen ("output.txt" , "w" , stdout);
    }
    #endif
}
signed main(){
    start();

    int n,k;
    cin>>n>>k;
    vector<int> a(n+1),vis(n+1),count;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    count.push_back(1);
    vis[1] = 1;
    int temp = 1;
    while(vis[a[temp]] != 1){
        temp = a[temp];
        count.push_back(temp);
        vis[temp] = 1;
    }
    int length = find(count.begin(),count.end(),a[temp]) - count.begin();
    if(k<=length){
        cout<<count[k];
    }
    else{
        cout<<count[length+(k-length)%(count.size()-length)];
    } 

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s, t, out="";
    cin >> s >> t;
    for(int i=0;i<n;i++){
       out += s[i];
       out += t[i];
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
sumf = sum(a[:k])
for i in range(1,n-k+1):
    sumn = sumf - a[i-1] + a[i+k-1]
    print("Yes" if sumn>sumf else "No")
    sumf = sumn


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int amin = 2000;
    int amax = -1;
    for(int i = 0; i < n; i++){
        if(a[i] > amax) amax = a[i];
        if(a[i] < amin) amin = a[i];
    }
    cout << amax - amin << endl;
    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn=  1000+10;
const int maxm = maxn*21+10;
//Pretests passed
int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}


int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    int n;
    sd(n);
    int ans = 0;
    while(n--)
    {
        int l,r;
        sdd(l,r);
        ans+=(r-l+1);
    }
    ansn();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int array[4];
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    scanf("%d %d %d %d",&array[0],&array[1],&array[2],&array[3]);
    for(int i=0; i<=3; i++){
        if(array[i]==1){
            a++;
        }
        if(array[i]==9){
            b++;
        }
        if(array[i]==7){
            c++;
        }
        if(array[i]==4){
            d++;
        }
    }
    if(a==1 && b==1 && c==1 && d==1){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int a;
    int b;
    int i;
    int res = 0;
    cin >> a;
    cin >> b;

    for(i = 0; i<1000000000; i++){

            if(abs(a-i) == abs(b-i)){
                res = i;
                break;
            }
    }

                if(res>0){
                    cout<< i;
                }
                else
                    cout<< "IMPOSSIBLE";
}


Measured memory_bytes: 256
#include<stdio.h>



int main(void){
	int x,y,result=0;
	int temp;
	scanf("%d",&x);
	scanf("%d",&y);
	if(x<=y){
		temp=x;
		x=y;
		y=temp;	
	}
	result=x%y;

	while(result!=0){
	x=y;
	y=result;
	result=x%y;
		
	}
	printf("%d\n",y);
	
	
	return 0;
}


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

using namespace std;


int main() {
    int h,w;
    cin>>h>>w;
    for (int i = 0; i < h; ++i) {
        string s;
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.size();
    int n_s = 0;
    int cnt = 0;
    rep(i, n) {
        if (s[i] == 'S') {
            n_s++;
        } else if (n_s > 0) {
            n_s--;
            cnt++;
        }
    }
    cout << n - 2*cnt << endl;
}

Measured memory_bytes: 720
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ans=10**9
    n=II()
    xx=LI()
    for p in range(1,101):
        cur=sum((p-x)**2 for x in xx)
        ans=min(cur,ans)
    print(ans)

main()

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

vector<vector<ll>> dp(2001, vector<ll> (2001, -1));
int dpcnt = 0;
ll cmb(int a, int b){

  //cout << a << "," << b << endl;
  if(dp[a][b]!=-1){
    //dpcnt++;
    return dp[a][b];
  }else if(a >= 1 && b >= 1 && dp[a-1][b] != -1 && dp[a-1][b-1] != -1){
    dp[a][b] = (dp[a-1][b] + dp[a-1][b-1])%MOD;
    //dpcnt++;
    //cout << "dp";
    return dp[a][b];
  }
  if(b == 0||a==b){
    dp[a][b] = 1;
    return 1;
  }
  ll ans = a;
  for(int i = 1; i < b; i++){
    ans *= a-i;
  }
  for(int i = 1; i <= b; i++){
    ans /= i;
  }
  dp[a][b] = ans % MOD;
  return dp[a][b];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, n;
  cin >> n >> k;
  for(int i = 0; i <= 2000; i++){
    for(int j = 0; j <= 2000; j++){
      cmb(j,i);
    }
  }
  
  for(int i = 1; i <= k; i++){
    cout << (cmb(n-k+1, i) * cmb(k-1,i - 1)) %MOD << endl;
  }
  return 0;
} 


Measured memory_bytes: 31744
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <numeric>
#include <bitset>
#include <random>
#include <tuple>
#include <initializer_list>
#include <fstream>
#include <cctype>
#include <string>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<int> cards(n + 1, 0);
	for (auto i = 0; i < m; ++i) {
		int l, r; std::cin >> l >> r;
		cards[l - 1]++; cards[r]--;
	}
	for (auto i = 1; i < cards.size(); ++i) {
		cards[i] += cards[i - 1];
	}
	std::cout << std::count(cards.begin(), cards.end(), m) << std::endl;
}


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

int main() {
  string s; cin >> s;
  int A[4] = {s[0] - '0',s[1] - '0',s[2] - '0',s[3] - '0'};

  char op[3];
  for (int i = 0; i < 1 << 3; i++) {
    int total = A[0];
    for (int j = 0; j < 3; j++) if (i & 1 << j) total += A[j + 1]; else total -= A[j + 1];
    if (total == 7)
      for (int j = 0; j < 3; j++) if (i & 1 << j) op[j] = '+'; else op[j] = '-';
  }

  cout << A[0];
  for (int i = 0; i < 3; i++) cout << op[i] << A[i + 1];
  cout << "=7" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000];
	int i,len,q=0,j;
	gets(a);
	len=strlen(a);
	for(i=0;i<len;i++)
	{
		if(a[i]=='C')
		{
			q=1;
		}
		if(q==1)
		{
			for(j=i;j<len;j++)
			{
				if(a[i]=='F')
				{
					printf("Yes");
					return 0;
				}
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000009
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl '\n'

int dp[105][100005];

int knapsack(int wt[],int val[],int n,int w){
	if(n == 0 || w == 0){
		return 0;
	}

	if(dp[n][w] != -1){
		return dp[n][w];
	}

	if(wt[n-1] > w){
		return dp[n][w] = knapsack(wt,val,n-1,w);
	}else{
		return dp[n][w] = max(val[n-1]+knapsack(wt,val,n-1,w-wt[n-1]),knapsack(wt,val,n-1,w));
	}
}

signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	int n,w;
	cin >> n >> w;
	int wt[n],val[n];

	for0(i,n){
		cin >> wt[i] >> val[i];
	}

	memset(dp,-1,sizeof(dp));

	cout << knapsack(wt,val,n,w);

	return 0;
}

Measured memory_bytes: 85680
//#pragma GCC optimize(2)
//ÄÏ¾©ÊÐµÚÈýÇøOIÎ¯ÌáÐÑÄú£º
//´úÂëÇ§ÍòÌõ£¬-O2µÚÒ»Ìõ¡£
//-O2²»¹æ·¶£¬³¬Ê±Á½ÐÐÀá¡£
// Happy TLE and WA every day!
// by: zxb
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            4557430888798830399
#define pb              push_back
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
#define read            ZXBs_fast_input
#define write           ZXBs_fast_output
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool write(int x){
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n, k;
int a[200200];
int cnt[200200];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> k;
	rep(i, n){
		cin >> a[i];
		cnt[a[i]]++;
	}
	sort(cnt+1, cnt+n+1);
	reverse(cnt+1, cnt+n+1);
	int sum = 0;
	for(int i = 1; i <= k; i++){
		sum += cnt[i];
	}
	cout << (n-sum) << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,x,y;cin>>a>>b>>c>>x>>y;
  ll m=min(2*c,a+b);
  ll ans=0;
  ans+=m*min(x,y);
  ll ama=abs(x-y);
  if(x>=y){
    ll n=min(a,2*c);
    ans+=ama*n;
  }
  else{
    ll n=min(b,2*c);
    ans+=ama*n;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
<?php

$s = explode(' ', trim(fgets(STDIN)));

if (abs($s[2]-$s[0]) <= $s[3]){
  echo 'Yes';
} else if (abs($s[1]-$s[0])<= $s[3] && abs($s[2]-$s[1]) <= $s[3]){
  echo 'Yes';
} else {
  echo 'No';
}

?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
int main()
{
  ll ara[5];
  
  for (ll i=0;i<5;i++)
    {
    cin>>ara[i];
    if(ara[i]==0)
     {
      cout<<i+1<<endl;
      break;
    }
  }
}





Measured memory_bytes: 3588
from collections import deque


H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(lambda x: int(x) - 1, input().split())
grid = [input() for _ in range(H)]

INF = float('inf')
path = [[[(INF, INF)] * 4 for _ in range(W)] for _ in range(H)]

q = deque()
for d in range(4):
    path[x1][y1][d] = (1, 0)
    q.append((x1, y1, d, 1, 0))

D = [(-1, 0), (0, 1), (1, 0), (0, -1)]
while q:
    x, y, d, s, k = q.popleft()
    if k == K:
        for nd in range(4):
            if nd == d:
                dx, dy = D[nd]
                nk = 1
            else:
                dx, dy = 0, 0
                nk = 0
            nx = x + dx; ny = y + dy
            ns = s + 1
            if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk):
                path[nx][ny][nd] = (ns, nk)
                q.append((nx, ny, nd, ns, nk))
    else:
        for nd in range(4):
            if nd == d:
                dx, dy = D[nd]
                nk = k + 1
            else:
                dx, dy = 0, 0
                nk = 0
            nx = x + dx; ny = y + dy
            ns = s + (d != nd)
            if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny][nd] > (ns, nk):
                path[nx][ny][nd] = (ns, nk)
                if ns == s:
                    q.appendleft((nx, ny, nd, ns, nk))
                else:
                    q.append((nx, ny, nd, ns, nk))

ans = INF
for d in range(4):
    ans = min(ans, path[x2][y2][d][0])
ans = -1 if ans == INF else ans
print(ans)


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
    cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int32_t main(){
    
    fast;
    string s1,s2; cin >> s1 >> s2;

    int c = 0;
    
    for(int i=0;i<s1.size();i++){
        if(s1[i]==s2[i]) c++;
    }
    

    cout << c;
 
    return 0;
} 

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

using namespace std;
typedef long long LL;

#define LOG(...) fprintf (stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;

string s; int n; 
char sc (char x, int n) {
	int t = x;
	t -= 'A';
	t = (t + n) % 26;
	return (char)(t + 'A');
}
int main() {
#ifdef LiM_817
	freopen ("input.txt", "r", stdin);
	double cl = clock();
#endif

	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		s[i] = sc(s[i], n);
	}
	
	cout << s << endl;
#ifdef LiM_817
	cerr << fixed << setprecision(2) << "Time ellapsed: " << ((double)(clock() - cl) / CLOCKS_PER_SEC) << "s\n";
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	
	int* a = new int[n+1];
	a[0] = 0;
	queue<int> que;
	que.push(0);
	REP(i, 1, n + 1) {
		while (!que.empty()) {
			if (i > que.front() + m) que.pop();
			else break;
		}

		if (que.empty()) {
			cout << "-1" << "\n";
			return 0;
		}

		if (s[i] != '1') {
			a[i] = que.front();
			que.push(i);
		}
	}

	deque<int> ans;
	int i = n;
	while (i != 0) {
		ans.push_front(i - a[i]);
		i = a[i];
	}

	while (!ans.empty()) {
		cout << ans.front() << " ";
		ans.pop_front();
	}

	cout << "\n";

	return 0;
}


Measured memory_bytes: 4484
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int h;
        cin >> h;
        if (h >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans, N;
vector<string> s;
int t[105];

int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) {
        string S;
        cin >> S;
        s.pb(S);
        cin >> t[i];
    }

    string X;
    cin >> X;

    int i = 0;
    while (s[i] != X) {
        i++;
    }

    rep(x, i+1, N) ans += t[x];
   

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

	  return 0;
}


Measured memory_bytes: 256
// B - Palindromic Numbers
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> a >> b;

  repe(i, a, b)
  {
    s = to_string(i);
    t = s;
    REV(s);
    if (t == s)
    {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
         
using namespace std;
                 
int main(){
  int N;
  cin >> N;
  vector<long> vec(3*N, 0);
  long sum = 0;
  for(int i = 0; i < 3*N; i++) cin >> vec[i];
  sort(vec.begin(), vec.end(), greater<int>());

  for(int i = 1; i < 2*N; i +=2) sum += vec[i];
  cout << sum;
}

Measured memory_bytes: 2560
n = int(input())
R = []

for i in range(n):
    R.append(int(input()))

max_R, min_R = 10**9*(-1), R[0]
for j in range(1, n):
    max_R = max(max_R, R[j]-min_R)
    min_R = min(min_R, R[j])

print(max_R)


Measured memory_bytes: 13588
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define rep2(i, N, s) for(int (i) = (s); (i) < (N) + (s); (i) ++)
#define rrep(i, N) for(int (i) = (N) - 1; (i) >= (0); (i) --)
#define rrep2(i, N, s) for(int (i) = (s); (i) >= (s) - (N) + 1; (i) --)
#define INF 1e9

#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

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

int main() {
    int N;
    int i;
    cin >> N >> i;
    cout << (N - i + 1);
    return 0;
}


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


void trace(int a[],int n){
    for(int i=0;i<n;i++){
        if(i==0){
            cout<<a[i];
        }
        if(i>0){
            cout<<" "<<a[i];
        }
    }
    cout<<endl;
}

void insertionSort(int a[],int n){
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(a[j]>v&&j>=0){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        trace(a,n);
    }
}

int main(){
    int n; cin>>n;
    int a[100];
    for(int i=0;i<n;i++){
    cin>>a[i];
    }
    trace(a,n);
    insertionSort(a,n);
    return 0;
}


Measured memory_bytes: 3116
from collections import deque


def dfs(G, start):
    S = deque()
    S.append(start)
    while len(S) > 0:
        x, parent = S.pop()
        Counter[x] += Counter[parent]
        for g in G[x]:
            if g == parent:
                continue
            S.append((g, x))


N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N - 1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
G = [[] for _ in range(N + 1)]
for a, b in AB:
    G[a].append(b)
    G[b].append(a)

Counter = [0 for _ in range(N + 1)]

for p, x in PX:
    Counter[p] += x

dfs(G, (1, 0))
Counter = [str(a) for a in Counter]
print(" ".join(Counter[1:]))


Measured memory_bytes: 104524
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int solve(int n, int d)
{
    int ans = d * ((n + 1) / 2 * 2 - 1);
    ans += (d ^ 127) * (n / 2 * 2);
    return ans;
}

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

    while(--t >= 0){
        int n, d;
        cin >> n >> d;
        cout << solve(n, d) << endl;
    }

    return 0;
}

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

using namespace std;

const int INF=1e5;

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    
    vector<vector<int> > dp(401, vector<int>(401, INF));
    dp[0][0]=0;
    
    vector<pair<pair<int, int>, int> > abc(N);
    for(int n=0; n<N; n++) {
        int a, b, c;
        cin >> a >> b >> c;
        abc[n]=make_pair(make_pair(a, b), c);
    }
    
    // dp
    for(int n=0; n<N; n++) {
        vector<vector<int> > dptmp(401, vector<int>(401));
        dptmp=dp;
        for(int wa=0; wa<401; wa++) {
            for(int wb=0; wb<401; wb++) {
                if(wa-abc[n].first.first>=0 && wb-abc[n].first.second>=0 &&\
                 dp[wa-abc[n].first.first][wb-abc[n].first.second]!=INF) {
                    dptmp[wa][wb] \
                    = min(dp[wa][wb], \
                        dp[wa-abc[n].first.first][wb-abc[n].first.second]+abc[n].second);
                }
            }
        }
        dp=dptmp;
    }
    
    // cout << "Searching Ma:Mb" << endl;
    // Searching Ma : Mb 
    int mmax=max(Ma, Mb);
    int ma=Ma, mb=Mb;
    int min_cost=INF;
    while(mmax<=400) {
        for(int wa=0; wa<401; wa++) {
            for(int wb=0; wb<401; wb++) {
                min_cost = min(min_cost, dp[ma][mb]);
            }
        }
        
        mmax+=mmax;
        ma += Ma;
        mb += Mb;
    }

    if(min_cost==INF) {
        cout << -1 << endl;
    } else {
        cout << min_cost << endl;
    }

    return 0;
    
}

Measured memory_bytes: 1588
#include <stdio.h>

// 2????????´??°?????\??????????????¢??°
void swapper(int *x, int *y) {
    int buf;

    buf = *y;
    *y = *x;
    *x = buf;
}

int main(void) {
    int x, y, r;

    scanf("%d %d", &x, &y);
    if (x < y) swapper(&x, &y); // ??????x>y??§?????????????????????
    r = x % y;
    while (r != 0) {
        x = y;
        y = r;
        r = x % y;
    }
    printf("%d\n", y);

    return 0;
}

Measured memory_bytes: 592
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def tk(i, j, k):
    return '%d %d %d' % (i, j, k)

def tkr(key):
    return sp2nn(key)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    aa = sp2nn(ss[1])
    bb = sp2nn(ss[2])
    cc = sp2nn(ss[3])
    aa.sort()
    aa.reverse()
    bb.sort()
    bb.reverse()
    cc.sort()
    cc.reverse()
    
    d = {}
    st = set()
    key = tk(0, 0, 0)
    st.add(key)
    d[key] = aa[0] + bb[0] + cc[0]
    for _ in range(K):
        vmax = -1
        vk = ''
        for k, v in d.items():
            if vmax < v:
                vmax = v
                vk = k
        print(vmax)
        d.pop(vk)
        st.add(vk)
        i, j, k = tkr(vk)
        if i + 1 < len(aa):
            key = tk(i+1, j, k)
            if key not in st:
                d[key] = aa[i+1] + bb[j] + cc[k]
        if j + 1 < len(bb):
            key = tk(i, j+1, k)
            if key not in st:
                d[key] = aa[i] + bb[j+1] + cc[k]
        if k + 1 < len(cc):
            key = tk(i, j, k+1)
            if key not in st:
                d[key] = aa[i] + bb[j] + cc[k+1]
        
main(ii2ss(4))

Measured memory_bytes: 4264
r1, c1, r2, c2 = map(int, input().split())

MAX = 2 * 10 ** 6 + 1
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1

# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1

# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1

for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def f(r, c):
    return fac[r + c] * finv[r] * finv[c] % MOD


ans = 0
for i in range(c1, c2 + 1):
    ans += f(r2, i + 1) - f(r1 - 1, i + 1)
    ans %= MOD
print(ans)


Measured memory_bytes: 135704
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=5e5+5,M=5e7+5;
int a[N],b[N],las[N],nxt[N],n;ll res;
inline bool ck(R int x){return (b[x]-a[x])>=b[las[x]]+b[nxt[x]];}
int q[M];
int main(){
	scanf("%d",&n);
	fp(i,1,n)las[i]=i-1,nxt[i]=i+1;las[1]=n,nxt[n]=1;
	fp(i,1,n)scanf("%d",&a[i]);fp(i,1,n)scanf("%d",&b[i]);
	int h=1,t=0,u,k;
	fp(i,1,n)if(ck(i))q[++t]=i;
	while(h<=t){
		u=q[h++];
		k=(b[u]-a[u])/(b[las[u]]+b[nxt[u]]);
		res+=k,b[u]-=k*(b[las[u]]+b[nxt[u]]);
//		printf("%d %d\n",u,b[u]);
		if(ck(las[u]))q[++t]=las[u];
		if(ck(nxt[u]))q[++t]=nxt[u];
		if(ck(u))q[++t]=u;
	}
	fp(i,1,n)if(a[i]!=b[i])return puts("-1"),0;
	return printf("%lld\n",res),0;
}

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

int main()
{   char s[51];
    scanf("%s",s);
    int l=strlen(s);
    if(l>=10){
        printf("NO");
        return 0;
    }
    if(l==9&&strcmp(s,"AKIHABARA")==0){
        printf("YES");
        return 0;
    }
    if(l==8&&(strcmp(s,"AKIHABAR")==0||strcmp(s,"AKIHABRA")==0||strcmp(s,"AKIHBARA")==0||strcmp(s,"KIHABARA")==0)){
        printf("YES");
        return 0;
    }
    if(l==7&&(strcmp(s,"AKIHABR")==0||strcmp(s,"AKIHBAR")==0||strcmp(s,"KIHABAR")==0||strcmp(s,"AKIHBRA")==0||strcmp(s,"KIHABRA")==0||strcmp(s,"KIHBARA")==0)){
        printf("YES");
        return 0;
    }
    if(l==6&&(strcmp(s,"KIHBRA")==0||strcmp(s,"KIHBAR")==0||strcmp(s,"KIHABR")==0||strcmp(s,"AKIHBR")==0)){
        printf("YES");
        return 0;
    }
    if(l==5&&strcmp(s,"KIHBR")==0){
        printf("YES");
        return 0;
    }
    printf("NO");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define MOD     1000000007
#define pb      push_back
#define mp      make_pair
#define all(v)  (v).begin(),(v).end();
#define T		int t;cin>>t;while(t--)
#define IOS     ios_base::sync_with_stdio(false);cin.tie(NULL);
const int N = 2e5 + 2;
vector<int> g[N];

int dp[N + 1];
void addEdge(int u, int v) {

	g[u].push_back(v);
}

int findLongest(int u) {

	if (dp[u] != INT_MIN) {
		return dp[u];
	}

	if (g[u].empty()) {
		return 0;
	}
	int ans = 0;
	for (auto i : g[u]) {

		ans = max(ans, 1 + findLongest(i));

	}

	dp[u] = ans;

	return ans;

}
int main() {




	int n, m;

	cin >> n >> m;

	int u, v;
	while (m--) {

		cin >> u >> v;
		addEdge(u, v);

	}


	for (int i = 0 ; i <= n ; i++) {
		dp[i] = INT_MIN;
	}
	int ans = -1;
	for (int i = 1 ; i <= n; i++) {
		ans = max(ans, findLongest(i));
	}

	cout << ans << endl;
}




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

int main()
{
    long N, capacity[5];
    cin >> N;

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

    long min = capacity[0];
    for (int i = 1; i < 5; i++) {
        if (capacity[i] < min) {
            min = capacity[i];
        }
    }

    cout << (N-1) / min + 5 << endl;
    return 0;
}

Measured memory_bytes: 256