akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		long X = long.Parse(str[1]);
		long[][]A = new long[N][];
		for(var i=0;i<N;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i] = new long[3];
			A[i][0] = long.Parse(str2[0]);
			A[i][1] = long.Parse(str2[1]);
			A[i][2] = long.Parse(str2[2]);
		}
		Array.Sort(A,(x,y)=>((y[0]*y[1]+(X-y[0])*y[2])).CompareTo(x[0]*x[1]+(X-x[0])*x[2]));
		long[]S1 = new long[N+1];
		long[]S2 = new long[N+1];
		long[]S3 = new long[N+1];
		long[]S4 = new long[N+1];
      	long[]S5 = new long[N+1];
		long[]C = new long[N+1];
		for(var i=0;i<N;i++){
			S1[i+1] = S1[i]+X*A[i][2];
			C[i+1] = C[i]+X;
			S2[i+1] = S2[i]+A[i][0]*A[i][2];
			S4[i+1] = S4[i]+A[i][0]*A[i][1]+(X-A[i][0])*A[i][2];
          	S5[i+1] = S5[i]+A[i][0]*A[i][1];
		}
		for(var i=N-1;i>=0;i--){
			S3[i] = S3[i+1]+A[i][0]*A[i][1];
		}
		long ans = 999999999999999999;
		for(var i=0;i<N;i++){
			int min = 0;
			int max = N-1;
			while(min<max){
				int m = (min+max)/2;
				long sum;
				if(m>i){
					sum = S4[m+1]-S5[N];
				} else {
					sum = S4[m]-S5[N];
					sum += A[i][0]*A[i][1]+(X-A[i][0])*A[i][2];
				}
				if(sum>=0){
					max = m;
				} else {
					min = m+1;
				}
			}
			long s;
			if(min>i){
				s = S4[min+1]-S5[N] - (A[i][0]*A[i][1]+(X-A[i][0])*A[i][2]);
			} else {
				s = S4[min]-S5[N];
			}
			long cs = X*min;
			if(s<0){
				if(-s>A[i][0]*A[i][1]){
					cs += A[i][0]+(-s-A[i][0]*A[i][1]-1)/A[i][2]+1;
				} else {
					cs += (-s-1)/A[i][1]+1;
				}
			}
			ans = Math.Min(cs,ans);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 27968
using System;
using System.Linq;

namespace B___Contest_with_Drinks_Easy
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Tn = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var M = int.Parse(Console.ReadLine());
            var PmXm = new int[M].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

            for (int i = 0; i < M; i++)
            {
                int index = PmXm[i][0] - 1, Xm = PmXm[i][1];
                Console.WriteLine(Tn.Sum() - Tn[index] + Xm);
            }
        }
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}
int power(int a,int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
const int maxn=2e5+10;
int a,b,c,n,f[maxn],inv[maxn];
int ncr(int N,int R){
    if(N<R)return 0;
    if(R==0||R==N)return 1;
    return mul(f[N],mul(inv[R],inv[N-R]));
}

int main(){
    scanf("%d%d%d%d",&n,&a,&b,&c);
   // int tt=power(100,mod-2);
   // a=mul(a,tt);b=mul(b,tt);c=mul(c,tt);
    f[0]=1;
    for(int i=1;i<=200000;i++)
        f[i]=mul(f[i-1],i);
    for(int i=0;i<=200000;i++){
        inv[i]=power(f[i],mod-2);
    }
    //int base=power(sub(1,c),mod-2);
    int ans=0;
    int x=1;
    for(int i=n;i<2*n;i++){
        x=mul(i,mul(100,power(100-c,mod-2)));
        x=mul(x,ncr(i-1,n-1));
        x=mul(x,add(mul(power(a,n),power(b,i-n)),mul(power(a,i-n),power(b,n))));
        x=mul(x,power(power(a+b,i),mod-2));
        ans=add(ans,x);
    }
    printf("%d\n",ans);

}



Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int n, m, x, y; cin >> n >> m >> x >> y;
	int p = -100, q = 100;
	for (int i = 0; i < n; i++) {
		int foo; cin >> foo;
		p = max(p, foo);
	}
	for (int i = 0; i < m; i++) {
		int foo; cin >> foo;
		q = min(q, foo);
	}
	cout << (p<y&&q>x&&p<q ? "No War\n" : "War\n");
}

Measured memory_bytes: 256
def main():
    a, b, ab, x, y = map(int, input().split())
    # abをx枚買うかy枚買うか、0枚買うかの3パターン
    ab *= 2
    ab_x = ab * x + b * max((y - x), 0)
    ab_y = ab * y + a * max((x - y), 0)
    ab_0 = a * x + b * y
    print(min(ab_x, ab_y, ab_0))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
s = gets.chomp
t = gets.chomp
news0 = s[0]
newt0 = t[0]
news1 = s[1]
newt1 = t[1]
news2 = s[2]
newt2 = t[2]
result = 0

if news0 == newt0
  result += 1
end
if news1 == newt1
  result += 1
end
if news2 == newt2
  result += 1
end

p result


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<P> lens[100005];

int bit[MAX_N+1],n,m;
//i番目までの和を計算する
int sum(int i)
{
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
//i番目の値にxを加える
void add(int i,int x)
{
	while(i <= MAX_N){
		bit[i] += x;
		i += i & -i;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	rep(i,n){
		int l,r;
		scanf("%d%d",&l,&r);
		r++;
		lens[r-l].push_back(P(l,r));	//rはr+1を指すようにする
	}
	printf("%d\n",n);
	int rest = n;
	for(int i=2;i<m+1;i++){	//iは間隔dのこと
		rep(j,lens[i-1].size()){
			add(lens[i-1][j].first,1);
			add(lens[i-1][j].second,-1);
			rest--;
		}
		int ans = rest;	//間隔がm以上の区間
		int it = i;
		while(it<=m){
			ans += sum(it);
			it += i;
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 7936
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int A,B;

	cin >> A >> B;

	if(A%3==0){
		cout << "Possible" << endl;
	}else if(B%3==0){
		cout << "Possible" << endl;
	}else if((A+B)%3==0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}


	return 0;

}

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

int main(void){
    int n,a;
    vector<int> f,b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        b.push_back(a);
        swap(f,b);
    }
    reverse(f.begin(),f.end());
    for(int i:f) cout<<i<<" ";
    for(int i:b) cout<<i<<" ";
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf=1e16;
int n,a[200010];
ll s[200010],f[200010][2],g[200010][2],ans=inf;
void upd(ll &x,ll v)
{
	x=min(x,v);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		s[i]=s[i-1]+a[i];
	}
	for (int i=1;i<=n;i++)
	{
		f[i][0]=s[i-1]+(a[i]&1);
		f[i][1]=s[i-1]+((a[i]&1)^1);
		if (!a[i])
		{
			upd(f[i][0],f[i-1][0]+2);
			upd(f[i][1],min(f[i-1][0],f[i-1][1])+1);
		}
		else
		{
			upd(f[i][0],f[i-1][0]+(a[i]&1));
			upd(f[i][1],min(f[i-1][0],f[i-1][1]+((a[i]&1)^1)));
		}
	}
	for (int i=n;i;i--)
	{
		g[i][0]=s[n]-s[i]+(a[i]&1);
		g[i][1]=s[n]-s[i]+((a[i]&1)^1);
		if (!a[i])
		{
			upd(g[i][0],g[i+1][0]+2);
			upd(g[i][1],min(g[i+1][0],g[i+1][1])+1);
		}
		else
		{
			upd(g[i][0],g[i+1][0]+(a[i]&1));
			upd(g[i][1],min(g[i+1][0],g[i+1][1]+((a[i]&1)^1)));
		}
	}
	for (int i=1;i<=n;i++)
	{
		upd(ans,min(f[i][0],f[i][1])+min(g[i+1][0],g[i+1][1]));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8960
// B - Power Socket
#include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b; cin>>a>>b;

	if(b==1){
		cout<< 0 <<endl;
		return 0;
	}

	int c = 0;
	while(b>0){
		b -= a;
		++c;
		if(b>0) ++b;
	}
	cout<< c <<endl;
}

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

int main(void)
{
    long long H, W;
    long long num;
    cin >> H >> W;
    num = H*W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (num+1)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
x = []
y = []
for i in range(n):
  _x, _y = map(int, input().split())
  x.append(_x)
  y.append(_y)
#それぞれの組み合わせに対して2*(n-1)!回ずつ合計に加算される→平均への寄与は2/n倍
def d(x1, y1, x2, y2):
  return ((x1-x2)**2 + (y1-y2)**2)**0.5

ans = 0
for i in range(n):
  for j in range(i+1, n):
    ans += d(x[i], y[i], x[j], y[j])
print(ans*2/n)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
char a[100001];
int num[100001];
int main()
{
	int n,k,i,l,sum,ans;
	scanf("%d %d", &n,&k);
	scanf("%s",a);
	for(i=0;i<n;i++)
		num[i]=a[i]-'0';
	i=l=sum=ans=0;
	while(i<n)
    {
		while(i<n&&num[i])
			i++;
		ans=max(ans,i-l);
		while(i<n&&!num[i])
			i++;
		k--;
		if(k<0)
        {
			while(l<n&&num[l])
				l++;
			while(l<n&&!num[l])
				l++;
		}
		ans=max(ans,i-l);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
ll MOD=998244353;

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(){
    ll S,W;
    cin>>S>>W;
    if(S<=W){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
//#define double ld
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ifstream in("input.txt");ofstream out("output.txt");
const int inf=1e18;
const int mod=1e9+7;
int n;
vector<int>h;
vector<int>a;
vector<int>t;
void update(int ind,int val,int v=1,int tl=1,int tr=n)
{
    if(tl==tr)
        t[v]=max(t[v],val);
    else
    {
        int tm=(tl+tr)>>1ll;
        if(ind<=tm)
            update(ind,val,v<<1ll,tl,tm);
        else
            update(ind,val,v<<1ll|1ll,tm+1,tr);
        t[v]=max(t[v<<1ll],t[v<<1ll|1ll]);
    }
}
int gett(int l,int r,int v=1,int tl=1,int tr=n)
{
    if(l>r)
        return 0;
    if(tl==l&&tr==r)
        return t[v];
    int tm=(tl+tr)>>1ll;
    return max(gett(l,min(tm,r),v<<1ll,tl,tm),
               gett(max(l,tm+1),r,v<<1ll|1ll,tm+1,tr));
}
vector<int> dp;
void init()
{
    cin>>n;
    h.resize(n+1);
    a.resize(n+1);
    dp.resize(n+1);
    t.resize(4*n+15);
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=n;i++)
        cin>>a[i];
}

void solve()
{
    for(int i=1;i<=n;i++)
    {
        dp[i]=gett(1,h[i]-1)+a[i];
        update(h[i],dp[i]);
    }
    int ans=-1;
    for(int i=1;i<=n;i++)
        ans=max(ans,dp[i]);
    cout<<ans;
}

signed main()
{
    init();
    solve();
    return 0;
}









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

int main() {
	int n;
	cin >> n;
	int x=7%n;
	for(int i=1; i<=n; ++i) {
		if(x==0) {
			cout << i << "\n";
			return 0;
		}
		x=(x*10+7)%n;
	}
	cout << -1 << "\n";
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main()
{
    int n, optim = 0, ans = 0;
    cin >> n;
    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    double b, c, sum;
    for (int i = 0; i < n; i++)
    {
        sum += a.at(i);
    }
    sum /= n;
    b = (int)sum;
    if (b < sum)
    {
        c = b + 1;
        if (sum - b > c - sum)
        {
            optim = c;
        }
        else
        {
            optim = b;
        }
    }
    else if (b > sum)
    {
        c = b - 1;
        if (b - sum > sum - c)
        {
            optim = c;
        }
        else
        {
            optim = b;
        }
    }
    else
    {
        optim = (int)sum;
    }

    for (int i = 0; i < n; i++)
    {
        int s = a.at(i);
        int dis;
        if (s > optim)
        {
            dis = s - optim;
        }
        else
        {
            dis = optim - s;
        }
        ans += pow(dis, 2);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll tot = 0;
    rep(i, n) {
        tot += a[i];
        tot %= MOD;
    }
    tot %= MOD;
    ll ans = 0;
    rep(i, n-1) {
        tot -= a[i];
        if (tot<0) tot+=MOD;
        ans += a[i]*tot%MOD;
        ans %= MOD;
    }
    cout << ans%MOD << endl;
}

Measured memory_bytes: 4048
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

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

#define fr first
#define sc second

int N;
string S;

bool comp(string x,string y){
	for(int i = 0 ; i < min(x.size(),y.size()) ; i ++){
		if(x[i] != y[i]){
			return x[i] > y[i];
		}
	}
	return x.size() > y.size();
}

bool eq(string x,string y){
	if(x.size() != y.size())return false;
	for(int i = 0 ; i < x.size() ; i ++){
		if(x[i] != y[i])return false;
	}
	return true;
}

bool comp2(pair<string,int> x,pair<string,int> y){
	if(eq(x.fr,y.fr))return x.sc < y.sc;
	return comp(x.fr,y.fr);
}

string solve(int s,int t){
	if(S[s] == 'a'){
		int pre = 0;
		int cnt[2] = {};
		string ret = "";
		for(int i = s ; i <= t ; i ++){
			cnt[S[i]-'a'] ++;
			if(S[i] == 'a'){
				if(cnt[1] >= pre){
					pre = cnt[0];
					ret += "a";
				}
			}
			else {
				if(cnt[1] == pre){
					ret += "b";
				}
			}
		}
		return ret;
	}
	vector<string> vec;
	for(int k = 0 ; k <= (t-s)/2 ; k ++){
		int cnt[2] = {};
		string ret;
		for(int i = s ; i <= t ; i ++){
			if(cnt[S[i]-'a'] == k)ret += S[i];
			else cnt[S[i]-'a'] ++;
		}
		vec.push_back(ret);
	}
	sort(vec.begin(),vec.end(),comp);
	return vec[0];
}

int main(){
	cin >> N >> S;
	
	int cnt[6002] = {};
	for(int i = 0 ; i < S.size() ; i++){
		cnt[i+1] = cnt[i]+1-2*(S[i]=='b'?1:0);
	}
	vector<pair<string,int>> vec;
	int l = 0;
	for(int i = 0 ; i < S.size() ; i ++){
		if(cnt[i+1] == 0){
			string s = solve(l,i);
			if(s[0] == 'a'){
				for(int j = 0 ; j < s.size() ; j += 2){
					vec.push_back(pair<string,int>("ab",(int)vec.size()));
				}
			}
			else vec.push_back(pair<string,int>(s,(int)vec.size()));
			l = i+1;
		}
	}
	
	sort(vec.begin(),vec.end(),comp2);
	string ret = "";
	int Max = -1;
	for(int i = 0 ; i < vec.size() ; i ++){
		if(vec[i].sc > Max){
			Max = vec[i].sc;
			ret += vec[i].fr;
		}
	}
	cout << ret << endl;
}



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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
void ruisekiwa(ll A,vector<int>& digitA){
    int i=1;
    ll amari;
    ll k;
    if(A%4==3||A%4==0){
        digitA.push_back(0);
    }else{
        digitA.push_back(1);
    }
    while(pow(2,i)<=A){
        k=pow(2,i+1);
        amari=A%k;
        if(amari<pow(2,i)){
            digitA.push_back(0);
        }else{
            if(A%2==0){
                digitA.push_back(1);
            }else{
                digitA.push_back(0);
            }
        }
        i++;
    }
}
int main() {
    unordered_map<char,int> mp;
    string w=in<string>();
    REP(i,w.length()){
        if(mp.count(w[i])>0){
            mp[w[i]]+=1;
        }else{
            mp[w[i]]=1;
        }
    }
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        if(itr->second%2==1){
            print("No");
            return 0;
        }
    }
    print("Yes");
    return 0;

}

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

int main() {
  string S; cin >> S;
  bool flag = false;
  for(int i = 0; i < 3; ++i){
    if(S.at(i) == S.at(i+1)) flag = true;
  }
  
  if(flag) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

#define LEN(x) (i64)x.length()

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

  i64 n;
  cin >> n;

  i64 minv = LINF;
  for (i64 a = 1; a*a <= n; ++a) {
    if (n % a == 0) {
      i64 b = n / a;
      string A = to_string(a);
      string B = to_string(b);
      chmin(minv, max(LEN(A), LEN(B)));
    }
  }

  cout << minv << "\n";

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int N_1 = N%10;
    
    if( N_1 == 3)
      System.out.println("bon");
    else{
      if(N_1 == 0 || N_1 == 1 || N_1 == 6 || N_1 == 8 )
        System.out.println("pon");
      else
        System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int a,b;
char s[15];
bool f=1;
int main()
{
	scanf("%d%d",&a,&b);
	b=a+b+1;
	scanf("%s",&s);
	if(s[a]!='-')f=0;
	else for(int i=0;i<b;i++)
	{
		if(s[i]<'0'||s[i]>'9')
		{
			if(i!=a)
			{
				f=0;
				break;
			}
		}
	}
	if(!f)printf("No");
	else printf("Yes");
	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

struct unionFind {
    int elements = 0;
    vector<int> Par, Rank_p;
    unionFind(int n) : Par(n), Rank_p(n) {
        for (int id = 0; id < n; id++) {
            elements   = n;
            Par[id]    = id;
            Rank_p[id] = 0;
        }
    }
    int find(int x) {
        if (Par[x] == x)
            return x;
        else
            return Par[x] = find(Par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (Rank_p[x] < Rank_p[y])
            Par[x] = y;
        else {
            Par[y] = x;
            if (Rank_p[x] == Rank_p[y]) Rank_p[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int groups() {
        set<int> se;
        for (auto x : Par) {
            se.insert(x);
        }
        return se.size();
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N, -1);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    unionFind uf(N);
    rep(i, M) {
        int ai, bi;
        cin >> ai >> bi;
        ai--, bi--;
        uf.unite(ai, bi);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(P[i], i)) { ans++; }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;



int main(){

	long long n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;

	for(long long m=0;m<n;m++){
		if( c*(n-1-m)-d*m <= b-a && b-a<=-c*m+d*(n-1-m) ){
			cout<<"YES"<<endl;
			return 0;
		}
	}

	cout<<"NO"<<endl;


	return 0;
}


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


int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> mt(n+1);
    for (int i = 1; i < n+1; i++) {
        cin >> a[i];
    }
    long long s = 0;
    for (int i = 1; i < n+1; i++) {
        s += a[i];
    }
    mt[1] = s;
    for (int i = 1; i < (n+1)/2; i++) {
        mt[1] -= a[2*i]*2;
    }
    for (int i = 2; i < n+1; i++) {
        mt[i] = a[i-1]*2 - mt[i-1];
    }
    for (int i = 1; i < n+1; i++) {
        if (i == n) {
            cout << mt[n] << endl;
        }else{
            cout << mt[i] << ' ';
        }
    }
    return 0;
}

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

int main () {
  int n;
  cin >> n;
  int num = n / 100;
  int ans = n % 100;
  if (5 * num >= ans) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int main(){
	int n,r;
	scanf("%d%d",&n,&r);
	if(n>=10)printf("%d",r);
	else {
		printf("%d\n",r+100*(10-n));
	}
	return 0;
}


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

int main(){
    string s;
    char a,b,c;
    getline(cin,s);
    a=s[0];
    b=s[1];
    c=s[2];
    if(a==b&&a==c&&b==c)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
let () =
    let nums = Scanf.scanf "%d %d %d %d %d" (fun a b c d e -> [|a; b; c; d; e|]) in
    Array.sort (fun a b -> compare b a) nums ;
    Printf.printf "%d %d %d %d %d\n" nums.(0) nums.(1) nums.(2) nums.(3) nums.(4);

Measured memory_bytes: 2352
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll int 
#define pi 3.1415926536
using namespace std;
const ll N=55;

void solve()
{ll n,k,m,h,x,y,z,w,mini,maxi=INT_MAX,prev,res;
 string s="ABC",t="ARC",u;
 cin>>u;
 if(u==s)
 cout<<t;
 else
 cout<<s;
}
  
int main()
{
  fast
  //for(ll i=0;i<=9;i++)
  //cal(1,3234566667,i);
  //sort(v.begin(),v.end());
  //pre();
ll t=1;
//cin>>t;
//SieveOfEratosthenes();
//cout<<"ok";
while(t--)
{ //cout<<"ok";

solve();
 //cout<<ma<<endl;
}
return 0;}
/*
ll pr(ll a,ll b,ll c)
{
	if(b==0)
	return 1LL;
	ll ans=1;
	while(b>0)
	{
		if(b%2)
		ans=((ans%c)*(a%c))%c;
		a=((a%c)*(a%c))%c;
		b/=2;
		a%=c;
		ans%=c;
	}
	return ans;
}
vector<ll> fact(N+1);
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=N;i++)
	fact[i]=fact[i-1]*i,fact[i]%=hell;
	
}
*/

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int dp[3002][3002];
string ans;

void lcs(string a, string b, int n, int m){

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

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i-1]==b[j-1])
				dp[i][j] = 1 + dp[i-1][j-1];
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

}

void print(string a,string b,int n, int m){
	int i=n,j=m;
	while(i!=0 && j!=0){
		if(a[i-1]==b[j-1]){
			ans.push_back(a[i-1]);
			i--;j--;
		} else{
			if(dp[i-1][j]>dp[i][j-1]){
				i--;
			} else{
				j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}



int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    lcs(s,t,s.size(),t.size());
    print(s,t,s.size(),t.size());
    return 0;
}


Measured memory_bytes: 38748
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
using namespace std;

int q,lim;
//セグ木
int dat[1<<20+2];
//リーフ(一番下の葉)の最小
int low=1<<19+1;
//dat配列はどこまで埋まっているか
int size;
//固体番号
int rnum[500000];
//固体番号を円環するときに利用
map<int,int> num;

void add(int x){
	//固体番号(円環)追加
	num[x]=size;
	//要素数追加
	dat[size]=0;
	//固体番号追加
	rnum[size-low]=x;
	//配列が1つ埋まった
	size++;
	//管理できる個体数が1つ減った
	lim--;

	int pos=size-1;
	//ルートノードまで登りながら, 各ノードをインクリメント
	while(0<pos){
		dat[pos]++;
		pos=(pos-1)/2;
	}
}

//配列のx番目が, dat配列の何番目か求める
int find(int x){
	int pos=0;
	//左にもぐるか, 右にもぐるか決めつつ, リーフまでもぐる
	while(pos<low){
		int left=pos*2+1;
		int right=pos*2+2;
		if(x<=dat[left]){
			pos=left;
		}else{
			x-=dat[left];
			pos=right;
		}
	}
	return pos;
}

//dat配列のpos番目を削除する処理
void erase(int pos){
	lim++;
	while(0<pos){
		dat[pos]--;
		pos=(pos-1)/2;
	}
}

int main(void){
	while(1){
		scanf("%d%d",&q,&lim);
		if(q==0 && lim==0)break;
		memset(dat,0,sizeof(dat));
		memset(rnum,0,sizeof(rnum));
		num.clear();
		size=low;
		for(int i=0;i<q;i++){
			int query,x;
			scanf("%d%d",&query,&x);
			if(query==0){
				add(x);
				if(lim<0){
					int pos=find(0);
					erase(pos);
				}
			}else if(query==1){
				int pos=find(x);
				erase(pos);
			}
			else if(query==2){
				int pos=find(x);
				printf("%d\n",rnum[pos-low]);
			}
			else if(query==3){
				int pos=num[x];
				erase(pos);
			}
		}
		printf("end\n");
	}

    return 0;
}

Measured memory_bytes: 31000
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int N, cnt = 0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N-2; i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> h >> w;
	cin >> n;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<vector<ll>> mp(h, vector<ll>(w));
	vector<ll> d(h * w);
	ll t = 0;
	ll h0 = 0; ll w0 = 0;
	rep(i, n) {
		rep(j, a[i]) {
			d[t] = i + 1;
			++t;
		}
	}
	t = 0;
	rep(i, h) {
		rep(j, w) {
			mp[i][j] = d[t];
			++t;
		}
	}
	rep(i, h) {
		if (i % 2 == 0) {
			rep(j, w) {
				cout << mp[i][j];
				if (j != w - 1) {
					cout << " ";
				}
			}
		}
		else {
			rep(j, w) {
				cout << mp[i][w-1-j];
				if (j != w - 1) {
					cout << " ";
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int N,M,m[205][2],i,j,dp[205],R;

int cmp(const void *a,const void *b)
{
	int *x=(int*)a,*y=(int*)b;
	if(x[0]==y[0])return x[1]-y[1];
	return x[0]-y[0];
}

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%d%d",&m[i][0],&m[i][1]);
		scanf("%d",&M);
		for(i=0;i<M;i++)
			scanf("%d%d",&m[i+N][0],&m[i+N][1]);
		int tmp=N+M;
		qsort(m,tmp,sizeof(int[2]),cmp);
		for(i=0;i<N+M;i++)dp[i]=1;
		for(i=0,R=1;i<N+M;i++)
			for(j=i;j<N+M;j++)
				if(m[j][0]>m[i][0]&&m[j][1]>m[i][1])
				{
					dp[j]=dp[j]<dp[i]+1?dp[i]+1:dp[j];
					R=dp[j]>R?dp[j]:R;
				}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  int c=0,d=1,e,f,g,h,n,m,mx=0;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
    if(a[i]%2==0) c++;
  }
  rep(i,0,n) d*=3;
  co(d-pow(2,c));
  
  return 0;
}

Measured memory_bytes: 256
while True :
    n, m = map(int, input().split())
    if m == 0 and n == 0 :
        break
    
    List = []
    max_ans = 0
    sum_ans = 0
    for i in range(n) :
        List.append(int(input()))
        if i < m : 
            sum_ans += List[i] 
        else : 
            sum_ans += List[i] - List[i-m]
        if i >= m - 1 and max_ans < sum_ans :
            max_ans = sum_ans
    print(max_ans)


Measured memory_bytes: 9608
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	n := getInt()
	as := make([]int, n+2)
	as[0], as[n+1] = 0, 0
	sum := 0
	for i := 1; i <= n; i++ {
		as[i] = getInt()
		sum += abs(as[i] - as[i-1])
	}
	sum += abs(as[n+1] - as[n])

	ans := make([]string, n)
	for i := range ans {
		ans[i] = strconv.Itoa(sum - abs(as[i+1]-as[i]) - abs(as[i+2]-as[i+1]) + abs(as[i+2]-as[i]))
	}

	fmt.Println(strings.Join(ans, "\n"))
}

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

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

int main()
{
  int n,a;
  cin >>n >> a;
  
	if (n%500 <= a){
      cout << "Yes" << endl;
    }else{
		cout << "No" << endl;
    }
      
    
    return 0;
}






Measured memory_bytes: 256
program sample
implicit none

integer :: n, k
integer, allocatable :: a(:), b(:)
integer :: d
integer :: number

integer :: i, j

read(*,*) n, k
allocate(a(n))
a = 0
do i = 1, k
read(*,*) d
allocate(b(d))
read(*,*) b
do j = 1, d
a(b(j)) = 1
end do
deallocate(b)
end do

number = 0

do i = 1, n
if (a(i) == 0) then
number = number + 1
end if
end do

write(*,*) number

stop
end program sample

Measured memory_bytes: 2864
N, T = gets.split.map(&:to_i)
t = gets.split.map(&:to_i)
t.push(t[-1]+T)

s = t[0]
sum = 0

(0..N-1).each do |i|
  
  sum += [T, t[i+1]-t[i]].min
    
end

puts sum


Measured memory_bytes: 19972
#include<stdio.h>
int main()
{
    int n, p[55], i, j, c=0, d=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &p[i]);
    }
    for(i=0; i<n; i++)
    {
        if(p[i]!=i+1)
        {
            c++;
        }
    }
    if(c>2)
    {
        printf("NO");
    }
    else if(c==0)
    {
        printf("YES");
    }
    else
    {
        for(i=0; i<n-1; i++)
        {
            for(j=1; j<n; j++)
            {
                if(p[i]!=i && p[j]!=j && p[i]==j)
                {
                    d++;
                    break;
                }
            }
        }
        if(d==0)
        {
            printf("NO");
        }
        else
        {
            printf("YES");
        }
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

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

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n){
        int a;
        cin >> a;
        mp[a]++;
        if(mp[a] == 2) mp[a] = 0;
    }

    int ans = 0;
    for (auto& p : mp) {
        ans += p.second;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
main(){
string str;
cin>>str;
int a=0,b=0,c=0;
for(int i=0;i<3;i++){
if(str[i]=='a')a++;
}
for(int i=0;i<3;i++){
if(str[i]=='b')b++;
}
for(int i=0;i<3;i++){
if(str[i]=='c')c++;
}
if(!a||!b||!c) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
return 0;
}


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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)
#define c2i(c) {i-48;}
#define i2c(n) {n+48;}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int m,n,cnt=0;
    string s;

    cin >> n >> s;
    forN(i,s.size()){
        s[i]=(s[i]+n-65)%26 + 65;
    }
    cout << s << endl;
}


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

int main(){
    string in, out;
    cin >> in;

    for(int i = 0; i < (in.size() + 1) / 2; i++){
        out.push_back(in[i * 2]);
    }

    cout << out;

    return 0;
}

Measured memory_bytes: 512
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n, m;

unordered_map <int, vector <int > > g[N];

unordered_map <int, int> d[N];

int c[N];

pair <int, pair <int, int> > st[N * 4];
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
    freopen ("E.out", "w", stdout);
	#endif
	Kazakhstan
	cin >> n >> m;
	rep(i, 1, m) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a][c].pb(b);
    g[b][c].pb(a);
	}
	d[1][0] = 0;
  int l = N*2, r = N*2;
	st[l] = {0, {1, 0}};
  vector <bool> was(n + 1, 0);
	while (l <= r) {
		int dist = st[l].f;
		int v = st[l].s.f, last = st[l].s.s;
    l++;

    if (!was[v]) {
      for (auto it : g[v]) {
        int C = it.f;
        for (auto to : it.s) {
          if (!d[to].count(C) || d[to][C] > dist + 1) {
            d[to][C] = dist + 1;
            st[++r] = {d[to][C], {to, C}};
          }
        }
      }
      was[v] = 1;
    }

    if (sz(g[v][last])) {
      int C = last;
      for (auto to : g[v][last]) {
        if (!d[to].count(last) || d[to][last] > dist) {
          d[to][C] = dist;
          st[--l] = {d[to][C], {to, C}};
        }
      }
      g[v][last].clear();
      g[v].erase(last);
    }
  }
  int ans = inf;
  for (auto it : d[n]) ans = min(ans, it.s);
  cout << (ans == inf ? -1 : ans);
	ioi
}


Measured memory_bytes: 108444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            Console.WriteLine(x == 0 ? 1 : 0);
        }
    }
}


    


Measured memory_bytes: 27320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    lol;
    string a,b;cin >> a >> b;
    ll c = 0;
    for(ll i=0;i<a.length();i++)
    {
        if(a[i]!=b[i]) c++;
    }
    cout << c<< endl;
}
    

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

#define M 2019
#define INF 100000000

int		main(void)
{
	int l, r;
	cin >> l >> r;
	if (l + 2019 < r || l % M > r % M)
	{
		cout << 0 << endl;
		return (0);
	}
	int min = INF;
	for (int i = l; i < r; i++)
	{
		int im = i % M;
		for (int j = i + 1; j <= r; j++)
		{
			int modij = (im * (j % M)) % M;
			if (modij < min)
				min = modij;
		}
	}
	cout << min << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1')
			s[i]='9';
		else
			s[i]='1';
	}
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long table[2010][2010] = {0};

void solve() {
  long N, K;
  cin >> N >> K;

  rep (i, 2010) rep (j, 2010) table[i][j] = 0;
  for (long i = 1; i < 2010; i++) table[i][1] = 1;
  for (long i = 2; i < 2010; i++) for (long j = 2; j < 2010; j++) table[i][j] = (table[i-1][j-1] + table[i-1][j]) % MOD;

  for (long i = 1; i <= K; i++) {
    if (i == 1) {
      cout << (N - K) + 1 << endl;
    } else {
      long result = 0;
      result += table[K][i] * table[N-K][i-1];
      result += table[K][i] * table[N-K][i] * 2;
      result += table[K][i] * table[N-K][i+1];
      result %= MOD;
      cout << result << endl;
    }
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 31872
(let* ((n (read))
       (m (read))
       (q (read))
       (lst (loop :repeat q :collect (cons (list (1- (read)) (1- (read)) (read)) (read))))
       (ll nil))
  (labels ((fl (l)
             (if (= (length l) n)
                 (push l ll)
                 (loop :for x :from 1 :upto (car l)
                       :do (fl (cons x l))))))
    (loop :for k :from 1 :upto m :do (fl (list k)))
    (princ (reduce
            #'max
            (mapcar (lambda (x)
                      (reduce #'+ (mapcar (lambda (y)
                                            (if (= (third (car y))
                                                   (- (elt x (second (car y))) (elt x (first (car y)))))
                                                (cdr y)
                                                0)) lst))) ll)))))

Measured memory_bytes: 82364
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	a,b := scanInt(), scanInt()
	c,d := scanInt(), scanInt()

	for i := 0; i < n; i++ {
		mi := i*c - (n-1-i)*d
		ma := i*d - (n-1-i)*c

		if mi <= b-a && b-a <= ma {
			fmt.Println("YES")
			return
		}
	}

	fmt.Println("NO")
}


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

int main(){
	long long dp[11][1010];
	fill((int*)dp, (int*)(dp+11), 0);
	dp[0][0] = 1;
	for(int i = 0;i <= 100;i++){
		for(int j = 9;j >= 0;j--){
			for(int k = 0;k <= 1000-i;k++){
				dp[j+1][k+i] += dp[j][k];
			}
		}
	}

	int n, s;
	while(cin >> n >> s, n | s)cout << dp[n][s] << endl;
	return 0;
}

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

int main()
{
	int N, db = 0;
	string s, t;
	cin >> N >> s >> t;
	for (int i = N; i >= 1; i--) {
		bool flag = true;
		for (int j = 0; j < i; j++) {
			if (s[N - i + j] != t[j]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			db = i;
			break;
		}
	}
	cout << N * 2 - db << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int l,r,d;
	cin >> l >> r >> d;
	if(d==1){
		cout << r-l+1;
		return;
	}
	int ans = 0;
	if(l%d==0){
		ans++;
		l++;
	}
	if(r%d==0){
		ans++;
		r--;
	}
	ans += r/d - l/d;
	cout << ans;

	return;
}

int main(){

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

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3840
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
int n,m,K,ans,a[maxn],b[maxn];
inline char nc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int main(){
	n=read(),m=read(),K=read();a[0]=b[0]=1e9;
	for (int i=1;i<=n;i++) a[0]=min(a[0],a[i]=read());
	for (int i=1;i<=m;i++) b[0]=min(b[0],b[i]=read());
	ans=a[0]+b[0];
	for (int i=1;i<=K;i++){
		int x=read(),y=read(),c=read();
		ans=min(ans,a[x]+b[y]-c);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

int A,B,C,D;

int main(){
    cin>>A>>B>>C>>D;
    int a=(A/D);
    int b=(C/B);
    if(A%D!=0)a++;
    if(C%B!=0)b++;
    if(a>=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int k,x;
    cin >> k >> x;

    for(int i = x - k + 1; i <= x + k - 1; i++){
        cout << i << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 384