akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    void solve(){  
        string s,t;
        cin>>s>>t;
        int total=1e5;
        int flag=0;
        for(int i=0;i<(int)s.size();i++){
            int cur=0;
            for(int j=0;j<(int)t.size();j++){
                if(i+j>=(int)s.size()){
                    flag=1;
                    break;
                }
                if(t[j]!=s[i+j])
                    cur++;
            }
            if(flag==1)
                break;
            total=min(total,cur);
        }
        cout<<total;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    char X,Y; cin >> X >> Y;
    if(X==Y) cout << "=" << endl;
    else if(X>Y) cout << ">" << endl;
    else cout << "<" << endl;
    return 0;
}


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

int main()
{
	int R, G, B, N;
	scanf("%d %d %d %d", &R, &G, &B, &N);
	
	int r, g, count = 0;
	for (r = 0; r <= N; r += R) {
		for (g = 0; g <= N - r; g += G) {
			if ((N - r - g) % B == 0) count++;
		}
	}
	
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,A,B,C,D,p=0;
  cin>>N>>A>>B>>C>>D   ;
  string s;
  cin>>s;

  if(C>D){
    p++;
     for(int i=B-1;i<D;i++){
  if(s.at(i-1)=='.'&&s.at(i)=='.'&&s.at(i+1)=='.')
    p=0;
  }
  }
  
  else if(C<D){
  for(int i=A;i<D-2;i++){
  if(s.at(i)=='#'&&s.at(i+1)=='#')
    p++;
  }
  }
  
       for(int i=A;i<C-2;i++){
  if(s.at(i)=='#'&&s.at(i+1)=='#')
    p++;
  }
    
  if(p>0)
  cout<<  "No" <<endl;
  else if(p==0)
    cout<<  "Yes" <<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    // cout << a << b << c << endl;
    if(a == 5){
        if(b==5){
            if(c==7){
                cout << "YES" << endl;
            }
            else{
                cout << "NO" << endl;
            }
        }
        else if(b==7){
            if(c==5){
                cout << "YES" << endl;
            }
            else{
                cout << "NO" << endl;
            }
        }
        else{
            cout << "NO" << endl;
        }
    }
    else if(a==7){
        if(b==5 && c==5){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="RRR")cout<<"3"<<endl;
	else if(s=="SRR"||s=="RRS")cout<<"2"<<endl;
	else if(s=="SSS")cout<<"0"<<endl;
	else cout<<"1"<<endl;

}

Measured memory_bytes: 3592
#import numpy as np
import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    R = first_input[0]

    print(R*2*math.pi)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62040
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  vector<bool> ok(100001, true);
  ok[0] = ok[1] = false;
  loop(i,2,100001) {
    if (!ok[i]) continue;
    for (int j=i*2; j<100001; j += i) {
      ok[j] = false;
    }
  }
  
  vector<int> acc { 0, 0, 0 };
  loop(i,3,100001) {
    if (i%2==0) { acc.push_back(acc[acc.size()-1]); continue; }
    int v = acc[acc.size()-1];
    if (ok[i] and ok[(i+1)/2]) v++;
    acc.push_back(v);
  }
  int q; cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << acc[r] - acc[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 4060
n, q = map(int, input().split())
S = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if S[i : i+2] == "AC" else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 9540
N, M = map(int, input().split())
index = [i for i in range(1, N + 1)]
cnt = [0] * (N)

dict = dict(zip(index, cnt))

s = [0] * M
c = [0] * M

if M == 0:
    if N == 1:
        print(0)
        exit()
    print(10 ** (N - 1))
    exit()

for i in range(0, M):
    s[i], c[i] = map(int, input().split())
    if s[i] == 1 and c[i] == 0 and N != 1:
        print(-1)
        exit()


for i in range(0, M):
    if dict[s[i]] == 0:
        dict[s[i]] = c[i]
    elif dict[s[i]] == c[i]:
        pass
    else:
        print(-1)
        exit()
# print(dict)
ans = ""
for i in range(1, N + 1):
    if i == 1 and dict[1] == 0 and N != 1:
        ans = ans + "1"
    else:
        ans = ans + str(dict[i])
    # print(ans)

print(ans)


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

int main(){
  string s;
  cin>>s;
  do{
    s=s.substr(0,s.size()-1);
    if(s.size()%2==0&&s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size()/2)){
      break;
    }
  }while(s.size()>1);
  cout<<s.size()<<endl;
}

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

namespace ABC042A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C,x;
            String X;
            
            var word = Console.ReadLine().Split(' ');
            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            C = int.Parse(word[2]);
            x = A + B + C;
            if(x==17&&(A == 5&&(B==5||C==5)||B==5&&C==5))
            {
                X="YES";  
            }
            else { X = "NO"; }
            Console.WriteLine(X);
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
// 6/20 解き直し
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[3010][3010][4];

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    // dp初期化
    rep(i, n + 1) {
        rep(j, s + 1) {
            rep(k, 3) {
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;

    rep(i, n) {
        for (int j = 0; j <= s; j++) {
            // A[i]を使わない場合
            // dp[i + 1][j] += dp[i][j] * 2;
            // if (j >= a[i]) dp[i+1][j] += dp[i][j-a[i]];

            // L, Rが決まっていない時
            dp[i+1][j][0] += dp[i][j][0];

            // Lが決まっている時
            dp[i+1][j][1] += (dp[i][j][0] + dp[i][j][1]);

            // L, Rが決まっている時
            dp[i+1][j][2] += (dp[i][j][1] + dp[i][j][2]);

            // a[i]を使う時
            if (j >= a[i]) {
                dp[i+1][j][1] += (dp[i][j-a[i]][0] + dp[i][j-a[i]][1]);
                dp[i+1][j][2] += (dp[i][j-a[i]][0] + dp[i][j-a[i]][1]);  // L=Rもあるので、0, 1両方から遷移する
            }
        }
    }

    cout << dp[n][s][2] << endl;
}

Measured memory_bytes: 286744
def primes(N):
    '''Sieve of Eratosthenes'''
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    return p


p, c = primes(10 ** 5), [0]
for i in range(1, 10 ** 5 + 1):
    c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1])

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r] - c[l - 1])


Measured memory_bytes: 5732
import java.util.Scanner;

public class Main{
	
	static int k(String e,char c1,char c2) {
		int nest = 0;
		for(int i=e.length()-1;i>=0;i--) {
			if(e.charAt(i) == ')') {
				nest++;
			}
			if(e.charAt(i) == '(') {
				nest--;
			}
			if((e.charAt(i) == c1 ||e.charAt(i) == c2) && nest==0) {
				return i;
			}
		}
		return -1;
	}
	
	static int calc(String e) {
		int pos = k(e,'+','-');
		if(pos!=-1) {
			if(e.charAt(pos)=='+') {
				return calc(e.substring(0,pos)) + calc(e.substring(pos+1));
			}else {
				return calc(e.substring(0,pos)) - calc(e.substring(pos+1));
			}
		}
		pos = k(e,'*','/');
		if(pos!=-1) {
			if(e.charAt(pos)=='*') {
				return calc(e.substring(0,pos)) * calc(e.substring(pos+1));
			}else {
				return calc(e.substring(0,pos)) / calc(e.substring(pos+1));
			}
		}
		if(e.startsWith("(")) {
			return calc(e.substring(1,e.length()-1));
		}
		return Integer.parseInt(e);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			String e = sc.next();
			System.out.println(calc(e.substring(0,e.length()-1)));	
		}
	}
}


Measured memory_bytes: 25892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int p,q,r;
  cin>>p>>q>>r;
  if(p>=q && p>=r)cout<<q+r<<endl;
  else if(q>=p && q>=r)cout<<p+r<<endl;
  else if(r>=p && r>=q)cout<<p+q<<endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();

        List<Integer> order = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            order.add(sc.nextInt());
        }

        List<Integer> satisfaction = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            satisfaction.add(sc.nextInt());
        }

        List<Integer> moreSatisfaction = new ArrayList<>();
        for (int i = 0; i < n-1; i++) {
            moreSatisfaction.add(sc.nextInt());
        }

        int sum = 0;
        int preOrder = 30;
        for (int i = 0; i < n; i++) {
            Integer nowOrder = order.get(i);

            sum += satisfaction.get(nowOrder - 1);

            if (nowOrder - preOrder == 1) {
                sum += moreSatisfaction.get(nowOrder - 2);
            }

            preOrder = nowOrder;
        }

        System.out.println(sum);

    }
}

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

public class Main {

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

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    
    int breaking = 0;
    int target = 1;
    
    for (int i = 0; i < n; i++) {
      if (a[i] == target) {
        target++;
      } else {
        breaking++;
      }
    }
    if (breaking == n) {
      os.println(-1);
    } else {
      os.println(breaking);
    }
  }
}

Measured memory_bytes: 80224
#include <iostream>
#include <cstdio>
#define MAX_N 15
using namespace std;
int main(){
	int n,i,j;
	while(1){
		cin >> n;
		if(n==0)break;
		int a[MAX_N][MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				a[i][j]=0;
			}
		}


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

		int sum1=0,sum[MAX_N];
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

		for(j=0;j<=n;j++){
			for(i=0;i<=n;i++){
				sum1+=a[i][j];
				if(i==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}


		for(i=0;i<=n;i++){
			for(j=0;j<n;j++){
				printf("%5d",a[i][j]);
			}
			printf("%5d\n",a[i][n]);
		}

	}
	return 0;
}

Measured memory_bytes: 3128
#include<stdio.h>

struct Card{
  char suit;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d%c", &n, &ch);
  //scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    //scanf("%c%c ", &C1[i].suit, &C1[i].value);
    scanf("%c%c%c", &C1[i].suit, &C1[i].value, &ch);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  string S;
  std::cin >> S;
  if(N%2==1){
    std::cout << "No" << '\n';
  }else{
    for(int i=0;i<N/2;i++){
      if(S[i]!=S[i+N/2]){
        std::cout << "No" << '\n';
        exit(0);
      }
    }
    std::cout << "Yes" << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body

str = inputs[1][0]

if $debugFlag
  p str
end

hh = {}
str.length.times do |i|
  if hh[ str[i..i] ] == nil
    hh[ str[i..i] ] = 1
  else
    hh[ str[i..i] ] += 1
  end
end

mul = 1
hh.each do |k, v|
  mul *= (v + 1)
end

puts ((mul - 1) % (10**9 + 7))


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5+10 , OO = 0x3f3f3f3f ;
//const int mod = 1000000007;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

int a[N] , b[N] , c[N] , n;
int dp[N][4];

int solve(int idx , int lst){
	
	if(idx == n) return 0;
	int& ret = dp[idx][lst];
	if(~ret) return ret;
	ret = -OO;
	if(lst != 0) // swim
		ret = max(ret , solve(idx+1 , 0) + a[idx]);
	if(lst != 1)
		ret = max(ret , solve(idx+1 , 1) + b[idx]);
	if(lst != 2)
		ret = max(ret , solve(idx+1 , 2) + c[idx]);
		
	return ret;
}


int main()
{
    startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin >> n;
	for(int i = 0 ; i < n ; ++i)
		cin >> a[i] >> b[i] >> c[i];

	clr(dp , -1);
	cout << solve(0 , 3) << "\n";


    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main(){
    int h, w; cin>>h>>w;
    char s[60][60];
    int white_cnt=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>s[i][j];
            if(s[i][j] == '.') white_cnt++;
        }
    }

    queue<T> que;
    que.push(T(0, 0, 1));
    while(!que.empty()){
        int py, px, cnt;
        tie(py, px, cnt)=que.front(); que.pop();

        if(py == h-1 && px == w-1){
            cout << white_cnt - cnt << endl;
            return 0;
        }

        for(int i=0; i<4; i++){
            int ny=py+dy[i], nx=px+dx[i];

            if(ny >= 0 && ny < h && nx >= 0 && nx < w){
                if(s[ny][nx] == '.'){
                    que.push(T(ny, nx, cnt+1));
                    s[ny][nx] = '#';
                }
            }
        }
    }
    cout << -1 << endl;
}

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

inline int sum(int x, int y, int mod) { return (x+(long long)y) % mod; }
inline int sub(int x, int y, int mod) { return ((x-(long long)y) % mod + mod) % mod; }
inline int mul(int x, int y, int mod) { return (x*(long long)y) % mod; }
inline int power(int x, int y, int mod) {
    int ans = 1;
    for (int i=0; i<31; i++, x=mul(x, x, mod)) if ((y>>i)&1) ans = mul(ans, x, mod);
    return ans;
}

int N, K, x, y, m[200004];
string s;

int f(int x) {
	if (!x) return 0;
	if (m[x]) return m[x];
	return m[x] = 1 + f(x % __builtin_popcount(x));
}

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

	cin >> N >> s;

	for (int i=0; i<N; i++) K += (s[i] == '1');

	for (int i=0; i<N; i++) {
		x = (K == 1 ? 0 : sum(x, mul(s[i] - '0', power(2, N-1-i, K-1), K-1), K-1));
		y = sum(y, mul(s[i] - '0', power(2, N-1-i, K+1), K+1), K+1);
	}

	for (int i=0; i<N; i++) {
		if (s[i] == '0') {
			cout << f(sum(y, power(2, N-1-i, K+1), K+1)) + 1 << '\n';
		} else {
			if (K == 1) cout << 0 << '\n';
			else cout << f(sub(x, power(2, N-1-i, K-1), K-1)) + 1 << '\n';
		}
	}
}

Measured memory_bytes: 4096
import sys
input = sys.stdin.readline
from functools import reduce
from itertools import starmap
from operator import xor, mul
N = int(input())
A = list(map(int ,input().strip()))

A = [abs(x-y) for x,y in zip(A,A[1:])]
n = len(A)
# Lucas
coef = [((n-1)&k)==k for k in range(n)]
if 1 in A:
    B = [x % 2 for x in A]
    ans = reduce(xor, starmap(mul, zip(B,coef)))
else:
    B = [x // 2 for x in A]
    ans = reduce(xor, starmap(mul, zip(B,coef)))*2

print(ans)


Measured memory_bytes: 34424
#include<stdio.h>

int main(){
	int N;			//要素数
	int count = 0;	//交換回数
	int s;			//ソート用変数
	int minj;		//未ソート部分の最小値の位置
	
	//要素数の入力
	scanf("%d",&N);
	
	int A[N];	//配列
	
	//配列の入力
	for(int i = 0;i < N;i++){
		scanf("%d",&A[i]);
	}
	
	for(int i = 0;i < N;i++){
		//最小値の位置を初期化
		minj = i;
		
		//minjから最後までの最小値の位置を求める
		for(int j = i;j < N;j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		//交換が行われるとき
		if(minj != i){
			//交換
			s = A[i];
			A[i] = A[minj];
			A[minj] = s;
			//交換をカウント
			count++;
		}
	}
	
	//配列の出力
	for(int i = 0;i < N;i++){
		if(i == N - 1){
			printf("%d\n",A[i]);
		}
		else{
			printf("%d ",A[i]);
		}
	}
	
	//交換回数の出力
	printf("%d\n",count);
	
	return 0;
}



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

using namespace std;


int main(){
    
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if ((i+1)%2 == 1) {
            if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D') {
                ans += 1;
            }
            
        }else if((i+1)%2 == 0){
            if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D') {
                ans += 1;
            }
            
        }
    }
    
    if (ans == S.length()) {
        cout << "Yes" << endl;
    }else{
        
        cout << "No" << endl;
    }
    
    
}


Measured memory_bytes: 256
#python3

def main():
    w, a, b = map(int, input().split())
    x = min(abs(a-b), abs((a+w)-b))
    y = min(abs((b+w)-(a+w)), abs((b+w)-a))
    ans = min(x, y)
    if (a <= b) & (b <= a+w):
        print(0)
    elif (a <= b+w) & (b+w <= a+w):
        print(0)
    else:
        print(ans)
main()


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        List<Integer> leftList = new ArrayList<>();
        List<Integer> rightList = new ArrayList<>();
        for (int i=0; i < M; i++) {
            leftList.add(scanner.nextInt());
            rightList.add(scanner.nextInt());
        }

        int left = Collections.max(leftList);
        int right = Collections.min(rightList);

        int result = Math.min(right, N) - Math.max(left, 1) + 1;
        if (result < 0) {
            result = 0;
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 69008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
static const ll MOD = 1e9+7;
const ll MAX = 200005;
ll MODINV[MAX];

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


ll moddiv(ll a, ll b, ll M){
    ll ans = (a % M) * (MODINV[b] % M);
    return ans%M;
}
 
int main() {
    // 前処理
    ll N, A, B; cin >> N >> A >> B;
    ll ans = 1;
    vector<ll> COM_(MAX), K(MAX);
    for(int i = 1; i < MAX; i++) MODINV[i] = modinv(i, MOD);
    

    COM_[1] = N;
    ll Max = min((ll)N, MAX);


    for(int i = 2; i <= Max; i++){
        ll tmp=COM_[i-1];
        tmp *= (N-i+1);
        tmp%= MOD;
        tmp = moddiv(tmp, i, MOD);
        tmp %= MOD;
        COM_[i] = tmp;
    }

    ans = modpow(2, N, MOD);
    ans-=COM_[A];
    if(ans<0) ans+= MOD;
    ans-=COM_[B];
    if(ans<0) ans+= MOD;

    

    
 
    // 計算例
    cout << ans -1 << endl;
    //for(int i = 1; i <= 10500; i++) cout << COM_[i] << endl;
}

Measured memory_bytes: 4992
import copy
s = input().split()

n = int(s[0])
m = int(s[1])
x = int(s[2])

s_list = [[0 for i in range(m+1)] for j in range(n)]

for i in range(n):
    r = input().split()
    s_list[i][0] = int(r[0])
    for j in range(1,m + 1):
        s_list[i][j] = int(r[j])


gen = [0] * (m + 1)
kakaku = -1

for i in range(2 ** n):
    k = i
    kari = copy.copy(gen)
    for j in reversed(range(n)):
        if k >= 2 ** j:
            k -= 2 ** j
            for l in range(m+1):
                kari[l] += s_list[j][l]

    check = 0
    for j in range(1,m + 1):
        if kari[j] < x:
            check = 1
            break
    if check == 0 and (kari[0] < kakaku or kakaku == -1):
        kakaku = kari[0]

print(kakaku)

Measured memory_bytes: 9324
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    const ll INF = -1e15;
    struct edge{
        ll from;
        ll to;
        ll cost;
    };
    ll n, m;
    cin >> n >> m;
    vector<edge>edges(m);
    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[i] = {a, b, c};
    }
    vector<ll>ans(n, INF);
    ans[0] = 0;
    rep(i,n - 1){
        rep(j, m){
            if(ans[edges[j].from] != INF){ 
                ans[edges[j].to] = max(ans[edges[j].to], ans[edges[j].from] + edges[j].cost);
            }
        }
    }
    bool ok = true;
    rep(j,m){
        ll a = ans[n - 1];
        if(ans[edges[j].from] != INF){
            ans[edges[j].to] = max(ans[edges[j].to], ans[edges[j].from] + edges[j].cost);
        }
        if(a < ans[n - 1]) ok = false;
    }
    if(!ok) cout << "inf" << endl;
    else cout << ans[n - 1] << endl;
    return 0;
}



Measured memory_bytes: 3644
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int H , W;
char s[100];

int main(){
  scanf("%d%d",&H,&W);
  rep(i,1,H+1) rep(j,1,W+1) {
    scanf("%s",s);
    if(string(s) == string("snuke")) {
      printf("%c%d\n",j-1+'A',i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n={},o=0;o<t;o++){for(var u=r[o+1].split(""),i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f=0;f<10;f++){var l=u[f];"a"==l&&(i[0]+=1),"b"==l&&(i[1]+=1),"c"==l&&(i[2]+=1),"d"==l&&(i[3]+=1),"e"==l&&(i[4]+=1),"f"==l&&(i[5]+=1),"g"==l&&(i[6]+=1),"h"==l&&(i[7]+=1),"i"==l&&(i[8]+=1),"j"==l&&(i[9]+=1),"k"==l&&(i[10]+=1),"l"==l&&(i[11]+=1),"n"==l&&(i[12]+=1),"m"==l&&(i[13]+=1),"o"==l&&(i[14]+=1),"p"==l&&(i[15]+=1),"q"==l&&(i[16]+=1),"r"==l&&(i[17]+=1),"s"==l&&(i[18]+=1),"t"==l&&(i[19]+=1),"u"==l&&(i[20]+=1),"v"==l&&(i[21]+=1),"w"==l&&(i[22]+=1),"x"==l&&(i[23]+=1),"y"==l&&(i[24]+=1),"g"==l&&(i[25]+=1)}var a=i.join("-");n[a]||(n[a]=0),n[a]+=1}var c=0;for(var p in n){var d=n[p];d<=1||(c+=d*(d-1)/2)}console.log(c)}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 51848
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    group_count = int(input())

    seated_numbers = [list(map(int, input().split())) for _ in range(group_count)]
    total_person = 0

    for line in seated_numbers:
        total_person += max(line) - min(line) + 1

    print(total_person)


Measured memory_bytes: 3188
#include <iostream>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    k = min(n-1, k);
    long ans = 1;
    for(int i=1; i<=k; i++){
        long add = COM(n, i)*COM(n-1, i);
        add = add % MOD;
        ans += add;
        ans = ans % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,k;
    cin >> n >> k;
    intl r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    string u = "";
    rep(i,k){
        if(t[i] == 'r')u += 'r';
        else if(t[i] == 's')u += 's';
        else u += 'p';
    }
    repi(i, k, n){
        //cout << t[i] << u[i - k] << endl;
        if(t[i] == u[i - k])u += '0';
        else if(t[i] == 'r')u += 'r';
        else if(t[i] == 's')u += 's';
        else u += 'p';
    }
    //debug(u);
    intl cnt = 0;
    rep(i,n){
        if(u[i] == 'r')cnt += p;
        else if(u[i] == 's')cnt += r;
        else if(u[i] == 'p')cnt += s;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
 	int n;
 	cin>>n;
 	for(int i=111;i<=999;i+=111)
 	{
 		if(i>=n)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};



int main(){
    lint n,a,b;
    cin>>n>>a>>b;
    repi(i,a,b+1){
        if(i%n==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}

Measured memory_bytes: 3656
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n;
  scanf("%d", &n);

  int i;

  int c = n; int d = n; int ans; int m = 100000;

  for(i = 0; i <= n; i++){
    ans = 0;
    c =  i; d = n - i;
    while(c >= 1){
      ans += c % 6;
      c /= 6;
    }
    while(d >= 1){
      ans += d % 9;
      d /= 9;
    }
    if(m > ans){
      m = ans;
    }
  }

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


Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+7;

int n;
int dp[N];
vector < int > all;

int go(int x){
    if(x == 0)
        return 0;
    if(dp[x] != -1)
        return dp[x];
    int best = N;
    for(int i = all.size()-1; i >= 0; i--){
        if(all[i] <= x){
            best = min(best , 1 + go(x - all[i]));
            //cout << x << " " << all[i] << endl;
            //system("PAUSE");
        }
    }
    return dp[x] = best;
}

int main () {
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        dp[i] = -1;
    }
    int nin = 9 , six = 6;
    while(1){
        if(six * 6 <= n)
           six *= 6;
        if(nin * 9 <= n)
           nin *= 9;
         all.push_back(six);
         all.push_back(nin);
         if(six * 6 > n && nin * 9 > n)
            break;
    }
    all.push_back(1);
    all.push_back(6);
    all.push_back(9);
    sort(all.begin() , all.end());
    printf("%d\n" , go(n));
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef unsigned long long int ulint;
typedef long long int lint;

ulint N;

vector<ulint> coloring;

vector<vector<ulint>> edge_list;

// vector<vector<ulint>> edge_id;

unordered_map<ulint, ulint> edge_id_tbl;

ulint edge_id(ulint a, ulint b) {
  ulint large, small;
  large = max(a, b);
  small = min(a, b);
  return edge_id_tbl[small * N + large];
}

void dfs(ulint node_id, ulint prev_edge_id) {
  vector<ulint> edges = edge_list[node_id];

  ulint c = 0;
  for (auto it = edges.begin(); it != edges.end(); ++it) {    
    ulint child_node_id = *it;

    ulint child_edge_id = edge_id(node_id, child_node_id);
    
    if (child_edge_id == prev_edge_id) {
      continue;
    }
    
    if (c == coloring[prev_edge_id]) {
      ++c;
    }
    
    coloring[child_edge_id] = c;

    dfs(child_node_id, child_edge_id);
    
    ++c;

  }
}

int main(){
  cin >> N;

  edge_list = vector<vector<ulint>>(N);

  // edge_id = vector<vector<ulint>>(N, vector<ulint>(N));

  coloring = vector<ulint>(N, -1);
  
  for (int i = 0; i < N - 1; ++i) {
    ulint a, b;
    cin >> a >> b;

    --a;
    --b;

    edge_list[a].push_back(b);
    edge_list[b].push_back(a);

    // edge_id[a][b] = i;
    // edge_id[b][a] = i;
    ulint large = max(a, b);
    ulint small = min(a, b);
    edge_id_tbl[small * N + large] = i;
  }

  for (int i = 0; i < N; ++i) {
    sort(edge_list[i].begin(), edge_list[i].end());
  }

  // Depth-first search
    
  dfs(0, N-1); // There is no N-1 -th edge.

  ulint n_colors = *max_element(coloring.begin(), coloring.end() - 1);

  cout << n_colors + 1 << endl;
  for (int i = 0; i < N - 1; ++i) {
    cout << coloring[i] + 1 << endl;
  }
}


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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int state[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    string s;

    cin >> n >> s;

    for(int i = 0; i < 2; ++i){ // sheep? wolf?
        for(int yikes = 0; yikes < 2; ++yikes){
            for(int j = 0; j < n; ++j)
                state[j] = -1;
            state[0] = i;
            if((s[0] == 'o') ^ i){
                state[1] = state[n - 1] = yikes;
            } else {
                state[1] = yikes; state[n - 1] = 1 - yikes;
            }
            bool bad = false;
            for(int pos = 1; pos < n; ++pos){
                if((s[pos] == 'o') ^ (state[pos] == 1)){
                    //cout << "CHECL " << pos << " " << state[(pos + 1) % n] << endl;
                    if(state[(pos + 1) % n] != -1 && state[pos - 1] != state[(pos + 1) % n])
                        bad = true;
                    state[(pos + 1) % n] = state[pos - 1];
                } else {
                    //cout << "HELLO " << endl;
                    if(state[(pos + 1) % n] != -1 && state[pos - 1] == state[(pos + 1) % n])
                        bad = true;
                    state[(pos + 1) % n] = 1 - state[pos - 1];
                }
                //cout << "BOI " << pos << " " << state[pos] << endl;
            }
            if(bad) continue;
            for(int pos = 0; pos < n; ++pos)
                cout << (state[pos] == 0 ? "S" : "W");
            cout << "\n";
            return 0;
        }
    }

    cout << "-1\n";

    return 0;

}


Measured memory_bytes: 976
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double mx = 0;
  int swater = 100*a, sugar = 0;
  for (int i = 0; i*a*100 <= f; i++) {
    for (int j = 0; i*a*100+j*b*100 <= f; j++) {
      int w = i*a*100+j*b*100;
      for (int k = 0; k*c <= (i*a+j*b)*e && k*c+w <= f; k++) {
        int l = min(((i*a+j*b)*e-k*c)/d, (f-w-k*c)/d);
        int s = k*c+l*d;
        if (chmax(mx, 100.0*s/(s+w))) {
          swater = w+s;
          sugar = s;
        }
      }
    }
  }
  cout << swater << ' ' << sugar << endl;
  return 0;
}

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

main(){
  int p, q;
  while(cin >> p >> q){
    map<int, int> pos;
    p = p%q * 10;
    pos[p] = 0;
    for(int i=1;;i++){
      cout << p/q;
      int tmp = p%q;
      if(tmp == 0){
	cout << endl;
	break;
      }
      p = tmp*10;
      if(pos.find(p) != pos.end()){
	cout << endl;
	for(int j=1;j<=i;j++){
	  if(pos[p]<j) cout << '^';
	  else cout << ' ';
	}
	cout << endl;
	break;
      }
      pos[p] = i;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  for(ll i=1;i<=n;++i) if(i%3!=0&&i%5!=0) ans+=i;
  print(ans);
  return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <algorithm>
using namespace std;

long long a[100005];
long long b[100005];

int main()
{

    int n;

    scanf("%d",&n);

    for (int i = 0;i < n;i++)
        scanf("%lld",&a[i]);

    sort(a,a+n);

    int cnt = 0;

    for (int i = n - 1;i >= 1;)
    {
        if (a[i] == a[i-1])
        {
            b[cnt++] = a[i];
            i -= 2;
        }
        else i--;
    }

    if (cnt >= 2)
    {
        printf("%lld\n",b[0] * b[1]);
    }
    else
        printf("0");

    return 0;
}


Measured memory_bytes: 1280
N, L = map(int, input().split())

sum = 0
sum2 = 0
min = 10000000000
ans = 0
for i in range(1,N+1):
    sum = sum + L + i - 1

# print(sum)

for i in range(1,N+1):
    for j in range(1,N+1):
        if j == i:
            continue
        else:
            sum2 = sum2 + L + j - 1
    # print(sum2)
    if abs(sum - sum2) < min:
        min = abs(sum-sum2)
        ans = sum2
    sum2 = 0

print(ans)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define sq(x) ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// typedef pair<i64, i64> pii;

int main()
{
    i64 n , m , i , j ;

    cin>>n>>m ;

    if(n>m) swap(n,m) ;

    if(n==1)
    {
        if(m==1) printf("1\n") ;
        else printf("%lld\n",m-2) ;
    }

    else printf("%lld\n",n*m- (2*(n+m)-4) ) ;

    return 0 ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
int a[50];
int b[50];
int c[50];
int d[50];

int estimate(vector<int> numList,int q){
	int ans = 0;
	//cout<<numList.size()<<endl;
	for(int i = 0; i < q; i++){
		if( numList[b[i]-1] - numList[a[i]-1] == c[i]){
			ans += d[i];
		}
	}
	return ans;
}

int dfs(vector<int> numList,int n,int m,int q){
	if( numList.size() == n){
		return estimate(numList,q);
	}
	int last = numList.back();
	int ans = 0;
	for(int i = last; i <= m; i++){
		numList.push_back(i);
		ans = max(ans,dfs(numList,n,m,q));
		numList.pop_back();
	}
	return ans;
}

int main()
{
	int n,m,q;
	cin>>n>>m>>q;
	rep(i,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	vector<int> numList;
	int ans = 0;
	for(int i = 1; i <= m; i++){
		//cout<<numList.size()<<endl;
		numList.push_back(i);
		ans = max(ans,dfs(numList,n,m,q));
		numList.pop_back();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3164