akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_139
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            if (n == 1)
            {
                WriteLine(0);
            }
            else
            {
                WriteLine(n * (n - 1) / 2);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    // freopen("inputf.txt","r",stdin);
    // freopen("outputf.txt","w",stdout);
    
    int n=0;
    int k;
    bool got=true;

    cin>>k;
    for(int i=1;i<=1e7;i++){
        n=n*10+7;
        if(n>=k){
            if(n%k==0){
                got=false;
                cout<<i;
                break;
            }
            n=n%k;
        }
    }
    if(got)
        cout<<"-1\n";
    
}

Measured memory_bytes: 3568
import java.util.Scanner;
class Main{
 public static void main(String args[]){
  Scanner scan = new Scanner(System.in);
  
  int n = scan.nextInt();
  int sup[] = new int[n+1];
  int ans[] = new int[n+1];
   ans[1] = 0;
  for(int i = 2; i<=n; i++){ //初期化
    sup[i] = scan.nextInt();
    ans[i] = 0;
  }
  for(int i = 2; i<= n; i++){
    ans[sup[i]]++;
  }
  for(int i = 1; i<= n; i++){
    System.out.println(ans[i]);
  }
 }
}


Measured memory_bytes: 63352
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	char c; cin >> c;
	if(c == 'A') cout << 'T' << "\n";
	if(c == 'T') cout << 'A' << "\n";

	if(c == 'G') cout << 'C' << "\n";
	if(c == 'C') cout << 'G' << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
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;
}

int main() {

    string s;
    cin >> s;

    int a = 0;
    rep(i, s.length()){
        if(i%2 == 0 && s[i] != '0'){
            a++;
        }
        if(i%2 == 1 && s[i] != '1'){
            a++;
        }
    }

    int b = 0;
    rep(i, s.length()){
        if(i%2 == 0 && s[i] != '1'){
            b++;
        }
        if(i%2 == 1 && s[i] != '0'){
            b++;
        }
    }

    cout << min(a, b) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	int main() {
		// #ifndef ONLINE_JUDGE
		// 	// for getting input from input.txt
		// 	freopen("input.txt", "r", stdin);
		// 	// for writing output to output.txt
		// 	freopen("output.txt", "w", stdout);
		// #endif
		int n,c=0;
  	cin>>n;
	vector<int> v(n,0);
  	vector<int> b(n,0);
  	for(int i=0;i<n;i++){
  	cin>>v[i];
  	}
  	b = v;
  	sort(b.begin(),b.end());
    for(int i=0;i<n;i++){
    	if(v[i] != b[i]){
        c++;
        }
    }
  	if(c>2){
    	cout<<"NO"<<"\n";
    }
  else{
    cout<<"YES"<<"\n";
}
	return 0;
		}	

Measured memory_bytes: 256
import numpy as np
S = str(input()) #strでまず受けた方が楽
forward = S[:2]
back	= S[2:]

def str2int(str_):
  if str_[0] == "0":
    return int(str_[1])
  else:
    return int(str_)

# flagを作って、それで答えますかね
count = np.zeros((2)) # 0 : YYMM 1:MMYY
# 一発退場の00系 2000年代はいけるわ...
if (forward=="00") and (back=="00") :
  print("NA")
  
elif (forward=="00") and (back!="00"):
  if str2int(back) <= 12:
    print("YYMM")
  else:
    print("NA")
elif (forward!="00") and (back=="00"):
  if str2int(forward) <= 12:
    print("MMYY")
  else:
    print("NA")
else:
  ## 西暦はなんでもオッケーなので、あとはMMに両方なれるかどうか
  ## 1以上も確定なので、12以下かだけでよい
  if str2int(forward) <= 12:
    count[0] += 1
  if str2int(back) <= 12:
    count[1] += 1 
  ## あとは条件分岐
  if np.sum(count) == 2:
    print("AMBIGUOUS")
  elif np.sum(count) == 1 and count[0] == 1:
    print("MMYY")
  elif np.sum(count) == 1 and count[1] == 1:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 12496
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j;
string s,t;
int main()
{
	cin>>n>>m>>s;
	if (s[n]!='-')
	{
		cout<<"No";
		return 0;
	}
	s.erase(n,1);
	for (i=0;i<s.size();i++)
	if (!isdigit(s[i]))
	{
		cout<<"No";
		return 0;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	double x1,y1,x2,y2;
	double ans;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	ans = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
	printf("%lf\n",ans);
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  	cin>>n;
  	char c[n];
  	for(int i=0; i<n; ++i)
      	cin>>c[i];
  	int i=0, j=n-1, ans=0;
  	while(i<j)
    {
    	while(c[i]!='W' && i<n)
          	++i;
      	while(c[j]!='R' && j>=0)
          	--j;
      	if(i<j)
        {
        	++ans;
          	int temp= c[j];
          	c[j]=c[i];
          	c[i]=temp;
          	++i;
          	--j;
        }
      	
    }
  	cout<<ans;
  	return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define s second
#define f first
int main()
{
   int n,k;
   cin>>n>>k;
   if(n%k==0) cout<<"0";
   else cout<<"1"; return 0;
}

Measured memory_bytes: 256
/// b.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int s[1 << 20];
    static ll dp1[1 << 20];
    static ll dp2[1 << 20];
    int n;
    IOS;
    fi>>n;
    for (int i = 1;i <= 3 * n;++i)
        fi>>s[i];
    ll ss = 0;
    priority_queue < ll > Q;
    for (int i = 1;i <= n;++i)
        Q.push(-s[i]),ss += s[i];
    for (int i = n;i <= 3 * n;++i)
    {
        dp1[i] = ss;
        if (i == 3 * n)
            break;
        if (-Q.top() < s[i + 1])
            ss += Q.top(),ss += s[i + 1],Q.pop(),Q.push(-s[i + 1]);
    }
    while (!Q.empty())
        Q.pop();
    ss = 0;
    for (int i = 3 * n;i > n + n;--i)
        Q.push(s[i]),ss += s[i];
    for (int i = n + n + 1;i;--i)
    {
        dp2[i] = ss;
        if (i == 1)
            break;
        if (Q.top() > s[i - 1])
            ss -= Q.top(),ss += s[i - 1],Q.pop(),Q.push(s[i - 1]);
    }
    ll ans = -1e18;
    for (int i = n;i <= n + n;++i)
        smax(ans,dp1[i] - dp2[i + 1]);
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 8820
from fractions import gcd

A, B, C, D = map(int, input().split())

def lcm(a, b):
    return a*b //gcd(a, b)

ABmulC = B//C - (A-1)//C
ABmulD = B//D - (A-1)//D
LCM = lcm(C,D)
ABmulLCM = B//LCM - (A-1)//LCM

ans = B - A + 1
ans -= ABmulC + ABmulD
ans += ABmulLCM
print(ans)

Measured memory_bytes: 64748
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int value[100010];
int main() {
    long long sum = 0;
    int n;
    int v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v;
        value[v]++;
        sum += v;
    }
    int q;
    cin >> q;
    int b, c, diff, cnt;
    for (int i = 0; i < q; i++) {
        cin >> b >> c;
        diff = c - b;
        cnt = value[b];
        value[b] = 0;
        value[c] += cnt;
        sum += cnt * diff;
        cout << sum << endl;
    }
}

Measured memory_bytes: 3976
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
n=len(s)
i=0
k=0
l=[[]]
while i<n:
    if s[i]=="A":
        l[k].append(0)
    elif i<n-1:
        if s[i:i+2]=="BC":
            l[k].append(1)
            i+=1
        else:
            l.append([])
            k+=1
    i+=1
ans=0
for lis in l:
    m=len(lis)
    if m>0:
        n1=[0]*m
        c=0
        for i in range(m):
            if lis[-1-i]==1:
                c+=1
            n1[-1-i]=c
        for i in range(m):
            if lis[i]==0:
                ans+=n1[i]
print(ans)

Measured memory_bytes: 85212
import numpy as np

n = int(input())

s = np.zeros(n)
s = input()

x = 0
x1 = 0

for i in range(n):
    if s[i] == 'I':
        x1 += 1
        if x1 > x:
            x = x1
    else:
        x1 -= 1

print(x)

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

#define JUDGE 1000000007
#define BLANK 1

int N, M;

typedef struct 
{
    int type;
    int road;
} Stair;

void visit(Stair*);

int main()
{
    int i;
    char buf[256];
    fgets(buf, 256, stdin);
    sscanf(buf, "%d %d", &N, &M);

    Stair* p = (Stair*)malloc(sizeof(Stair) * N);

    for (i = 0; i < N; i++)
    {
        p[i].type = 0;
        p[i].road = 0;
    }

    int a = 0;
    for (i = 0; i < M; i++)
    {
        scanf("%d", &a);
        p[a-1].type = BLANK;
    }
    
    if (p[0].type != BLANK || p[1].type != BLANK)
    {
        p[0].road = 1 % JUDGE;
        p[1].road = 1 % JUDGE;
        visit(p);
    }
    printf("%d\n", p[N-1].road % JUDGE);

    return 0;
}

void visit(Stair* p)
{
    int i;
    for (i = 0; i < N-2; i++)
    {
        if (p[i].type == BLANK) continue;
        if (p[i+1].type != BLANK)
        {
            p[i+1].road += p[i].road % JUDGE;
        }
        
        if (p[i+2].type != BLANK)
        {
            p[i+2].road += p[i].road % JUDGE;
        }
    }

    if (p[N-1].type != BLANK && p[N-2].type != BLANK)
    {
        p[N-1].road += p[N-2].road % JUDGE;
    }

    return;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  int h,w,n;cin>>h>>w>>n;
  vector<vector<int>> ans(h,vector<int>(w));
  
  int in=0,dex=0;

  rep(i,n){
    int a;cin>>a;
    while(a--){
      ans[in][dex]=i+1;
      dex++;
      if(dex==w){
        dex=0;
        if(in%2==1)reverse(all(ans[in]));
        in++;
      }
    }
  }

  rep(i,h)rep(j,w){
    cout<<ans[i][j]<<" ";
    if(j==w-1)cout<<endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s.at(0)=='R'){
    if(s.at(1)=='R'){
      if(s.at(2)=='R'){
        cout<<"3"<<endl;
      }
      else if(s.at(2)=='S'){
        cout<<"2"<<endl;
      }
    }
    else if(s.at(1)=='S'){
      if(s.at(2)=='R'){
        cout<<"1"<<endl;
      }
      else if(s.at(2)=='S'){
        cout<<"1"<<endl;
      }
    }
  }
  else if(s.at(0)=='S'){
    if(s.at(1)=='R'){
       if(s.at(2)=='R'){
        cout<<"2"<<endl;
      }
       else if(s.at(2)=='S'){
        cout<<"1"<<endl;
      }
    }
    if(s.at(1)=='S'){  
      if(s.at(2)=='R'){
        cout<<"1"<<endl;
      }
      else if(s.at(2)=='S'){
        cout<<"0"<<endl;
      }
    }
  }
}

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

int main(){
  int A[3],m=0,n=0;
  cin >> A[0] >> A[1] >> A[2];
  for(int i = 0; i < 3; i++){
    if(A[i] == 5)
      m++;
    if(A[i] == 7)
      n++;
  }
  if(m == 2 && n == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


x, n = invr()
if n == 0:
    print(x)
else:
    mark = [0]*101
    a = inlist()

    lx = rx = res = x
    while True:
        if lx not in a:
            res = lx
            break
        if rx not in a:
            res = rx
            break
        lx -= 1
        rx += 1
    print(res)


Measured memory_bytes: 10560
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
string s,head,tail,ts,res;
int q;
int flag;
int t,f;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> s;
	cin >> q;
	while(q--){
		cin >> t;
		if(t == 1){
			flag ^= 1;
		}else{
			cin >> f >> ts;
			if(flag == 0){
				if(f == 1){
					head = ts + head;
				}else{
					tail = tail + ts;
				}
			}else{
				if(f == 1){
					tail = tail + ts;
				}else{
					head = ts + head;
				}
			}
		}
	}
	res = head + s;
	res = res + tail;
	if(flag == 0){
		cout << res << endl;
	}else{
		reverse(res.begin(),res.end());
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1424
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001];
long long int f(long long int arr[],int i,int j,int n)
{
    if(i>j)return 0;
    if(dp[i][j]!=-9999999999)
    return dp[i][j];
   if(!((n-j+i-1)&1)){
		return  dp[i][j]=max(f(arr,i+1,j,n)+arr[i],f(arr,i,j-1,n)+arr[j]);
	}else{
		return dp[i][j]=min(f(arr,i+1,j,n)-arr[i],f(arr,i,j-1,n)-arr[j]);
	}
}

int main() {
	int n,j;
	cin>>n;
	long long int arr[n]={0};
	int i; 
	for(i=0;i<n;i++)
	cin>>arr[i];
	for(i=0;i<n;i++)
	for(j=0;j<n;j++)
	{
	    dp[i][j]=-9999999999;
	}
	long long int x=f(arr,0,n-1,n);
	cout<<x;
	return 0;
	
}


Measured memory_bytes: 70784
#include <iostream>
using namespace std;
#include<stdlib.h>
#include<stdio.h>
int main(){
    int n,m;
    cin>>n>>m;
    int cnt=0;
    do{
        n=n/m;
        cnt++;
    }while(n!=0);
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007
#define int long long

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

int gcd(int a, int b)
{
    return b != 0 ? gcd(b, a % b) : a;
}
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
int extgcd(int a, int b, int &x, int &y)
{
    int g = a;
    x = 1;
    y = 0;
    if (b != 0)
        g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

signed main()
{
    int n, x;
    cin >> n >> x;
    priority_queue<int, vector<int>, greater<int>> q;
    REP(i, n)
    {
        int tmp;
        cin >> tmp;
        if (abs(tmp - x) != 0)
        {
            q.push(abs(tmp - x));
        }
    }
    if (q.empty())
    {
        cout << 0 << endl;
        return 0;
    }
    int ans = q.top();
    q.top();
    while (!q.empty())
    {
        if (q.top() % ans != 0)
        {
            ans = gcd(ans, q.top());
        }
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
def c_align(N, A):
    from collections import deque
    if N == 2:
        return abs(A[0] - A[1])
    tmp = sorted(A)

    seq = tmp[:]
    old_check = seq.pop(-1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans1 = 0
    turn = 0
    while seq:
        current_check = seq.pop() if turn % 2 == 0 else seq.popleft()
        ans1 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    seq = tmp[:]
    old_check = seq.pop(1 + N // 2) if N % 2 == 0 else seq.pop(N // 2)
    current_check = -1
    seq = deque(seq)
    ans2 = 0
    turn = 0
    while seq:
        current_check = seq.popleft() if turn % 2 == 0 else seq.pop()
        ans2 += abs(current_check - old_check)
        old_check = current_check
        turn += 1

    ans = max(ans1, ans2)
    return ans

N = int(input())
A = [int(input()) for _ in range(N)]
print(c_align(N, A))

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

int main() {
	ios_base::sync_with_stdio( false );

	const int n = 11; // station num
	vector<int> st( n );
	int v1, v2;

	string line;
	while( getline( cin, line ) ) {
		for( auto& c: line ) {
			if( c == ',' ) { c = ' '; }
		}

		istringstream iss( line );

		for( int i = 1; i < n; ++i ) {
			iss >> st[i];
			st[i] += st[i-1];
		}
		iss >> v1 >> v2;

		double a = st.back() * ((double)v1 / (v1+v2));
		for( int i = 1; i < n; ++i ) {
			if( st[i] >= a ) {
				cout << i << '\n';
				break;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int dp[n+1];
    dp[n]=0;
    for(int i=n-1;i>=0;--i){
        if(s[i]=='o')dp[i]=max(dp[i+1],dp[min(n,i+c+1)]+1);
        else dp[i]=dp[i+1];
    }
    int now=0;
    int dame=-1;
    for(int i=0;i<n;++i){
        if(s[i]!='o')continue;
        if(now+dp[max(i+1,dame+1)]<k){
            cout<<i+1<<endl;
        }
        if(dame<i){
            ++now;
            dame=min(i+c,n-1);
        }
    }
}


Measured memory_bytes: 2564
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 8 2019
 * 
 */

#include <bits/stdc++.h>

#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    int n;

    cin>>n;

    vi v(n);

    iv(v);

    sort(all(v));

    cout<<v[n/2] - v[n/2 - 1]<<endl;



    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 640
S = gets.chomp
K = gets.to_i
N = S.size

list = S.chars

i = 0
k = K

class String
  def next_alpha(n)
    b = self.ord - 97
    (97 + (n + b) % 26).chr
  end
end

while k > 0 && i < N
  s = list[i]

  if i < N - 1 && s == 'a'
    i += 1
    next
  end

  d = 26 - (s.ord - 97)

  if i == N - 1
    k %= 26
    list[i] = s.next_alpha(k)
  elsif d <= k
    k -= d
    list[i] = 'a'
  end

  i += 1
end

puts list.join


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

int main() {
        int n;
        scanf("%d", &n);
        int cur = 0;
        rep(i, n) {
                int a;
                scanf("%d", &a);
                if (a == cur + 1) {
                        cur ++;
                }
        }
        if (cur == 0) printf("-1\n");
        else printf("%d\n", n - cur);
        return 0;
}


Measured memory_bytes: 256
#include <string.h>
#include<stdio.h>
int palin(char *s)
{
    int i,n,c=0,ans=0;
    n=strlen(s);
 
    for(i=0;i<n/2;i++)  
    {
    	if(s[i]!=s[n-i-1])
    	{
    	    ans++;
    	}
 	}
    return ans;
}
int main()
{
    char s[101];
    int i,l;
    scanf("%s",s);
    printf("%d",palin(s));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	long long x1, y1, x2, y2, x3, y3, s, mod;
	cin >> s;
	x1 = y1 = 0;
	x2 = 1e9, y2 = 1;
	mod = 1e9;
	y3 = s / mod + 1;
	x3 = x2 * y3 - s;
	if (s == 1e18) {
		y2--, y3--;
	}
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int n, x, y; 
    cin >> n >> x >> y;
    x--; y--;
    vector<int> res(n);
    rp(i, 0, n) {
        rp(j, i+1, n) {
            int dis = min(j-i, abs(i-x) + abs(j-y) + 1);
            res.at(dis) ++;
        }
    }
    rp(i, 1, n) {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;

const int N = 1e6;
int dp[N];


int main() {

        for(int i = 100; i < 106; i++)
                dp[i] = 1;

        for(int i = 106; i < N; i++) {
                bool flag = false;
                for(int j = 100; j < 106; j++) {
                        flag |= dp[i - j];
                }
                dp[i] = flag;
        }

        int n; scanf("%d",&n);
        printf("%d\n",dp[n]);

        return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  vector<ll> list;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list.emplace_back(v);
  }

  ll h = list[0];

  for (ll i = 1; i < N; i++) {
    h = h ^ list[i];
  }
  // cout << h << endl;

  for (ll i = 0; i < N; i++) {
    cout << (h ^ list[i]) << endl;
  }
}


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

using namespace std;

int bit[200001];
int N, K;

int sum(int i){
    int s = 0;
    while(i > 0){
        s += bit[i];
        i-= i&-i;
    }
    return s;
}

void add(int i, int x){
    while(i <= N){
        bit[i] += x;
        i += i & -i;
    }
}

typedef pair<long, int> P;
int main(){
    cin >> N >> K;
    long b[200000];
    P S[200000];
    int idx[200000];
    long ans = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        b[i] = a - K;
        if(i == 0) {
            S[0].first = b[0];
            S[0].second = 0;
        }else{
            S[i].first = S[i-1].first+b[i];
            S[i].second = i;
        }
        if(S[i].first >= 0) ans += 1;
    }
    sort(S, S+N);
    for(int i = 0; i < N; i++){
        idx[S[i].second] = i;
    }
    //cout << ans << endl;
    for(int i = 0; i < N; i++){
        ans += sum(S[i].second+1);
        add(S[i].second+1, 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
  int an = 0 ;
  int ans = 0 ;
  int N , co = 0 ;
  cin >> N ;
  vector<int> A(N);
  rep(i,N) cin >> A.at(i);
  rep(i,N) {
  if (i == N - 1 ) break ;
  if( A.at(i) >= A.at(i+1) ) co++ ;
  else {
    if ( an < co ) an = co ;
    co = 0;
  }
  if ( an < co ) an = co ;
  }
  //cout << co << endl;
  cout << an << endl;
}

Measured memory_bytes: 640
def hanntei(x):
  a=[1,3,5,7,8,10,12]
  b=[4,6,9,11]
  c=[2]
  if x in a:
    return "a"
  elif x in b:
    return "b"
  else:
    return "c"
x,y=map(int,input().split())
x=hanntei(x)
y=hanntei(y)
print("Yes" if x==y else "No")

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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int N;
    vector<int> A;

    cin >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];

    // Process
    sort(A.begin(), A.end());
    const int max_a = A.back();

    vector<bool> dp(max_a + 1, true);
    dp[0] = false;
    for (int i = 0; A[i] <= max_a / 2; i++) {
        if (!dp[A[i]]) continue;

        if (A[i] == A[i + 1]) dp[A[i]] = false;

        for (int j = A[i] * 2; j <= max_a; j += A[i]) dp[j] = false;
    }

    for (int i = 1; i < N; i++)
        if (A[i - 1] == A[i]) dp[A[i]] = false;

    int ans = 0;
    rep(i, N) if (dp[A[i]]) ans++;

    // Output
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int N; vector<int> I, U, A, P, C;
    
    while(true)
    {
        cin >> N;
        
        if(N == 0) { break; }
        
        I = vector<int>(N);
        U = vector<int>(N);
        A = vector<int>(N);
        P = vector<int>(N);
        
        for(int i = 0; i < N; i++)
        {
            cin >> I[i] >> U[i] >> A[i] >> P[i];
        }
        
        C = vector<int>(1001, 0);
        
        for(int i = 0; i < N; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                if(A[i] < A[j] || (A[i] == A[j] && P[i] > P[j]))
                {
                    swap(A[i], A[j]);
                    swap(P[i], P[j]);
                    swap(I[i], I[j]);
                    swap(U[i], U[j]);
                }
            }
        }
        
        int count_ = 0;
        
        for(int i = 0; i < N; i++)
        {
            if((count_ < 10 && C[U[i]] < 3) || (count_ < 20 && C[U[i]] < 2) || (count_ < 26 && C[U[i]] == 0))
            {
                cout << I[i] << endl;
                
                C[U[i]]++; count_++;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 3092
a = int(input())
list_p = list(map(int, input().split()))
count = 0
for i in range(a-2):
    if((list_p[i] < list_p[i+1] and list_p[i+1] < list_p[i+2]) or\
        (list_p[i] > list_p[i+1] and list_p[i+1] > list_p[i+2])):
        count += 1

print(count)

Measured memory_bytes: 3060
def main():
    h, w = (int(x) for x in input().split())
    n = int(input())
    ax = [int(x) for x in input().split()]

    cur_color = 0
    output = [[0] * w for _ in range(h)]

    for i in range(h):
        if i % 2 == 0:
            items = range(0, w)
        else:
            items = range(w-1, -1, -1)

        for j in items:
            output[i][j] = cur_color + 1

            ax[cur_color] -= 1
            if ax[cur_color] == 0:
                cur_color += 1
    
    for i in range(h):
        for j in range(w):
            print(output[i][j], end=" ")
        print()


if __name__ == "__main__":
    main()






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

int main() {
  int n;
  cin >> n;
  string a,b;
  cin >> a >> b;
  
  int cnt = 0;
  while(cnt < n){
    cout << a[cnt] << b[cnt];
    cnt++;
  }
  cout << endl;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    ll n,k;
    cin >> n >> k;
    if(n%k==0||n==0)cout << 0 << endl;
    else{
        ll t = n%k;
        ll ans = min(t,k-t);
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
ans = -1
for i in range(10 ** (n - 1), 10 ** n):
    strI = str(i)
    ans = strI
    for s, c in sc:
        if strI[s - 1] != str(c):
            ans = -1
            break
    if ans != -1:
        break
if n == 1:
    for i in range(0, 10 ** n):
        strI = str(i)
        ans = strI
        for s, c in sc:
            if strI[s - 1] != str(c):
                ans = -1
                break
        if ans != -1:
            break
print(ans)

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

using namespace std;

int main() {
    long long n, c, k;
    long long *t;
    cin >> n >> c >> k;
    t = new long long[n];
    for (int i = 0; i < n; i++)
        cin >> t[i];
    sort(t, t+n);
    int ans = 0;
    for (int i = 0; i < n;) {
        int j = i+1;
        while(j < n && t[j] - t[i] <= k && j-i+1 <= c)
            j++;
        ans++; 
        i = j;       
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using std::sort;
int n,k,a[10001],ans;
int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++)scanf("%d",a+i);
  sort(a+1,a+n+1);
  for(int i=1;i<=k;i++)ans+=a[i];
  printf("%d\n",ans);
}

Measured memory_bytes: 1708
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using ll = long long;

using namespace std;

ll mod=1e9+7;


int main() {
	int n;
	cin>>n;
	vector<pair<int,int>>robot(n);
	for(int i=0;i<n;i++){
		int x,l;
		cin>>x>>l;
		robot[i].first=x+l;
		robot[i].second=x-l;
	}
	sort(robot.begin(),robot.end());
	int ans=0;
	int tmp=-1e9-1;
	for(int i=0;i<n;i++){
		if(tmp>robot[i].second)continue;
		ans++;
		tmp=robot[i].first;
	}
	cout<<ans<<endl;
	return 0;
}

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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = int;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

u64 n, E;
u64 d[10000][10000], w[10000][10000];
bool negative_cycle = false;

void floydWarshall(){
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
            d[i][j] = w[i][j];
        }
    }
    for (int k = 1; k <= n; k++){
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= n; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                if(k == n && i == j && d[i][j] < 0) {
                    negative_cycle = true;
                }
            }
        }
    }
    return;
}

int main(int argc, char *argv[])
{
    // input from txt （提出時にこの箇所は削除すること）
    //ifstream in("in.txt");
    //cin.rdbuf(in.rdbuf());
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> E;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            w[i][j] = (i == j) ? 0 : Inf;
        }
    }
    
    for (int i = 1; i <= E; i++) {
        int u, v;
        cin >> u >> v;
        u++;
        v++;
        cin >> w[u][v];
    }
    floydWarshall();
    if(!negative_cycle){
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if(d[i][j] >= Inf/2) {
                    cout << "INF";
                } else {
                    cout << d[i][j];
                }
                if (j == n) {
                    cout << endl;
                }
                else {
                    cout << " ";
                }
            }
        }
    } else {
        cout << "NEGATIVE CYCLE" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

 ll h,m,h1,m1,h2,m2,time=0,k;
 cin>>h1>>m1>>h2>>m2>>k;
 h=h1,m=m1;
 while(1)
 {
     if(h1==h2&&m1==m2)
     {
         break;
     }
     m1++;
     if(m1==60)
     {
         m1=0;
         h1++;
     }
     time++;
 }
 cout<<time-k<<endl;

return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  int ans=1;
  for(int i = 2; i*i<=x; i++){
    for(int j = i*i; j<=x; j*=i){
      ans=max(ans,j);
    }
  }
  cout << ans << endl;
}



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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int len = s.size();
	if(len<4)	cout<<"No\n";
	else if(s[0]!='Y'||s[1]!='A'||s[2]!='K'||s[3]!='I')	cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
 } 

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

using namespace std;

int main(void){
  int n,sum,a[26],b[26],total;

  while(1){
    total=0;
    fill(a,a+26,0);
    fill(b,b+26,0);
    
    cin >> n ;
    if(n==0)break;
    
    for(int i=0;i<n;i++){
      cin >> a[i] >> b[i] ;
      total+=a[i];
    }
    
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	if(b[i]>b[j]){
	  int t=b[i];
	  b[i]=b[j];
	  b[j]=t;
	  t=a[i];
	  a[i]=a[j];
	  a[j]=t;
	}
      }
    }
   
    sum=0;

    for(int i=0;i<n;i++){
      if(sum+a[i]<=b[i])sum+=a[i];
      else break;
    } 
    printf((sum==total)?"Yes\n":"No\n");
  }
  return 0;
}

Measured memory_bytes: 0
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(){
    val s = readLn()
    println(s.substring(0, 3))
}

Measured memory_bytes: 34460
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; ll w; cin >> n >> w;
	ll t[200000];
	rep(i, n) {
		cin >> t[i];
	}
	ll sum = 0;
	Rep(i,1, n) {
		if (t[i] - t[i - 1] < w) {
			sum += t[i] - t[i - 1];
		}
		else {
			sum += w;
		}
	}
	sum += w;
	cout << sum << endl;
	return 0;
}

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

int main(){
	int n;
	while( cin >> n , n ){
		int x=0,y=0;
		for(int i=0 ; i<n ; ++i ){
			int a,b;
			cin >> a >> b;
			if( a == b )
				x += a, y += b;
			else
				((a>b)? x : y ) += a+b;
		}
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
        if(a+b==c+d)cout<<"Balanced"<<endl;
        else if(a+b>c+d)cout<<"Left"<<endl;
        else cout<<"Right"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n; cin >> n;
    cout << (ld)((n + 1) / 2) / n << endl;
    
}

Measured memory_bytes: 256
A,B,C = [ int(n) for n in input().split() ]
K = int(input())

ptrn = ["A","B","C"]
for k in range(1,K):
  plen = len(ptrn)
  for i in range(plen) :
    wptrn = ptrn.pop(0)
    ptrn.append( wptrn + "A") 
    ptrn.append( wptrn + "B")
    ptrn.append( wptrn + "C")
    
flg = False    
for p in ptrn :
  plist = list(p)
  a = A
  b = B
  c = C
  for q in plist:
    if q == 'A':
      a *= 2
    elif q == 'B':
      b *= 2
    else:
      c *= 2
  if a < b and b < c:
    flg = True
    
print("Yes" if flg else "No")

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long
 
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
 
int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    cin>>s;
    int cnta = 0; 
    int cntb= 0;
    for(char c: s){
        if(c == 'A'){
            cnta++;
        } else cntb++;
    }
    if(cnta > 0 and cntb > 0){
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
d=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        e=m//i
        d.append(i)
        d.append(e)
ans=0

for i in d:
    if m>=n*i:
        ans=max(ans,i)

print(ans)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
const int N=101;
string G[N];
bitset<N> vis[N];
int n,m;
signed main(void){
	ios::sync_with_stdio(false);
	while(cin>>n>>m&&n&&m){
		//getchar();
		for(int i=0;i<n;i++)
				cin>>G[i];
		int x=0,y=0;
		for(int i=0;i<n;i++)
			vis[i].reset();
		while(true){
			if(vis[x][y]){
				cout<<"LOOP"<<endl;	
				break;
			}
			else if(G[x][y]=='.'){
				cout<<y<<" "<<x<<endl;
				break;	
			}
			vis[x][y]=true;
			switch(G[x][y]){
				case('>'):y++;break;
				case('<'):y--;break;
				case('^'):x--;break;
				case('v'):x++;break;
			}
		}
	}
}

Measured memory_bytes: 1232