akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

typedef long long int ll;

std::vector<ll> enum_div(ll n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;

//自作関数一覧---------------------------
ll gcd(ll a, ll b); //最小公倍数の導出
ll lcm(ll x, ll y); //最大公約数の導出
ll bur(ll N, ll X); //??
//---------------------------------------

//UF木
class UnionFind {
public:
	//親
	vector<int> Parent;

	//初期状態
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//サイズ確認
	int size(int A) {
		return -Parent[root(A)];
	}

	int connect(int A, int B) {
		//root同氏をくっつける
		A = root(A);
		B = root(B);

		//結合済み
		if (A == B) {
			return false;
		}
		//大きいほうに小さいほうをくっつける
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズ更新
		Parent[A] += Parent[B];
		//Bの親をAに
		Parent[B] = A;

		return true;
	}

};

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;


	string S, T;
	char fi[50], fv[50];
	char board[4][4];
	bool start = false;
	ll left = 0, right = 0;
	ll all = 0;
	
	cin >> N;
	vector<ll> mo(N);

	rep(i, 0, N) {
		cin >> mo[i];
	}

	rep(j, 0, N) {
		rep(i, j+1, N) {
			all += mo[i] * mo[j];
		}
	}
	cout << all << endl;

	return 0;
}


std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> res;
	for (int i = 1; i*i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}








bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}



//combination
long long comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v[n][r];
}


ll gcd(ll a, ll b) {

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y / b*x;
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
	if (x == 0 || y == 0)  // 引数チェック
	{
		//fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	return (x * y / gcd(x, y));
}

ll bur(ll N, ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

Measured memory_bytes: 256
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 23:15:00 2019
//
package main

import (
	"fmt"
	"sort"
)

func min(slice ...int) int {
	sort.Ints(slice)
	return slice[0]
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)

	for i := range arr {
		fmt.Scan(&arr[i])
	}

	dp := make([]int, N)
	for i := range arr {
		if i > 1 {
			dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]))
		} else if i > 0 {
			dp[i] = dp[i-1] + abs(arr[i]-arr[i-1])
		}
	}

	fmt.Println(dp[N-1])
}


Measured memory_bytes: 5504
n,k= map(int,input().split())
p = list(map(int,input().split()))

s = [1+0.5*(i-1) for i in range(1,max(p)+1)]

q = [0]
c = 0
for i in p:
    c += s[i-1]
    q.append(c)

ma = 0
for i in range(k,n+1):
    ans = q[i]-q[i-k]
    if(ma<ans):
        ma = ans
    
print(ma)

Measured memory_bytes: 76040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


static const int MAX_S = 2000;
VB visited(MAX_S + 1, false);
VLL num(MAX_S + 1, 0);

ll f(ll a) {
    if (a == 0) return 1;
    if (a < 3) return 0;

    if (visited[a]) return num[a];

    ll res = 0;
    FOR(x, 3, a + 1) {
        res = (res + f(a - x)) % MOD;
    }
    visited[a] = true;
    return num[a] = res;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    ll S; cin >> S;

    ll ans = f(S);
    cout << ans << '\n';

    return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define fastio    ios::sync_with_stdio(0); cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  fastio;
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int x, n;
  cin >> x >> n;
  vector<bool> a(102);
  rep(i, n) {
    int x;
    cin >> x;
    a[x] = true;
  }

  rep(i, 51) {
    if (!a[x - i]) {
      cout << x - i;
      break;
    }

    if (!a[x + i]) {
      cout << x + i;
      break;
    }
  }

  return 0;
}


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

using namespace std;

int main()
{
  int cnt=0;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++)
    if(s[i]=='g')
      cnt++;
    else
      cnt--;
  cout<<cnt/2<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define sp  set< pair<ll,ll> >
#define vp vector< pair<ll,ll> >
#define spp set< pair<pair<ll,ll>,ll> >
#define maxe 100000000
#define MOD 1000000007
#define ll long long int
#define pb push_back
#define mp  make_pair
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef map<int,int> MPII;
typedef set<int> SETI;
#define ps fixed<<setprecision(y)<<x;
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define REP(i,n) FOR(i,0,(int)n-1)
#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACH_FN(v, fn) for_each(ALL(v), myobject);

#define SORT(a) sort(a.begin(),a.end())
#define RSORT(a) sort(a.rbegin(),a.rend())
#define REV(a) reverse(a.begin(),a.end())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MINIMUM(a)	*min_element(a.begin(), a.end())
#define MAXIMUM(a)	*max_element(a.begin(), a.end())

#define ld long double
#define bigint int64_t
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define hurry ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))
const int N =1e+5;
int main()
{
hurry;
int a,b,c,five=0,sev=0;
cin>>a>>b>>c;
if(a==5 )
five++;
else if(a==7)
sev++;
if(b==5 )
five++;
else if(b==7)
sev++;
if(c==5 )
five++;
else if(c==7)
sev++;
if(five==2 && sev==1)
cout<<"YES"<<'\n';
else
cout<<"NO"<<'\n';




}


Measured memory_bytes: 3572
import math
lst=input().split()
lst=list(map(lambda i:int(i),lst))
a,b,C=lst[0],lst[1],lst[2]
S=(1/2)*a*b*math.sin(math.radians(C))
h=(2/a)*S
c=(a**2+b**2-2*a*b*math.cos(math.radians(C)))**(1/2)
L=a+b+c
print(S)
print(L)
print(h)



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> a>>b>>c>>pos;
       if(a+b>c+pos){
           Cout("Left");
       }
       else if(a+b==c+pos){
           Cout("Balanced");
       }
       else{
           Cout("Right");
       }
       
return 0;
}


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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int x, t; cin >> x >> t;
        cout << max(0, x - t);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0 ;i < N;i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  vec.at(0) = vec.at(0) / 2;
  int answer = 0;
  for(int j = 0;j < N;j++) {
    answer += vec.at(j);
  }
  cout << answer << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
void solve(){
    string s;
    cin>>s;
    int x = 0;
    for(char c:s){
        x+=(int)(c-'0');
        x%=9;
    }
    if(x==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3744
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

x, y = map(int, input().split())

if x in a:
    flagx = 0
if x in b:
    flagx = 1
if x in c:
    flagx = 2
if y in a:
    flagy = 0
if y in b:
    flagy = 1
if y in c:
    flagy = 2
if flagx == flagy:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&h[i])
	}
	ans := "Yes"
	for i:=n-2; i>0; i-- {
		if h[i]-h[i+1]==1 {
			h[i]--
		} else if h[i]-h[i+1]>1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5504
#include <cstdio>
#include <cstring>

using namespace std;

#define MOD 998244353

int a, b, c, d;

long long dp[3005][3005];

int main() {
	scanf("%d%d%d%d", &a, &b, &c, &d);
	dp[a][b] = 1;
	for (int i = a; i <= c; i++) for (int j = b; j <= d; j++) {
		if (i != a) dp[i][j] = (dp[i - 1][j] * j) % MOD;
		if (j != b) dp[i][j] += (dp[i][j - 1] * i) % MOD;
		dp[i][j] = (dp[i][j] + MOD) % MOD;
		if (i != a && j != b) dp[i][j] -= (dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD;
		dp[i][j] = (dp[i][j] + MOD) % MOD;
	}
	printf("%lld\n", dp[c][d]);
	return 0;
}


Measured memory_bytes: 72144
from itertools import groupby

def sgn(num):
    if num>0:
        return 1
    elif num==0:
        return 0
    else:
        return -1

N=int(input())
h=list(map(int,input().split()))
ans=0
for i in range(1,101):
    sublist=[sgn(h[j]) for j in range(0,N)]
    sublist=groupby(sublist)
    for key,group in sublist:
        if key==1:
            ans+=1
    h=[h[j]-1 for j in range(0,N)]
print(ans)

Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

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

bool grid[1000][1000];
ll dp[1000][1000];
int h, w;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string str;
		cin >> str;
		for (int j = 0; j < w; j++) grid[i][j] = (str[j] == '.');
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i == 0 && j == 0) {
				dp[i][j] = 1;
				continue;
			}
			if (!grid[i][j]) continue;
			if (i > 0) 
				dp[i][j] += dp[i - 1][j];
			if (j > 0) 
				dp[i][j] += dp[i][j - 1];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

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

int main(){
  int N,D;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>X.at(i).at(j);
    }
  }

  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int distance=0;
      for(int k=0;k<D;k++){
        distance+=(X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
      }
      for(int l=1;l<=200;l++){
        if(distance==l*l){
          ans++;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>

template <class T>
void print(T& v) {
    std::for_each(v.begin(), v.end(), [](auto el) { std::cout << el << " "; });
    std::cout << std::endl;
}

int main() {
    long long n;
    std::cin >> n;
    std::vector<long long> a(3 * n);
    for (auto i = 0ll; i < 3 * n; i++) std::cin >> a[i];

    std::multiset<long long> fst(a.begin(), a.begin() + n), snd(a.begin() + n, a.end());
    std::multiset<long long> fsnd(snd.begin(), std::next(snd.begin(), n)), lsnd(std::next(snd.begin(), n), snd.end());

    long long sfst = std::accumulate(fst.begin(), fst.end(), 0ll);
    long long ssnd = std::accumulate(fsnd.begin(), fsnd.end(), 0ll);
    long long ret = sfst - ssnd;

    for (auto i = 0ll; i < n; i++) {
        fst.insert(a[n + i]);
        sfst = sfst + a[n + i] - *fst.begin();
        fst.erase(fst.begin());

        auto it = fsnd.find(a[n + i]);
        if (it != fsnd.end()) {
            ssnd = ssnd - *it + *lsnd.begin();
            fsnd.erase(it);
            fsnd.insert(*lsnd.begin());
            lsnd.erase(lsnd.begin());
        } else {
            lsnd.erase(lsnd.find(a[n + i]));
        }
        
        ret = std::max(ret, sfst - ssnd);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 25984
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    A = in_nl()

    now_max = A[0]
    ans = 0
    for i in range(1, N):
        if A[i] < now_max:
            ans += now_max - A[i]
        now_max = max(now_max, A[i])

    print(ans)


if __name__ == '__main__':
    main()


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll mod;
ll dp[600][300];

int main() {
	int N, M; cin >> N >> M;
	mod = M;

	vector<pii> vec;
	vi mx(N);

	for (int i = 0; i < N * 2; ++i) {
		if (i < N) {
			int p = 0;
			for (int x = 0; x < N * 2; ++x) {
				if (i * i + x * x < N * N) {
					p = x + 1;
				}
			}
			vec.eb(p, -i);
		}

		int q = 0;
		for (int y = 0; y < N * 2; ++y) {
			if (i * i + y * y <= N * N * 4) {
				q = y + 1;
			}
		}
		if (i < N) mx[i] = q;
		else vec.eb(q, -i);
	}

	sort(ALL(vec));

	int sz = vec.size();

	ll ans = 0;

	for (int ban = 0; ban <= N; ++ban) {
		memset(dp, 0, sizeof(dp));

		dp[0][0] = 1;
		int big = 0;

		rep(i, sz) {
			for (int j = 0; j <= min(i, ban); ++j) {
				if (dp[i][j] == 0) continue;
			//ng
				if (vec[i].se <= 0 && vec[i].se > -N) {
					dp[i+1][j+1] += dp[i][j] * max<ll>(0, vec[i].fi - big - j);
				}
			//ok
				if (vec[i].se <= -N) {	
					dp[i+1][j] += dp[i][j] * max<ll>(0, vec[i].fi - big - j);
				} else {
					dp[i+1][j] += dp[i][j] * max<ll>(0, mx[-vec[i].se] - (N + ban + (i - j - big)));
				}
				dp[i+1][j+1] %= mod;
				dp[i+1][j] %= mod;
			}
			if (vec[i].se <= -N) ++big;
		}

		ll way = dp[sz][ban];

		if (ban & 1) way = mod - way;
		ans = (ans + way) % mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1664
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef pair<int,P> PI;

set<PI> q;

int main() {
    int a,b,c;
    int d,e,f,t = 0;;
    scanf("%d%d%d",&a,&b,&c);
    d = min(a,min(b,c));
    f = max(a,max(b,c));
    e = 1LL * a + b + c - d - f;
    while(1) {
    if((a & 1) || (b & 1) || (c & 1)) {
            printf("%d\n",t);
            return 0;
        }
        d /= 2;
        e /= 2;
        f /= 2;
        a = d + e;
        b = d + f;
        c = e + f;
        d = min(a,min(b,c));
        f = max(a,max(b,c));
        e = 1LL * a + b + c - d - f;
        if(q.find(PI(d,P(e,f))) != q.end()) break;
        q.insert(PI(d,P(e,f)));
        t++;
    }
    printf("-1\n");
    return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 44
using namespace std;

int dp[MAXN][MAXN * 12][MAXN * 12];

struct chemical{
	int a , b , cost;
	chemical(int _a , int _b , int _c){
		a = _a;
		b = _b;
		cost = _c;
	}
};

inline void fill(){
	rep(i , MAXN){
		rep(j , MAXN * 12){
			rep(k , MAXN * 12){
				dp[i][j][k] = INF;
			}
		}
	}	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	int n , a , b;
	cin >> n >> a >> b;
	fill();
	vector<chemical> v;
	rep(i , n){
		int a , b , c;
		cin >> a >> b >> c;
		v.pb(chemical(a , b , c));
	}
	dp[0][0][0] = 0;
	rep(i , n){
		rep(j , MAXN * 12){
			rep(k , MAXN * 12){
				if(dp[i][j][k] != INF){
					dp[i + 1][j][k] = min(dp[i + 1][j][k] , dp[i][j][k]);
					dp[i + 1][j + v[i].a][k + v[i].b] = min(dp[i + 1][j + v[i].a][k + v[i].b] , dp[i][j][k] + v[i].cost);
				}
			}
		}
	}
	int ans = INF;
	rep(i , MAXN * 12){
		rep(j , MAXN * 12){
			if(i == 0 || j == 0)continue;
			if(b * i == a * j){
				ans = min(ans , dp[n][i][j]);
			}
		}
	}
	if(ans == INF)dier(-1);
	die(ans);
	return 0;
}

Measured memory_bytes: 48128
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

bool f(vector<int>& a, vector<int>& b) 
{
	long long s = 0;
	for (int i = 0; i < a.size(); ++i) {
		s += (b[i] - a[i]) * (b[i] - a[i]);
	}

	long long t = static_cast<long long>(sqrt(s));

	return (s == t * t) || (s == (t+1) * (t+1));
}

int main() 
{
	int n, d;
	cin >> n >> d;
	vector<vector<int>> xv(n, vector<int>(d));
	for (auto& i : xv) {
		for (auto& j : i) {
			cin >> j;
		}
	}

	int ret = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (f(xv[i], xv[j])) {
				++ret;
			}
		}
	}

	cout << ret << endl;
	system("pause");
	return 0;
}

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

int main() {
	int n, x;
	cin >> n >> x;
	int* d = new int[n + 1];
	d[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	int ans = 0;
	int sum = 0;
	for (int i = 0; i <= n; i++) {

		sum += d[i];
		if (sum <= x)ans++;
	
	}
	cout << ans << endl;
}

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

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

int main() {
  for(int a, b; cin >> a >> b; ) {
    int g = gcd(a,b);
    cout << g << " " << a / g * b << endl;
  }
}

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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long s[] = {0,0};
  vector< vector<int> > I(2);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    if(A[i] < 0)
      I[i%2].push_back(i+1);
    else
      s[i%2] += A[i];
  }
  if(*max_element(A.begin(), A.end()) < 0){
    int idx = max_element(A.begin(), A.end()) - A.begin();
    cout << A[idx] << endl << N-1 << endl;;
    ++idx;
    for(int i = N; i > idx; --i) cout << i << endl;
    for(int i = 1; i < idx; ++i) cout << 1 << endl;
    return 0;
  }
  int idx;
  if(s[0] < s[1]) idx = 1;
  else idx = 0;
  bool f = (idx == 1);
  cout << s[idx] << endl;
  vector<int> C;
  while(not I[idx].empty()){
    C.push_back(I[idx].back());
    if(I[idx].back() == N or I[idx].back() == 1) ++N;
    if(I[idx].back() == 1) f = !f;
    N -= 2;
    I[idx].pop_back();
  }
  if(f){
    C.push_back(1);
    --N;
  }
  while(N > 1){
    C.push_back(2);
    N -= 2;
  }
  cout << C.size() << endl;
  for(auto e : C) cout << e << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq

N = int(input())
es = [[] for _ in range(N)]
for i in range(N-1):
    a,b,c = map(int, input().split())
    es[a-1].append((c, b-1))
    es[b-1].append((c, a-1))

Q,K = map(int, input().split())
xy = [tuple(map(int, input().split())) for _ in range(Q)]

INF = float("inf")

dist = [INF] * N
dist[K-1] = 0
q = []
q.append((0,K-1))

while q:
    cost, curr = heapq.heappop(q)
    if cost > dist[curr]:
        continue

    for c, nxt in es[curr]:
        if dist[curr] + c < dist[nxt]:
            dist[nxt] = dist[curr] + c
            heapq.heappush(q, (dist[nxt], nxt))

for x,y in xy:
    print(dist[x-1] + dist[y-1])




Measured memory_bytes: 59768
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));


int main(){
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(10)<<sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
}


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

int main()
{
int A,B,C,D;

  cin >> A >> B >> C >> D ;
  
  while((A>0)&&(B>0)){
	C=C-B;
   if(C<=0){
    cout << "Yes" << endl;
     break;}
    
    A=A-D;
   if(A<=0){
    cout << "No" << endl;
     break;}

}

return 0;
}



Measured memory_bytes: 3632
'use strict';
process.stdin.on('data', function(chunk) {
 
  var inputs = chunk.toString().trim().split('\n');
  var cols = inputs.filter(function(v) {
    return v !== '0 0';
  })
  .map(function(v) {
    return v.split(' ')
          .map(Number)
          .sort(function(a ,b) {
            return a - b;
          })
          .join(' ');
  })
  .join('\n');
 
  console.log(cols);
 
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 18404
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/A-iai.py
#
c = input()
if c == "a" or c == "e" or c == "i" or c == "o" or c == "u":
    print("vowel")
else:
    print("consonant")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    if(n == 1){
        puts("1");
        return 0;
    }
    int ans = INF<int>;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i == j) continue;
            int dx = x[i]-x[j], dy = y[i]-y[j];
            vector<int> cnt(n);
            int a = 0;
            for (int k = 0; k < n; ++k) {
                for (int l = 0; l < n; ++l) {
                    if(k == l) continue;
                    if(x[l]-x[k] == dx && y[l]-y[k] == dy) cnt[l]++;
                }
            }
            for (int k = 0; k < n; ++k) {
                if(!cnt[k]) a++;
            }
            ans = min(ans, a);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
def main():
    N = int(input())
    S = list(input())
    MOD = 10 ** 9 + 7
    C = Counter(S)
    ans = 1
    for c in C.values():
        ans *= (c+1)
        ans %= MOD

    print(ans - 1)


    

if __name__ == "__main__":
    main()

Measured memory_bytes: 10172
k = gets.to_i
sum = 0

(1..k).each do |a|
  (a..k).each do |b|
    (b..k).each do |c|
      case
      when a == b && b == c
        sum += a
      when a == b
        sum += b.gcd(c) * 3
      when b == c
        sum += c.gcd(a) * 3
      when c == a
        sum += a.gcd(b) * 3
      else
        sum += a.gcd(b).gcd(c) * 6
      end
    end
  end
end

puts sum

Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int n;
ll x;
vector<ll> a, p;

ll f(int i, ll j) {
    if (i == 0) {
        return 1;
    }

    if (j == 1) return 0;
    if (j <= 1+a[i-1]) return f(i-1, j-1);
    if (j == 2+a[i-1]) return 1+p[i-1];
    if (j <= 2*a[i-1]+2) return 1+p[i-1]+f(i-1, j-a[i-1]-2);
    else return 1+2*p[i-1];

}

int main() {
    cin >> n >> x;
    a.resize(n+1); p.resize(n+1);
    a[0] = 1; p[0] = 1;
    rep(i, n) {
        a[i+1] = 2*a[i]+3;
        p[i+1] = 2*p[i]+1;
    }

    ll ans = f(n, x);

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
using namespace std;




int main() {
	long long int a,b,k;
	cin >> a >> b >> k;
	
	if( a >= k){
		cout << a-k << " " << b << endl;		
		return 0;
	}else{
		k = k-a;
		a = 0;
	}

	//cout << a << " " << b <<" " << k <<endl;

	if(b >= k){
		b -= k;
	}else{
		b = 0;
	}
	
	cout << a << " " << b << endl;
	
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class myheap
{
public:
    myheap() {}
    myheap(int size)
    : H(size), cbt(vs32(size + 1, 0))
    {}
    ~myheap() {}
    int parent(int i) { return i / 2; }
    int left(int i) { return 2 * i; }
    int right(int i) {return 2 * i + 1; }

    void maxHeapify(int i)
    {
        int l = left(i);
        int r = right(i);

        int largest;
        if (l <= H && cbt[l] > cbt[i])
        {
            largest = l;
        }
        else
        {
            largest = i;
        }

        if (r <= H && cbt[r] > cbt[largest])
        {
            largest = r;
        }

        if (largest != i)
        {
            swap(cbt[i], cbt[largest]);
            maxHeapify(largest);
        }
    }

    void buildMaxHeap()
    {
        for (int i = (H / 2); i >= 1; --i)
        {
            maxHeapify(i);
        }
    }

    int H;
    vs32 cbt;
};

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

    int n;
    cin >> n;

    myheap mheap(n);
    rep (i, n) cin >>  mheap.cbt[i + 1];
    mheap.buildMaxHeap();

    rep (i, n)
    {
        cout << " " << mheap.cbt[i + 1];
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 4576
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif

	int n;
	cin>>n;

	int arr[n];
	loop(i,0,n)
		cin>>arr[i];

	int dp[n] = {};

	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);

	loop(i,2,n)
		dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));

	cout<<dp[n-1],nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <sstream>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){

	int k,x;
	cin >> k >> x;
	if(k * 500 >= x) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
/* ex9_2
   YSK722 */

#include <stdio.h>
#include <stdlib.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if (new == NULL)
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char text[SIZE], top;
    int i = 0, count = 0;
    //最初のノードの指す先
    node *first = NULL;
    scanf("%s", text);
    while (text[i] != '\0'){
        // 最初にfirstに要素を追加
        if (first == NULL){
            push(&first, text[i]);
            i++;
            continue;
        }
        top = pop(&first);
        if (text[i] != top)
            // topが要素と等しくないとき、countに2を足す
            count += 2;
        else{
            //スタックにノードを追加
            push(&first, top);
            push(&first, text[i]);
        }
        i++;
    }
    printf("%d\n", count);
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') cnt1++;
        if(s[i]=='G') cnt2++;
        if(s[i]=='B') cnt3++;
    }

ans = cnt1 * cnt2 * cnt3;

for(int i = 1; i <= n; i++){
  for(int j = 0; j< n; j++){
    if(j - i < 0 || j + i >= n) continue;
    if(s[j] != s[j - i] && s[j] != s[j + i] && s[j + i] != s[j - i]) ans--;
  }
}
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

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

        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if(x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26388
# -*- coding: utf-8 -*-
n = input()
a = map(int,raw_input().split())

ave = int(0.5 + 1.0*sum(a)/len(a)) if sum(a)>=0 else int(-0.5 + 1.0*sum(a)/len(a)) 
cost = 0
for i in a:
    cost += (i-ave)**2
print(cost)

Measured memory_bytes: 2568
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n=0,a=0,b=0,c=0,d=0,i=0,j=0,a1=0,b1=0,c1=0;
        cin >> n;
        cin >> a;
        for(i=0;i<n-1;i++){
            cin >> b;
            a1=a;
            b1=b;
            if(a<b){
                    swap(a,b);
                }
                while(b>0){
                    c = a%b;
                    a=b;
                    b=c;
                }
                c1=(a1*b1)/a;
                a=c1;
        }
        cout << c1 << endl;
    }

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

int main(){
  string s; cin >> s;
  int cnt = 0;
  for(int i=0; i<s.size()-1; ++i){
    if(s[i] != s[i+1]) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 512
#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; }

vector<vpii> g;
vi ans;
void dfs(int v, int p, int c) {
    int nc = 1;
    for (auto tp : g[v]) {
        int t = tp.first, en = tp.second;
        if (t == p) continue;
        if (nc == c) ++nc;
        ans[en] = nc;
        dfs(t, v, nc);
        ++nc;
    }
}

int main(){
    int n;
    cin >> n;
    g = vector<vpii>(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    ans = vi(n-1);
    dfs(0, 0, 0);
    int cnum = 0;
    rep(i, n-1) cnum = max(cnum, ans[i]);
    cout << cnum << endl;
    rep(i, n-1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 10896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int gcd(int x, int y)
{
    int r;
    if(x < y)
        swap(x, y);
    while(y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = a * b / gcd(a, b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = listOfInt().sortedDescending()
    val U = arrayListOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val V = A.map { U[it] }
    val S = Array<String?>(10001) { null }; S[0] = ""
    for (n in 1 .. N) {
        for (m in 0 until M) {
            val t = n - V[m]
            if (t >= 0 && S[t] != null) {
                if (S[n] == null) S[n] = ""
                if (S[n]!!.length <= S[t]!!.length) {
                    S[n] = S[t] + A[m]
                }
            }
        }
    }
    val ans = S[N]!!.split("").sortedDescending()
    println(ans.joinToString(""))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

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

using namespace std;

int main(){
  string o, e;
  std::cin >> o >> e;

  for(int idx = 0; idx < e.size(); idx++){
      std::cout << o[idx];
      std::cout << e[idx];
  }
  if(o.size() > e.size()){
    std::cout << o.back();
  }
  std::cout << '\n';
  return 0;
}


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

using namespace std;

class Dataset{
private:
 string X;
 string Y;
public:
 Dataset(){
  string tmp = "";
  cin >> tmp; X = tmp; X = " " + X;
  cin >> tmp; Y = tmp; Y = " " + Y;
 };

 unsigned long getLongestCommonLength(){
  unsigned long Xsize = X.size();
  unsigned long Ysize = Y.size();
 
  vector< vector<unsigned long> > LC(Xsize, vector<unsigned long>(Ysize, 0));

  for(unsigned long X_i = 1; X_i < Xsize; ++X_i){
   for(unsigned long Y_i = 1; Y_i < Ysize; ++Y_i){
    unsigned long tmp = LC[X_i-1][Y_i-1];
    if(X[X_i] == Y[Y_i]) ++tmp;
    if(tmp < LC[X_i-1][Y_i]) tmp = LC[X_i-1][Y_i];
    if(tmp < LC[X_i][Y_i-1]) tmp = LC[X_i][Y_i-1];
    LC[X_i][Y_i] = tmp;
//cout << LC[X_i][Y_i] << " ";
   }
//cout << endl;
  }

  return LC[Xsize-1][Ysize-1];
 };


protected:
};

int main(){
 long datasetNum = 0; cin >> datasetNum;
 for(unsigned long dataset_i = 0; dataset_i < datasetNum; ++dataset_i){
  Dataset data;
  cout << data.getLongestCommonLength() << endl;
 }

 return 0;
};

Measured memory_bytes: 9000
X, K, D = map(int, input().split())
first = 0
if X < 0:
    first = -1
elif X > 0:
    first = 1
ans = 0
X = abs(X)
judge = 0 # 奇数なら1偶数なら0
if first == 0:
    if D % 2 == 1:
        ans = D
    else:
        ans = 0
else:
    if K < X // D:
        ans = X - (K * D)
    else:
        judge = (X // D) % 2
        if judge == 0:
            if K % 2 == 0:
                ans = X % D
            else:
                ans = X % D - D
        else:
            if K % 2 == 0:
                ans = X % D - D
            else:
                ans = X % D
print(abs(ans))


Measured memory_bytes: 61832
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int main()
{
	int n;string s,t;
	cin>>n>>s>>t;
	int ans=0;
	for(int i=1;i<=n;i++)
		if(s.substr(n-i)==t.substr(0,i))
			ans=max(ans,i);
	cout<<n*2-ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N){
  cout << pow(N,3) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(c==0) cout<<"YES"<<endl;
	else if(gcd(a,b)==1) cout<<"YES"<<endl;
	else if(c%gcd(a,b)==0) cout<<"YES"<<endl;
	else  cout<<"NO"<<endl;
}

Measured memory_bytes: 256