akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long H, long long W, vector<string> s) {
  vector< vector<long long> > d(H+W, vector<long long>(H+W, 0));
  vector< vector<long long> > cx(H+W+1, vector<long long>(H+W, 0));
  vector< vector<long long> > cy(H+W, vector<long long>(H+W+1, 0));
  long long ans = 0;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '#') {
        d[i+j][i-j+W] = 1;
      }
    }
  }

  for (int x = 0; x < H+W; x++) {
    for (int y = 0; y < H+W; y++) {
      cy[x][y+1] = cy[x][y] + d[x][y];
      cx[x+1][y] = cx[x][y] + d[x][y];
    }
  }

  for (int y = 0; y < H+W; y++) {
    for (int x = 0; x < H+W-1; x++) {
      if (d[x][y] != 1) continue;
      for (int xd = 1; x + xd < H+W; xd++) {
        if (d[x+xd][y] == 1) {
          if (y+xd < H+W) {
            ans += cx[x+xd][y+xd] - cx[x][y+xd];
          }
          if (y-xd >= 0) {
            ans += cx[x+xd+1][y-xd] - cx[x+1][y-xd];
          }
        }
      }
    }
  }

  for (int x = 0; x < H+W; x++) {
    for (int y = 0; y < H+W-1; y++) {
      if (d[x][y] != 1) continue;
      for (int yd = 1; y + yd < H+W; yd++) {
        if (d[x][y+yd] == 1) {
          if (x+yd < H+W) {
            ans += cy[x+yd][y+yd+1] - cy[x+yd][y+1];
          }
          if (x-yd >= 0) {
            ans += cy[x-yd][y+yd] - cy[x-yd][y];
          }
        }
      }
    }
  }

  std::cout << ans << std::endl;
}

int main(){
  long long H, W;
  std::cin >> H >> W;
  vector<string> s(H);
  for (int i = 0; i < H; i++) {
    std::cin >> s[i];
  }

  solve(H, W, s);

  return 0;
}


Measured memory_bytes: 9088
import java.util.*;
import java.awt.geom.Line2D;

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

	int n = sc.nextInt();

	while(n!=0){
	    int[][] c = new int[n][4];
	    for(int i=0; i<n; i++){
		for(int j=0; j<4; j++){
		    c[i][j] = sc.nextInt();
		}
	    }

	    int ans = 2;
	    List<Double> xlist = new ArrayList<Double>();
	    List<Double> ylist = new ArrayList<Double>();
	    for(int i=1; i<n; i++){
		xlist = new ArrayList<Double>();
		ylist = new ArrayList<Double>();
		boolean boo = true;
		Line2D a = new Line2D.Double(c[i][0],c[i][1],c[i][2],c[i][3]);
		for(int j=0; j<i; j++){
		    Line2D b = new Line2D.Double(c[j][0],c[j][1],c[j][2],c[j][3]);

		    if(a.intersectsLine(b)
		       && !((c[i][0]==c[j][0]&&c[i][1]==c[j][1]) || (c[i][2]==c[j][2]&&c[i][3]==c[j][3]) || (c[i][0]==c[j][2]&&c[i][1]==c[j][3]) || (c[i][2]==c[j][0]&&c[i][3]==c[j][1]))){
			double bx = c[j][2]-c[j][0];
			double by = c[j][3]-c[j][1];
			double d1 = Math.abs(bx*(c[i][1]-c[j][1])-by*(c[i][0]-c[j][0]));
			double d2 = Math.abs(bx*(c[i][3]-c[j][1])-by*(c[i][2]-c[j][0]));
			double t = d1/(d1+d2);

			double x = c[i][0]+(c[i][2]-c[i][0])*t;
			double y = c[i][1]+(c[i][3]-c[i][1])*t;
			if(xlist.contains(x) && ylist.contains(y)){continue;}
			else{xlist.add(x); ylist.add(y);}
			if(boo){ans+=2; boo = false;}
			else ans++;
		    }
		}
		if(boo){ans++;}
	    }

	    System.out.println(ans);
	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 13000
import java.util.Scanner;

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

        if (a1+a2+a3 >= 22){
            System.out.println("bust");
        }
        else {
            System.out.println("win");
        }
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
long long tab[1000005];
long long licz[1000005];
const int mod=1e9+7;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int a,b;
    cin>>a;
    b=a;
    for(int x=1;x<=b;x++)
    {
        cin>>tab[x];
        if(tab[x]==tab[x-1])
        {
            x--;
            b--;
        }
    }
    a=b;
    licz[tab[1]]=1;
    long long pom=0;
    for(int x=2;x<=a;x++)
    {
        pom=licz[tab[x-1]];
        licz[tab[x]]+=pom;
        licz[tab[x]]%=mod;
    }
    cout<<licz[tab[a]];
	return 0;
}

Measured memory_bytes: 5888
tmp = input().split()
n = int(tmp[0])
m = int(tmp[1])

a = [0] * m
b = [0] * m

for i in range(m):
    tmp = input().split()
    tmp = list(map(int,tmp))
    a[i] = tmp[0]
    b[i] = tmp[1]

arr = [[0] * (n+1) for i in range(n+1)]

for i in range(m):
    arr[a[i]][b[i]] += 1
    arr[b[i]][a[i]] += 1

for i in range(1,n+1):
    count = 0
    for k in range(len(arr[i])):
        if arr[i][k] != 0:
            count += arr[i][k]
    print(count)


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
  public static void main (String[] arg) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int a[] = new int[N];
    int b[] = new int[N];
    int M = 0;
    
    for (int i = 0; i < N; i++){
      a[i] = scan.nextInt();
    }
    
    for(int i = N; i > 0; i--){
      int Bc = 0;
      for(int j = N/i; j > 1; j--){
        Bc += b[(i*j)-1];
      }
      b[i-1] = (a[i-1]+Bc)%2;
      M += b[i-1];
    }
    
    System.out.println(M);
    for(int i = 0; i < N; i++){
      if(b[i] == 1){
        System.out.print((i+1) + " ");
      }
    }
  }
}

Measured memory_bytes: 88288
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  scanf("%d",&a)
#define in2(a,b)  in(a),in(b)
#define in3(a,b,c)  in2(a,b),in(c)
#define in4(a,b,c,d)  in2(a,b),in2(c,d)
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
il long long read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 30010
#define inf 0x7fffffff
#define ll long long
#define ull unsigned ll
/*------------------------------------------------------------*/
int n,m;
int main(){
	int a[10];
	in3(a[1],a[2],a[3]);
	sort(a+1,a+4);
	int c=a[3]-a[2];
	int ans=c;
	a[1]+=c;a[2]+=c;
	if((a[2]-a[1])%2)ans+=(a[2]-a[1])/2+2;
	 else ans+=(a[2]-a[1])/2;
	out(ans);
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#define Pi 3.1415926535898
//#define mp{(x),(y)} make_pair{(x),(y)}
#define _1 first
#define _2 second
#define LL long long
#define maxn 200000+10
const int INF = 1e9+7;
using namespace std;

int k,flag=1,x1,x2,y1,x,y,y2,n,cnt;
int st[maxn];
double ans;
pair <int ,int > a[maxn];

int cmp(pair<int ,int > A,pair<int ,int > B)
{
	return A._1<B._1;
}

int main()
{
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	if (x1>x2) swap(x1,x2),swap(y1,y2);
	if (y1>y2) flag=-1;
	y1*=flag;y2*=flag;
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	  {
	  	scanf("%d%d",&x,&y);y*=flag;
	  	if (x<x1||x>x2||y<y1||y>y2) continue;
	  	a[++cnt]={x,y};
	  }
	sort(a+1,a+1+cnt,cmp)	;
	st[0]=-INF;for (int i=1;i<=n+2;++i) st[i]=INF;
	for (int i=1;i<=cnt;++i)
	{
		int y=a[i]._2;
		int pos=upper_bound(st,st+n+2,y)-st;
		st[pos]=y;
	}
	k=lower_bound(st,st+n+2,INF)-st-1;
	//cnt-1;
	//cout.precision(25);
	int len=min(x2-x1,y2-y1);
	ans=(LL)(x2-x1+y2-y1)*(LL)100;
	ans-=20*k;
	ans+=5*k*Pi;
	if (len+1==k) ans+=5*Pi;;
	printf("%.15f\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i,H){
        cin >> a[i];
    }
    rep(i,W+2)cout << "#";
    cout << endl;
    rep(i,H){
        cout << "#";
        cout << a[i];
        cout << "#" << endl;
    } 
    rep(i,W+2)cout << "#";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((n/3)**3)


Measured memory_bytes: 38256
import java.util.*;

public class Main {
    static int[] par, rank;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] p = new int[n];
        for(int i=0; i<n; i++){
            p[i] = sc.nextInt() - 1;
        }
        int[][] x = new int[m][2];
        for(int i=0; i<m; i++){
            x[i][0] = sc.nextInt() - 1;
            x[i][1] = sc.nextInt() - 1;
        }
        par = new int[n];
        rank = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }

        for(int i=0; i<m; i++){
            unite(x[i][0], x[i][1]);
        }
        int ans = 0;
        for(int i=0; i<n; i++){
            if(same(i, p[i])) ans++;
        }
        System.out.println(ans);
    }

    public static int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    public static void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

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

    public static boolean same(int x, int y){
        return find(x) == find(y);
    }
}

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

int main(){
  int n,m;
  cin >> n;
  map<string,int> flg;
  for(int i=0;i<n;i++){
    string str;
    cin >> str;
    flg[str] = 1;
  }
  cin >> m;
  int now = 1;
  for(int i=0;i<m;i++){
    string str;
    cin >> str;
    if(flg[str] == 1){
      if(now) {
	cout << "Opened by " << str << endl;
	now = 0;
      }
      else {
	cout << "Closed by " << str << endl;
	now = 1;
      }
    }
    else {
      cout << "Unknown " << str << endl;
    }
  }
}

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

int main(){

    int n,k;
    int d,a;

    int ans_n[128]={};
    int ans = 0;
    
    cin >>n >>k;
    for(int i=1;i<=k;i++){
        cin >>d;
        for(int j=1;j<=d;j++){
            cin >>a;
            ans_n[a]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(ans_n[i] == 0){
            ans++;
        }
    }
    
    cout <<ans <<endl;

    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;

    int r = 0;
    int l = 0;
    int size = s.size();
    for (int i = 0; i < size; ++i) {
        if (s[i] == 'R') r++;
        if (s[i] == 'L') l++;
        if (s[i] == 'L' && (i + 1 == size || s[i + 1] == 'R')) {
            int r_num = (r - 1) / 2 + l / 2 + 1;
            int l_num = r / 2 + (l - 1) / 2 + 1;
            for (int j = 0; j < r - 1; ++j) {
                cout << 0 << " ";
            }
            cout << r_num << " " << l_num << " ";
            for (int k = 0; k < l - 1; ++k) {
                cout << 0 << " ";
            }
            r = l = 0;
        }
    }

    return 0;
}


Measured memory_bytes: 640
def main():
    N, M = map(int,input().split())
    k = [None] * M
    s = [None] * M
    for i in range(M):
        k[i], *s[i] = map(int, input().split())
    p = list(map(int, input().split()))
    # print(s)

    # スイッチONOFFパターンをbit全探索
    ans = 0
    for i in range(0, 2**N):

        # ONOFFリスト取得
        switchs = [False for _ in range(N)]
        for j in range(N):
            if (i>>j) & 1:
                switchs[j] = True
        # print(bin(i))
        # print(switchs)

        # 各電球が点灯しているか判定
        ok = True
        for si,pi in zip(s,p):
            # print(si)
            # print(pi)
            # ONの個数
            on_count = [switchs[sij-1] for sij in si].count(True)
            # print(on_count)
            # 消灯していた場合
            if on_count % 2 != pi:
                ok = False
                break
        if ok:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

int main(int argc, char const *argv[]) {
  int n, a, b;
  int out;
  cin >> n >> a >> b;
  int d = n * a;

  if (d < b) {
    out = d;
  } else {
    out = b;
  }

  cout << out << endl;
  return 0;
}

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

void solve(){
long long a,b,c,k;
cin>>a>>b>>c>>k;
long long ans=1e5;
ans=min(a,k);
k=k-a;
if(k<=b){
	cout<<ans;
	return ;
}
else{
	k=k-b;
}
long long x=min(k,c);
ans=ans-x;
cout<<ans;

}


int  main() {

solve();



}



Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

def main():
    n,q = map(int, input().split())
    way = [[] for _ in range(n)]
    for i in range(n-1):
        a,b = map(int, input().split())
        way[a-1].append(b-1)
        way[b-1].append(a-1)
    add = [0]*n
    for i in range(q):
        a,b = map(int, input().split())
        add[a-1] += b
    ans = [-1]*n
    ans[0] = add[0]
    
    stack = [(0,add[0])]
    while stack:
        a,b = stack.pop()
        for i in range(len(way[a])):
            if (ans[way[a][i]]==-1):
                stack.append((way[a][i],b+add[way[a][i]]))
                ans[way[a][i]] = b+add[way[a][i]]
    print(*ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 99328
#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()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}
	if (n == 1) {
		for (auto& c : mp) {
			if (c.first == 0) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
		return 0;
	}
	if (n % 2 == 0) {
		for (auto& c : mp) {
			if (c.second != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
		ll ans = modPow(2, n / 2, mod);
		cout << ans << endl;
	}
	else {
		for (auto& c : mp) {
			if (c.second != 2) {
				if (!(c.second == 1 && c.first == 0)) {
					cout << 0 << endl;
					return 0;
				}
			}
		}
		ll ans = modPow(2, (n - 1) / 2, mod);
		cout << ans << endl;
	}
	return 0;
}


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

int main() {
  int n,c=0;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin>>v.at(i);
  for(int i=1;i<n-1;i++){
    if((v.at(i-1)>v.at(i)&&v.at(i)>v.at(i+1))||(v.at(i-1)<v.at(i)&&v.at(i)<v.at(i+1)))
      c++;
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n-1;i++) cin>>b[i];
    b[n-1]=1000000;
    long long s=b[0]+b[n-2];
    for(int i=1;i<n-1;i++){
        s+=min(b[i-1],b[i]);
    }
    cout<<s;
}


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

#define INF 1e09
#define min(a,b) (a<b?a:b)

using namespace std;

int main(){
	int n,k,res=INF;
	vector<int> h;
	cin >> n >> k;
	h.resize(n);
	for(int i=0;i<n;++i){
		cin >> h[i];
	}
	sort(h.begin(),h.end());
	for(int i=k-1;i<n;++i){
		res = min(res,abs(h[i]-h[i-k+1]));
	}
	cout << res << endl;
}

Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//239///F.Sugoroku
	double n;
	cin>>n;
	double m=ceil(n/1.08);
	if(floor(m*1.08)==n)cout<<round(m);
	else cout<<":(";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3772
using System;
using System.Linq;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            long[] As = ToLongArray(input);
            long MAX = (long)Math.Pow(10,18);
            if(As.Contains(0))
            {
                Console.WriteLine(0);
                return;
            }
            long total = 1;
            for(long i = 0; i < n ; i++)
            {
                if(MAX / As[i] < total)
                {
                    Console.WriteLine("-1");
                    return;
                }else{
                    total *= As[i];
                }
            }
            
            Console.WriteLine(total);
        }
    }
    //2回位使ったら追加する
    class MyLibrary
    {
        public static long[] ToLongArray(string[] stringArray)
        {
            long length = stringArray.Length;
            long[] longArray = new long[length];
            for (long i = 0; i < length; i++)
            {
                longArray[i] = long.Parse(stringArray[i]);
            }
            return longArray;
        }
    }
}


Measured memory_bytes: 41724
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll h,w;
    cin>>h>>w;
    ll ansA=INF,ansB=INF;
    for(int i=h-1;i>0;i--){
            ll s1=w*i;
            ll s2=(h-i)*((w+1)/2);
            ll s3=(h-i)*(w/2);
            ll sa=w*((h-i+1)/2);
            ll sb=w*((h-i)/2);

            ll ans1=max(s1,s2)-min(s3,s1);
            ll ans2=max(s1,sa)-min(sb,s1);
            ll ans3=min(ans1,ans2);
            ansA=min(ansA,ans3);

    }
   for(int i=w-1;i>0;i--){
            ll s1=h*i;
            ll s2=(w-i)*((h+1)/2);
            ll s3=(w-i)*(h/2);
            ll sa=h*((w-i+1)/2);
            ll sb=h*((w-i)/2);

            ll ans1=max(s1,s2)-min(s3,s1);
            ll ans2=max(s1,sa)-min(sb,s1);
            ll ans3=min(ans1,ans2);
            ansB=min(ansB,ans3);
    }
    cout<<min(ansA,ansB)<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

var h, w int
var maze [][]byte

var visited [][]bool

type dice struct {
	top, bottom, right, left, up, down int
}

func move(d *dice, dir byte) {
	now := d.top
	switch dir {
	case 'N':
		d.top = d.down
		d.down = d.bottom
		d.bottom = d.up
		d.up = now
	case 'S':
		d.top = d.up
		d.up = d.bottom
		d.bottom = d.down
		d.down = now
	case 'W':
		d.top = d.right
		d.right = d.bottom
		d.bottom = d.left
		d.left = now
	case 'E':
		d.top = d.left
		d.left = d.bottom
		d.bottom = d.right
		d.right = now
	}
}

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

func dfs(x, y int, d *dice) bool {
	// fmt.Printf("dfs(%d,%d) en: dice.bottom=%d\n", x, y, d.bottom)
	visited[y][x] = true // (x,y)に到達した
	if (y == h-1) && (x == w-1) {
		return true
	}
	// 4方のマス目に進めるかどうかチェック
	for i := 0; i < 4; i++ {
		nx := x + dx[i]
		ny := y + dy[i]
		dir := []byte{'E', 'W', 'S', 'N'}
		dc := *d
		move(&dc, dir[i]) // 動かしてみる
		if 0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' && !visited[ny][nx] && dc.bottom == int(maze[ny][nx]-'0') {
			// fmt.Printf("move dir %c, new bottom=%d, move to (nx, ny)=(%d,%d)\n", dir[i], dc.bottom, nx, ny)
			if dfs(nx, ny, &dc) {
				return true
			}
		} else {
			continue
		}
	}
	return false
}

func main() {
	fmt.Scan(&h, &w)
	maze = make([][]byte, h)
	visited = make([][]bool, h)
	for i := 0; i < h; i++ {
		visited[i] = make([]bool, w)
		maze[i] = make([]byte, w)
		fmt.Scan(&maze[i])
	}
	// fmt.Println("h", h, "w", w, "maze", maze)
	// visited[0][0] = true
	var d dice
	d.bottom = 6
	d.top = 1
	d.right = 3
	d.left = 4
	d.down = 2
	d.up = 5
	if dfs(0, 0, &d) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b;
	cin>>a>>b;
	if(a==b)cout<<b+b<<endl;
	if(a>b)cout<<a+a-1<<endl;
	if(b>a)cout<<b+b-1<<endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int l[10];
  while(~scanf("%d,",&l[0])){
    int v1, v2;
    int sum = l[0];
    REP(i,9){
      scanf("%d,",&l[i+1]);
      sum += l[i+1];
      l[i+1] += l[i];
    }
    scanf("%d,%d",&v1,&v2);
    double t = (double) sum / (v1 + v2);
    double pos = t * v1;
    REP(i,10){
      if(((double)l[i]) >= pos){
	printf("%d\n",i+1);
	break;
      }
    }
  }
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0) {
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }
    return 0;
}

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

int leftChild(int index){
  return 2*index;
}

int rightChild(int index){
  return 2*index+1;
}

int leftBound(int index, const int N){
  while ( index < N )
    index *= 2;
  return index-N;
}

int rightBound(int index, const int N){
  while ( index < N )
    index = 2*index+1;
  return index-N;
}

void update(int *list, const int N, const int i, const int x){
  int current = N+i, even;
  list[current] = x;
  while ( current != 1 ){
    current /= 2;
    list[current] = list[leftChild(current)] < list[rightChild(current)] ? list[leftChild(current)] : list[rightChild(current)];
  }
  return;
}

int findMin(int *list, const int N, const int index, const int x, const int y){
  int left = leftBound(index,N);
  int right = rightBound(index,N);
  if ( x == left && y == right )
    return list[index];
  // check if range is in left subtree
  else if ( rightBound(leftChild(index),N) >= y )
    return findMin(list,N,2*index,x,y);
  // check if range is in right subtree
  else if ( leftBound(rightChild(index),N) <= x )
    return findMin(list,N,2*index+1,x,y);
  else {
    int leftMin = findMin(list,N,leftChild(index),x,rightBound(leftChild(index),N));
    int rightMin = findMin(list,N,rightChild(index),leftBound(rightChild(index),N),y);
    if ( leftMin < rightMin )
      return leftMin;
    else
      return rightMin;
  }
}

void print(int *list, int N){
  int i;
  for ( i = 0; i < 2*N; i++ )
    printf("%d%c", list[i], i==(2*N-1) ? '\n' : ' ');
  return;
}
  
int main(){
  int n, q, i = 1, N, com, x, y;
  scanf(" %d %d", &n, &q);
  while ( i <= n )
    i *= 2;
  N = i;
  int *list = (int *) malloc(sizeof(int[2*N]));
  for ( i = 0; i < 2*N; i++ )
    list[i] = (1 << 30) - 1 + (1 << 30);
  for ( i = 0; i < q; i++ ){
    scanf(" %d %d %d", &com, &x, &y);
    switch( com ){
    case 0:
      update(list, N, x, y);
      break;
    case 1:
      printf("%d\n", findMin(list, N, 1, x, y));
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 2812
#include <iostream>

using std::cin;

struct Ink {
    int x;
    int y;
    int size;
};

constexpr int PAPER_SIZE = 10;
int paper[PAPER_SIZE][PAPER_SIZE] = {{0}};

void size1(const Ink& drop);
void size2(const Ink& drop);
void size3(const Ink& drop);

int main()
{
    Ink dropped;
    char ch;
    while (cin >> dropped.x >> ch >> dropped.y >> ch >> dropped.size) {

        if (dropped.size == 1) {
            size1(dropped);
        } else if (dropped.size == 2) {
            size2(dropped);
        } else if (dropped.size == 3) {
            size3(dropped);
        } else {
            std::cout << "ERROR!" << std::endl;
        }
    }

    int white = 0, dropped_max = 0;
    for (auto i = 0; i < PAPER_SIZE; i++) {
        for (auto j = 0; j < PAPER_SIZE; j++) {
            if (paper[i][j] == 0) {
                white++;
            } else if (paper[i][j] > dropped_max) {
                dropped_max = paper[i][j];
            }
        }
    }

    std::cout << white << std::endl << dropped_max << std::endl;

    return 0;
}

void dropInk(const int x, const int y);

void size1(const Ink& dropped)
{
    int x = dropped.x;
    int y = dropped.y;

    dropInk(x, y);
    dropInk(x + 1, y);
    dropInk(x - 1, y);
    dropInk(x, y + 1);
    dropInk(x, y - 1);
}

void size2(const Ink& dropped)
{
    int x = dropped.x;
    int y = dropped.y;

    size1(dropped);
    dropInk(x + 1, y + 1);
    dropInk(x + 1, y - 1);
    dropInk(x - 1, y + 1);
    dropInk(x - 1, y - 1);
}

void size3(const Ink& dropped)
{
    int x = dropped.x;
    int y = dropped.y;

    size2(dropped);
    dropInk(x, y + 2);
    dropInk(x, y - 2);
    dropInk(x + 2, y);
    dropInk(x - 2, y);
}

void dropInk(int x, int y)
{
    if (x >= 0 && x < 10 && y >= 0 && y < 10) {
        paper[x][y]++;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const ll inf = 1LL<<60;


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

    int H,W,K; cin >> H >> W >> K;

    // dp[i][j] := i行j列から下に向かう経路にたどり着くようなあみだくじの数
    vector<vector<ll>> dp(110, vector<ll>(10, 0));
    dp[0][0] = 1;

    for(int i=1; i<=H; ++i){
        for(int j=0; j<W; ++j){
            // 1の行のあみだを列挙してもらうdp
            for(int bit=0; bit<1<<(W-1); ++bit){
                bool ok = true;
                for(int k=0; k<(W-1); ++k) if(bit&1<<k && bit&1<<(k+1)) ok = false;
                if(!ok) continue;

                if(j!=0 && bit&1<<(j-1)) dp[i][j] += dp[i-1][j-1];
                else if(j!=W-1 && bit&1<<j) dp[i][j] += dp[i-1][j+1];
                else dp[i][j] += dp[i-1][j];
                
                chmod(dp[i][j]);
            }
        }
    }


    cout << dp[H][K-1] << endl;
    
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCorder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long a = int.Parse(input[0]);
            long b = int.Parse(input[1]);
            long c = int.Parse(input[2]);

            Console.WriteLine(Method(a, b ,c));
        }

        static string Method(long a, long b , long c)
        {
            long left = 4 * a * b;
            long right = c - a - b;

            if (right < 0) return "No";

            right = right * right;

            if (left < right) return "Yes";

            return "No";
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)

#define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin();  v != (c).rend(); ++v)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

typedef long long int slong;
typedef pair<int, int> pii;
typedef pair<slong, slong> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

#ifdef VSP4 
    #include "debug.h"    
#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

const int MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;

const int MAXN = 50;
const int SQRTN = 550;
const int LOGN = 60;
const int INT_INFINITY = 1001001001;
const int LIMIT = 40000;

const slong LONG_INFINITY = 1001001001001001001ll;
const slong LONG_LIMIT = 200100100100101ll;

slong k;
const slong MAXLIM = 5ll*1000*1000*1000*1000*100000;
const slong MAXVAL = 1ll*1000*1000*1000*1000*10000 + 1000;

int n;
slong arr[MAXN+5];

int main()
{
	#ifdef VSP4
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	cout.tie(0);
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int t, i, j, u, v;
	
	cint(n);
	
	for (i = 1; i <= n; i++)
	{
		clong(arr[i]);
	}
	
	slong count = 0;
	
	while (true)
	{
		bool found = false;
		
		slong maxi = *max_element(arr+1, arr+1+n);
		
		if (maxi < n)
		{
			break;
		}
		
		for (i = 1; i <= n; i++)
		{
			if (arr[i] == maxi)
			{
				slong moves = (arr[i] - (n-1) + n - 1)/n;
				found = true;
				
				arr[i] -= moves*n;
				
				count += moves;
				
				for (j = 1; j <= n; j++)
				{
					if (i != j)
					{
						arr[j] += moves;
					}
				}
				
				break;
			}
		}
		
		if (!found)
		{
			break;
		}
	}
	
	cout << count;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	    Scanner std = new Scanner(System.in);
	    int a = Integer.parseInt(std.next());
	    int b = Integer.parseInt(std.next());
	    if (a<b){
	    	 System.out.println("a < b");
	    }else{
	    	if(a>b){
	    		System.out.println("a > b");
	    	}else{
	    		System.out.println("a == b");
	    	}
	    }
	}
}

Measured memory_bytes: 26028
from math import sqrt
n = int(input())
p = 0

for i in range(n):
    x = int(input())
    ad = 1
    j = 2
    while j < (int(sqrt(x))+1):
        if x%j == 0:
            ad = 0
            break
        else:
            j += 1
    p += ad



print(p)


Measured memory_bytes: 5672
fn main() {
    let ans = solve(input());
    println!("{} {}", ans.0, ans.1);
}

fn input() -> i64 {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let x: i64 = buf.parse().unwrap();
    x
}

fn solve(x: i64) -> (i64, i64) {
    for a in -118..120 {
        for b in -119..119 {
            if (a as i64).pow(5) - (b as i64).pow(5) == x {
                return (a, b);
            }
        }
    }
    (-1, -1)
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n,m , M, K;

vector<ll> v;
int main(){
    ll a,b,tmp;
    cin >> a >> b;
    ll x = a * b;

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 cout << x/b;
}


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

int main(){
    int ans=0;
    string a;
    cin>>a;
    for(int i=1;i<a.length();++i){
        if(a[i]!=a[i-1]){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

int main() {//変数名まちがえたてへぺろ
	int n;
	string N;
	cin >>n>> N;
	int ans=0;
	for (int i = 2; i < N.length();i++) {
		if (N[i - 2] == 'A'&&N[i - 1] == 'B'&&N[i] == 'C')
		{
			ans++;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
s=input()
length=len(s)

K=int(input())
#print(s,K)

left=0
right=0
#ss=s[left:right]
#print(ss)

ss=deque()
for left in range(length+1):
    for right in range(left+1,length+1):
      if len(s[left:right]) <= K:
        ss.append(s[left:right])

myset=set(ss)
for i in range(K):
    tmp=min(myset)
    myset.remove(tmp)
print(tmp)


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int a;
  vector<int> b(100001, 0);
  for(int i = 0; i < n; i++){
    cin >> a;
    b.at(a)++;
  }
  
  int ans = 0, even = 0;
  for(int i = 0; i < 100001; i++){
    if(b.at(i) == 0) continue;
    else if(b.at(i) == 1) ans++;
    else if(b.at(i) % 2 == 1) ans++;
    else even++;
  }
  
  if(even % 2 == 0) ans += even;
  else ans += even - 1;
  
  cout << ans << '\n';
}

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

using namespace std;

int main()
{
  long double n,ans = 1;
  vector<long double> a;
  cin >> n;
  a.resize(n);
  for(long double i = 0; i < n;i++)
  {
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());
  for(long double i = 0; i < n;i++)
  {
    ans *= a[i];
    if(ans > 1.0e+18)
    {
      cout << -1;
      return 0;
    }
  }
  cout << (unsigned long long)ans;

  return 0;  
}

Measured memory_bytes: 4900
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int maxN = 5000;
int n,k;
vector<bool>vis(maxN+5);
vector<int>a(maxN+5);
vector<int>b(maxN+5);
vector<int>path;
void dfs(int i,int val)
{
    vis[i] = 1;
    val+=b[i];
    path.push_back(val);
    if (!vis[a[i]])dfs(a[i],val);
}
int32_t main()
{
    fastio;
    cin>>n>>k;
    for (int i = 0;i<n;i++){cin>>a[i];a[i]--;}
    for (int i = 0;i<n;i++)cin>>b[i];
    int fin = -1e20;
    for (int i = 0;i<n;i++){
        for (int i = 0;i<n;i++)vis[i] = 0;
        path.clear();
        dfs(i,0);
        int ans = -1e20;
        if (path.back()>0 && k>=(path.size())){
            int num = k/(path.size());
            int left = k%(path.size());
            int maxpos = -1e20;
            for (int j = 0;j<left;j++)maxpos = max(maxpos,path[j]);
            ans = num*(path.back()) + maxpos;
            maxpos = -1e20;
            for (int j = 0;j<path.size();j++)maxpos = max(maxpos,path[j]);
            ans = max(ans,(num-1)*(path.back())+maxpos);
        }
        else{
            for (int j = 0;j<min(k,(int)path.size());j++)ans = max(ans,path[j]);
        }
        fin = max(fin,ans);
    }
    cout<<fin;
    return 0;
}

Measured memory_bytes: 4004
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pii; //first: id, second: to
using node = pii; //first: id, second: before_color

int main() {
    int n; cin >> n;
    vector<vector<edge>> G(n, vector<edge>());
    vector<bool> seen(n, false); vector<int> colors(n-1, -1);
    rep(i, n-1){
        int a,b; cin >> a >> b; a--, b--;
        G[a].push_back(edge(i, b));
        G[b].push_back(edge(i, a));
    }
    int mx = 0, start;
    rep(i, n){
        if(mx < G[i].size()){
            mx = G[i].size();
            start = i;
        }
    }
    seen[start] = true;  
    queue<node> que;
    que.push(node(start, -1));

    while(!que.empty()){
        node nd = que.front(); que.pop();
        int num = nd.first, bc = nd.second;
        int nc = 1;
        for(edge e: G[num]){
            int id = e.first, to = e.second;
            if(seen[to]) continue;
            seen[to] = true;
            if(bc == nc) nc++;
            colors[id] = nc;
            que.push(node(to, nc));
            nc++;
        }
    }
    cout << mx << ln;
    rep(i, n-1) cout << colors[i] << ln;
}

Measured memory_bytes: 7040
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long a, long long b){

    set<int> s;
    s.emplace(a);
    s.emplace(b);
    for(int i = 1; i <= 3; ++i)
        if(!s.count(i))
            cout << i << endl;
}


signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int main(){

    int n, m;

    while(cin >> n >> m){
        vector<int> c(n);
        vector<int> v(n);
        vector<int> d(n);
        vector<int> l(n);

        for(int i = 0; i < n; i++){
            
            string s;
            cin.ignore();
            getline(cin, s);
            //cout << "ok" << endl;
            // cin >> c[i] >> v[i] >> d[i] >> l[i];
            scanf("%d %d %d %d", &c[i], &v[i], &d[i], &l[i]);
        }

        int ans = 0;
        vector<vector<int> > dp(n + 1, vector<int> (m + 1, 0));
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= m; j++){
                int value = 0;

                for(int k = j; k <= m; k += c[i]){
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + value);
                    value += v[i];
                }
            }
        }

        for(int j = 0; j <= m; j++){
            ans = max(ans, dp[n][j]);
        }

        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= m; j++){
                dp[i][j] = 0;
            }
        }


        for(int i = 0; i < n; i++){
            for(int j = 0; j <= m; j++){
                int value = 0;

                for(int k = j; k <= m; k += c[i]){
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + value);
                    value += d[i];
                }
            }
        }

        for(int j = 0; j <= m; j++){
            ans = max(ans, dp[n][j]);
        }
        

        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= m; j++){
                dp[i][j] = 0;
            }
        }

        for(int i = 0; i < n; i++){
            for(int j = 0; j <= m; j++){
                int value = 0;

                for(int k = j; k <= m; k += c[i]){
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + value);
                    value += l[i];
                }
            }
        }

        for(int j = 0; j <= m; j++){
            ans = max(ans, dp[n][j]);
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b; cin>>a>>b;
	int ans = (a<10 & b<10)? a*b:-1;
	ote(ans);
}


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

string L;
ll dpC[100010] = { 0 };  //dpC[i] : 上からi番目まででL以下確定
ll dpUC[100010] = { 0 };

int main(){
  cin >> L;
  int len = L.size(); //桁数取得

  dpUC[0] = 1;  //初期は不確定
  for(int i = 0; i < len; i++){
    if(L[i] == '0'){  //桁が0
      dpC[i+1] = (3 * dpC[i]) % MOD;  //(1,0),(0,1),(0,0)
      dpUC[i+1] = dpUC[i] % MOD;  //(0,0)
    } else if(L[i] == '1'){
      dpC[i+1] = (dpUC[i] + 3 * dpC[i]) % MOD;  //(0,0) | (1,0), (0,1), (0,0)
      dpUC[i+1] = (2 * dpUC[i]) % MOD;  //(1,0), (0,1)
    }
  }

  cout << (dpC[len] + dpUC[len]) % MOD << endl;
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

    string s;
cin>>s;
  if(s=="RRR")cout<<3<<endl;
  else if(s=="RRS")cout<<2 <<endl;
  else if(s=="RSS")cout<< 1<<endl;
  else if(s=="RSR")cout<<1 <<endl;
  else if(s=="SRR")cout<<2 <<endl;
  else if(s=="SSR")cout<<1 <<endl;
  else if(s=="SRS")cout<<1 <<endl;
  else  cout<<0 <<endl;
  //else  cout<<0<<endl;


}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N, d[105];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> d[i];
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			ans += d[i] * d[j];
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5+1;
const int inf=1e9;
int main(){
	int N,K; cin>>N>>K;
	long a; long sum[2][N+1]; sum[0][0] = sum[1][0] = 0;
	rep(i,0,N){
		cin>>a;
		sum[0][i+1] = sum[0][i] + a;
		sum[1][i+1] = sum[1][i] + max(a, 0L);
	}
	long ans = 0;
	rep(i,0,N-K+1){
		int j = i + K;
		long res = 0;
		res += sum[1][i] - sum[1][0];
		res += max(sum[0][j] - sum[0][i], 0L);
		res += sum[1][N] - sum[1][j];
		ans = max(ans, res);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792