akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    string s;
    while(cin>>s){
        for(int i=0;i<s.size();i++){
            if(s[i]==','){
                cout<<" ";
                continue;
            }
            cout<<s[i];
        }
        cout<<endl;
    }
return 0;
}

Measured memory_bytes: 256
/* ex9_1:
    Jun_JPN*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 128
typedef struct{
    int size;       // 格納際代数
    int count;      // 現在のデータ数
    char str[SIZE]; // 文字列
    char *top;      // トップへのポインタ（トップは末尾の要素の1つ上の要素のポインタ）
}stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char bin);
void pop(stack *stk);

int main(void){
    stack stk;
    char str[SIZE];
    int i;

    scanf("%s", str);           // 文字列を受け取る
    initialize_stack(&stk);     // スタックstkを初期化

    for(i=0; str[i] != '\0'; i++){
        if(str[i]=='B') pop(&stk);  // Bが来たらポップ
        else push(&stk, str[i]);    // B以外が来たらプッシュ
    }

    print_stack(&stk);

    return 0;
}

/* スタックを初期化 */
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->str[0] = '\0';
    stk->top = &(stk->str[0]);  // 頭文字のポインタををtopに
}

/* スタックの中身を表示 */
void print_stack(stack *stk){
    for(int i=0; stk->str[i] != '\0'; i++){
        printf("%c", stk->str[i]);
    }
    printf("\n");
}

/* B以外の文字ををプッシュ */
void push(stack *stk, char bin){
    if(stk->count >= stk->size){    // オーバーフロー処理
        printf("Error: stack overflow\n");
        exit(1);
    }else{
        *(stk->top) = bin;  // スタックのトップに文字を加える
        stk->top++;         // スタックのトップを1つ上に
        *(stk->top) = '\0'; // スタックのトップをヌル文字に
        stk->count++;
    }
}

/* Bが来たらポップ
    要素を取り除く＝要素をヌル文字で書き換える */
void pop(stack *stk){
    if(stk->count <= 0){            // アンダーフロー処理
        ;   // 何もしない
    }else{
        stk->top--;         // スタックのトップを1つ下に
        *(stk->top) = '\0'; // スタックのトップをヌル文字に
        stk->count--;
    }
}

Measured memory_bytes: 1648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {   
    int n, a, b; cin >> n >> a >> b;
    cout << min(n*a, b) << ln;
}


Measured memory_bytes: 256
import sys

N, Y = map(int, input().split())
find_ans = False

for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        num = a*10000 + b*5000 + c*1000
        if num == Y:
            print("{} {} {}".format(a, b, c))
            find_ans = True
            sys.exit()

if find_ans == False:
    print('-1 -1 -1')

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

main(){
  int n,q;
  cin>>n;
  vector<int>v(n);
  r(i,n)cin>>v[i];
  cin>>q;
  while(q--){
    int l,r;
    cin>>l>>r;
    reverse(v.begin()+l,v.begin()+r);
  }
  r(i,n){
    if(i)cout<<' ';
    cout<<v[i];
  }
  cout<<endl;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b,c;
	int n;
	cin>>n>>a>>b>>c;
	int ans=0;
	for (int i=0;i<n;i++)
	{
		if (a[i]==b[i] && b[i]==c[i] && a[i]==c[i]) ans+=0;
		else if (a[i]!=b[i] && b[i]!=c[i] && a[i]!=c[i])ans+=2;
		else ans++;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
count=0
for i in range(N):
    for j in range(N):
        atai=0
        for k in range(D):
            atai+=(X[i][k]-X[j][k])**2
        else:
            #print(math.sqrt(atai))
            if math.sqrt(atai)==math.ceil(math.sqrt(atai)):
               count+=1
print((count-N)//2)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

ll mod26(ll n) {
	ll rev = (n) % 26;
	return rev;
}

int main() {
	ll n;
	cin >> n;
	//n = 26 * 26;
	/*for (ll i = 0; i < 1000001; i++) {
		n = i;*/
		vector<ll> ans;
		while (n > 0) {
			ans.push_back(mod26(n));
			n /= 26;
		}
		for (auto itr = ans.begin(); itr != ans.end(); itr++) {
			if (*itr <= 0) {
				if (itr == ans.end() - 1) {
					break;
				}
				*itr += 26;
				*(itr + 1) -= 1;
			}
		}
		for (auto itr = ans.rbegin(); itr != ans.rend(); itr++) {
			if (*itr < 0 || *itr > 26) {
				cout << n << endl;
			}
			if (*itr != 0) {
				cout << char('a' + *itr - 1);
			}
		}
		cout << endl;
	//}

}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <stack>
#include <cmath>
typedef long long ll;
using namespace std;


int a[100003];
int main()
{
    int n; cin>>n;
    stack<int> sta1,sta2;
    int mi=10002,sum0=0,mii,mai,ma=-10002;
	for (int i=1; i<=n; i++) 
	{
		cin>>a[i]; 
		if (a[i]<mi)
		{
			mi=a[i];
			mii=i;
		}
		if (a[i]>ma)
		{
			ma=a[i];
			mai=i;
		}
		if (a[i]>0) 
		{
			sta1.push(a[i]); sum0++;
		}
		else sta2.push(a[i]); 
	}
	
    

	if (n==2)
	{
		cout << abs(a[1]-a[2]) << endl;
		if (a[1]>a[2]) cout << a[1]<<' '<< a[2] << endl;
		else cout << a[2]<<' '<< a[1] << endl;
		return 0;
	}
	
	else if (mi>0)
	{
		int sum=0; 
		for (int i=1; i<=n; i++) sum+=abs(a[i]);
		sum-=2*mi;
		cout << sum << endl;		
	}
	else if (ma<=0)
	{
		int sum=0;
		for (int i=1; i<=n; i++) sum+=abs(a[i]);
		sum+=2*ma;
		cout << sum << endl;
	}
	else 
	{
		int sum=0; 
		for (int i=1; i<=n; i++) sum+=abs(a[i]);
		cout << sum << endl;
	}
	
	
	int che=0;
	if (sta1.empty()) 
	{
		while(!sta2.empty()) sta2.pop(); 
		if (mai==1) 
		{
			cout << a[1] <<' '<< a[2] << endl;
		    a[1]=a[1]-a[2];
			for (int i=1; i<=n; i++)
			    if (i!=2&&i!=1) sta2.push(a[i]);
			sta1.push(a[1]);
			sum0=1;
		}
		else 
		{
			cout << ma <<' '<< a[1] << endl;
		    a[mai]=a[mai]-a[1];
		    for (int i=2; i<=n; i++)
		        if (i!=mai) sta2.push(a[i]);
		    sta1.push(a[mai]);
		    sum0=1;
		}

	}
	
	
	if(sta2.empty())
	{
		while(!sta1.empty()) sta1.pop(); 
		if (mii==1) 
		{
			cout << a[1] <<' '<< a[2] << endl;
		    a[1]=a[1]-a[2];
			for (int i=1; i<=n; i++)
			    if (i!=2&&i!=1) sta1.push(a[i]);
			sta2.push(a[1]);
			sum0-=2;
		}
		else 
		{
			cout << mi <<' '<< a[1] << endl;
		    a[mii]=a[mii]-a[1];
		    for (int i=2; i<=n; i++)
		        if (i!=mii) sta1.push(a[i]);
		    sta2.push(a[mii]);
		    sum0-=2;
		}
	} 
	while(sum0>1)
	{
		cout << sta2.top() << ' ' << sta1.top() << endl;
		int x=sta2.top()-sta1.top();
		sta1.pop(); sta2.pop();
		sta2.push(x);
		sum0--;
	}
	while(!sta2.empty())
	{
	    cout << sta1.top() << ' ' << sta2.top() << endl;
		int x=sta1.top()-sta2.top();
		sta1.pop(); sta2.pop();
		sta1.push(x);
	}
 } 

Measured memory_bytes: 2636
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int n; cin >> n;
  cout << pow(n, 3) << endl;
}


Measured memory_bytes: 384
import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		HashMap<Integer,Integer> states = new HashMap<Integer,Integer>(65536);
		int diff[] = new int[4096];
		int diff0[] = new int[4096];
		try {
			for(;;){
				buf = br.readLine();
				if(buf == null){
					break;
				}
				Scanner scanner = new Scanner(buf);
				if(!scanner.hasNext()){
					break;
				}
				int i, k;
				int initState = 0;
				int cMap, p0x, p0y, dLen, d0Len, d0Index;
				for(i = 0; i < 8; i++){
					initState |= scanner.nextByte() << (i * 3);
				}
				states.put(initState, 0);
				diff[0] = initState;
				dLen = 1;
				for(i = 0; ; i++){
					if(states.containsKey(0xFAC688)){
						System.out.println(states.get(0xFAC688));
						break;
					}
					System.arraycopy(diff, 0, diff0, 0, d0Len = dLen);
					dLen = 0;
					for(d0Index = 0; d0Index < d0Len; d0Index++){
						cMap = diff0[d0Index];
						p0x = 0;
						p0y = 0;
						for(k = 0; k < 8; k++){
							if(((cMap >>> (k * 3)) & 7) == 0){
								p0x = k % 4;
								p0y = k / 4;
								break;
							}
						}
						if(p0y == 1){
							if(states.putIfAbsent(k = Main.getExchanged(cMap, p0x, 0, p0x, 1), i+1) == null){
								diff[dLen++] = k;
							}
						} else{
							if(states.putIfAbsent(k = Main.getExchanged(cMap, p0x, 0, p0x, 1), i+1) == null){
								diff[dLen++] = k;
							}
						}
						if(p0x != 3){
							if(states.putIfAbsent(k = Main.getExchanged(cMap, p0x, p0y, p0x + 1, p0y), i+1) == null){
								diff[dLen++] = k;
							}
						}
						if(p0x != 0){
							if(states.putIfAbsent(k = Main.getExchanged(cMap, p0x, p0y, p0x - 1, p0y), i+1) == null){
								diff[dLen++] = k;
							}
						}
					}
				}
				states.clear();
				dLen = 0;
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
	public static int getExchanged(int org, int px, int py, int qx, int qy){
		int p, q;
		p = ((org >>> ((py * 4 + px) * 3)) & 7);
		q = ((org >>> ((qy * 4 + qx) * 3)) & 7);
		org &= ~(7 << ((py * 4 + px) * 3));
		org |= q << ((py * 4 + px) * 3);
		org &= ~(7 << ((qy * 4 + qx) * 3));
		org |= p << ((qy * 4 + qx) * 3);
		return org;
	}
	public static void printMap(int map){
		int i;
		System.out.println(Integer.toHexString(map));
		for(i = 0; i < 4; i++){
			System.out.print(((map >>> (i * 3)) & 7) + " ");
		}
		System.out.println();
		for(i = 4; i < 8; i++){
			System.out.print(((map >>> (i * 3)) & 7) + " ");
		}
		System.out.println();
		System.out.println();
	}
}

Measured memory_bytes: 290324
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 100010;

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

    string s;
    cin >> s;
    long long dp[N][13] = {};
    dp[0][0] = 1;

    reverse(s.begin(), s.end());

    int n = s.size();
    long long base = 1;
    for(int i = 0; i < n; i++){
        if(s[i] == '?'){
            for(int j = 0; j < 13; j++){
                int ii = i + 1;
                for(int d = 0; d < 10; d++){
                    int ji = (j + d * base) % 13;
                    dp[ii][ji] = (dp[ii][ji] + dp[i][j]) % MOD;
                }
            }
        }else{
            int snum = int(s[i] - '0');
            for(int j = 0; j < 13; j++){
                int ii = i + 1;
                int ji = (j + snum * base) % 13;
                dp[ii][ji] = (dp[ii][ji] + dp[i][j]) % MOD;
            }
        }
        base = base * 10 % 13;
    }

    cout << dp[n][5] << endl;

    return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto& it:a) cin>>it;
    sort(a.rbegin(),a.rend());
    ll sum=a[0];
    int rem=n-2;
    for(int i=1;i<n&&rem;i++){
        if(rem){
            sum+=a[i];
            rem--;
        }
        if(rem){
            sum+=a[i];
            rem--;
        }
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 4024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    char c; cin >> c;
    if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') out("vowel");
    else out("consonant");

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a, b, c;
	cin >> a >> b >> c;
	cout << (a+b+c >= 22 ? "bust" : "win") << endl;
}



Measured memory_bytes: 256
N, W = map(int, input().split())
w_list = [0]
v_list = [0]

for i in range(N):
    w, v = map(int, input().split())
    w_list.append(w)
    v_list.append(v)
    
dp = [[0] * (W + 1) for i in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dp[i][j] = dp[i - 1][j]
        if j - w_list[i] >= 0:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w_list[i]] + v_list[i])
        
print(dp[N][W])

Measured memory_bytes: 120172
#include <stdio.h>

int main(void){
  int K;
  scanf("%d",&K);
  int N = (K+1)/2;
  if(N%2 == 1){
    N++;
  }
  if(K == 1){
    printf("1\n1\n");
    return 0;
  }
  int data[N][N];

  for(int r = 0;r<N;r++){
    for(int c = 0;c<N;c++){
      if(r%2 == 0){
        data[r][c] = (r-c+N)%N;
      }else{
        data[r][c] = N+(r-c+N)%N;
      }
      if(data[r][c]>=K){
        data[r][c] -= N;
      }
    }
  }

  printf("%d\n",N);
  for(int r = 0;r<N;r++){
    for(int c = 0;c<N;c++){
      printf("%d",data[r][c]+1);
      if(c != N-1){
        printf(" ");
      }
    }
    printf("\n");
  }

  return 0;
}

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

int x,y;

int main(){
     cin >> x >> y;
     long long ans = 0;
     if(x == 1){
     	ans += 300000;
     }
     if(x == 2){
   		ans += 200000;  
     }
     if(x == 3){
     	ans += 100000;	
     }
     if(y == 1){
     	ans += 300000;	
     }
     if(y == 2){
     	ans += 200000;	
     }
     if(y == 3){
      	ans += 100000;
     }
     if(x == 1 && y == 1) ans += 400000;
     cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    print_ans(a <= c && c <= b);
    return 0;
}


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

int N;

int digit_sum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    cin >> N;

    int S_N = digit_sum(N);
    if (N % S_N == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import math
for i in range(int(raw_input())):
    x1, y1, x2, y2, x3, y3 = map(float,raw_input().split())
    px = ((y1-y3)*(y1**2 -y2**2 +x1**2 -x2**2) -(y1-y2)*(y1**2 -y3**2 +x1**2 -x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3))
    py = ((x1-x3)*(x1**2 -x2**2 +y1**2 -y2**2) -(x1-x2)*(x1**2 -x3**2 +y1**2 -y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3))
    r = math.sqrt((x1-px)**2 + (y1-py)**2)
    print "%.3f %.3f %.3f" % (px, py, r)

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

int main() {
    int N, min = 0, num = 0, i, w = 0, e = 0;
    char ch;
    cin >> N;
    for (i = 0; i < N; ++i) {
        cin >> ch;
        if (ch == 'W') {
            w++;
        } else if (w != 0 && ch == 'E') {

            w--;
            num++;
        }
    }


    cout << num;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

MOD = 10**9 + 7

result = 0
for ki in range(k, n+2):
   first = ki * (ki - 1) / 2
   final = (2*n - ki + 1) * ki / 2
   add = final - first + 1
   result = (result + add) % MOD

print(int(result))


Measured memory_bytes: 9160
#include <cstdio>

#define NR 101000

bool vis[100];
int n, a[NR];

int main() {
	scanf("%d", &n);

	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		sum ^= a[i];
	}

	for (int i = 1; i <= n; ++i) {
		int w = a[i] ^ (a[i] - 1);
		for (int d = 1; d < 31; ++d)
			if ((1 << d) - 1 == w)
				vis[d - 1] = true;
	}

	int ans = 0;
	for (int d = 30; d >= 0; --d) {
		if (sum >> d & 1) {
			if (!vis[d]) {
				puts("-1");
				return 0;
			} else {
				sum ^= (1 << (d + 1)) - 1;
				++ans;
			}
		}
	}

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

	return 0;
}


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

#define ALL(x) (x).begin(), (x).end()

typedef struct{int x,y;}Point;
Point p1,p2;
int grid[8][8];
char ans[8][8];

bool Put(Point p){
	if(grid[p.y][p.x])return false;

	for(int dx=-1; dx<=1; dx++){
		for(int dy=-1; dy<=1; dy++){
			for(int d=0;d<8;d++){
				int nX=p.x+(d*dx), nY=p.y+(d*dy);
				if(nX<0||nY<0||nX>=8||nY>=8)continue;

				grid[nY][nX]=true;
			}
		}
	}
	return true;
}

int main(){
	int n;	cin>>n;
	vector<Point> init(n);
	for(int i=0;i<n;i++){
		cin>>init[i].y>>init[i].x;
	}

	for(int i=0;i<8;i++)for(int j=0;j<8;j++)ans[i][j]='.';
	vector<int> order(8);	for(int i=0;i<8;i++)order[i]=i;

	do{
		bool flag=true;
		for(int i=0;i<n;i++){
			if(order[init[i].y]!=init[i].x){
				flag=false;
				break;
			}
		}
		if(flag==false)continue;

		memset(grid,0,sizeof(grid));

		for(int i=0;i<8;i++){
			Point p;
			p.y=i;	p.x=order[i];
			if(Put(p)==false){
				flag=false;
				break;
			}
		}
		if(flag){
			for(int i=0;i<8;i++)ans[i][order[i]]='Q';

			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++)cout<<ans[i][j];
				cout<<endl;
			}
			return 0;
		}
	}while(next_permutation(ALL(order)));

	return 0;
}



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

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

  if (a.length() > b.length())
  {
    cout << "GREATER" << endl;
  }
  else if (a.length() < b.length())
  {
    cout << "LESS" << endl;
  }
  else
  {
    for (int i = 0; i < a.length(); i++)
    {
      if (a[i] - '0' > b[i] - '0')
      {
        cout << "GREATER" << endl;
        return 0;
      }
      else if (a[i] - '0' < b[i] - '0')
      {
        cout << "LESS" << endl;
        return 0;
      }
    }

    cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
const int MAXN = 15;
int A[MAXN];
int X[MAXN][MAXN];
int Y[MAXN][MAXN];
int N;

bool test(int mask, int bit) { return ((mask >> bit) & 1); }

bool valid(int mask) {
  for (int i = 0; i < N; ++i) {
    if (!test(mask, i)) continue;
    for (int j = 0; j < A[i]; ++j) {
      if (Y[i][j] ^ test(mask, X[i][j])) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    for (int j = 0; j < A[i]; ++j) {
      scanf(" %d%d", &X[i][j], &Y[i][j]);
      --X[i][j];
    }
  }
  int L = (1 << N);
  int ret = 0;
  for (int mask = 1; mask < L; ++mask) {
    if (!valid(mask)) continue;
    ret = std::max(__builtin_popcount(mask), ret);
  }
  printf("%d\n", ret); 
  return 0;
}

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

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

int main(){
  long A,B;
  cin >> A>>B;
  long G=GCD(A,B);
  long ans=1;
  for(int i=2; i<sqrt(G); i++){
    if(G%i==0){
      while(G%i==0) G/=i;
      ans++;
    }
  }
  if(G!=1) ans++;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long INF=123456789123456789;
int main()
{
  long long x,y,res=INF;
  cin >> x >> y;
  if(y>x) res=y-x;
  if(y>=-x) res=min(y+x+1,res);
  if(-y>=x) res=min(-y-x+1,res);
  if(-y>-x) res=min(-y+x+2,res);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
h = list(map(int, input().split()))

ans = 0
for i in range(n):
  if i == 0:
    ans += 1
  elif (i == 1) and (h[0] <= h[i]):
    ans += 1
  elif (i > 1) and (max(h[:i]) <= h[i]):
    ans += 1

print(ans)


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

 int s;
 string a;
 int main()
 {
 	cin >>  a;
 	for (int i =1; i < a.size(); i++) {
	    if (a[i] != a[i - 1])  s++;
	 }
	 cout << s;
	 return 0;
}

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

using namespace std;

int main() {
	int n;
	ignore = scanf("%d", &n);
	
	if (n == 3) {
		printf("2 5 63\n");
		return 0;
	}
	
	if (n == 4) {
		printf("2 5 20 63\n");
		return 0;
	}
	
	vector<int> ans;
	for (int i = 2; (int)ans.size() < n + 5; i++)
		if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0)
			ans.push_back(i);
	
	int sum = accumulate(ans.begin() + 10, ans.end(), 0) % 30;
	for (size_t i = 10; i < ans.size(); i++) printf("%d ", ans[i]);
	
	for (int msk = 0; msk < (1 << 10); msk++)
		if (__builtin_popcount(msk) == 5) {
			int cur = 0;
			for (int i = 0; i < 10; i++)
				if ((msk >> i) & 1) {
					cur += ans[i];
				}
			
			if ((sum + cur) % 30 == 0) {
				for (int i = 0; i < 10; i++)
					if ((msk >> i) & 1)
						printf("%d ", ans[i]);
			
				printf("\n");
				
				return 0;
			}
		}
	
	return 0;
}


Measured memory_bytes: 512
import fractions 

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

gcd = C * D // fractions.gcd(C, D)

print(B - A + 1 - (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + (B // gcd - (A - 1) // gcd))


Measured memory_bytes: 66028
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define ll long long
#define rsz resize
#define mod 1000000007
#define LIMIT 1000010


int main()
{
  int a,b,k;
 cin>>k>>a>>b;
 for(int i=a;i<=b;++i)
 {
     if(i%k==0)
{
    cout<<"OK"<<endl;
    return 0;
}
 }
 cout<<"NG"<<endl;
 return 0;
 
} 


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
ll F(ll x,ll y)
{
    ll p=0,q=0;
    while(x>0)
    {
        x/=10;
        p++;
    }
    while(y>0)
    {
        y/=10;
        q++;
    }
    return max(p,q);
}
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n;
    m=LLONG_MAX;
    for(i=1;i<=(n/i);i++)
    {
        if(n%i==0)
        {
            m=min(m,F(i,(n/i)));
        }
    }
    cout<<m<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 1

int memo[128][128];  //[time][node]
int edge[128][128];
int reitou[128];
int n,m,l,k,a,h;

class state{
  public:
	int now,life,cost;
	state(int _n, int _l, int _c){
		now = _n;
		life = _l;
		cost = _c;
	}
	bool operator<(const state& a)const{
		return cost > a.cost;
	}
};

int main(){

	while(scanf("%d%d%d%d%d%d",&n,&m,&l,&k,&a,&h),n|m|l|k|a|h){
		memset(reitou,0,sizeof(reitou));
		rep(i,128)rep(j,128)edge[i][j]=memo[i][j]=INT_MAX;
		
		rep(i,l){
			int g; scanf("%d",&g);
			reitou[g] = 1;
		}
		rep(i,k){
			int x,y,t; scanf("%d%d%d",&x,&y,&t);
			edge[x][y] = edge[y][x] = t;
		}

		priority_queue<state> q;
		q.push(state(a,m,0));
		memo[m][a] = 0;

		while( !q.empty() ){
			int nw = q.top().now;
			int lf = q.top().life;
			int co = q.top().cost;
			q.pop();

			//Ú®·ép^[
			rep(i,n)if( edge[nw][i]!=INT_MAX && lf-edge[nw][i]>=0 ){
				int next_life = lf - edge[nw][i];
				if( memo[next_life][i] > co+edge[nw][i] ){
					memo[next_life][i] = co+edge[nw][i];
					q.push(state(i,next_life,co+edge[nw][i]));
				}
			}

			//â·ép^[
			if( reitou[nw]==1 ){
				for(int i=1; i+lf<=m; i++){
					if( memo[i+lf][nw] > co+i ){
						memo[i+lf][nw] = co+i;
						q.push(state(nw,i+lf,co+i));
					}
				}
			}
		}

		int ans = INT_MAX;
		rep(i,m+1){
			ans = min(ans, memo[i][h]);
		}
		if( ans==INT_MAX ){
			puts("Help!");
		}else{
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

/**
 * Taro
 */
public class Main {

    int n;
    int m;
    int[] costs;

    public void scan() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            n = sc.nextInt();
            m = sc.nextInt();
            if (n == 0 && m == 0) {
                return;
            }
            costs = new int[n];
            for (int i = 0; i < n; i++) {
                costs[i] = sc.nextInt();
            }
            boolean[] used = new boolean[n];
            for (int i = 0; i < n; i++) {
                used[i] = false;
            }
            calc();

        }
    }

    public void calc() {
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                int c = costs[i] + costs[j];
                if (c <= m) {
                    if (max < c) {
                        max = c;
                    }
                }
            }
        }
        System.out.println((max == 0) ? "NONE" : max);
    }

    public static void main(String[] args) {
        Main cui = new Main();
        cui.scan();
    }
}


Measured memory_bytes: 48348
#include <iostream>
#include <array>

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner; 	//first second third home
								//runner:1 no:0 home:point
	
	public:
	Baseball(){
		out_count = 0;
		for(int i=0; i<4; ++i)
			runner[i] = 0;
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::cin >> str;
		
			if(str == "HIT") hit();
			else if(str == "OUT") out();
			else if(str == "HOMERUN") homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
			if(i == 3)
				++runner[i];
		}
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<3; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
		++runner[3];
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int k=0; k<n; ++k){
		Baseball game;
		game.ining();
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 1000100;

ll x, y;
long fac[MAX], inv[MAX], finv[MAX];
void init()
{
    fac[0] = inv[0] = finv[0] = 1;
    fac[1] = inv[1] = finv[1] = 1;
    for (int i = 2; i < MAX; ++i)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long C(int n, int k)
{
    if (n < 0 || k < 0 || n < k)
        return 0;
    return (fac[n] * finv[n - k] % MOD) * finv[k] % MOD;
}

int main()
{
  cin >> x >> y;
  // a + b * 2 == x && a * 2 + b == y
  // 2 * (x - b * 2) + b == y
  // -3 * b == y - 2 * x
  // b == (2 * x - y) / 3
  // a == (2 * y - x) / 3
  init();
  if ((2 * x - y) % 3 == 0 && (2 * y - x) % 3 == 0) {
    ll a = (2 * x - y) / 3;
    ll b = (2 * y - x) / 3;
    cout << C(a + b, a);
  } else {
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 23680
S = input()
dp = [[0]*13 for i in range(len(S))]
MOD = 10**9+7
 
if S[0]=='?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(S[0])] = 1
 
for i,c in enumerate(S[1:]):
    for j in range(13):
        if c=='?':
            for k in range(10):
                nj = (j*10 + k) % 13
                dp[i+1][nj] += dp[i][j]
                dp[i+1][nj] %= MOD
        else:
            nj = (j*10 + int(c)) % 13
            dp[i+1][nj] += dp[i][j]
            dp[i+1][nj] %= MOD
 
print(dp[-1][5])


Measured memory_bytes: 61916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 #define endl '\n'

int main()
{
    long long int t=1,n,c=1,i,ans=1;
   long double cur=1;
   // cin>>t;
    //while(t--){
        cin>>n;
        long long int a[n+1];
        for(i=0;i<n;i++){
            cin>>a[i];
            if(a[i]==0){
                    cout<<"0";
            return 0;
        }
        }
           for(i=0;i<n;i++){
           cur*=a[i];
            if(cur>1000000000000000000 || ans<0){
                    c=0;
                break;
            }
            ans*=a[i];
        }
        if(c!=0)cout<<ans<<endl;
        else cout<<"-1"<<endl;
    }



Measured memory_bytes: 4392
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = []
j = 0
na= 0
c = 0
if sum(a)<sum(b):
    print(-1)
else:
    for i in range(n):
        if a[i]<b[i]:
            na +=b[i]-a[i]
            c+=1
        elif a[i] > b[i]:
            k.append(a[i]-b[i])
    k.sort()
    k = k[::-1]
    while na > 0:
        na -=k[j]
        c +=1
        j+=1
    print(c)


Measured memory_bytes: 18524
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

    ll cnt = 0;
    rep(i, n-1){
        ll diff = a[i]-a[i+1];
        if(diff>0){
            a[i+1]+=diff;
            cnt += diff;
        }
    }
    out(cnt);
}

Measured memory_bytes: 5144
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#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 ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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 solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,y,z; cin >> x >> y >> z;
    cout << z <<" " << x << " " <<y << endl;
    
    
}



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int buc[7]={0};
		while(n--){
			int a;	cin>>a;
			if(a>60)	a=60;
			buc[a/10]++;
		}
		for(int i=0;i<7;i++)	cout<<buc[i]<<endl;
	}
	return 0;
}

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

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

using namespace std;

int main() {
    int N, L;
    
    cin >> N >> L;
    
    vector<int> ringo(N), aji(N);
    int count[3]={};
    int sum=0;
    
    rep(i, N) {
        ringo[i] = i+1;
        aji[i] = L + ringo[i] - 1;
        sum += aji[i];
        
        if(aji[i]>0) count[2]++;
        else if(aji[i]==0) count[1]++;
        else count[0]++;
    }
    
    if(count[1]>0) {
        ;
    } else if(count[0]==0 && count[2]>0) {
        sum -= aji[0];
    } else if(count[0]>0 && count[2]==0) {
        sum -= aji[aji.size()-1];
    }
    
    
    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 384
import itertools
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
  c.append(list(input()))

for i in range(2 ** h - 1):
  c2 = []
  x = str(bin(i))[2:].zfill(h)
  for a in range(h):
    if x[a] == '0':
      c2.append(c[a])
    elif x[a] == '1':
      c2.append(['*'] * w)
  black = list(itertools.chain.from_iterable(c2)).count('#')
  for j in range(2 ** w - 1):
    black2 = black
    y = str(bin(j))[2:].zfill(w)
    for b in range(w):
      if y[b] == '1':
        for a in range(h):
          if c2[a][b] == '#':
            black2 -= 1
    if black2 == k:
      ans += 1
print(ans)

Measured memory_bytes: 9224
n=int(input())
ans=0
if n%2==1:
  for i in range(1,n+2,2):
    x=0
    for k in range(1,i+1):
      if i%k==0:
        x+=1
    if x==8:
      ans+=1
else:
  for i in range(1,n+1,2):
    x=0
    for k in range(1,i+1):
      if i%k==0:
        x+=1
    if x==8:
      ans+=1
print(ans)

Measured memory_bytes: 63836
#include <stdio.h>
    
    int main(void){
        int n, a ,max = -1000000 ,min = 1000000;
        long long int sum = 0;
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d", &a);
            if(max < a){max = a;}
            if(min > a){min = a;}
            sum = sum + a;
        }
        printf("%d %d %lld\n",min,max,sum);

        return 0;
    }


Measured memory_bytes: 2100
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    # リーダーの方を向く人数＝リーダーより左のWの数＋リーダーより右のEの数
    accum_W = [0]*N #iより左にWが何個あるか
    accum_E = [0]*N #iよりみぎにEが何個あるか

    for i in range(1,N):
        accum_W[i] = accum_W[i-1]+int(S[i-1]=="W")

    for i in range(N-2,-1,-1):
        accum_E[i] = accum_E[i+1] + int(S[i+1] == "E")
    
    answer = N
    for i in range(N):
        a = accum_W[i]+accum_E[i]
        answer = min(answer,a)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27340
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	long long A, B, N;
	cin >> A >> B >> N;

	long long minv = B - 1;
	if (minv > N) minv = N;

	cout << A * minv / B;

	return 0;
}


Measured memory_bytes: 3648
// D - Negative Cycle
#include <bits/stdc++.h>

using namespace std;

#define	INF	1e16

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	cin >> n;
	vector<vector<long long> > a(n, vector<long long>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j) cin >> a[i][j];

	vector<vector<long long> > dp(n + 1, vector<long long>(n + 1, INF));
	dp[0][0] = 0;

	for (int i = 1; i <= n; i++) {
		vector<long long> x(i), y(i);
		for (int j = 0; j < i; j++) {
			for (int k = i + 1; k <= n; k++) x[j] += a[k - 1][j - 1];
			if (j > 0) x[j] += x[j - 1];
		}
		for (int j = i - 1; j >= 0; j--) {
			for (int k = j + 1; k < i + 1; k++) y[j] += a[j][k - 1];
			if (j + 1 < i - 1) y[j] += y[j + 1];
		}
		for (int j = 0; j < i; j++)
			for (int k = 0; k < j + 1; k++)
				dp[i][j] = min(dp[i][j], dp[j][k] + x[j] - x[k] + y[j]);
	}

	cout << *min_element(dp[n].begin(),dp[n].end()) << endl;

	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n, m; cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


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

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

    
  

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b) 
{
    return *(int *)a - *(int *)b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), asc);
    int ans = 0;
    int x;
    i = 0;
    while (i < n)
    {
        x = 1;
        while (a[i] == a[i + 1])
        {
            i++;
            x++;
        }
        if (a[i] > x)
            ans += x;
        else
            ans += x - a[i];
        i++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	int n;
	long long int h[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int hi = h[0], count = 0, s = 0;
	for (int i = 1; i < n; i++) {
		if (hi >= h[i]) {
			hi = h[i];
			count++;
		}
		else {
			hi = h[i];
			s = max(s, count);
			count = 0;
		}
	}
	s = max(s, count);
	cout << s << endl;
}


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

int num;
vector<string> ans;

void rec(char alpha, string &s, bool must){
  if(alpha<'a'){
    rep(i,ans.size()){
      if(ans[i] == s)return;
    }
    num++;
    ans.push_back(s);
    /*
    if(ans.size()<10){
      ans.push_back(s);
      sort(ans.begin(),ans.end());
    }else{
      string tmp = s;
      for(int i=0;i<5;i++){
	if(ans[i] > tmp)swap(ans[i],tmp);
	else break;
      }
      for(int i=9;i>=5;i--){
	if(ans[i] < tmp)swap(ans[i],tmp);
	else break;
      }
    }
    */
    return;
  }

  int R = s.size();
  char nxt = alpha+1;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i] == nxt)R = i;
  }

  bool f = false;
  for(int i=R-1;i>=0;i--){
    if(s[i] == alpha){
      R = i;
      f = true;
      s[i] = nxt;
      rec(alpha-1, s,0);
      s[i] = alpha;
    }
  }

  if(f && !must){
    if(alpha!='a'){
      for(int i=0;i<R;i++){
	if(s[i] == alpha-1){
	  rec(alpha-1,s,1);
	  break;
	}
      }
    }else rec(alpha-1,s,1);
  }
  if(R==s.size() && !f && !must)rec(alpha-1,s,0);
}

int main(){
  string c;
  while(cin >> c, c!="#"){
    ans.clear();
    num = 0;
    rec('y',c,0);

    cout << num << endl;
    if(num)sort(ans.begin(),ans.end());

    if(num<=10){
      for(int i=0;i<ans.size();i++){
	cout << ans[i] << endl;
      }
    }else{
      for(int i=0;i<5;i++)cout << ans[i] << endl;
      for(int i=5;i>=1;i--)cout << ans[ans.size()-i] << endl;
    }
  }
}

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

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

int main(){
	int n;
  	cin >> n;
  
  	int ans = 0;
	for(int i = 1; i <= n; i++){
    	for(int j = 1; j <= n; j++){
    		for(int k = 1; k <= n; k++){
    			ans += gcd(gcd(i, j), k);
    		}
    	}
    }
  
  	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n, k;
    cin >> n >> k;
    if(k % 2 == 1) {
        ll g = n / k;
        cout << g * g * g << endl;
    }

    else {
        ll g = n / k;
        ll h = (2 * n)/k;
        h = h - g;
        cout << h * h * h + g * g * g << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
local n = io.read("*n")
local t, a = io.read("*n", "*n")
t, a = t * 1000, a * 1000
local nearest_x = 1
local tbl = {}
for i = 1, n do tbl[i] = io.read("*n") end
for i = 2, n do
  if math.abs(t - 6 * tbl[i] - a) < math.abs(t - 6 * tbl[nearest_x] - a) then
    nearest_x = i
  end
end
print(nearest_x)


Measured memory_bytes: 760
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	ans := 0
	for {
		if a == b && b == c {
			break
		} else if a > b && a > c {
			b += 1
			c += 1
		} else if b > a && b > c {
			a += 1
			c += 1
		} else if c > a && c > b {
			a += 1
			b += 1
		} else if a == b {
			c += 2
		} else if a == c {
			b += 2
		} else {
			a += 2
		}
		ans += 1
	}
	fmt.Print(ans)
}


Measured memory_bytes: 1832
<?php

$C = [];
for ($i = 0; $i < 3; ++$i) {
    $C[] = explode(' ', trim(fgets(STDIN)));
}

$total_flg = false;
for ($x = 0; $x <= 100; ++$x) {
    $a = [];
    $b = [];
    $a[0] = $x;
    for ($i = 0; $i < 3; ++$i) $b[$i] = $C[0][$i]  - $a[0];
    for ($i = 1; $i < 3; ++$i) $a[$i] = $C[$i][0]  - $b[0];
    
    $flg = true;
    for ($i = 0; $i < 3; ++$i) {
        for ($j = 0; $j < 3; ++$j) {
            if ($C[$i][$j] != $a[$i] + $b[$j]) {
                $flg = false;
                break 2;
            }
        }
    }
    $total_flg |= $flg;
}
echo $total_flg ? 'Yes' : 'No', PHP_EOL;


Measured memory_bytes: 16244
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int main(){
	const int INF = 1e+8;
	int h, w;
	char m[51][51];
	int dp[51][51] = {0};
	
	cin >> h >> w;
	for(int y = 0 ; y < h ; y++ ){
		cin >> m[y];
	}
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			dp[y][x] = INF;
		}
	}
	dp[0][0] = 0;
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			dp[y+1][x] = min( dp[y+1][x] , dp[y][x] + (m[y][x] - '0') );
			dp[y][x+1] = min( dp[y][x+1] , dp[y][x] + (m[y][x] - '0') );
		}
	}
	cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 1184