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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int N,Q;
VI V,W;
VVI item;
int dp[(1<<9)+1][100001];

void dfs(int v){
    if(v>=N) return;
    int par = (v-1)/2;
    if(v>0) item[v] = VI(item[par]);
    item[v].push_back(v);
    dfs(2*v+1); dfs(2*v+2);
    return;
}

void dfs2(int v){
    if(v>=N || item[v].size()>9) return;
    int par = v==0 ? 0 : (v-1)/2+1;

    REP(i,100001){
        chmax(dp[v+1][i], dp[par][i]);
        if(i+W[v]<=100000) chmax(dp[v+1][i+W[v]], dp[par][i]+V[v]);
    }

    dfs2(2*v+1); dfs2(2*v+2);
    return;
}

int solve(int v, int L){
    int K = item[v].size();
    if(K<=9) return dp[v+1][L];

    int par = (v-1)/2;
    while(item[par].size()>9){
        par = (par-1)/2;
    }
    par++;

    int N = K-9;
    int ans = 0;
    REP(i,1<<N){
        int vv = 0,ww = 0;
        REP(j,N) if(i & (1<<j)){vv += V[item[v][9+j]]; ww += W[item[v][9+j]];}
        if(ww>L) continue;
        vv += dp[par][L-ww];
        chmax(ans, vv);
    }
    return ans;
}

void Main(){
    cin >> N;
    V.resize(N); W.resize(N);
    REP(i,N) cin >> V[i] >> W[i];

    cin >> Q;
    item.resize(N);
    dfs(0); dfs2(0);
    REP(i,Q){
        int v,L;
        cin >> v >> L; v--;
        int ans = solve(v,L);
        cout << ans << en;
    }

    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 246276
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int main() {
	int n;
	int dp1[7][4] = {0}, dp2[7][4] = { 0 };
	int key[1005] = {-1};
	cin >> n;
	for (int i = 1; i <= n; i++) {
		char a;
		cin >> a;
		if (a == 'J') {
			key[i] = 0;
		}
		else if (a == 'O') {
			key[i] = 1;
		}
		else {
			key[i] = 2;
		}
	}
	for (int i = 0; i < 7; i++) {
		if (i == 0 || i == 2 || i == 4 || i == 6) {
			dp1[i][2] = 1;
			dp2[i][2] = 1;
		}
		if (i == 1 || i == 2 || i == 5 || i == 6) {
			dp1[i][1] = 1;
			dp2[i][1] = 1;
		}
		if (i >= 3) {
			dp1[i][0] = 1;
			dp2[i][0] = 1;
		}
		
		if (dp1[i][key[1]] == 1&&dp1[i][0]==1) {
			dp1[i][3] = 1;
		}
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < 7; j++) {
			for (int l = 0; l < 7; l++) {
				if (dp2[l][key[i]] == 1) {
					
					for (int m = 0; m < 3; m++) {
						if (dp1[j][m] != 0) {
							if (dp1[j][m] ==1 &&dp2[l][m]==1) {
							
								dp2[l][3] += dp1[j][3];
								if (dp2[l][3] >= 10007) {
									dp2[l][3] = dp2[l][3] % 10007;
								}
								
								break;
							}

						}
					}
				}
			}
		}
		for (int j = 0; j < 7; j++) {
			dp1[j][3] = dp2[j][3];
			dp2[j][3] = 0;
		}
	}
	int max = 0;
	for (int i = 0; i < 7; i++) {
		max += dp1[i][3];
		
		if (max >= 10007) {
			max = max % 10007;
		}
	}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3092
N, K = map(int, input().split())

# K == 0        complete graph K_N
# K <= N-2      complete graph K_{N-1} + 1 pendant
# K <= N-2+N-3  complete graph K_{N-2} + 2 pendants
# K <= (N-1)*(N-2)//2  (N-1) pendants

def compgraph(n):
    edges = []
    for i in range(n):
        for j in range(i+1, n):
            edges.append((i+1, j+1))
    return edges

def generategraph(N, pendant, K):
    # K_{N - pendant}
    edges = compgraph(N - pendant)
    # pendants
    edges.extend([(1, i+1) for i in range(N - pendant, N)])
    # adjustments
    edges.extend([(i+2, N) for i in range(-K)])
    return edges

for pendant in range(0, N):
    if K <= 0:
        edges = generategraph(N, pendant, K)
        print(len(edges))
        for e in edges:
            print(' '.join(map(str, e)))
        exit()
    K -= N - 2 - pendant

print(-1)


Measured memory_bytes: 3716
/* ===================================*/
/* Author :   MD FAHAD                */
/* Email  :   fahad.mohad99@gmail.com */
/* Institute: HSTU                    */
/* ===================================*/

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / gcd(a,b)))

#define READ_IN freopen("Input.txt","r",stdin)
#define READ_OUT freopen("Output.txt","w",stdout)

typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void)
{
    int A,B;

    cin >> A >> B;

    if(A==1 && B==1)
        cout << "Draw" << "\n";
    else if(A==1)
        cout << "Alice" << "\n";
    else if(B==1)
        cout << "Bob" << "\n";
    else if(A>B)
         cout << "Alice" << "\n";
    else if(B>A)
        cout << "Bob" << "\n";
    else
        cout << "Draw" << "\n";




    return 0;
}



Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

ans = 0.0
(1..[n, k - 1].min).each do |i|
  ans += 1.0 / n * 0.5**(((k.to_f / i).ceil - 1).bit_length)
end
ans += 1.0 / n * [0, n - k + 1].max
puts ans

Measured memory_bytes: 1788
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define deb(x) cerr <<#x<<" = "<<x<<"\n"
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////



/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n;cin >> n;
	int a[n];
	ll x = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		x ^= a[i];
	}
	for(int i=0;i<n;i++){
		cout << (x^a[i]) <<" ";
	}
	cout <<"\n";

}


int main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	/* #ifndef ONLINE_JUDGE
    printf("\nRun Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
    #endif  */
}

Measured memory_bytes: 4384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int ans[100000];
int neighbor[100000];

int main()
{
	int N, M, index = 0, pos;
	int near = -1;
	string S;

	cin >> N >> M >> S;
	pos = N;

	rrep(i, N + 1) {
		if (S[i] == '0') near = i;
		neighbor[i] = near;
	}

	while (pos > 0) {
		int d;
		d = pos - neighbor[max(0, pos - M)];

		if (d <= 0) {
			cout << -1 << endl;
			return 0;
		}

		pos = neighbor[max(0, pos - M)];
		ans[index] = d;
		index++;
	}

	cout << ans[index - 1];
	rrepc(i, index - 2, 0) cout << ' ' << ans[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define mod 998244353
int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    map<LL,LL> hash;
    LL N;
    cin>>N;
    for(LL i=1;i<=99;i++)
    {
        for(LL j=1;j<=99;j++)
        {
            for(LL k=1;k<=99;k++)
            {
                hash[i*i+j*j+k*k+i*k+i*j+k*j]++;
            }
        }
    }
    for(LL i=1;i<=N;i++)
    {
        cout<<hash[i]<<endl;
    }
}


Measured memory_bytes: 5980
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]);
        int y = int.Parse(input[1]);

        for (int i = 0; i <= x; i++)
        {
            int j = x - i;

            if (i * 2 + j * 4 == y)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 27524
import java.util.*;
class Main {
       public static void main(String[] args){
              int a[] = new int[10];
              Scanner docaoa = new Scanner(System.in);
              for (int i = 0; i < 10; i++){
                  a[i] = docaoa.nextInt();
              }
              Arrays.sort(a);
              System.out.println(a[9]);
              System.out.println(a[8]);
              System.out.println(a[7]);        
       }
}

Measured memory_bytes: 26128
N = int(input())
W = list(map(int, input().split()))
res = -1

for i in range(1, N):
  total_l = sum(W[:i])
  total_r = sum(W[i:])
  #print("l" + str(total_l))
  #print("r" + str(total_r))
  s = abs(total_l - total_r) 
  if s < res or res < 0:
    res = s
print(res)

Measured memory_bytes: 3060
n = int(input())
 
s = [str(input()) for i in range(n)]

set_key = list(set(s))
set_key.sort()
dic = dict(zip(set_key, [0]*len(set_key)))

for c in s:
  dic[c] += 1

n_max = max(dic.values())

for c in set_key:
  if dic[c] == n_max:
    print(c)

Measured memory_bytes: 46092
N, K = map(int, input().split())
P = list(map(int, input().split()))
_c = list(map(int, input().split()))

# Cを書き換える
C = [0] * N
for i in range(N):
    P[i] -= 1
    C[i] = _c[P[i]]

m = 31 # bit数

# ダブリング
vertex = list()
score = list()
vertex.append(P)
score.append(C)
for b in range(1, m+1):
    p_bth = [0] * N
    c_bth = [0] * N
    for i in range(N):
        p_bth[i] = vertex[b-1][vertex[b-1][i]]
        c_bth[i] = score[b-1][i] + score[b-1][vertex[b-1][i]]
    vertex.append(p_bth)
    score.append(c_bth)

# 桁DP
MIN = -(1 << 63) 
prv = [[MIN, 0] for _ in range(N)]
nxt = [[MIN, MIN] for _ in range(N)] 
for b in range(m, -1, -1):
    for i in range(N):
        if (K >> b) & 1:
            nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
            nxt[vertex[b][i]][1] = max(nxt[vertex[b][i]][1], prv[i][1] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0], prv[i][1])
        else:
            nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0])
            nxt[i][1] = max(nxt[i][1], prv[i][1])
    prv, nxt = nxt, prv

ans = max(max(x) for x in prv)
if ans == 0:
    ans = max(C)

print(ans)

Measured memory_bytes: 20644
//ITP1_8_C
#include<iostream>
#include<stdio.h>
using namespace std;
	
int moji[26];

int main(){
	int i;
	char ch;
	
	while(cin>>ch){
		if('a'<=ch&&ch<='z')
			moji[ch-'a']++;
			
		else if('A'<=ch&&ch<='Z')
			moji[ch-'A']++;
		else if(ch==EOF)
			break;
	}
	
	for(i=0;i<26;i++)
		cout<<(char)('a'+i)<<" : "<<moji[i]<<endl;
	
	return 0;
}

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

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {

		int W = in.nextInt();
		int H = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		int r = in.nextInt();

		if (0 > x - r || 0 > y - r || W < x + r || H < y + r) {
			out.println("No");
		} else {
			out.println("Yes");
		}
	}
}

Measured memory_bytes: 17284
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

ll gcd(ll a,ll b){
  a=abs(a); b=abs(b);
  if(a==0 || b==0){
    return abs(a+b);
  }
  if(a<b){
    ll tmp=a; a=b; b=tmp;
  }
  ll r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

ll RepSq(ll a,ll n,ll mod){
  if(n==0){
    return 1;
  }else if(n%2!=0){
    return (a*RepSq(a,n-1,mod))%mod;
  }else{
    ll x=RepSq(a,n/2,mod);
    return (x*x)%mod;
  }
}

int main(){
  ll n;
  cin>>n;
  ll mod=1000000007;
  ll a[n],b[n],g[n];
  map<pair<ll,ll>,ll> mp;
  ll iwashinainotoissyo=0;
  rep(i,n){
    cin>>a[i]>>b[i];
    if(a[i]!=0 || b[i]!=0){
      g[i]=gcd(a[i],b[i]);
      a[i]/=g[i]; b[i]/=g[i];
      if(a[i]<0 || (a[i]==0 && b[i]>0)){
        a[i]*=-1; b[i]*=-1;
      }
    mp[make_pair(a[i],b[i])]++;
    }else{
      iwashinainotoissyo++;
    }
  }
  ll ans=1; ll rest=n-iwashinainotoissyo;
  for(auto p:mp){
    ll x,y,z,w;
    x=p.first.first; y=p.first.second;
    z=p.second;
    if(y<0){
      w=mp[make_pair(-y,x)];
      if(w!=0){
        ans=(ans*(RepSq(2,z,mod)+
                  RepSq(2,w,mod)-1))%mod;
        rest=rest-z-w;
      }
    }
  }
  ans=(RepSq(2,rest,mod)*ans)%mod;
  cout<<(ans+mod-1+iwashinainotoissyo)%mod;
}


Measured memory_bytes: 26980
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

ll f(ll x) {
    if (x < 2) return 1;
    else return x*f(x-2); 
}

int main(void) {
    ll N;
    cin >> N;
    ll res = 0;
    // for (int i=0;i<N;i++) cout << i << ": " << f(i) << endl;
    if (N%2 == 0) {
        res += N/10;
        N /= 10;
        while (N) {
            res += N/5;
            N /= 5;
        }
    }
    cout << res << endl;

    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    REP(i,n+1){
        if((int)(i*1.08)==n){
            COUT(i);
            return 0;
        }
    }
    COUT(":(");
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 1e5 + 1;
int n;
int a[N][3], dp[N][3];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
			}
		}
	}
	printf("%d\n", *max_element(dp[n], dp[n] + 3));
}


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

struct Mod {
    static const int N = 998244353;
    long long n;
    Mod() = default;
    Mod(const long long n) : n(n%N) {}
};

Mod operator+(const Mod a, const Mod b) {
    return a.n + b.n;
}

Mod operator+=(Mod& a, const Mod b) {
    return a = a + b;
}

Mod operator*(const Mod a, const Mod b) {
    return a.n * b.n;
}

Mod operator*=(Mod& a, const Mod b) {
    return a = a * b;
}

Mod power(const Mod a, const long long k) {
    if (k == 0) {
        return 1;
    } else if (k % 2 == 0) {
        return power(a*a, k/2);
    } else {
        return a * power(a*a, k/2);
    }
}

Mod inverse(const Mod a) {
    return power(a, Mod::N-2);
}

int main() {
    int N, A, B; long long K;
    cin >> N >> A >> B >> K;

    auto fac = vector<Mod>(N+1);
    fac[0] = 1;
    for (int i = 1; i <= N; i++) {
        fac[i] = fac[i-1] * i;
    }

    auto invfac = vector<Mod>(N+1);
    invfac[N] = inverse(fac[N]);
    for (int i = N; i >= 1; i--) {
        invfac[i-1] = i * invfac[i];
    }

    auto bincoef = [&](const int n, const int k) {
        return fac[n] * invfac[k] * invfac[n-k];
    };

    Mod result = 0;
    for (long long x = 0; x <= N; x++) {
        const long long y = (K - x*A) / B;
        if (0 <= y && y <= N && x*A + y*B == K) {
            result += bincoef(N, int(x)) * bincoef(N, int(y));
        }
    }
    cout << result.n << endl;
}


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

using namespace std;


int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n, max = 0, ans = 0;
    cin >> n;

    while (n--) {
        int a, b;
        cin >> a >> b;
        if(max < a) {
            max = a;
            ans = a + b;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
n=int(input())
a=list(map(int,input().split()))
a.append(0)
stock=0
cash=1000
for i in range(n):
  if a[i]>=a[i+1] and stock==0:
    continue
  elif a[i]<a[i+1] and stock==0:
    stock=cash//a[i]
    cash-=stock*a[i]
  elif a[i]<=a[i+1] and stock!=0:
    continue
  elif a[i]>a[i+1] and stock!=0:
    cash+=stock*a[i]
    stock=0
print(cash)

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

int main(){
    int64_t X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    if(X/D >= K){
        cout << X-K*D << endl;
    }else{
        K -= X/D;
        X %= D;
        if(K%2){
            cout << D-X << endl;
        }else{
            cout << X << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] P = new int[n];
        int s = 0;
        int maxs= 0;
        int ans=0;
        for(int i = 0;i<n;i++){
            P[s] = scan.nextInt();
        
            s+=1;
        }
        
        s= 0;
        maxs = P[0];
        for(int i=0;i<n;i++){
            int r = P[i];
            if(r>maxs){
                maxs =r;
            }
    
        }
        for(int i=0;i<n;i++){
            ans += P[i];
        

        }
        
        System.out.println(ans-maxs+(maxs/2));
        
    }

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll overall = 0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		overall = overall^a[i];
	}
	for(ll i=0;i<n;i++)
		cout<<(ll)(overall^a[i])<<" ";
	cout<<endl;
	return 0;
}

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

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

    string s[110000];

    for(int i =0 ; i<N; i++) cin >> s[i];
    
    int j[4]={};
    for(int i =0 ; i<N; i++){
        if(s[i] == "AC") j[0] += 1;
        else if(s[i] == "WA") j[1] += 1;
        else if(s[i] == "TLE") j[2] += 1;
        else if(s[i] == "RE") j[3] += 1;
    }

    cout << "AC" << " " << "x" << " " << j[0] << endl;
    cout << "WA" << " " << "x" << " " << j[1] << endl;
    cout << "TLE" << " " << "x" << " " << j[2] << endl;
    cout << "RE" << " " << "x" << " " << j[3] << endl;
}


Measured memory_bytes: 7060
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n;
    cin>>n;
    char s[n][n];
    rep(i,n){
        rep(j,n){
            cin>>s[i][j];
        }
    }

    //ヨコだけを考えるO(N^2)までok
    ll ans=0;
    rep(slide,n){
        char t[n][n];
        rep(i,n){
            rep(j,n){
                t[i][(j+slide)%n]=s[i][j];
            }
        }
        bool f=true;
        rep(i,n){
            rep(j,n){
                if(t[i][j]!=t[j][i]){
                    f=false;break;
                }
            }
            if(!f) break;
        }
        if(f) ans+=n;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
# https://atcoder.jp/contests/abc153/submissions/9784108

import numpy as np
i8 = np.int64

def solve(X, H, D):
    xi = np.empty_like(X)
    hi = np.empty_like(H)
    p = 0
    N = X.shape[0]
    for i in range(1, N):
        if X[i] > X[i - 1]:
            xi[p] = X[i - 1]
            hi[p] = H[i - 1]
            p += 1
    xi[p] = X[N - 1]
    hi[p] = H[N - 1]
    p += 1
    area = 2 * D
    res = 0
    sum_right = 0
    sum_left = 0
    left = 0
    for i in range(p):
        while xi[i] - xi[left] > area:
            sum_left += hi[left]
            left += 1
        x = hi[i] - (sum_right - sum_left)
        if x > 0:
            res += x
            sum_right += x
            hi[i] = x
        else:
            hi[i] = 0
    return res


def main(X, H, D, A):
    arg = np.lexsort((H, X))
    X = X[arg]
    H = H[arg]
    H = (H - 1) // A + 1
    print(solve(X, H, D))


if __name__ == '__main__':
    stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
    N, D, A = stdin[:3]
    XH = stdin[3:].reshape((-1, 2)).T
    ans = main(XH[0], XH[1], D, A)


Measured memory_bytes: 23392
a=gets.chomp.to_i
b=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts b[a-1]

Measured memory_bytes: 3836
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int D; cin>>D;
	vector<int> cs(26);
	vector<vector<int>> s(D,vector<int> (26));
	vector<int> last(26,-1);
	rep(i,26)cin>>cs[i];
	rep(i,D)rep(j,26)cin>>s[i][j];
	ll sum = 0;

	vector<int> ans(D);
	rep(d, D){
		int m_type;
		ll m_plus = -INF;
		rep(t, 26){
			int e_ans = s[d][t];
			rep(k, 26){
				if(t == k)continue;
				e_ans -= cs[k] * (d - last[k]);
			}
			if(sum + e_ans > m_plus){
				m_plus = sum + e_ans;
				m_type = t;
			}
		}
		sum = m_plus;
		last[m_type] = d;
		ans[d] = m_type + 1;
	}
	// cout<<sum<<endl;
	rep(i,D)cout<<ans[i]<<endl;
	//cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3684
main(){
	double D,px,py,vx,vy,a;
	for(;scanf("%lf",&D),D!=0;){
		scanf("%lf%lf%lf%lf",&px,&py,&vx,&vy);
		//printf("cross=%e\n",fabs(px*vy-py*vx));
		if(fabs(px*vy-py*vx)<1e-9){
			if(a=hypot(px,py),px*vx+py*vy<0&&D>=a){
				printf("%.8f\n",a);
			}else if(a=2-hypot(px,py),px*vx+py*vy>0&&D>=a){
				printf("%.8f\n",a);
			}else{
				puts("impossible");
			}
		}else{
			puts("impossible");
		}
	}
	exit(0);
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {

    input!{
        n1: i32,
        n2: i32,
        n3: i32,
        n4: i32,
    }
    if n1 == 1 || n2 == 1 || n3 == 1 || n4 == 1 {
        if n1 == 9 || n2 == 9 ||n3 == 9 || n4 == 9 {
            if n1 == 7 || n2 == 7 || n3 == 7 || n4 == 7 {
                if n1 == 4 || n2 == 4 || n3 == 4 || n4 == 4 {
                    println!("YES");
                    return;
                }
            }
        }
    }
    println!("NO");
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

map<ll, ll> mp;
void divisor(ll n) {
  for(ll i=1; i*i<=n; i++) {
    if(n%i==0) {
      mp[i]++;
      mp[n/i]++;
    }
  }
}

int main() {
  ll N;
  cin >> N;
  ll a[MAX*2];
  ll i, j;
  ll cnt[MAX*2]={};
  
  for(i=1; i<=N; i++) {
    cin >> a[i];
  }
  
  vector<ll> v;
  for(i=N; i>=1; i--) {
    if(a[i]!=cnt[i]) {
      v.pb(i);
      mp.clear();
      divisor(i);
      for(auto it=mp.begin(); it!=mp.end(); it++) {
        
        cnt[it->ft]=1-cnt[it->ft];
      }
    }
  }
  
  pt(v.size());
  for(i=0; i<v.size(); i++)
    pt(v[i]);
  
}













Measured memory_bytes: 5376
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0

for i in range(N):
    ans += min(A[i],B[i])
    B[i] -= min(A[i],B[i])
    ans += min(A[i+1],B[i])
    A[i+1] -= min(A[i+1],B[i])

print(ans)

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

int main(){
	int N;
	cin >> N;
	string s[N];
	for(int i=0;i<N;i++){
		cin >> s[i];
	}
	int M;
	cin >> M;
	string t[M];
	for(int i=0;i<M;i++){
		cin >> t[i];
	}
	
	int value,ans=0;
	
	for(int i=0;i<N;i++){
		value=0;
		for(int j=0;j<N;j++){
			if(s[i]==s[j]) value++;
		}
		for(int j=0;j<M;j++){
			if(s[i]==t[j]) value--;
		}
		if(value>ans) ans=value;
	}
	
	cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int cnt = 0;
		int candySum = 0;
		int childNum = in.nextInt();
		for(cnt = 0;cnt < childNum+1;cnt++ ){
			candySum = candySum + cnt;
		}
		System.out.println(candySum);
	}
}

Measured memory_bytes: 9548
import java.util.*

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? = withIndex().maxBy{it.value}?.index
fun <T : Comparable<T>> Iterable<T>.argmin(): Int? = withIndex().minBy{it.value}?.index

fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val n = reader.readLine()!!.toInt()
    var s = Array(n, {
        val (s, p) = reader.readLine()!!.split(" ")
        Triple(s, p.toInt(), it+1)
    })

    s = s.sortedWith(Comparator<Triple<String, Int, Int>> { left, right ->
        if (left.first != right.first) {
            left.first.compareTo(right.first)
        } else {
            -left.second.compareTo(right.second)
        }
    }).toTypedArray()

    for (i in 0..n-1) {
        println(s[i].third)
    }
}


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

int main() 
{
  int n;
  cin >> n;
  int flag =0;
  int i =2,k =100;
  while(n>0 )
  {
      int digit = n/k;
      if(digit  == 7 )
        {   flag = 1;
            break;
        }
      n = n%k;
      i--;
      k = k/10;

  }
if( flag == 1)
{
    cout << "Yes";
}  
else cout << "No";

}


Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
  long long N;int sz=0;char str[12];
  if(!scanf("%lld",&N))return 0;
  while(N){N--;str[sz++]=97+N%26;N/=26;}
  for(int i=0;i<sz;i++)printf("%c",str[sz-i-1]);
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int n, m;

int fa[maxn];
int x, y, ans;

int find(int x){
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++) fa[i] = i;
	while(m--){
		scanf("%d%d", &x, &y);
		x = find(x), y = find(y);
		if(x == y) continue;
		fa[x] = y, ans++;
	}
	printf("%d", n - 1 - ans);
}

Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll a,b,p;

ll solve() {
	ll n=b-a+1;
	vector<ll> dp(n,1);
	unordered_map<ll,ll> preff;
	ll sum=0;
	for(ll i=n-1; i>=0; i--) {
		ll tmp1=a+i;
		string tmp2=to_string(tmp1);
		dp[i]+=sum;
		string buf="";
		REP(j,tmp2.size()) {
			for(char c='0'; c<tmp2[j]; c++) {
				if(preff.count(stol(buf+c))) {
					dp[i]-=preff[stol(buf+c)];
				}
			}
			buf+=tmp2[j];
		}
		dp[i]=(dp[i]%p+p)%p;
		while(tmp1>0) {
			preff[tmp1]+=dp[i];
			preff[tmp1]%=p;
			tmp1/=10;
		}
		sum+=dp[i];
		sum%=p;
	}
	return sum;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>a>>b>>p;
		if(a==0&&b==0&&p==0) break;
		cout<<solve()<<endl;
	}
}



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

long long int calc(vector<int> &s, vector<int> &plus) {
  long long int ans = 0, tmp = 0;
  int pl1 = 0, pl2 = 0;
  for(int i = 0; i < plus.size(); i++) {
    pl1 = pl2;
    pl2 = plus.at(i);
    for(int j = pl1; j < pl2; j++) {
      tmp = tmp * 10 + s.at(j);
    }
    ans += tmp;
    tmp = 0;
  }
  for(int i = pl2; i < s.size(); i++)
    tmp = tmp * 10 + s.at(i);
  ans += tmp;
  return ans;
}

long long int many_form(vector<int> &s, vector<int> &plus) {
  long long int ans = 0;
  if(plus.empty()) {
    for(int i = 1; i < s.size(); i++) {
      plus.push_back(i);
      ans += many_form(s, plus);
      plus.pop_back();
    }
  } else {
    for(int i = plus.at(plus.size() - 1) + 1; i < s.size(); i++) {
      plus.push_back(i);
      ans += many_form(s, plus);
      plus.pop_back();
    }
  }
  return ans + calc(s, plus);
}

int main() {
  long long int S;
  cin >> S;
  vector<int> s;
  while(true) {
    s.push_back(S % 10);
    if(S / 10) {
      S /= 10;
    } else {
      break;
    }
  }
  reverse(s.begin(), s.end());
  vector<int> plus;
  cout << many_form(s, plus) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}


Measured memory_bytes: 2528
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
const int mxn=10000005;
vector<int> p;
map<int,bool> mp;
ll a,b;

void fact(ll a)
{
  for(ll i=2;i*i<=a;i++)
  {
    if(a%i==0)
    {
      while(a%i==0)
        a/=i;
      if(!mp[i])
      {
        p.pb(i);
        mp[i]=1;
      }
    }
  }
  if(a!=1)if(!mp[a])
  {
    p.pb(a);
    mp[a]=1;
  }
} 

int main()
{
  fastio;
  p.pb(1);
  cin>>a>>b;
  fact(__gcd(a,b));
  int ans=0;
  for(int i=0;i<p.size();i++)
  {
      ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3576
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{

        List<int> a = new List<int>();
        List<int> b = new List<int>();

        //string[] s = Console.ReadLine().Split(' ');

        // int a = int.Parse(Console.ReadLine());

        while(true)
        {
            string[] s = Console.ReadLine().Split(' ');

            int c = int.Parse(s[0]);
			int d = int.Parse(s[1]);

            if(c==0&&d==0)
            {
                break;
            }
            else
            {
                if(c>d)
                {
                    int tmp = c;
                    c = d;
                    d = tmp;
                }
				a.Add(c);
				b.Add(d);
            }

        }

        for (int i = 0; i < a.Count;i++)
        {
            Console.WriteLine("{0} {1}",a[i],b[i]);
        }

		//Console.WriteLine("");


	}
}

Measured memory_bytes: 9300
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int cnt = 0;

		for(int i = 0; i < 3; i++){
			if(a.charAt(i)==b.charAt(i)){
				cnt++;
			}
		}
		System.out.print(cnt);
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath> 

using namespace std;

int main()
{
	int a,b,h,m;
	double ans;
	cin>>a>>b>>h>>m;
	double degree;
	degree=fabs((0.5*m+h*30)-6*m);
	ans=sqrt(a*a+b*b-2*a*b*cos(degree*acos(-1)/180));
	printf("%.20f\n",ans);
	return 0;
 } 

Measured memory_bytes: 4152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
int main(){
  int tmp;
  cin >>tmp;
  if(tmp>=30)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
/*
テストケースの出力
*/

#include<stdio.h>

int main(void){
  int x;
  int count;

  count = 1;
  while(1){
    scanf("%d",&x);
    if(x == 0)
      break;
    printf("Case %d: %d\n",count,x);
    count++;
  }
  return 0;
}  


Measured memory_bytes: 2584
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		int count = 0;
		for (int i = 0; i < n - 1; i++) {
			if (p[i] == i + 1) {
				p[i] = p[i + 1];
				p[i + 1] = i + 1;
				count++;
			}
		}
		if (p[n - 1] == n) {
			count++;
		}
		System.out.println(count);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

import static java.lang.System.in;

public class Main {
    static long ans=0;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] sum = new long[n+1];
        for(int i=1;i<=n;i++) sum[i] = sum[i-1]+sc.nextLong()-k;
        long[] temp = new long[n+1];
        // mean >= k ==> sum >= 0 (every a[i]=a[i]-k)
        merge(0,n,sum,temp);
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
    }
    static void merge(int left, int right, long[] sum, long[] temp){
        if(left>=right) return;
        int mid = (left+right)/2;
        merge(left,mid,sum,temp);
        merge(mid+1,right,sum,temp);
        // suppose left part and right part are sorted respectively
        int start = mid+1;
        for(int i=left;i<=mid;i++){
            while(start<=right&&sum[start]-sum[i]<0) start++;
            ans += right+1-start;
        }
        int k=left,i=left,j=mid+1;
        while(i<=mid&&j<=right){
            if(sum[i]<sum[j]) temp[k++] = sum[i++];
            else temp[k++] = sum[j++];
        }
        while(i<=mid) temp[k++] = sum[i++];
        while(j<=right) temp[k++] = sum[j++];
        for(int m=left;m<=right;m++) sum[m] = temp[m];
    }
}


Measured memory_bytes: 89832
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 9;
const int INF = 1 << 29;

int main() {
  string S;
  cin >> S;
  int l = S.length() - 1;
  long ans = 0;
  for (int bit = 0; bit < (1 << l); ++bit) {
    vector<int> ix;
    for (int i = 0; i < l; ++i) {
      if (bit & (1 << i)) ix.push_back(i);
    }
    ix.push_back(INF);
    int begin = 0;
    for (int i = 0; i < ix.size(); ++i) {
      ans += stol(S.substr(begin, ix[i] + 1 - begin));
      begin = ix[i] + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 2e12
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2;
ll i,n,m,g,s;
ii a[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,0,n)
        cin>>a[i].f>>a[i].se;
    sort(a,a + n);
    rep(i,0,n){
        g = min(m,a[i].se);
        s += g * a[i].f;
        m -= g;
    }
    cout<<s;
    return 0;
}

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

int main() {
	string s;
	int x=0;
	cin >> s;
	if(s.at(0) == '1') {
		x++;
	}
	if(s.at(1) == '1') {
		x++;
	}
	if(s.at(2) == '1') {
		x++;
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+1;
const int md=1e9+7;

void inc(int &x,int y){
	x=x+y>=md?x+y-md:x+y;
}

int n,c[maxn],f[maxn];
vector<int>son[maxn];
int pos[maxn],tot;
int cnt[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1,x;i<=n;++i){
		scanf("%d",&x);
		if (x!=c[tot]) c[++tot]=x;
	}
	n=tot;
	f[0]=1;
	for (int i=1;i<=n;++i){
		f[i]=f[i-1];
		inc(f[i],cnt[c[i]]);
		inc(cnt[c[i]],f[i-1]);
	}
	printf("%d\n",f[n]);
}

Measured memory_bytes: 7296
from networkx import*
H,*S=open(0)
H,W=map(int,H.split())
g=Graph()
for i in range(m:=H*W):g.add_weighted_edges_from([[m*2,h:=i//W,I:=m*3],[m*2,w:=i%W+m,I]]*((c:=S[h][w-m])=='S')+[[h,I,I],[w,I,I]]*(c=='T')+[[h,w,1],[w,h,1]]*(c>'T'))
print([-1,f:=minimum_cut(g,m*2,I,'weight')[0]][f<I])

Measured memory_bytes: 63716
# coding=utf-8

class Node:
    def __init__(self, idx, degree, children=None):
        self.id = idx
        self.parent = -1 #??????
        self.depth = 0 #??????
        self.type = None #??????
        self.children = children

n = int(input())
data = [list(map(int, input().split())) for x in range(n)]
node_list = [None for i in range(n)]

for data_row in data:
    idx, degree, *children = data_row
    node = Node(idx, degree, children)
    node_list[idx] = node

### set parent & type ###
for node in node_list:
    i = node.id
    if node.children:
        node.type = "internal node"
        for child in node.children:
            node_list[child].parent = i
    else:
        node.type = "leaf"

### calc depth ###
for i, node in enumerate(node_list):
    depth = 0
    parent = node.parent
    #?????\???type
    if parent == -1:
        node.type = "root"
    while parent != -1:
        parent = node_list[parent].parent
        depth += 1
    node.depth = depth

for node in node_list:
    print("node {}: parent = {}, depth = {}, {}, {}".format(node.id, node.parent, node.depth, node.type, node.children))

Measured memory_bytes: 68488