akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int X;
int Y;
int K;
char S[300][302];
int res[300][300];
int main(){
  int i;
  int j;
  int k = 0;
  rd(X);
  rd(Y);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(X);Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(X);i++){
    for(j=(0);j<(Y);j++){
      if(S[i][j]=='#'){
        res[i][j] = (++k);
      }
    }
  }
  for(i=(0);i<(X-1);i++){
    for(j=(0);j<(Y);j++){
      if(res[i][j] && res[i+1][j]==0){
        res[i+1][j] = res[i][j];
      }
    }
  }
  for(i=(X)-1;i>=(1);i--){
    for(j=(0);j<(Y);j++){
      if(res[i][j] && res[i-1][j]==0){
        res[i-1][j] = res[i][j];
      }
    }
  }
  for(i=(0);i<(X);i++){
    for(j=(0);j<(Y-1);j++){
      if(res[i][j] && res[i][j+1]==0){
        res[i][j+1] = res[i][j];
      }
    }
  }
  for(i=(0);i<(X);i++){
    for(j=(Y)-1;j>=(1);j--){
      if(res[i][j] && res[i][j-1]==0){
        res[i][j-1] = res[i][j];
      }
    }
  }
  for(i=(0);i<(X);i++){
    {
      int BUotOFBp;
      if(Y==0){
        putchar_unlocked('\n');
      }
      else{
        for(BUotOFBp=(0);BUotOFBp<(Y-1);BUotOFBp++){
          wt_L(res[i][BUotOFBp]);
          wt_L(' ');
        }
        wt_L(res[i][BUotOFBp]);
        wt_L('\n');
      }
    }
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int X, Y, K;
// char S[300][302];
// int res[300][300];
// 
// {
//   int i, j, k = 0;
//   rd(X,Y,K,S(X));
//   rep(i,X) rep(j,Y) if(S[i][j]=='#') res[i][j] = (++k);
// 
//   rep(i,X-1) rep(j,Y) if(res[i][j] && res[i+1][j]==0) res[i+1][j] = res[i][j];
//   rrep(i,1,X) rep(j,Y) if(res[i][j] && res[i-1][j]==0) res[i-1][j] = res[i][j];
//   rep(i,X) rep(j,Y-1) if(res[i][j] && res[i][j+1]==0) res[i][j+1] = res[i][j];
//   rep(i,X) rrep(j,1,Y) if(res[i][j] && res[i][j-1]==0) res[i][j-1] = res[i][j];
// 
//   rep(i,X) wt(res[i](Y));
// }


Measured memory_bytes: 1152
//  ######    ##   ######    ##   ##    ##
//  ##  ##   ###   ##  ##   ###   ###   ##
//  ######  ####   ######  ####   ##### ##
//  ##     ## ##   ##     ## ##   ## #####
//  ##    ##  ##   ##    ##  ##   ##   ###
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define mod 1000000007
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 


void solve()
{
   
    int n;
    string str;
    cin>>n>>str;
    if(n%2==1){cout<<"No";return;}
    int i=0,j=n/2;
    while(j<n)
    {
        if(str[i]!=str[j]){cout<<"No";return;}
        i++;
        j++;
    }
    cout<<"Yes";
}



int main()
{
    /*   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    lo t;
    //cin>>t;
    //while(t--)
        solve();




}


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

int main() {
	int n;
	int k;
	cin>>n;
	cin>>k;
    vector<int> arr (n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr.begin(),arr.end());
    int sum=0;
    for(int i=0;i<k;i++)
    {
        sum+=arr[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3632
[h,w,k]=list(map(int,input().split()))
cake=[]
for i in range(h):
	cake.append(list(input()))
ans=[[0 for i in range(w)]for j in range(h)]
num=1
ichigo=[]
for i in range(h):
	for j in range(w):
		if cake[i][j]=="#":
			ans[i][j]=num
			ichigo.append([i,j,num])
			num+=1
for i in range(len(ichigo)):
	yoko=ichigo[i][1]+1
	while True:
		if yoko==w:
			break
		elif ans[ichigo[i][0]][yoko]==0:
			ans[ichigo[i][0]][yoko]=ichigo[i][2]
			yoko+=1
		else:
			break
for i in range(len(ichigo)):
	left=ichigo[i][1]-1
	while True:
		if left<0:
			break
		elif ans[ichigo[i][0]][left]==0:
			ans[ichigo[i][0]][left]=ichigo[i][2]
			left-=1
		else:
			break

for i in reversed(range(ichigo[0][0])):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i+1][j]

for i in range(ichigo[0][0],h):
	for j in range(w):
		if ans[i][j]==0:
			ans[i][j]=ans[i-1][j]

for i in range(h):
	for j in range(w):
		print(ans[i][j], end=" ")
	print( )
	

Measured memory_bytes: 19536
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main() {
	int n = in();
	vector<int>a(n);
	REP(i, n) {
		a[i] = in();
	}
	int m = in();
	vector<int>b(m);
	REP(i, m) {
		b[i] = in();
	}
	vector<int>result;
	set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(result, result.end()));
	REPC(i, result) {
		cout << i << endl;
	}
}


Measured memory_bytes: 4640
import java.util.Scanner;

class Main {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int    x = in.nextInt();
       int    y = in.nextInt();
       int    z = in.nextInt();
       int    w;
       
       if(x>y){
	w = x;
        x = y;
        y = w;
	}

	if(x>z){
	w = x;
	x = z;
	z = w;
	}

	if(y>z){
	w = y;
	y = z;
	z = w;
	}



       System.out.println(x + " " + y + " " + z);
   }
}

Measured memory_bytes: 17340
# AGC007A - Shik and Stone
import sys
input = sys.stdin.readline

def main():
    h, w = tuple(map(int, input().rstrip().split()))
    B = tuple(input().rstrip() for _ in range(h))
    cnt = ("".join(B)).count("#")
    print("Possible" if cnt == h + w - 1 else "Impossible")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
int H,W,i,j;

while(1){
scanf("%d %d",&H, &W);

if(H == 0 && W == 0)break;

for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
        if( i != 0 && i != H - 1 && j != 0 && j != W - 1 ){
            printf(".");
        } else {
            printf("#");
        }
    }
    printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cstring>
using namespace std;

int flag[8]={1,2,6,24,120,720,5040,40320};

int main()
{
    int n;
    cin>>n;
    int num1[n];
    int num2[n];
    int i,j,k;
    for(i=0;i<n;i++)
        cin>>num1[i];
    for(i=0;i<n;i++)
        cin>>num2[i];
    int ans1=0,ans2=0,a[n],b[n];
    a[0]=num1[0]-1;
    b[0]=num2[0]-1;
    for(i=1;i<n;i++)
    {
        a[i]=num1[i]-1,b[i]=num2[i]-1;
        for(j=0;j<i;j++)
        {
            if(num1[j]<num1[i])
                a[i]--;
            if(num2[j]<num2[i])
                b[i]--;
        }
    }
    for(i=0;i<n;i++)
    {
        ans1+=(a[i]*flag[n-2-i]);
        ans2+=(b[i]*flag[n-2-i]);
    }
    cout<<abs(ans1-ans2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string s;
int main() 
{
    cin>>s;
    int ans=s.size(),len=s.size();
    for(int i=0;i<s.size()-1;i++)
        if(s[i]!=s[i+1])
            ans=min(ans,max(i+1,len-i-1));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <cctype>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    if(a==b) cout << "Draw" << endl;
    else if(a==1||b==1){
        if(a>b) cout << "Bob" << endl;
        else cout << "Alice" << endl;
    }
    else{
        if(a<b) cout << "Bob" << endl;
        else cout << "Alice" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] count  = new int[N+1];
        for(int i=2; i<=N; i++){
            int a = scanner.nextInt();
            count[a] ++;
        }
        for(int i=1; i<=N; i++){
            System.out.println(count[i]);
        }
    }
}

Measured memory_bytes: 62536
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin>>s;
  switch(s[s.size()-1]){
    case '3':
      cout<<"bon"<<endl;
      break;
    case '0':
    case '1':
    case '6':
    case '8':
      cout<<"pon"<<endl;
      break;
    default:
      cout<<"hon"<<endl;
      break;
  }
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;
typedef long long ll;
const int maxn = 1e6;
ll n, t, a[maxn], b[maxn];
int main()
{
    cin>>n;
    for(int i = 1; i <= n; i++) cin>>a[i]>>b[i];
    for(int i = n; i >= 1; i--)
    {
        while((a[i]+t) % b[i] != 0)
            t += (b[i] - (a[i]+t)%b[i]);
    }
    cout<<t<<endl;
}


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

using namespace std;

int main()
{
	string a;
	cin>>a;
	int len=a.length();
	for(int i=0;i<len-1;i++)
	{
		if(a[i]=='C')
		{
			for(int j=i;j<len;j++)
			if(a[j]=='F')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
signed main(){
  int a;
  scanf("%d",&a);
  int b[100];
  for(int c=0;c<a;c++){
      scanf("%d",&b[c]);
      }
      for(int d=a-1;d!=-0;d--){
	  printf("%d ",b[d]);
	  }
	  printf("%d\n",b[0]);	  
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
  ll N,M,i,j,A;cin>>N>>M;ll answer[N+1];bool condition[N+1];
  memset(condition,true,sizeof(condition)/sizeof(bool));
  for(i=0;i<M;i++){cin>>A;condition[A]=false;}
  answer[0]=1;
  if(condition[1]){answer[1]=1;}else{answer[1]=0;}
  for(i=2;i<=N;i++){if(!condition[i]){answer[i]=0;}else{answer[i]=(answer[i-1]+answer[i-2])%1000000007;}}
  cout<<answer[N]<<endl;
  return 0;
}

Measured memory_bytes: 1152
#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 M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
ll dfs(ll x,VLL ad[],ll dp[])
{
    if(dp[x]!=-1) return dp[x];
    ll nv=ad[x].size();
    ll ans=0;
    REP(i,0,nv)
    {
        ans=max(ans,dfs(ad[x][i],ad,dp));
    }
    dp[x]=ans+1;
    return dp[x];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,m;
        cin>>n>>m;
        VLL ad[n];
        REP(i,0,m)
        {
            ll t1,t2;
            cin>>t1>>t2;
            ad[t1-1].PB(t2-1);
        }
        ll dp[n];
        REP(i,0,n) dp[i]=-1;
        ll ans=0;
        REP(i,0,n)
        {
            ans=max(ans,dfs(i,ad,dp));
        }
        cout<<ans-1;
    }
 
    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;



int main()
{
    FAST
    ll mon=1000,st=0;
    ll n;cin>>n;
    ll a[n];f(i,0,n) cin>>a[i];
    ll start=0;
    while(start<n-1 && a[start]>=a[start+1]) start++;
    if(start==n-1)
    {
        cout<<1000<<endl;
        return 0;
    }
    while(mon-a[start]>=0) mon-=a[start],st++;
    ll pos=start+1;
    while(1)
    {
        while(pos<n-1 && a[pos]<=a[pos+1]) pos++;
        while(st) mon+=a[pos],st--;
        while(pos<n-1 && a[pos]>=a[pos+1]) pos++;
        if(pos!=n-1) 
        {
            st += mon/a[pos];
            mon -= st*a[pos];
        }
        else if(pos>=n-1) break;
    }
    cout<<mon<<endl;
}


Measured memory_bytes: 3644
from heapq import heappop, heappush


def solve(field, s, t, k):
    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0
    MOVE = [(-w2, 0), (-1, 1), (1, 1), (w2, 0)]

    q = [(0, s, 0)]
    while q:
        cost, v, direction = heappop(q)
        if v == t:
            return (cost - 1) // k + 1

        ceiling = ((cost - 1) // k + 1) * k + 1
        for di, ax in MOVE:
            u = v + di
            if field[u] == '@':
                continue
            nc = cost + 1 if di == direction else ceiling
            if ans[u][ax] <= nc:
                continue
            ans[u][ax] = nc
            heappush(q, (nc, u, di))

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = ['@' * w2]
for row in field_tmp:
    field.append('@')
    field.append(row)
    field.append('@')
field.append('@' * w2)
field = ''.join(field)
s = x1 * w2 + y1
t = x2 * w2 + y2
print(solve(field, s, t, k))


Measured memory_bytes: 444872
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var s = next();
  var t = "";
  for(var i = 0; i < N / 2; i++){
    t += s[i];
  }
  if(t + t == s){
    myout("Yes");
  }else{
    myout("No");
  }
}


Measured memory_bytes: 31104
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long n,a[2],b;
	char z;
	cin>>n;
	a[0]=0,a[1]=0;
	bool no=false;
	for(int i=0;i<n;i++){
		cin>>z>>b;
		if(z=='(')
			a[0]+=b;
		else
			a[1]+=b;
		if(a[1]>a[0])
			no=true;
	}
	if(no==true||a[0]!=a[1])cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1160
x, k, d = map(int, input().split())
x = abs(x)
flag = 0
times = 0

# ==0はどちらに置いても良い
# 0を跨がない(そのまま引いて終了)
if x - d * k >= 0:
    ans = x - d * k

# 0を跨ぐ
else:
    # 0を跨ぐ直前まで何回動くことができるか x//dで求め(ギリギリまで引き続けることと同じなのであまり(k -= times)が偶数の場合は0を跨いだときの方が小さくなることはない)
    # 偶 2までたどり着いて2度3動く場合は2に戻るのが最適
    # 奇 2までたどり着いて1度3動く場合はabs|-1| == 1
    # 割り算なので 3までたどり着いて3動くということはない(余らない)
    
    # 座標と回数を反映
    times = x // d
    k = k - times
    x -= d * times
    if k % 2 == 0:
        ans = x
    else:
        ans = abs(x - d)
print(ans)

Measured memory_bytes: 9152
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;


#define ll          long long
#define pb          push_back
#define pii         pair<int ,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define REP(i,n) for (int i = 1; i <= n; i++)

// mp::cpp_int



int solve( ){
    
  ll s;
  int k=1;
  cin>>s;
  map<ll,ll> m;
  m[s]++;
  while(true)
  {  k++;
     if(s%2==0){ s=s/2;m[s]++;}
     else
      {s=3*s+1;m[s]++;}
    if(m[s]>=2){cout<<k;return 0;}
  }



return 0;
}
 

int main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
  
  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;
   while(t--)
     {solve();
     }

         time_req = clock() - time_req;
    //cout << "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}


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

using namespace std;

struct LOG_DATA{
  bool is;
  int wa, t;
  LOG_DATA(){ is = false; wa = 0; t = 0; }
  void correct(int t_){ is = true; t = t_ + 1200*wa; }
  void wrong(){ ++wa; }
};

struct RESULT_DATA{
  int id, ans, pn;
  RESULT_DATA(){ id = 0; ans = 0; pn = 0; }
};

bool compare(const RESULT_DATA& a, const RESULT_DATA& b){
  if(a.ans != b.ans) return (a.ans > b.ans);
  if(a.pn != b.pn) return (a.pn < b.pn);
  return (a.id < b.id);
}

int main(){
  int t, p, r;
  int t_, p_, time;
  string result;

  while(1){
    cin >> t >> p >> r;
    if(!t && !p && !r) break;

    vector< vector<LOG_DATA> > data1(t, vector<LOG_DATA>(p, LOG_DATA()));
    for(int i=0; i<r; ++i){
      cin >> t_ >> p_ >> time >> result;
      --t_; --p_;
      if(data1[t_][p_].is) continue;
      if(result == "CORRECT") data1[t_][p_].correct(time);
      else data1[t_][p_].wrong();
    }

    vector<RESULT_DATA> data2(t, RESULT_DATA());
    for(int i=0; i<t; ++i){
      data2[i].id = i+1;
      for(int j=0; j<p; ++j){
	if(!data1[i][j].is) continue;
	++data2[i].ans;
	data2[i].pn += data1[i][j].t;
      }
    }

    sort(data2.begin(), data2.end(), compare);
    for(int i=0; i<t; ++i)
      cout << data2[i].id << " " << data2[i].ans << " " << data2[i].pn << endl;
  }
  return 0;
}

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

int main(){
    int a,b,c;
    cin >> a>>b>>c;
    
    cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
int n, l, j, u, k, tmp;
int list[100][100];
int lengthlist[100];

void search(int y, int length){
  int i;
  length++;
  lengthlist[y] = length;


  for( i = 0 ; i < n ; i++){
    if( list[y][i] == 1 ){
      if( lengthlist[i] <= length && lengthlist[i] >= 0 ){
        continue;
      }
      search(i, length);
    }
  }
}

int main(){
  scanf("%d", &n);
  for(l = 0 ; l < n ; l++){
    scanf("%d", &u);
    scanf("%d", &k);
    for( j = 0 ; j < k ; j++){
      scanf("%d", &tmp);
      list[u-1][tmp-1] = 1;
    }
  }
  for( l = 0 ; l < n ; l++){
    lengthlist[l] = -1;
  }
  search(0, -1);

  for(j = 0 ; j < n ; j++){
    printf("%d %d\n", j+1, lengthlist[j]);
  }

  return 0;
}



Measured memory_bytes: 2104
def convert(s):
    convertStr = ""
    l = len(s)
    i = 0
    while i < l:
        if i + 1 < l:
            word = s[i]
            sequenceNum = 1
            j = i + 1
            while j < l:
                if(word == s[j]):
                    sequenceNum += 1
                else:
                    break
                j += 1
            convertStr += str(sequenceNum) + word
            i = i + sequenceNum - 1
        else:
            convertStr += "1" + str(s[i])
        i += 1
    return convertStr

while True:
    try:
        n = int(input())
        s = input()
        for i in range(0,n):
            s = convert(s)
        print(s)
    except:
        break


Measured memory_bytes: 5636
q = int(input())
l = [list(map(int,input().split())) for _ in range(q)]

def prime_table(n):
    list = [True for _ in range(n+1)]
    for i in range(2,int(n**0.5)+1):
        if list[i]:
            j = i*2
            while j<=n:
                list[j] = False
                j += i
    table = [i for i in range(n+1) if list[i] and i>=2]
    return table

table = prime_table(10**5)
table_set = set(table)
sim_sum = [0]*(10**5+1)

for p in table:
    if p*2-1 in table_set:
        sim_sum[p*2-1] += 1
for i in range(1,10**5+1):
    sim_sum[i] += sim_sum[i-1]
for l_ in l:
    print(sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])

Measured memory_bytes: 32236
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// A, Bの入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		// 結果の出力
		System.out.println(Math.max(0, A-(2*B)));
		
		sc.close();
	}

}


Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,m) for(int i=0;i<m;i++)
using namespace std;

int main(){
    int n, temp, a=0, b=0;
    vector<int> vec;
    cin >> n;
    rep(i,n){
        cin >> temp;
        vec.push_back(temp);
    }
    
    sort(vec.begin(), vec.end());
    
    while(vec.size()>0){
        a += vec.back();
        vec.pop_back();
        if(vec.size() <= 0) break;
        b += vec.back();
        vec.pop_back();
    }
    
    cout << a - b << endl;
    
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;

int main() {
long	double W, H;
long	double x, y;
	cin >> W >> H >> x >> y;
	W / 2 == x && H / 2 == y ? cout <<W * H / 2 << " " << 1: cout << W * H / 2 << " " << 0;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
#define sz(x) (int) (x).size()
#define INF 0x3f3f3f3f
#define pb push_back
    
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
    
const int N = 100005;
const int mod = 1000000007;

int n, a[N], b[N], c[N];
int dp[N][3][3];

int solve(int pos, int cur, int q) {
    if (pos == n) return 0;
    int &ans = dp[pos][cur][q];
    if (ans != -1) return ans;
    if (cur == 0) {
        ans = a[pos] + solve(pos + 1, 1, q);
        ans = max(ans, a[pos] + solve(pos + 1, 2, q));
    }
    else if (cur == 1) {
        ans = b[pos] + solve(pos + 1, 0, q);
        ans = max(ans, b[pos] + solve(pos + 1, 2, q));
    }
    else {
        ans = c[pos] + solve(pos + 1, 1, q);
        ans = max(ans, c[pos] + solve(pos + 1, 0, q));
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        for (int j = 0; j < 3; j++)
            dp[i][j][0] = dp[i][j][1] = dp[i][j][2] = -1;
    }
    int ans = solve(0, 0, 0);
    ans = max(ans, solve(0, 1, 1));
    ans = max(ans, solve(0, 2, 2));
    cout << ans << "\n";
    
    //cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

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

//https://qiita.com/tubo28/items/e6076e9040da57368845
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 mut x0 = 0;
    let mut y0 = 0;
    let mut w: i32 = read();
    let mut h: i32 = read();
    let n: usize = read();

    for _i in 0..n {
        let x = read();
        let y = read();
        let a = read();

        match a {
            1 => if x0 <= x { x0 = x; },
            2 => if x <= w { w = x; },
            3 => if y0 <= y { y0 = y; },
            4 => if y <= h { h = y; },
            _ => () ,
        }
    }

    if (w-x0) < 0 || (h-y0) < 0 {
        println!("0");
    }else{
        println!("{}", (w-x0) * (h-y0));
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
	int S;
	cin >> S;
	int up = S/100;
	int dn = S-up*100;
	//cout << up <<endl;
	//cout << dn <<endl;
	
	if(1<=up&&up<=12){
		if(1<=dn&&dn<=12){
			cout << "AMBIGUOUS" <<endl;
		}else{
			cout << "MMYY" <<endl;
		}
	}else if(1<=dn&&dn<=12){
		cout << "YYMM" <<endl;
	}else{
		cout << "NA" <<endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	int n,q;
	int i;
	scanf("%d",&n);
	int S[n];
	for(i=0;i<n;i++){			//S入力
		scanf("%d",&S[i]);
		}
	scanf("%d",&q);
	int T[q];
	for(i=0;i<q;i++){			//T入力
		scanf("%d",&T[i]);
	}
	int count=0;
	
	for(i=0;i<n;i++){			//同一要素削除
		for(int j=i+1;j<n;j++){
			if(S[i]==S[j])S[j]=-1;
		}
	}
		
	
	for(i=0;i<n;i++){
		for(int j=0;j<q;j++){
			if(S[i]==T[j])count++;
		}
	}
	printf("%d\n",count);
	return 0;
}
		


Measured memory_bytes: 2092
#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
using namespace std;
ll N;
ll f[1100][1100],g[1100];
ll a[1100],H[1100],lisan[1100],lcnt;
ll &ml=lcnt;
ll ans;
ll qpow(ll a,ll b) {
    ll ans=1;
    for(;b;b>>=1,a=(a*a)%mod) if(b&1) ans=(ans*a)%mod;
    return ans;
}

int main() {
    //cerr<<qpow(2,0)<<endl;
    scanf("%lld",&N);
    for(int i=1;i<=N;++i) scanf("%lld",a+i),lisan[i]=a[i];
    sort(lisan+1,lisan+N+1);
    lcnt=unique(lisan+1,lisan+N+1)-lisan-1;
    for(int i=1;i<=N;++i) H[i]=lower_bound(lisan+1,lisan+lcnt+1,a[i])-lisan;
    //for(int i=1;i<=N;++i) printf("H[%d]=%lld\n",i,H[i]);
    g[1]=2;
    for(int i=1;i<=H[1];++i) f[1][i]=qpow(2,a[1]-lisan[i])*(qpow(2,lisan[i])-2);//,tt(1,i);
    for(int i=H[1]+1;i<=ml;++i) f[1][i]=f[1][i-1];//,tt(1,i);
    for(int i=2;i<=N;++i) {
        for(int j=1;j<=H[i];++j) {
            f[i][j]+=f[i-1][j]%mod*qpow(2,max(0ll,a[i]-a[i-1]))%mod;
            f[i][j]%=mod;
            if(j>H[i-1]) {
                f[i][j]+=2*g[i-1]%mod*qpow(2,a[i]-lisan[j])%mod*(qpow(2,lisan[j]-a[i-1])-1)%mod;
                f[i][j]%=mod;
            }
            //tt(i,j);
        }
        for(int j=H[i]+1;j<=ml;++j) f[i][j]=f[i][j-1];
        if(H[i-1]<=H[i]) g[i]=g[i-1]*2%mod;
        else g[i]=(g[i-1]*2%mod+(f[i-1][H[i-1]]-f[i-1][H[i]]+mod)*2%mod)%mod;
        g[i]=(g[i]%mod+mod)%mod;
        //printf("g[%d]=%lld\n",i,g[i]);
    }
    ans=(g[N]+f[N][ml])%mod;
    //printf("ans=%lld\n",ans);
    printf("%lld\n",ans%mod);
    return 0;
}


Measured memory_bytes: 768
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */
/*
 *
 *
 *
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N, K;
	cin>>N>>K;
	vector<int> h(N);
	for(int i=0; i<N; i++) {
		cin>>h[i];	
	}
	vector<int> dp(N);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for(int i=2;i<N;i++) {
		int min = abs(h[i-1] - h[i]) + dp[i-1];
		for(int j=2;j<=K && i-j >= 0;j++) {
			int n = abs(h[i-j] - h[i]) + dp[i-j] ;
			if(n<min)
				min = n;
			
		}
		dp[i] = min;
	}
	cout<<dp[N-1];
	return 0;
}





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

int main() {
	int h, w;
	for (;;) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}


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


int main(){
	int a[10];
	int n;
	for (int i = 0; i < 10; i++){
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 10; j++){
			if (i < j){
				if (a[i] < a[j]){
					n = a[i];
					a[i] = a[j];
					a[j] = n;
				}
			}
		}
	}
	for (int i = 0; i < 3; i++){
		cout << a[i] << endl;
	}
	return 0;
}


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


int main()
{
	int a=0,b=0;
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='A')a++;
		else b++;
	}
	if(a>0 && b>0)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
struct P {
	ll j, o, i;
};
P operator+(P a, P b) {
	return P{ a.j + b.j,a.o + b.o,a.i + b.i };
}
P operator-(P a, P b) {
	return P{ a.j - b.j,a.o - b.o,a.i - b.i };
}
char a[1000][1000];
P b[1000][1000];
int main() {
	int h, w, n;
	cin >> h >> w >> n;
	for (int i = 0; i < h; i++) {
		string u;
		cin >> u;
		for (int j = 0; j < w; j++) {
			a[i][j] = u[j];
			if (j == 0) {
				if (u[0] == 'J')
					b[i][j] = P{ 1,0,0 };
				else if (u[0] == 'O') 
					b[i][j] = P{ 0,1,0 };
				else b[i][j] = P{ 0,0,1 };
			}
			else {
				b[i][j] = b[i][j - 1];
				if (u[j] == 'J')
					b[i][j].j++;
				else if (u[j] == 'O')
					b[i][j].o++;
				else b[i][j].i++;
			}
		}
	}
	for (int z = 0; z < n; z++) {
		int a, e, c, d;
		cin >> a >> e >> c >> d;
		a--; e--; c--; d--;
		P sum = { 0,0,0 };
		for (int i = a; i <= c; i++) {
			if (e == 0) sum = sum + (b[i][d]);
			else sum = sum + (b[i][d] - b[i][e-1]);
		}
		cout << sum.j << " " << sum.o << " " << sum.i << endl;
	}
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    vector<string> S(3);
    cin >> S[0] >> S[1] >> S[2];

    int now = 0;
    int ans;
    Vi idx(3);
    while (true) {
        int t = S[now][idx[now]] - 'a';
        ++idx[now];
        if (idx[now] > (int)S[now].size()) {
            ans = now;
            break;
        }
        now = t;
    }

    cout << (char)('A' + ans) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String A = stdIn.next();
		if(A == A.toLowerCase()){
			System.out.println("a");
		}
		else{
			System.out.println("A");
		}
		stdIn.close();
	}
}

Measured memory_bytes: 35560
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main(void) {
	int w,h;
	while(cin >> w >> h && w && h) {
		vector< vector<int> > data(h+2,vector<int>(w+2,0));
		for (int i = 1; i <= h; ++i) {
			for (int j = 1; j <= w; ++j) {
				cin >> data[i][j];
			}
		}

		int nx,ny;
		int count = 0;
		for (int i = 1; i <= h; ++i) {
			for (int j = 1; j <= w; ++j) {
				if (data[i][j] == 1) {
					nx = j;
					ny = i;
					data[i][j] = 0;
					queue<int> fx,fy;
					fx.push(nx);
					fy.push(ny);
					++count;

					while (!fx.empty()) {
						nx = fx.front();
						ny = fy.front();
						fx.pop();
						fy.pop();
						for (int d = 0; d < 8; ++d) {
							if (data[ny+dy[d]][nx+dx[d]] == 1) {
								fx.push(nx+dx[d]);
								fy.push(ny+dy[d]);
								data[ny+dy[d]][nx+dx[d]] = 0;
							}
						}
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
(N,),r,*L=$<.map{_1.split.map &:to_i}
n=*0..N
l=n.map{[1e9]*$.}
L.map{l[_1][_2]=l[_2][_1]=_3}
n.product(n,n){|k,i,j|l[i][j]=[l[i][j],l[i][k]+l[k][j]].min}
p r.permutation.map{|b,*a|a.sum{l[b][b=_1]}}.min

Measured memory_bytes: 49508
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main()
{
   int a, b, c;
   cin >> a >> b >> c;

   int ans;
   ans = min(a + b, b + c);
   ans = min(ans, c + a);
   cout << ans << endl;
}


Measured memory_bytes: 256
# 改善1：sys入力
# 改善2：ifで分岐させるより、あとから個別対応した方が分岐を毎回やらないですむ？


import sys
input=sys.stdin.readline

def main():
    k,n = map(int, input().split())
    s = list(map(int, input().split()))
    l = []
    for i in range(1,n):
        a = s[i] - s[i-1]
        l.append(a)
    l.append(k - (s[-1] - s[0]))
    print(k - max(l))

if __name__ == '__main__':
    main()


Measured memory_bytes: 101016
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

bool check(const vector<int>& a, int m, int v, int p, int idx) {
    if (a.size() - idx <= p)
        return true;

    int val = a[idx] + m;
    if (val < a[a.size() - p])
        return false;

    int need = max(0, v - p);
    vector<int> f;
    for (int i = 0; i <= a.size() - p; ++i)
        if (i != idx)
            f.push_back(val - a[i]);
    reverse(f.begin(), f.end());

    long long sum = 0;
    for (int i = 0; i < f.size(); ++i) {
        int t = i - (f.size() - need);
        if (t > 0) {
            f[i] = min<long long>(f[i], sum / t);
        }
        sum += f[i];
    }

    return sum >= need *1LL* m;
}

int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n,m,v,p;
    cin >> n >> m >> v >> p;

    vector<int> a(n);
    for (int& x : a)
        cin >> x;

    sort(begin(a), end(a));

    int l = -1;
    int r = n;

    while (r-l > 1) {
        int mid = (l+r) >> 1;
        if (check(a, m, v, p, mid))
            r = mid;
        else
            l = mid;
    }
    cout << n - r << endl;
}


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

int main(){
    long long  i,n,m,sum=0;
    cin >> n >> m;
    vector<long long> a(m);
    for(i=0;i<m;i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    if(n<sum) cout << -1 << endl;
    else cout << n-sum << endl;
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int N;
    cin >> N;
    int H[N];
    int ans=0, cnt=0;
    for(int i=0;i<N;i++) cin >> H[i];
    for(int i=0;i<N-1;i++){
        if(H[i]>=H[i+1]){
            cnt++;
            ans = max(cnt, ans);
        }
        else{
            cnt=0;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int X, Y;
    cin >> X >> Y;
    for (int crane = 0; crane <= X; ++crane) {
        int turtle = X - crane;
        if (2 * crane + 4 * turtle == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3636
h, w = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
s = Array.new(h + 4) { Array.new(w + 4, -1) }
h.times do |j|
  gets.chomp.chars.each_with_index do |t, i|
    if t == '.'
      s[j + 2][i + 2] = 0
    end
  end
end
que = []
que << [c[0] + 1, c[1] + 1]
s[c[0] + 1][c[1] + 1] = 1
while que.size > 0
  h = {}
  while que.size > 0
    y, x = que.shift
    cnt = s[y][x]
    if s[y + 1][x] == 0
      s[y + 1][x] = cnt
      que << [y + 1, x]
    elsif s[y + 1][x] == -1
      h[[y, x]] = 1
    end
    if s[y - 1][x] == 0
      s[y - 1][x] = cnt
      que << [y - 1, x]
    elsif s[y - 1][x] == -1
      h[[y, x]] = 1
    end
    if s[y][x + 1] == 0
      s[y][x + 1] = cnt
      que << [y, x + 1]
    elsif s[y][x + 1] == -1
      h[[y, x]] = 1
    end
    if s[y][x - 1] == 0
      s[y][x - 1] = cnt
      que << [y, x - 1]
    elsif s[y][x - 1] == -1
      h[[y, x]] = 1
    end
  end
  h.keys.each do |y, x|
    cnt = s[y][x]
    (y - 2).upto(y + 2) do |j|
      (x - 2).upto(x + 2) do |i|
        if s[j][i] == 0
          s[j][i] = cnt + 1
          que << [j, i]
        end
      end
    end
  end
end
puts s[d[0] + 1][d[1] + 1] - 1

Measured memory_bytes: 26376
module M = Map.Make (struct
  type t = char list * char list
  let compare = compare
end)

let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let m =
    Array.fold_left (fun m rb ->
      M.add rb (1 + try M.find rb m with Not_found -> 0) m) M.empty @@
    Array.init (1 lsl n) @@ fun i ->
      Array.fold_left (fun (r, b) j ->
        if i land (1 lsl j) = 0
        then (s.[j + n] :: r, b)
        else (r, s.[j + n] :: b)) ([], []) @@
      Array.init n @@ fun j -> j in
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init (1 lsl n) @@ fun i ->
    let (r, b) =
      Array.fold_left (fun (r, b) j ->
        if i land (1 lsl j) = 0
        then (s.[j] :: r, b)
        else (r, s.[j] :: b)) ([], []) @@
      Array.init n @@ fun j -> j in
    try M.find (List.rev b, List.rev r) m with Not_found -> 0


Measured memory_bytes: 143224
#!/bin/bash

read S

S=$(echo $S | awk -v FS='' '{for (i = 1; i <= NF; i++) print $i;}')
i=0
for c in $S; do
  i=$(expr $i + 1)
  # even
  if [ $(expr $i % 2) -eq 0 ]; then
    if [ $c != 'L' -a $c != 'U' -a $c != 'D' ]; then
      echo 'No'
      exit
    fi
  # odd
  else
    if [ $c != 'R' -a $c != 'U' -a $c != 'D' ]; then
      echo 'No'
      exit
    fi
  fi
done
echo 'Yes'

Measured memory_bytes: 760
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    size_t N;
    char S[101], T[101];
    intmax_t ans = 0;

    scanf("%jd", &N);
    scanf("%s %s", S, T);

    for (size_t i = 0; i < N; i++) {
        putchar(S[i]);
        putchar(T[i]);
    }
    putchar('\n');

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long llong;
// static const int max_n = 110;
// static const int max_s = 20010;
static const llong mod = 1000000007;
// static const int max_v = 10000000;
// vector<int> num_array(max_n);
// vector<vector<int>> dp(max_n, vector<int>(max_s, 0));

vector<llong> factor(300001, 1);
vector<llong> inverse_factor(300001, 1);

template<typename T>
vector<pair<T, T>> prime_fatorize(T N){
    vector<pair<T, T>> primes;
    T power_it = 0;
    T base = 2;

    while(N > 1){
        if(N % base == 0){
            power_it += 1;
            N /= base;
        }else{
            if (power_it > 0){
                primes.push_back(make_pair(base, power_it));
                power_it = 0;
            }

            base ++;
        }
    }

    if (power_it > 0){
        primes.push_back(make_pair(base, power_it));
        power_it = 0;
    }

    return primes;

}

template<typename T>
T mod_pow(T base, T power_it){
    // calc base ^ power_it % mod 
    T ans = 1;
    while(power_it != 0){
        if(power_it&1) ans = ans * base % mod;
        base = base * base % mod;
        power_it = power_it >> 1;
    }
    // if(base <= 10){
    //     printf("mod pow %lld ^ %lld = %lld", base ,power_it, ans);
    // }

    return ans;

}

template<typename T>
T mod_comb(T n, T r){
    if(n < r || n < 0) return 0;
    llong devider = inverse_factor[n-r] * inverse_factor[r] % mod;
    return factor[n] * devider % mod;
}

int main(){
    llong N, M;
    scanf("%lld %lld", &N, &M);
    for(llong i=1; i<(llong)factor.size();i++){
        factor[i] = factor[i-1] * i % mod;
        inverse_factor[i] = inverse_factor[i-1] * mod_pow(i, mod-2) % mod;
        // if(i<= 10){
            // printf("factor [%lld] = %lld\n", i, factor[i]);
            // printf("inverse factor [%lld] = %lld\n", i, inverse_factor[i]);
        // }

    }
    auto primes = prime_fatorize(M);

    llong ans = 1;
    for(auto &prime: primes){
        // printf("prime: %lld ^ %lld\n", prime.first, prime.second);
        ans = (ans * mod_comb(prime.second + (N - 1), prime.second)) % mod;
    }

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

}

Measured memory_bytes: 4992
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
const int MAXN = 100010;
using namespace std;

map<int, int> M;
int N, T[MAXN], Ans = 0;

int main() {
	int i;
	scanf("%d", &N);
	for(i = 1; i <= N; i++) {
		scanf("%d", &T[i]);
		M[T[i]] = i;
	}

	sort(T + 1, T + N + 1);
	for(i = 1; i <= N; i++)
		Ans += (M[T[i]] - i) & 1;

	printf("%d", Ans / 2);
	return 0;
}


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

int main()
{
    string s, p;
    bool res = false;

    getline(cin, s);
    getline(cin, p);

    for (int i = 0; i < s.size(); i++)
        if (s[i] == p[0]) {
            res = true;
            for (int j = 0; j < p.size(); j++)
                if (s[(i + j) % s.size()] != p[j]) {
                   res = false;
                   break; 
                }
            if (res)
                break;
        }

    cout << (res ? "Yes" : "No") << endl;

    return 0;
}


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

int main() {
    ll i, j, k, l, test, n;
    map<ll,ll> m;

    cin>>n>>k;
    while(k--) {
        cin>>j;
        while(j--) {
            cin>>l;
            m[l]++;
        }
    }
    ll c=0;
    for(i=1;i<=n;i++) if(m[i]==0) c++;
    cout<<c;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
struct edge {
  ll to, cost;
};

int main() {
  string s; cin >> s;
  ll K; cin >> K; ll tmp = 0; bool flag = false;
  REP(i, s.size()) {
    if(s[i] != 'a' && tmp + ('z' - s[i] + 1) <= K) {
      tmp += ('z' - s[i] + 1);
      s[i] = 'a';
    }
  }
  if(s[s.size() - 1] + ((K - tmp) % 26) <= 'z') s[s.size() - 1] += ((K - tmp) % 26);
  else {
    ll a = 'z' - s[s.size() - 1];
    ll b = ((K - tmp) % 26) - a - 1;
    s[s.size() - 1] = ('a' + b);
  }
  cout << s << endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std; 
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin>>a>>b;
	if(a<=b)cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
    return 0; 
}/*
*/

Measured memory_bytes: 3636