akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# coding: utf-8

"""
input:
3 3
0 1
0 2
1 2

output:
0
"""

import sys


def generate_graph_table(edges):
    for edge in edges:
        source, target = map(int, edge)
        init_adj_table[source].append(target)

    return init_adj_table


def graph_dfs(current, visited, stack):
    if not visited[current]:
        visited[current] = True
        stack[current] = True

        for adj in adj_table[current]:
            if not visited[adj] and graph_dfs(adj, visited, stack):
                return True
            elif stack[adj]:
                return True

    stack[current] = False
    return False


def check_cyclic():
    visited, stack = ([False] * v_num for _ in range(2))
    for v in range(v_num):
        if graph_dfs(v, visited, stack):
            return True
    return False


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    c_edges = map(lambda x: x.split(), _input[1:])

    init_adj_table = tuple(list() for _ in range(v_num))
    adj_table = generate_graph_table(c_edges)

    print(int(check_cyclic()))

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

vll calc(ll x){
  vll v;
  for (int l=0;l<100;l++){
    ll c=x%2;
    v.push_back(c);
    x/=2;
  }
  return v;
}

vll counter(vll& x){
  ll N=x.size();
  vll cnt(100);
  for (int l=0;l<100;l++){
    cnt[l]=0;
  }

  for(ll i=0;i<N;i++){
    vll v=calc(x[i]);
    for(ll l=0;l<100;l++){
      cnt[l]+=v[l];
    }
  }
  return cnt;
}

int main(){
  //入力の受け取り
  ll N,K;cin>>N>>K;
  vll x;
  for(ll i=0;i<N;i++){
    ll a;cin>>a;
    x.push_back(a);
  }
  //各桁の買ううんとをした。
  vll count=counter(x);
  //Kをbinary representした。
  vll bin_K=calc(K);

  //maxを与えるXを求める。
  ll X=0;
  int flag=0;
  //大きい方から決めてく。
  for(int l=99;l>=0;l--){
    //X_lは、Xのl桁目？
    int X_l=0;
    //Kの上位とXの上位が一致していて、かつKのl桁目が0だったり
    if((flag==0)&&(bin_K[l]==0)){
      X+=0;
    }
    //Nが偶数かつ個数が拮抗七衛うなら。
    else{
      if((N%2==0) and(count[l]==N/2)){
        X+=0;
      }
      else if(count[l]<=N/2){
        //1が真に少数派ならpow(2,l)をたす。
        X+=pow(2,l);
        X_l=1;
      }
      else{
        X+=0;
      }
    }

    if (X_l!=bin_K[l]){
      //Kのl桁目とXのl桁目が一致していないなら、flag=1。上から決めてるからね。
      flag=1;
    }
  }
  //最後に、実際の値を計算する。
  ll ans=0;
  for (ll i=0;i<N;i++){
    ans+=X^x[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    string S;
    cin>>S;
    cout<<"2018"<<S.substr(4)<<endl;
    return 0;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
    }
    deque<int> DQ;
    if(N % 2 == 0){
        for(int i = 0;i<N;i++){
            if(i % 2 == 0){
                DQ.push_back(retu.at(i));
            }
            else{
                DQ.push_front(retu.at(i));
            }
        }
    }
    else{
        for(int i = 0;i<N;i++){
            if(i % 2 == 0){
                DQ.push_front(retu.at(i));
            }
            else{
                DQ.push_back(retu.at(i));
            }
        }
    }
    for(int V : DQ) cout << V << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
using namespace std;

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

	int max = INT_MIN;
	if (a - b > max)
		max = a - b;
	if (a * b > max)
		max = a * b;
	if (a + b > max)
		max = a + b;

	cout << max;
}

Measured memory_bytes: 3552
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    H, W = read_values()
    C = tuple(read_index())
    D = tuple(read_index())
    S = [input().strip() for _ in range(H)]

    F = [False] * (H * W)

    M = {C}
    Q = [C]
    F[C[0] * W + C[1]] = 0
    c = 0
    while len(M) > 0:
        M.clear()
        while Q:
            h, w = Q.pop()
            M.add((h, w))
            if (h, w) == D:
                print(c)
                return

            for d in (1, -1):
                if 0 <= w + d < W and S[h][w + d] == "." and not F[h * W + w + d]:
                    F[h * W + w + d] = True
                    Q.append((h, w + d))
                if 0 <= h + d < H and S[h + d][w] == "." and not F[(h + d) * W + w]:
                    F[(h + d) * W + w] = True
                    Q.append((h + d, w))
        for h, w in M:
            for hh in range(h - 2, h + 3):
                for ww in range(w - 2, w + 3):
                    if 0 <= ww < W and 0 <= hh < H and S[hh][ww] == "." and not F[hh * W + ww]:
                        F[hh * W + ww] = True
                        Q.append((hh, ww))
        c += 1
    print(-1)
            

if __name__ == "__main__":
    main()



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

using namespace std;

bool is_present(int n) {
	while(n) {
		int d = n%10;
		if(d == 7) {
			return true;
		}
		
		n /= 10;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	
	if(is_present(n)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

class Card{
    public String suit;
    public int value;
    public int index;
}

public class Main{
    public static void main(String[] args){
	int i, q;
	
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
    	Card[] A = new Card[n];

	for(i=0; i<n; i++){
	    A[i] = new Card();
	}

	for(i=0; i<n; i++){
	    A[i].suit = s.next();
	    A[i].value = s.nextInt();
	    A[i].index = i; 
	}

	quickSort(A, n, 0, n-1);

	if(isStable(A) == true){
	    System.out.print("Stable\n");
	}else{
	    System.out.print("Not stable\n");
	}
	for(i=0; i<n; i++){
	    System.out.printf("%s %d\n", A[i].suit, A[i].value);
	    
	}
    }

    public static void quickSort(Card[] A, int n, int p, int r){
	int q;
	if(p < r){
	    q = partition(A, n, p, r);
	    quickSort(A, n, p, q - 1);
	    quickSort(A, n, q + 1, r); 
	}
    }
    
    public static int partition(Card[] A, int n, int p, int r){
	int x, i, j;
	Card tmp;
	x = A[r].value;
	i = p-1;
	for(j=p; j<r; j++){
	    if(A[j].value<=x){
		i++;
		tmp = A[i]; A[i] = A[j]; A[j] = tmp;
	    }
	}
	tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp;
	return i+1;
    }
    
    static boolean isStable(Card[] A){
	for(int i = 0; i < A.length; i++){
	    for(int j = i + 1; j < A.length; j++){
		if(A[i].value == A[j].value && A[i].index > A[j].index)
		    return false;
	    }
	}
    return true;
    }	    
}

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

int main() {
    // your code goes here
    ll n,i,t[55],ans=0;
    bool ok=false;
    char s[55][105],m[105];
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> s[i] >> t[i];
    }
    cin >> m;
    for(i=1;i<=n;i++){
        if(ok) ans+=t[i];
        if(strcmp(s[i],m)==0) ok=true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){

    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool IsPrime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for(ll i = 3; i <= sqrtNum; i += 2){
        if(num%i==0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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



signed main(){
  int a,b; cin>>a>>b;
  cout << lcm(a,b) << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int R = sc.nextInt();
        int S = sc.nextInt();
        int P = sc.nextInt();
        String T = sc.next();

        System.out.println(solve(N, K, R, S, P, T));
    }

    private static int solve(int N, int K, int R, int S, int P, String T) {
        int[][] score = new int[N+1][3];

        for (int i=0; i<N; i++) {
            char ch = T.charAt(i);

            if (i < K) {
                score[i+1][0] = max(score[i]) + toScore(R, S, P, ch, 'r');
                score[i+1][1] = max(score[i]) + toScore(R, S, P, ch, 's');
                score[i+1][2] = max(score[i]) + toScore(R, S, P, ch, 'p');
            } else {
                score[i+1][0] = max(score[i]) - max(score[i+1-K]) + Math.max(score[i+1-K][1], score[i+1-K][2]) + toScore(R, S, P, ch, 'r');
                score[i+1][1] = max(score[i]) - max(score[i+1-K])+ Math.max(score[i+1-K][2], score[i+1-K][0]) + toScore(R, S, P, ch, 's');
                score[i+1][2] = max(score[i]) - max(score[i+1-K]) + Math.max(score[i+1-K][0], score[i+1-K][1]) + toScore(R, S, P, ch, 'p');
            }

            // System.err.println((i+1) + ": " + score[i+1][0] + ", " + score[i+1][1] + ", " + score[i+1][2]);
        }

        return max(score[N]);
    }

    private static int toScore(int R, int S, int P, char t, char s) {
        if (t == 'r' && s == 'p') return P;
        if (t == 'p' && s == 's') return S;
        if (t == 's' && s == 'r') return R;

        return 0;
    }

    private static int max(int[] array) {
        int max = array[0];
        for (int i=1; i<array.length; i++) {
            max = Math.max(max, array[i]);
        }

        return max;
    }
}

Measured memory_bytes: 29636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    long long int X;
    cin >> X;
    int yr=0;
    long long int yokin=100;
    while(yokin<X){
        yokin *= 1.01;
        yr++;
    }
    cout << yr << endl;
}

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

int main() {
    string S;
    cin>>S;
    if(S.size()>=4){
        if(S.at(0)=='Y'){
            if(S.at(1)=='A'){
                if(S.at(2)=='K'){
                    if(S.at(3)=='I'){
                        cout<<"Yes"<<endl;
                            return 0;
                    }
                }
            }    
        }
    }else{
        cout<<"No"<<endl;
        return 0;
    }
cout<<"No"<<endl;
return 0;}
/*
g++ code.cpp
./a.out
*/

Measured memory_bytes: 256
#include <stdio.h>

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

int main(){
	int n, a[210000];
	scanf("%d", &n);
	REP(i, n) scanf("%d", a + i);
	REP(i, (n + 1)/2) printf("%d ", a[n - i * 2 - 1]);
	FOR(i, (n + 1)/2, n) printf("%d ", a[i * 2 - n]);
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int h, w;
bool used[1005][1005];
vector<string> s, v(2);

int func(int i, int j) {
	int ret = 0;
	if(i-1 >= 0 && j-1 >= 0) {
		if(s[i-1][j-1] == v[0][0] && s[i-1][j] == v[0][1] && s[i][j-1] == v[1][0] && s[i][j] == v[1][1]) {
			ret++;
		}
	}

	if(i-1 >= 0 && j+1 < w) {
		if(s[i-1][j] == v[0][0] && s[i-1][j+1] == v[0][1] && s[i][j] == v[1][0] && s[i][j+1] == v[1][1]) {
			ret++;
		}
	}
	if(i+1 < h && j-1 >= 0) {
		if(s[i][j-1] == v[0][0] && s[i][j] == v[0][1] && s[i+1][j-1] == v[1][0] && s[i+1][j] == v[1][1]) {
			ret++;
		}
	}

	if(i+1 < h && j+1 < w) {
		if(s[i][j] == v[0][0] && s[i][j+1] == v[0][1] && s[i+1][j] == v[1][0] && s[i+1][j+1] == v[1][1]) {
			ret++;
		}
	}
	return ret;
}

int main() {
	cin >> h >> w;

	s.resize(h);

	rep(i, h) cin >> s[i];
	rep(i, 2) cin >> v[i];

	int ans = 0;
	memset(used, 0, sizeof(used));

	rep(i, h-1) {
		rep(j, w-1) {
			if(s[i][j] == v[0][0] && s[i][j+1] == v[0][1] && s[i+1][j] == v[1][0] && s[i+1][j+1] == v[1][1]) {
				ans++;
				used[i][j] = true;
				used[i][j+1] = true;
				used[i+1][j] = true;
				used[i+1][j+1] = true;
			}
		}
	}

	int res = 0;
	rep(i, h) {
		rep(j, w) {
			int t = func(i, j), t2 = 0;
			char c = s[i][j];

			s[i][j] = 'J';
			t2 = func(i, j);
			res = max(res, t2 - t);

			s[i][j] = 'O';
			t2 = func(i, j);
			res = max(res, t2 - t);

			s[i][j] = 'I';
			t2 = func(i, j);
			res = max(res, t2 - t);

			s[i][j] = c;
		}
	}

	cout << ans + res << endl;

	return 0;
}

Measured memory_bytes: 3120
import java.util.Scanner;

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

    long MOD = 1_000_000_007;
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] s = new int[N];
    int[] t = new int[M];
    for (int i = 0; i < N; i++) s[i] = scanner.nextInt();
    for (int i = 0; i < M; i++) t[i] = scanner.nextInt();

    long[][] dp = new long[N + 1][M + 1];
    for (int i = 0; i < N + 1; i++) dp[i][0] = 1;
    for (int i = 0; i < M + 1; i++) dp[0][i] = 1;
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= M; j++) {
        dp[i][j] = dp[i - 1][j];
        dp[i][j] += dp[i][j - 1];
        if (dp[i][j] >= MOD) dp[i][j] -= MOD;
        if (s[i - 1] != t[j - 1]) {
          dp[i][j] -= dp[i - 1][j - 1];
          if (dp[i][j] < 0) dp[i][j] += MOD;
        }
      }
    }
    System.out.println(dp[N][M]);
  }
}


Measured memory_bytes: 82660
n = int(raw_input())
p = [0 for i in range(0, 101)]
m = [[0 for i in range(0, 101)] for j in range(0, 101)]

for i in range(1, n+1):
    p[i-1], p[i] = map(int, raw_input().split())
     
for l in range(2, n+1):
    for i in range(1, n-l+2):
        j = i+l-1
        m[i][j] = float("inf")
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])
 
print m[1][n]

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

using namespace std;
typedef long long ll;

int N, M;
int A[110];

int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++) cin >> A[i];
    int sum = 0;
    for(int i=0;i<N;i++) sum += A[i];
    int c = 0;
    for(int i=0;i<N;i++){
        if(sum <= A[i] * 4 * M) c++;
    }
    if(c >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,A,B,K = map(int,input().split())
n = 0
MOD = 998244353
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


memo = [0]*(N+1)
memo[0] = memo[N] = 1
for k in range(1,N//2+1):
  v = memo[k-1]*(N-k+1)*modinv(k,MOD)
  v %= MOD
  memo[k] = memo[N-k] = v
for i in range(N+1):
    j = K-A*i
    if j < 0:
        break
    if j%B==0 and j/B <= N:
        j //= B
        n+=memo[i]*memo[j]
        n%=998244353
print(n%998244353)

Measured memory_bytes: 11708
s = input()
n = len(s)

g, p = 0, 0
ans = 0
for i in range(n):
  if g == p:
    g += 1
    if s[i] == "p":
      ans -= 1
  else:
    p += 1
    if s[i] == "g":
      ans += 1

print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;


class Main{
    public static void main(String[] a){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) {
				break;
			} else if (n != 0) {
				int ua = 0;
				int ub = 0;
				for(int i=0; i<n; i++) {
					int va = sc.nextInt();
					int vb = sc.nextInt();
					if (va > vb) {
						ua += va+vb;
					} else if (vb > va) {
						ub += va + vb;
					} else {
						ua += va;
						ub += vb;
					}
				}
				System.out.println(ua + " " + ub);
			}
		}
	}
}

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

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

int main() {
    int N;
    cin >> N;
    int x = f(N);
    if (N%x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <set>

using namespace std;

int N;
string S;

set<pair<int, int> > T[5005];

int C[5005][5005];


int main(void) {

	cin >> N;
	cin >> S;

	
	for (int j = N - 1; j >= 1; j--) {

		for(int i=j+1;i>=0;i--){

			if (S[i] != S[j]) { C[i][j] = 0; }
			else {
				int k = C[i + 1][j + 1];
				C[i][j] = C[i + 1][j + 1] + 1;
				if (i + k >= j) { C[i][j] = 0; }
			}

		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans = max(ans, C[i][j]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 97024
#include <iostream>

using namespace std;

int main(){
    double n;
    int k;
    cin >> n >> k;

    double sum = 0;
    for(int i = 1; i <= n; i++){
        double x = 1;
        double y = i;
        while(y < k){
            x *= 1.0/2.0;
            y *= 2;
        }
        sum += (1.0/n) * x;
    }

    printf("%.14f\n", sum);
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return

    ans = 1
    for i in range(N):
        ans *= A[i]
        if ans > 10 ** 18:
            print(-1)
            return

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22316
n,w=map(int,input().split())
mer=[list(map(int,input().split())) for i in range(n)]
dp=[[0]*(w+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(w+1):
        if j>=mer[i-1][0]:
            dp[i][j]=mer[i-1][1]+dp[i-1][j-mer[i-1][0]]
        dp[i][j]=max(dp[i][j],dp[i-1][j])
print(dp[-1][-1])

Measured memory_bytes: 120940
n, k = list(map(int, input().split()))
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans = Base_10_to_n(n, k)
print(len(ans))


Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
ans = 0
MOD = 10**9+7

for i in range(K, N+2):
    low = i*(i-1)//2
    up = i*(2*N-i+1)//2
    ans += up-low+1
    ans %= MOD

print(ans)

Measured memory_bytes: 68156
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadLongArray();
	long a = tmp[0], b = tmp[1], c = tmp[2];

	long c2Eat = Math.Min(a+b+1, c);
	WriteLine(c2Eat + b);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

class B{
public:
  int x1, y1, x2, y2;
  string to;
  B(){}
  B(int x1, int y1, int x2, int y2, string to) : x1(x1), y1(y1), x2(x2), y2(y2), to(to) {}
};

int n, h, w, b[100], m;
vector<B> buttons[100];
string name[100];
map<string, int> stoi;

int clicked(int x, int y, int p){
  for(int i=0;i<b[p];i++){
    B but = buttons[p][i];
    if(but.x1 <= x && x <= but.x2 && but.y1 <= y && y <= but.y2) return stoi[but.to];
  }
  return -1;
}

main(){
  while(cin >> n && n){
    stoi.clear();
    for(int i=0;i<n;i++) buttons[i].clear();
    cin >> w >> h;
    for(int i=0;i<n;i++){
      cin >> name[i];
      cin >> b[i];
      stoi[name[i]] = i;
      for(int j=0;j<b[i];j++){
        B in;
        cin >> in.x1 >> in.y1 >> in.x2 >> in.y2 >> in.to;
        buttons[i].push_back(in);
      }
    }
    cin >> m;
    int p = 0;
    vector<int> buf;
    buf.push_back(0);
    for(int i=0;i<m;i++){
      string str;
      cin >> str;
      if(str == "forward"){
        if(p+1 < buf.size()) p++;
      }else if(str == "back"){
        if(p != 0) p--;
      }else if(str == "show"){
        cout << name[buf[p]] << endl;
      }else{
        int x, y;
        cin >> x >> y;
        int next = clicked(x, y, buf[p]);
        if(next == -1) continue;
        if(p+1 < buf.size()) buf.erase(buf.begin() + p+1, buf.end());
        buf.push_back(next);
        p++;
      }
    }
  }
}

Measured memory_bytes: 0
/*
memo
????????°??????

*/

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

int m, n;
int ma[300];
int ka[300][300];
vector<int> g[300];
bool go[300], ba[300];
void iki(int x)
{
	//????????§????????¨????????????????????????

	//????????????????????´??????????????????????????°?????¨??????
	//????????´??????????????°???????????????
	//???????????????????????§??????????????¶???????????????????????????????????£???
	//??????????????°????????????????????°????????????????????°?????¨???????????????????????????
	//?????????????????????????????°?????¨??°?????°????????´???????¨???????????????????
	//????????????????????´???????????£???????????´???????????????????????????????????????
	//??´?????????????????????????????´??????????§???????????????????????????????????????´????????????????????¨??????????????°????????????????????????????????????

	int i;

	if (go[x]) return;
	go[x] = true;				//????????°??????
	if (x == n + 1) return;
	for (i = 1; i <= m; i++)
	{
		int y = x + i;
		if (y <= n+1)
		{
			y = y + ma[y];
			if (y>0)
			{
				if (y > n + 1) y = n + 1;
				if (ka[y][x] == 1)continue;
				ka[y][x] = 1;

				g[y].push_back(x);
				iki(y);
			}
		}

	}
	return;
}

void kae(int x)
{
	//????????§?????°?????¨????????´???????????????????????????????????¨???????????????????????????

	//????????????????????´?????????????§??????¨??????????????????????????°????????????????????§???????????´?????????????????????
	//??????????????§?????£?????´??????????????¨?????????????????°???????????????


	int i;
	if (ba[x]) return;
	ba[x] = true;
	if (x == 0) return;
	for (i = 0; i<g[x].size(); i++)
	{
		kae(g[x][i]);
	}
	return;
}

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

		//---------------?????????--------------------//
		for (i = 0; i<300; i++)
		{
			g[i].clear();
			ma[i] = 0;
			for (int j = 0; j<300; j++)
			{
				ka[i][j] = 0;
			}
		}
		memset(go, 0, sizeof(go));
		memset(ba, 0, sizeof(ba));


		for (i = 1; i <= n; i++)
		{
			cin >> ma[i];
		}
		ma[0] = ma[n + 1] = 0;

		iki(0);
		kae(n + 1);


		/*
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << go[i] << "  " ;
		}
		cout << endl;
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << ba[i] << "  ";
		}
		*/



		for (i = 0; i <= n + 1; i++)
		{
			if (go[i])
			{
				if (ba[i] == 0)
				{
					cout << "NG\n";
					break;
				}
			}
			if (i == n + 1) cout << "OK\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3484
#include <stdio.h>

int main () {
	int i, j, n, x, y, z;
	int m[200][200] = { 0 };

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &x);
		scanf("%d", &y);

		for (j = 0; j < y; j++) {
			scanf("%d", &z);
			m[x - 1][z - 1]++;
		}
	}
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			printf("%d", m[i][j]);

			if (j != n - 1) {
				putchar(' ');
			}
		}
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 2144
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        String S = scan.next();

        int state = 0;
        int ans = 0;
        for(int i = 0; i < S.length(); i++){
            switch (state) {
                case 0: {
                    if (S.charAt(i) == 'A')
                        state = 1;
                    break;
                }

                case 1: {
                    if (S.charAt(i) == 'A')
                        state = 1;
                    else if (S.charAt(i) == 'B')
                        state = 2;
                    else
                        state = 0;
                    break;
                }

                case 2: {
                    if (S.charAt(i) == 'C') {
                        ans++;
                        state = 0;
                    }
                    else if(S.charAt(i) == 'A')
                        state = 1;
                    else
                        state = 0;
                    break;
                }
            }
        }

        os.println(ans);
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int cityCnt = scanner.nextInt();
			int routeCnt = scanner.nextInt();

			int[][] map = new int[cityCnt][cityCnt];
			int a, b;
			for (int i = 0; i < routeCnt; i++) {
				a = scanner.nextInt() - 1;
				b = scanner.nextInt() - 1;

				map[a][b]++;
				map[b][a]++;
			}

			int cnt;
			StringBuilder builder = new StringBuilder();
			for (int i = 0; i < cityCnt; i++) {
				cnt = 0;
				for (int j = 0; j < cityCnt; j++) {
					if (map[i][j] > 0) {
						cnt += map[i][j];
					}
				}
				builder.append(cnt + "\n");
			}
			System.out.println(builder.toString());
		}
	}
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);
 

void solve() {
    int N;
    map<ll, int, greater<int>> m;
    cin >> N;
    REP(i, N){
        ll a;
        cin >> a;
        if(m.find(a) == m.end()) m[a] = 0;
        m[a]++;
    }
    for(auto &n : m){
        n.second /= 2;
    }
    int k = 0;
    ll ans = 1ll;
    for(auto &n : m){
        REP(i, n.second){
            ans *= n.first;
            k++;
            if(k == 2) {
                cout << ans << endl;
                return;
            }
        }
    }
    cout << 0 << endl;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll a, b, c;
	cin >> a >> b >> c;
	cout << max((ll)0, c - (a - b)) << endl;
	ggr
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){
    int n;
    char max = 0, *a, *mb;
    //unsigned long long a,b,c, t;
    //bool flag = false;

    scanf("%d", &n);
    a = (char *)calloc(n, 1);
    mb = (char *)calloc(n, 1);

    while(true){    //2文字目
        max = 0;
        for(int j = 0; j < n; j++){
            if(a[j] > max) max = a[j];
            mb[j] = max;
        }
        for(int i = n-1; i >= 1; i--){
            if(a[i] > mb[i-1] + 1) {
                a[i] = 0;
                a[i-1]++;
            }
        }
        if(a[0] > 0) break;
        for(int j = 0; j < n; j++){
            printf("%c", 'a'+a[j]);
        }
        printf("\n");
        a[n-1]++;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
llong atack(llong x,llong y,llong ans){
    if(y%x == 0){
        ans += x*((y/x)*2-1);
        return ans;
    }
    else{
        ans += x*((y/x)*2);
        atack(y%x,x,ans);
    }
}
 
int main(){
    llong n,x;
    cin >> n >> x;

    llong ans = n;
    ans = atack(min(x,n-x),max(x,n-x),ans);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let* ((n (read))
	   (k (read))
	   (l (concatenate 'vector (loop for i from 1 to n collect (read)))))
  (sort l #'>)
  (princ (reduce #'+ (subseq l 0 k))))


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int n;
vector<ll>a;
void dfs(string s,char m){
    ll b=stol(s);a.PB(b);
	if(s.size()<10){
	for(char c=((m=='0')?(char)m:(m-1));c<=((m=='9')?(char)m:(m+1));c++){
		dfs(c+s,c);
	}
	}	
}

int main(){
	cin>>n;
	for(char i='0';i<='9';++i){string t="";t.PB(i);dfs(t,i);}
	sort(all(a));
    a.erase(unique(all(a)),a.end());
	cout<<a[n]<<endl;
}


Measured memory_bytes: 2420
# -*- coding: utf-8 -*-
import sys
from itertools import product
from collections import Counter, defaultdict
from string import ascii_uppercase as ABC
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N = int(input())
R = []
for _ in range(N):
    x, l = inpl()
    R.append([x-l, x+l])

R = sorted(R, key=lambda x: x[1])
now = -10**10
ans = 0
for l, r in R:
    if l < now:
        continue
    ans += 1
    now = r
print(ans)


Measured memory_bytes: 65564
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long const mod = 1000000007;
long long mod_pow(long long a, long long b){
    long long res = 1;
    a %= mod;
    while(b > 0){
        if(b%2 == 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}
int main(void){
    int n;
    bool flg = true;
    vector<int> a;
    cin >> n;
    a.assign(n, 0);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        if((n+a[i])%2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    sort(a.begin(), a.end());
    if(n%2 == 0){
        for(int i=1;i<n;i+=2){
            if(a[i] != a[i-1] || a[i] != i){
                flg = false;
            }
        }
        
    }else{
        if(a[0] != 0)flg = false;
        for(int i=2;i<n;i+=2){
            if(a[i] != a[i-1] || a[i] != i){
                flg = false;
            }
        }
        
    }
    if(flg)cout << mod_pow(2, n/2) << endl;
    else cout << 0 << endl;
}


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

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

  int lenb = b.length();
  int numb = atoi(b.c_str());
  if ( lenb == 1 ) a *= 10;
  else if ( lenb == 2 ) a*=100;
  else if ( lenb == 3 ) a*=1000;
  int n = a + numb;
  bool f = false;
  for ( int i = 1; i <= 10000; i++ ) {
    if ( i*i == n ) {
      f = true;
      break;
    }
  }
  if(f)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> S_raw(N);
    vector<int> P(N);
    REP(i, N){
        cin >> S_raw[i] >> P[i];
    }
    set<string> S;
    REP(i, N){
        S.insert(S_raw[i]);
    }
    for(auto s: S){
        vector<vector<int>> num;
    REP(i, N){
        if(S_raw[i] == s){
            vector<int> a = {i, P[i]};
            num.insert(num.begin(), a);
        }
    }
        if(num.size() > 0)sort(num.begin(), num.end(),[](vector<int> x, vector<int> y){return x[1] > y[1];});
        REP(k, num.size()){
            cout << num[k][0]+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << a + b + c + max({a, b, c}) * (pow(2, k) - 1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


template<class T> class BIT   // 1-indexed (0 is not used)
{
private:
    int num;
    vector<T> bit;
public:
    BIT(int n) :bit(vector<T>(n + 1, 0)), num(n) {}

    T sum(int i) {   // sum of 1..i
        if (!i) return 0;
        return bit[i] + sum(i - (i&-i));
    }

    void add(int i, T x) {
        if (i > num) return;
        bit[i] += x;
        add(i + (i&-i), x);
    }

    int lower_bound(T x) {
        T res = 0;
        int N = 1;
        while (N < num) N *= 2;
        int i;
        for (i = N / 2; i > 0; i /= 2) {
            if (res + i < num && bit[res + i] < x) {
                x = x - bit[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

void solve()
{
    int n, Q;
    scanf("%d%d", &n, &Q);
    BIT<ll> bit(n);
    int i;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        bit.add(i + 1, tmp);
    }
    
    for (i = 0; i < Q; i++) {
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
        if (t == 0) {
            bit.add(u + 1, v);
        }
        else {
            printf("%lld\n", bit.sum(v) - bit.sum(u));
        }
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 8208
#include <iostream>
#include <assert.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
//#include <functional>


int main(){
    int32_t N;
    std::cin >> N;

    // naiive approach
    // reorder N strings O(NlogN * 10)
    // check every combination nC2 = N^2
    // to avoid N^2, hash_map can be used.

    std::unordered_map<std::string, int64_t> s2cnt_um;
    std::string s;
    int64_t res = 0;
    for(int32_t i = 0; i < N; i++){
        std::cin >> s;
        std::sort(s.begin(),s.end());
        //std::cout << "sorted string: " << s << std::endl;
        
        if(s2cnt_um[s] != 0){
            res += s2cnt_um[s];
        }
        s2cnt_um[s] += 1;
    }
    std::cout << res;
    return 0;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
int N;
int rplus[200100], rminus[200100];

int main() {
    int N; cin >> N;
    string X; cin >> X;
    //int N = 200000;
    //string X =  string(N - 2, '0') + "10";
    reverse(begin(X), end(X));
    int npop = count(begin(X), end(X), '1');

    if(npop == 0) {
        for(int i=N-1; i>=0; --i) cout << 1 << '\n';
        return 0;
    }
    if(npop == 1 && X[0] == '1') {
        for(int i=N-1; i>0; --i) cout << 2 << '\n';
        cout << 0 << '\n';
        return 0;
    }
    if(npop == 1) {
        for(int i=N-1; i>0; --i) {
            if(X[i] == '1') cout << 0 << '\n';
            else cout << 1 << '\n';
        }
        cout << 2 << '\n';
        return 0;
    }
    
    rplus[0] = 1;
    for(int i=1; i<=N; ++i) rplus[i] = rplus[i - 1] * 2 % (npop + 1);
    rminus[0] = (npop > 2 ? 1 : 0);
    for(int i=1; i<=N; ++i) rminus[i] = rminus[i - 1] * 2 % (npop - 1);

    int fplus = 0;
    for(int i=0; i<N; ++i) {
        fplus = (fplus + (X[i] == '0' ? 0 : rplus[i])) % (npop + 1);
    }
    int fminus = 0;
    for(int i=0; i<N; ++i) {
        fminus = (fminus + (X[i] == '0' ? 0 : rminus[i])) % (npop - 1);
    }

    //cout << npop << '\n';
    //cout << fplus << ' ' << fminus << '\n';

    for(int i=N-1; i>=0; --i) {
        int f = (X[i] == '0' ? fplus : fminus);
        if(X[i] == '0') f = (f + rplus[i]) % (npop + 1);
        else f = ((f - rminus[i]) % (npop - 1) + npop - 1) % (npop - 1);

        int res = 1;
        while(f) {
            int tmp = __builtin_popcount(f);
            f %= tmp;
            ++res;
        }
        cout << res << '\n';
    }
}

Measured memory_bytes: 5280
n,m = gets.strip.split.map(&:to_i)
ary = []
n.times do
  c,d = gets.strip.split.map(&:to_i)
  ary << [c,d].to_a
end
arys = ary.sort{|a, b| a[0] <=> b[0]}
i = 0
sum = 0
nokori = m
while i >= 0 do
  nokori -= arys[i][1]
  if nokori <= 0
    sum += (arys[i][0])*(nokori+arys[i][1])
    break
  else
    sum += (arys[i][0])*(arys[i][1])
  end
  i += 1
end
puts sum

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

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  rep(i,3) {
    if (s[i] == 'R') cnt++;
    else {
      ans = max(ans,cnt);
      cnt = 0;
    }
  }
  cout << max(ans,cnt) << endl;
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int a, b;
    cin>>a>>b;
    int ans = (a + b) % 24;
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(b>a+w)cout<<b-a-w;
	else if(b<=a+w&&b+w>=a)cout<<0;
	     else  cout<<a-b-w;
	   
	return 0;
}

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

class UnionFind{
public:
  vector<int> par;
  vector<int> rank;
  vector<int> sz;
  int N;

  UnionFind(int n){N=n;}

  //初期化
  void init(){
    for(int i=0;i<N;i++){
      par.push_back(i);
      rank.push_back(0);
      sz.push_back(1);
    }
  }

  //木の根を求める
  int find(int x){
    if(par[x]==x) return x;
    else{
      par[x]=find(par[x]);
      return par[x];
    }
  }

  //xとyの集合の併合
  void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じ集合にあるか
  bool same(int x, int y){
    return find(x) == find(y);
  }

  //xの木のサイズ
  int size(int x){
    return sz[find(x)];
  }
};

int main(){
  ll N,M;
  cin >> N >> M;
  pair<int,int> p[M];
  for(int i=0;i<M;i++){
    cin >> p[i].first >> p[i].second;
    p[i].first--;
    p[i].second--;
  }

  UnionFind uf = UnionFind(N);
  uf.init();

  ll ans[M];
  ans[M-1] = N*(N-1)/2;
  for(int i=M-1;i>0;i--){
    int s = p[i].first;
    int t = p[i].second;

    if(!uf.same(s,t)){
      ans[i-1] = ans[i] - uf.size(s)*uf.size(t);
      uf.unite(s,t);
    }else{
      ans[i-1] = ans[i];
    }
  }

  for(int i=0;i<M;i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4332
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	x, _ := strconv.Atoi(sc.Text())
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	x := make([]int, 3)
	for i := range x {
		x[i] = nextInt()
	}
	sort.Ints(x)
	fmt.Println(x[0] + x[1] + x[2]*10)

}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
using namespace std;

#define all(c) c.begin(),c.end()
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i,0,n)
#define MAX(x, y)  ((x > y)? x : y);
#define MIN(x, y)  ((x < y)? x : y);
#define dump(x)  cout << #x" = " << x << endl;
#define debug(x) cout << #x" = " << x << " (" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
typedef vector<int> vi;

const int N = 100010;
int check[N][2];

int main() {
	int n, m, ans = 0;
	cin >> n >> m;

	check[1][1] = 1;
	REP(i, n + 1)check[i][2] = 1;
	REP(i, m) {
		int x, y;
		cin >> x >> y;

		if (check[x][1] == 1 && check[x][2] != 0) {
			if(--check[x][2] == 0) check[x][1]--;
			check[y][1] = 1;
			check[y][2]++;
		}
		else {
			check[x][2]--;
			check[y][2]++;
		}
	}

	FOR(i, 1, n + 1) {
		if (check[i][1] == 1) ans++;
	}
	cout << ans << endl;

	/*FOR(i, 1, n + 1) {
		cout << check[i][1] << " ";
		if (i == n) cout << endl;
	}
	FOR(i, 1, n + 1) {
		cout << check[i][2] << " ";
		if (i == n) cout << endl;
	}*/

	return 0;
}

Measured memory_bytes: 1024