akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define INF 1e9
#define mod 1000000007
#define eps 1e-6
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef long long ll;
void read(ll &x)
{
	scanf("%lld",&x);
}
void read(ll &x, ll &y)
{
	scanf("%lld%lld",&x,&y);
}
void read(ll &x, ll &y, ll &z)
{
	scanf("%lld%lld%lld",&x,&y,&z);
}
void print(ll x)
{
	printf("%lld ",x);
}
void println(ll x)
{
	printf("%lld\n",x);
}
const ll N=300000;
ll n,a[N+10],b[N+10],ans=N;
char s[N+10];
int main()
{
	//freopen("c.cpp","r",stdin);
 
	cin>>n;
	scanf("\n%s",s);
	for(ll i=1;i<=n;i++)
		a[i]=a[i-1]+(s[i-1]=='W');
	for(ll i=n;i>=1;i--)
		b[i]=b[i+1]+(s[i-1]=='E');
	for(ll i=1;i<=n;i++)
		ans=min(ans,a[i-1]+b[i+1]);
	cout<<ans;
}

Measured memory_bytes: 5248
n = int(input())
#h  = list(map(int, input().split()))
#h, w = list(map(int, input().split()))

#j-i=k-jではない 2j=k+i i=2j-k

s = input()
count = 0

"""
for i in range(n):
    for j in range(i+1, n):
        if s[i]!=s[j]:    
            for k in range(j+1, n):
                if j-i!=k-j:
                    if s[i]!=s[k] and s[j]!=s[k]:
                        count += 1
"""
for i in range(n):
    a = s[i:]
    if s[i]=="R":
        point = a.count("G")*a.count("B")
    elif s[i]=="G":
        point = a.count("R")*a.count("B")
    else:
        point = a.count("R")*a.count("G")
    count += point

#j-i=k-jではない 2j=k+i i=2j-k
#rgb

kom = 0
for i in range(n):
    for j in range(i+1, n):
        if 2*j-i < n:
            if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                kom += 1


print(count-kom)





Measured memory_bytes: 68120
#include <cstdio>

int main(void){
		int x, y, W, H, r;
		scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
		if(x-r >= 0 && x+r <= W && y-r >= 0 && y+r <= H)printf("Yes\n");
		else printf("No\n");
		return 0;
}



Measured memory_bytes: 2676
#include<iostream>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int sum=3;
    for(int i=0;i<3;i++)
    {
    	if(s[i]!=t[i])
    	{
    		sum--;
		}
	}
	cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
int A[200010];
int MAX;
int MAX2;

int main(){
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> A[i];
		MAX2 = max(MAX2, A[i]);
		if (MAX < MAX2){
			swap(MAX, MAX2);
		}
	}
	for (int i = 0; i < N; i++){
		if (MAX == A[i])cout << MAX2 << endl;
		else cout << MAX << endl;
	}

	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    reverse(bit.begin(), bit.end());
    return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    ll res = A[0];
    ll cnt = N-2;
    for(int i=1;i<N;i++){
        ll toru = min(cnt, 2ll);
        res += A[i]*toru;
        cnt -= toru;
        if(cnt==0) break;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);
const int N = 100010;
struct info
{
	int pre, d;
} A[N];

void init()
{
	for (int i = 0; i < N; ++i)
	{
		A[i].pre = i;
		A[i].d = 0;
	}
}
inline int Find(int n)
{
	if(A[n].pre == n)
		return n;
	int tpre = A[n].pre;
	A[n].pre = Find(A[n].pre);
	A[n].d += A[tpre].d;
	return A[n].pre;
}
inline int Merge(int a, int b, int c)
{
	int fa = Find(a), fb = Find(b);
	if(fa == fb)
		return abs(A[a].d - A[b].d) == c;
	else
	{
		A[fa].pre = fb;
		A[fa].d = (c + A[b].d - A[a].d);
		return 1;
	}
}
int main(void)
{
	int n, m, a, b, i;
	while (~scanf("%d%d", &n, &m))
	{
		init();
		int flag = 1;
		while (m--)
		{
			int c;
			scanf("%d%d%d", &a, &b, &c);
			if(flag)
				flag &= Merge(a, b, c);
		}
		puts(flag ? "Yes" : "No");
	}
	return 0;
}

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

int a[100];

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int t;
            cin >> t;
            a[t-1]++;
        }
    }
    int ans = 0;
    for(int i=0; i<50; i++){
        if(a[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}  

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int age,yen;
    cin >> age >> yen;
    int ans;
    if(age >=13){
        ans = yen;
    }else if(age >=6){
        ans = yen/2;
    }else{
        ans = 0;
    }

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

Measured memory_bytes: 256
n = int(input())
sList = input()

alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
    alpha_dict[i+1] = chr(c)
    
new_s = []
for s in sList:
    key = [k for k, v in alpha_dict.items() if v == s][0]
    key = key + n
    if key > 26:
        key -= 26
    new_s.append(alpha_dict[key])
new_s = "".join(new_s)
print(new_s)

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

bool IsFind(vector<int> &v, int val)
{
  	int size = v.size();
  	for(int i = 0; i < size; i++)
    {
  		if(v[i] == val)
        {
         	 return true;
        }
    }
  	return false;
}

int main(void){
  int n, G;
  string token1, token2;

  cin >> G >> n;  
  vector<int> ret;
  long T[G+1] = {};
  
  for(int i = 0; i < G+1; i++){ T[i] = -1;}
  T[0] = 1;
  T[1] = 1;   
  
  for(int i = 0; i < n; i++) {
    int r;
    cin >> r;
    T[r] = 0;
  }
  
  for(int i = 2; i < G+1; i++)
  {
      if(T[i] == -1)
      {
        T[i] = (T[i-1] + T[i-2]) % 1000000007;
      }
  }
  //cout << T[1] << "\n";
  //cout << G << "\n";
  cout << (T[G] % 1000000007);
  return 0;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(1000000)


def solve(N, A):
    q = [(a, i) for i, a in enumerate(A)]
    q.sort(reverse=True)
    dp = [[-1 for _ in range(N + 1)] for __ in range(N + 1)]

    x = 0
    y = 0
    dp[x][y] = 0
    for a, i in q:
        dp[x+1][y] = dp[x][y] + a * abs(i - x)
        x += 1
    x = 0
    for a, i in q:
        dp[x][y+1] = dp[x][y] + a * abs(N - 1 - y - i)
        y += 1

    ans = 0
    for x in range(1, N+1):
        for y in range(1, N+1):
            if x + y > N:
                continue
            a, i = q[x+y-1]
            left = a * abs(i - (x - 1))
            right = a * abs(N - 1 - (y - 1) - i)
            dp[x][y] = max(dp[x-1][y] + left, dp[x][y-1] + right)
            ans = max(ans, dp[x][y])
    # [print(row) for row in dp]
    return ans

def slow_solve(N, A):
    import itertools
    ans = 0
    K = [i for i in range(N)]
    for p in itertools.permutations(K):
        tans = 0
        for i in range(N):
            tans += A[i] * abs(p[i] - i)
        ans = max(ans, tans)
    return ans

#
# assert (slow_solve(4, [1, 3, 4, 2]) == 20)
# assert (slow_solve(4, [1, 3, 4, 2]) == 20)
# assert (slow_solve(6, [5, 5, 6, 1, 1, 1]) == 58)
# assert (slow_solve(6, [8, 6, 9, 1, 2, 1]) == 85)
# print("OK")
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split(" ")))

    print(solve(N, A))


Measured memory_bytes: 137204
s=sorted(list(input()))
t=sorted(list(input()),reverse=True)
for i in range(min(len(s),len(t))):
  if ord(s[i])<ord(t[i]):
    print("Yes")
    break
  elif ord(s[i])>ord(t[i]):
    print("No")
    break
else:
  if len(s)>=len(t):
     print("No")   
  else:
     print("Yes")
               
 


Measured memory_bytes: 9056
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    h,w = map(int,input().split())
    dp = [[0]*w for i in range(h)]
    a = [input() for i in range(h)]
    dp[0][0] = 1
    for i in range(h):
        for j in range(w):
            if i+1 < h and a[i+1][j] == ".":
                dp[i+1][j] += dp[i][j]
                dp[i+1][j] %= Mod
            if j+1 < w and a[i][j+1] == ".":
                dp[i][j+1] += dp[i][j]
                dp[i][j+1] %= Mod

    print(dp[h-1][w-1])

if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 45820
#include<bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5
int h, w;
int a[500][500];
typedef pair<int , int> P;
typedef pair<P, P> PP;
#define MP make_pair
vector<PP> vec;
int direct(int i){
    return i % 2 ? -1 : 1;
}
int main(){
   cin >> h >> w;
   int sum = 0;
   for(int i = 0; i < h; i++){
       for(int j = 0; j < w; j++){
           cin >> a[i][j];
           sum += a[i][j];
        }
   }
    for(int i = 0; i < h; i++){
        for(int j = i % 2 ? w - 1 : 0; j < w && j >= 0; j += i % 2 ? -1 : 1){
            if(a[i][j] % 2){
                a[i][j]--;
                if(j + direct(i) < w && j + direct(i) >= 0){
                    a[i][j + direct(i)]++;
                    vec.push_back(MP(MP(i + 1, j + 1), MP(i + 1, j + direct(i) + 1)));
                 }
                else{
                    if(i + 1 >= h){
                        break;
                    }
                    a[i + 1][j]++;
                    vec.push_back(MP(MP(i + 1, j + 1), MP(i + 2, j + 1)));
                }
            }
        }
    }
    cout << vec.size() << endl;
    for(int i = 0; i < vec.size(); i++){
        cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second.first << " " << vec[i].second.second << endl; 
    }
}

Measured memory_bytes: 5104
m, n = map(int, input().split())

count = 0
if m > 1 and n > 1:
  count = (m - 2)*(n - 2)
elif m == 1 and n > 1:
  count = n - 2
elif m > 1 and n == 1:
  count = m - 2
elif m == 1 and n == 1:
  count = 1
 
print(count)

Measured memory_bytes: 3060
unittest
{
	assert( [ "4", "3 4 2 1" ].parse.expand.solve == 1 );
	assert( [ "3", "1 1000 1" ].parse.expand.solve == 0 );
	assert( [ "7", "218 786 704 233 645 728 389" ].parse.expand.solve == 23 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto as_s = as.sort();
	while( !as_s.empty )
	{
		auto a = as_s.front;
		as_s.popFront;
		auto bs_s = as_s;
		while( !bs_s.empty )
		{
			auto b = bs_s.front;
			bs_s.popFront;
			if( !bs_s.empty ) ans += bs_s.lowerBound( a + b ).length;
		}
	}
	return ans;
}


Measured memory_bytes: 2428
#include <stdio.h>
int main() {
  int N, i;
  scanf("%d", &N);
  int A[N+10];
  int B[N+10];
  for (i = 1; i < N + 1; ++i) {
    scanf("%d", &A[i]);
    B[A[i]] = i;
  }
  for (i = 1; i < N + 1; ++i) {
    printf("%d\n", B[i]);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const int mxn = 2e5;
int n;
char c[mxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  int red_size = 0, res = 0;
  for (int i = 0; i<n; i++) {
    cin >> c[i];
    if (c[i]=='R') red_size++;
  }
  for (int i = 0; i< red_size;i++) {
    if (c[i]=='W') res++;
  }
   cout << res <<endl;


}


Measured memory_bytes: 3836
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll dp[MAX_N][13];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    dp[0][0] = 1;
    for (int i = 0; i < S.size(); ++i) {
        for (int j = 0; j < 13; ++j) {
            if (S[i] != '?') {
                dp[i + 1][(j * 10 + (int)(S[i] - '0')) % 13] = (dp[i + 1][(j * 10 + (int)(S[i] - '0')) % 13] + dp[i][j]) % MOD;
            }
            else {
                for (int k = 0; k < 10; k++) {
                    dp[i + 1][(j * 10 + k) % 13] = (dp[i + 1][(j * 10 + k) % 13] + dp[i][j]) % MOD;
                }
            }
        }
    }
    cout << dp[S.size()][5] << endl;
    return 0;
}

Measured memory_bytes: 10704
c = [list(map(int, input().split())) for _ in range(3)]
for i in [1, 2]:
  d1 = c[0][0] - c[i][0]
  d2 = c[0][1] - c[i][1]
  d3 = c[0][2] - c[i][2]
  d4 = c[0][0] - c[0][i]
  d5 = c[1][0] - c[1][i]
  d6 = c[2][0] - c[2][i]
  if d1 != d2 or d1 != d3 or d4 != d5 or d4 != d6:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 9116
import collections
N =int(input())
V =list(map(int,input().split()))
ev_col = collections.Counter(V[::2]).most_common()
od_col = collections.Counter(V[1::2]).most_common()

if ev_col[0][0] != od_col[0][0]:
    ans = N - od_col[0][1] - ev_col[0][1]
else:
    if len(ev_col) >= 2 and len(od_col)  >= 2:
        if ev_col[1][1] >= od_col[1][1]:
            ans = N - ev_col[1][1] - od_col[0][1]
        else:
            ans = N - od_col[1][1] - ev_col[0][1]
    else:
        ans = N - ev_col[0][1]
print(ans)


Measured memory_bytes: 25320
'use strict'

function main(s) {

  s = s.split('\n').slice(0, -1);

  const a = s[0];
  const b = s[1];

  let ans = '';

  if (a.length > b.length) {
    ans = 'GREATER';
  } else if (a.length < b.length) {
    ans = 'LESS';
  } else {
    if (a < b) ans = 'LESS';
    if (a > b) ans = 'GREATER';
    if (a === b) ans = 'EQUAL';
  }

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define UNK 2000000000

bool valid(vector<int>&v){
	int i;
	for(i=1;i<v.size();i+=2){
		if(v[i-1]<=v[i])return false;
	}
	for(i=2;i<v.size();i+=2){
		if(v[i-1]>=v[i])return false;
	}
	return true;
}

int main(){
	int n,i,j;
	string s;
	for(;cin>>n,n;){
		vector<int>unknown;
		vector<int>num;
		vector<int>v;
		v.push_back(1000010000);
		num.push_back(1000010000);
		for(i=0;i<n;i++){
			cin>>s;
			if(s=="x"){
				unknown.push_back(i+1);
				v.push_back(0);
			}else{
				int n=strtol(s.c_str(),NULL,10);
				num.push_back(n);
				v.push_back(n);
			}
		}
		if(v.size()%2==0){
			v.push_back(1000010001);
			num.push_back(1000010001);
		}else{
			v.push_back(-1000010001);
			num.push_back(-1000010001);
		}

		int _min=UNK,_max=UNK;
		if(unknown.empty()){
			if(valid(v))cout<<"ambiguous"<<endl;
			else cout<<"none"<<endl;
			continue;
		}
/*
		for(i=1;i<unknown.size();i++)if(unknown[i-1]+1==unknown[i]){
			cout<<"none"<<endl;
			goto next;
		}
*/
		for(i=0;i<unknown.size();i++){
			if(unknown[i]%2==0){
				if(_min==UNK)_min=max(v[unknown[i]-1],v[unknown[i]+1])+1;
				_min=max(_min,max(v[unknown[i]-1],v[unknown[i]+1])+1);
			}else{
				if(_max==UNK)_max=min(v[unknown[i]-1],v[unknown[i]+1])-1;
				_max=min(_max,min(v[unknown[i]-1],v[unknown[i]+1])-1);
			}
		}
		if(_min==UNK||_max==UNK)cout<<"ambiguous"<<endl;
		else if(_min>_max)cout<<"none"<<endl;
		else{
			for(j=0;j<unknown.size();j++)v[unknown[j]]=_min;
			if(valid(v)){
				if(_min==_max)cout<<_min<<endl;
				else cout<<"ambiguous"<<endl;
			}else{
				cout<<"none"<<endl;
			}
		}

/*
		sort(num.begin(),num.end());
		for(i=1;i<num.size();i++){
			for(j=0;j<unknown.size();j++)v[unknown[j]]=num[i-1]+1;
			if(valid(v)){
				if(num[i-1]+1==num[i]-1)cout<<num[i-1]+1<<endl;
				else cout<<"ambiguous"<<endl;
				goto next;
			}
		}
		cout<<"none"<<endl;
		next:;
*/
	}
}

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

int main(int argc, char *argv[]) {
  int N, K, X, Y, ans;
  scanf("%d %d %d %d", &N, &K, &X, &Y);
  ans = 0;
  for (int i = 0; i < N; i++)
    ans += i < K ? X : Y;
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int n,m;
vector<int> E[maxn],ans;
int vis[maxn];
int ind[maxn];
int dp[maxn];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    rep(i,1,m){
        int x,y;
        cin>>x>>y;
        E[x].push_back(y); 
        ind[y]++;
    }
    queue<int> Q;
    rep(i,1,n)if(!ind[i])Q.push(i);
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        vis[now]=1;
        ans.push_back(now);
        for(auto t:E[now]){
            if(vis[t])continue;
            dp[t]=dp[now]+1;
            ind[t]--;
            if(ind[t]==0)Q.push(t);
        }
    }
    int mx=0;
    rep(i,1,n)mx=max(mx,dp[i]);
    cout<<mx<<endl;;
}
/* 
dp[i]：终点为i的最长路
dp[i]=dp[j]+1  for all j->i
更新顺序：toposort
 */


Measured memory_bytes: 37500
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;


int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<n-1;i++)
	{
		map<char,int> l;
		int anso=0;
		for(int j=0;j<i;j++) l[s[j]]++;
		for(int j=i;j<n;j++)
		{
			if(l[s[j]]) anso++,l[s[j]]=0;
		}
		ans=(anso>ans?anso:ans);
		l.clear();
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        int[] b = new int[n];
        for(int i=0;i<n+1;i++){
            a[i] = Integer.parseInt(sc.next());
        }
        for(int i=0;i<n;i++){
            b[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        long monster = 0;
        for(int i=n-1;i>=0;i--){
            if(b[i] > a[i+1]){
                monster+=a[i+1];
                b[i]-=a[i+1];
                monster+=Math.min(a[i],b[i]);
                a[i]-=Math.min(a[i],b[i]);
            }else{
                monster+=b[i];
                a[i+1]-=b[i];
            }
        }
        System.out.println(monster);
    }
}


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

int main() {
  ll a,b,x;cin>>a>>b>>x;
  ll ans = b/x;
  if (a==0) ans++;
  else ans -= (a-1)/x;
  cout << ans;
}


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


void solve(std::string S){
  long long N = S.size();

  for(long long i = 1; i < N; i++){
    if((N-i)%2 == 1) continue;

    if(S.substr(0,(N-i)/2) == S.substr((N-i)/2,(N-i)/2)) {

      cout << N-i << endl;
      return;
    }
  }

  cout << 0 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
    ll n;
    cin>>n;
    ll arr[n],dp[n];
    for(ll i=0;i<n;i++) cin>>arr[i];
    dp[1]=abs(arr[1]-arr[0]);
    dp[0]=0;
    for(ll i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=1e5+5;
const int M=1e9+7;
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;

int top, S[1000];

void push(int x) { // ???????????????????????????????´?x???????????????
	S[++top] = x; // top?????????????????????????????????????????\
}

int pop() { // ??????????????????????????????????´????????????????
	top--;
	return S[top + 1]; // top??????????????????????´??????????
}

int main() {
	int a, b;
	top = 0;
	char s[100];
	
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}

	cout << pop() << "\n";
	return 0;
}

Measured memory_bytes: 3236
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		String[] s = new String[n];
		int[] t = new int[n];
		for(int i = 0;i < n;i++){
			s[i] = saori.nextHayami();
			t[i] = saori.saori_hayami();
		}
		int ans = 0;
		boolean flg = false;
		String x = saori.nextHayami();
		for(int i = 0;i < n;i++){
			if(flg){
				ans += t[i];
			}
			if(s[i].equals(x)){
				flg = true;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

map<char, int> c = {{'r', 0}, {'s', 1}, {'p', 2}};
// char c[3] = {'r', 'p', 's'};

bool win(int a, int b) {
    if (a == 0 && b == 1)
        return 1;
    if (a == 1 && b == 2)
        return 1;
    if (a == 2 && b == 0)
        return 1;
    // swap(a, b);
    // if (a == 0 && b == 2)
    //     return -1;
    // if (a == 2 && b == 1)
    //     return -1;
    // if (a == 1 && b == 0)
    //     return -1;
    

    return 0;
}

const int inf = 1e-13;

void solve(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    int cost[3];
    for (auto &i : cost)
        cin >> i;
    string t;
    cin >> t;
    int dp[n][3];
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (i < k) {
                dp[i][j] = win(j, c[t[i]]) * cost[j];
            } else {
                for (int z = 0; z < 3; ++z) { 
                    if (j == z)
                        continue;
                    dp[i][j] = max(dp[i][j], dp[i - k][z] + win(j, c[t[i]]) * cost[j]);
                }
            }
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }
    int sum = 0;
    for (int i = 0; i < k; ++i) {
        sum += max(dp[n - i - 1][0], max(dp[n - i - 1][1], dp[n - i - 1][2]));
    }
    cout << sum << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}


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

int arr[100005];

#undef int
int main()
{
#define int long long
    int n,m;
    cin >> n >> m;

    for(int i=0;i<n;i++)
       cin >> arr[i];
           
    int sum=0;
    priority_queue<int>pq;
    for(int i=0;i<n;i++)
    {
        pq.push(arr[i]);
    }
    for(int i=0;i<m;i++)
    {
        int x=pq.top();
        pq.pop();
        pq.push(x/2);
    }
    for(int i=0;i<n;i++)
    {
       sum+=pq.top();
       pq.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 2168
fun main(args: Array<String>) {
    abc099c()
}

fun abc099c() {
    val n = readLine()!!.toLong()

    val sixTable = sortedSetOf<Long>()
    var six = 1L
    while (six < 100000) {
        sixTable.add(six)
        six *= 6
    }

    val nineTable = sortedSetOf<Long>()
    var nine = 1L
    while (nine < 100000) {
        nineTable.add(nine)
        nine *= 9
    }

    var answer = Long.MAX_VALUE
    for (i in 0..n) {
        var sixRemain = i
        var nineRemain = n - i
        var count = 0L

        while (sixRemain > 0) {
            count++
            sixRemain -= sixTable.findLast { it <= sixRemain } ?: error("なんで？")
        }
        while (nineRemain > 0) {
            count++
            nineRemain -= nineTable.findLast { it <= nineRemain } ?: error("なんで？")
        }

        answer = Math.min(answer, count)
    }

    println(answer)
}


Measured memory_bytes: 67580
import java.util.Scanner;
// A - Multiplication 1
class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();

		int ans;

		if (A == 0) {
			System.out.println("1");
		}
		if (B == 0) {
			System.out.println("2");
		}
		if (C == 0) {
			System.out.println("3");
		}
		if (D == 0) {
			System.out.println("4");
		}
		if (E == 0) {
			System.out.println("5");
		}

	}
}

Measured memory_bytes: 27052
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>
typedef long long LL;
using namespace std;
int a[100005];
int gcd(int x,int y)
{
    int r;
    do
    {
        r=x%y;
        x=y;
        y=r;
    }while(y);
    return x;
}
int main()
{
    int n,k,f,c;
    scanf("%d%d",&n,&k);
    int ma=-1;
    scanf("%d",&c);
    ma=c;
    for(int i=1;i<n;++i)
    {
        scanf("%d",&f);
        ma=max(f,ma);
        c=gcd(c,f);
    }
    if(ma>=k&&k%c==0) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 256
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])
A_list = list(map(int,input().split()))

sugoi = 4 * M
_sum = sum(A_list)
ok = 0
for i in range(len(A_list)):
  if A_list[i] >=  _sum / sugoi:
    ok += 1
    
if ok >= M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
#include <set>
using namespace std;

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

#define max_n 100

string s, t;

int main() {

	cin >> s >> t;

	vector<int> AP[30];

	rep(i, s.size()){
		AP[s.at(i) - 'a'].push_back(i);
	}

	bool Unable = false;
	rep(i, t.size()) {
		if (AP[t.at(i) - 'a'].size() <= 0)Unable = true;
	}
	if(Unable)
	{
		cout << "-1" << endl;
		return 0;
	}


	int Lap = 0; //周回数
	int point = 0;//1週の位置

	rep(i, t.size()) {

		//AP[t.at(i)-'a'].　の二分探索
		int b = 0;
		int e = AP[t.at(i) - 'a'].size() - 1;

		for (; b < e;) {
			int j = (b + e) / 2;
			if (AP[t.at(i) - 'a'].at(j) < point)b = j + 1;
			else e = j;
		}

		if (point > AP[t.at(i) - 'a'].at(b)) {
			point = AP[t.at(i) - 'a'][0];
			Lap++;
		}
		else point = AP[t.at(i) - 'a'].at(b);

		point++;
		if (point >= s.size()) {
			point = 0; Lap++;

		}
	}
	long long ans = s.size()*Lap + point;
	cout << ans << endl;

	return 0;	
}

Measured memory_bytes: 1216
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, x, d;
  cin >> n >> x >> d;

  // Check the case when d = 0
  if (d == 0) {
    if (x == 0) {
      cout << 1 << endl;
      return 0;
    } else {
      cout << n+1 << endl;
      return 0;
    }
  }

  map<int, vector<P>> mp;
  rep(i, n+1) {
    // Here, we consider the case in which we use i.
    ll s = x*i;
    ll l = (ll)i*(i-1)/2; // the sum of [0, i)
    ll r = l + (ll)i*(n-i); // slide to [n-i, n)
    s += l*d;
    r -= l; // [l, r] is closed range. the distance is r+1.
    mp[((s%d)+d)%d].emplace_back(s, r);
  }

  ll ans = 0;
  for (auto& p : mp) {
    auto& a = p.second;
    int m = a.size();
    // subtract remainder and divide by d.
    rep(i, m) {
      a[i].first = (a[i].first - p.first)/d;
    }
    vector<P> ev;
    rep(i, m) {
      ev.emplace_back(a[i].first, 1);
      ev.emplace_back(a[i].first + a[i].second + 1, -1);
    }
    sort(all(ev));
    ll cnt = 0, pre = -INF;
    for (auto& e : ev) {
      ll len = e.first - pre;
      if (cnt) { ans += len; }
      cnt += e.second;
      pre = e.first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 22144
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=10000005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int ar[N];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i)
        ar[j]++;
        ans+=(i*ar[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 81732
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int a[105];

int main() {
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) {
        if (((i+1)&1) && (a[i]&1)) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int d[n + 1];
  d[0] = 0;
  for (int i = 0; i < n; ++i) {
    d[i + 1] = d[i] + a[i];
  }

  double ans = 0;
  rep(i, n - k + 1) {
    double now = (d[i + k] - d[i] + k) / 2.0;
    ans = max(ans, now);
  }

  printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll k,x;
    cin>>k>>x;
    if(500*k>=x)
    cout<<"Yes";
    else
    cout<<"No";
}


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

int main(){
  int n, y;
  cin >> n >> y;
  
  for (int i=0; i<=n; i++){
    for (int j=0; j<=n-i; j++){
      int z = n - i - j;
      if (10000*i+5000*j+1000*z==y){
        printf("%d %d %d\n",i,j,z);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		while (true) {
			int[][] field = new int[21][21];
			
			int robotPositionYoko=10;
			int robotPositionTate=10;

			int jueleNumber = scan.nextInt();
			int juelePositionYoko;
			int juelePositionTate;
			if (jueleNumber == 0)
				break;

			for (int i = 0; i < jueleNumber; i++) {
				juelePositionYoko = scan.nextInt();
				juelePositionTate = scan.nextInt();
				field[juelePositionYoko][juelePositionTate] = 1;
			}

			int order = scan.nextInt();
			char direction;
			int dirNumber;
			for (int i = 0; i < order; i++) {
				direction = scan.next().charAt(0);
				dirNumber = scan.nextInt();
				switch (direction) {
				case 'N':
					for(int j=0;j<dirNumber;j++){
						robotPositionTate++;
						if(field[robotPositionYoko][robotPositionTate]==1)field[robotPositionYoko][robotPositionTate]=0;
					}
					break;
				case 'E':
					for(int j=0;j<dirNumber;j++){
						robotPositionYoko++;
						if(field[robotPositionYoko][robotPositionTate]==1)field[robotPositionYoko][robotPositionTate]=0;
					}
					break;
				case 'S':
					for(int j=0;j<dirNumber;j++){
						robotPositionTate--;
						if(field[robotPositionYoko][robotPositionTate]==1)field[robotPositionYoko][robotPositionTate]=0;
					}
					break;
				case 'W':
					for(int j=0;j<dirNumber;j++){
						robotPositionYoko--;
						if(field[robotPositionYoko][robotPositionTate]==1)field[robotPositionYoko][robotPositionTate]=0;
					}
					break;
				}
				
			}
			int flag=0;
			for(int i=0;i<21;i++){
				for(int j=0;j<21;j++){
					if(field[i][j]==1)flag=1;
				}
			}
			if(flag==0){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
			
		}
	}
}

Measured memory_bytes: 35120
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int a[110];
int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	int n;
	cin>>n;
	int x=0;
	for(int i=1; i<=n; ++i) {
		int t;
		cin>>t;
		if (t%2!=0) x^=1;
	}
	if (x==0) 
		puts("YES");
	else
		puts("NO");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Card {
    String suit;
    int value;

    @Override
    public String toString() {
        return this.suit + this.value;
    }

    Card(String str) {
        this.suit = str.substring(0, 1);
        this.value = Integer.parseInt(str.substring(1));
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Card[] arrOrigin = new Card[n];
        for (int i = 0; i < n; i++) {
            arrOrigin[i] = new Card(sc.next());
        }
        Card[] arrBubble = arrOrigin.clone();
        bubbleSort(arrBubble);
        printArray(arrBubble);
        System.out.println(isStable(arrOrigin, arrBubble) ? "Stable" : "Not stable");
        Card[] arrSelection = arrOrigin.clone();
        selectionSort(arrSelection);
        printArray(arrSelection);
        System.out.println(isStable(arrOrigin, arrSelection) ? "Stable" : "Not stable");
    }


    static boolean isStable(Card[] org, Card[] dst) {
        int orgN = org.length;
        int dstN = dst.length;
        boolean res = true;
        for (int i = 0; i < orgN; i++) {
            for (int j = i + 1; j < orgN; j++) {
                for (int a = 0; a < dstN; a++) {
                    for (int b = a + 1; b < dstN; b++) {
                        if (org[i].value == org[j].value && org[i] == dst[b] && org[j] == dst[a]) {
                           res = false;
                        }
                    }
                }
            }
        }
        return res;
    }


    static void bubbleSort(Card[] arr) {
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            for (int j = n - 1; j > i; j--) {
                if (arr[j].value < arr[j - 1].value) {
                    Card tmp = arr[j];
                    arr[j] = arr[j - 1];
                    arr[j - 1] = tmp;
                }
            }
        }
    }

    static void selectionSort(Card[] arr) {
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            int minJ = i;
            for (int j = i; j < n; j++) {
                if (arr[j].value < arr[minJ].value) {
                    minJ = j;
                }
            }
            Card tmp = arr[i];
            arr[i] = arr[minJ];
            arr[minJ] = tmp;
        }
    }


    static void printArray(Card[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length - 1; i++) {
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[arr.length - 1]);
        System.out.println(sb.toString());
    }
}



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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S; 
    for(int i = 0; i < S.size(); i++){
        char c;
        int s = (int)S[i] + N;
        if( s > 90){
            c = (char)(64 + s - 90);
        }else{
            c = (char)s;
        }
        cout << c;
    }
    cout << endl;
    
}


Measured memory_bytes: 256
n = int(input())
la = list(map(int, input().split()))
la.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if la[i]!=la[j] and la[j]!=la[k] and la[i]+la[j]>la[k]:
        ans += 1
print(ans)

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

int main() {
    int N; cin >> N;
    vector<int64_t> A(N), B(N), C(N);
    for(auto &e : A) cin >> e;
    for(int i = 0; i < N; ++i) {
        B[i] = A[i] + i;
        C[i] = -A[i] + i;
    }
    int64_t ans = 0;
    map<int, int> ma;
    for(int i = 0; i < N; ++i) {
        if(ma[C[i]]) ans += ma[C[i]];
        ma[B[i]]++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 24752
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

N = int(input())
L = list(map(int, input().split()))

mx = L[0]
idx = 0
for i in range(N):
    if L[i] > mx:
        mx = L[i]
        idx = i

if mx < sum(L[i] for i in range(N) if i != idx):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65288
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var l = o.a();
  var a = o.r(l);
  var dp = [];
  for(var j = 0; j < 5; j++)dp[j] = f(a[0], j);
  for(var i = 1; i < l; i++){
    var d = Array(5).fill(9e99);
    d[0] = dp[0] + a[i];
    for(j = 1; j < 5; j++)for(var k = 0; k <= j; k++){
      var t = dp[k] + f(a[i], j);
      if(d[j] > t)d[j] = t;
    }
    dp = d;
  }
  return Math.min(...dp);

  function f(n,k){
    if(k === 0 || k === 4)return n;
    if(k === 2)return (n + 1) % 2;
    return n === 0 ? 2 : n % 2;
  }
}

Measured memory_bytes: 39608