akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ll)(1e9)+7)

vector<ll> v((ll)(1e5+1),0);
vector<ll> v_inv((ll)(1e5+1),0);

ll pmod(ll n, ll p){
	ll m=n%mod;
	if(p==0) return 1;
	ll ans=pmod((m*m)%mod, p/2)%mod;
	if(p%2==1) ans=ans*m%mod;
	return ans;
}

void factorial(ll n){
	v[0]=1;
	for(ll i=1; i<=n; i++){
		v[i]=v[i-1]*i%mod;
	}
	return;
}

void factorial_inv(ll n){
	for(ll i=0; i<=n; i++){
		v_inv[i]=pmod(v[i],mod-2);
	}
}

ll binom(ll n, ll k){
	if(n<k || n<0 || k<0) return 0;
	ll tmp=v_inv[k]*v_inv[n-k]%mod;
	return v[n]*tmp%mod;
}

int main(){
	int n, k;
	cin >> n >> k;
	ll a[n+1];
	for(int i=1; i<=n; i++) cin >> a[i];
	sort(a+1, a+n+1);

	if(k==1 || n==1){
		cout << 0 << endl;
		return 0;
	}

	factorial(n);
	factorial_inv(n);
	ll s[n-1];
	s[0]=binom(0, k-2);
	for(int i=1; i<=n-2; i++){
		s[i]=s[i-1]+binom(i, k-2);
		s[i]%=mod;
	}

	ll ans=(a[n]-a[1])*s[n-2]%mod;
	if(n>=3){
		for(int i=2; i<=n-1; i++){
			ans+=(s[i-2]-s[n-i-1])*a[i];
			ans%=mod;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  int N, A, G = 0;
  vector<int> V(1e6+1);
  cin >> N;
  while (cin >> A) {
    V.at(A)++;
    G = gcd(G, A);
  }
  if (G > 1) return cout << "not coprime" << "\n", 0;

  for (int i = 2; i <= 1e6; i++) {
    for (int j = i, dup = 0; j <= 1e6; j += i) {
      if (V.at(j)) {
        if (dup) return cout << "setwise coprime" << "\n", 0;
        else dup = 1;
      }
    }
  }
  cout << "pairwise coprime" << "\n";
}


Measured memory_bytes: 7072
#include <stdio.h>
#include <algorithm>

int main() {
	int n, s[100], sum = 0, min = 100;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", s + i);
		sum += s[i];
		if (s[i] % 10)
			min = std::min(min, s[i]);
	}

	if (sum % 10)
		printf("%d\n", sum);
	else
		printf("%d\n", (min != 100 ? sum - min : 0));
}

Measured memory_bytes: 128
N, K, S = map(int, input().split())
ans = []
for _ in range(K):
    ans.append(S)
for _ in range(N - K):
    if S == 10 ** 9:
        ans.append(1)
    else:
        ans.append(S + 1)
print(" ".join(map(str, ans)))

Measured memory_bytes: 15000
from collections import Counter

def comb(x,y):
    c=1
    for i in range(y):
        c*=(x-i)
        c//=(i+1)
    return c

n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
print(sum(V[:a])/a)
c=Counter(V)
cnt=0
for v in V:
    i=c[v]
    cnt+=i
    if cnt>=a:
        break
if V[0]==V[a-1]:
    ans=0
    for j in range(a,min(cnt,b)+1):
        ans+=comb(i,j)
    print(ans)
else:
    print(comb(i,a+i-cnt))

Measured memory_bytes: 3444
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str = br.readLine();
      int x = Integer.parseInt(str);

      System.out.println( (int)Math.pow(x,3) );

   }
}

Measured memory_bytes: 24436
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[200001];
int main(){
    int n;
    cin>>n;
    ll ai;
    rep(i,n){
        cin>>ai;
        a[i]=ai-(i+1);
    }
    sort(a,a+n);
    ll b=a[n/2];
    ll sum=0;
    rep(i,n){
        sum+=abs(a[i]-b);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  string s[h];
  for(int i=0;i<h;i++) {
    cin>>s[i];
  }
  for(int i=0;i<w+2;i++) {
    cout<<'#';
  }
  cout<<endl;
  for(int i=0;i<h;i++) {
    cout<<'#'<<s[i]<<'#'<<endl;
  }
  for(int i=0;i<w+2;i++) {
    cout<<'#';
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong(); String s = "";
        while (n > 0) {
            int mod = (int) (n % 26 + 96);
            n -= (n % 26 == 0 ? 26 : n % 26);
            if (mod == 96) mod = 122;
            s = (char) mod + s;
            n /= 26;
        }
        System.out.println(s);
    }


}

Measured memory_bytes: 39232
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define the_flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

using namespace std;

int main()
{
	//input_output;
	the_flash;
	int x;
	cin >> x;
	if (x >= 400 && x < 600)
		cout << 8 << endl;
	else if (x >= 600 && x < 800)
		cout << 7 << endl;
	else if (x >= 800 && x < 1000)
		cout << 6 << endl;
	else if (x >= 1000 && x < 1200)
		cout << 5 << endl;
	else if (x >= 1200 && x < 1400)
		cout << 4 << endl;
	else if (x >= 1400 && x < 1600)
		cout << 3 << endl;
	else if (x >= 1600 && x < 1800)
		cout << 2 << endl;
	else if (x >= 1800 && x < 2000)
		cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 3656
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

int main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
       string s,t;int cnt=0;
       cin>>s>>t;
       for(int i=0;i<(int)s.length();++i){
        if(s[i]!=t[i]){
            cnt++;
        }
       }
       cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 3800
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int b, a;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> a >> b;
    int d = b - a;
    int i = 1;
    int sum = 0;
    while (i < d) {
        sum += i;
        ++i;
    }
    cout << sum - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 1) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}
	int y;
	cin >> y;
	return 0;
}

Measured memory_bytes: 256
'use strict'
function Main(input) {
  const a = input.trim().split('')
  const N = a.length

  if(N === 1) {
    console.log(0)
    return
  }

  let c = 0
  for(let i = 0; i < Math.floor(N/2); ++i) {
    const t = a[i]
    const l = a[N - 1 - i]
    if (t !== l) c++
  }
  console.log(c)
  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
/* 
 * Project: AtCoder Beginners Contest 144 A - 9x9
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/12
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
using namespace std;

uint32_t a;
uint32_t b;

void solve() {

    if (a > 9 || b > 9) {
        printf("-1\n");
        return;
    }

    printf("%d\n", a*b);

}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);

    solve();

}

Measured memory_bytes: 3164
import sys

N,M,X = map(int,input().split())

A = list(map(int,input().split()))


for i in range(M):
  if A[i] > X:
    AX_index = i
    break
cost_n = len(A) - AX_index
cost_0 = AX_index

print(min(cost_n,cost_0))

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

int main(){
  int N, K, X, Y, price=0;
  cin >> N >> K >> X >> Y;
  for (int i=0; i < N; i++) {
    if (i < K) {
      price += X;
    } else {
      price += Y;
    }
  }
  cout << price << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.io.*;

class Main
{
	public static void main(String[] arg)throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader(System.in));

		String line;
		while((line=input.readLine())!=null)
		{
			String[] str=line.split(" ");
			int num[]=new int[3];

			num[0]=Integer.parseInt(str[0]);
			num[1]=Integer.parseInt(str[1]);
			num[2]=num[1]+num[0];

			System.out.println((int)Math.log10(num[2])+1); 
		}
	}
}

Measured memory_bytes: 24312
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<unordered_map>
using namespace std;
int n,m,a[500][500],ban[500],cur[500];
bool check(int x)
{
	memset(ban,0,sizeof ban);
	for(int i=1;i<=n;i++)cur[i]=1;
	for(;;)
	{
		unordered_map<int,int> M;
		for(int i=1;i<=n;i++)
		{
			while(cur[i]<=m&&ban[a[i][cur[i]]])cur[i]++;
			if(cur[i]>m)return false;
			M[a[i][cur[i]]]++;
		}
		bool f=true;
		for(auto i:M)
			if(i.second>x){f=false;ban[i.first]=1;}
		if(f)return true;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
	int l=1,r=n,ans=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}


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

#define INF_MAX 	2147483647
#define INF_MIN 	-2147483648
#define INF 		(1 << 30)
#define SORT(a,n)   sort(a,a+n)
#define EPS			1e-9
#define PI 			acos(-1.0)
#define N 		    2 + 100
#define MOD			10000000007
#define sz(x) 		(int)(x).size()
#define all(x) 		(x).begin(), (x).end()
#define pb 			push_back
#define mp			make_pair
#define ms(x, a) 	memset((x), (a), sizeof(x))
#define ff           first
#define ss           second
#define rep(i,a,b)  for(int i=(a); i<(b); i++)
#define repC(i,x) 	for(size_t i=0; i<x.size(); i++)
#define repIT(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define nn          '\n'
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define i64 __int64
#define isValid(x, y) ( x >= 0 And x < row And y >= 0 And y < col )
#define dump cin.ignore()


typedef long long 		LL;
typedef pair<int,int> 	pii;
typedef vector<int> 	vi;
typedef vector<string> 	vs;
typedef vector<char>	vc;
typedef vector<bool>    vb;
typedef vector< pii >   vii;
typedef map<string,int> msi;
typedef map<int,int>	mii;
typedef map<char,int>   mci;
typedef map<int,string>	mis;

template<class T> T Abs(T x) {return x>0 ? x : -x;}
template<class T> T Max(T a, T b) {return a>b ? a : b;}
template<class T> T Min(T a, T b) {return a<b ? a : b;}
template<class T> T gcd(T a, T b) {return (b ? gcd(b,a%b) : a);}
template< class T > T sq(T x){ return x * x;}
template< class T > T lcm(T a, T b){ return (a / gcd<T>(a, b) * b); }
template< class T > T deb(T cmd) {cout << "debugger:" << endl; cout << cmd << endl;}
template< class T > T deb(T cmd1, T cmd2) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3, T cmd4) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 <<"\t" << cmd4 << endl;}
bool isVowel(char ch){ch=tolower(ch);return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');}

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

#define MAX 10000

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
	#endif

    int a, b;

    while(scanf("%d %d", &a, &b) == 2)
        cout << gcd(a, b) << nn;

    return 0;
}

Measured memory_bytes: 1196
n = int(input())
witness = []
 
for i in range(n):
    a = int(input())
    witness.append([])
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        witness[-1].append((x,y))
 
def is_honest(i, j):
    return (i >> j) % 2 == 1
 
def honest_cnt(i):
    ans = 0
    for j in range(n):
        ans += is_honest(i, j)
    return ans
 
ans = 0
 
for i in range(1 << n):
    ok = True
    for j in range(n):
        if not is_honest(i,j):continue
        for (x, y) in witness[j]:
            if y == 0 and is_honest(i, x):
                ok = False
            if y == 1 and not is_honest(i, x):
                ok = False
    if ok:
        ans = max(ans, honest_cnt(i))
 
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

vector<string> vec;
int N;

void dfs(vector<int> rem, vector<vector<int>> V) {
	if (rem.size() == 0) {
		string S = "";
		for (int i = 0; i < N; i++) S += "0";
		for (int i = 0; i < V.size(); i++) {
			for (int j : V[i]) S[j] = ('a' + i);
		}
		vec.push_back(S);
		return;
	}

	for (int i = 0; i < (1 << rem.size()); i++) {
		int bit[12];
		for (int j = 0; j < rem.size(); j++) bit[j] = (i / (1 << j)) % 2;
		if (bit[0] != 1) continue;

		vector<int> F, G;
		for (int j = 0; j < rem.size(); j++) {
			if (bit[j] == 0) F.push_back(rem[j]);
			else G.push_back(rem[j]);
		}
		vector<vector<int>> S = V;
		S.push_back(G);
		dfs(F, S);
	}
}

int main() {
	cin >> N;
	vector<int> L; for (int i = 0; i < N; i++) L.push_back(i);
	dfs(L, vector<vector<int>>{});

	sort(vec.begin(), vec.end());
	for (int i = 0; i < vec.size(); i++) cout << vec[i] << endl;
	return 0;
}

Measured memory_bytes: 8180
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> 

using namespace std;

int a[200100];

int main()
{
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	int be = 0,en = 0,ans = 0;
	for(int i = 1;i <= n;i++)
	{
		if(a[i] >= en)ans += en - be,be = a[i],en = a[i] + t;
		else
		{
			en = max(en,a[i] + t);
		}
	}
	printf("%d\n",ans + en - be);
}

Measured memory_bytes: 896
import sys
def input():
    return sys.stdin.readline()[:-1]

import collections
def main():
    H, W, K = map(int,input().split())
    S = [input() for _ in range(H)]
    ans = 0
    for paint_h in range(2**H): #すべての行の塗りつぶし方を2進数で列挙する
        for paint_w in range(2**W): #すべての列の塗りつぶし方を2進数で列挙する
            cnt=0
            for i in range(H): #すべてのi行目j列目の要素についてみる
                for j in range(W):
                    if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
                        if S[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
                            cnt+=1
            if cnt== K: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
                ans+=1
            

    print(ans)


    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9300
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 10000007

int main()
{
    ll n,k;
    cin>>n;
    cin>>k;
    ll cost[n+1];
    ll dp[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>cost[i];

    }
    dp[n]=0;
     for(int i=n-1;i>0;i--)
    {
        dp[i]=INT_MAX ;
        for(int j=1;j<=k;j++)
        {    if(i+j<=n)
            {dp[i]=min(dp[i],(dp[i+j]+abs(cost[i+j]-cost[i])));
            }

        }
    }
    //
    cout<<dp[1]<<endl;
}





Measured memory_bytes: 5112
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int n, m, q;
vector<int> e[100005];
struct node {
    int v, d, c;
};
node t[100005];
void paint(node no)
{
    auto cur = no.v;
    // cout << cur << endl;
    if (t[cur].c != -1 && t[cur].d >= no.d) {
        return;
    } else if (t[cur].c != -1) {
        t[cur].d = no.d;
        if (no.d == 0)
            return;
        node ne{no.v, no.d - 1, no.c};
        for (auto to : e[cur]) {
            ne.v = to;
            paint(ne);
        }
    } else {
        t[cur] = no;
        if (no.d == 0)
            return;
        node ne{no.v, no.d - 1, no.c};
        for (auto to : e[cur]) {
            ne.v = to;
            paint(ne);
        }
    }
}
vector<node> query;
int main()
{
    cin >> n >> m;
    int a, b;
    int v, d, c;
    rep(i, m)
    {
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    cin >> q;
    node ini{0, 0, -1};
    rep(i, n)
    {
        ini.v = i;
        t[i] = ini;
    }
    rep(i, q)
    {
        cin >> v >> d >> c;
        v--;
        query.push_back({v, d, c});
    }
    reverse(query.begin(), query.end());
    rep(i, q)
    {
        paint(query[i]);
    }
    rep(i, n)
    {
        if (t[i].c == -1)
            t[i].c = 0;
        cout << t[i].c << endl;
    }
}


Measured memory_bytes: 9204
import bisect
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    if pos == 0:
        return x * n >= k * x
    return sums[pos-1]+ x * (n - pos) >= k * x

x = 0
res = []
for k in range(N, 0, -1):
    while check(k, x+1):
        x += 1
    res.append(x)
    
for x in res[::-1]:
    print(x)

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

int main() {
  int N;
  cin >> N;
  long ans = 1;
  for (int i = 1; i <= N; ++i) {
    ans = ((ans * i) % (long(pow(10,9)) + 7));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int H, W;
 cin >> H >> W;
 
 vector<string> snake(W, "snake");
 vector<string> alphabet;
  alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; 
 
 vector<vector<string>> vec(H, vector<string>(W)); 
 for(int i=0; i<H; i++){
   for(int j=0; j<W; j++)
     cin >> vec.at(i).at(j);
 }
 
 for (int i=0; i<H; i++){
  if (vec.at(i) != snake) {
    for (int j=0; j<W; j++){
     if (vec.at(i).at(j) == "snuke"){
      cout << alphabet.at(j) << i+1 << endl;
      break;
     }
    }
  }
 }

}


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

using namespace std;

int surface[6];

void manip_north() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = s3;
  surface[1] = t;
  surface[2] = s2;
  surface[3] = b;
  surface[4] = s4;
  surface[5] = s1;
}

void manip_east() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = s2;
  surface[1] = s1;
  surface[2] = b;
  surface[3] = s3;
  surface[4] = t;
  surface[5] = s4;
}

void manip_west() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = s4;
  surface[1] = s1;
  surface[2] = t;
  surface[3] = s3;
  surface[4] = b;
  surface[5] = s2;
}

void manip_south() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = s1;
  surface[1] = b;
  surface[2] = s2;
  surface[3] = t;
  surface[4] = s4;
  surface[5] = s3;
}

void manip_right() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = t;
  surface[1] = s2;
  surface[2] = s3;
  surface[3] = s4;
  surface[4] = s1;
  surface[5] = b;
}

void manip_left() {
  int t = surface[0];
  int s1 = surface[1];
  int s2 = surface[2];
  int s3 = surface[3];
  int s4 = surface[4];
  int b = surface[5];

  surface[0] = t;
  surface[1] = s4;
  surface[2] = s1;
  surface[3] = s2;
  surface[4] = s3;
  surface[5] = b;
}

int main() {
  while (true) {
    int n;
    surface[0] = 1;
    surface[1] = 5;
    surface[2] = 4;
    surface[3] = 2;
    surface[4] = 3;
    surface[5] = 6;
    int score = 1;
    
    cin >> n;

    if (n == 0) break;

    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;

      if (s == "North") {
        manip_north();
      } else if (s == "East") {
        manip_east();
      } else if (s == "South") {
        manip_south();
      } else if (s == "West") {
        manip_west();
      } else if (s == "Right") {
        manip_right();
      } else if (s == "Left") {
        manip_left();
      } else {
      }

      score += surface[0];
    }

    cout << score << endl;
  }

  return 0;
}



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

int main() {
    int gap[2];
    vector<vector<int>> c(3, vector<int>(3));
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> c[i][j];
        }
    }

    gap[0] = c[0][0] - c[0][1];
    gap[1] = c[0][0] - c[0][2];
    for(int i=1; i<3; i++) {
        for(int j=1; j<3; j++) {
            int ngap = c[i][0] - c[i][j];
            if(ngap != gap[j-1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
    
}

Measured memory_bytes: 256
// 2018/01/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int M, T, P, R;
		cin >> M >> T >> P >> R;

		if(M==0 && T==0 && P==0 && R==0)
			break;

		int CP[50];
		int TT[50];
		int PT[50][10];
		for(int i=0; i<T; i++){
			CP[i] = TT[i] = 0;

			for(int j=0; j<P; j++){
				PT[i][j] = 0;
			}
		}

		for(int i=0; i<R; i++){
			int m, t, p, j;
			cin >> m >> t >> p >> j;

			if(j==0){
				CP[t-1]++;
				TT[t-1] += (m+PT[t-1][p-1]);
			}
			else{
				PT[t-1][p-1] += 20;
			}
		}

//		for(int i=0; i<T; i++){
//			cout << CP[i] << ' ' << TT[i] << endl;
//		}

		bool flg[50];
		for(int i=0; i<T; i++){
			flg[i] = false;
		}

		int tnow, tpre = -1;

		for(int i=0; i<T; i++){
			tnow = -1;

			for(int j=0; j<T; j++){
				if(flg[j])
					continue;

				if(tnow==-1){
					tnow = j;
				}
				else{
					if(CP[j]>CP[tnow] || (CP[j]==CP[tnow] && TT[j]<=TT[tnow])){
						tnow = j;
					}
				}
			}

			if(tpre!=-1){
				if(CP[tnow]==CP[tpre] && TT[tnow]==TT[tpre]){
					cout << '=';
				}
				else{
					cout << ',';
				}
			}
			cout << tnow+1;

			flg[tnow] = true;
			tpre = tnow;
		}
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

int main(){
  int a,b,ans;
  bool flag = false;
  cin >> a >> b; 
 for(int i=1;i<=1000;i++){
   int z_a = i*0.08;
   int z_b = i*0.1;
   if(z_a == a && z_b == b) {
     flag = true;
     ans = i;
     break;
   } 
 } 
 if(flag) cout << ans << endl;
 else cout << -1 << endl; 
}

Measured memory_bytes: 256
import java.util.*;

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

    int[] cntChar = new int[3];
    for(int i = 0; i < 3; i++){
      switch(S.charAt(i)){
        case 'a':
          cntChar[0] += 1;
          break;
        case 'b':
          cntChar[1] += 1;
          break;
        case 'c':
         cntChar[2] += 1;
         break;
        default:
          break;
      }
    }

    if(cntChar[0] < 1 || cntChar[1] < 1 || cntChar[2] < 1){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


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

#define INF 1000000000

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

  vector<vector<int> > a;
  for (int i=0; i<n; i++) {
    vector<int> v;
    for (int j=0; j<m; j++) {
      int tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    a.push_back(v);
  }

  int sports[m+1];
  int ans = INF;
  while(1) {
    // debug
    /*
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
        printf("%d ", a[i][j]);
      }
        printf("\n");
      }
    printf("\n");
    */
    //

    memset(sports, 0, sizeof(sports));
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
        if (a[i][j] != 0) {
          sports[a[i][j]]++;
          break;
        }
      }
    }
    pair<int, int> fav = make_pair(0, 0);
    for (int i=0; i<m+1; i++) {
      if (fav.second < sports[i]) {
        fav = make_pair(i, sports[i]);
      }
    }
    if (fav.second == 0) { break; }
    ans = min(ans, fav.second);
    for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
        if (a[i][j] == fav.first) {
          a[i][j] = 0;
          break;
        }
      }
    }
  }


  cout << ans << endl;

  return 0;
}


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

using lint = long long;
#define bit(n) (lint(1) << n)
#define lb(v, n) lower_bound(v.begin(), v.end(), n)

int main() {
    int n;
    cin >> n;
    vector<lint> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    lint ans = 0;
    for (int k = 0; k < 50; k++) {
        lint m = bit(k);
        vector<lint> am(n), bm(n);
        for (int i = 0; i < n; i++) {
            am[i] = a[i] % (2 * m);
            bm[i] = b[i] % (2 * m);
        }
        sort(bm.begin(), bm.end());

        lint num = 0;
        for (int i = 0; i < n; i++) {
            num += lb(bm, 2 * m - am[i]) - lb(bm, m - am[i])
                   + lb(bm, 4 * m - am[i]) - lb(bm, 3 * m - am[i]);
        }
        ans += (num % 2) * m;
    }

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

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

int N,M;
vector<int> H;
vector<vector<int>> J;
vector<bool> v;

int main(){
  cin >> N >> M;
  H = vector<int>(N);
  J = vector<vector<int>>(M,vector<int>(2));
  v = vector<bool>(N,true);
  for(int i = 0; i < N; i++) cin >> H.at(i);
  for(int i = 0; i < M; i++) cin >> J.at(i).at(0) >> J.at(i).at(1);
  
  for(int i = 0; i < M; i++){
    int A = J.at(i).at(0);
    int B = J.at(i).at(1);
    if(H.at(A - 1) < H.at(B -1 )) v.at(A - 1) = false;
    else if(H.at(A - 1) > H.at(B - 1 )) v.at(B - 1) = false;
    else{
      v.at(A - 1) = false;
      v.at(B - 1) = false;
    }
  }
  int ans = 0;
  for(int i = 0; i < N; i++) if(v.at(i)) ans++;
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


char C;


signed main(){
    cin >> C;
    cout << (char)(C-'a'+'b') << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m,x;cin >> n >> m >> x;
    vector<int> a(m);
    rep(i,m)cin >> a[i];
    int cnt = 0;
    for(int i = 0;i < m && a[i] <= x;i++)cnt++;
    int ret = min(cnt,m-cnt);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3584
#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<ll, ll> 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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            int cnt = m * i + n * j - 2 * i * j;
            if(cnt == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

#define PA pair<int,int>

int main(){
	int n; cin>>n;
	int c[100001]={},c2[100001]={};
	FOR(i,0,n){
		int v; cin>>v;
		if(i%2){
			c2[v]++;
		}else{
			c[v]++;
		}
	}
	int M=0,M2=0,m=0,m2=0;
	int M3=-INF;
	FOR(i,0,100001){
		if(c[i]>M){
			m=M;
			M=c[i];
		}else if(c[i]>m){
			m=c[i];
		}
		if(c2[i]>M2){
			m2=M2;
			M2=c2[i];
		}else if(c2[i]>m2){
			m2=c2[i];
		}
		M3=max(M3,c[i]+c2[i]);
	}
	if(M+M2==M3){
		co(min(n-M-m2,n-m-M2));
	}else{
		co(n-M-M2);
	}
}


Measured memory_bytes: 1024
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
int main()
{ 
    fast;
    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    map<ll,ll>m;
    f(i,n)
    {
        cin>>a[i];
        sum+=a[i];
        m[a[i]]++;
    }
    CASES
    {
        ll x,y;
        cin>>x>>y;
        sum=sum-(x*m[x]);
        ll z=m[x];
        m[y]+=m[x];
        m[x]=0;
        sum+=(y*z);
        cout<<sum;
        endd;
    }
  return 0;
}

Measured memory_bytes: 10288
#include <stdio.h>

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

int main(){
	unsigned n, a, p, ans = 0, cnt = 0;
	scanf("%u", &n);
	scanf("%u", &p);
	RC(i, n - 1){
		scanf("%u", &a);
		if(a == p) ++cnt;
		else{
			ans += (cnt + 1) / 2;
			cnt = 0;
		}
		p = a;
	}
	ans += (cnt + 1) / 2;
	printf("%d\n", ans);
}


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

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

#define rep(a,n) for(int a = 0;a < n;a++)
vector<vector<pair<int, int>>> g;
vector<int> color;

void dfs(int v) {
	auto c = color[v];
	for (auto e : g[v]) {
		if (color[e.first] == 0) {
			color[e.first] = (e.second % 2 == 0 ? c : -c);
			dfs(e.first);
		}
	}
}

int main(void)
{
	ll n;
	cin >> n;
	g.resize(n);
	color.resize(n, 0);
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	color[0] = 1;
	dfs(0);
	rep(i, n) {
		cout << max(0, color[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 8192
<?php
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$a[$i]])) ++$cnt[$a[$i]];
    else $cnt[$a[$i]] = 1;
}
$sum = array_sum($a);
list($q) = ints();
$ans = [];
for ($i = 0; $i < $q; ++$i) {
    list($b, $c) = ints();
    if (isset($cnt[$b])) {
        $sum += ($c - $b) * $cnt[$b];
        if (isset($cnt[$c])) $cnt[$c] += $cnt[$b];
        else $cnt[$c] = $cnt[$b];
        unset($cnt[$b]);
    }
    $ans[] = $sum;
}
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 31096
let rec solve acc c i s =
  if String.length s <= i then acc
  else
    if s.[i] = 'W'
    then solve (c + acc) c (i + 1) s
    else solve acc (1 + c) (i + 1) s
let solve = solve 0 0 0


let () =
  let s = read_line () in
  Printf.printf "%d\n" @@ solve s



Measured memory_bytes: 2816
# https://atcoder.jp/contests/abc139/tasks/abc139_b

l = [input() for i in range(1)]
nums = [int(i) for i in l[0].split(' ')]
tap = nums[0]
want = nums[1]
plug = 1
num = 0
while plug < want:
    plug -= 1
    plug += tap
    num += 1
print(num)

Measured memory_bytes: 3060
import heapq
x, y, z, k = map(int, input().split())
a = sorted(map(int, input().split()))[::-1]
b = sorted(map(int, input().split()))[::-1]
c = sorted(map(int, input().split()))[::-1]

print(a[0] + b[0] + c[0])
candidates = []
if x > 1: candidates.append((-(a[1] + b[0] + c[0]), 1, 0, 0))
if y > 1: candidates.append((-(a[0] + b[1] + c[0]), 0, 1, 0))
if z > 1: candidates.append((-(a[0] + b[0] + c[1]), 0, 0, 1))
heapq.heapify(candidates)
popped = {(1, 0, 0): 1,
          (0, 1, 0): 1,
          (0, 0, 1): 1}

for i in range(1, k):
    value, p, q, r = heapq.heappop(candidates)
    print(-value)
    try:
        popped[(p+1, q, r)]
    except:
        if p+1 < x: 
            heapq.heappush(candidates, (-(a[p+1] + b[q] + c[r]), p+1, q, r))
            popped[(p+1, q, r)] = 1
    try:
        popped[(p, q+1, r)]
    except:
        if q+1 < y: 
            heapq.heappush(candidates, (-(a[p] + b[q+1] + c[r]), p, q+1, r))
            popped[(p, q+1, r)] = 1
    try:
        popped[(p, q, r+1)]
    except:
        if r+1 < z: 
            heapq.heappush(candidates, (-(a[p] + b[q] + c[r+1]), p, q, r+1))
            popped[(p, q, r+1)] = 1


Measured memory_bytes: 57816
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100005],b[100005],c[100005];
int main()
{
	ll n,i,q,sum=0,B,C,cha,j;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum+=a[i];
		b[a[i]]++;
	}
	scanf("%lld",&q);
	for(i=1,j=1;i<=q;i++){
		scanf("%lld %lld",&B,&C);
		cha=C-B;
		sum+=b[B]*cha;
		b[C]+=b[B];
		b[B]=0;
		c[j]=sum;
		j++;
	}
	for(i=1;i<j;i++){
		printf("%lld\n",c[i]);
	}
	return 0;
}


Measured memory_bytes: 6168
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int n, ans=0, d=1;
  scanf("%d", &n);
  for (int i=0; i<3; i++) {
    if (n%10 == 1) {
      ans += 9*d;
    }else {
      ans += 1*d;
    }
    d *= 10;
    n /= 10;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


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

		int w, n, pos;
		String string;
		String[] strings;

		w = sc.nextInt();
		n = sc.nextInt();
		int[] endPos = new int[w];
		int[] na = new int[n];
		int[] nb = new int[n];
		for(int i = 0; i < n; i++){
			string = sc.next();
			strings = string.split(",");
			na[i] = Integer.parseInt(strings[0]);
			nb[i] = Integer.parseInt(strings[1]);
		}

		for(int i = 0; i < w; i++){
			pos = i + 1;
			for(int j = 0; j < n; j++){
				if(pos == na[j]) pos = nb[j];
				else if(pos == nb[j]) pos = na[j];
			}
			endPos[pos - 1] = i + 1;
		}

		for(int value: endPos){
			System.out.println(value);
		}
	}
}

Measured memory_bytes: 12000
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i* 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

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

const int INF = 1e9;

vector<int> get_primes(int n) {
  int m = (int)sqrt(n);
  vector<int> primes;
  primes.push_back(2);

  for (int i=3; i<n+1; i++) {
    for (int p: primes) {
      if (i % p == 0) {
        continue;
      }
    }
    primes.push_back(i);
  }
  return primes;
}
int main() {
  int n;
  cin>>n;
  vector<int> primes = get_primes(n);
  map<int, int> m;
  for (int i=2; i<n+1; i++) {
    int j = i;
    for (int p: primes) {
      while (j % p == 0) {
        ++m[p];
        j = j / p;
      }
    }
  }

  int cnt74 = 0;
  int cnt24 = 0;
  int cnt14 = 0;
  int cnt4 = 0;
  int cnt2 = 0;
  for (auto mi: m) {
    int v = mi.second;
    if (v >= 74) {
      ++cnt74;
    }
    if (v >= 24) {
      ++cnt24;
    }
    if (v >= 14) {
      ++cnt14;
    }
    if (v >= 4) {
      ++cnt4;
    }
    if (v >= 2) {
      ++cnt2;
    }
  }
  int ans = 0;
  if (cnt74 > 0) {
    ans += cnt74;
  }
  if (cnt24 > 0) {
    ans += cnt24 * cnt2 - cnt24;
  }
  if (cnt14 > 0) {
    ans += cnt14 * cnt4 - cnt14;
  }
  if (cnt4 > 0) {
    ans += cnt4 * (cnt4 - 1) / 2 * (cnt2 - 2);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var tempArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var N = tempArray[0];
        var K = tempArray[1];
        var Q = tempArray[2];

        var memberPoints = Enumerable.Repeat(K - Q, N).ToList();

        for (var i = 0; i < Q; i++)
        {
            var A = int.Parse(Console.ReadLine());

            memberPoints[A - 1]++;
        }

        var ret = memberPoints.Select(f => f > 0 ? "Yes" : "No").ToList();

        foreach(var i in ret)
        {
            Console.WriteLine(i);
        }
        //Console.WriteLine(string.Join("\n", ret));
        //Console.ReadKey();
    }
}

Measured memory_bytes: 22492
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M, K  = (int(i) for i in input().split())

#graph = np.zeros((N+1, N+1))
#graph2 = [[0] * (N+1) for i in range(N+1)]
uf = UnionFind(N)
fblist = [0] * (N+1)

for i in range(M):
    A, B =  (int(i) for i in input().split())
    uf.union(A, B)
    fblist[A] += 1
    fblist[B] += 1
 
for j in range(K):
    A, B =  (int(i) for i in input().split())
    if uf.same(A, B):
        fblist[A] += 1
        fblist[B] += 1

for i in range(1, N+1):
    print(uf.size(i) - fblist[i] - 1, end=" ")

print()


Measured memory_bytes: 86872
#include <stdio.h>
void sort(int card[5]);
void sort2(int count[4]);

int main(void){
	int card[5], count[4];
	int i;
	while(scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF){
		for(i = 0;i < 4;i++){
			count[i] = 1;
		}
		sort(card);

		for(i = 1;i < 5;i++){
			if(card[0] == card[i]){
				count[0]++;
			} else {
				break;
			}
		}

		for(i = count[0] + 1;i < 5;i++){
			if(card[count[0]] == card[i]){
				count[1]++;
			} else {
				break;
			}
		}

		if(count[0] + count[1] <= 4){
			for(i = count[0] + count[1] + 1;i < 5;i++){
				if(card[count[0] + count[1]] == card[i]){
					count[2]++;
				} else {
					break;
				}
			}

			if(count[0] + count[1] + count[2] <= 4){
				for(i = count[0] + count[1] + count[2] + 1;i < 5;i++){
					if(card[count[0] + count[1] + count[2]] == card[i]){
						count[3]++;
					} else {
						break;
					}
				}
			}
		}

		sort2(count);

		if(count[0] == 4){
			printf("four card\n");
		} else if(count[0] == 3 && count[1] == 2){
			printf("full house\n");
		} else if((card[0] == card[1] - 1 && card[0] == card[2] - 2 && card[0] == card[3] - 3 && card[0] == card[4] - 4)|| (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 && card[4] == 13)){
			printf("straight\n");
		} else if(count[0] == 3){
			printf("three card\n");
		} else if(count[0] == 2 && count[1] == 2){
			printf("two pair\n");
		} else if(count[0] == 2){
			printf("one pair\n");
		} else {
			printf("null\n");
		}
	}

	return 0;
}

void sort(int card[5]){
	int i, j, temp;

	for(i = 0;i < 5;i++){
		for(j = 4;j > i;j--){
			if(card[j] < card[j - 1]){
				temp = card[j - 1];
				card[j - 1] = card[j];
				card[j] = temp;
			}
		}
	}
}


void sort2(int count[4]){
	int i, j, temp;

	for(i = 0;i < 4;i++){
		for(j = 3;j > i;j--){
			if(count[j] > count[j - 1]){
				temp = count[j - 1];
				count[j - 1] = count[j];
				count[j] = temp;
			}
		}
	}
}

Measured memory_bytes: 580
n = int(input())
ll = sorted([list(map(int,input().split())) for _ in range(n)],key=lambda k:k[2])[::-1]
for cx in range(101):
  for cy in range(101):
    ch = ll[0][2]+abs(ll[0][0]-cx)+abs(ll[0][1]-cy)
    for x,y,h in ll:
      if max(ch-abs(x-cx)-abs(y-cy),0) != h:
        break
    else:
      print(cx,cy,ch)
      break
  else:
    continue
  break

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vec dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vec dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

typedef vector<vector<P> > Graph;
vector<int> dijkstra(int s, Graph &G){
  priority_queue<P,vector<P>,greater<P>> que;
  int n = G.size();
  vector<int> dist(n);
  dist.assign(n,INF);
  dist[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.sc;
    REP(i,G[v].size()){
      if(dist[G[v][i].fs] > dist[v]+G[v][i].sc){
        dist[G[v][i].fs] = dist[v]+G[v][i].sc;
        que.push(P(dist[G[v][i].fs],G[v][i].fs));
      }
    }
  }
  return dist;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    Graph edge(3*n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--;y--;
        edge[3*x].pb(P(3*y+1,1));
        edge[3*x+1].pb(P(3*y+2,1));
        edge[3*x+2].pb(P(3*y,1));
    }

    int s,t;
    cin>>s>>t;
    s--;t--;
    vec dist = dijkstra(3*s,edge);
    if(dist[3*t]==INF) cout<<-1<<endl;
    else cout<<dist[3*t]/3<<endl;
    
}

Measured memory_bytes: 19072