akhauriyash/Code-Regression huggingface dataset:
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#define REPP(i,j,n) for(int i=j;i<n;++i)
#define REP(i,n) REPP(i,0,n)

using namespace std;
typedef long long LL;
typedef pair<LL,LL>  PLL;
typedef complex<double> cpx;

inline LL scan(){
  static LL a ;
  scanf("%lld",&a);
  return a;
}

LL A[100010];
int main(){
  LL n=scan();
  REP(i,n)A[i]=scan();
  sort(A,A+n,[=](LL a,LL b){return b<a;});
  LL ans=0;
  priority_queue<LL> pq;
  for(int i=0;i<n;++i){
    if(A[i]==A[i+1]){
        pq.push(A[i]);
      if(A[i]==A[i+3])
        pq.push(A[i]),i+=3;
      else i+=1;
    }
  }
  if(pq.size()<2)return 0*puts("0");
  LL l=pq.top();pq.pop();
  printf("%lld\n",l*pq.top());
}

Measured memory_bytes: 1660
#include <iostream>
using namespace std;
int a,b,c,d;
int sum1,sum2;
int main(){
    cin >> a >> b >> c >> d;
    sum1=a+b;
    sum2=c+d;
    if(sum1>sum2) cout<<"Left";
    if(sum2>sum1) cout<<"Right";
    if(sum1==sum2) cout<<"Balanced";
}

Measured memory_bytes: 256
#include <cstdio>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

int a, b, c, d, e, f, mx1, mx2, wa, su;

int main()
{
    scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); mx1 = 100 * a;
    FOR(i, 0, f / a / 100) FOR(j, 0, f / b / 100) FOR(k, 0, f) FOR(l, 0, f)
    {
        wa = a * i * 100 + b * j * 100;
        su = k * c + l * d;
        if (wa + su > f || su * 100 > e * wa) break;
        if (su * mx1 > (wa + su) * mx2) mx1 = wa + su, mx2 = su;
    }
    printf("%d %d\n", mx1, mx2);
    return 0;
}


Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ k, x ] <- readInts
	printList [ x - k + 1 .. x + k - 1 ]

printList [a] = print a
printList (a:as) = do
	printf "%d " a
	printList as

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long X){
  int fh = X / 500;
  int ff = X % 500 / 5;
  cout << fh * 1000 + ff * 5 << endl;
}

signed main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.nextLine();
        String c = sc.nextLine();

        int flag = 0;
        if(c.charAt(a) != '-'){
            flag++;
        }

        String d = c.substring(0,a);
        String e = c.substring(a+1,c.length());
        if(a != d.length() || b != e.length()){
            flag++;
            System.out.println(a);
            System.out.println(d.length());
            System.out.println(b);
            System.out.println(e.length());
        }
        int count =0;
        for(char x: c.toCharArray()){
            if(x == '-'){
                count++;
            }
        }
        if(count != 1){
            flag++;
        }
        if(flag == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main() {
	map<int, string> A, B;
	int N, M; cin >> N >> M;
	for(int i=0; i<N; ++i) cin >> A[i];
	for(int i=0; i<M; ++i) cin >> B[i];
	bool judge=false;
	for(int i=0; i<=N-M; ++i){
	    for(int j=0; j<=N-M; ++j){
	        bool check=true;
	        for(int k=0; k<M; ++k){
	            if(A[i+k].substr(j, M)!=B[k]){
	                check=false;
	                break;
	            }
	        }
	        if(check){
	            judge=true;
	            break;
	        }
	    }
	    if(judge) break;
	}
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100 + 17;

int n, m, a[MAXN], cnt;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> a[i], cnt += a[i] & 1;
	if (cnt > 2)
		return cout << "Impossible" << endl, 0;
	else if (cnt < 2) {
		if (cnt == 1)
			for (int i = 1; i <= m; i++)
				if (a[i] & 1)
					swap(a[i], a[1]);
		for (int i = 1; i <= m; i++)
			cout << a[i] << ' ';
		cout << endl;
		cout << m + (a[1] > 1) << endl;
		if (a[1] - 1)
			cout << a[1] - 1 << ' ';
		for (int i = 2; i <= m; i++)
			cout << a[i] << ' ';
		cout << 1 << endl;
		return 0;
	}
	else {
		for (int i = 1; i <= m; i++)
			if (a[i] & 1) {
				swap(a[i], a[1]);
				break;
			}
		for (int i = 2; i <= m; i++)
			if (a[i] & 1) {
				swap(a[i], a[m]);
				break;
			}
		for (int i = 1; i <= m; i++)
			cout << a[i] << ' ';
		cout << endl;
		cout << m - (a[1] == 1) << endl;
		if (a[1] - 1)
			cout << a[1] - 1 << ' ';
		for (int i = 2; i < m; i++)
			cout << a[i] << ' ';
		cout << a[m] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Char

main = do
  [a] <- map read . words <$> getLine
  getLine
  getLine
  getLine
  [e] <- map read . words <$> getLine
  [k] <- map read . words <$> getLine
  putStrLn $ if (abs (a-e)) > k then ":(" else "Yay!"

Measured memory_bytes: 508
#include<stdio.h>
#include<string.h>
#define M 1000003 
#define L 14
char H[M][L];
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2; 
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
} /* convert a string into an integer value */ 
int getKey(char str[]){ 
  int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
} 
int h1(int key){ 
  return key%M; 
} 
int h2(int key){ 
  return 1+key%(M-1); 
} 
int find(char str[]){
  int i=0,k,n=0,sum;
  sum=getKey(str);
  while(i<M){
    k=(h1(sum)+i*h2(sum))%M;
    if(H[k][0]=='\0'){
      break;
    }
    if(strcmp(H[k],str)==0){
      n=1;
      break;
    }
    i++;
  }
  return n;
} 
int insert(char str[]){
  int sum,i=0,k; 
  sum=getKey(str);
  while(i<M){
    k=(h1(sum)+i*h2(sum))%M;
    if(H[k][0]=='\0'){
      strcpy(H[k],str);
      break;
    }
    i++;
  }
  
}
int main(){
  int i, n, h,k=0; 
  char str[L], com[9], sc[500000][4];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    if(i<n)break;
  }
  
  for ( i = 0; i < n; i++ ){ 
    scanf("%s %s", com, str);
    if ( com[0] == 'i' ){ 
      insert(str); 
    }
    else {
      if (find(str)){ 
	strcpy(sc[k],"yes");
        k++;
      }
      else {
	strcpy(sc[k],"no");
	k++;
      }
    }
  }
  for(i=0;i<k;i++){
    printf("%s\n",sc[i]);
  }
  return 0;
}



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

using namespace std;

long long a[100001];
long long b[100001];	

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i] >> b[i];
	}
	long long cur = 0;
	for (int i = n;i >= 1;i --) {
		a[i] += cur;
		long long kol = b[i] * (a[i] / b[i] + 1 - (a[i] % b[i] == 0));
		cur += kol - a[i];
	}
	cout << cur;
	return 0;
}

Measured memory_bytes: 1792
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for a in range(0, n-1):
    for b in range(a+1, n):
        right = bisect.bisect_left(l, l[a]+l[b])
        left = b + 1
        ans += right - left
print(ans)

Measured memory_bytes: 3188
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
ans=0
c=0
for i in range(0,len(a),2):
    if c>n:
        break
    #print(a[i],a[i+1],min(a[i],a[i+1]))
    ans+=min(a[i],a[i+1])
    c+=1
print(ans)


Measured memory_bytes: 2940
S = input()
flg = True

for i in range(len(S)):
    if i % 2 == 0 and S[i] == 'L':
        flg = False
    if i % 2 == 1 and S[i] == 'R':
        flg = False

if flg: print('Yes')
else:
    print('No')

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

int main()
{
	int x, sum  = 0;
	cin >> x;
	while(x)
	{
		if(x >= 500)
		{
			x-=500;
			sum += 1000;
		}
		
		else if(x >= 5)
		{
			x-=5;
			sum += 5;
		}
		
		else break;
	}
	cout << sum;
	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, M = MI()
    
    # 1 -> ? -> N
    S = [0] * N
    for i in range(M):
        a, b = MI()
        if a == 1:
            S[b] += 1
        elif b == N:
            S[a] += 1
    
    for s in S:
        if s >= 2:
            print('POSSIBLE')
            return 
    print('IMPOSSIBLE')

if __name__ == '__main__':
    solve()



Measured memory_bytes: 10668
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n<1000) System.out.println("ABC");
        else System.out.println("ABD");
    }
}


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

using namespace std;

int main(){
    int x,y,ans=0;
    cin >> x >> y;
    if(x==1){
        ans += 300000;
    }else if(x==2){
        ans += 200000;
    }else if(x==3){
        ans += 100000;
    }

    if(y==1){
        ans += 300000;
    }else if(y==2){
        ans += 200000;
    }else if(y==3){
        ans += 100000;
    }

    if(x==1 && y==1){
        ans += 400000;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int count = scan.nextInt();
    List<Integer> list = new ArrayList<>();
    while (scan.hasNextInt()) {
      list.add(scan.nextInt());
    }
    Collections.sort(list);
    double x = 0;
    for (int num : list) {
      x = x==0?num:(num+x)/2;
    }
    System.out.println(x);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

void min_select(ll &a, ll b){
    a = min(a,b);
}

const ll INF = 1e18L + 5;

int main(){
    
    int n, w;
    scanf("%d%d", &n, &w);
    vector<int> weight(n), value(n);
    for(int i = 0; i < n; ++i){
        scanf("%d%d", &weight[i], &value[i]);
    }
    int sum_value = 0;
    for(int &x : value){
        sum_value += x;
    }
    vector<ll> dp(sum_value + 1, INF); 
    //dp[i] - the minimum total weight of item with total value exactly i
    dp[0] = 0;
    for(int item = 0; item < n; ++item){
        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already){
            min_select(dp[value_already + value[item]], dp[value_already] + weight[item]);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= sum_value; ++i){
       if(dp[i] <= w){
           answer = max(answer,(ll) i);
       }
    }
    printf("%lld\n", answer);

    return 0;
}

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

using namespace std;

int v[123456], w[123456];
long long ans[105][123456];
int N, W;

int main(int argc, char *argv[])
{
  cin >> N >> W;

  std::fill(ans[0], ans[0] + W, 0);
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
    ans[i][0] = 0;
  }

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j < w[i]) {
        ans[i][j] = ans[i-1][j];
      } else {
        ans[i][j] = max(ans[i][j-w[i]], max(ans[i-1][j], ans[i-1][j-w[i]] + v[i]));
      }
    }
  }

  cout << ans[N][W] << endl;
  return 0;
}


Measured memory_bytes: 98176
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repe(i, n) REPN(i, 0, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

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

	Vec2<ll> dp0(n+1, Vec(k+1)), dp1(n+1, Vec(k+1));

	dp1[0][0] = 1;

	repn(i, n){
		repe(j, k){
			if(s[i-1] == '0'){
				dp0[i][j] = dp0[i-1][j];
				dp1[i][j] = dp1[i-1][j];
				if(j) dp0[i][j] += 9*dp0[i-1][j-1];
			}else{
				ll m = s[i-1]-'0';
				dp0[i][j] = dp0[i-1][j];
				dp0[i][j] += dp1[i-1][j];
				if(j){
					dp0[i][j] += 9*dp0[i-1][j-1];
					dp0[i][j] += (m-1)*dp1[i-1][j-1];
					dp1[i][j] = dp1[i-1][j-1];
				}
			}
		}
	}
	co(dp0[n][k]+dp1[n][k]);

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();

        int[] hate = new int[k];
        for (int i = 0; i < k; i++) {
            hate[i] = in.nextInt();
        }

        String number = n + "";
        boolean flag = false;
        int out = n;
        while (true) {
            for (int m : hate) {
                if (number.contains(m + "")) {
                    flag = true;
                    break;
                }} if (!flag){
                    System.out.println(number);
                    return;
                }else {
                    out++;
                    number=out+"";
                    flag=false;

                }
            }
        }


    }

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

int main()
{

  int M, N;
  cin >> N >> M;
  double input[N];
  double max = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> input[i];
    max += input[i];
  }

  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if (input[i] >= max / (4 * (double)M))
    {
      count++;
    }
  }
  if (count >= M)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}
        int n=sc.nextInt();

        int a[] = new int[n];
        long ans=1L<<62;

        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        long s=0,e=0;


        e=max(1,a[0]);  
        if(a[0]<1)s=abs(a[0]-1);
        for(int i=1; i<n; i++){
            e+=a[i];
            if(i%2==1){
                if(e>=0){s+=e+1; e=-1;}
            }
            else{
                if(e<=0){s+=-e+1; e=1; }
            }
        }
        ans =min(ans,s); 

        e=min(-1,a[0]);   s=0;  
        if(a[0]>-1) s=abs(a[0]+1);
        for(int i=1; i<n; i++){
            e+=a[i];
            if(i%2==0){
                if(e>=0){s+=e+1; e=-1;}
            }
            else{
                if(e<=0){s+=-e+1; e=1; }
            }
        }
        ans =min(ans,s); 
        


        out.println(ans);
        out.flush();
    }



    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 36968
def d_blue_and_red_balls(N, K, MOD=10**9 + 7):
    from math import factorial

    def comb(n, r):
        if r == n or r == 0:
            return 1
        if r > n:
            return 0
        return factorial(n) // (factorial(r) * factorial(n - r))

    ans = [comb(N - K + 1, i) * comb(K - 1, i - 1) % MOD for i in range(1, K + 1)]
    return ' '.join(map(str, ans))

N, K = [int(i) for i in input().split()]
print(d_blue_and_red_balls(N, K))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;
        //   cerr << n << m << endl;
        int sh[n + 1], sw[m + 1];
        map<int, int> mph, mpw;
        sh[0] = 0;
        rep(i, 1, n + 1)
        {
            int t;
            cin >> t;
            sh[i] = sh[i - 1] + t;
            //     cerr << "h:" << sh[i] << endl;
        }
        sw[0] = 0;
        rep(i, 1, m + 1)
        {
            int t;
            cin >> t;
            sw[i] = sw[i - 1] + t;
            //  cerr << "w:" << sw[i] << endl;
        }

        rep(i, n + 1) rep(j, i)
        {
            // cerr << i << "," << j << endl;
            //cerr << "*" << sh[i] << "," << sh[j] << endl;
            //cerr << sh[i] - sh[j] << endl;
            mph[sh[i] - sh[j]]++;
        }
        rep(i, m + 1) rep(j, i)
        {
            //     cerr << i << "," << j << endl;
            //    cerr << "*" << sw[i] << "," << sw[j] << endl;
            //   cerr << sw[i] - sw[j] << endl;
            mpw[sw[i] - sw[j]]++;
        }

        ll ans = 0;
        for (auto x : mpw)
        {
            int key = x.first;
            //      cerr << key << "->" << value << endl;
            ans += mph[key] * mpw[key];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 34300
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cctype>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;
#define REP(i,k) for(int (i)=0;(i)<(k);(i)++)
#define INF ~(1<<31)
#define CLR(a) memset((a),0,sizeof((a)))
#define EPS 1e-9
#define DBG 1
#define D(s,v) if(DBG) cout<<(s)<<": "<<(v)<<endl;
#define DVEC(s,v) if(DBG) {cout<<(s)<<": "; for(int i=0;i<(v).size();i++) cout<<(v)[i]<<" "; cout<<endl;}
#define DARR(s,v,n) if(DBG) {cout<<(s)<<": "; for(int i=0;i<n;i++) cout<<(v)[i]<<" "; cout<<endl;}

#define MAX 100005
#define NODIST 10000000000L

vector<pair<int,ll> > edges[MAX];
ll dist[MAX];
bool vis[MAX];

ll mindist, maxdist;

bool dfs(ll node, ll curdist){
    if(dist[node]==NODIST){
        dist[node] = curdist;
        mindist = min(mindist , curdist);
        maxdist = max(maxdist, curdist);
    }
    else if(dist[node] != curdist)
        return false;

    if(vis[node]) return true;
    vis[node] = true;

    for(int i=0;i<edges[node].size();i++){
        int nb = edges[node][i].first;
        int dist = edges[node][i].second;
        if(!dfs(nb, curdist + dist))
            return false;
    }
    
    return true;
}

int main(){
    ios_base::sync_with_stdio(0);

    int N, M;
    while(cin>>N>>M){
        for(int i=0;i<MAX;i++) edges[i].clear();
        for(int i=0;i<MAX;i++) dist[i] = NODIST;
        CLR(vis);

        for(int i=0;i<M;i++){
            int L,R,D;
            cin>>L>>R>>D;
            L--;
            R--;
            edges[L].push_back(make_pair(R,D));
            edges[R].push_back(make_pair(L,-D));
        }

        bool good = 1;
        for(int i=0;i<N;i++){
            if(vis[i]) continue;
            mindist = 1e10;
            maxdist = 0;
            if(!dfs(i,0L)){
                good = 0;
                break;
            }

            if(maxdist - mindist > 1e9){
                good = 0;
                break;
            }
        }

        if(good) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }
}

Measured memory_bytes: 16640
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

int main() {
    string s;
    cin >> s;
    int K;
    cin >> K;
    int len = s.size();
    for (int i = 0; i < len; i++) {
        if (s[i] != 'a' && K >= 'z' - s[i] + 1) {
            K -= 'z' - s[i] + 1;
            s[i] = 'a';
        }
    }
    s[len - 1] += (K % 26);
    cout << s << endl;
}


Measured memory_bytes: 512
n,x,y = map(int,input().split())
x -= 1
y -= 1
cnt = [0]*n
for i in range(n):
    for j in range(i+1,n):
        d = min(j-i,abs(x-i)+1+abs(j-y))
        #print(d,end=' ')
        cnt[d] += 1
for i in range(1,n):
    print(cnt[i])


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	static String rep(int a , int b){
		StringBuilder sb = new StringBuilder();
		for(int i = 0 ; i < b; ++i){
			sb.append(a);
		}
		return sb.toString();
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s1 = rep(a, b);
		String s2 = rep(b ,a);
		if(a < b){
			System.out.println(s1);
		}else{
			System.out.println(s2);			
		}
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
signed main() {
	string s;
	cin >> s;
	f(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i] || s[i] != s[s.size() / 2 - 1 - i] || s[s.size() / 2 + 1 + i] != s[s.size() - 1 - i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--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())

#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
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL a,b;
    cin >> a >> b;
    if ((a+b)%2 == 0) cout << (a + b) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}

int main() {
    solve();
    
    return 0;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> vec(h);
  for(int i=0;i<h;i++){
  	cin >> vec.at(i);
  }
  cout << string(w+2,'#') << endl;
  for(int i=0;i<h;i++){
  	cout << '#' << vec.at(i) << '#' << endl;
  }
  cout << string(w+2,'#');
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll X,Y;
  cin>>X>>Y;
  if(Y>=X*2&&Y<=X*4&&Y%2==0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 3632
import java.util.*;

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

    boolean tmp = true;

    while(tmp){
      String s = sc.next();

      if(s.equals("-")){
        tmp = false;
        break;
      }

      int m = sc.nextInt();

      for(int i = 0; i < m; i++){
        int h = sc.nextInt();
        s = s.substring(h) + s.substring(0, h);
      }

      System.out.println(s);
    }
  }
}



Measured memory_bytes: 26420
#python3
from collections import defaultdict
n,m = map(int, input().split())
a = []
dic = defaultdict(list)
for _ in range(m):
  x,y = map(str, input().split())
  dic[int(x)].append(y)

acc=0
for j in dic.values():
  if 'AC' in j:
    acc+=1;


cnt=0
for li in dic.values():
  if 'AC' in li:
    for j in li:
      if j == 'AC':
        break
      cnt+=1

ans = str(acc) + ' ' + str(cnt)
print(ans) 

Measured memory_bytes: 29804
n = gets.chomp.to_i
result = 0
(1..n).each do |num|
  if ((num%3) == 0 && (num%5) == 0)
  	#puts 'FizzBuzz'
  elsif((num%3) == 0)
    #puts 'Fizz'
  elsif((num%5) == 0)
    #puts 'Buzz'
  else
    result += num
  end
end
puts result

Measured memory_bytes: 14368
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int i,j,k,N;
  cin>>N;
  i=N/100;
  j=(N-100*i)/10;
  k=N-100*i-j*10;
  if(i==7||j==7||k==7)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<_> = st.trim().chars().collect();
    let mut r:i64 = 0;
    let mut c:i64 = 0;
    for i in 0..s.len() {
        if s[i] == 'W' {
            r += c;
        } else {
            c += 1;
        };
    };
    println!("{}", r)
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pair<string, int>> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	map<pair<string, int>, int> mp;
	rep(i, n) {
		mp[p[i]] = i + 1;
	}
	sort(p.begin(), p.end(), [](auto const& x, auto const& y) {
		string s = x.first, t = y.first;
		int sa = x.second, sb = y.second;
		if (s == t) {
			if (sa < sb) return false;
		}
		if (s > t) return false;
		return true;
		});
	rep(i, n) {
		cout << mp[p[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if (a > b)swap(a, b);
	if (a != 1) cout << 1 << endl;
	else if (b != 3) cout << 3 << endl;
	else cout << 2 << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
 
  public static void main(String args[])
  {
		
    Scanner s = new Scanner (System.in);
    String input=s.next();
    
    if(input.contains("ABC"))
      System.out.println("ARC");
   	else 
       System.out.println("ABC");
    
    
    
 
  }
 
 
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007

int main() {
	int h, w, a, b;
	scanf("%d%d%d%d", &h, &w, &a, &b);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++)
			printf("%d", (int)((i<b) ^ (j<a)));
		printf("\n");
	}
}

Measured memory_bytes: 1280
import collections
N,K=[int(_) for _ in input().split()]
AB=[[int(_) for _ in input().split()] for _ in range(N-1)]
mod=10**9+7
G=collections.defaultdict(set)
for a,b in AB:
    G[a].add(b)
    G[b].add(a)
count=collections.defaultdict(int)
for i in range(1,N+1):
    count[i]=len(G[i])-1
ans=collections.defaultdict(int)
for k,v in count.items():
    if k!=1:
        ans[v]+=1
#1   2   3
#K-2 K-3 .. K-v
fact=[0]*(N+1)
fact[0]=1
fact[1]=K-2
for i in range(2,N+1):
    fact[i]=fact[i-1]*(K-i-1)%mod
#ret=K*(K-1)*(K-2)*(K-3)
ret=K
for i in range(len(G[1])):
    ret*=(K-1-i)
ret%=mod
for k,v in ans.items():
    ret*=pow(fact[k],v,mod)
    ret%=mod
print(ret)

Measured memory_bytes: 68968
#include<iostream>

using namespace std;

int main(){
  int n,m,c;
  int ans, count = 0;

    cin >> n >> m >> c;
  int a, b[m];



  for(int i = 0; i < m; ++i){
    cin >> b[i];
  }

  for(int i = 0; i < n; ++i){
    ans = 0;
    for(int j = 0; j < m; ++j){
      cin >> a;
      ans += a * b[j];
    }
    if(ans + c > 0) count++;
  }

  cout << count << endl;
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;





int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);

    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll> > AB(N);
    rep(i, N){
        ll a, b;
        cin >> a >> b;
        //debug(a)
        AB[i] = pair<ll, ll>(a, b);
    }
    sort(all(AB));

    ll c = 0;
    ll ans = 0;
    for(int i = 0; i < N; i++){
        pair<ll, ll> ab = AB[i];
        if(c+ab.second >= M){
            cout << ans+ab.first*(M-c) << "\n";
            return 0; 
        }
        ans += ab.first * ab.second;
        c+=ab.second;
    }
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long n = scan.nextInt();
        long out = 0;
        for(long i = 1; i <= n; i++){
            if(i % 3 != 0 && i % 5 != 0){
                out += i;
            }
        }
        System.out.println(out);
    }
}

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

int main()
{
  int H, N;
  cin >> H >> N;
  bool ans = false;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    H -= a;
    if (H <= 0)
    {
      ans = true;
      break;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}


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

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

#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n; //最大で10000
    int a, b;
    cin >> a >> b;

    int wa = 0;
    REP(i, n + 1) //1から"Nまで"探す
    {
        //各桁を取り出して和をとる
        // wa += i % 10;
        // wa += i / 10 % 10;
        // wa += i / 100 % 10;
        // wa += i / 1000 % 10;
        // wa += i / 10000 % 10; //10^4までなので

        int num = i;
        while (num > 0)
        {
            wa += num % 10;
            num /= 10;
        }

        //和が条件を満たしていたらカウント
        if (wa >= a && b >= wa)
        {
            //cout << "満たしている" << i << endl;
            count += i;
        }
        wa = 0;
    }
    cout << count << endl;

    //-----------
    cin >> Z;
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // abc176_a();
    abc176_b();
  }

  private static void abc176_a() {
    try (Scanner sc = new Scanner(System.in)) {
      double nAll = sc.nextInt();
      double xOneTime = sc.nextInt();
      int tMinute = sc.nextInt();

      System.out.println((int) Math.ceil(nAll / xOneTime) * tMinute);

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  private static void abc176_b() {
    try (Scanner sc = new Scanner(System.in)) {
      String nValue = sc.next();
      ArrayList<Integer> numList = new ArrayList<Integer>();

      for (int i = 1; i <= nValue.length(); i++) {
        numList.add(parseI(nValue.substring(i - 1, i)));
      }

      int sum = 0;

      for (int num : numList) {
        sum += num;
      }

      if (sum % 9 == 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }

  // int 2147483648 [ 2 * 10(9)]
  // long 9223372036854775808 [ 9 * 10(18)]

  public static int parseI(String value) {
    return Integer.parseInt(value);
  }

  public static long parseL(String value) {
    return Long.parseLong(value);
  }

  public static double parseD(String value) {
    return Double.parseDouble(value);
  }

  public static <T> String parseS(T value) {
    return String.valueOf(value);
  }

  public static BigDecimal parseBigD(String value) {
    return new BigDecimal(value);
  }

  public static BigInteger parseBigI(String value) {
    return new BigInteger(value);
  }

}


Measured memory_bytes: 53132
N, C, K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort(reverse=True)

#print(T)
t_before = T[0]
cnt = 0
ans = 0
for t in T:
    #print(t, t_before, cnt, ans)
    if t_before - t <= K and cnt + 1 <= C:
        cnt += 1
        continue
    else:
        t_before = t
        cnt = 1
        ans += 1

print(ans+1)

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

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


Measured memory_bytes: 256
x = []
y = []
i = 0

while True:
  a, b = map(int, input().split())
  if b < a:
    stock = a
    a = b
    b = stock
  x.append(a)
  y.append(b)
  if x[i] == 0 and y[i] == 0:
    break
  i += 1

for j in range(i):
  print(str(x[j]), str(y[j]))

Measured memory_bytes: 8040
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <map>
#include <math.h>
#include <time.h>
#include <vector>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

#define ll long long

using namespace std;

void
update(int from, int index, int c, map<pair<int, int>, int> & color, vector<vector<int>> & link) {
  int now = 1;
  for (int next : link[index]) {
    if (next == from) continue;

    if (now == c) now++;
    color[{next, index}] = now;
    color[{index, next}] = now;
    update(index, next, now, color, link);
    now++;
  }
}

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

  int a, b;
  vector<vector<int>> l(n+1, vector<int>());
  vector<pair<int, int>> d;
  for (int i=0; i<n-1; i++) {
    cin>>a>>b;

    l[a].push_back(b);
    l[b].push_back(a);
    d.push_back({a, b});
  }

  int root = 1;
  for (int i=1; i<=n; i++)
    if (l[i].size() > l[root].size())
      root = i;

  map<pair<int, int>, int> color;
  int now = 1;
  for (int next : l[root]) {
    color[{next, root}] = now;
    color[{root, next}] = now;
    update(root, next, now, color, l);
    now++;
  }

  cout<<l[root].size()<<endl;
  for (auto p : d) 
    cout<<color[p]<<endl;
 
  return 0;
}



Measured memory_bytes: 21368
object Main extends App {
  val S = io.StdIn.readLine().toString.toCharArray.map(_.toInt)

  var prev = 0
  var result = "Good"

  S.zipWithIndex.foreach {
    case (s, 0) => prev = s
    case (s, _) =>
      if (s == prev) result = "Bad"
      prev = s
  }

  println(result)
}

Measured memory_bytes: 25420
import java.io.*;
public class Main{
  public static void main(String args[]) throws IOException{
    BufferedReader reader  = new BufferedReader (new InputStreamReader(System.in));
    String[] list = reader.readLine().split(" ");
    if(Integer.parseInt(list[0])+Integer.parseInt(list[1])+Integer.parseInt(list[2]) >=22){
      System.out.println("bust");
    }
    else{
      	System.out.println("win");
    }}}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	int n,m,q=0;
	std::cin >>n>>m;


	std::vector<int> v(m);
	for (int& x : v) {
		std::cin >> x;
	}

	std::vector<int> vv;

	
	if(m <= n) {
		std::cout << 0 << std::endl;
		exit(0);
	}
	

	std::sort(v.begin(), v.end());

	std::reverse(v.begin(), v.end());

	for (int i = 0; i < v.size()-1; i++) {
		vv.push_back(v[i]-v[i+1]);
	}

	std::sort(vv.begin(), vv.end());

	//std::reverse(vv.begin(), vv.end());

	for (int i = 0; i < vv.size()-n+1; i++) {
		q += vv[i];
	}





	std::cout << q << std::endl;
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

class UnionFind {
private:
  int n;
  vector<int> a;
public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));}
  bool equal(int x, int y) {return find(x) == find(y);}
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    n--;
  }
  int size() {return n;}
  int size(int x) {return -a[find(x)];}
};

struct Edge {
  int a, b, w;
  bool operator<(const Edge &e) const {return w < e.w;}
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    vector<Edge> edge(m);
    rep (i, m) cin >> edge[i].a >> edge[i].b >> edge[i].w;
    rep (i, m) --edge[i].a;
    rep (i, m) --edge[i].b;
    sort(edge.begin(), edge.end());
    int res = 1e9;
    rep (i, m) {
      UnionFind uf(n);
      for (int j = i; j < m; ++j) if (!uf.equal(edge[j].a, edge[j].b)) {
	  uf.unite(edge[j].a, edge[j].b);
	  if (uf.size() == 1) {
	    res = min(res, edge[j].w - edge[i].w);
	    break;
	  }
      }
    }
    if (res == 1e9) cout << -1 << endl;
    else cout << res << endl;
  }
}

Measured memory_bytes: 1272
/***************************************************************
	File name: C.cpp
	Author: ljfcnyali
	Create time: 2019年09月01日 星期日 19时57分39秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

const int maxn = 100010;

int n, a[maxn], ans, sum;

int main()
{
    scanf("%d", &n);
    REP(i, 1, n) scanf("%d", &a[i]);
    REP(i, 1, n - 1)
    {
        if ( a[i] >= a[i + 1] ) ++ sum;
        else { ans = max(ans, sum); sum = 0; }
    }
    ans = max(ans, sum);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		long voteT = sc.nextLong();
		long voteA = sc.nextLong();
		int prevT = (int)voteT;
		int prevA = (int)voteA;
		for(int i = 1; i < n; i++){
			int t = sc.nextInt();
			int a = sc.nextInt();

//			System.out.println(prevT +" "+ prevA+" " + t + " " + a);
			if(prevT == t && prevA == a){
				continue;
			}

			if(voteT % t != 0){
				voteT += t - (voteT % t);
			}

			if(voteA % a != 0){
				voteA += a - (voteA % a);
			}

			if(voteT < voteA/a*t){
				voteT = voteA/a*t;
			}
			else{
				voteA = voteT/t*a;
			}

			prevT = t;
			prevA = a;
//			System.out.println(voteT + " " + voteA);
		}

		System.out.println(voteT + voteA);
	}

}


Measured memory_bytes: 31060
#include <iostream>
using namespace std;
int main() {
string str;
string rr="";
string ss="";
int b;
cin >> str;
cin >> b;
for (int i =0; i<str.length(); i = i + b){
rr = str.substr(i, b);
ss+=rr[0];
}
cout << ss << endl;
}



Measured memory_bytes: 256
import collections
n = int(input())
s = [[0 for j in range(10)] for i in range(n)]
for i in range(n):
    t = input()
    s[i] = "".join(sorted(t))
ans = 0

c = collections.Counter(s)
for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)

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

int main(){
	int k=0;
	while(1){
		int a, b, x[3000];
		int l=0;
		
		cin >> a >> b;
		
		if(a==0 && b==0) break;
		else if(k!=0) cout << endl;
		
		k++;
		
		for(int i=a; i<=b; i++){
			if(0==i%4 && 0!=i%100 ){
				x[l]=i;
				l++;
			}else if(0==i%400){
				x[l]=i;
				l++;
			}
		}
		
		if(l==0) cout << "NA" <<endl;
		
		for(int m=0; m<l && l!=0; m++){
			cout << x[m] <<endl;
		}
		
	}
}

Measured memory_bytes: 1172