akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a < b) {
			if (b < c) {
				System.out.printf("%d %d %d\n", a, b, c);
			} else {
				if (a < c) {
					System.out.printf("%d %d %d\n", a, c, b);
				} else {
					System.out.printf("%d %d %d\n", c, a, b);
				}
			}
		} else {
			if (a < c) {
				System.out.printf("%d %d %d\n", b, a, c);
			} else {
				if (b > c) {
					System.out.printf("%d %d %d\n", c, b, a);
				} else {
					System.out.printf("%d %d %d\n", b, c, a);
				}
			}
		}
	}
}


Measured memory_bytes: 26356
n = int(input())
l = list(map(int, input().split()))

ans = []
for i in range(n):
    for j in range(n):
        for k in range(n):
            if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
                a, b, c = sorted([l[i], l[j], l[k]])
                if a + b > c:
                    ans.append([i, j, k])


print(len(set(frozenset(i) for i in ans)))


Measured memory_bytes: 155936
// Problem : C - Digits in Multiplication
// Contest : AtCoder - AtCoder Beginner Contest 057
// URL : https://atcoder.jp/contests/abc057/tasks/abc057_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int digits(ll i)
{
	int count=0;
	while(i>0)
	{
		i=i/10;
		count++;
	}
	return count;
}
ll n;
void factors(ll n)
{	
	int ans=INT_MAX;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		ans=min(ans,max(digits(i),digits(n/i)));
	}
	cout<<ans<<nl;	
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	cin>>n;
	factors(n);
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3644
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int H,W,N,sum=0;
char array[1005][1005];
int book[1005][1005];
int price[4][2]={0,1,1,0,0,-1,-1,0};
int a,b,c,d;
struct node
{
	int x;
	int y;
	int time;
}st;
queue<node> q;
bool bfs(){
	memset(book,0,sizeof(book));    //book初始化 
	book[a][b]=1;
	while(!q.empty()){              //队列初始化 
		q.pop();
	}
	st.x=a;
	st.y=b;
	st.time=0;
	q.push(st);
	node v1;
	int tx,ty;
	while(!q.empty()){
		v1=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			tx=v1.x+price[i][0];
			ty=v1.y+price[i][1];
			if(tx<0||tx>=H||ty<0||ty>=W||array[tx][ty]=='X'||book[tx][ty]==1)
				continue;
			book[tx][ty]=1;
			st.x=tx;
			st.y=ty;
			st.time=v1.time+1;
			q.push(st);
			if(tx==c&&ty==d){
				return true;
			}
		}
	}
}
int main(){
	node v2;
	cin>>H>>W>>N;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>array[i][j];
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			if(array[i][j]=='S'){
				a=i;
				b=j;
		}
	for(int k=0;k<N;k++)
		for(int i=0;i<H;i++)
			for(int j=0;j<W;j++){
				if(array[i][j]=='1'+k){
					c=i;
					d=j;
					if(bfs()){
						v2=q.back();
						sum+=v2.time;
					}
					a=c;
					b=d;
				}
			}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 8064
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double width[]=new double[N];
    double max=width[0];
    double sum=0;
    for(int i=0;i<N;i++){
      width[i]=sc.nextDouble();
    }
    for(int i=0;i<N;i++){
      if(width[i]>max){
      	max=width[i];
      }
    }
    for(int j=0; j<N; j++){
    	sum+=width[j];
    }
    
    if(sum-max>max){
    System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 25044
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
#include<functional>
#include <cassert>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    cout<<n<<":"<<" ";
    ll a=2;
    while(n>=a*a){
        if(n%a==0){
            cout<<a<<" ";
            n /= a;
        }else a++;
    }
    cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
	int a, b;
	char op = '\0';

	while(op != '?') {
		cin >> a >> op >> b;

		switch(op) {
			case '+' : cout << a + b << endl; break;
			case '-' : cout << a - b << endl; break;
			case '*' : cout << a * b << endl; break;
			case '/' : if(b) cout << (int)a / b << endl; break;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
n = gets.split.map(&:to_i)
divi = [0,0,0]
divi[0] = (n[1]/n[2])-((n[0]-1)/n[2])
divi[1] = (n[1]/n[3])-((n[0]-1)/n[3])
require 'prime'
prime = []
Prime.each(10**5) do |pr|
  prime.push(pr)
end
mini = 1
for i in 0..prime.length-1
  while n[2] % prime[i] == 0 && n[3] % prime[i] == 0
    n[2] /= prime[i]
    n[3] /= prime[i]
    mini *= prime[i]
  end
end
mini *= n[2]
mini *= n[3]
divi[2] = (n[1]/mini)-((n[0]-1)/mini)
puts (n[1]-n[0]+1) - divi[0] - divi[1] + divi[2]


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

void merge(int *,int ,int ,int);
void mergeSort(int *,int, int);

int count = 0;

int main(){
  int n,s[500000],i,left,right;

  scanf("%d",&n);
  if(500000 < n)exit(0);
  
  left = 0;
  right = n;
   
  //  s = (int *)malloc(n*sizeof(int));
  for(i = 0; i < n; i++){
    scanf(" %d",&s[i]);
    if(s[i] < 0 || 1000000000 < s[i])exit(0);
  }
  
  mergeSort(&s[0],left,right);
  
  printf("%d",s[0]);
  for(i = 1; i < n; i++){
    printf(" %d",s[i]);
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}

void mergeSort(int *s,int left,int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(&s[0],left,mid);
    mergeSort(&s[0],mid,right);
    merge(&s[0],left,mid,right);
  }
  
}

void merge(int *s,int left,int mid ,int right){
  int n1,n2,l1[mid - left],l2[right - mid],i,j,k,inf = 9999999999;
  
  n1 = mid - left;
  n2 = right - mid;

  //  l1 = (int *)malloc(n1*sizeof(int));
  //l2 = (int *)malloc(n2*sizeof(int));
  
  for(i = 0; i < n1; i++)l1[i] = s[left + i];
  for(i = 0; i < n2; i++)l2[i] = s[mid + i];
  
  l1[n1] = inf;
  l2[n2] = inf;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    if(l1[i] <= l2[j]){
      
      s[k] = l1[i];
      i = i + 1;
      count++;
    }
    else {
      
      s[k] = l2[j];
      j = j + 1;
      count++;
    }
    
  }
}



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

typedef long long ll;
const ll MOD = 1000000007;

int N, K;
vector<vector<int>> G;

ll dfs (int u, int parent) {
    int remaining;
    if (parent == -1) {
        remaining = K - 1;
    } else {
        remaining = K - 2;
    }

    if (K < G[u].size()) {
        return 0;
    } else {
        ll res = 1;
        for (int v : G[u]) {
            if (v == parent) continue;

            res *= remaining;
            remaining--;
            res %= MOD;
        }

        for (int v : G[u]) {
            if (v == parent) continue;

            res *= dfs(v, u);
            res %= MOD;
        }
        return res;
    }
}
int main() {
    cin >> N >> K;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll res = K * dfs(0, -1);
    res %= MOD;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 10368
NM=list(map(int,input().split()))
inp=list(map(int,input().split()))

N=NM[0]
M=NM[1]

inp.sort()
dis=[]
#print(inp)
c=0
for r in inp[:-1]:
    dis.append(inp[c+1]-inp[c])
    c+=1
#print(dis)
dis.sort()
for de in range(N-1):
    if len(dis)>0:    
        del dis[-1]
#print(dis)
print(sum(dis))

Measured memory_bytes: 13960
if __name__ == '__main__':
    n, m, l = [int(i) for i in input().split()]
    A = [[int(i) for i in input().split()] for j in range(n)]
    B = [[int(i) for i in input().split()] for j in range(m)]
    B = list(map(list, zip(*B))) # trace
    C = [[sum(map(lambda x,y: x*y, A[i], B[j])) for j in range(l)] for i in range(n)]
    for i in C:
        print(' '.join([str(x) for x in i]))

Measured memory_bytes: 7760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		
		System.out.println((a + b >= c) ? "Yes" : "No");
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl '\n'

int main() {

    fast
    string s;cin>>s;
    map<int, vector<int> > mp;
    for(int i=0; i<4; ++i){
        mp[s[i]].push_back(i);
    }
    if(mp.size()==2){
        map<int, vector<int> > :: iterator it, it2;
        it=mp.begin();
        it2=it;it2++;
        if(it->second.size()==2 && it2->second.size()==2){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


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

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define re reverse
#define ps push
#define in insert
#define sv(v) shuffle(all(v), default_random_engine())
#define sa(a, n) shuffle(a, a+n, default_random_engine())
#define ca(v) for(auto i:v) cout<<i<<" ";
#define nl cout<<"\n"
#define del(s, x) s.erase(s.find(x))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
#define debug cout<<"DEBUG\n"
const int MOD = 1e9 + 7;
const int MAXN = 3e3+5;

double dp[MAXN][MAXN];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    double ar[n];
    for(int i=0; i<n; i++) cin>>ar[i];
    dp[0][0] = 1-ar[0];
    dp[0][1] = ar[0];
    for(int i=1; i<n; i++){
        for(int j=n; j>0; j--) {
            dp[i][j]+=dp[i-1][j-1] * ar[i];
            dp[i][j]+=dp[i-1][j] * (1-ar[i]);
        }
        dp[i][0] = dp[i-1][0] * (1-ar[i]);
    }
    double tot = 0;
    for(int i=n/2+1; i<=n; i++){
        tot+=dp[n-1][i];
    }
    cout<<fixed<<setprecision(12)<<tot;
}



Measured memory_bytes: 74040
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramA a = new ProgramA();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            //時間に換算して起きてる時間からk時間を除く
            Console.WriteLine(s.Substring(0,3));

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            //?はD、それ以外は普通に出す
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '?')
                {
                    Console.Write('D');
                }
                else
                {
                    Console.Write(s[i]);
                }
            }


        }
    }

    class ProgramC
    {
        public void main()
        {

            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');

            //n=0のときは例外処理
            if (n == 0)
            {
                if (a[0] == "1")
                    Console.WriteLine("1");
                else
                    Console.WriteLine("-1");
                return;
            }
            //0のときは0以外はダメ
            if (a[0] != "0")
            {
                Console.WriteLine("-1");
                return;
            }
            long[] num = new long[n + 1];
            long[] leave = new long[n + 1];
            num[0] = 1;
            leave[n] = long.Parse(a[n]);
            //深さiを含む後ろの根の数を数えておく
            for (int i = n - 1; i >= 0; i--)
                leave[i] = leave[i + 1] + long.Parse(a[i]);
            //前から根の数を決める（ただし、最大は後ろに考えるべき根の数に限られる）
            for (int i = 1; i <= n; i++)
            {
                num[i] = Math.Min(2 * (num[i - 1] - long.Parse(a[i - 1])), leave[i]);
                //あり得る数が葉になる数より大きければあり得ない(n-1まで）
                if (i < n && num[i] <= long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }
                //最後は頭からの条件で満たさないならアウト
                if (i == n && num[i] < long.Parse(a[i]))
                {
                    Console.WriteLine("-1");
                    return;
                }
            }

            //答え出力
            long ans = 0;
            for (int i = 0; i <= n; i++)
                ans += num[i];

            Console.WriteLine(ans);
        }
    }
}






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

vector<vector<int>> G;
vector<int> ans;

int main(){
	// sengen
	int n,m;
	// nyuryoku
	cin >> n >> m;
	G.assign(n,vector<int>());
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ans.assign(n,-1);
	// keisan
	queue<int> que;
	for(auto v:G[0]){
		que.push(v);
		ans[v] = 0;
	}
	while(!que.empty()){
		int now = que.front();
		que.pop();
		for(auto v:G[now]){
			if(ans[v] == -1){
				ans[v] = now;
				que.push(v);
			}
		}
	}
	// syutsuryoku
	int count = 0;
	for(int i=1;i<n;i++){
		if(ans[i] == -1){
			count++;
		}
	}
	if(count > 0){
		cout << "No";
	}else{
		cout << "Yes" << endl;
		for(int i=1;i<n;i++){
			cout << ans[i]+1 << endl;
		}
	}
}

Measured memory_bytes: 10160
#include <stdio.h>

void push(int);
int pop();

int top,S[1000];

int main(){
  int a,b;
  int top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if ( s[0] == '-' ){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
    }
    else {
      push(atoi(s));
    }
  }

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


void push(int x){
  top++;
  S[top] = x;
 
}
  
int pop(void){
  top--;
  return S[top + 1];
}



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

int N, M, R;
int r[201];/*
int A[1000];
int B[1000];
int C[1000];
bool nes[201];*/
int d[201][201];
int dp[1 << 8][8];
constexpr int64_t INF = 1 << 28;

int rec(int S, int v){
    if(dp[S][v] >= 0){
        return dp[S][v];
    }
    if(S == (1 << R) - 1){
        return dp[S][v] = 0;
    }
    int res = INF;
    for(int u = 0; u < R; ++u){
        if(d[r[v]][r[u]] != 0 && !(S >> u & 1)){
            //cout << (S | 1 << u) << " " << u << endl;
            res = min(res, rec(S | 1 << u, u) + d[r[v]][r[u]]);
            //cout << res << endl;
        }
    }
    return dp[S][v] = res;
}

int solve(){
    int res = INF;
    for(int k = 0; k < R; ++k){
        //cout << k << endl;
        for(int i = 0; i < (1 << 8); ++i){
            for(int j = 0; j < 8; ++j){
                dp[i][j] = -1;
            }
        }
        res = min(res, rec(1 << k, k));
    }
    return res;
}

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

    cin >> N >> M >> R;

    for(int i = 0; i < R; ++i){
        cin >> r[i];
        r[i]--;
    }
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            d[i][j] = INF;
        }
    }
    for(int i = 0; i < M; ++i){
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;
        d[A][B] = C;
        d[B][A] = C;
    }


    for(int k = 0; k < N; ++k){
        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }/*
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            cout << d[i][j] << " ";
        }
        cout << endl;
    }*/


    cout << solve() << endl;

    return 0;
}

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

const int MAX_V=100000;

struct edge {int to, cost; };

vector<edge> G[MAX_V+1];
vector<int> res;
int n;

//v:=current vertex, p:=parent of v, color:=color of v
void dfs(int v, int p, int color) {
  res[v]=color;
  for (auto e : G[v]) {
    int next_v=e.to;
    int weight=e.cost;
    if (next_v==p) continue;
    if (weight%2==1) dfs(next_v, v, (1^color));
    else dfs(next_v, v, color);
  }
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n-1; i++) {
    int u,v,w;
    scanf("%d %d %d", &u,&v,&w);
    u--; v--;
    G[u].push_back(edge{v, w});
    G[v].push_back(edge{u, w});
  }
  res.resize(n, -1);
  dfs(0, -1, 0);
  for (int i=0; i<n; i++) cout<<res[i]<<endl;
  return 0;
}


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

int main(){
int a,b,x;
cin>>a>>b>>x;
bool ok=false;
if (a+b<x||a>x)
{
    /* code */
    cout<<"NO"<<endl;
}
else
{
    cout<<"YES"<<endl;
}


}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

ll gcd(vector<ll> xs){
    sort(xs.begin(),xs.end());
    vector <ll> nxs(xs.size());
    nxs[0] = xs[0];
    bool same = true;
    rep(j,xs.size()){
        if (xs[j]%xs[0]!=0) {nxs[j] = xs[j]%xs[0]; same = false;}
        else nxs[j] = xs[j];
    }
    if (same){
        rn xs[0];
        
    }
    else{
        rn gcd(nxs);
    }
}

int main(){
    ll N, X; cin >> N >> X;
    vector <ll> xs(N);
    rep(i,N){
        ll x;
        cin >> x;
        xs[i] = (ll) abs(x - X);
    }
    ll ans;
    
    ans = gcd(xs);
    
    
    cout << ans;
    
}

Measured memory_bytes: 4096
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    ll k,x;
    cin >> k >> x;
    if(500*k >= x)Yes;
    else No;
    return  0;
}


Measured memory_bytes: 256
N=int(input())
A = list(map(int,input().split()))
#print(A)
sum_org=sum(A)
#print(sum_org)

for i in range(N-1):
    tallest=max(A[i],A[i+1])
    if A[i] > A[i+1]:
        A[i+1]=tallest
#print(A)
sum_new=sum(A)
#print(sum_new)

print(sum_new-sum_org)

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

int main(){
  int a, b;
  cin >> a >> b;
  if(b==1){
    cout << 0 << endl;
  }else{
    int res = 1;
    while(true){
      if(b <= (a-1) * (res-1) + a){
        break;
      }
      res++;
    }
    cout << res << endl;
  }
}


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

using namespace std;

void fast()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
const int mxA = 1e7;
int freq [mxA+1] ;
int pref [mxA+1];

int main()
{
    fast();
    int n ,x;
    cin >> n >>x;
     cout << (n-1) * (x-1) ;
}



Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n,k,q = inp
a = []
q.times{a << inp[0]}
tab = na(n+1,k-q)
a.each do |d|
  tab[d] += 1
end
tab.shift
tab.each do |d|
  if(d > 0)
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n, q;
  while(cin >> n >> q, n+q) {
    int date[110] = {};
    for(int i = 0; i < n; i++) {
      int m; cin >> m;
      for(int j = 0; j < m; j++) {
        int x; cin >> x;
        date[x]++;
      }
    }

    int mnum = q, ans = 1000;
    for(int i = 0; i < 110; i++) {
      if((date[i] == q && i < ans) || date[i] > mnum) {
        ans = i;
        mnum = date[i];
      }
    }
    if(ans == 1000) ans = 0;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
using namespace std;

class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
int N,L,K,p,q;

int main()
{
  cin>>N>>K>>L;
  UnionFind uf1(N), uf2(N);
  for (int i=0; i<K; i++){
    cin>>p>>q;p--;q--;
    uf1.unite(p,q);
  }
  for (int i=0; i<L; i++){
    cin>>p>>q;p--;q--;
    uf2.unite(p,q);
  }
  map<pair<int,int>,int> ans;
  for(int i=0; i<N; i++){
    ans[make_pair(uf1.root(i),uf2.root(i))]++;
  }
  for(int i=0; i<N; i++){
    cout<<ans[make_pair(uf1.root(i),uf2.root(i))]<<endl;
  }
}


Measured memory_bytes: 15104
# coding: utf-8
N = int(input())
P = list(map(int, input().split()))
L = [P[0]]
ans = 0
for i in range(1, N):
    if L[-1] == P[i]:
        ans += 1
    L.append(min(L[-1], P[i]))
print(len(set(L)) + ans)

Measured memory_bytes: 25788
#%%
N =int(input())

#import sympy

l = [0] * (N+1)

#for i in range(1,N+1):
#    a = sympy.factorint(i)
#    for k, v in a.items():
#        l[k] += v


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

for j in range(1, N+1):
    a = factorize(j)
#    print(a)
    for i in range(len(a)):
        l[a[i][0]] += a[i][1]


#print(l)

l_2 = []
l_4 = []
l_14 = []
l_24 = []
l_74 = []

for i in range(len(l)):
    if l[i]>=2:
        l_2.append(i)
    if l[i]>=4:
        l_4.append(i)
    if l[i]>=14:
        l_14.append(i)
    if l[i]>=24:
        l_24.append(i)
    if l[i]>=74:
        l_74.append(i)

#print(l_2)
#print(l_4)
#print(l_14)
#print(l_24)
#print(l_74)

count_2_4_4 = 0
count_4_14 = 0
count_2_24 = 0
count_74 = 0

for i in range(len(l_2)):
    for j in range(len(l_4)):
        for k in range(j,len(l_4)):
            if l_2[i] != l_4[j] and l_2[i] != l_4[k] and l_4[j] != l_4[k]:
                count_2_4_4 += 1

for i in range(len(l_4)):
    for j in range(len(l_14)):
        if l_4[i] != l_14[j] :
            count_4_14 += 1

for i in range(len(l_2)):
    for j in range(len(l_24)):
        if l_2[i] != l_24[j]:
            count_2_24 += 1

count_74 += len(l_74)


#print(count_2_4_4)
#print(count_4_14)
#print(count_2_24)
#print(count_74)

ans = count_2_4_4 + count_4_14 + count_2_24 + count_74
print(ans)



Measured memory_bytes: 3316
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
INF = 10 ** 10
dp = [INF] * (2 ** N)
dp[0] = 0

for i in range(M):
  a,b = map(int,readline().split())
  c = list(map(int,readline().split()))
  key = 0
  for j in range(len(c)):
    key += (1 << (c[j] - 1))
  for j in range(len(dp)):
    if dp[j] == INF:
      continue
    if j | key == j:
      continue
    dp[j | key] = min(dp[j | key], dp[j] + a)

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define ld long double
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    BRAHAMASTRA
    ll t; t=1;
    // cin >>t;
    while(t--)
    {
         ll x; cin >>x;  
         if(x>=400 and x<=599)cout<<8;
         else if(x>=600 and x<=799)cout << 7;
         else if(x>=800 and x<=999)cout<<6;
         else if(x>=1000 and x<= 1199)cout <<5;
         else if(x>=1200 and x <=1399)cout <<4;
         else if(x>=1400 and x<=1599)cout <<3;
         else if(x>=1600 and x<= 1799)cout <<2;
         else if(x>=1800 and x<=1999)cout <<1;    
    }
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main() {
  string a, b;
  cin >> a >> b;
  int n = a.size();
  int m = b.size();
  string ans;
  int j=0, k=0;
  rep(i, 0, n+m){
    if(i%2==0){
      ans += a[j];
      j++;
    }else{
      ans += b[k];
      k++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll D, G;
    cin >> D >> G;
    vector<ll> p(D);
    vector<ll> c(D);
    vector<ll> pc(D);
    ll ans = (1<<29);
    rep(i, D){
        cin >> p[i] >> c[i];
        pc[i] = (i+1)*100*p[i] + c[i];
    }
    rep(bit, (1<<D)){
        vector<int> flag(D, 0);
        ll a=0;
        ll p_sum=0;
        rep(i, D){
            if(bit & (1<<i)){
                a += pc[i];
                p_sum += p[i];
                flag[i] = 1;
            }
        }
        if(a>=G){
            ans = min(ans, p_sum);
        }else{
            for(int i=D-1; i>=0; i--){
                if(flag[i]) continue;
                rep(j, p[i]){
                    p_sum++;
                    a += (i+1)*100;
                    if(a>=G){
                        ans = min(ans, p_sum);
                    }
                }
            }
        }
    }
    out(ans);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if (a + b > c + d)printf("Left\n");
	else if (a + b == c + d)printf("Balanced\n");
	else printf("Right\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) for(i=1;i<=n;i++)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	int h, w;
	cin >> h >> w;
	char c[105][105];
	rep(i, h){
		rep(j, w){
			cin >> c[i][j];
		}
	}
	rep(i, 2*h){
		rep(j, w){
			cout << c[i/2][j];
		}
		cout << endl;
	}
}

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

int main() {

	int N;
    cin >> N;
    string x;
    int check = 0;
    
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x == "Y") {
      check = 1;
    }
  }
  if (check == 0) {
      cout << "Three" << endl;
    }
  else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 3568
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define ll long long int
#define vi vector<int>
#define pr pair<ll, ll>
#define vll vector<pr>
#define vl vector<ll>
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(a, b))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x%mod);
    return v;}
void out(vl v){fl(i,v)cout<<i;}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;}

void solve(){
    ll n, a, x, total = 0;
    cin>>a>>n;
    f(i, n)
    cin>>x, total+=x;
    (total >= a) ? cout<<"Yes" : cout<<"No";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct edge{
    int to;
    ll cost;
    int trans;
};

const int N = 200000;
const ll INF = LLONG_MAX/3;

using pi = pair<int,int>;
using pl = pair<ll,int>;

vector<edge> G[N];
pl d[N];

int main(){
    int n,T;
    string start,goal;
    cin >>n >>T >>start >>goal;

    map<string,int> s2id;
    int num = 0;
    s2id[start] = num++;
    s2id[goal] = num++;

    vector<int> a(n);
    vector<vector<int>> r(n),t(n);
    rep(i,n){
        cin >>a[i];
        r[i] = vector<int>(a[i]);
        t[i] = vector<int>(a[i]-1);

        rep(j,a[i]){
            string tmp;
            cin >>tmp;
            if(!s2id.count(tmp)) s2id[tmp] = num++;
            r[i][j] = s2id[tmp];
        }
        rep(j,a[i]-1) cin >>t[i][j];
    }

    map<pair<int,pi>, int> p2id;
    int SZ = 0;
    rep(i,num) p2id[{i,{-1,-1}}] = SZ++;

    rep(i,n){
        rep(j,a[i]){
            if(!p2id.count({r[i][j], {i,j}})) p2id[{r[i][j], {i,j}}] = SZ++;
            int u = p2id[{r[i][j], {i,j}}], v = p2id[{r[i][j], {-1,-1}}];

            if(r[i][j]==1) G[u].pb({v,0,0});
            else G[u].pb({v,T,1});
            G[v].pb({u,0,0});
        }

        rep(j,a[i]-1){
            int u = p2id[{r[i][j], {i,j}}], v = p2id[{r[i][j+1], {i,j+1}}];
            G[u].pb({v,t[i][j],0});
            G[v].pb({u,t[i][j],0});
        }
    }

    fill(d,d+N,pl(INF,N));
    using P = pair<pl,int>;
    priority_queue<P, vector<P>, greater<P>> pq;

    d[p2id[{0,{-1,-1}}]] = {0,0};
    pq.push({{0,0},p2id[{0,{-1,-1}}]});
    while(!pq.empty()){
        P now = pq.top();
        pq.pop();

        int v = now.se;
        if(now.fi > d[v]) continue;

        for(const auto &e:G[v]){
            pl nx = now.fi;
            nx.fi += e.cost;
            nx.se += e.trans;

            if(d[e.to] > nx){
                d[e.to] = nx;
                pq.push({nx, e.to});
            }
        }
    }

    pl ans = d[p2id[{1,{-1,-1}}]];
    if(ans.fi == INF) cout << -1 << endl;
    else cout << ans.fi << " " << ans.se << endl;
    return 0;
}



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

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

using namespace std;

const int INF = 10 * 1000 * 1000;
int H, W, K;
int S[10][1000];
int tot[10][1000];

int dfs(int h, vector<int>& assignments, const vector<vector<int>>& tot) {
  if (h == H) {
    int prev = -1;
    int cuts = 0;
    // cout << "assignments: ";
    // for (auto x : assignments) cout << x << " "; cout << endl;
    // return 0;
    for (int w = 0; w < W; ++w) {
      bool need_cut = false;
      for (int ai = 0; ai < assignments.size() ; ++ai) {
        auto cnt = [&tot](int hh, int hw, int lh, int lw){
                     return tot[hh][hw]
                         - tot[lh][hw]
                         - tot[hh][lw]
                         + tot[lh][lw];
                   };
        int lh = (ai == 0 ? 0 : assignments[ai - 1]);
        int hh = assignments[ai];
        int before = cnt(hh, w, lh, prev);
        int after = cnt(hh, w + 1, lh, prev);
        // cout << "w:" << w << " ai:" << ai << " lh" << lh << " hh" << hh << " before" << before << " after" << after << endl;
        if (after - before > K) return INF;
        if (after > K) need_cut = true;
      }
      // cout << need_cut << endl;
      if (need_cut) {
        ++cuts;
        prev = w;
      }
    }
    // cout << "cuts:" << cuts << endl;
    return cuts + assignments.size() - 1;
  }
  int ans = INF;
  for (++h; h <= H; ++h) {
    assignments.push_back(h);
    ans = min(ans, dfs(h, assignments, tot));
    assignments.pop_back();
  }
  return ans;
}

vector<vector<int>> cal(const vector<string>& s) {
  vector<vector<int>> tot(H + 1, vector<int>(W + 1));
  REP(i, H) REP(j, W) {
    tot[i + 1][j + 1] = tot[i][j + 1] + tot[i + 1][j] - tot[i][j] + (s[i][j] == '1');
  }
  return tot;
}

int main() {
  cin >> H >> W >> K;
  vector<string> S(H);
  REP(i, H) cin >> S[i];

  vector<int> v;
  cout << dfs(0, v, cal(S)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    double a, b, c, d, e, f;
    double ans, ans2;
 
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
 
            ans2 = (c * d - a * f) / (b * d - a * e);
            ans = (c - b * ans2) / (a);
 
        printf("%.3f %.3f\n", ans, ans2);
    }
    return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

const double PI=3.14159265358979323846;

int main(){
    double a, b, x;
    cin>>a>>b>>x;
    double h;
    double  theta;
    if(2*x>=a*a*b){
        h = 2*x/(a*a) - b;
        theta = atan(a/(b-h))*180/PI;
        cout<<setprecision(10)<<90-theta<<endl;
    }
    else {
        h = a - 2*x/(a*b);
        theta = atan((a-h)/b)*180/PI;
        cout<<setprecision(10)<<90-theta<<endl;
    }
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll a;
    int b1, b2;
    cin >> a;
    scanf("%d.%d", &b1, &b2);
    ll ans = (a * (b1 * 100 + b2)) / 100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    int t,a; cin>> t >> a;
    double ans=INF;
    int Ans;
    rep(i,n){
        int h; cin >> h;
        double tem=t-h*0.006;
        double now=abs(a-tem);
        if(ans>now){
            Ans=i+1;
            ans=now;
        }
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 3640
while True:
    a = input().split()

    op = a[1]
    x = int(a[0])
    y = int(a[2])

    if op == "?":
        exit(0)
    elif op == "+":
        print(x+y)
    elif op == "*":
        print(x*y)
    elif op == "-":
        print(x-y)
    elif op == "/":
        print(int(x/y))
    


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int n;
ll ans;
vi g[N];

void dfs(int a, int p){
	if(p < a) ans += 1LL * (a-p) * (n-a+1);
	else ans += 1LL * a * (p-a);
	for(int i : g[a]) if(i != p) dfs(i, a);
}

int main(){
	scanf("%d", &n);
	REP(i, n-1){
		int a, b; scanf("%d%d", &a, &b);
		g[a].EB(b);
		g[b].EB(a);
	}
	dfs(1, 0);
	printf("%lld\n", ans);
}


Measured memory_bytes: 24320
import numpy as np
N = int(input().strip('\n'))
k2 = 1+np.sqrt(1+8*N)
if k2%2==0:
    k=int(k2/2)
    print('Yes')
    print(k)
    yel = [1]
    red = [1]
    for i in range(1,k-1):
        yel.append(yel[i-1]+1+i)
        red.append(red[i-1]+i)
    yel = np.array(yel).astype('int32')
    red = np.array(red).astype('int32')
    print(k-1,*yel)
    print(k-1,*red)
    for i in range(1,k-1):
        fs = np.arange(red[i],red[i]+i).astype('int32')
        sc = red[i:]+i
        fs = np.concatenate((fs,sc))
        print(k-1,*fs)
else:
    print('No')

Measured memory_bytes: 13792
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,mod;std::cin>>n>>mod;
    std::string s;std::cin>>s;
    std::vector<lint>a(n+1);
    std::transform(s.begin(),s.end(),a.begin(),[](char c){return c-'0';});
    if(mod==2||mod==5){
        lint ans=0;
        for(lint i=0;i<n;i++){
            if(a.at(i)%mod==0)ans+=i+1;
        }
        std::cout<<ans<<'\n';
        return 0;
    }
    std::partial_sum(a.rbegin(),a.rend(),a.rbegin(),
        [mod,j=1](lint x,lint y)mutable{return(x+std::exchange(j,10*j%mod)*y)%mod;});
    std::vector<lint>b(mod);
    for(lint x:a)b.at(x)++;
    lint ans=std::accumulate(b.begin(),b.end(),0ll,[](lint x,lint y){return x+y*(y-1)/2;});
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 2196
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int a; cin >> a;
  int b; cin >> b;
  int k; cin >> k;

  int i = a;
  while (i <= b) {
    if (i < a + k || (b - k + 1 <= i && i <= b))
      cout << i << endl;
    ++i;
  }
}


Measured memory_bytes: 256
#include <cstdint>
#include <cstdio>

const int N = 60, mod = 1e9 + 7;
const int FIRST = 0, SAME = 1, DIFF = 2;
int n, status = FIRST;
char c1[N], c2[N];
int64_t ans = 1;

int main() {
    scanf("%d%s%s", &n, c1, c2);
    for (int i = 0; i < n; i++) {
        if (c1[i] == c2[i]) {
            switch (status) {
                case FIRST:
                    ans = ans * 3 % mod;
                    break;
                case SAME:
                    ans = ans * 2 % mod;
                    break;
                case DIFF:
                    break;
            }
            status = SAME;
        } else {
            switch (status) {
                case FIRST:
                    ans = ans * 6 % mod;
                    break;
                case SAME:
                    ans = ans * 2 % mod;
                    break;
                case DIFF:
                    ans = ans * 3 % mod;
                    break;
            }
            i++;
            status = DIFF;
        }
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
set <int> s;
vector <int > d;





int main()
{

	cin >> N;



	REP(i,N){
		int a;
		cin >> a;
		s.insert(a);
	}
	cout << s.size();




}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
    	while(line!=null){
    		String[] lines = line.split(" ");
    		int a = Integer.parseInt(lines[0]);
    		int b = Integer.parseInt(lines[1]);
    		System.out.println(Integer.toString(a+b).length());
    		line = br.readLine();
    	}
	}
}

Measured memory_bytes: 24324
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    string s;
    cin >> s;
    REP(i,s.length()) if(s[i] == ',') s[i] = ' ';
    cout << s << "\n";
}

Measured memory_bytes: 256