akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

struct Data{
	int y, x, dep;
	Data(){
		dep = 0;
	}
};

int main(){
	int n, x_sp[10], y_sp[10];
	Data s;
	int nx_phon[13] = { 0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1 },
		ny_phon[13] = { -2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1, -2 };
	int nx_sp[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 },
		ny_sp[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 };

	while (cin >> s.x >> s.y, s.x != 0 || s.y != 0){
		cin >> n;
		for (int i = 0; i < n; i++){
			cin >> x_sp[i] >> y_sp[i];
		}

		queue<Data> q;
		q.push(s);
		Data q_c, q_d;
		int px_phon, py_phon, px_sp, py_sp, ans = false;
		bool frst = true;
		while (!q.empty()){
			bool memo[10][10] = {};
			q_c = q.front();
			q.pop();
			for (int i = 0; i < 12; i++){
				px_phon = q_c.x + nx_phon[i];
				py_phon = q_c.y + ny_phon[i];
				if (px_phon < 0 || 9 < px_phon || py_phon < 0 || 9 < py_phon) continue;
				for (int j = 0; j < 9; j++){
					px_sp = x_sp[q_c.dep] + nx_sp[j];
					py_sp = y_sp[q_c.dep] + ny_sp[j];
					if (px_sp < 0 || 9 < px_sp || py_sp < 0 || 9 < py_sp) continue;
					//if (memo[px_sp][py_sp])continue;
					if (px_phon == px_sp && py_phon == py_sp){
						//printf("%d",q_c.dep);
						if (q_c.dep == n - 1){
							ans = true;
							goto END;
						}
						memo[px_sp][py_sp] = true;
						q_d.x = px_sp; q_d.y = py_sp; q_d.dep = q_c.dep + 1;
						if (q_d.dep == n){
							q_d.dep = 0;
							frst = false;
						}
						q.push(q_d);
						break;
					}
				}
			}
		}
		END:
		if (ans) printf("OK\n");
		else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1172
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*when the going gets tough the tough gets going  */
/*we are what we repeatedly do , Excellence then is not an act but a habit  - aristotle */
/*The best way to predict the future is to create it - abraham lincoln*/
/*First think , second believe , third dream and finally dare - walt disney*/
/*It is during our darkest moments that we must focus to see the light */
/*Nothing is impossible the word itself says "i'm fucking possible man just try me again and again till i seem impossible "*/
/*Dont judge each day by the harvest you reap but by the seeds you plant */
/*Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment*/
/*Success is not final failure is not fatal : it is the courage to continue that counts */ 
/*the future belongs to those who believe in the beauty of their dreams */
/*The pessimist complains about the wind , the optimist waits for it to change; the realist adjusts the sails  */
/*Believe you can and you are half way there */
/*Everything has beauty but not everyone sees it */
/*Life is not about finding yourself , life is about creating yourself*/
/*You are the average of the 5 people you spend the most time with .........*/
/*Everything is hard before it is easy see for example now the list of examples is very long hahahahahaha...... ......*/
/*I believe in miracles .......*/
#include<bits/stdc++.h>
#define LL long long 
#define pb push_back

#define PII pair<int , int > 
#define PLL pair<LL , LL >
#define LD long double
#define VLL vector<LL>
#define VPII vector<PII>
#define VI vector<int>
#define VPLL vector<PLL>
#define VLD vector<LD>
#define VVI vector<VI>
#define VVLL vector<VLL>
#define VVPLL vector<VPLL>
#define VVII vector<VPII>
#define IN insert
#define wht while (t--)
#define FU( i , a  , n ) for ( int i = (int)a ; i <=(int)n ; i++  )
#define FD( i , n , a ) for (int i = (int)n ; i >=(int)a ;i--)
#define REP(i,n) for ( int i = 0 ; i < (int)n;  i++)
#define FST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define SZ(a) int((a).size())
#define pi(n) printf("%d" , n ) 
#define pl(n) printf("%lld" , n )
#define ff first
#define ss second
#define ii(n) scanf("%d" , &n)
#define il(n) scanf("%lld" , &n )
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define ALL(V) V.begin(), V.end()
#define ic(n) cin>>n
#define pr printf
#define INF 99999999
#define en endl
using namespace std ;
string str ;
const int tt = 0;
 void solve()
 {
 	int   m , n ,a , b ,c ;
 	string ans;
 	cin>> str;
 	cin>> ans;
 	int cnt  = 0 ;
 	REP(i, SZ(str))
 	{
 		if (str[i] != ans[i])cnt++;
 	}
 	cout << cnt;
 }
int main()
{
	FST;
	
    if (tt)
    {
    	int t;
    	cin>> t ;
    	while (t--)
    	{
    		solve();
    	}
    }
    else
    {
    	solve();
    }
	return 0 ;
	
 
} 

Measured memory_bytes: 3780
def modinv(a,m):
    b, u, v = m, 1, 0
    while b:
        t = a//b
        a -= t*b
        a,b = b,a
        u -= t * v
        u,v = v,u
    u %= m
    return u


N_MAX = 10**6
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX, [0]*N_MAX, [0]*N_MAX
def com_init():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, N_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def com(n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD



def main():
    x, y = map(int, input().split()) 
    com_init()

    a3 = -x+2*y
    b3 = 2*x-y

    if a3%3 != 0 or b3%3 != 0:
        print(0) 
        return

    a = a3//3
    b = b3//3

    print(com(a+b, min(a,b)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 62192
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	vector<long long> abc_list(3, 0);

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

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

	long long plane = abc_list[0] * abc_list[1];
	long long red = abc_list[2] / 2 * plane;
	long long blue = (abc_list[2] - abc_list[2] / 2) * plane;

	cout << abs(red - blue);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define int long long
using namespace std;
const int MX = 100;
const int oo = 1ll << 30;
int boss[MX];
pii v[MX];
int Find(int u) {
	return boss[u] == u ? u : boss[u] = Find(boss[u]);
}
main () {
	map<pii, int> mp;
	int n; cin >> n;
	int ans = n;
	for(int i = 1; i <= n; i ++) {
		int x, y; cin >> x >> y;
		v[i] = {x, y};
		mp[{x, y}] = i;
	}
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= n; j ++) {
			if(i == j) continue;
			for(int k = 1; k <= n; k ++) boss[k] = k;
			int p = v[i].F - v[j].F;
			int q = v[i].S - v[j].S;
			for(int k = 1; k <= n; k ++) {
				if(mp[{v[k].F - p, v[k].S - q}]) {
					boss[Find(k)] = mp[{v[k].F - p, v[k].S - q}];
				}
			}
			set<int> s;
			for(int k = 1; k <= n; k ++) s.insert(Find(k));
			ans = min(ans, (int) s.size());
		}
	}
	cout << ans;
}

Measured memory_bytes: 4096
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
A,B = zip(*AB)

a = max(A) #振る
B = [b for b in B if b > a] #投げる
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)


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

int main()
{
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl; //Rainlyにしてた。。。
  else
    cout << "Sunny" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	pll a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].second;
		cin>>a[i].first;
	}
	sort(a+1,a+n+1);
	ll curr=0;
	for(int i=1;i<=n;i++)
	{
		curr+=a[i].second;
		if(curr>a[i].first)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;
vector<int>ar[N + 5];
ll sum[N + 5];
ll cost[N + 5];
bool visited[N + 5];
void DFS(int x, ll S){
  if (visited[x]){
    return ;
  }
  visited[x] = true;
  cost[x] = S + sum[x];
  for (int v: ar[x]){
    DFS(v, S + sum[x]);
  }
}
int main(){
  FASTER;
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; i++){
    int x, y;
    cin >> x >> y;
    ar[x].push_back(y);
    ar[y].push_back(x);
  }
  while (q--){
    int node, val;
    cin >> node >> val;
    sum[node] += val;
  }
  DFS(1, 0);
  for (int i = 1; i <= n; i++){
    cout << cost[i] << ' ';
  }
  return 0;
}


Measured memory_bytes: 25856
fun main(args:Array<String>):Unit {
    val (h, w) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(h){readLine()!!.trim()}
    val forecast = Array(h){Array(w){-1}}
    for (y in 0 until h){
        for (x in 0 until w){
            if (state[y][x] == 'c'){
                forecast[y][x] = 0
            }else{
                if (x > 0 && forecast[y][x - 1] >= 0) forecast[y][x] = forecast[y][x - 1] + 1
            }
        }
    }
    forecast.forEach {
        println(it.joinToString(" "))
    }
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    ll n;
    cin>>n;
    ll x[n];
    for(int i=0;i<n;i++)
        cin>>x[i];
    ll ans=1e18,pos=-1;
    for(int i=1;i<=100;i++)
    {
        ll res=0;
        for(int j=0;j<n;j++)
        {
            res+=(x[j]-i)*(x[j]-i);
        }
        if(res<ans)
        {
            ans=res;
            pos=i;
        }
    }
    cout<<ans<<"\n";
  return 0;
 }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
  int N;
  cin>>N;
  int count=0;
  long int mn=10000000000;
  vector<long int> A;
  for(int i=0; i<N; ++i){
    long int a;
    cin>>a;
    if(a<0) count++;
    if(mn>abs(a)) mn=abs(a);
    A.push_back(abs(a));
  }
  
  long int ans=0;
  for(int i=0; i<N; ++i){
    ans+=A[i];
  }
  if(count%2==1) ans-=mn*2;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 1400
W,H,N=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(N):
  s=input().split()
  x.append(int(s[0]))
  y.append(int(s[1]))
  a.append(int(s[2]))
w=[0,W,0,H]
for i in range(N):
  if a[i]==1:
    w[0]=max(w[0],x[i])
  elif a[i]==2:
    w[1]=min(w[1],x[i])
  elif a[i]==3:
    w[2]=max(w[2],y[i])
  else:
    w[3]=min(w[3],y[i])
if w[1]-w[0]<=0 or w[3]-w[2]<=0:
  S=0
else:
  S=(w[1]-w[0])*(w[3]-w[2])
print(S)

Measured memory_bytes: 3064
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
      var n = readLine.split(" ").map(_.toInt)
      while( n(0) != 0 || n(1) != 0) {
        (1 to n(0)).foreach(s=>println("#"*n(1)))
        println("")
        n = readLine.split(" ").map(_.toInt)
      }
  }
}

Measured memory_bytes: 45088
n,m = map(int, input().split())
set_a = set()
set_b = set()
AB = [list(int(x) for x in input().split()) for _ in range(m)]


for a,b in AB:
  if a > b:
    a,b = b,a
  
  if a == 1:
    set_a.add(b)
  if b == n:
    set_b.add(a)

se = set_a & set_b
print('POSSIBLE' if se else 'IMPOSSIBLE')

Measured memory_bytes: 58880
#include <cstdio>
#include <cmath>
#include <iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{

	long long a, b, c,d;
	cin >> a >> b >> c >> d;
	if (a>=d)
	{
		cout << d << endl;
		return 0;
	}
	else if (a + b >= d)
	{
		cout << a << endl;
		return 0;
	}
	else
	{
		cout << a - (d - a - b) << endl;
		return 0;
	}
}

Measured memory_bytes: 3636
import sys, math
from collections import defaultdict, deque, Counter
#from bisect import bisect_left, bisect_right
#from itertools import combinations, permutations, product
#from heapq import heappush, heappop
#from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W, M = rl()
B = set()
for i in range(M):
	h, w = rl()
	B.add((h-1, w-1))

ch = defaultdict(int)
cw = defaultdict(int)
for h, w in B:
	ch[h] += 1
	cw[w] += 1

mh = max(ch.values())
mw = max(cw.values())

his = []
for k, v in ch.items():
	if v != mh: continue
	his.append(k)

wis = []
for k, v in cw.items():
	if v != mw: continue
	wis.append(k)

ans = mh + mw
for i in his:
	for j in wis:
		if (i, j) not in B:
			print(ans)
			exit()
print(ans-1)



Measured memory_bytes: 225160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <numeric>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

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

bool solve(ll A, ll B, ll C, ll D) {
	if (A < B || B > D) return false;
	if (B - 1 <= C) return true;
	ll G = gcd(B, D);
	A = (A - B) % G;
	if (A > C) return false;
	ll k = (C - A) / G + 1;
	ll X = A + k * G;
	return X >= B;
}

int main() {
	int T; cin >> T;
	rep(i, T) {
		ll A, B, C, D;
		cin >> A >> B >> C >> D;
		cout << (solve(A, B, C, D) ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N ,X, Y = map(int, input().split()) 

rlt = [0]*N

for i in range(1,N+1):
  for j in range(i+1,N+1):
    if (i < X and j < X) or (i > Y and j > Y):
      rlt[j-i] += 1
    elif i < X and j > Y:
      rlt[X-i+j-Y+1] += 1
    elif i < X and j <= Y:
      rlt[min(j-i,X-i+1+Y-j)] += 1
    elif i >= X and j > Y:
      rlt[min(j-i,i-X+1+j-Y)] += 1
    elif i >= X and j <= Y:
      rlt[min(j-i,i-X+Y-j+1)] += 1
      
for i in rlt[1:]:
  print(i)

Measured memory_bytes: 75252
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int n;
    int h[110];
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        if (h[i] < h[i - 1] && i > 0)
            ans = ans + h[i - 1] - h[i];
    }
    ans += h[n - 1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct point {
	int x;
	int y;
};
list<point> l;
int main()
{
	int n, k;
	cin >> n >> k;
	if ((n - 2)*(n - 1) / 2 < k)
	{
		cout << -1;
		return 0;
	}
	else
	{
		int t = (n - 2)*(n - 1) / 2;
		for (int i = 2; i <= n; i++)
			l.push_back({ 1,i });
		for (int i = 2; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				if (t == k)
					break;
				l.push_back({ i,j });
				t--;
			}
		}
	}
	cout << l.size() << endl;
	for (point p : l)
	{
		cout << p.x << " " << p.y << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

long long dpup1[100004];
long long dpdown1[100004];
long long dpup2[100004];
long long dpdown2[100004];

int main(){
  int N;
  long long C;
  scanf("%d", &N);
  scanf("%lld", &C);
  std::vector<long long > x(N), v(N);
  for (int i=0; i<N; i++){
    scanf("%lld", &x[i]);
    scanf("%lld", &v[i]);
  }
  long long vsum = 0;
  for (int i=0; i<N; i++){
    dpup1[i+1]=std::max(dpup1[i], vsum+v[i]-x[i]);
    dpup2[i+1]=std::max(dpup2[i], vsum+v[i]-2*x[i]);
    vsum+=v[i];
  }
  vsum = 0;
  for (int i=N-1; i>=0; i--){
    dpdown1[i]=std::max(dpdown1[i+1], vsum+v[i]-(C-x[i]));
    dpdown2[i]=std::max(dpdown2[i+1], vsum+v[i]-2*(C-x[i]));
    vsum+=v[i];
  }

  long long ans = 0;
  ans = std::max(ans, dpup1[N]);
  ans = std::max(ans, dpdown1[N]);

  for (int i=0; i<N; i++){
    ans = std::max(ans, dpup1[i]+dpdown2[i]);
    ans = std::max(ans, dpdown1[i]+dpup2[i]);
  }
  
  std::cout << ans << std::endl;
  return 0;
}
 

Measured memory_bytes: 7588
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] k = new int[n][m];
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            for (int j = 0 ; j < a[i] ; j++) {
                int x = sc.nextInt() - 1;
                k[i][x]++;
            }
        }
        int ans = 0;
        for (int j = 0 ; j < m ;j++) {
            int c = 0;
            for (int i = 0 ; i < n ; i++) {
                if (k[i][j] == 1) {
                    c++;
                }
            }
            if (c == n) {
                ans++;
            }
        }


        System.out.println(ans);
    }

}


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

int n,w,we[104],v[104],dp[100004];

int main() {
    scanf("%d%d",&n,&w);
    for(int i=0;i<n;++i)    scanf("%d%d",we+i,v+i);
    memset(dp,62,sizeof(dp));//set to greater than 10^9
    dp[0] = 0;
    int ret = 0;
    for(int i=0;i<n;++i)
        for(int j=100000;j>=v[i];--j)
            if(dp[j-v[i]]+we[i]<=w) {
                dp[j] = min(dp[j],dp[j-v[i]]+we[i]);
                ret = max(ret,j);
            }

    printf("%d",ret);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
const int N=100005;
using namespace std;
string s[N];
int n;
int main(){
	
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i],sort(s[i].begin(),s[i].end());
	sort(s+1,s+n+1);
	long long ans=0,times=1;
	/*for(int i=1;i<=n;i++)
		cout<<s[i]<<endl;*/
	for(int i=2;i<=n+1;i++)
		if(s[i]==s[i-1])times++;
		else ans+= times*(times-1)/2,times=1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7296
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	int a,b;
	cin>>a>>b;
	int arr[a+1],s=0;
	for(int i=1;i<=a;++i){
		arr[i]=i+b-1;
		s+=arr[i];
	}
	int res=1e9,ans=0;
	for(int i=1;i<=a;++i){
		int sum=0;
		for(int j=1;j<=a;++j){
			if(i==j)continue;
			sum+=arr[j];
		}
		if(abs(sum-s)<res){
			res=abs(sum-s);
			ans=sum;
		}
	}
	cout<<ans;

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(var,start,stop,step) for(long long var=start;var<stop;var+=step)
#define vi vector<int>
#define vl vector<long long>
#define fio  cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr);
 
int main()
{
    fio;
    ll n,k;cin>>n>>k;
    vi v(n);
    loop(i,0,n,1)
        cin>>v[i];
    sort(v.begin(),v.end());
    ll sum=0;
    loop(i,0,k,1)
        sum+=v[i];
    cout<<sum<<endl;
    return 0;
}

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

using ll = long long int;
using P = std::pair<int, int>;

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

constexpr ll mod = 1e9 + 7;

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num + rhs.num + mod) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return num = (num + rhs.num) % mod;
    }

    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

int main()
{
    int n;

    std::cin >> n;

    std::vector<ll> vec;

    rep(i, n)
    {
        int a;
        std::cin >> a;
        vec.push_back(a);
    }

    if (n == 1)
    {
        std::cout << vec[0] * 2 % mod << std::endl;
        return 0;
    }

    std::sort(std::begin(vec), std::end(vec));

    mint p = 1;

    rep(i, 2 * n - 2)
    {
        p = (mint)2 * p;
    }

    mint ans = 0;

    rep(i, n)
    {
        ans += (mint)vec[i] * (n - i + 1);
    }

    ans = p * ans;

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

    return 0;
}

Measured memory_bytes: 5300
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
ll dp[100010][13];
ll mod = 1e9 + 7;
int main()
{
    dp[0][0] = 1;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int norm = 1;
    rep(i, s.length())
    {
        if (i == 0)
        {
            norm = 1;
        }
        else
        {
            norm *= 10;
            norm %= 13;
        }
        if (s[i] == '?')
        {
            //13*13
            rep(j, 10)
            {
                int x = (norm * j) % 13;
                rep(k, 13)
                {
                    dp[i + 1][(k + x) % 13] += dp[i][k];
                    dp[i + 1][(k + x) % 13] %= mod;
                }
            }
        }
        else
        {
            int x = (norm * (s[i] - '0'));
            x %= 13;
            rep(j, 13)
            {
                dp[i + 1][(j + x) % 13] += dp[i][j];
            }
        }
    }
    cout << dp[s.length()][5] << endl;
}

Measured memory_bytes: 10624
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll asum,bsum,sum;
int main(){
	int n;
	cin>>n;
	ll a[n];
	for(ll i =0; i < n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	double ans=(a[0]+a[1])/2.0;
	for(int i = 2; i < n; i++){
		ans += a[i];
		ans /= 2.0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=15;

int n,want;
int x[MAXN];

void run() {
	scanf("%d%d",&n,&want); REP(i,n) scanf("%d",&x[i]);
	ll ret=LLONG_MAX;
	REP(i,1<<n) {
		int cnt=0; REP(j,n) if(i&(1<<j)) ++cnt; if(cnt<want) continue;
		ll cur=0; int mx=0;
		REP(j,n) {
			if(i&(1<<j)) {
				if(x[j]<=mx) {
					cur+=mx+1-x[j];
					++mx;
				} else {
					mx=x[j];
				}
			} else {
				mx=max(x[j],mx);
			}
		}
		if(cur<ret) ret=cur;
	}
	printf("%lld\n",ret);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 1000005

ll a[ma];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,k,i,j,x,y,z;
    while(cin>>n>>k)
    {
       for(i=1;i<=n;i++)cin>>a[i];
       for(i=k+1;i<=n;i++)
       {
           if(a[i]>a[i-k])cout<<"Yes"<<endl;
           else cout<<"No"<<endl;
       }
    }
    return 0;
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  ll k;
  cin >> s >> k;
  set<string> st;
  ll n = SZ(s);
  if (n <= 100) {
    REP(i, n) FOR(j, 1, n + 1) if (i + j - 1 < n) { st.insert(s.substr(i, j)); }
  } else {
    REP(i, n) FOR(j, 1, k + 1) if (i + j - 1 < n) { st.insert(s.substr(i, j)); }
  }
  // DUMP(SZ(st));
  auto it = next(st.begin(), k - 1);
  cout << *it << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){

    cin.tie( nullptr );
    ios_base::sync_with_stdio(0);

    int n; cin >> n;

    vector<ll> v(n+1, 0);
    for(int i=1; i<=n; i++)
        cin >> v[i], v[i]+=v[i-1];

    vector< vector<ll> > dp;
    dp.assign(n+1, vector<ll>(n+1,1e16));

    for(int i=1; i<=n; i++) dp[i][i] = 0;
    for(int i=1, j=2; j<=n; i++, j++) dp[i][j] = v[j] - v[i-1];

    for(int len=3; len<=n; len++)
    for(int i=1, j=len; j<=n; i++, j++){
        ll tot = v[j] - v[i-1];
        for(int k=i; k<j; k++)
            dp[i][j] = min(dp[i][j], tot+dp[i][k]+dp[k+1][j]);
    }
    cout << dp[1][n] << "\n";

//    for(int i=1; i<=n; i++)
//    for(int j=1; j<=n; j++)
//        cout << dp[i][j] << " \n"[j==n];

    return 0;
}


Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+10;
const int MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
const ll inf = 1e9+10;
 
 

int n;
vector<int> solve(const string &s)
{
	int m = s.size();
	vector<int> a(m);
	int j = 1;
	int k;
	a[0] = m;
	for(int i=1;i<m;i=k)
	{
		if(j<i)
			j = i;
		while(j<m && s[j] == s[j-i])
		{
			j++;
		}
		a[i] = j-i;
		k = i+1;
		while(k+a[k-i]<j)
		{
			a[k] = a[k-i];
			k++;
		}
	}
	return a;
}
int main() {
	scanf("%d",&n);
	string t;
	cin>>t;
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		vector<int> z = solve(t.substr(i));
		int m = z.size();
		for(int j=0;j<m;j++)
		{
			if(z[j] <= j)
			{
				ans = max(min(z[j],j),ans);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    string A, B, C;
    cin >> A >> B >> C;
    
    int sa = A.size();
    int sb = B.size();
    
    if (A[sa - 1] == B[0] && B[sb - 1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

hq = []
for i in range(m-1):
    heapq.heappush(hq, x[i+1] - x[i])


move = 0

for i in range(m-n):
    move += heapq.heappop(hq)

print(move)


Measured memory_bytes: 13960
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  int size = s.size();
  int ans = size;
  for (int i = 1; i < size; i++) {
    if (s[i] == s[i-1]) continue;

    ans = min(ans, max(i, size - i));
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int INF = 1e9 + 7;

void solve() {
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    loop(i, n)
        cin >> a[i];
    int l = 0, r = INF;
    while (r - l > 1) {
        int m = l + r >> 1, calc = 0;
        loop(i, n)
            calc += (a[i] - 1) / m;
        if (calc > k)
            l = m;
        else
            r = m;
    }
    cout << r;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define rep(i,n) for(int i=0;i<n;i++)
#define geti(...) int __VA_ARGS__;bulk(__VA_ARGS__)
using vi=vector<int>;
int main(void){
    int m,n;
    while(cin>>m>>n,m){
        vector<vi> mp(21,vi(2,0));
        rep(i,m){
            geti(p);
            mp[p][0]+=p;
        }
        rep(i,n){
            geti(p);
            mp[p][1]+=p;
        }
        int ans=0;
        rep(i,21)
            ans+=max(mp[i][0],mp[i][1]);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

n = int(input())

x, y = map(int, input().split())
for i in range(n-1):
    a, b = map(int, input().split())
    k = max((x-1)//a+1, (y-1)//b+1)
    x, y = k * a, k * b
print(x+y)


Measured memory_bytes: 12736
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long f[100];
long long ff(int i){
	if(f[i]!=0) return f[i];
	else return f[i]=ff(i-1)+ff(i-2);
}
int main(){
	int n;
	cin>>n;
	f[0]=2;
	f[1]=1;
	cout<<ff(n);
	return 0;
}

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

int main(){
    int n,m,a,b;
    unsigned long long ans=0LL;
    cin>>n>>m;
    vector<vector<int> > vec(m+1, vector<int>(0) );
    priority_queue<int> qu;
    for(int i=0; i<n; i++){
        cin>>a>>b;
        if(a<=m)
            vec[a].emplace_back(b);
    }
    for(int i=1;i<=m;i++){
        for(int j=0;j<vec[i].size();j++){
            qu.push(vec[i][j]);
        }
        if(!qu.empty()){
            ans+=1LL*qu.top();
            qu.pop();
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 5504
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;

int t,n,m,k,ans=0,cnt=0;
char a[N]={0};
int b[N]={0};
int main(){
    scanf("%s",a+1);
    int len=strlen(a+1);
    for(int i=1;i<=len;i++) b[i]=a[i]-'0';
    for(int i=len;i>=0;i--){
        int sum=b[i];
        int pre=b[i-1];
        if(sum<5){
            ans+=sum;
        }else if(sum>5){
            ans+=10-sum;
            b[i-1]++;
        }else if(pre>=5){
            ans+=10-sum;
            b[i-1]++;
        }else{
            ans+=sum;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    
    for(int i=1;i<10;i++){
        if(n<=i*100+i*10+i){
            cout<<i*100+i*10+i<<endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main()
{
    int W, H, x, y, r;
    std::cin >> W >> H >> x >> y >> r;

    if ((x - r) < 0 || W < (x + r)) {
        std::cout << "No" << std::endl;
    } else if ((y - r) < 0 || H < (y + r)) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

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

    int a, b, c;
    cin >> a >> b >> c;
    bool flag;
    if (a < b) {
        if (a < c && c < b) {
            flag = true;
        } else {
            flag = false;
        }
    }
    if (a > b) {
        if (a > c && c > b) {
            flag = true;
        } else {
            flag = false;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

struct Trie {
  Trie *children[2];
  Trie() {
    fill(children, children+2, nullptr);
  }
  void add(const string &s) {
    Trie *cur = this;
    for (char ch : s) {
      int d = ch - '0';
      if (!cur->children[d]) {
        cur->children[d] = new Trie();
      }
      cur = cur->children[d];
    }
  }
};

long long dfs(Trie *r, int lv, long long L) {
  if (lv == L) {
    return 0;
  }
  if (!r->children[0] && !r->children[1]) {
    return 0;
  }
  long long Xor = 0;
  for (int d = 0; d < 2; d++) {
    if (r->children[d]) {
      Xor ^= dfs(r->children[d], lv + 1, L);
    } else {
      long long h = L - (lv + 1);
      int p = 0;
      while (h % 2) {
        p++;
        h /= 2;
      }
      Xor ^= (1LL << p);
    }
  }
  return Xor;
}

const int N = int(1e5);
char s[N+1];

int main(void) {
  int n; long long L;
  scanf("%i %lld", &n, &L);
  
  Trie *tree = new Trie();
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    tree->add(string(s));
  }
  
  puts(dfs(tree, 0, L) ? "Alice" : "Bob");
  
  return 0;
}

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

using namespace std;

int n;
vector<vector<pair<int, int>>> g;
vector<int> sz;
long long sum;

void dfs(int v, int p) {
	sz[v] = 1;
	for (auto e : g[v]) {
		int to = e.first;
		if (to != p) {
			dfs(to, v);
			sz[v] += sz[to];
		}
	}
}

int get_cent(int v, int p) {
	for (auto e : g[v]) {
		int to = e.first;
		if (to != p && 2 * sz[to] > n) {
			return get_cent(to, v);
		}
	}
	return v;
}

int get_cent1(int v, int p) {
	for (auto e : g[v]) {
		int to = e.first;
		if (to != p && 2 * sz[to] >= n) {
			return get_cent1(to, v);
		}
	}
	return v;
}

void dfs_cent(int v, int p, long long dep) {
	sum += dep;
	for (auto e : g[v]) {
		int to = e.first;
		int w = e.second;
		if (to != p) {
			dfs_cent(to, v, dep + w);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}
	sz.resize(n);
	dfs(0, -1);
	int c1 = get_cent(0, -1);
	int c2 = get_cent1(0, -1);
	dfs_cent(c1, c2, 0);
	dfs_cent(c2, c1, 0);
	if (c1 == c2) {
		int lo = 1e9;
		for (auto e : g[c1]) {
			lo = min(lo, e.second);
		}
		sum -= lo;
	}
	else {
		int mid;
		for (auto e : g[c1]) {
			if (e.first == c2) {
				mid = e.second;
			}
		}
		sum *= 2;
		sum += (n - 1LL) * mid;
	}
	cout << sum;
}


Measured memory_bytes: 11520
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1LL << 50
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {

	int n, m;
	ll from[2000], to[2000], cost[2000];
	ll d[1000];
	bool negative[1000];

	cin >> n >> m;

	rep(i, m) {
		cin >> from[i] >> to[i] >> cost[i];
		from[i]--; to[i]--;
		cost[i] = -cost[i];
	}

	rep(i, n) {
		d[i] = INF;
		negative[i] = false;
	}

	d[0] = 0;

	for (int j = 0; j < n-1; j++) {
		for (int i = 0; i < m; i++) {
			if (d[from[i]] != INF && d[to[i]] > d[from[i]] + cost[i]) {
				d[to[i]] = d[from[i]] + cost[i];
			}
		}
	}

	ll ans = d[n - 1];

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < m; i++) {
			if (d[from[i]] != INF && d[to[i]] > d[from[i]] + cost[i]) {
				d[to[i]] = d[from[i]] + cost[i];
				negative[to[i]] = true;
			}
			if (negative[from[i]])negative[to[i]] = true;
		}
	}

	if (negative[n - 1]) {
		cout << "inf" << endl;
	}
	else {
		cout << -ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
/****** HAREE KRISHNA   ******/

//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<climits>

using namespace std;

typedef long long int lld;
typedef double lf;
typedef unsigned long long int llu;
typedef char C;

#define sf scanf
#define pf printf
#define ff first
#define ss second
#define PI acos(-1.0)
#define sq(x) (x)*(x)
#define nn printf("\n")
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define TEST int test,zz;scanf("%d",&zz);getchar();for(test=1;test<=zz;test++)

#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d %d",&x,&y)
#define sci3(x,y,z) scanf("%d %d %d",&x,&y,&z)

#define pfi(x) printf("%d\n",x)
#define pfi2(x,y) printf("%d %d\n",x,y)
#define pfi3(x,y,z) printf("%d %d %d\n",x,y,z)

#define scs(str) scanf("%s",str)

#define pfs(str) printf("%s\n",str)

#define pb push_back

// ASCII Vlaue
// A=65,Z=90,a=97,z=122,0=48,9=57

#define chk1 printf("chek1\n")
#define chk2 printf("chek2\n")
#define chk3 printf("chek3\n")
#define sz1 1005
#define sz 5

/******   start your code   *******/
lld arr[sz];
lld pr[sz];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    bool key;
    C ch1,ch2,ch;
    lld i,j,n,m,a,b,c,k;
    //TEST // "test" as variable
    //while(1)
    key=true;
    for(i=0; i<3; i++) sf("%lld",&arr[i]);
    sort(arr,arr+3);
    for(i=0; i<3; i++)
        if((arr[i]&1)==0)
        {
            key=false;
            pfi(0);
            break;
        }
    if(key)
    {
        lld res=(arr[0]*arr[1]);
        res-=(arr[0]*(arr[1]-1));
        pr[0]=arr[2]*res;

        res=(arr[1]*arr[2]);
        res-=(arr[1]*(arr[2]-1));
        pr[1]=arr[0]*res;

        res=(arr[0]*arr[2]);
        res-=(arr[0]*(arr[2]-1));
        pr[2]=arr[1]*res;
        sort(pr,pr+3);
        pf("%lld\n",pr[0]);
    }
    return 0;
}

/*
input:

output:

*/


Measured memory_bytes: 256
from collections import defaultdict
import heapq


def main():
    N, M = map(int, input().split())
    E_in = [list(map(int, input().split())) for _ in range(M)]
    S, T = map(int, input().split())

    N2 = N * 2
    # 1-indexed
    V = [0] + [i for i in range(3*N+1)]
    E = defaultdict(dict)
    for e in E_in:
        u = e[0]
        v = e[1]
        E[u][v+N] = 1
        E[u+N][v+N2] = 1
        E[u+N2][v] = 1
    
    INF = 10 ** 18

    def calc_distance(V, E, S):
        d = [INF] * len(V)
        d[S] = 0
        h = []
        heapq.heappush(h, (0, S))
        while h:
            du, u = heapq.heappop(h)
            for v, x in E[u].items():
                if du + x < d[v]:
                    d[v] = du + x
                    heapq.heappush(h, (d[v], v))
        return d
    

    d = calc_distance(V, E, S)
    if d[T] == INF:
        print(-1)
    else:
        print(d[T] // 3)


main()

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

typedef long long ll;
using namespace std;
int main()
{
  ll a,b,c;
  cin>>a>>b>>c;
  reps(i,b+1){
    if((a*i)%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
string longestRepeatedSubstring(string str) 
{ 
    int n = str.length(); 
    int LCSRe[n+1][n+1]; 
  
    memset(LCSRe, 0, sizeof(LCSRe)); 
  
    string res;
    int res_length  = 0;
    int i, index = 0; 
    for (i=1; i<=n; i++) 
    { 
        for (int j=i+1; j<=n; j++) 
        {  
            if (str[i-1] == str[j-1] && 
                LCSRe[i-1][j-1] < (j - i)) 
            { 
                LCSRe[i][j] = LCSRe[i-1][j-1] + 1; 
  
                if (LCSRe[i][j] > res_length) 
                { 
                    res_length = LCSRe[i][j]; 
                    index = max(i, index); 
                } 
            } 
            else
                LCSRe[i][j] = 0; 
        } 
    } 
    if (res_length > 0) 
        for (i = index - res_length + 1; i <= index; i++) 
            res.push_back(str[i-1]); 
  
    return res; 
} 
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,i;
	string s;
	cin>>n>>s;
	string s1=longestRepeatedSubstring(s);
	cout<<s1.length()<<endl;
}

Measured memory_bytes: 195712
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n, d, x;
  scanf("%d%d%d", &n, &d, &x);
  while(n--) {
    int k;
    scanf("%d", &k);
    for(int a = 1; a <= d; a += k) {
      x++;
    }
  }
  printf("%d\n", x);
}


Measured memory_bytes: 256