akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to, w;
    Edge(int next = 0, int to = 0, int w = 0):next(next), to(to), w(w) {};
}edge[N<<1];
int head[N], tot;
void _add(int x, int y, int z) { edge[++tot] = Edge(head[x], y, z), head[x] = tot; }
void add(int x, int y, int z) { _add(x, y, z), _add(y, x, z); }
int n, p, size[N], f[N], delta = 0x3f3f3f3f;
int64 ans;
void dfs(int x, int fa)
{
    size[x] = 1;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to, z = edge[i].w; if(y == fa) continue;
        dfs(y, x), size[x] += size[y], f[x] = max(f[x], size[y]);
        ans += 2ll*min(n-size[y], size[y])*z;
    }
    f[x] = max(f[x], n-size[x]), p = f[x]<f[p]?x:p;
}
int main()
{
    n = read(), f[0] = n;
    for(int i = 1; i < n; ++i) 
    {
        int x = read(), y = read(), z = read();
        add(x, y, z);
    }
    dfs(1, 0);
    for(int i = head[p]; i; i = edge[i].next)
    {
        int y = edge[i].to, z = edge[i].w;
        if(f[p] == f[y]) return printf("%lld\n", ans-z), 0;
        delta = min(delta, z);
    }
    printf("%lld\n", ans-delta);
    return 0;
}

Measured memory_bytes: 8960
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000001;
using namespace std;
struct Edge{int from, to, cost;};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,k;
    cin >> n >> m >> k;

    int flag = 0;
    REP(i,n){
        REP(j,m+1){
            int num = (n-i)*j + (m-j)*i;
            if(k == num){
                flag = 1;
                break;
            }
        }
    } 

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mof=1e9+7;
LL p=mof;
const LL maxn=100007;
inline LL pow_mod(LL a,LL k,LL mo)
{
    LL ans=1;
    while(k)
    {
        if(k%2) ans=ans*a%mo;
        a=a*a%mo;
        k>>=1;
    }
    return ans%mo;
}
LL jc[maxn+7];
inline LL inv(LL x)
{
    return pow_mod(x,mof-2,mof);
}
LL Inv[maxn+7];
LL C(LL N,LL k)
{
    if(k>N||k<0)return 0;
    if(k==0||k==N)return 1;
    LL ans=1;
    ans=ans*jc[N]*Inv[k]%mof*Inv[N-k]%mof;
    return ans;
}
void init()
{
    jc[1]=jc[0]=1;
    for(LL i=2; i<=maxn; ++i) jc[i]=jc[i-1]*i%mof;
    for(int i=0; i<=maxn; ++i) Inv[i]=inv(jc[i]);
}
int n,k;
int a[maxn];
LL ans;
int main()
{
    init();
    cin>>n>>k;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n-k+1;++i)
    {
        ans += (-a[i] + mof) * C(n-i,k-1) % mof;
        ans %= mof;
    }
    for(int i=k;i<=n;++i)
    {
        ans += a[i] * C(i-1,k-1) % mof;
        ans %= mof;
    }
    cout<<ans<<endl;
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int n, l, t, a[N], b[N], w[N], ans;
int main()
{                         
	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)
			b[i] = (a[i] + t) % l;
		else
			b[i] = (a[i] - t % l + l) % l;
	}
	sort(b, b + n);

	for(int i = 1; i < n; i++){
		if(w[0] == w[i])
			continue;
		int p1 = a[0];
		int p2 = a[i];
		ans = (ans + t / l * 2) % n;
		ll d;
		
		if(w[0] == 1)
			d = (p2 - p1); 
		else
			d = (p1 - p2 + l);   
		
		if(d <= t % l * 2)
			ans = (ans + 1) % n;
		
		d += l;
		
		if(d <= t % l * 2)
			ans = (ans + 1) % n;
	}
	if(w[0] == 2)
		ans = (n - ans) % n;
	
	int cur, pos;

	if(w[0] == 1)
		cur = (a[0] + t) % l;
	else
		cur = (a[0] - t % l + l) % l;
	
	for(int i = 0; i < n; i++)
		if(b[i] == cur){
			pos = i;
			if(w[0] == 2)
				break;
		}

	for(int i = 0; i < n; i++)
		printf("%d\n", b[(i + pos - ans + n) % n]);
	return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int main(void){
	int n,m;
	int a[5001],b[5001];
	int i,j,k;
	int MAX=0;
	cin>>n>>m;
	for(i=0;i<n;i++)	cin>>a[i];
	for(i=0;i<m;i++)	cin>>b[i];
	for(k=0;k<m;k++){
		i=k;j=0;
		while(i<m){
			while(j<n){
				if(b[i]==a[j]){
					i++;
					j++;
				}
				else	j++;
			}
			MAX=max(MAX,(i+1)-(k+1));
			break;
		}
	}
	cout<<MAX<<endl;
	return 0;
}
	


Measured memory_bytes: 3160
s=sorted(input())
t=sorted(input(),reverse=True)
ans='Yes'
for i in range(min(len(s),len(t))):
    if ord(s[i])<ord(t[i]):
        break
    elif ord(s[i])==ord(t[i]):
        ans='UN'
        continue
    else:
        ans='No'
        break
if ans=='UN':
    if len(t)>len(s):
        ans='Yes'
    else:
        ans='No'
print(ans)

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

#define int long long

using namespace std;

 main () {
 	int n, k;
 	cin >> n >> k;
 	int gcd = 0;
 	int mn = 0;
 	for (int i = 1;i <= n;i ++) {
 		int x;
 		cin >> x;
 		gcd = __gcd (gcd, x);
 		mn = max (mn, x);
 	}
	if (k % gcd == 0 && k <= mn) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
    return 0;           		
}

Measured memory_bytes: 256
// C - Together
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }

int main(){
	int N; cin>>N;
	vi C(100000+1);
	int a,b,c, cmax = 0;
	rp(i, 0, N){
		cin>>a; C[a]++;
		cmax = max(cmax, a);
	}
	C.resize(max(3, cmax+1));
	// vprn(C);//

	int ans = 0;
	rp(x, 1, C.size()-1){
		ans = max(ans, C[x-1] + C[x] + C[x+1]);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   ll n,m;
   ll ans=0;
   cin>>n>>m;
   ans+=(n-1)*n*0.5;
   ans+=m*(m-1)*0.5;
   cout<<ans;

    return 0;
}


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

using namespace std;

int N, M;

bool ans;

int main()
{
	cin >> N >> M;
	vector<int> from1;
	vector<int> toN;
	for (int i = 0; i < M; i++){
		int bufA, bufB;
		cin >> bufA >> bufB;
		
		if (bufA == 1){
			from1.push_back(bufB);
		} else if (bufB == N){
			toN.push_back(bufA);
		}
	}
	
	ans = false;
	sort(toN.begin(), toN.end());
	
	for (int n : from1){
		if (binary_search(toN.begin(), toN.end(), n)){
			ans = true;
			break;
		}
	}
	
	if (ans) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
	return 0;
}


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

int dp[3][100010];
int a[100010],b[100010],c[100010];

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	if ((B - A) % 2 == 0) {
		cout << (B-A)/2 << endl;
	} else {
		auto r = N;
		{
			auto rr = A-1;
			auto a = 1LL, b = B - rr;
			++ rr;
			-- b;
			r = min(r, rr+(b-a)/2);
		}
		{
			auto rr = N-B;
			auto a = A + rr, b = N;
			++ rr;
			++ a;
			r = min(r, rr+(b-a)/2);
		}
		cout << r << endl;
	}
}


Measured memory_bytes: 256
import math


def koch(count, p1, p2):
    if count == 0:
        return
    s = [0, 0]
    t = [0, 0]
    u = [0, 0]
    s[0] = (2 * p1[0] + p2[0]) / 3
    s[1] = (2 * p1[1] + p2[1]) / 3
    t[0] = (2 * p2[0] + p1[0]) / 3
    t[1] = (2 * p2[1] + p1[1]) / 3
    u[0] = (t[0] - s[0]) * math.cos(math.pi / 3) - (t[1] - s[1]) * math.sin(math.pi / 3) + s[0]
    u[1] = (t[0] - s[0]) * math.sin(math.pi / 3) + (t[1] - s[1]) * math.cos(math.pi / 3) + s[1]

    koch(count - 1, p1, s)
    print(s[0], s[1])

    koch(count - 1, s, u)
    print(u[0], u[1])

    koch(count - 1, u, t)
    print(t[0], t[1])

    koch(count - 1, t, p2)


if __name__ == '__main__':
    n = int(input())
    p1 = [0.0, 0.0]
    p2 = [100.0, 0.0]
    print(p1[0], p1[1])
    koch(n, p1, p2)
    print(p2[0], p2[1])



Measured memory_bytes: 5780
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include<bitset>
#include <utility>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//#define xs1 xs
//#define xs2 x
//const ll M=1e9+7;
//const ll maxn=2e5+7;
//const int MAXN=1005;
const int MAX=2e5+5;
const int MAX_N=MAX;
//const int N=55;
const ll MOD=1000000007;
const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
ll xs1,xs2,ys1,ys2,xmin,xmax,ymin,ymax;
bool stx,sty;
struct node
{
    ll x,y;
}a[MAX];
int n,cnt,dp[MAX],ge;
bool cmp(node p,node q)
{
    return ((p.x-q.x)>0)==stx;//若满足 则从下标小到大为p在q的右侧
}
bool judge(ll nx,ll ny)
{
    if(nx<xmin||nx>xmax||ny<ymin||ny>ymax)
        return false;
    return true;
}
long double an;
int cn()//数最多有序的个数
{
    if(!cnt)
        return 0;
    sort(a,a+cnt,cmp);
    ge=1;
    dp[0]=a[0].y;
    for(int i=1;i<cnt;i++)
    {
//        printf("%d %d\n",dp[ge-1],a[i].y);
        if(((dp[ge-1]-a[i].y)>0)==sty)
        {
//            printf("!wow\n");
            dp[ge]=a[i].y;
            ++ge;
            continue;
        }
        int l=0,r=ge-1,mid,ans=-1;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(((dp[mid]-a[i].y)>0)==sty)
            {
                l=mid+1;
                ans=mid;
            }
            else
                r=mid-1;
        }
        dp[ans+1]=a[i].y;
//        if(ans+2>ge)
//            ge=ans+2;
    }
    return ge;
}
int main()
{
    scanf("%lld%lld%lld%lld",&xs1,&ys1,&xs2,&ys2);
    xmin=min(xs1,xs2);xmax=max(xs1,xs2);ymin=min(ys1,ys2);ymax=max(ys1,ys2);
    stx=(xs1-xs2)>0;//xs1在xs2右侧
    sty=(ys1-ys2)>0;//ys1在ys2上方
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        ll p,q;
        scanf("%lld%lld",&p,&q);
        if(judge(p,q))a[cnt++]=node{p,q};
    }
    int num=cn();
//    printf("num=%d \n",num);
    if(num==min(ymax-ymin+1LL,xmax-xmin+1LL))
        an=100.0*(xmax-xmin+ymax-ymin)+(10.0*pi-20.0)-(20.0-pi*5.0)*(num-1);
    else
    {
        an=100.0*(xmax-xmin+ymax-ymin)-(20.0-pi*5.0)*num;
    }
    printf("%.16Lf\n",an);
}

/*
2 2 1 1
2
2 1
1 2
*/


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

long join_number(vector<int> &num, int start, int end) {
  long sum = 0;
  int digit = end - start;
  for (int i = 0; i < digit; i++) {
    sum += num.at(start + i) * pow(10, digit - i - 1);
  }
  return sum;
}

vector<long> split_number(vector<int> &num, int start, int pcount) {
  if (pcount == 0) {
    return {join_number(num, start, num.size())};
  }

  vector<long> subset;
  for (int i = start; i < num.size() - pcount; i++) {
    long first_num = join_number(num, start, i + 1);
    vector<long> after_list = split_number(num, i + 1, pcount - 1);
    
    for (long number : after_list) {
      subset.push_back(first_num + number);
    }
  }
  return subset;
}

int main() {
  string S;
  cin >> S;

  vector<int> num(S.size());
  for (int i = 0; i < num.size(); i++) {
    num.at(i) = 0 + S.at(i) - 48;
  }

  long sum = 0;
  for (int i = 0; i < num.size(); i++) {
    for (long n : split_number(num, 0, i)) {
      sum += n;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3960
valuenum = int(input())

values = [int(input()) for _ in range(valuenum)]

Minv = values.pop(0)
ans = -(10 ** 9)

for Rj in values:
  temp_ans = Rj - Minv
  if temp_ans > ans:
    ans = temp_ans
  if Rj < Minv:
    Minv = Rj

print(ans)


Measured memory_bytes: 13600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int64_t> A(N),B(N),C(N);
    rep(n,0,N) cin>>A.at(n);
    rep(n,0,N) cin>>B.at(n);
    rep(n,0,N) cin>>C.at(n);

    sort(ToEnd(A));
    sort(ToEnd(B));
    sort(ToEnd(C));

    vector<int64_t> kA(N+1,0),kB(N+1,0);
    _rep(i,N-1,0) kB.at(i)=kB.at(i+1)+distance(upper_bound(ToEnd(C),B.at(i)),C.end());
    _rep(i,N-1,0) kA.at(i)=kA.at(i+1)+kB.at(distance(B.begin(),upper_bound(ToEnd(B),A.at(i))));

    int64_t ans=kA.front();
    cout<<ans<<endl;
}

Measured memory_bytes: 4224
import java.math.*

fun main(args: Array<String>) {
    val (n, d) = readInputLine().split(" ").map { it.toInt() }
    
    val points = mutableListOf<MutableList<Long>>()
    
    for (i in 1..n) {
        val xsList = mutableListOf<Long>()
        
        val xs = readInputLine().split(" ").map { it.toLong() }
        
        for (x in xs) {
            xsList.add(x)
        }
        
        points.add(xsList)
    }
    
    var ans = 0
    
    for (i in 0 until n) {
        for (j in (i + 1) until n) {
            var distance = 0L
            for (k in 0 until d) {
                distance += pow(points[j][k] - points[i][k], 2L)
            }
            
            for (i in 1..Int.MAX_VALUE) {
                val pow = pow(i.toLong(), 2L)
                if (pow > distance) {
                    break
                }
                if (pow == distance) {
                    ans++
                    break
                }
            }
        }
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}

fun pow(x: Long, y: Long): Long {
    var ret = 1L
    for (i in 1..y) {
        ret *= x
    }
    
    return ret
}


Measured memory_bytes: 37904
dic={}
n=int(input())
for i in range(n):
    s=input()
    if s not in dic:
        dic[s]=1
    else:
        dic[s]+=1
m=max(dic.values())
ans=[i for i,v in dic.items() if v==m]
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 94424
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f;
	string s1,s2;
	cin>>s1>>s2;
	n=s1.length();
	vector<vc>dp((s1.length()+1),vc(s2.length()+1));
	for(i=1;i<=s1.length();i++)
	{
	    for(j=1;j<=s2.length();j++)
	    {
	        if(s2[j-1]==s1[i-1])
	            dp[i][j]=dp[i-1][j-1]+1;
	        else 
	            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	i=s1.length();j=s2.length();
	string s="";
	while(i!=0&&j!=0)
	{
	    if(s1[i-1]==s2[j-1])
	    {
	        s=s1[i-1]+s;
	        i--;j--;
	    }
	    else
	    {
	        if(dp[i-1][j]>dp[i][j-1])
	            i--;
	        else
	            j--;
	    }
	    
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 74084
#include <iostream>
#include <algorithm>

using namespace std;

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

    if (N == 0) {
        cout << "0" << endl;
        return 0;
    }

    while (N != 0){
        int check = N % -2;

        if (check != 0 && N < 0) {
            n += "1";
            N = N / -2 + 1; 
        }else if(check != 0 && N > 0){
            n += "1";
            N /= -2;
        }else{
            n += "0";
            N /= -2;
        }
        
    }

    reverse(n.begin(), n.end());
    
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#C
H,W,K = map(int,input().split())
cake = [list(str(input())) for i in range(H)]

ans = [[0 for j in range(W)] for i in range(H)]
used = 1
for i in range(H):
    C = cake[i]
    #print(C)
    flag = 0
    if "#" in C:
        for j in range(W):
            if C[j] != "#":
                ans[i][j] = used
            else:
                if flag == 0:
                    flag = 1
                else:
                    used+=1
                ans[i][j] = used
        used+=1
    else:
        if i > 0:
            for j in range(W):
                if ans[i-1][j] != 0:
                    ans[i][j] = ans[i-1][j]
                    
for i in range(H):
    I = H-i-1
    A = ans[I]
    if 0 in A:
        if I != H-1:
            for j in range(W):
                if ans[I+1][j] != 0:
                    ans[I][j] = ans[I+1][j]
                    
for a in ans:
    print(*a)
        
    



Measured memory_bytes: 8272
n, T = gets.strip.split.map(&:to_i)

def chmin(a, b) a > b ? a : b end

INF = 10 ** 5
cost = INF
time = INF
n.times do
  c, t = gets.strip.split.map(&:to_i)
  if t <= T && c < cost
    cost = c
    time = t
  end
end

if cost != INF 
  puts cost
else
  puts 'TLE'
end


Measured memory_bytes: 1788
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int n = scanner.nextInt();
    int l = scanner.nextInt();
    
    ArrayList<String> word = new ArrayList<>();
    
    // N回データを取得し格納する
    for(int i = 0; i < n; i++) {
      word.add(scanner.next());
    }
    
    // データをソートする
    boolean changed = true;
    while(changed) {
      changed = false;
      for(int i = 1; i < n; i++) {
        if(compare(word.get(i), word.get(i - 1))) {
          String tmp; // 退避しておくところ
          tmp = word.get(i);
          word.set(i, word.get(i - 1));
          word.set(i - 1, tmp);
          changed = true;
        }
      }
    }
    
    for(String w: word) {
      System.out.print(w);
    }
  }
  
  
  public static boolean compare(String str1,String str2) {
    return str1.compareTo(str2) < 0;
  }
}


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

int main() {
  int A = 0, B = 0, C = 0, D = 0;
  
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef vector<pair<ll,ll> > vpl;
typedef vector<pair<int,int> > vpi;
typedef vector<ll> vec;
typedef map<ll,ll> mp;
ll GCD(ll a,ll b)
{
    if(a == 0)
    {
        return b;
    }
    return GCD(b%a,a);
}
int main()
{
    FastIO;
    int q = 1;
    //cin >> q;
    while(q--)
    {
        int n;
        cin >> n;
        if(n >=30)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}




Measured memory_bytes: 3556
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<i64>();
    let b = read::<i64>();
    let _c = read::<i64>();
    println!("{}", a * b / 2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
     string s;
     cin>>s;
     ll l=s.length();
     ll ans=0;
     for(int i=0;i<l;i++)
     {
         ans+=s[i]-'0';
     }
     if(ans%9==0)
     {
         cout<<"Yes"<<endl;
     }
     else
     {
         cout<<"No"<<endl;
     }


    return 0;
}


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

int main() {
  int M1, D1, M2, D2 ; 
  cin >> M1 >> D1 >> M2 >> D2;
  
  bool ans = 0;
  
  if (M1 != M2) {
    ans = 1;
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int d;
	int n, i;
	int ans;
	
	n = 600;
	while (scanf("%d", &d) != EOF){
		ans = 0;
		
		for (i = 0; i < n; i += d){
			ans += (d * i * i);
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 1024
s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
  query=input().split()
  if int(query[0])==1:
    r=1-r
  else:
    if (r^(int(query[1])-1))==0:
      f+=query[2]
    else:
      b+=query[2]
ret=f[::-1]+s+b
if r:
  ret=ret[::-1]
print(ret)

Measured memory_bytes: 9824
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let s = read::<String>().as_bytes().to_vec();

    println!(
        "{}",
        std::cmp::min(
            s.windows(2)
                .map(|x| if x[0] == x[1] { 1 } else { 0 })
                .sum::<usize>()
                + 2 * k,
            n - 1
        )
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();

    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();

        int answer = (a - 1) * (b - 1);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int x = Integer.parseInt(br.readLine());
            int a = Integer.parseInt(br.readLine());
            int b = Integer.parseInt(br.readLine());
            int temp = x - a;
            int ans = temp % b;
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
// 0 1 2 3
// 0 0 1 0
bool dbg;
int grundy(int n, int k) {
	//if(dbg) printf("n:%d, k:%d\n", n, k);
	if(n < 0) return 0;
	if(n / k == 0) return 0;
	if(n % k == 0) return n / k;
	// [n / k] == d
	// n -= d + 1 
	// (n - (d + 1)x) / k >= d
	// (n - (d + 1)x) >= kd
	// n - kd >= (d + 1)x
	// x <= (n - kd) / (d + 1);
	//n - (d + 1)(x + 1) < d
	int d = n / k;
	int x = (n - k * d) / (d + 1);
	if(!x) x++;
	return grundy(n - (d + 1) * x, k);
}
int main() {
	int m, n, k;
	scanf("%d", &m);
	int res = 0;
	for(int i=0; i<m; i++) {
		scanf("%d%d", &n, &k);
		int g = grundy(n, k);
		//printf("i:%d, g:%d\n", i, g);
		res ^= g;
	}
	puts(res ? "Takahashi" : "Aoki");
	return 0;
}

Measured memory_bytes: 256
a, b, k = gets.split.map(&:to_i)

lta = a + k - 1
stb = b - k + 1

if stb <= lta
  (a..b).each{|x| puts x}
else
  (a..lta).each{|x| puts x}
  (stb..b).each{|x| puts x}
end

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




int main() {

vector<int>K(3);
REP(i, 3) cin >> K.at(i);


if(K.at(0) == K.at(1) && K.at(1) == K.at(2)) print(1);
else if(K.at(0) == K.at(1) || K.at(1) == K.at(2)|| K.at(0) == K.at(2)) print(2);
else print(3);

}

Measured memory_bytes: 256
h,w,d=map(int,input().split())
c="RYGB"
for i in range(h):
	l=[]
	for j in range(w):
		x=(i-j)%(2*d)>=d
		y=(i+j)%(2*d)>=d
		l+=c[2*x+y]
	print(''.join(l))

Measured memory_bytes: 44252
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector <int>
#define vl vector <long long>
#define pb push_back
#define mk make_pair
#define pi pair <int,int>
#define pl pair <ll,ll>
#define rep(a,b) for(int i=a;i<=b;i++)
#define rep_(a,b) for(int i=a;i>=b;i--)
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d;
    cin>>n>>d;
    d=2*d+1;
    int ans=n/d;
    if(n%d)
    	ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main() {
   char r[20],temp;
   int i,j=0;
   gets(r);
   i = 0;
   j = strlen(r) - 1;
   while (i < j) {
      temp= r[i];
      r[i]=r[j];
      r[j]=temp;
      i++;
      j--;
   }
   printf("%s\n",r);
   return (0);
}

Measured memory_bytes: 916
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}


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

    int N;
    cin >> N;

    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(to_string(i).size() % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000000
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 200001;
const ll M = 21;
struct point {
    ll x, y, cur;
    bool operator == (const point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (const point b) {return !(*this == b);}
    friend bool operator < (const point a, const point b)
    {
        if(a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}
bool overflow;
ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         if(ans > ans * ans % mod)
                overflow = 1;
         ans = ans * ans % mod;
    }
    else
    {
        ans = fast_exp(x, n - 1);
        if(ans > ans * x % mod)
            overflow = 1;
        ans = ans * x % mod;
    }
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 0, x = 0, y = 1, ans = 0, p;
        cin >> n >> m >> x >> y;
        ll dp[x + 2][y + 2] = {};
        for(int i = 0; i <= n; i++)
        {
            for(int j = 0; j <= m ; j++)
                dp[i][j] = 1;
        }
        for(int i = n + 1; i <= x; i++) dp[i][m] = dp[i - 1][m] * m % mod;
        for(int i = m + 1; i <= y; i++) dp[n][i] = dp[n][i - 1] * n % mod;
        for(ll i = n + 1; i <= x; i++)
        {
            for(ll j = m + 1; j <= y ; j++)
            {
                dp[i][j] = dp[i - 1][j] * j % mod + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod + mod;
                dp[i][j] %= mod;
            }
        }
        cout << dp[x][y] << "\n";
     }
     return 0;
}


Measured memory_bytes: 74016
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

mod = 998244353
N, M, K = mapint()

pos = {}
neg = {}
pos[0] = 1
neg[0] = 1
for i in range(1, N+1):
    pos[i] = i*pos[i-1]%mod
    neg[i] = pow(pos[i], mod-2, mod)
ans = 0
for i in range(K+1):
    ans += M*pow((M-1), (N-i-1), mod)*pos[N-1]*neg[i]*neg[N-i-1]
    ans %= mod
print(ans)

Measured memory_bytes: 113180
#include "bits/stdc++.h"
    using ll = long long;
    using namespace std;
    int main(){
    ll ans;
    string k;
    cin>>k;
      
    if(k[0]+k[1]+k[2]+k[3]==k[0]*4){
      cout<<"No"<<endl;
    return 0;
    }
      
      
    if(k[0]==k[1]){
    if(k[2]==k[3]){
    cout<<"Yes"<<endl;
    return 0;
    }
    }
    if(k[0]==k[2]){
    if(k[1]==k[3]){
    cout<<"Yes"<<endl;
    return 0;
    }
    }
    if(k[0]==k[3]){
    if(k[1]==k[2]){
    cout<<"Yes"<<endl;
    return 0;
    }
    }
     
    cout<<"No"<<endl;
    return 0;
     
    }

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(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    int x;
    cin >> x;
    a[x-1]=i+1;
  }
  rep(i,n) cout << a[i] << ' ';
  return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N;
int h[100];

void dfs(int i) {
  h[i]--;
  int ni = i + 1;
  if (ni < N && h[ni] != 0) dfs(ni);
  return;
}

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> h[i];

  int ans = 0;
  rep(i, 0, N) {
    int t = h[i];
    rep(j, 0, t) {
      dfs(i);
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

dp = [0]*(1 << n)
for bit_state in range(1 << n):
    for i in range(n):
        if not((1 << i) & bit_state): 
            tmp = 0
            for j in range(n):
                if (1 << j) & bit_state: 
                    tmp += a[i][j]
            dp[bit_state|(1<<i)] = dp[bit_state] + tmp 

dq = [0]*(1 << n)
for mask in range(1 << n):
    bit_state = mask
    while bit_state >= 0:
         bit_state &= mask
         dq[mask] = max(dq[mask], dp[bit_state] + dq[mask - bit_state])
         bit_state -= 1
print(dq[-1])

Measured memory_bytes: 47372
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]

gates = [list(map(lambda x: int(x), input().split())) for i in range(m)]

first_max = 0
second_min = 100001
for gate in gates:
  first_max = max(first_max, gate[0])
  second_min = min(second_min, gate[1])

answer = second_min - first_max + 1
if (answer <= 0):
  print(0)
else:
  print(answer)

Measured memory_bytes: 27356
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
int main()
{
    int n;
    ll ans=0;int x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        ans+=1ll*x;
    }
    printf("%lld\n",ans-n);
    return 0;
}


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

    int main() {
      int N, count = 0;
      cin >> N;
      if(N >= 1) {
        for(int i = 1; i <= N; i++) {
          if(to_string(i).length() % 2 == 1)
            count++;
        }
     }
      cout << to_string(count);
      return 0;
    }

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

// 19
public class Main {
    static int func(int n) {
        if(n % 2 == 0) return n / 2;
        return 3 * n + 1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Set<Integer> set = new HashSet<Integer>();
        int i = 1;
        while(true) {
            set.add(n);
            n = func(n);
            if(set.contains(n))
                break;
            ++i;
        }

        System.out.println(i + 1);
    }

}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d){
    cout << "Left" <<endl;
  }else if (a+b<c+d){
    cout << "Right" <<endl;
  }else{
    cout << "Balanced" <<endl;
  }
}

Measured memory_bytes: 256
import sys
import numpy as np
from math import ceil as C, floor as F
from collections import defaultdict as D
 
def S(): return sys.stdin.readline().rstrip().split(' ')
def Ss(): return list(S())
def I(): return _I(S())
def Is(): return list(I())
def _I(ss): return map(int, ss) if len(ss) > 1 else int(ss[0])
 
N = I()
alp = 'abcdefghijklmnopqrstuvwxyz'
 
def get_name(n, name):
  n = n-1
  
  if n <= 25:
    return '{}{}'.format(alp[n], name)
  
  q = F(n / 26)
  r = n % 26
  return get_name(q, '{}{}'.format(alp[r], name))
 
print(get_name(N, ''))

Measured memory_bytes: 27032
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
};

struct edge {
    int u, v;
    int64_t cost;
    edge(int u=0, int v=0, int64_t cost=0):u(u), v(v), cost(cost) {} 
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

vector<edge> es; // 辺の数でresize
//最小全域木
int64_t kruskal(int V) { // Vは頂点数
    int E = es.size();
    sort(es.begin(), es.end(), comp);
    UnionFind uft(V);
    int64_t res = 0;
    for(int i = 0; i < E; ++i) {
        edge e = es[i];
        if(!uft.same(e.u, e.v)) {
            uft.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

bool comp_(const pair<int, P>& x, const pair<int, P>& y) {
    return x.second.first < y.second.first;
}

int main() {
    int n;
    cin >> n;
    vector<pair<int, P> > po(n);
    rep(i, n) {
        cin >> po[i].first >> po[i].second.first;
        po[i].second.second = i;
    }

    vector<pair<int, P> > popo = po;
    sort(all(po));
    sort(all(popo), comp_);
    rep(i, n-1) {
        es.push_back(edge(po[i].second.second, po[i+1].second.second, min(abs(po[i].first-po[i+1].first), abs(po[i].second.first-po[i+1].second.first))));
        es.push_back(edge(popo[i].second.second, popo[i+1].second.second, min(abs(popo[i].first-popo[i+1].first), abs(popo[i].second.first-popo[i+1].second.first))));
    }

    cout << kruskal(n) << endl;
}

Measured memory_bytes: 8816
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,a,b,c,sum=0;
    cin>>a>>b>>c;
    if(c%__gcd(a,b)==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}





Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,h,i,j,s,z,k,len;
	char a[201],b[201];
	while(1){
		scanf("%s",a);
		if(a[0]=='-')break;
		len=strlen(a);
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&h);
			s=len-h;
			for(j=0;j<h;j++){
				b[s]=a[j];
				s++;
			}
			s=0;
			for(j=h;j<len;j++){
				b[s]=a[j];
				s++;
			}
			for(j=0;j<len;j++){
				a[j]=b[j];
			}
		}
		printf("%s\n",a);
	}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    int h[n];
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int max = h[0];
    for(int i = 0; i < n; i++) {
        if(max - 1 > h[i]) {
            cout << "No";
            return 0;
        }else if(max < h[i]) {
            max = h[i];
        }
    }
    /*
    for(int i = 0; i < n-1; i++) {
        if(h[i] > h[i+1]) {
            h[i]--;
        }
    }
    int height = h[0];
    for(int i = 0; i < n; i++) {
        if(height <= h[i]) {
            height = h[i];
        }else {
            cout << "No";
            return 0;
        }
    }
    */
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
from operator import itemgetter

N=int(input())
grid=[]
for i in range(N):
    xi,li=map(int,input().split())
    grid.append((xi-li,xi+li))
grid = sorted(grid, key=itemgetter(1))
res=1
cur=grid[0]

for i, a in enumerate(grid):
    if i==0:
        continue
    if a[0]>=cur[1]:
        res+=1
        cur=a
print(res)

Measured memory_bytes: 19112
#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() { int x;
    cin >> x;
    if (x == 0) cout << 1 << endl;
    if (x == 1) cout << 0 << endl;
}

Measured memory_bytes: 3612
import sys
import numpy as np
import numba

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


@numba.njit("(i8, i2[:], i4[:,:], i2[:])", cache=True)
def optimize(D, C, S, sol):
    NUM_ITERS = 240000

    def calc_score(sol):
        last = -np.ones((26, D + 1))
        score = 0
        for d in range(D):
            ct = sol[d]
            score += S[d, ct]
            for i in range(26):
                last[i, d + 1] = last[i, d]
            last[ct, d + 1] = d
            for i in range(26):
                score -= C[i] * (d - last[i, d + 1])
        return score, last

    sol_bak = sol.copy()
    max_score, last = calc_score(sol)
    last_bak = last.copy()

    def update(d, before, after):
        score = max_score
        score -= S[d, before]
        score += S[d, after]
        lb = last[before, d]
        la = last[after, d]
        da = db = 0
        for x in range(d, D):
            if x > d and sol[x] == before:
                break
            last[before, x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if x > d and sol[x] == after:
                break
            last[after, x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        sol[d] = after
        return score

    tried = numba.typed.Dict.empty(
        key_type=numba.types.int32, value_type=numba.types.boolean
    )
    for i in range(NUM_ITERS):
        new_d = np.random.randint(0, D)
        c_before = sol[new_d]
        c_after = np.random.randint(0, 26)
        if c_before == c_after:
            continue
        candidate = new_d * 26 + c_after
        if candidate in tried:
            continue
        tried[candidate] = True
        new_score = update(new_d, c_before, c_after)
        if max_score < new_score:
            max_score = new_score
            sol_bak = sol.copy()
            last_bak[c_before, :] = last[c_before, :].copy()
            last_bak[c_after, :] = last[c_after, :].copy()
            tried.clear()
        else:
            sol = sol_bak.copy()
            last[c_before, :] = last_bak[c_before, :].copy()
            last[c_after, :] = last_bak[c_after, :].copy()
    return sol


def main():
    D = ini()
    C = np.array(inl(), dtype="int16")
    assert len(C) == 26
    S = np.zeros((D, 26), dtype="int32")
    for i in range(D):
        S[i, :] = inl()

    sol = np.zeros(D, dtype="int16")
    last = -np.ones(26, dtype="int16")
    for d in range(D):
        score = 0
        mi = -1
        for i in range(26):
            s = S[d, i] - C[i] * (d - last[i])
            if score < s:
                score = s
                mi = i
        sol[d] = mi
        last[mi] = d
    sol = optimize(D, C, S, sol)

    print(*(sol + 1), sep="\n")


main()


Measured memory_bytes: 108536
N,L = map(int,input().split())
tas = list(L+i for i in range(N))
sum_tas = sum(tas)
ans = 0
if tas[0]>0:
    ans = sum_tas - tas[0]
elif tas[-1]<0:
    ans = sum_tas - tas[-1]
else:
    ans = sum_tas
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;

int main() {
    ll n, k, m;
    cin>>n>>k;
    
    m = n/k;
    
    n = n - k * m;
    
    n = min(n, abs(n-k));
    
    cout<<n<<endl;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_057
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            double rn = Math.Sqrt(n);
            for (long i = (long)rn; i >=1; i--)
            {
                if (n % i != 0) continue;

                long b = n / i;
                int digit = (int)Math.Log10(b) + 1;
                Console.WriteLine(digit);
                return;
            }
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
typedef long long LL;
const LL maxn=2e3+9;
LL n;
LL a[maxn],pos[maxn],f[maxn][maxn];
bool cmp(LL x,LL y){
	return a[x]>a[y];
}
int main(){
	scanf("%lld",&n);
	for(LL i=1;i<=n;++i) scanf("%lld",a+i);
	for(LL i=1;i<=n;++i) pos[i]=i;
	std::sort(pos+1,pos+1+n,cmp);
	f[0][0]=0;
	for(LL i=1;i<=n;++i){
		LL x(pos[i]);
		for(LL j=0;j<=i;++j){
			if(j) f[i][j]=f[i-1][j-1]+a[x]*std::abs(x-j);
			if(j!=i) f[i][j]=std::max(f[i][j],f[i-1][j]+a[x]*std::abs(x-(n-(i-1-j))));
		}
	}
	LL ans(0);
	for(LL i=0;i<=n;++i){
		ans=std::max(ans,f[n][i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
static const int MOD = 1000000007;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	for(int i = 0; i < n; ++i){ cin >> b[i]; }
	vector<bool> fixed(n);
	fixed[0] = fixed[n - 1] = true;
	int a_max = 0, b_max = n - 1;
	for(int i = 1; i < n; ++i){
		if(a[i] > a[i - 1]){
			fixed[i] = true;
			a_max = i;
		}
	}
	for(int i = n - 2; i >= 0; --i){
		if(b[i] > b[i + 1]){
			fixed[i] = true;
			b_max = i;
		}
	}
	if(a_max >  b_max || a[a_max] != b[b_max]){
		cout << 0 << endl;
		return 0;
	}
	ll answer = 1;
	for(int i = 0; i < n; ++i){
		if(fixed[i]){ continue; }
		answer = (answer * min(a[i], b[i])) % MOD;
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {

	var N, X int
	fmt.Scanf("%d %d", &N, &X)

	L := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &L[i])
	}

	var count int = 1
	D := make([]int, N+1)
	D[1] = 0
	for i := 1; i < N+1; i++ {
		D[i] = D[i-1] + L[i-1]
		if X < D[i] {
			break
		}
		count++
	}

	fmt.Println(count)
}


Measured memory_bytes: 1848