akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ABC098C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var directions = Console.ReadLine().ToCharArray().Reverse().ToArray();
            int left_east = 0;
            int right_west = 0;
            foreach (var d in directions.Skip(1))
            {
                if(d == 'W')
                {
                    right_west++;
                }
            }
            int min = right_west;

            for (int i = 1; i < directions.Length; i++)
            {
                if (directions[i] == 'W')
                {
                    right_west--;
                }

                if (directions[i - 1] == 'E')
                {
                    left_east++;
                }

                int turning = right_west + left_east;
                if (turning < min)
                {
                    min = turning;
                }
            }

            Console.WriteLine($"{min}");
        }
    }
}


Measured memory_bytes: 17760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int x;
int main()
{
	cin>>x;
	if(x>=30) re("Yes") else re("No")
	return 0;}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void)
{
    int k, l;
    scanf("%d %d", &k, &l);
    
    int a[k][l], b[l], c[k];//k x l * l x 1
    int i, j;

    /*initialize a, b, c */
    for (i = 0; i < k; ++i) {
        for (j = 0; j < l; ++j) {
            scanf("%d", &a[i][j]);
        }
    }
    for (i = 0; i < l; ++i) {
        scanf("%d", &b[i]);
    }
    
    for (i = 0; i < k; ++i) {
        c[i] = 0;
    }
    //calc
    for (i = 0; i < k; ++i) {
        for (j = 0; j < l; ++j) {
            c[i] += a[i][j] * b[j];
        }
    }
    //output
    for (i = 0; i < k; ++i) {
        printf("%d\n", c[i]);
    }
    return 0;
}

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


int main(void){
   long long n;
   cin >> n;
   
   long long ans = (n-1)*n/2;
   cout << ans << endl;
}

Measured memory_bytes: 256
S = raw_input()
flag1 = S[0] == 'A'

cnt = 0
index = 0
for i in range(2, len(S)-1):
	if S[i] == 'C':
		cnt += 1
		index = i
flag2 = cnt == 1

if not(flag1 and flag2): print 'WA'
else:
	flag3 = True
	for i in range(1, len(S)):
		if i != index:
			n = ord(S[i])
			if n < 97: flag3 = False
	if flag3: print 'AC'
	else: print 'WA'

Measured memory_bytes: 28012
#include <iostream>
 
using namespace std;
 
int main()
{
    string s[100001];
    int i , n ;
    int AC=0 , WA=0 , TLE=0, RE=0;
    cin>>n;
    for(i=0;i<n; i++){
        cin>>s[i];}
    for(i=0;i<n;i++){
        if(s[i]=="AC"){ AC+=1;}
        else if (s[i]=="WA"){WA+=1;}
        else if (s[i]=="TLE"){TLE+=1;}
        else if (s[i]=="RE"){RE+=1;}
        }
    cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;
 
    return 0;
}

Measured memory_bytes: 6736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll s;cin>>s;
    if(s==(1e+18)){
        cout<<0<<" "<<0<<" "<<1000000000<<" "<<0<<" "<<0<<" "<<1000000000<<endl;
        return 0;
    }
    ll x2=1e+9,y2=1;
    ll y3=s/(1000000000),x3=s%(1000000000);
    x3=1000000000-x3;y3++;
    cout<<0<<" "<<0<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define vll vector<long long>
#define pb push_back
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[500005];
ll vis[500005],color[500005],I[101][101];

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

bool isPrime(int n)
{
    if (n<=1) return false; 
    if (n<=3) return true; 
    if (n%2==0||n%3==0) return false; 
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; 
    return true; 
}

ll binpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res*=n;
			po--;
		}
		else
		{
			n*=n;
			po/=2;
		}
	}
	return res;
}

ll swap(ll a, ll b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll fact(ll n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}


int main()
{
	float a,b;
	cin>>a>>b;
	ll ans=1;
	ans+=ceil((b-a)/(a-1));
	cout<<ans;
}

Measured memory_bytes: 13696
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 10**12
    a = -1
    for i in range(0,102):
        if i not in p and abs(X-i) < ans:
            ans = abs(X-i)
            a = i
    print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9464
N,M,X=map(int,input().split())
C_li=[]
for _ in range(N):
    C=list(map(int,input().split()))
    C_li.append(C)
cost_min=10**9
for i in range(2**N):
    total=[0]*M
    cost=0
    for j in range(N):
        if (i>>j)&1:
            cost+=C_li[j][0]
            for k in range(M):
                total[k]+=C_li[j][k+1]
    flag=True
    for l in range(M):
        if total[l]<X:
            flag=False
    if flag==True and cost<cost_min:
        cost_min=cost
if cost_min==10**9:
    print(-1)
else:
    print(cost_min)

Measured memory_bytes: 9164
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, k, ans=1;
	cin >> n >> k;
	for (int i = 1; i <= n;i++) {
		if (ans*2>ans+k) {
			ans += k;
		}
		else {
			ans *= 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools
N,K=map(int,input().split())
l=[0]*N
n=0
for i in range(K):
  d=int(input())
  have=list(input().split())
  for j in have:
    l[int(j)-1]=1

for i in range(N):
  if l[i]==0:
    n+=1
print(n)


Measured memory_bytes: 9224
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {1:0, 2:0, 4:0}
    for a in A:
        if a % 2 == 1:
            d[1] += 1
        elif a % 4 == 0:
            d[4] += 1
        else:
            d[2] += 1
    if d[2] == 0 and d[4] + 1 >= d[1]:
        print("Yes")
    elif d[2] != 0 and d[4] >= d[1]:
        print("Yes")
    else:
        print("No")
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 85180
#include <stdio.h>
#define A 100000
int main(int argc, char const *argv[]){
	int sum,i=0,n,o=0,a[A];
	scanf("%d",&n);
	for(i=0;i<n;i++)
			scanf("%d",&a[i]);
	while(1){
		for(i=0;i<n;i++){
			if(a[i]%2!=0)
				break;
			a[i]/=2;
		}
		if(i!=n)
			break;
		else
			o++;
	}
	printf("%d\n",o);
	return 0;
}

Measured memory_bytes: 128
from collections import Counter


N = int(input())
S = []
for i in range(N):
    S.append(input())

c = Counter(S)
c_sorted = sorted(c.items(), key=lambda x: x[1], reverse=True)
j = -1
for i in range(len(c_sorted)):
    if i == len(c_sorted) - 1:
        break
    if c_sorted[i + 1][1] < c_sorted[i][1]:
        break

c_sorted_best = c_sorted[:i + 1]
c_sorted_best_dicOrder = sorted(c_sorted_best, key=lambda x: x[0])
print('\n'.join([x[0] for x in c_sorted_best_dicOrder]))


Measured memory_bytes: 53480
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
//#include<string>
//#include<sstream>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=2e5+5;
const double eps=1e-10;
int tot;
int head[MAXN];
int n,m;
struct Node
{
    int from,to,nxt;
}e[MAXN];
bool dd(int s,int t,int k);
void age(int u,int v);
int main()
{
    int d,k;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(head,-1,sizeof(head));
        int u,v;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&u,&v);
            age(u,v);
        }
        if(dd(1,n,0))
            printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}
void age(int u,int v)
{
    e[tot].from=u;
    e[tot].to=v;
    e[tot].nxt=head[u];
    head[u]=tot++;
}
bool dd(int s,int t,int k)
{
    if(s==n&&k==2) return true;
    for(int i=head[s];i!=-1;i=e[i].nxt)
    {
        int to=e[i].to;
        if(dd(to,n,k+1)) return true;
    }
    return false;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    int A, B;
    cin >> A >> B;
    
    int tmp = 1;
    int ans = 0;
    while(tmp < B){
        tmp += A-1;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
bool func(){
    string str;
    cin>>str;
    for(int i=0;i<str.size()-1;++i){
        if(str.substr(i,2)=="AC"){
            return true;
        }
    }
    return false;
}
int main(){
    cout<<(func()?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
	public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int X = scanner.nextInt();
			    int t = scanner.nextInt();
			    
			    if (X-t >= 0) {
			    	System.out.println(X-t);
			    } else {
			    	System.out.println(0);
			    }
			    
		}
		}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int n;
	cin >> n;

	vi a(n);
	int allxor = 0;
	rep(i,n){
		cin >> a[i];
		allxor = allxor ^ a[i];
	}

	int ans;
	rep(i,n){
		ans = allxor ^ a[i];
		cout << ans;
		if(i < n-1){
			cout << " ";
		}
	}
	cout << "\n";
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------

void Main(){
  int n;
  map<ll,ll> m;
  priority_queue<ll> can;
  cin>>n;
  rep(i,n){
    ll a;
    cin>>a;
    m[a]++;
    if(m[a]==2){can.push(a);m[a]=0;}
  }
  if(can.size()>=2){
    ll ans = can.top();can.pop();
    cout<<ans*can.top()<<endl;
  }else{
    cout<<0<<endl;
  }
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		int num = 0;
		int sum = 0;
		
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		
		for(int i = 0; i < N; i++) {
			sum += a[i];
			if(sum > x) {
				num = i;
				break;
			}
			
			if((i == (N - 1)) && (sum != x)) {
				num = i;
			} else if((i == (N - 1)) && (sum == x)) {
				num = i + 1;
			}
			
		}
		
		System.out.println(num);
	
	}
}


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

using ll = long long;


int main() {
    int H, W, N, a;
    cin >> H >> W >> N;
    vector<int> s(N + 1, 0), c(H * W);
    rep(i, N) {
        cin >> a;
        s[i + 1] = s[i] + a;
        for (int j = s[i]; j < s[i + 1]; j++) c[j] = i + 1;
    }
    rep(i, H) {
        rep(j, W) {
            if (i % 2) cout << c[i * W + j];
            else cout << c[i * W + W - 1 - j];
            if (j == W - 1) cout << "\n";
            else cout << " ";
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    long N;
    cin >> N;

    multiset<long> s {};
    for (long i=0; i<N; i++) {
        long a;
        cin >> a;

        // cout << "i: " << i << endl;
        // cout << "a: " << a << endl;
        // cout << "s.begin(): " << *(s.begin()) << endl;
        // cout << "s.end(): " << *(s.end()) << endl;
        if (i == 0) {
            s.insert(a);
        } else {
            auto itr = s.lower_bound(a);
            //cout << "a: " << a <<  ", lower_bound: " << *itr << endl;
            if (itr == s.begin()) {
                //cout << "insert: " << a << endl;
                s.insert(a);
            } else {
                //cout << "update: " << *(--itr) << " -> " << a << endl;
                s.erase(--itr);
                s.insert(a);
            }
        }
    }

    cout << s.size() << endl;
    // cout << "s.begin(): " << *(s.begin()) << endl;
    // cout << "s.end(): " << *(s.end()) << endl;
    //for (auto itr=s.begin(); itr!=s.end(); itr++) {
    //    cout << "s: " << *itr << endl;
    //}
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  cout << (s[0]==s[1] && s[2]==s[3] && s[1]!=s[2] ? "Yes" : "No") << endl;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin >>n;

    rep(i,n){
        int l,r;
        cin >>l>>r;
        ans += r-l+1;
    }
    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

int main(){
    int N;cin>>N;
    vector<int> P(N,0);
    rep(i,N){
        cin>>P[i];
    }
    int min_hist = 1e+8;
    int ans = 0;
    rep(i,N){
        if(min_hist>=P[i])ans++;
        min_hist = min(min_hist,P[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2019/03/24/110200
using pint = pair<int, int>;
int main() {
    int N;
    cin >> N;
    vector<pint> res;
    int dame = N;
    if(N % 2 == 1) {
        //奇数なら
        dame--;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(j <= i | j == dame) {
                continue;
            }
            res.push_back(pint(i, j));
        }
        dame--;
    }
    cout << res.size() << endl;
    for(auto p : res) {
        cout << p.first << " " << p.second << endl;
    }
}

Measured memory_bytes: 384
def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

Measured memory_bytes: 16520
a=int(input())
sum=0
s=''
'''if a<0:
    b = abs(a)
    if b%2==1:
        b=b+1
        print(str(bin(b))[2:-1]+'1')
    else:
        print(str(bin(b))[2:-1])'''
if a!=0:
    while(a!=1):
        if a%(-2)==-1:
            s=s+'1'
            a=a-1
            a=a/-2
        else:
            s = s + '0'
            a=a/-2
    s=s+'1'
    for i in range(len(s)):
        print(s[len(s)-1-i],end='')
    print()
else:
    print(0)



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

#define INF 1e9

typedef complex<double> Point;
typedef vector<Point> VP;
const double EPS = 1e-9;
const double PI = acos(-1.0);
#define X real()
#define Y imag()
using star = vector<Point>;


double dot(Point a, Point b){
    return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b){
    return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c){
    b -= a; c -= a;
    if(cross(b,c) > EPS) return +1;
    if(cross(b,c) <-EPS) return -1;
    if(dot(b,c)   <-EPS) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}


bool isecSS(Point a1,Point a2,Point b1,Point b2){
    return ccw(a1,a2,b1)*ccw(a1,a2,b2) <= 0 &&
           ccw(b1,b2,a1)*ccw(b1,b2,a2) <= 0;
}

bool isecSP(Point a1,Point a2,Point b){
    return !ccw(a1,a2,b);
}

Point proj(Point a1, Point a2, Point p){
    return a1 + dot(a2-a1, p-a1)/norm(a2-a1)*(a2-a1);
}

double distSP(Point a1, Point a2, Point p){
    Point r = proj(a1,a2,p);
    if(isecSP(a1,a2,r)) return abs(r-p);
    return min(abs(a1-p),abs(a2-p));
}


double distSS(Point a1,Point a2,Point b1,Point b2){
    if(isecSS(a1,a2,b1,b2)) return 0;
    return min(
        min(distSP(a1,a2,b1),distSP(a1,a2,b2)),
        min(distSP(b1,b2,a1),distSP(b1,b2,a2))
    );
}

star make_star(double x,double y,double a,double r){
    star s(5);
    rep(i,5){
        s[i] = Point(x,y) + polar(r, (90+a+144*i)*PI/180.0);
    }
    return s;
}

double dist_star(star s1, star s2){
    double res = INF;
    rep(i,5)rep(j,5){
        double dist = distSS(s1[i],s1[(i+1)%5], s2[j],s2[(j+1)%5]);
        res = min(res,dist);
    }
    return res;
}

int main(){
    int N,M,L;
    while(cin>>N>>M>>L, N|M|L){
        vector<star> st(N);
        rep(i,N){
            double x,y,a,r;
            cin>>x>>y>>a>>r;
            st[i] = make_star(x,y,a,r);
        }
        vector<vector<double>> d(N, vector<double>(N, INF));
        rep(i,N) d[i][i] = 0;
        rep(i,N)rep(j,i){
            double dist = dist_star(st[i],st[j]);
            d[i][j] = dist;
            d[j][i] = dist;
        }
        rep(k,N)rep(i,N)rep(j,N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
        printf("%.20f\n",d[M-1][L-1]);
    }
}


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

typedef struct {
  char suit, value;
} card;

void BubbleSort(card c[], int n)
{
  int flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = n - 1; j > i; j--) {
      if (c[j].value < c[j - 1].value) {
	swap(c[j], c[j - 1]);
	flag = 1;
      }
    }
  }
}

void SelectionSort(card c[], int n)
{
  int minj;
  for (int i = 0; i < n; i++) {
    minj = i;
    for (int j = i + 1; j < n; j++) {
      if (c[j].value < c[minj].value)
	minj = j;
    }
    swap(c[i], c[minj]);
  }
}

bool isStable(card a[], card b[], int n)
{
  for (int i = 0; i < n; i++)
    if (a[i].suit != b[i].suit)
      return false;
  return true;
}

int main()
{
  int n;
  card a1[100];
  card a2[100];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a1[i].suit >> a1[i].value;
    a2[i] = a1[i];
  }

  BubbleSort(a1, n);
  SelectionSort(a2, n);

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << a1[i].suit << a1[i].value;
  } cout << endl;
  cout << "Stable" << endl;

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << a2[i].suit << a2[i].value;
  } cout << endl;
  if (isStable(a1, a2, n))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;

  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 18500000
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

bool flag(int x)
{
    int arr[5], i=4;
    while (x) {
        arr[i--]=x%10;
        x/=10;
    }
    if (arr[0]==arr[4] && arr[1]==arr[3]) return true;
    return false;
}

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int a, b, cnt=0, i;
    cin >> a >> b;
    for (i=a; i<=b; i++) {
        if (flag(i)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3528
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010;
int front[N],nxt[N<<1],to[N<<1],cnt,top,s[N],k[N];
void Add(int u,int v)
{
	to[++cnt]=v;nxt[cnt]=front[u];front[u]=cnt;
}
int dep[N],f[N],tot,n,m,len,U,V;ll ans;
void dfs(int u,int fa)
{
	dep[u]=dep[fa]+1;f[u]=dep[u]&1?1:-1;
	tot+=f[u];
	for(int i=front[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v==fa)continue;
		if(dep[v])len=abs(dep[u]-dep[v])+1,U=u,V=v;
		else dfs(v,u);
	}
}
void dfs2(int u,int fa)
{
	for(int i=front[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v==fa || (U==u && V==v) || (U==v && V==u))continue;
		dfs2(v,u);
		k[u]+=k[v];f[u]+=f[v];
	}
	if(!k[u])ans+=abs(f[u]);
	else s[++top]=k[u]*f[u];
}
int main()
{
	n=gi();m=gi();
	for(int i=1;i<=m;i++)
	{
		int u=gi(),v=gi();
		Add(u,v);Add(v,u);
	}
	dfs(1,1);
	if(m==n-1){if(tot!=0){puts("-1");return 0;}}
	if(len%2)
	{
		if(tot&1){puts("-1");return 0;}
		ans+=abs(tot/2);f[U]-=tot/2;f[V]-=tot/2;
	}
	else
	{
		if(tot){puts("-1");return 0;}
		k[U]=1,k[V]=-1;
	}
	dfs2(1,1);
	s[++top]=0;
	sort(s+1,s+top+1);
	for(int i=1;i<=top;i++)ans+=abs(s[i]-s[(top+1)/2]);
	printf("%lld\n",ans);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int p[6],q[6];

double calc(double x){
    double ret=0.0;
    rep(i,6)ret+=max(x*p[i],(1-x)*q[i]);
    return ret;
}

signed main(){
    rep(i,6)cin>>p[i];
    rep(i,6)cin>>q[i];


    double l=0,r=1;
    rep(i,10000){
        double m1=(l*2+r)/3;
        double m2=(l+r*2)/3;

        if(calc(m1)>calc(m2))l=m1;
        else r=m2;
    }

    printf("%.20f\n",calc(l)/100);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    string s; cin >> s;

    if(s == "RSR") {
        cout << 1; return 0;
    }
    int cnt = 0;
    for(auto x : s)
        if(x == 'R') cnt++;
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

bool judge(int x) {
  string s;
  while (x) {
    s.push_back(x % 10);
    x /= 10;
  }
  for (int l = 0, r = s.size() - 1; l < r; ++l, --r)
    if (s[l] != s[r]) return false;
  return true;
}

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 0;
  for (int i = a; i <= b; ++i) if (judge(i)) cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int a,b;
    in>>a>>b;
    cout<<6-a-b<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

void run() {
	int n; cin >> n;
	Vi elems(n);

	each(e, elems) {
		cin >> e;
	}

	each(e, elems) {
		int k; cin >> k;
		e -= k;
	}

	ll ans = 0;
	each(e, elems) if (e > 0) ans += e;
	cout << ans << endl;
}


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

int main(){
  set<int> s;

  for (int i = 0; i < 3; i++){
    int insert = 0;
    cin >> insert;
    s.insert(insert);
  }

  cout << s.size() << endl;
}

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


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

  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// dinic法
const ll INF = 1e17;
const ll MAX_V = 103;

struct edge {ll to, cap, rev;};

vector<edge> G[MAX_V]; // グラフの隣接リスト表現
ll level[MAX_V]; // sからの距離
ll iter[MAX_V]; //　どこまで調べ終わったか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(ll from, ll to, ll cap){
	G[from].push_back((edge){to, cap, (ll) G[to].size()});
	G[to].push_back((edge){from, 0, (ll) G[from].size()-1});
}

// sからの最短距離をbfsで計算する
void bfs(ll s){
	memset(level, -1, sizeof(level));
	queue<ll> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		ll v = que.front();
		que.pop();
		rep(i,G[v].size()){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}

	}
}

// 増加パスをdfsで探す
ll dfs(ll v, ll t, ll f){
	if(v == t) return f;
	for(ll &i = iter[v]; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			ll d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// sからtへの最大流を求める
ll max_flow(ll s, ll t){
	ll flow = 0;
	while(true){
		bfs(s);
		if(level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		ll f;
		while((f = dfs(s, t, INF)) > 0){
			flow += f;
		}
	}
}


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

	ll n;
	cin >> n;

	ll a[n];
	rep(i,n) cin >> a[i];

	ll s = n;
	ll t = n + 1;

	ll sum = 0;
	rep(i,n) sum += max(0LL,a[i]);
	
	rep(i,n){
		if(a[i] <= 0) add_edge(s,i,abs(a[i]));
		else add_edge(i,t,abs(a[i]));
	}

	rep(i,n){
		for(ll j = 2*(i+1); j <= n; j+=i+1){
			ll b = j-1;
			add_edge(i,b,INF);
		} 
	}
	
	cout << (sum - max_flow(s,t)) << endl;
	
}

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

using namespace std;
 
int main(void){
	
	string s, t;
	
	cin >> s >> t;
	
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	if(s >= t)
		cout << "No";
	else
		cout << "Yes";
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;


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

	if (X < 600) {
		cout << 8 << endl;
	}
	else if (X < 800)
	{
		cout << 7 << endl;
	}
	else if (X < 1000)
	{
		cout << 6 << endl;
	}
	else if (X < 1200)
	{
		cout << 5 << endl;
	}
	else if (X < 1400)
	{
		cout << 4 << endl;
	}
	else if (X < 1600)
	{
		cout << 3 << endl;
	}
	else if (X < 1800)
	{
		cout << 2 << endl;
	}
	else if (X < 2000) {
		cout << 1 << endl;
	}

	return 0;
} 

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

using namespace std;

int main() {

	int n,ww;
	cin >> n >> ww;
	vector<int> v(n + 1);
	vector<int> w(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}

	vector<int> dp(ww+1, 0);


	for (int j = 1; j <=ww ; j++) {
		for (int i = 1; i <= n; i++) {

			if (j - w[i] >= 0) {
				dp[j] = max(dp[j],dp[j - w[i]] + v[i]);
			}
		}
	}

	cout << dp[ww] << endl;
	return 0;

}


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

int main(){
  int N;cin>>N;
  int A[N];
  for(int i=0;i<N;i++) cin>>A[i];
  long B[N+1];
  for(int i=0;i<=N;i++) B[i]=0;
  for(int i=0;i<N;i++) B[A[i]]++;
  long count=0;
  for(int j=1;j<=N;j++) count += B[j]*(B[j]-1)/2;
 //コードテスト用 cout<<'N'<<count<<endl;
  for(int i=0;i<N;i++){
    int X=A[i];
    long Y=B[X]-1;
    cout<<count-Y<<endl;
  }
}

Measured memory_bytes: 5964
import java.util.*;
import java.io.*;

//dpによる解法：この前に半分全列挙で解いた

class Med{
	int a, b, c;

	public Med(int a, int b, int c) {
		super();
		this.a = a;
		this.b = b;
		this.c = c;
	}
	
}


public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), ma = fs.nextInt(), mb = fs.nextInt();
		Med ms[] = new Med[n];
		for(int i=0;i<n;i++) {
			int a = fs.nextInt(), b = fs.nextInt(), c = fs.nextInt();
			ms[i] = new Med(a,b,c);
		}
		
		int dp[][][] = new int[n+1][410][410];
		int inf = Integer.MAX_VALUE/2;
		for(int i=0;i<n+1;i++) {
			for(int j=0;j<410;j++)for(int k=0;k<410;k++) dp[i][j][k]=inf;
		}
		dp[0][0][0] = 0;
		for(int i=1;i<n+1;i++) {
			int a = ms[i-1].a, b = ms[i-1].b, c = ms[i-1].c;
			for(int j=0;j<405;j++) {
				for(int k=0;k<405;k++) {
					if(j-a<0||k-b<0) {
						dp[i][j][k] = dp[i-1][j][k];
					}
					else {
						dp[i][j][k] = Math.min(dp[i-1][j][k], dp[i-1][j-a][k-b] + c);
					}
				}
			}
		}
		
		int ans = inf;

		for(int j=0;j<401;j++) {
			for(int k=0;k<401;k++) {
				if(dp[n][j][k]==inf)continue;
				if(j==0&&k==0)continue;
				if(j*mb - k*ma==0) ans = Math.min(ans, dp[n][j][k]);
			}
		}
		if(ans == inf)System.out.println(-1);
		else System.out.println(ans);
		
		
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


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

int main() {
	int q;
	long long n,i,k,j,sum=0,count=0,ans=0,m,a,b,r,p,s;
    cin>>n>>k;
    cin>>r>>s>>p;
    string t,t2;
    cin>>t;
    t2=t;
    for(i=0;i<n;i++)
    {
        if(t[i]=='r')
        t2[i]='p';
        else if(t[i]=='p')
        t2[i]='s';
        else
        t2[i]='r';
    }

     for(i=0;i<k;i++)
     {
         if(t2[i]=='r')
         sum+=r;
         else if(t2[i]=='p')
         sum+=p;
         else sum+=s;
        
     }
   
    
      for(i=k;i<n;i++)
      {
          if(t2[i]!=t2[i-k])
          {
                if(t2[i]=='r')
                  sum+=r;
                else if(t2[i]=='p')
                sum+=p;
               else sum+=s;
          }
          else
          {
               if(t2[i]=='r' && ((i+k)<n))
                {
                    if(t2[i+k]=='s')
                    t2[i]='p';
                    else 
                    t2[i]='s';
                }
                else if(t2[i]=='p'&& ((i+k)<n))
               {
                     if(t2[i+k]=='s')
                    t2[i]='r';
                    else
                    t2[i]='s';
               }
               else if(((i+k)<n))
               {
                   
                     if(t2[i+k]=='p')
                    t2[i]='r';
                    else
                    t2[i]='p';
               }
          }
      }
  
      cout<<sum;
    
    
    
    
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  ll max_pxpy, min_pxpy, max_mxpy, min_mxpy;
  max_pxpy = max_mxpy = INT_MIN;
  min_pxpy = min_mxpy = INT_MAX;
  for (int i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    max_pxpy = max(max_pxpy, x + y);
    min_pxpy = min(min_pxpy, x + y);
    max_mxpy = max(max_mxpy, -x + y);
    min_mxpy = min(min_mxpy, -x + y);
  }
  cout << max(max_pxpy - min_pxpy, max_mxpy - min_mxpy) << endl;
}


Measured memory_bytes: 3620
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    dic = {}
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        key, value = input().split()
        dic[key] = value

    ret = ''

    m = int(input())
    for i in range(m):
        s = input().split()[0]
        ret += dic.get(s, s)

    print(ret)

Measured memory_bytes: 7172
#include<iostream>

using namespace std;

int main(void)
{
  long long int n; cin>>n;
  long long int sum=0;
  
  for(int i=1;i<=n;i++){
    if((i%5==0)||(i%3==0)){;}
    else{sum+=i;}
  }
  
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

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

        int[] sum = new int[n];

        for (int i = 0; i < n; i++) {
            sum[i] = 2 * scanner.nextInt();
        }

        long[] res = new long[n];

        long totalSum = 0;

        int mul = 1;

        for (int i = 1; i < sum.length; i++) {
            totalSum += sum[i] * mul;
            mul *= -1;
        }

        long first = (sum[0] - totalSum) / 2;

        res[0] = first;

        for (int i = 1; i < sum.length; i++) {
            res[i] = sum[i - 1] - res[i - 1];
        }

        for (int i = 0; i < res.length; i++) {
            System.out.print(res[i] + " ");
        }
    }
}

Measured memory_bytes: 64336
function main(input) {
  const args = input.split(" ");
  const N = parseInt(args[0]);  
  const A = parseInt(args[1]);  
  const B = parseInt(args[2]);  
  const max = Math.min(A, B);
  const min = Math.max(0, ((A+B) - N));
  console.log(`${max} ${min}`)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import numpy as np
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

d = {b"U": 0, b"R": 1, b"D": 2, b"L": 3}


def f(x):
    if x in d.keys():
        return d[x]
    return int(x) - 100000


INF = 10 ** 18
n = int(readline())
inp = np.array(list(map(f, read().split())), np.int64)
x = inp[::3]
y = inp[1::3]
u = inp[2::3]


def ur(x, y, u):
    UX = x[u == 0]
    UY = y[u == 0]
    RX = x[u == 1]
    RY = y[u == 1]

    dct = defaultdict(list)
    for ex, ey in zip(UX, UY):
        dct[ex+ey].append([ey, 0])
    for ex, ey in zip(RX, RY):
        dct[ex+ey].append([ey, 1])

    ret = INF
    for v in dct.values():
        vv = sorted(v)
        for (e1, d1), (e2, d2) in zip(vv, vv[1:]):
            if d1 == 0 and d2 == 1:
                ret = min(ret, (e2 - e1) * 10)

    return ret


def ud(x, y, u):
    UX = x[u == 0]
    UY = y[u == 0]
    DX = x[u == 2]
    DY = y[u == 2]

    dct = defaultdict(list)
    for ex, ey in zip(UX, UY):
        dct[ex].append([ey, 0])
    for ex, ey in zip(DX, DY):
        dct[ex].append([ey, 2])

    ret = INF
    for v in dct.values():
        vv = sorted(v)
        for (e1, d1), (e2, d2) in zip(vv, vv[1:]):
            if d1 == 0 and d2 == 2:
                ret = min(ret, (e2 - e1) * 5)

    return ret


def rotate(x, y, u):
    x, y = y, -x
    u = (u + 1) % 4
    return x, y, u


ans = INF
for _ in range(4):
    ans = min(ans, ur(x, y, u), ud(x, y, u))
    x, y, u = rotate(x, y, u)

if ans == INF:
    print("SAFE")
else:
    print(ans)


Measured memory_bytes: 107072
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
string S;
int N;
bool is_uniq(const string &T)
{
  map<char, int> cnts;
  for (const auto &val : T)
  {
    cnts[val]++;
    if (cnts[val] >= 2)
    {
      return false;
    }
  }
  return true;
}
int main()
{
  cin >> S;
  N = S.size();
  for (char i = 'a'; i <= 'z'; i++)
  {
    string tmp = S + i;
    if (is_uniq(tmp))
    {
      cout << tmp << endl;
      return 0;
    }
  }
  string result = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  bool ok = false;
  for (int i = 0; i < N; i++)
  {
    
    for (char j = 'a'; j <= 'z'; j++)
    {
      string tmp = S.substr(0, i) + j;

      if (is_uniq(tmp) && S < tmp)
      {

        ok = true;
        result = min(result, tmp);
      }
    }
  }
  if (ok){
    cout << result << endl;
    return 0;
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 pair<int,int> P;

int main(){
  string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
  int k;
  cin >> k;
  k--;
  int n = s.size();
  vector<string> ans;
  string t = "";
  rep(i,n){
    if(s[i]!=','&&s[i]!=' ')t+=s[i];
    if(s[i]==','){
      ans.push_back(t);
      t = "";
    }
  }
  t = "51";
  ans.push_back(t);
  cout << ans[k] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("ip.txt","r",stdin);
  freopen("op.txt","w",stdout);
  #endif
}

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


int main() 
{ 
    fast_io
    go();
    int n;cin>>n;
    if(n%1000==0)
      cout << "0" <<"\n";
    else
    cout << (1000-n%1000) <<"\n";
}

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 3652