akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

class SegTree{
  int n; int uni = 0; 
  vector<int> dat;
public:
  void num(int k) {
    n = 1;
    while(n < k) n *= 2;
    dat = vector<int>(2*n,uni);
  }
  void set(int k, const int x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = dat[2*i] + dat[2*i+1];
    }
  }
  void update(int k, int x) {
    k += n;
    dat[k] = x;
    while(k >>= 1){
      dat[k] = dat[2*k] + dat[2*k+1];
    }
  }
  int query(int a, int b) {
    int l = uni, r = uni;
    for(a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if(a & 1) l = l + dat[a++];
      if(b & 1) r = dat[--b] + r;
    }
    return l + r;
  }
};

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<SegTree> st(26);
  rep(i,26) st[i].num(n);
  rep(i,n) {
    int a = s[i] - 'a';
    st[a].set(i,1);
  }
  rep(i,26) st[i].build();
  vector<int> ans;
  rep(x,q) {
    int p;
    cin >> p;
    if(p == 1) {
      int i; char c;
      cin >> i >> c;
      i--;
      st[s[i]-'a'].update(i,0);
      st[c-'a'].update(i,1);
      s[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      int k = 0;
      rep(i,26) {
        if(st[i].query(l,r) > 0) k++;
      }
      ans.push_back(k);
    }
  }
  for(auto k : ans) cout << k << endl;
  return 0;
}


Measured memory_bytes: 107652
#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() {
    int N, a;
    cin >> N;
    ll ans = 0;
    rep(i,N) {
        cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
}


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

int main(){
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    A[i]--;
    A[i] %= K;
  }

  vector<int> rem_sum(N + 1);
  map<int, int> rem_sum_cnt;
  rem_sum_cnt[0] = 1;
  long long ans = 0;
  for(int i = 0; i < N; i++){
    if(i + 1 - K >= 0){
      rem_sum_cnt[rem_sum[i + 1 - K]]--;
    }
    rem_sum[i + 1] = (rem_sum[i] + A[i]) % K;
    // cout << rem_sum[i + 1] << endl;
    ans += rem_sum_cnt[rem_sum[i + 1]];
    rem_sum_cnt[rem_sum[i + 1]]++;
  }

  cout << ans << endl;
}

  


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


int main(void) {
  string S, T;
  cin >> S >> T;

  int ans = 0;
  rep(i, S.size()) {
    if (S[i] != T[i]) {
      ans++;
    }
  }

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

Measured memory_bytes: 3912
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#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 <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  map<int, int> cnt;
  set<int> cnt2;
  vi a(n);
  rep(i, n){
    cin >> a[i];
    if(a[i] != 1){
      if(cnt[a[i]]) cnt2.insert(a[i]);
      cnt[a[i]]++;
    }
  }
  sort(all(a));
  if(a[0] == 1){
    if(a[1] == 1) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  vi check(1000100, 0);
  set<int> d;
  int ans = n;
  rep(i, n){
    if(check[a[i]]){
      ans--;
      if(!d.count(a[i])) cnt2.erase(a[i]);
    }
    d.insert(a[i]);
    for(int j = a[i]; j < 1000100; j += a[i]) check[j] = 1;
  }
  cout << ans - cnt2.size() << endl;
}

Measured memory_bytes: 26532
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String alp = "abcdefghijklmnopqrstuvwxyz";
        char[] alps = alp.toCharArray();
        String s = sc.next();
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i < alps.length; i++){
            String chk = s;
            int tmp = 0;
            while(chk.replace(String.valueOf(alps[i]),"").length() != 0){
                StringBuilder sb = new StringBuilder();
                for(int j = 0; j < chk.length()-1; j++){
                    if(chk.charAt(j+1) == alps[i]){
                        sb.append(alps[i]);
                    }else{
                       sb.append(chk.charAt(j));
                    }
                }
                chk = sb.toString();
                tmp++;
            }
            ans = Math.min(ans, tmp);
        }
        System.out.println(ans);
    }
    
}

Measured memory_bytes: 27476
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;
//--------------------

int main() {

	long res[300009] = {};

	long N; cin >> N;
	long A[300009]; for (int i = 1; i <= N; i++) cin >> A[i]; A[0] = A[N];

	long sumA = 0; for (int i = 1; i <= N; i++) sumA += A[i];

	long ruiA[300009] = {}; for (int i = 1; i <= N; i = i + 2) ruiA[(i + 1) / 2] = ruiA[(i + 1) / 2 - 1] + 2 * A[i];//まず初段から累積。
	//次中段累積。

	for (int i = 2; i <= N - 1; i = i + 2) ruiA[(N + 1) / 2 + i / 2] = ruiA[(N + 1) / 2 + i / 2 - 1] + 2 * A[i];
	//三段目累積。
	for (int i = 1; i <= N; i = i + 2) ruiA[(i + 1) / 2 + N] = ruiA[(i + 1) / 2 + N - 1] + 2 * A[i];
	ruiA[0] = 0;

	for (int i = 1; i <= N; i++) res[(2 * i) % N] = sumA - ruiA[i + (N - 1) / 2] + ruiA[i];
	res[N] = res[0];
	for (int i = 1; i <= N; i++) cout << res[i] << endl;
}

Measured memory_bytes: 8320
n,k=map(int,input('').split(' '))
a=[]
d=[]
for i in range(k):
    s=int(input(''))
    d.append(s)

    s=input('')
    s=s.split(' ')
    for j in range(len(s)):
        s[j]=int(s[j])
    a.append(s)

b=[]
for i in range(n):
    b.append(0)

for i in range(k):
    for j in range(d[i]):
        b[a[i][j]-1]+=1

m=0
for i in range(n):
    if b[i]==0:
        m=m+1

print(m)

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var D = vals[1];
        var X = new int[N][];
        for (int i = 0; i < N; i++)
        {
            X[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }


        var count = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                var sum = Enumerable.Range(0, D).Select(d => X[i][d] - X[j][d]).Sum(d => d * d);
                var root = (int)Math.Sqrt(sum);
                if (root * root == sum)
                {
                    count++;
                }
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13524
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String s = sc.nextLine();
            switch (s) {
                case "A":
                    System.out.println("T");
                    break;
                case "T":
                    System.out.println("A");
                    break;
                case "C":
                    System.out.println("G");
                    break;
                case "G":
                    System.out.println("C");
                    break;
            }
        }
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define ll long long
#define P pair<int,int>
#define INT_MAX 1000000000
#define MAX_N 1000000000
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a <= b){
        cout<< "Yes" <<endl;
    }else{
        cout<< "No" <<endl;
    }
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	string s; cin >> s;
	int n = s.size() - 2;
	cout << s[0] << n << s[s.size() - 1] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      int n = scnr.nextInt();
      int m = scnr.nextInt();
      int[] likedFoods = new int[m];
      for (int i = 0; i < n; i++) {
        int k = scnr.nextInt();
        for (int j = 0; j < k; j++) {
          int food = scnr.nextInt();
          likedFoods[food-1]++;
        }
      }
      int result = 0;
      for (int i = 0; i < m; i++) {
        if (likedFoods[i] == n) result++;
      }
      System.out.println(result);
    }
}

Measured memory_bytes: 24404
N, M = map(int, input().split())

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N+1)

for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)

print(max(uf.size(num) for num in uf.roots()))    

Measured memory_bytes: 18264
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

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

int main(void) {
    string s;
    li K;
    cin >> s >> K;
    li ans;

    REP(i, min((li)s.size(), K)) {
        if (s[i] >= '2') {
            cout << s[i] << endl;
            return 0;
        }
    } 

    cout << '1' << endl;
    return 0;
}

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

 
public class Main{
	char[] S;
	int K;
	public void solve(){
		S = next().toCharArray();
		K = nextInt();
		for(int i = 0; i < S.length; i++){
			int c = S[i] - 'a';
			c = (26 - c) % 26;
			if(c <= K){
				S[i] = 'a';
				K -= c;
			}
		}
		int c = S[S.length - 1] - 'a';
		c = (K + c) % 26;
		S[S.length - 1] = (char) (c + 'a');
		out.println(new String(S));
		
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

using namespace std;

int main(){
  string s;
  int k;
  cin>>k;
  cin>>s;
  if (s.size() > k) {
    cout<<s.substr(0,k)<<"..."<<endl;;
  } else {
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

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

    int H, W;
    int N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<vector<int>> color(H, vector<int>(W, 0));
    int pos = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < a[i]; j++) {
            const int w = pos / H;
            const int h = (w % 2 == 0) ? pos % H : H - 1 - (pos % H);
            color[h][w] = i + 1;
            pos++;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j != 0) {
                cout << " ";
            }
            cout << color[i][j];
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
	
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define prime 998244353 

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << endl;

using namespace std;


int v[10], c[5];

int main(){
	
	for (int i = 0; i < 6; ++i){
		scanf("%d", &v[i]);
	}

	for (int i = 0; i < 6; ++i){
		c[v[i]]++;
		if(c[v[i]] > 2){
			printf("NO\n");
			return 0;
		}
	}

	printf("YES\n");




	return 0;
}

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

public class Main {


	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {

		Scanner sc = new Scanner(System.in);
		Map<Integer,List<Integer>> graph = new HashMap<>();
		int N = sc.nextInt();
		int M = sc.nextInt();

		for(int i=0;i<M;i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			List<Integer> children = graph.getOrDefault(u, new ArrayList<Integer>());
			children.add(v);
			graph.put(u, children);
		}

		long [] dp = new long[N+1];
		long ans = Long.MIN_VALUE;
		for(int i=1;i<=N;i++) {
			ans = Math.max(ans, solve(i, dp, graph));
		}
		return ans;
	}

	private long solve(int u, long[] dp, Map<Integer, List<Integer>> graph) {
		if (dp[u]!=0) return dp[u];
		if (!graph.containsKey(u)) return 0L;
		long bestChild = 0;
		for(int child: graph.get(u)){ 
			bestChild = Math.max(bestChild, solve(child, dp, graph));
		}
		dp[u] = bestChild+1;
		return dp[u];
	}


}

Measured memory_bytes: 84828
while  (m, f, r = gets.split.map(&:to_i)) != [-1,-1,-1]
a = m + f

  if m == -1 || f == -1
    puts "F"
  elsif a >= 80
    puts "A"
  elsif  a >= 65 && a < 80
    puts "B"
  elsif a >= 50 && a < 65
    puts "C"
  elsif  a < 30
    puts "F"

  elsif a >= 30 && a < 50
    puts "D" if r < 50
    puts "C" if r >= 50
  end
end

Measured memory_bytes: 6104
#include<stdio.h>
    #include<math.h>
     
    int main(void)
    {
    		int sum, ans=0,n,d;
    		double m,p;
     
    		scanf("%d",&n);
    		scanf("%d", &d);
     
    		int x[n][d];
     
    		for (int i = 0;i < n;i++)
    			for (int j = 0;j < d;j++)
    				scanf("%d",&x[i][j]);
     
    	for (int a = 0;a < n - 1;a++)
    	{
    		for (int b = a + 1;b < n;b++)
    		{
    			sum = 0;
    			for (int i = 0;i < d;i++)
    				sum += (x[a][i] - x[b][i]) * (x[a][i] - x[b][i]);
    				m = sqrt((double)sum);
    				
    				sum = (int)m;
    				p = (double)sum;
    				if (m == p)
    					ans++;
    				
     
    		}
    	}
    	printf("%d", ans);
    	return 0;
    }


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

static int v[1001];
static inline int comparator(const void *a, const void *b)
{
    return ( *(int*)a - *(int*)b );
}

int main(int n, int m, float t)
{
    t=0;
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;++i)
    {
        scanf("%d", &v[i]);
        t+=v[i];
    }

    qsort(v, n, sizeof(int), comparator);

    t /= (4*m);
    printf("%s\n", (v[n-m]>=t) ? "Yes" : "No");
    return 0;
}

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

#define pb         push_back

const int INF = 100000000;

int main(void) {
	vector<int> sum;
	sum.pb(0);
	for(int i=1; i<=1000; i++){
		sum.pb(sum[i-1] + i);
	}

	while(1){
		int n;
		cin >> n;
		if(n == 0) break;

		int ans = 0;
		for(int i=0; i<=n; i++){
			for(int j=i+2; j<=n; j++){
				if(sum[j] - sum[i] == n){
					ans++;
				}
			}
		}

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

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
string s[7];
int R, C, k;
bool func(int x, int y) {
	int cnt = 0;
	for (int i = 0; i < R; ++i) {
		for (int j = 0; j < C; ++j) {
			if(x&(1 << i) || y &(1 << j))
				continue;
			if(s[i][j] == '#')
				++cnt;		
		}
	}
	if(cnt == k)
		return true;
	return false;
}

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> R >> C >> k;
	for (int i = 0; i < R; ++i) {
		cin >> s[i];
	}
	int ans = 0;
	for (int i = 0; i < (1 << R); ++i) {
		for (int j = 0; j < (1 << C); ++j) {
			if(func(i, j))
				++ans;
		}
	}

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

Measured memory_bytes: 3636
a,b,n=map(int,input().split())
l=[]
m=a//b
if b==1:
    print(0)
    exit()
if n>=b:
    for x in range(b-1,n+1,b):
        y=a*x//b-a*(x//b)
        #l.append(y)
        m=max(m,y)
    x=n
    y=a*x//b-a*(x//b)
    m=max(m,y)
else:
    x=n
    y=a*x//b-a*(x//b)
    #l.append(y)
    xx=n-1
    yy=a*xx//b-a*(xx//b)
    m=max(y,yy)


print(m)


Measured memory_bytes: 61896
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string s;
    cin >> s;
    ll k;
    cin >> k;
    int num = s.size();

    for(int i=1; i <= num-1; ++i) {
        if(num%i) continue;
        string x = s.substr(0, i);
        bool ch = true;
        rep(j, num/i) {
            if(x != s.substr(j*i, i)) {
                ch = false;
                break;
            }
        }
        if(ch) {
            k *= num/i;
            num = i;
            s = x;
            break;
        }
    }
    ll ans = 0;
    ll yyy=0;
    if(s[num-1] == s[0]) {
        int j = 0;
        while(s[num-1] == s[j]) {
            j++;
        }
        int k = 1;
        while(s[num-k] == s[0]) {
            k++;
        }
        --k;
        if(!((k+j)&1) and j&1) {
            --yyy;
        }
        rotate(s.begin(), s.begin()+j, s.end());
    }



    
    rep(i, num-1) {
        if(s[i] == s[i+1]) {
            ans++;
            s[1+i] = 'A';
        }
    }
    ans *= k;


    if(num == 1) {
        ans = k/2-yyy;
    }

    cout << ans+yyy << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;

    bool acan=true, bcan=true;
    FOR(i, A, C-2) {
        if(S[i]=='#' && S[i+1]=='#') acan=false;
    }
    FOR(i, B, D-2) {
        if(S[i]=='#' && S[i+1]=='#') bcan=false;
    }

    if(!acan || !bcan) {
        cout << "No" << endl;
        return 0;
    }

    if(C<D) {
        cout << "Yes" << endl;
    } else {
        bool can = false;
        FOR(i, B-2, D-1) {
            if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.') {
                can = true;
                break;
            }
        }
        if(can)  cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 640
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line;
        while(true) {
            try {
                line = sc.nextLine();
            }catch(Exception e) {
                break;
            }
            double v = Double.parseDouble(line);
            double t = v / 9.8;
            double y = 4.9 * Math.pow(t, 2);
            double N = (y + 5)/5;
            int ans = (int)N;
            if(N % 1 == 0) {
                System.out.println(ans);
            }else {
                System.out.println(ans+1);
            }
        }
        
    }
}


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

int main(void){
  int N,i,n,d;
  int Xmin,Xmax,Ymin,Ymax;
  //←...0/↓...1/→...2/↑...3//
  while(scanf("%d",&N)!=EOF){
    if(N==0){break;}

    int x[200]={},y[200]={};
    Xmin=x[0];Xmax=x[0];Ymin=y[0];Ymax=y[0];
    for(i=1;i<N;i++){
      scanf("%d %d",&n,&d);
      switch(d){
        case 0:
          x[i]=x[n]-1;
          y[i]=y[n];
          break;
        case 1:
          x[i]=x[n];
          y[i]=y[n]-1;
          break;
        case 2:
          x[i]=x[n]+1;
          y[i]=y[n];
          break;
        case 3:
          x[i]=x[n];
          y[i]=y[n]+1;
          break;
        }
        if(Xmin>=x[i]) Xmin=x[i];
        if(Xmax<=x[i]) Xmax=x[i];
        if(Ymin>=y[i]) Ymin=y[i];
        if(Ymax<=y[i]) Ymax=y[i];
    }
    printf("%d %d\n",abs(Xmin-Xmax)+1,abs(Ymin-Ymax)+1);
  }
  return 0;
}



Measured memory_bytes: 2036
N,W=map(int,input().split())
wv=[[0,0] for _ in range(N)]

for i in range(N):
    wv[i]=list(map(int,input().split()))

    
dp=[[0]*(W+1) for _ in range(N+1)]#i番目までの商品で重さj以下の時の総和

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

Measured memory_bytes: 120300
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const int MAX=1e5+1;
const ll INF=1e9;

int main()
{
    int a[5];
    int point=0;
    int prev=9;
    rep(i,5)
    {
        cin>>a[i];
        if(a[i]%10!=0 & a[i]%10<prev)
        {
            point=i;
            prev=a[i]%10;
        }
    }
    int ans=0;
    rep(i,5)
    {
        if(i!=point)
        {
            int mod=a[i]%10;
            a[i]+=mod==0?0:(10-mod);
        }
        ans+=a[i];
    }
    cout<<ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll a,b,c,k;
cin>>a>>b>>c>>k;
ll sum =a;
if(k<=a)
{
	cout<<k;
	return 0;
}
k-=a;
if(k<=b)
{
	cout<<sum;
	return 0;
}
k-=b;
cout<<sum-k;

}


Measured memory_bytes: 3588
#include <stdio.h>
int main()
{
    int long a,b,i,sum,c;
    while(scanf("%ld %ld",&a,&b)!=EOF)
    {
        c=0;
        sum=a+b;
        while(sum!=0)
        {

                 sum=sum/10;
                 c=c++;

        }
        printf("%d\n",c);
    }
return 0;
}

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

int main(){
  int A,B;
  int ans = 0;

  cin >>A>>B;

  if(A > B)ans = max(A,B) + max(A-1,B);
  else ans = max(A,B) + max(A,B-1);

  
  cout <<ans<<endl;
  

  return 0;
  }

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int t=ri(),ch;
	while(t--)
	{
		for(ch=getchar();ch<'A'||ch>'Z';ch=getchar());
		if(ch=='Y')
		{
			puts("Four");
			return 0;
		}
	}
	puts("Three");
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int p2[4000], fact[4000], fact_m[4000];
long long int DP[3100][3100] = {};

long long int mul_pow(long long int num, long long int pow_num, long long int mod_num){
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

int main(){
    long long int N;
    cin >> N >> MOD;
    p2[0] = fact[0] = fact_m[0] = 1;
    for(int i = 1; i < 4000; i++){
        p2[i] = p2[i - 1] * 2;
        p2[i] %= MOD;
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
        fact_m[i] = fact_m[i - 1] * mul_pow(i, MOD - 2, MOD);
        fact_m[i] %= MOD;
    }
    DP[1][1] = 1;
    for(int i = 2; i <= N; i++){
        for(int j = 1; j <= N; j++){
            DP[i][j] = DP[i - 1][j] * j + DP[i - 1][j - 1];
            DP[i][j] %= MOD;
        }
    }
    long long int ans = mul_pow(2, mul_pow(2, N, MOD - 1), MOD);
    long long int sig = -1;
    for(int i = 1; i <= N; i++){
        long long int P = 1, S = 0;
        for(int j = 1; j <= i; j++){
            S += DP[i][j] * (j * P % MOD);
            S %= MOD;
            P *= p2[N - i];
            P %= MOD;
            S += DP[i][j] * P;
            S %= MOD;
        }
        S *= mul_pow(2, mul_pow(2, N - i, MOD - 1), MOD);
        S %= MOD;
        long long int comb = (fact[N] * fact_m[i] % MOD) * fact_m[N - i] % MOD;
        S *= comb;
        S %= MOD;
        ans += S * sig + MOD * 10;
        ans %= MOD;
        sig *= -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 73984
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	table := make(map[string]bool, n)
	buf := bytes.Buffer{}
	for i := 0; i < n; i++ {
		command := scanString()
		key := scanString()

		switch command {
		case "insert":
			table[key] = true
		case "find":
			if table[key] {
				buf.WriteString("yes\n")
			} else {
				buf.WriteString("no\n")
			}
		}
	}

	fmt.Println(strings.TrimRight(buf.String(), "\n"))
}



Measured memory_bytes: 66716
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = (int)1e5;
int dp[N];
int hs[N];

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

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> hs[i];
	}
	dp[1] = abs(hs[1] - hs[0]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(dp[i-1] + abs(hs[i-1] - hs[i]), dp[i-2] + abs(hs[i-2] - hs[i]));
	}
	cout << dp[n-1] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;
int power(int base,int n,int m = mod)
 {
  if(n == 0)
     return 1;
  if(n&1)
     {
      int y = power(base,n-1,m);
      return (y*base)%m;
     }
  else
     {
      int y = power(base,n/2,m);
      return (y*y)%m;
     }
 }
  
void solve()
  {
   int n,k;
   cin>>n>>k;
   int ans = 0;
   int inv2 = power(2ll,mod-2);
   loop(i,k,n+2)
     {
      int llimit = ((i%mod)*(i-1)%mod)%mod;
      llimit = (llimit*inv2)%mod;
      int ulimit_u = ((n%mod)*(n+1)%mod)%mod;
      ulimit_u = (ulimit_u *inv2)%mod;
      int ulimit_l = ((n-i)%mod*(n-i+1)%mod)%mod;
      ulimit_l = (ulimit_l *inv2)%mod;
      int local = (ulimit_u - ulimit_l + mod)%mod;
      //cerr<<llimit<<" "<<ulimit_l<<" "<<ulimit_u<<END;
      //local = (local * inv2)%mod;
      int a = (local - llimit + 1+ mod)%mod;
      ans = (ans + a)%mod;
     }
    cout<<ans;
  } 

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

     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] s = new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
        }

        int[][] row = new int[h][w];
        for (int r = 0; r < h; r++) {
            int cnt = 0;
            int start = 0;
            for (int c = 0; c < w; c++) {
                if (s[r][c] == '.') {
                    cnt++;
                    continue;
                }
                for (int i = start; i < c; i++) {
                    row[r][i] = cnt;
                }
                cnt = 0;
                start = c + 1;
            }
            if (start != w) {
                for (int i = start; i < w; i++) {
                    row[r][i] = cnt;
                }
            }
        }
        int[][] col = new int[h][w];
        for (int c = 0; c < w; c++) {
            int cnt = 0;
            int start = 0;
            for (int r = 0; r < h; r++) {
                if (s[r][c] == '.') {
                    cnt++;
                    continue;
                }
                for (int i = start; i < r; i++) {
                    col[i][c] = cnt;
                }
                cnt = 0;
                start = r + 1;
            }
            if (start != h) {
                for (int i = start; i < h; i++) {
                    col[i][c] = cnt;
                }
            }
        }

        int ans = 1;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ans = Math.max(ans, row[i][j] + col[i][j] - 1);
            }
        }
        System.out.println(ans);
    }

}


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

using namespace std;

int main(){
        bool f[110][20];
        int N;
        cin>>N;
        for(int i=0;i<N;i++){
                for(int j=0;j<10;j++){
                        cin>>f[i][j];
                }
        }
        int p[110][20];
        for(int i=0;i<N;i++){
                for(int j=0;j<=10;j++){
                        cin>>p[i][j];
                }
        }
        int res=-1e9;
        for(int a=1;a<pow(2, 10);a++){
                int vres=0;
                for(int i=0;i<N;i++){
                        int c=0;
                        for(int j=0;j<10;j++){
                                if(((a>>j)&1)&&f[i][j])
                                        c++;
                        }
                        vres+=p[i][c];
                }
                res=max(vres, res);
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<ll> a(n + 1), lb(n + 1), ub(n + 1);
    read(a);
    lb[n] = 0, ub[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
        lb[i] = (lb[i + 1] + a[i + 1]) / 2 + (lb[i + 1] + a[i + 1]) % 2;
        ub[i] = ub[i + 1] + a[i + 1];
    }
    ll x = 1;
    if (a[0] > 0) {
        if (n == 0 && a[0] == 1) {
            cout << 1 << newl;
        } else {
            cout << -1 << newl;
        }
        return 0;
    }
    ll res = 1;
    for (int i = 1; i <= n; i++) {
        ll nx = min(2LL * x - a[i], ub[i]);
        if (lb[i] > nx || x - a[i] > nx) {
            cout << -1 << newl;
            return 0;
        }
        x = nx;
        res += x + a[i];
    }
    cout << res << newl;
}

Measured memory_bytes: 5512
#include <stdio.h>
int main(){
    int m,f,r;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1){
            break;
        }
        if(m==-1||f==-1){
            puts("F");
        }
        else if(m+f>=80){
            puts("A");
        }
        else if(m+f>=65){
            puts("B");
        }
        else if(m+f>=50||r>=50){
            puts("C");
        }
        else if(m+f>=30){
            puts("D");
        }
        else{
            puts("F");
        }
    }
    return 0;
}


Measured memory_bytes: 2108
use proconio::{input, fastout};
use proconio::marker::{Chars};

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[fastout]
fn main() {
    input!{
        mut s: Chars,
    }
    let n = s.len();
    s.push('R');
    let mut r: bool = true;
    let mut l: bool = false;
    let mut spot_r = 0;
    let mut spot_l = n-1;
    let mut cnt = 0;
    // let mut sum = 0;
    let mut ans: Vec<usize> = vec![0;n];
    for i in 0..n+1 {
        if r==true && s[i]=='L' {
            r = false;
            l = true;
            spot_r = i-1;
            spot_l = i;
        }
        if l==true && s[i]=='R' {
            let tmp = cnt;
            cnt = i - cnt;
            r = true;
            l = false;
            if cnt%2==0 {
                ans[spot_r] = cnt/2;
                ans[spot_l] = cnt/2;
            } else {
                if (spot_r-tmp)%2==0 {
                    ans[spot_r] = cnt/2 + 1;
                    ans[spot_l] = cnt/2;
                } else {
                    ans[spot_r] = cnt/2;
                    ans[spot_l] = cnt/2 + 1;
                }
            }
            debug!(spot_r);
            debug!(cnt);
            cnt = i;
        }
    }

    for i in 0..n {
        print!("{} ",ans[i]);
    }
    // let mut dp: Vec<usize> = vec![0;n];
    // let mut o = 0;
    // let mut e = 0;
    // let mut spot = 0;
    // for i in 0..n-1 {
    //     if s[i]=='R' {
    //         if i%2!=0 {
    //             o += 1;
    //         } 
    //         if i%
    //         if s[i+1]=='L' {
    //             spot = i;
    //         }
    //     } else {
    //         if s[i+1]=='R' {
    //             dp[spot] = tmp;
    //             tmp = 0;
    //         } else {
    //             tmp += 1;
    //         }
    //     }
    // }

}


Measured memory_bytes: 3296
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string n;
    int i;
    cin>>n;
    for(i=0;i<n.size();i++)
    {
       if(n[i]==',')
         cout<<" ";
       else
         cout<<n[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0;i<s.length();i++){
        int x=s[i]-'A';
        x=(x+n)%26;
        cout << char('A'+x);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

ll MOD = 1000000007;

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

	if (a[0] >= 1) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 3;
	vector<ll> dp(3);
	dp[0] = 1;
	dp[1] = 0;
	dp[2] = 0;
	for (int i = 1; i < n; i++) {
		int num = 0;
		for (int j = 0; j < 3; j++)
		{
			if (dp[j] == a[i]) {
				num++;
				if (num == 1) dp[j]++;
			}
		}
		ans *= num;
		ans %= MOD;
	}
	cout << ans << endl;
	
    
    return 0;
}

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

int main() {
	int a[3], b[3];
	for (int i = 0; i < 3; ++i) cin >> a[i] >> b[i];

	int cnt[5] = {};
	for (int i = 0; i < 3; i++) {
		cnt[a[i]]++;
		cnt[b[i]]++;
	}

	int c1 = 0, c2 = 0;
	for (int i = 1; i <= 4; i++) {
		if (cnt[i] == 1) c1++;
		else if (cnt[i] == 2) c2++;
	}

	cout << (c1 == 2 && c2 == 2 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <vector>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <cstring>

using namespace std;

int main(){
  while(1){
    int n;
    char t[256];
    scanf("%d %s", &n, t);

    if (n==0) break;

    string s(t);

    int count;
    char buf, tmp[256];

    for(int i=0;i<n;i++){
      int l = s.length();
      string str;
      count=0;

      for(int j=0;j<l;j++){
        if(j==0 || s[j] == buf){
          count++;
        }else{
          sprintf(tmp, "%d", count*10+(buf-'0'));
          str += string(tmp);
          count = 1;
        }
        buf=s[j];
      }
      sprintf(tmp, "%d", count*10+(buf-'0'));
      str+=string(tmp);
      s = str;
    }

    printf("%s\n", s.c_str());
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main() {
	long long a,b,k;
	scanf("%ld%ld%ld", &a,&b,&k);
	if(a>=k){
		a-=k;
	}else{
		if(b>=k-a){
			b=b-(k-a);
		}else{
			b=0;
		}
		a=0;
	}
	printf("%ld %ld\n", a,b);
	return 0;
}


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

#define int long long
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
int f(string s,int a){
  if(a==0)return -1;
  int res=0,t=1;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    (res+=t*(s[i]=='1'))%=a;
    (t*=2)%=a;
  }
  return res;
}
int p(int a){
  int res=0;
  while(a){
    if(a&1)res++;
    a>>=1;
  }
  return res;
}
int F(int a){
  int res=0;
  while(a){
    res++;
    a%=p(a);
  }
  return res;
}

ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return ans;
}
ll bit2[1000010]={};

ll getIntSubstr(string s,ll start_index,ll length){
    return atoi(s.substr(start_index,length).c_str());
}

signed main(){
    int n;cin>>n;
    string s;cin>>s;
    int sum=0;
    for(char p:s)sum+=p=='1';
  
    ll base_pop = 0;
    string S = s;
    ll N = n;
    rep(ni,N){
        bit2[ni] = getIntSubstr(S,ni,1);
        //bit2[ni] = 1;
        base_pop+=bit2[ni];
    }
    sum = base_pop;
  
  int A=f(s,sum+1);
  int B=f(s,sum-1);


  for(int i=0;i<n;i++){
    if(sum==1&&s[i]=='1'){
      cout<<0<<endl;
      continue;
    }
    if(s[i]=='0'){
      int res=A;
      res+=getPower(2,n-i-1,sum+1);res%=sum+1;
      cout<<F(res)+1<<endl;
    }
    else{
      int res=B;
      res-=getPower(2,n-i-1,sum-1);
      res+=sum-1;res%=sum-1;
      cout<<F(res)+1<<endl;
    }
  }
}


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

using namespace std;
using ll = long long;
using V = vector<ll>;
using Vv = vector<V>;
using Vvv = vector<Vv>;

int main() {
    ll r, c, k;
    cin >> r >> c >> k;
    Vv items(r, V(c));
    for (int _ = 0; _ < k; _++){
      ll i, j, v;
      cin >> i >> j >> v;
      i--;
      j--;
      items[i][j] += v;
    }
    Vvv dp(r, Vv(c, V(4)));
    for (int i = 0; i < r; i++){
      for (int j = 0; j < c; j++){
        for (int k = 2; k > -1; k--)
          dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + items[i][j]);
        for (int k = 0; k < 4; k++){
          if (i + 1 < r) dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
          if (j + 1 < c) dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
        }
      }
    }
    ll ans = 0;
    for (int k = 0; k < 4; k++) ans = max(ans, dp[r - 1][c - 1][k]);
    cout << ans << endl;
}


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

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

    string s;
    cin >> s;
    int res = 0;
    rep(i, s.size()){
        if(s[i] == '2') ++res;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
int main(){
  int i,count[26]={0};
  char ch;
  while((ch=getchar())!=EOF){
    ch=tolower(ch);
    count[ch-'a']++;
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n",'a'+i,count[i]);
  }
  return 0;
}

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

#define endl "\n"
#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll int a,b,c,d,x,y,z,w,ans;
	cin >> a >> b >> c >> d;
	x=a*c;
	y=a*d;
	z=b*c;
	w=b*d;
	ans=max(x,w);
	ans=max(ans,y);
	ans=max(ans,z);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  int a[1001],b[1001];
  int flag[1001]={0};
  int ansp=-1;
  int count[1001]={0};
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(flag[i]==0 && a[j]<=b[i]){
	count[j]++;
	if(ansp==-1){
	  ansp=j;
	}else if(count[j]>count[ansp]){
	  ansp=j;
	}
	flag[i]=1;
	//cout<<j<<endl;
	break;
      }
    }
  }
  cout<<ansp+1<<endl;
  return 0;
}
    

Measured memory_bytes: 1176
A=input()
B=input()
C=input()
count=[0,0,0]
vic=[len(A),len(B),len(C)]
turn='a'
while True:
    if turn=='a':
        if count[0]==vic[0]:
            print('A')
            exit()
        turn=A[count[0]]
        count[0] +=1
    elif turn=='b':
        if count[1]==vic[1]:
            print('B')
            exit()
        turn=B[count[1]]
        count[1] +=1
    else:
        if count[2]==vic[2]:
            print('C')
            exit()
        turn=C[count[2]]
        count[2] +=1
        

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

int main(){
	double a, b, c, d, e, f, x, y;
	
	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
		if (a*e-d*b != 0){
			x = (c*e-f*b)/(a*e-d*b);
			y = (c*d-f*a)/(b*d-e*a);
			if (x == -0.000){ x = 0.000; }
			if (y == -0.000){ y = 0.000; }
			printf("%.3f %.3f\n", x, y);
		} else {
			printf("0.000 0.000\n");
		}
	}
	return 0;
}

Measured memory_bytes: 648
// 600

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

typedef long long ll;
typedef unsigned long long ull;

    ll dp[5][200001];

int main(){
    int L;
    cin >> L;
    ll A[200001];
    for(int i=1;i<=L;i++) cin >> A[i];

    for(int i=0;i<5;i++)dp[i][0]=0;
    for(int i=1;i<=L;i++){
        dp[0][i]=dp[0][i-1]+A[i];

        if(A[i]==0) dp[1][i]=min(dp[0][i-1], dp[1][i-1])+2;
        else        dp[1][i]=min(dp[0][i-1], dp[1][i-1])+A[i]%2;

        dp[2][i]=min(min(dp[0][i-1],dp[1][i-1]),dp[2][i-1])+(A[i]+1)%2;

        dp[3][i]=min(min(min(dp[0][i-1],dp[1][i-1]),dp[2][i-1]),dp[3][i-1]);
        if(A[i]==0) dp[3][i] += 2;
        else dp[3][i] += A[i]%2;

        dp[4][i]=min(min(min(min(dp[0][i-1],dp[1][i-1]),dp[2][i-1]),dp[3][i-1]),dp[4][i-1])+A[i];
    }
    
    int i=L+1;
    cout << min(min(min(min(dp[0][i-1],dp[1][i-1]),dp[2][i-1]),dp[3][i-1]),dp[4][i-1]) << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int gcd(int a, int b) {
  while( b ) {
    int t = a % b;
    a = b, b = t;
  }
  return a;
}

int main(void) {
  int w, h, c;
  scanf("%d%d%d", &w, &h, &c);
  printf("%d\n", w * h / gcd(w, h) / gcd(w, h) * c);
  return 0;
}


Measured memory_bytes: 2724