akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
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; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  ll sum1 = 0,sum2 = 0, ans1 = 0, ans2 = 0;
  rep(i, 0, n)cin >> a[i];
  rep(i, 0, n){
    //sum1 += a[i];
    if(i%2==0){
      if(sum1+a[i]>0){
        sum1 += a[i];
        continue;
      }
      sum1 += a[i];
      ans1 += abs(1-sum1);
      sum1 = 1;
    }else{
      if(sum1+a[i]<0){
        sum1 += a[i];
        continue;
      }
      sum1 += a[i];
      ans1 += abs(-1-sum1);
      sum1 = -1;
    }
  }
  rep(i, 0, n){
    //sum2 += a[i];
    if(i%2==1){
      if(sum2+a[i]>0){
        sum2 += a[i];
        continue;
      }
      sum2 += a[i];
      ans2 += abs(1-sum2);
      sum2 = 1;
    }else{
      if(sum2+a[i]<0){
        sum2 += a[i];
        continue;
      }
      sum2 += a[i];
      ans2 += abs(-1-sum2);
      sum2 = -1;
    }
  }
  cout << min(ans1,ans2) << endl;
  //cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 3988
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s;
	if(s.size()>9)
	{
		cout << "NO" << endl; return 0;
	}
	int cnt = 0;
	rep(i, s.size() - 1)
	{
		if (s[i] == s[i + 1])
			cnt++;
		if (s[i] == 'K' && s[i + 1] == 'A')
			cnt++;
		if (s[i] == 'I' && s[i + 1] == 'A')
			cnt++;
	}
	if(cnt>0)
	{
		cout << "NO" << endl; return 0;
	}
	
	rep(i, s.size())
	{
		while (s[i] == 'A')
			s.erase(i, 1);
	}
	if (s == "KIHBR")
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
a.sort()
m = a[-1]  # m = max(a)
s = [0]*(m+1)  # インデックスを合わせる
ans = 0
for i in a:
    if s[i] <= 100:  # 2以上なら計算しても意味ない
        for j in range(i, m+1, i):
            s[j] += 1  # sのiの倍数の部分を増やす
# ここで、s[i] == 1なら、自分自身で一度だけ+1されてることと同値なので他の数字と互いに素。
# 逆に2以上なら自分自身と自分の倍数で+1されてるから互いに素ではない。
for k in a:
    if s[k] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 33220
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
int main(){
	int n,k;
	while(cin>>n>>k){
		if(n==0){
			break;
		}

	int d[20]={},cnt[10000]={},c;
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	if(k==2){
	c=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j){
					if(d[j]>=10){
						cnt[c]+=d[i]*100+d[j];
						
					}
				else{
				cnt[c]+=d[i]*10+d[j];
				
				}
				c++;
				}
			}
		}

	}
	if(k==3){
	c=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j){
				for(int k=0;k<n;k++){
					if(i!=k && j!=k){
						if(d[k]>=10){
							if(d[j]>=10){
								cnt[c]=d[i]*10000+d[j]*100+d[k];
							}
							else{
								cnt[c]=d[i]*1000+d[j]*100+d[k];
							}
						}
						else{
							if(d[j]>=10){
								cnt[c]=d[i]*1000+d[j]*10+d[k];
							}
							else{
								cnt[c]=d[i]*100+d[j]*10+d[k];
							}
						}
					c++;
					}

			}
				}
		}

	}
	}
	if(k==4){
	c=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
			if(i!=j){
				for(int k=0;k<n;k++){
				if(i!=k && j!=k){
					for(int l=0;l<n;l++){
						if(i!=l && j!=l && k!=l){
					if(d[l]>=10){
						if(d[k]>=10){
							if(d[j]>=10){
								cnt[c]=d[i]*1000000+d[j]*10000+d[k]*100+d[l];
							}
							else{
								cnt[c]=d[i]*100000+d[j]*10000+d[k]*100+d[l];
							}
						}
						else{
							if(d[j]>=10){
								cnt[c]=d[i]*100000+d[j]*1000+d[k]*100+d[l];
							}
							else{
								cnt[c]=d[i]*10000+d[j]*1000+d[k]*100+d[l];
							}
						}
					}
					else{
						if(d[k]>=10){
							if(d[j]>=10){
								cnt[c]=d[i]*100000+d[j]*1000+d[k]*10+d[l];
							}
							else{
								cnt[c]=d[i]*10000+d[j]*1000+d[k]*10+d[l];
							}
						}
						else{
							if(d[j]>=10){
								cnt[c]=d[i]*10000+d[j]*100+d[k]*10+d[l];
							}
							else{
								cnt[c]=d[i]*1000+d[j]*100+d[k]*10+d[l];
							}
						}
					}
					c++;
				}
					}
				}
				}
			}
			}
			}
		
	}
	sort(cnt,cnt+c+1,greater<int>());
	int ans=0;
	for(int i=0;i<c;i++){
		if(cnt[i]>cnt[i+1]){
				ans++;
		}
	}
	cout<<ans<<endl;
	}
	return 0;
	}

Measured memory_bytes: 1220
import java.util.*;
class Main
{
	public static void main(String[] args) 
    { 	Scanner s=new Scanner(System.in);
         String str = s.nextLine(); 
         StringBuilder input1 = new StringBuilder(); 
          StringBuilder input2 = new StringBuilder(); 
          StringBuilder s3 = new StringBuilder(); 
           StringBuilder s4 = new StringBuilder(); 
          String s1="",s2="";
          int c1,c2;
          int l=str.length();
          s1=str.substring(0,(l-1)/2);
          
         	
        
  
        if (isPalindrome(s1))  
        	c1=1;
            //System.out.print("Yes"); 
        else
        	c1=0;
        
       
          s2=str.substring((l-1)/2 +1,l);
          
        
  
        if (isPalindrome(s2))  
        	c2=1;
            //System.out.print("Yes"); 
        else
        	c2=0;
            //System.out.print("No"); 
 

        if ((isPalindrome(str))  && c1==1 && c2==1 ) 
        	
            System.out.print("Yes"); 
        else
        	System.out.print("No"); 

        	
    } 
    static boolean isPalindrome(String str) 
    { 
  
        // Pointers pointing to the beginning 
        // and the end of the string 
        int i = 0, j = str.length() - 1; 
  
        // While there are characters toc compare 
        while (i < j) { 
  
            // If there is a mismatch 
            if (str.charAt(i) != str.charAt(j)) 
                return false; 
  
            // Increment first pointer and 
            // decrement the other 
            i++; 
            j--; 
        } 
  
        // Given string is a palindrome 
        return true; 
    } 
}


Measured memory_bytes: 23892
a,b,c=map(int,input().split())
num=0
while (a%2==0 and b%2==0 and c%2==0):
  a,b,c=(b//2+c//2),(a//2+c//2),(a//2+b//2)
  num+=1
  if (num>10**7):
    print(-1)
    break
else:
  print(num)

Measured memory_bytes: 40684
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);

$array = str_split($S);
$count = count($array);
$sumL = $sumR = array();

for ($i = 0; $i < $N; $i++) {
	if ($i == 0) {
		$sumL[$i] = 0;
		$sumR[$N - $i - 1] = 0;
	} else {
		if ($array[$i - 1] == "W") {
			$sumL[$i] = $sumL[$i - 1] + 1;
		} else {
			$sumL[$i] = $sumL[$i - 1];
		}
		if ($array[$N - $i] == "E") {
			$sumR[$N - $i - 1] = $sumR[$N - $i] + 1;
		} else {
			$sumR[$N - $i - 1] = $sumR[$N - $i];
		}
	}
}

/* 検証セクション
for ($i = 0; $i < $N; $i++) {
echo $sumL[$i];
}
echo PHP_EOL;
for ($i = 0; $i < $N; $i++) {
echo $sumR[$i];
}
echo PHP_EOL;
 */

$answer = PHP_INT_MAX;

for ($i = 0; $i < $N; $i++) {
	$answer = min($answer, $sumR[$i] + $sumL[$i]);
}

echo $answer;


Measured memory_bytes: 50680
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
long long int gcd(long long int a, long long int b) {
             long long int tmp;
             long long int r = 1;
             if (b > a) {
                           tmp = a;
                           a = b;
                           b = tmp;
             }
             r = a % b;
             while (r != 0) {
 
 
                           a = b;
                           b = r;
                           r = a % b;
 
             }
             return b;
}

const long long int mod=1000000007;
int main(){
	long long int n,m;
	cin>>n>>m;
	if(n%m==0){cout<<-1<<endl;return 0;}
	else{cout<<n<<endl;}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			boolean[][] gem = new boolean[21][21];
			for(int i=0;i<n;i++) {
				gem[sc.nextInt()][sc.nextInt()] = true;
			}
			int m = sc.nextInt();
			int rx = 10;
			int ry = 10;
			int collected = 0;
			if (gem[rx][ry]) {
				collected++;
				gem[rx][ry] = false;
			}
			for(int i=0;i<m;i++) {
				char c = sc.next().charAt(0);
				int step = sc.nextInt();
				int dx = 0,dy = 0;
				switch (c) {
				case 'N':
					dx = 0; dy = 1;
					break;
				case 'E':
					dx = 1; dy = 0;
					break;
				case 'S':
					dx = 0; dy = -1;
					break;
				case 'W':
					dx = -1; dy = 0;
					break;
				}
				for(int j=0;j<step;j++) {
					rx += dx;
					ry += dy;
					if (gem[rx][ry]) {
						collected++;
						gem[rx][ry] = false;
					}
				}
			}
			System.out.println(collected == n ? "Yes" : "No");
		}
	}

}

Measured memory_bytes: 36812
#include <bits/stdc++.h>
#define LL long long
#define lowbit(x) (x & (-x))
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 50 + 5;

int n;
int a[N];

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	int mx = -INF, mn = INF;
	for (int i = 1; i <= n; i++) mx = max(mx, a[i]), mn = min(mn, a[i]);
	if (-mn > mx) {
		int id = 0;
		for (int i = 1; i <= n; i++) if (a[i] == mn) id = i;
		printf("%d\n", 2 * n - 1);
		for (int i = 1; i <= n; i++) printf("%d %d\n", id , i);
		for (int i = n; i >= 2; i--) printf("%d %d\n", i, i - 1);
	} else {
		int id = 0;
		for (int i = 1; i <= n; i++) if (a[i] == mx) id = i;
		printf("%d\n", 2 * n - 1);
		for (int i = 1; i <= n; i++) printf("%d %d\n", id, i);
		for (int i = 1; i < n; i++) printf("%d %d\n", i, i + 1);
	}
	return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())
i = K
while B <=A:
    if i == 0:
        print("No")
        break
    B = B*2
    i -=1
while i >=0:
    if C > B:
        print("Yes")
        break
    elif i == 0:
        print("No")
        break
    else:
        C=C*2
        i -=1

Measured memory_bytes: 9180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int count = 0;
        int temp = i;
        while (temp > 0)
        {
            temp /= 10;
            count++;
        }
        if (count % 2 == 1)
        {
            ans++;
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll L,R;
  cin>>L>>R;
 ll s=2019;
if(L/s!=R/s) {
cout<<0<<endl;
 
return 0;
}
  else if(L%s==0) {
cout<<0<<endl;
    
    return 0;
  }
  
  vector<ll> vec(R-L+1);
  ll A=L%s;
  
  for(ll i=0;i<R-L+1;i++) {
    vec[i]=A+i;
  }
  
  ll ans=2018;
  for(ll i=0;i<R-L;i++) {
for(ll j=i+1;j<R-L+1;j++) {
  ans=min(ans,(vec[i]*vec[j])%s);
}
  }
  
  cout<<ans<<endl;
}

    

  

  
  


Measured memory_bytes: 3592
#!/usr/bin/env python3
#AGC8 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
a = LI()
b = [0] + list(accumulate(a))
c = [max(0,a[i]) for i in range(n)]
c = [0] + list(accumulate(c))
ans = -inf
for i in range(n-k+1):
    tmp = max(b[i+k] - b[i],0)
    tmp += c[i] - c[0]
    tmp += c[-1] - c[i+k]
    ans = max(tmp,ans)
print(ans)


Measured memory_bytes: 74988
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<cmath>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<string> s(n);
    int c1 = 0, c2 = 0, c3 = 0;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        for(int j = 0; j < s[i].size() - 1; j++){
            if(s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
        }
        if(s[i][0] == 'B'){
            if(s[i].back() == 'A'){
                c3++;
            }else{
                c1++;
            }
        }else if(s[i].back() == 'A'){
            c2++;
        }
    }
    if(c1 == 0 && c2 == 0){
        ans += max(0, c3 - 1);
    }else{
        ans += min(c1, c2);
        int t = abs(c1 - c2);
        ans += min(c3, t);
        t = max(0, c3 - t);
        ans += t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N;
    cin >> N;
    vector<ll> H(N);
    bool state = true;
    repi(i, N, 0)
    {
        cin >> H[i];
    }
    repd(i, N - 2, 0)
    {
        if (H.at(i + 1) - H.at(i) < -1)
        {
            puts("No");
            return 0;
        }else if(H.at(i + 1) - H.at(i) < 0){
            H.at(i)--;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int space[100000];

int partition(int *toPart, int p, int r) {
  int x=toPart[r], i=p-1, swap, j;
  for ( j = p; j < r; j++ )
    if ( toPart[j] <= x ) {
      i++;
      swap = toPart[i];
      toPart[i] = toPart[j];
      toPart[j] = swap;
    }
  swap = toPart[i+1];
  toPart[i+1] = toPart[r];
  toPart[r] = swap;
  return i+1;
}

int main(void) {
  int n, i, posn;
  scanf(" %d", &n);
  for ( i = 0; i < n; i++ )
    scanf(" %d", space+i);
  posn = partition(space, 0, n-1);
  for ( i = 0; i < n; i++ ) {
    if ( i == posn )
      printf("[%d]", space[i]);
    else
      printf("%d", space[i]);
    printf("%c", i==n-1 ? '\n' : ' ');
  }
  return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define INFTY 200000000000
long long dp[110][110];
int seen[110][110];
vector<int>ro(110),co(110);
long long ch(int l,int r){
    long long mn = dp[l][r];
    if(r==l) return dp[l][r] = 0;
    if(dp[l][r]!=INFTY) return dp[l][r];
    for (int k = l; k < r; k++)
    {
        long long sum = ch(l,k)+ch(k+1,r)+ro[l]*co[r]*ro[k+1];
        mn = min(mn,sum);
    }  
    return dp[l][r] = mn;
}
int main(){
    int n;cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> ro[i]>>co[i];
    }
    
    for (int i = 0; i < n;i++)
    {
        for(int j=0;j<n;j++){
            dp[i][j] = INFTY;
        }
        }
    long long ans = ch(0,n-1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3180
let readInt () = stdin.ReadLine() |> int

let rec solve addedLast ans list =
    match (addedLast, list) with
    | (true, x :: xx) -> if x % 10 = 0 then solve false (ans + x) xx else solve true (ans + x + (10 - x % 10)) xx
    | (false, x :: xx) -> if x % 10 = 0 then solve false (ans + x) xx else solve true (ans + x) xx
    | (_, []) -> ans

[ 1 .. 5 ]
|> List.map (fun _ -> () |> readInt)
|> List.sortBy (fun x -> x % 10)
|> solve false 0
|> printfn "%d"


Measured memory_bytes: 30272
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  LL ans = 0;
  for (int i = 1; i <= N; ++i)
    ans += ((LL)i * (N - i + 1));
  int a, b;
  for (int i = 0; i < N - 1; ++i)
    {
      cin >> a >> b;
      if (a > b) swap(a, b);
      ans -= ((LL)a * (N - b + 1));
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3580
a = input()
if a=='SUN':
    print(7)
elif a=='MON':
    print(6)
elif a=='TUE':
    print(5)
elif a=="WED":
    print(4)
elif a=="THU":
    print(3)
elif a=="FRI":
    print(2)
elif a=="SAT":
    print(1)


Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;
    if(A==B)
    {
        cout<<"Draw";
    }
    else if (B==1)
    {
    cout<<"Bob";

    }
    else if (A==1)
    {
    cout<<"Alice";
    }
    else if(A>B)
    {
        cout<<"Alice";
    }
    else
    {
        cout<<"Bob";
    }
    
return 0;
    
    
}

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

int main() {
	int n, m, a[100], b[100], kazu[100];

	cin >> n >> m;


	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}

	for (int z = 0; z <= n; z++) {
		kazu[z] = 0;
	}

	for (int k = 0; k < m; k++) {
		for (int z = 1; z <= n; z++) {
			if (a[k] == z||b[k]==z)
				kazu[z]++;
		}
	}

	for (int k = 1; k <= n; k++) {
		cout << kazu[k] << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int N;
    int c = 0;
    int k;
    string S;
    string s;
    
    cin >> N;
    cin >> S;
    
    //cout << N << "\n";
    //cout << S << "\n";
    
    for (int i = 0; i < 1000; i++) {
		s = to_string(i);
		s = string((3-s.size()),'0')+s;
		k = 0;
		//cout << s << "\n";
		for (int m = 0; m < N; m++){
		    char j = S[m];
		    if (j == s[k]){
		        k += 1;
		        if (k == 3){
		            c += 1;
		            break;
		        }
		    }
		    
		}
	}
	cout << c <<"\n";
    
    
    /*
    N = int(input())
    S = input()
    c = 0
    for i in range(1000):
        s = "0"*(3-len(str(i)))+str(i)
        k = 0
        for j in S:
            if j == s[k]:
                k += 1
                if k == 3:
                    c += 1
                    break
    print(c)
    */
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

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

    int x = N % 10;
    if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
        cout << "hon" << endl;
    } else if (x == 0 || x == 1 || x == 6 || x == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	var hs []int
	for i := 0; i < n; i++ {
		var h int
		fmt.Scan(&h)
		hs = append(hs, h)
	}

	cnt := 0
	for _, h := range hs {
		if h < k {
			continue
		}
		cnt++
	}
	fmt.Print(cnt)
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;

string s, t;
    
bool par(string t) {
    for (int i = 0; i < t.size(); i += 2) {
        if (t[i/2] != t[t.size() - 1 - i/2]) return false;
    }
    return true;
}

int main(void){
    cin >> s;
    t = "";
    for (int i = 0; i < s.size(); i++) {
        if (char(s[i]) != 'x') t += s[i];
    }
    
    int ans = 0;
    if (!par(t)) cout << -1 << endl;
    else {
        int x = 0, y = s.size() - 1;
        while (x < y) {
            if (s[x] == s[y]) {x++;  y--;}
            else {
                if (char(s[x]) == 'x') {x++; ans++;}
                else {y--; ans++;}
            }
        }
        cout << ans << endl;
    }
    
    
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=610,Mo=1000000007;
bool w[N],v[N];
int f[N][N/2][N/2];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=='-'?o=-1:0,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return o*x;
}
inline void add(int &x,long long y) {x=(x+y)%Mo;}
int main() {
    int n,s=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
	int x=gi(),y=gi();
	if(min(x,y)==-1) {
	    if(x+y==-2) ++s;
	    else w[x+y+1]=1;
	}
	else v[x]=v[y]=1;
    }
    f[n+n][0][0]=1;
    for(int i=n+n;i;i--) {
	if(v[i]) memcpy(f[i-1],f[i],sizeof(f[i]));
	else {
	    for(int j=0;j<=n;j++)
		for(int k=0;k<=n;k++) {
		    int t=f[i][j][k];
		    if(t) {
			if(j) add(f[i-1][j-1][k],t);
			if(w[i]) add(f[i-1][j][k+1],t);
			else {
			    add(f[i-1][j+1][k],t);
			    if(k) add(f[i-1][j][k-1],1LL*k*t);
			}
		    }
		}
	}
    }
    n=f[0][0][0];
    for(int i=1;i<=s;i++) n=1LL*n*i%Mo;
    cout<<n;
    return 0;
}

Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> B(111111, 0);
  for (ll i = 0; i < N; i++)
  {
    ll a;
    cin >> a;
    B.at(a)++;
  }

  ll ans = 0;
  for (ll i = 0; i < 111100; i++)
  {
    chmax(ans, B.at(i) + B.at(i + 1) + B.at(i + 2));
  }

  cout << ans << endl;
}

Measured memory_bytes: 1152
def func(x,y):
    global s,h,w
    d = [-1,0,1]
    rv = 0
    for i in d:
        for j in d:
            if i == 0 and j == 0:
                continue
            if x+i >= 0 and x+i < h and y+j >= 0 and y+j < w:
                if s[x+i][y+j] == "#":
                    rv += 1
    return str(rv)

h,w = map(int,input().split())
s = [input() for _ in range(h)]
for i in range(h):
    ans = ""
    for j in range(w):
        if s[i][j] == ".":
            ans += func(i,j)
        else:
            ans += "#"
    print(ans)

Measured memory_bytes: 3064
from math import ceil

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    def is_ok(arg):
    # 条件を満たすかどうか？問題ごとに定義
        B = [int(ceil(a/arg))-1 for a in A]
        #print(arg, B)
        if sum(B) <= K:
            return True
        else:
            return False

    def meguru_bisect(ng, ok):
        '''
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng ok は  とり得る最小の値-1 とり得る最大の値+1
        最大最小が逆の場合はよしなにひっくり返す
        '''
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    ans = meguru_bisect(0, int(1e20))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 178028
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a = 0;
  if(s[0] == 'R') a++;
  if(s[1] == 'R') a++;
  if(s[2] == 'R') a++;
  if(a == 2 && s[1] == 'S') a--;
  cout << a << "\n";
}


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

int main(){
  int n;
  cin >> n;
  vector<int> vc(n);
  for (int i=0;i<n;i++){
    cin >> vc.at(i);
  }

  sort(vc.begin(), vc.end());
  int ans = 0;
  int a, b, c;
  for (int i=0;i<n-2;i++){
    for (int j=i+1;j<n-1;j++){
      for (int k=j+1;k<n;k++){
        a = vc.at(i);
        b = vc.at(j);
        c = vc.at(k);
        if (a+b <= c)break;
        else if (c<(b+c)){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = 998244353;//1e9+7

vector<int> cnt[201],sp;

void pre() {

}

void solve() {
  int n,q;  cin>>n;
  ll s = 0;
  map<ll,int> cnt;
  rep(i,n)  {
    ll x;
    cin>>x;
    cnt[x]++;
    s += x;
  }
  cin>>q;
  rep(i,q) {
    ll x,y;  cin>>x>>y;
    s += cnt[x]*(y-x);
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout<<s<<'\n';
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 9464
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args){
		new Main().run();
	}
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int A=sc.nextInt();
		int ans=0;
		while(H-A*ans>0)++ans;
		System.out.println(ans);
	}
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


Measured memory_bytes: 23252
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <stack>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <string.h>
#include <set>
using namespace std;

struct Node {
	int next;
	int color;
};


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		printf("%d\n", (n - 1)*(m - 1));
	}
	return 0;
	
}

Measured memory_bytes: 256
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

vector<int> v[N];

int main()
{
	int n,m;

	scn(n); scn(m);

	int h[n+1];

	rep(i,1,n+1)
	scn(h[i]);

	rep(i,0,m)
	{
		int a,b;

		scn(a); scn(b);

		v[a].pb(b); v[b].pb(a);
	}

	int ans=0;

	rep(i,1,n+1)
	{
		int flag=1;

		for(int it:v[i])
		if(h[it]>=h[i])
		flag=0;

		//cout<<i<<" "<<flag<<endl;

		if(flag)
		ans++;
	}

	pri(ans);

    return 0;
}

Measured memory_bytes: 9336
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
from fractions import gcd
l= a[0]
ans = 1
for i in range(1, n):
    g = gcd(l,a[i])
    l = (l * a[i]) // g
    ans = (ans*a[i]//g +  l//a[i]) %mod
print(ans)


Measured memory_bytes: 5612
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}

	int sum = 0;
	for (int i = 0; i < n; i++) {
		
		for (int j = i+1; j < n; j++) {
			
			sum += d[i] * d[j];
		}
		
	}
	cout << sum << endl;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		int K = sc.nextInt();
		sc.nextLine();
		int sum = 0;
		for (int i = 0; i < N; i++) {
			int xi = sc.nextInt();
			int total1 = (xi * 2);
			int total2 = 0;
			if (K - xi < 0) {
				total2 = ((xi - K) * 2);
			} else {
				total2 = ((K - xi) * 2);
			}
			if (total2 < total1) {
				sum += total2;
			} else {
				sum += total1;
			}
		}
		sc.close();
		System.out.println(sum);
	}
}

Measured memory_bytes: 23636
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<28)

int N, B[64], C[64];
string A[64], D[64][64];
int g[64][64], dig[64];
int vis[64], use[64], conf[64];
vector<pair<int, int> > que;

void coll(int at) {
    if (vis[at]) return ;
    vis[at] = 1;
    que.push_back(mp(dig[at], at));
    rep (i, N) if (g[at][i]) coll(i);
}

int rec(int ix) {
    if (ix == -1) return 0;
    for (int i = ix+1; i < (int)que.size(); i++) {
        const int x = que[i].second;
        if (use[x] == 0 && conf[x] == 0) {
            bool some = false;
            rep (j, ix+1) {
                const int y = que[j].second;
                if (g[x][y]) some = true;
            }
            if (some == false) return -INF;
        }
    }
    const int at = que[ix].second;
    int ans = -INF;
    if (conf[at] == 0) {
        rep (i, N) if (g[at][i]) conf[i]++;
        use[at] = 1;
        ans = max(ans, rec(ix-1) + B[at]);
        rep (i, N) if (g[at][i]) conf[i]--;
        use[at] = 0;
    }
    if (at != 0) ans = max(ans, rec(ix-1));
    return ans;
}

int solve() {
    rep (i, N) dig[i] = C[i];
    memset(use, 0, sizeof(use));
    memset(conf, 0, sizeof(conf));
    memset(vis, 0, sizeof(vis));
    int ans = 0;
    rep (i, N) if (vis[i] == 0) {
        que.clear();
        coll(i);
        sort(que.begin(), que.end());
        ans += rec(que.size()-1);
    }
    return ans;
}

int main() {
    for (;;) {
        cin >> N;
        if (N == 0) return 0;
        map<string, int> of;
        rep (i, N) {
            cin >> A[i] >> B[i] >> C[i];
            of[A[i]] = i;
            rep (j, C[i]) cin >> D[i][j];
        }
        memset(g, 0, sizeof(g));
        rep (i, N) rep (j, C[i]) g[i][of[D[i][j]]] = 1;
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 1380
a = gets.split.map(&:to_i) 
S = 0
n = 0
if a[3] > a[0]
  S += a[0]
  n = a[3] - a[0]
  if n <= a[1]
    puts S
  else
    puts S - (n - a[1])
  end
else 
  puts a[3]
end

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, j, k, ans=0, r[10000]={0}, g[10000]={0}, b[10000]={0};
    string s;
    cin >> n >> s;
    for(i=1;i<=n;i++){
        r[i]=r[i-1];g[i]=g[i-1];b[i]=b[i-1];
        if(s[i-1]=='R') r[i]++;
        else if(s[i-1]=='G') g[i]++;
        else b[i]++;
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')) {
                ans+=b[n]-b[j+1];
              if(2*j-i<n){
                if(s.at(2*j-i)=='B') ans--;
              }
            }
            else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')) {
                ans+=g[n]-g[j+1];
              if(2*j-i<n){
                if(s.at(2*j-i)=='G') ans--;
              }
            }
            else if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G')) {
                ans+=r[n]-r[j+1];
              if(2*j-i<n){
                if(s.at(2*j-i)=='R') ans--;
              }
            }
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 3832
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
vector<int> v[2*maxn];
bool vis[2*maxn];
vector<int> aux;
vector<int> temp;
vector<int> z;
int pos=0;
void dfs(int node)
{
    if(vis[node])
    {
        pos=node;
        return;
    }
    vis[node]=true;
    aux.pb(node);
    dfs(v[node][0]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,x=0;lli k=0ll;
    cin>>n>>k;
    for(int i=0;i<n;++i)
    {
        cin>>x;
        --x;
        v[i].pb(x);
    }
    dfs(0);
    vector<int>:: iterator xx;
    for(auto i=aux.begin();i!=aux.end();++i)
    {
        if(*i!=pos)
            temp.pb(*i);
        else
        {
            xx=i;
            break;
        }
    }
    if(k<(int)temp.size())
    {
        cout<<temp[k]+1<<endl;
        return 0;
    }
/* for(auto i: aux)
    {
        cout<<i<<endl;
    }*/
    k-=(int)(temp.size());
    for(auto i=xx;i!=aux.end();++i)
        z.pb(*i);
    lli sz=z.size();
    //cout<<sz<<endl;
    int r=k%sz;
    //cout<<r<<endl;
    cout<<(z[r]+1)<<endl;
}

Measured memory_bytes: 22924
N = int(input())
A = []
for i in range(N):
    A.append([i+1, int(input())])

flag = False
cnt = 0
b, new = A[0]
for i in range(2*N):
    if b == 2:
        flag = True
        break

    cnt += 1
    b, new = A[new-1]

if flag:
    print(cnt)
else:
    print(-1)



Measured memory_bytes: 19572
#include <stdio.h>

int main(void)
{
	char str[3][4];
	int i, f;
	
	while (scanf("%s", str[0]), str[0][0] != '0'){
		scanf("%s", str[1]);
		scanf("%s", str[2]);
		
		f = 0;
		
		for (i = 0; i < 3; i++){
			if (str[i][0] != '+' && str[i][0] == str[i][1] && str[i][0] == str[i][2]){
				printf("%c\n", str[i][0]);
				f = 1;
				break;
			}
			else if (str[0][i] != '+' && str[0][i] == str[1][i] && str[1][i] == str[2][i]){
				printf("%c\n", str[0][i]);
				f = 1;
				break;
			}
			else if (str[1][1] != '+' && ((str[0][0] == str[1][1] && str[1][1] == str[2][2]) || (str[0][2] == str[1][1] && str[1][1] == str[2][0]))){
				printf("%c\n", str[1][1]);
				f = 1;
				break;
			}
		}
		
		if (!f){
			printf("NA\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 548
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//222
	ll n,p;
	cin>>n>>p;
	if(n>40||p==1){cout<<1;return;}
	if(n==1){cout<<p;return;}
	ll mx = 1;
	for(ll i=1;i<=p;i++) {
		ll val = pow(i,n);
		if(val>p||val<0)break;
		if(p%val==0){
			mx=i;
		}
	}
	cout<<mx;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	int n, a, b;
	std::cin >> n >> a >> b;
	int flag = 0;
	for(int i=0;i<100000;i++){
		if (a == 1 && b == 2) {
			std::cout << "Borys" << std::endl;
			flag = 1;
			break;
		}
		if (a == n - 2 && b == n) {
			std::cout << "Alice" << std::endl;
			flag = 1;
			break;
		}
		if (b != a + 1) {
			a++;
		}
		else {
			a--;
			if (a == 1) {
				std::cout << "Borys" << std::endl;
				flag = 1;
				break;
			}
		}
		if (a != b - 1) {
			b--;
		}
		else {
			b++;
			if (b == n) {
				std::cout << "Alice" << std::endl;
				flag = 1;
				break;
			}
		}
	}
	if (flag == 0) {
		std::cout << "Draw" << std::endl;
	}
	return 0;
}

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

vector<char> output;

int main()
{
    long long int input;
    scanf("%lld", &input);

    int tmp;
    char c;
    for (input = input - 1; input >= 26; input--) {
        tmp = ((int)(input % 26)) + 97;
        c = (char)tmp;
        output.push_back(c);
        input = input / 26;
    }
    tmp = ((int)(input % 26)) + 97;
    c = (char)tmp;
    output.push_back(c);

    for (int i = output.size() - 1; i >= 0; i--)
        printf("%c", output[i]);
    printf("\n");

    return 0;
}

Measured memory_bytes: 3776
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	int A = a, B = b;
	P p[100];
	int cnt = 0;
	while (1) {
		p[cnt] = { a,b };
		cnt++;
		if (cnt % 2 == 1) {
			a = a - b;
		}
		else {
			b = a + b;
		}
		if (A == a && B == b) {
			break;
		}
	}
	cout << p[n % cnt].first << " " << p[n % cnt].second << endl;

	return 0;
}



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

int main(){
    string S;
    cin >> S;
    
    ll size = S.size();
    ll ans = 0;
    
    for(ll i = 1; i < size; i++){
        if(S[i] == S[i-1]){
            ans++;
            if(S[i-1] == '0') S[i] = '1';
            else S[i] = '0';
        }
    }

    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 512
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B = I()
if A%3 == 0 or B%3 == 0 or (A+B)%3 == 0:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 77508
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

const long MOD = 1_000_000_007;

void main(){
	int n = readln.chomp.to!int;
	long[] xs = readln.chomp.split.map!(to!long).array;
	
	BigInt ans = BigInt(1);
	
	int count = 0;
	for(int i = 1; i <= n; i ++){
		if(xs[i - 1] < 2 * (i - count) - 1){
			ans *= (i - count);
			ans %= MOD;
			count += 1;
			}
		}
	for(int i = 1; i <= n - count; i ++){
		ans *= i;
		ans %= MOD;
		}
	
	ans.writeln;
	}

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

ll n, c;

ll solve(vector<ll> &x, vector<ll> &v){
    vector<ll> maxR(n);
    maxR[0] = max(v[0] - x[0] * 2, 0LL);
    ll sum = v[0];
    for(int i = 1; i < n; ++i){
        sum += v[i];
        maxR[i] = max(maxR[i-1], sum - 2 * x[i]);
    }
    ll res = 0, sumL = 0;
    for(int i = n-1; i > 0; --i){
        sumL += v[i];
        chmax(res, sumL - (c - x[i]) + maxR[i-1]);
    }
    sumL += v[0];
    chmax(res, sum - x[n-1]);
    chmax(res, sum - c + x[0]);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> c;
    vector<ll> x(n), v(n);
    rep(i,n) cin >> x[i] >> v[i];
    ll ans = solve(x, v);
    reverse(x.begin(), x.end());
    rep(i,n) x[i] = c - x[i];
    reverse(v.begin(), v.end());
    chmax(ans, solve(x, v));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5576
n = gets.to_i
time = 0
pos = 0,0
f = false
n.times do
    #移動先
    t, x, y = gets.split.map(&:to_i)
    #可能な移動
    even = 0
    x_step = []
    while (pos[0]-x).abs + even <= t-time do
        x_step << (pos[0]-x).abs + even
        even+=2
    end
    even = 0
    y_step = []
    while (pos[1]-y).abs + even <= t-time do
        y_step << (pos[1]-y).abs + even
        even+=2
    end
    #移動できるか
    f = false
    x_step.each{ |x|
        y_step.each{ |y|
            if (x+y)==(t-time)
                f = true
                break
            end
        }
    }
    #移動
    time = t
    pos = x,y
    if !f
        puts 'No'
        break
    end
end
puts 'Yes' if f

Measured memory_bytes: 3836
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int sum = 0, max = 0, small = 2 << 20;
        int point;
        rep(i,n){
            cin >> point;
            sum+= point;
            if(max < point) max = point;
            if(small > point) small = point;
        }
        cout << (sum - (max + small) ) / (n - 2) << endl;
    }
}

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

//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return ans;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> d(N);
	ll dmax = 0;
	rep(i,N){
		cin >> d[i];
		dmax = max(dmax, d[i]);
		if(i != 0 && d[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	
	map<ll,ll> count;
	
	rep(i,N){
		count[d[i]]++;
	}
	
	bool exist = true;
	rep(i,dmax+1){
		if(count[i] == 0) exist = false;
	}
	
	if(!exist){
		cout << 0 << endl;
		return 0;
	}
	
	ll ans = 1;
	
	REP(i,dmax-1){
		ans *= mpow(count[i], count[i+1]);
		ans %= M;
	}
	
	cout << ans<< endl;
	
	return 0;
}



Measured memory_bytes: 7296
#include <stdio.h>
#include <string.h>

int main() {
  int number_n, i, j, flag = 0;
  scanf("%d", &number_n);
  char str[number_n+1][11];
  for(i = 0; i < number_n; i++) scanf("%s", str[i]);
  for(i = 1; i < number_n; i++) {

    for(j = 0; j < i; j++) {
      if(strcmp(str[i], str[j]) == 0) {
        printf("No\n");
        flag = -1;
        break;
      }
    }
    if(flag == -1) break;
    if(str[i][0] != str[i-1][strlen(str[i-1])-1]) {
      printf("No\n");
      break;
    }
  }
  if(i == number_n) printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int a, b;
  cin >> a >> b;
  cout << max(a-b, 0) << endl;
}

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream&os, const pair<t,u>&p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream&operator <<(ostream&os,const vc<t>&v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	string s;cin>>s;
	
	int ans=0;
	rep(i,n)if(s[i]=='.'){
		string t=s;
		t[i]='W';
		
		int cnt[2]{};
		rep(k,2){
			int cur=-1;
			for(auto c:t){
				if(c=='.')cur=-1;
				else if(c=='W'){
					if(cur>=0)cnt[k]+=cur;
					cur=0;
				}else if(c=='B'){
					if(cur>=0)cur++;
				}
			}
			for(auto&c:t)
				if(c!='.')c='W'+'B'-c;
		}
		
		if(cnt[1]==0)
			chmax(ans,cnt[0]);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())

D = [0] * (N + 1)
for i in range(1, N + 1):
    j = 1
    while j * i <= N:
        D[j * i] += 1
        j += 1
S = 0
for i in range(1, N + 1):
    S += i * D[i]
print(S)

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

int main(){
  int a, b, i;
  cin >> a >> b;
  for(i=1; i<=1001; i++){
    int j =i*8 / 100;
    int k =  i /10 ;
    if( j == a && k == b)
       break;
  }
if(i != 1002)
  cout << i << endl;
  else cout << "-1" << endl;
}

Measured memory_bytes: 256