akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second

typedef long long ll;
typedef std::pair < int, int > pr;
const int N = 1e5 + 54;

using std::cin;
using std::cout;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }

int n, U[N], M[N], D[N];
ll ans, s[N], ans1;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> U[i];
    for (int i = 1; i <= n; ++i) cin >> M[i];
    for (int i = 1; i <= n; ++i) cin >> D[i];
    std::sort(U + 1, U + n + 1);
    std::sort(M + 1, M + n + 1);
    std::sort(D + 1, D + n + 1);
    for (int i = n; i; --i) s[i] = n - (std::upper_bound(D + 1, D + n + 1, M[i]) - D) + 1;
    for (int i = n; i; --i) s[i] = s[i + 1] + s[i];
    for (int i = 1; i <= n; ++i) ans += s[std::upper_bound(M + 1, M + n + 1, U[i]) - M];
    cout << ans << '\n';
    return 0;
}



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

int main(){
    long long N,a;
    int Z=26; //26^nで次のアルファベットの桁に移る
    string ans ="";
    cin >> N ;
    while(N>0){
        N--;
        a=N%Z;
        N/=Z;
        ans+='a'+a; //aから割ったあまりの分文字コードを移動する
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main(void){
	int b, r, g, c, s, t;
	while(1){
		cin >> b >> r >> g >> c >> s >> t;
		if((b | r | g | c | s | t) == 0){
			break;
		}
		cout << (100 + (b * 15 + r * 15 + (b * 5 + r * 3) * 15 + g * 7 + c * 2) - (t - (b * 5 + r * 3 + s)) * 3 - (b * 5 + r * 3) * 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}
int main(){
	cmbset(200002);
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	LL n,a,b,c,ans=0;
	cin>>n>>a>>b>>c;
	LL aa=dvs(a,a+b);
	LL bb=dvs(b,a+b);
	cerr<<aa<<" "<<bb<<endl;
	FOR(i,0,n){
		ans=add(ans,mul(i+n,mul(cmb(add(n-1,i),i),add(mul(power(aa,n),power(bb,i)),mul(power(bb,n),power(aa,i))))));
		//ans=add(ans,mul(i+n,mul(cmb(add(n-1,i),i),mul(pow(bb,n),pow(aa,i)))));
	}
	cerr<<ans<<endl;
	cout<<mul(ans,dvs(100,100-c))<<endl;

	return 0;
}


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int N,A,B;
    cin >> N >> A >> B;
    if(N == 1){
        if(A == B){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        if(A > B){
            cout << 0 << endl;
        }else if(A == B){
            cout << 1 << endl;
        }else{
            ll max_v = 1LL*(N-1) * B + A;
            ll min_v = 1LL*(N-1) * A + B;
            cout << max_v - min_v + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


int main() {
	int n, m;
	cin >> n >> m;
	if (n == m)PRIY;
	else PRIN;
	return 0;
}

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

int main(){
    bool A=1;
    while (A){
        string s;
        cin >> s;
        int sum=0;
        if (s=="0") {return 0;}
        for (int i=0; i<s.size(); i++){
            sum+=s.at(i)-48;
        }
        cout << sum << endl;
    }
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	string s;
	cin >> s;
	int N = s.size();
	vector<int> v(N, 1);
	vector<bool> b(N, false);
	vector<int> dist(N,0);
	int btrue = (int)MOD;
	int ctrue = (int)MOD;
	for (int i = 0; i < N; i++) {
		if (i != 0) {
			if (s[i] != s[i - 1] && s[i] == 'L') {
				b[i] = true;
				btrue = min(btrue, i);
			}
		}
		if (i != N - 1) {
			if (s[i] != s[i + 1] && s[i] == 'R') {
				b[i] = true;
				btrue = min(btrue, i);
			}
		}
	}
	for (int i = 1; i < N; i++) {
		if (s[i] == 'L') {
			if (b[i]) {
				dist[i] = 0;
			}
			else {
				dist[i] = dist[i - 1] + 1;
			}
		}
	}
	for (int i = N - 2; i >= 0; i--) {
		if (s[i] == 'R') {
			if (b[i]) {
				dist[i] = 0;
			}
			else {
				dist[i] = dist[i + 1] + 1;
			}
		}
	}
	//debugv(dist);
	vector<int>ans(N, 0);
	for (int i = 0; i < N; i++) {
		if (s[i] == 'R') {
			ans[i + dist[i] + (dist[i] % 2)]++;
		}
		else {
			ans[i - dist[i] - (dist[i] % 2)]++;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i];
		if (i != N - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{
  string S;

  cin >> S;

  if( S == "RRR"){
    cout << 3 << endl;
  }
  else if( S == "RRS"){
    cout << 2 << endl;
  }
  else if( S == "RSR"){
    cout << 1 << endl;
  }
  else if( S == "RSS"){
    cout << 1 << endl;
  }
  else if( S == "SRR"){
    cout << 2 << endl;
  }
  else if( S == "SRS"){
    cout << 1 << endl;
  }
  else if( S == "SSR"){
    cout << 1 << endl;
  }
  else if( S == "SSS"){
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    while (1)
    {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0)
            break;
        vector<int> h(n + 1, 0), w(m + 1, 0);
        rep(i, n) cin >> h[i + 1];
        rep(i, m) cin >> w[i + 1];
        rep(i, n) h[i + 1] += h[i];
        rep(i, m) w[i + 1] += w[i];
        map<int, int> cnt;
        rep(i, n + 1) Rep(j, i + 1, n + 1)
        {
            int d = h[j] - h[i];
            cnt[d]++;
        }
        int ans = 0;
        rep(i, m + 1) Rep(j, i + 1, m + 1)
        {
            int d = w[j] - w[i];
            ans += cnt[d];
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 26920
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    queue< pair<string, int> > Q;
    string name;
    int time;
    for (int i = 0; i < n; i++) {
        cin >> name >> time;
        Q.push(make_pair(name, time));
    }

    int ans = 0;
    pair<string, int> tmp;
    while (!Q.empty()) {
        tmp = Q.front();
        Q.pop();
        int t = min(q, tmp.second);
        tmp.second -= t;
        ans += t;
        if (tmp.second > 0) Q.push(tmp);
        else cout << tmp.first << " " << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6336
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define N 100005
vi par(N);
vi unionrank(N);
void init(int n)
{
    rep(i, n)
    {
        par[i] = i;
        unionrank[i] = 0;
    }
}
int root(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = root(par[x]);
    }
}
void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y)
    {
        return;
    }
    if (unionrank[x] < unionrank[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (unionrank[x] == unionrank[y])
        {
            unionrank[x]++;
        }
    }
}
bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int a[m];
    int b[m];
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    rep(i, m)
    {
        init(n);
        bool flag = true;
        rep(j, m)
        {
            if (i == j)
            {
                continue;
            }
            unite(a[j], b[j]);
        }
        rep(k, n-1)
        {
            if (root(k) != root(k + 1))
            {
                flag = false;
            }
        }
        if (!flag)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
	int i, j, r, n, K;
	if (scanf("%d", &K), K == 1) return puts("1\n1"), 0;
	printf("%d\n", n = (K + 3) / 4 * 2);
	for (i = 0; i < n; ++i)	
		for (j = 0; j < n; ++j)
			r = (i + j) % n + (i & 1 ? n : 0),
 			printf("%d%c", r - (r >= K ? n : 0) + 1, j == n - 1 ? 10 : 32);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl

#define INF 1e9+5
#define N 40001
#define MAXN   100001


bool sortbysec(const tuple<int, int, int>& a,  
               const tuple<int, int, int>& b) 
{ 
    return (get<1>(a) < get<1>(b)); 
}



int spf[0];
void sieve(){
	spf[1] = 1;
	for(int i=2;i<MAXN;i++) spf[i] = i;

	for(int i=4;i<MAXN;i+=2) spf[i] = 2;

	for(int i=3; i*i<MAXN;i++){
		if(spf[i]==i){
			for(int j=i*i;j<MAXN;j+=i){
				if(spf[j]==j) spf[j] = i;
			}
		}
	}
}
bool custom(const pair<int, int>& a,  
               const pair<int, int>& b) 
{ 
    if(a.first==b.first) return a.second < b.second;
	return a.first > b.first; 
}

// A.reize(unique(A.begin(),A.end())- A.begin());
#define int long long
void solve(){
	int a; long double b; cin>>a>>b;

	long double res = a*b;
	cout<<(int)floor(res)<<endl;
}

signed main() {
IOS;
	int t=1; 
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}




vector<int> getFactorization(int x){

	vector<int> primeFactors;
	while(x>1){
		primeFactors.pb(spf[x]);
		x /= spf[x];
	}
	return primeFactors;
}


Measured memory_bytes: 3784
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    int a=1;
    int b=1;
    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
        printf("%dx%d=%d\n",a,b,a*b);
        b++;
        }
        b=1;
        a++;
    }
    return 0;
}


Measured memory_bytes: 2040
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())

cnt=1
while cnt*(cnt+1)//2<n:
    cnt+=1

# print(cnt)

while n:
    if n>=cnt:
        n-=cnt
        print(cnt)
        cnt-=1
    else:
        print(n)
        n=0

Measured memory_bytes: 9844
N = int(input())
S = input()

sets = set(S)
ans = 0
for i in range(1,N):
    cnt = 0
    for s in sets:
        l = 0
        r = 0
        for j in S[:i]:
            if j ==s :
                l=1
                break
        for j in S[i:N]:    
            if j == s  :  
                r=1
                break
        if l*r == 1:
            cnt += 1
    ans = max(ans,cnt)
    
print(ans)

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

int main(){
	int n, x, sum=0;
	scanf("%d %d", &n, &x);
	int vet[n];
	for (int i=0; i<n; ++i)
		scanf("%d", &vet[i]);

	int cont=1;
	for (int i=0; i<n; ++i){
		sum+= vet[i];
		if (sum > x)
			break;
		cont+=1;
	}
	printf("%d\n", cont);
    return 0;
	
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    SortedSet<Integer> set = new TreeSet<>((i1, i2) -> i2 - i1);
    set.add(a + b);
    set.add(a - b);
    set.add(a * b);
    System.out.println(set.first());
  }
}

Measured memory_bytes: 28628
//write your own code folks... //
/*//             _..._
//           .'      '.      _
//          /     .-""-\   _/ \
//        .-|    /:.   |  |   |
//        |  \   |:.   /.-'-./
//        | .-' -;:__.'    =/      
//       .'=    *=|ASH  _.='                                                                                                                                                                                                        
//       /   _.   |    ;
//       ;-.-'|   \    |                      
//     /   |  \   _\  _\
//     \__/'._;.  ==' ==\
//              \    \   |
//              /    /   /  
//              /-._/-._/
//              \   `\  \
//               `-._/._/ Built by King_Atomic....
//*/
#include<bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include<valarray>
#include<deque>
#include <stack>
#include<numeric>
#include <algorithm>
#include <functional>
#include <unordered_map>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace std;
#define ll              long long
#define ps(x,y)         fixed<<setprecision(y)<<x //how much precision is required
#define max(x,y)        ((x>y)?x:y)
#define min(x,y)        ((x<y)?x:y)
#define pb              push_back
#define mp              make_pair
#define gcd(x,y)        __gcd(x,y)
#define vi              vector<int>
#define vl              vector<ll>
#define vc              vector<char>
#define pii             pair<int,int>
#define setbits(x)    __builtin_popcountll(x)// how many 1 are present
#define zrobits(x)      __builtin_ctzll(x)//how many zero are present from left to first 1.
#define PI 3.1415926535897932384626
const int mod = 1000000007;//1e9+7
void ash()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("/home/ashish/Desktop/C++/in.txt", "r", stdin);
    freopen("/home/ashish/Desktop/C++/out.txt", "w", stdout);
#endif
}
int main()
{
    ash();
int n;
cin>>n;
int k;
cin>>k;
vi a;
for(int i=0;i<n;i++)
{
 int x;
 cin>>x;
 a.emplace_back(x);
}
sort(a.begin(),a.end());
vi::iterator it=a.begin();
vi::iterator it1=a.begin();
it1=it1+k;
int sum=0;
while(it!=it1)
{
sum=sum+(*it);
it++;
}
cout<<sum;
}    

 

Measured memory_bytes: 3644
N = int(input())
S = input()

r = 0
g = 0
b = 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

total = r * g * b
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k > N-1:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            total -= 1

print(total)

Measured memory_bytes: 9240
package main

import (
	"fmt"
	"sort"
)

type p struct {
	i     int
	color int
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	A := make([][]int, N)
	an := make([]int, N)
	bn := make([]int, N)
	for i := 0; i < N-1; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		A[a-1] = append(A[a-1], b-1)
		an[i] = a - 1
		bn[i] = b - 1
	}
	q := []*p{{i: 0, color: 0}}
	for _, a := range A {
		sort.Ints(a)
	}
	max := 1
	m := map[string]int{}
	for len(q) > 0 {
		qi := q[0]
		q = q[1:]

		c := 1
		for _, b := range A[qi.i] {
			if c == qi.color {
				c++
			}
			q = append(q, &p{i: b, color: c})
			m[fmt.Sprintf("%d:%d", qi.i, b)] = c
			c++
		}
		if qi.color > max {
			max = qi.color
		}
	}
	fmt.Println(max)
	for i := 0; i < N-1; i++ {
		a, b := an[i], bn[i]
		fmt.Println(m[fmt.Sprintf("%d:%d", a, b)])
	}
}


Measured memory_bytes: 18688
n = [ int(i) for i in input().split()]
m = [[ int(i) for i in input().split()] for i in range(n[0])]

count=0

for i in range (n[0]-1):
  for j in range (i+1, n[0]):
    r = 0
    
    for l in range (n[1]):
      r += (m[i][l]-m[j][l])**2
      
    if r**0.5 == int( r**0.5):
      count += 1
      
print (count)      



Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

#define MAX_NUM (998244353)
#define PI 3.14159265358979323846
using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

i64 modinv(i64 a, i64 m) {
  i64 b = m, u = 1, v = 0;
  while (b) {
    i64 t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

i64 My_Comb(u64 n, u64 k, i64 m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  u64 res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (u64 i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}

u64 My_Pow(u64 a, u64 n, i64 m) {
  u64 tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}

int main() {
  cout << setprecision(18);

  double A, B, H, M;
  cin >> A >> B >> H >> M;
  i64 minute = (H * 60) + M;
  i64 Max_minute = 12 * 60;
  pair<double, double> H_Pos, M_Pos;
  H_Pos.first = A * sin(2 * PI * minute / Max_minute);
  H_Pos.second = A * cos(2 * PI * minute / Max_minute);
  M_Pos.first = B * sin(2 * PI * M / 60);
  M_Pos.second = B * cos(2 * PI * M / 60);
  double res;
  double tmp1, tmp2;
  tmp1 = M_Pos.second - H_Pos.second;
  tmp2 = M_Pos.first - H_Pos.first;
  res = sqrt(tmp1 * tmp1 + tmp2 * tmp2);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4132
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 2e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}
const ll MAX = 51;


ll mat[MAX][MAX];
ll cp[MAX][MAX];
ll n;
void copy(ll a[][MAX],ll b[][MAX]){
  FOR(i,1,n)FOR(j,1,n)a[i][j]=b[i][j];
}

void multiply(ll a[][MAX],ll b[][MAX],ll c[][MAX]){
  ll d[MAX][MAX];
  FOR(i,1,n){
    FOR(j,1,n){
      d[i][j] = 0;
      FOR(k,1,n){
        d[i][j] = add(d[i][j],mul(a[i][k],b[k][j]));
      }
    }
  }
  // cout << "----------------------\n";    
  // FOR(i,1,n){
  //   FOR(j,1,n)cout << d[i][j] << " ";
  //   cout << "\n";
  // }
  copy(c,d);
}

void expo(ll k){
  if(k==1)return;
  expo(k/2);
  multiply(mat,mat,mat);
  if(k%2) multiply(mat,cp,mat);
}

int main(int argc, char const *argv[])
{    
  #ifdef LOCAL_TEST
  freopen("in.txt","r",stdin);
  //freopen("out.txt", "w", stdout);
  #else
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  #endif
    
  ll k;
  cin >> n >> k;

  FOR(i,1,n)FOR(j,1,n)cin >> mat[i][j];
  copy(cp,mat);
  expo(k);
  ll ans = 0;
  // cout << "---------------------\n";
  // FOR(i,1,n){
  //   FOR(j,1,n)cout << mat[i][j] << " ";
  //   cout << "\n";
  // }
  FOR(i,1,n)FOR(j,1,n)ans = add(ans,mat[i][j]);

  cout << ans;


  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstdlib>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n + 2), b(n + 1);
    for(int i = 1; i < n + 1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n + 1; i++){
        b[i] = a[i + 1] - a[i];
    }
    int sum  = 0;
    for(int i = 0; i < n + 1; i++){
        sum += abs(b[i]);
    }
    int ans;
    for(int i = 0; i < n; i++){
        ans = sum  - abs(b[i]) - abs(b[i + 1]) + abs(b[i] + b[i + 1]);
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

bool is_prime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

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

  vector<ll> ans;
  for (ll i = 1; i <= sqrt(g); i++) {
    if (g % i == 0) {
      ans.push_back(i);
      if (g / i != i) {
	ans.push_back(g / i);
      }
    }
  }

  ll cnt = 0;
  for (int i = 0; i < (int)ans.size(); ++i) {
    if (is_prime(ans[i])) cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)

using namespace std;

long long N, D, A;

vector<pair<long long, long long> > XH;
queue<pair<long long, long long> > imo;


int main(){
	cin >> N >> D >> A;
	rep(i, N) {
		long long x, h;
		cin >> x >> h;
		XH.push_back(make_pair(x, h));
	}

	sort(XH.begin(), XH.end());


	long long ans = 0;
	long long cur = 0;
	rep(i, N) {
		long long x = XH[i].first;
		long long h = XH[i].second;
		//cout << "x = " << x << " h = " << h << " cur = " << cur << endl;

		while(!imo.empty() && imo.front().first <= x) {
			cur -= imo.front().second;
			imo.pop();
		}
		//cout << " cur = " << cur << endl;

		if(cur < h) {
			long long cou;
			if((h-cur)%A == 0) {
				cou = (h-cur)/A;
			} else {
				cou = (h-cur)/A + 1;
			}
			//cout << "i = " << i << " plus " << cou << " min " << i + 2 * D + 1 << " dmg = " << cou * A << endl;
			imo.push(make_pair(x + 2 * D + 1, cou * A));
			ans += cou;
			cur += cou * A;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 7968
from fractions import gcd

a,b=map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    return arr
  
d = gcd(a,b)
print(len(factorization(d)) + 1) 


Measured memory_bytes: 5304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
 
const ll N = 302;
const ll mod = 1000000007;
const long long int inf = 2*(1e16);
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
 
 
 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


ll dp[101][100001];

int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    rep1(i,n+1) cin>>a[i];
    if(k==0){
        cout<<1<<endl;
        return 0;
    }
    rep1(i,k+1){
        if(i<a[1]) dp[1][i] = i+1;
        else dp[1][i] =a[1]+1;
    }
    rep1(i,n+1) dp[i][0] = 1;
    for(ll i = 2;i<=n;i++){
        for(ll j = 1;j<=k;j++){
            dp[i][j] = modadd(dp[i][j-1],dp[i-1][j]);
            if(j>a[i]) dp[i][j] = modadd(dp[i][j],mod-dp[i-1][j-a[i]-1]);
        }
    }
    // rep1(i,n+1){
    //     rep1(j,k+1) cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<modadd(dp[n][k],mod-dp[n][k-1]);
    cout<<endl;
    



}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

typedef struct node{
	int p;
	int left;
	int right;
} Node;

int searchHight(int);

Node *node;

int main(){
	
	int n,i,id,depth,tmpP,deg,nowNode,sibling;

	scanf("%d", &n);

	node = malloc(sizeof(Node)*n);

	for (i = 0; i < n; ++i){
		node[i].p = -1;
	}

	for (i = 0; i < n; ++i){
		scanf("%d",&id);
		scanf("%d%d",&node[id].left,&node[id].right);
		node[node[id].left].p = id;
		node[node[id].right].p = id;
	}

	nowNode = 0;
	while(1){
		if (node[nowNode].left != -1 && node[nowNode].right != -1)
		{
			break;
		} else if (node[nowNode].left == -1)
		{
			nowNode = node[nowNode].right;
		} else {
			nowNode = node[nowNode].left;
		}
	}

	//Search
	for (i = 0; i < n; ++i){
		
		//sibling
		tmpP = node[i].p;
		if (tmpP == -1) sibling = -1;
		else if(node[tmpP].left == i) sibling = node[tmpP].right;
		else sibling = node[tmpP].left;

		//depth
		depth = 0;
		while(tmpP != -1){
			tmpP = node[tmpP].p;
			depth++;
		}

		//degree
		deg = 0;
		if (node[i].left != -1) deg++;
		if (node[i].right != -1) deg++;

		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
			,i,node[i].p,sibling,deg,depth,searchHight(i));

		if(node[i].p == -1) printf("root\n");
    	else if(node[i].left == -1 && node[i].right == -1) printf("leaf\n");
    	else printf("internal node\n");
	}

	return 0;
}

int searchHight(int index){
	int hLeft = 0;
	int hRight = 0;

	if (node[index].left != -1){
		hLeft = searchHight(node[index].left) +1;
	}
	if (node[index].right != -1){
		hRight = searchHight(node[index].right) +1;
	}
	if (hLeft < hRight) return hRight;
	else return hLeft;
}

Measured memory_bytes: 612
def gcd(x, y):
    if y==0:
        return x
    return gcd(y, x%y)

def lcm(x, y):
    return x//gcd(x, y)*y

K = int(input())

GCD = [[0 for _ in range(201)] for _ in range(201)]
for i in range(1, 201):
    for j in range(1, 201):
        GCD[i][j] = gcd(i, j)

ans = 0
for a in range(1, K+1):
    for b in range(a, K+1):
        for c in range(b, K+1):
            # t = gcd(gcd(a, b), c)
            t = GCD[GCD[a][b]][c]
            if (a == b and b < c ) or (a < b and b == c):
                ans += 3*t
            elif a < b and b < c:
                ans += 6*t
            else:
                ans += t

print(ans)

Measured memory_bytes: 9516
object Main extends App {
  val Array(n, k) = io.StdIn.readLine().split(' ').map(_.toInt)
  val h = io.StdIn.readLine().split(' ').map(_.toInt)
  val dp = Array.fill(n)(-1)
  for (i <- 0 until n) {
    if (i == 0) dp(i) = 0
    else {
      val cost = ((if (k <= i) i-k else 0) until i).map(j => dp(j) + Math.abs(h(i) - h(j))).min
      dp(i) = cost
    }
  }
  println(dp(n-1))
}

Measured memory_bytes: 111888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderExamCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string tmp = Console.ReadLine();
            string[] tmpSplit = tmp.Split();
            int A, B;
            A = int.Parse(tmpSplit[0]);
            B = int.Parse(tmpSplit[1]);
            int answer = A * B;

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27528
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

g = [set() for _ in range(N)]
for a, b in AB:
    a, b = a-1, b-1
    g[b].add(a)
    g[a].add(b)

mark = [-1]*N
mark[0] = 0
q = deque([0])
while q:
    t = q.popleft()

    for c in g[t]:
        if mark[c] == -1:
            mark[c] = t
            q.append(c)

print("Yes")
for m in mark[1:]:
    print(m+1)

Measured memory_bytes: 98344
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;

const LL INF=1<<30;
const LL MOD=1000000007;






int main(){
    char p,q,r,s;
    cin>>p>>q>>r>>s;
    int a[4];
    a[0]=p-'0';
    a[1]=q-'0';
    a[2]=r-'0';
    a[3]=s-'0';

    int ans2=0;
    for(int i=0;i<8;++i){
        int ans=a[0];
        for(int j=0;j<3;++j){
            if(i&(1<<j)){
                ans+=a[j+1];
            }else ans-=a[j+1];
        }
        if(ans==7){
            ans2=i;
            break;
        }
    }
    cout<<a[0];
    for(int i=0;i<3;++i){
        if(ans2&(1<<i)){
            cout<<'+';
        }else cout<<'-';
        cout<<a[i+1];
    }
    cout<<"=7"<<endl;
}



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

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

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

  int minv, maxv = -1e9;
  minv = a[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, a[i] - minv);
    minv = min(minv, a[i]);
  }

  cout << maxv << endl;
}


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

int main() {
	int n, q;
	string s;
	cin >> n >> q;
	cin >>s;
	vector<int> i(q), r(q);
	for (int j = 0; j < q; ++j)
	{
		cin >> i[j] >> r[j];
	}
	vector<int> t(n + 1);
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'A' && s[i + 1] == 'C')
		{
			t[i + 1] = t[i] + 1;
		}
		else 
		{
			t[i + 1] = t[i];
		}
	}
	for (int k = 0; k < q; ++k)
	{
		cout << t[r[k]-1] - t[i[k]-1] << endl;
	}
}

Measured memory_bytes: 2176
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

a,b = map(int,input().split())

if (a*b)%2==0:
    print("Even")
else:
    print("Odd")

Measured memory_bytes: 2940
from collections import Counter
n = int(input())
s = Counter([str(input()) for _ in range(n)])
max_list = []
max_count = 0
for k, v in s.items():
    if max_count < v:
        max_count = v
        max_list = []
    if max_count == v:
        max_list.append(k)
max_list.sort()
for x in max_list:
    print(x)


Measured memory_bytes: 35572
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a[4],b[3],i,m[3];
    char num[5];
    scanf("%s",num);
    for (i=0;i<4;i++)
    {
        a[i]=num[i]-'0';
    }
    for (i=0;i<8;i++)
    {
        m[0]=i%2;
        m[1]=i/2%2;
        m[2]=i/4%2;
        b[0]=pow(-1,m[0])*a[1];
        b[1]=pow(-1,m[1])*a[2];
        b[2]=pow(-1,m[2])*a[3];
        if (a[0]+b[0]+b[1]+b[2]==7) break;
    }
    printf("%d",a[0]);
    for (i=0;i<3;i++)
    {
        if (m[i]) printf("-");
        else printf("+");
        printf("%d",a[i+1]);
    }
    printf("=7");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,x,y,temp;
    scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
    int ans=1e9;
    if(x>y)
    {
        temp=x;
        x=y;
        y=temp;
        temp=a;
        a=b;
        b=temp;
    }
    if(x*a+y*b<ans)ans=x*a+y*b;
    if(x*2*c+(y-x)*b<ans)ans=x*2*c+(y-x)*b;
    if(2*y*c<ans)ans=2*y*c;
    printf("%d\n",ans);
    return 0;

}

Measured memory_bytes: 128
function Main(s) {
  var s = s.split("\n").map(e => e*1);
  var cnt = 0, idx = 1, flag = false;
  for(var i = 1; i <= s[0]; i++) {
    cnt++;
    if (s[idx] === 2) {
      flag = true;
      break;
    } else {
      idx = s[idx];
    }
  }
  console.log(flag ? cnt:-1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  ll K;
  cin>>s;
  string q = s;
  cin>>K;
  ll p = s.size();
  ll cnt = 0;
  for(ll i = 0;i<p-1;i++){
    if(s.at(i) == s.at(i+1)){
      cnt++;
      s.at(i+1) = '#';
    }
  }
  ll cnttemp1 = cnt;
  string ss = s+q;
  for(ll i = 0;i<ss.size()-1;i++){
    if(ss.at(i) == ss.at(i+1)){
      cnt++;
      ss.at(i+1) = '.';
    }
  }
  ll cnttemp2 = cnt;
  string sss = ss+q;
  for(ll i = 0;i<sss.size()-1;i++){
    if(sss.at(i) == sss.at(i+1)){
      cnt++;
      sss.at(i+1) = '(';
    }
  }
  if(s.size()==1){
    cout << K/2 << endl;
  }
  else{
    if(K == 1){
      cout << cnttemp1 << endl;
    }
    else if(K == 2){
      cout << cnttemp2 << endl;
    }
    else{
      if(K%2 == 1){
        cout << cnttemp1 + ((K/2)*(cnt-cnttemp1)) << endl;
      }
      else{
        cout << cnttemp1 + ((K-1)/2)*(cnt-cnttemp1)+cnttemp2-cnttemp1 << endl;
      }
    }
  }

  return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define pii pair < int , int >

const int N = 100005;
ll dpb[N], dpw[N];
vector < int > g[N];
const int M = 1e9 + 7;

void dfs(int v, int p = -1)
{
    dpb[v] = dpw[v] = 1;

    for (auto to : g[v])
    if (to != p)
    {
        dfs(to, v);
        dpb[v] *= dpw[to];
        dpb[v] %= M;
        dpw[v] = dpw[v] * dpw[to] + dpw[v] * dpb[to];
        dpw[v] %= M;
    }
//    cout<< v + 1 << " " << dpw[v] << " " << dpb[v] << endl;
}

int main()
{
    #ifdef Estb_probitie
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n;
    cin >> n;

    for (int i = 1; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].pb(y);
        g[y].pb(x);
    }

    dfs(0);
    cout<<(dpw[0] + dpb[0]) % M;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
const int K = 1000;
int v[2*K][2*K];
int s[2*K+1][2*K+1];
const int dx[] = {0,1,2,1,0,-1,-2,-1};
const int dy[] = {2,1,0,-1,-2,-1,0,1};
int main() {
  int n,k;
  cin >> n >> k;
  rep(i,n){
    int x,y; char c;
    cin >> x >> y >> c;
    if(c=='B') x+=k;
    x %= 2*k; y %= 2*k;
    v[x][y]++;
  }
  rep(i,2*k)rep(j,2*k) s[i+1][j+1] = s[i][j+1]+s[i+1][j]-s[i][j]+v[i][j];
  auto f = [&](int x1,int y1,int x2,int y2){
    if(x1>=2*k||y1>=2*k||x2<0||y2<0) return 0;
    x1=max(x1,0); y1=max(y1,0); x2=min(x2,2*k); y2=min(y2,2*k);
    return s[x2][y2] - s[x2][y1] - s[x1][y2] + s[x1][y1];
  };
  int ans = 0;
  rep(i,2*k)rep(j,k){
    int temp = f(i,j,i+k,j+k);
    rep(d,8) {
      int x = i+k*dx[d], y = j+k*dy[d];
      temp += f(x,y,x+k,y+k);
    }
    ans = max(ans,temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 31488
lines = readlines.map(&:strip)
n, k = lines[0].split.map(&:to_i)
s = lines[1].split('')

s[k-1] = 'a' if s[k-1]=='A'
s[k-1] = 'b' if s[k-1]=='B'
s[k-1] = 'c' if s[k-1]=='C'

puts s.join

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
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;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long A, long long B){
    if (A + B == 3) print(3);
    if (A + B == 4) print(2);
    if (A + B == 5) print(1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

t = [s[0]]

for i in range(1, n):
    if s[i-1] != s[i]:
        t.append(s[i])

#print(t)

a = 0

if len(t) <= 2 * k:
    a = n-1
else:
    a = (n-1) - (len(t) - 1 - 2 * k)

print(a)


Measured memory_bytes: 76112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, m;   cin >> n >> m;
    if (n == 1 && m == 0) {
        cout << 0 << endl;
        return 0;
    }
    int *s = new int[m], *c = new int[m];
    for (int i = 0; i < m; i++)
        cin >> s[i] >> c[i];

    int *ans = new int[n];
    for (int i = 0; i < n; i++)
        ans[i] = -1;

    for (int i = 0; i < m; i++) {
        if (ans[s[i]-1] != -1 && ans[s[i]-1] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans[s[i]-1] = c[i];
    }

    if (ans[0] == 0) {
        if (n == 1) {
            cout << 0 << endl;
            return 0;
        }
        cout << -1 << endl;
        return 0;
    }


    for (int i = 0; i < n; i++) {
        if (ans[i] == -1) {
            if (i == 0)
                cout << 1;
            else
                cout << 0;
        }
        else 
            cout << ans[i];
    }

    cout << endl;
    return 0;
}

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

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if ((b+b)>=a)
            System.out.println(0);
        else
            System.out.println(a-(b+b));
    }
}


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

using namespace std;

int gcd(int a, int b) {
  while (b) {
    //a = b*n + r
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    x[i] = abs(x[i] - X);
  }

  int D = x[0];
  for (int i = 1; i < N; i++) {
    D = gcd(D, x[i]);
  }
  cout << D << endl;

  return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int a, b;
	cin >> a >> b;

	cout << max(0, a - 2 * b); 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int N;
  cin >> N;
  int result = 0;
  if(N < 10){
    result = N;
  }
  else if (N < 100){
    result = 9;
  }
  else if (N < 1000){
    result = 9 + (N-99);
  }
  else if (N < 10000){
    result = 9 + 900;
  }
  else if (N < 100000){
    result = 9 + 900 + (N-9999);
  }
  else {
    result = 90909;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256