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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

bool pairCompare_ll(const Pll& firstElof, const Pll& secondElof)
{
    if(firstElof.first == secondElof.first) return firstElof.second > secondElof.second;
    else return firstElof.first < secondElof.first;
}

int main() {
    ll N, K;
    cin >> N >> K;

    vector<Pll> Psx(N), Psy(N);
    for(int i=0;i<N;i++){
        cin >> Psx[i].first >> Psx[i].second;
        Psy[i].first = Psx[i].second;
        Psy[i].second = Psx[i].first;
    }

    sort(Psx.begin(),Psx.end());
    sort(Psy.begin(),Psy.end());


    ll ans = (Psx[N-1].first - Psx[0].first) * (Psy[N-1].first - Psy[0].first);

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int l=0;l<N;l++){
                for(int k=l+1;k<N;k++){

                    ll rx = Psx[j].first;
                    ll lx = Psx[i].first;
                    ll uy = Psy[k].first;
                    ll by = Psy[l].first;

                    ll num = 0;
                    for(int m=0;m<N;m++){
                        ll x = Psx[m].first;
                        ll y = Psx[m].second;
                        if(lx<=x && x<=rx && by<=y && y<=uy) num++;
                    }
                    if(num>=K){
                        ll tmp;
                        tmp = (rx - lx) * (uy - by);
                        ans = min(ans,tmp);
                    }
                }
            }
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,s;
	cin>>k>>s;
	int n=0;
	int m=min(k,s);
	for(int i=0;i<=m;i++) for(int j=0;j<=m;j++){
		if(s-i-j<=k&&i+j<=s){
			n++;
		}
	}
	cout<<n<<'\n';
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-


def main():
    """Function."""
    h, w = map(int, input().split())

    s = []
    s.append(["!" for _ in range(w+2)])
    for _ in range(h):
        dum = str(input())
        dum = list(dum)
        dum.insert(0, "!")
        dum.append("!")
        s.append(list(dum))
    s.append(["!" for _ in range(w+2)])

    for _i in range(h):
        for _j in range(w):
            i = _i + 1
            j = _j + 1
            if s[i][j] == "#":
                pass
            else:
                counter = 0
                if s[i-1][j-1] == "#":
                    counter += 1
                if s[i-1][j] == "#":
                    counter += 1
                if s[i-1][j+1] == "#":
                    counter += 1
                if s[i][j-1] == "#":
                    counter += 1
                if s[i][j+1] == "#":
                    counter += 1
                if s[i+1][j-1] == "#":
                    counter += 1
                if s[i+1][j] == "#":
                    counter += 1
                if s[i+1][j+1] == "#":
                    counter += 1
                s[i][j] = str(counter)

    for i in range(h):
        dum = s[i+1][1:-1]
        dum_2 = "".join(dum)
        print(dum_2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    int N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> info(N);
    for (int i=0;i<N;i++){
        ll p, q;
        cin >> p >> q;
        info[i] = make_pair(p,q);
    }
    sort(info.begin(), info.end());
    ll sum = 0;
    ll count = 0;
    for (int i=0;i<N;i++){
        if (M-count<=info[i].second){
            sum += info[i].first*(M-count);
            break;
        }
        count += info[i].second;
        sum += info[i].first*info[i].second;
    }
    cout << sum << endl;
}



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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int a, b, h;
    cin >> a >> b >> h;
    if(a > b)
        swap(a, b);
    cout << a * h + ((b - a) * h) / 2;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    r=INT()
    print(3*r*r)
if __name__ == '__main__':
    do()

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

// #define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define pii pair < int , int >
#define all(a) a.begin(),a.end()

int gcd(int x, int y) {
    int t;
    while(x%y)
        t = x, x = y, y = t%y;
    return y;
}

const int N = 1e6+1;
bool prime[N+10];
vector < int > k; 
bool present[N+10];

void sieve() {
    memset(prime,true,sizeof(prime));
    for (int p = 2;  p*p <= N; p++) {
        if (prime[p] == true) {
            for (int i = p*p; i <= N; i += p) {
                prime[i] = false;
            }
        }
    }
    for (int p = 2; p <= N; p++) if (prime[p]) k.eb(p);
}

bool pairwisecoprime(int arr[],int n) {
    repd (i,n) {
        int val = arr[i];
        if (present[val] == true && val != 1) {
            return false;
        }
        for (auto x:k) {
            if (prime[val] == true) {
                if (present[val] == true) {return false;}
                else {if (val!=1) present[val] = true; break;}
            }
            if (val%x == 0) {
                if (present[x] == true) return false;
                present[x] = true;
                while (val%x == 0) {
                    present[val] = true;
                    val/=x;
                }
            }
            if (val == 1) break;
        }
    }
    return true;
}

bool setwisecoprime(int arr[],int n) {
    int g = arr[0];
    reps (i,n,1) {
        g = gcd(g,arr[i]);
        if (g == 1) break;
    }
    if (g == 1) return true;
    else return false;
}


void solve() {
    sieve();
    int n; cin >> n;
    int arr[n];
    rep(i,n) cin >> arr[i];
    if (pairwisecoprime(arr,n)) {
        cout << "pairwise coprime" << endl;
    }else if (setwisecoprime(arr,n)) {
        cout << "setwise coprime" << endl;
    }else {
        cout << "not coprime" << endl;
    }
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; t=1;
    while (t--) solve();
}

Measured memory_bytes: 8724
from collections import deque

N, M = map(int, raw_input().split())
way = {}
for _ in xrange(M):
    a, b = map(int, raw_input().split())
    if a not in way:
        way[a] = set()
    if b not in way:
        way[b] = set()
    way[a].add(b)
    way[b].add(a)

counter = 0
states = deque([({1}, 1)])
while states:
    passed, current = states.popleft()
    if len(passed) == N:
        counter += 1
        continue
    for next_index in way.get(current, []):
        if next_index not in passed:
            states.append((passed | {next_index}, next_index))
print counter

Measured memory_bytes: 33180
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int N;
  cin >> N;

  vector<int> A(N);
  int two = 0;
  int four = 0;
  for( int i = 0; i < N; i++ ){
    cin >> A[i];
    if( A[i]%4 == 0 ) four++;
    else if( A[i]%2 == 0 ) two++;
  }

  int pea = two/2 + four;
  if( pea >= N/2 ) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  int a, b;
  cin >> a >> b;
  
  if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  }
  else cout << -1 << endl;

  
  return 0;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)

start = -1
end = -1

if n == 2:
    if s[0] == s[-1]:
        start = 1
        end = 2
    
for i in range(n-2):
    a = [0]*26
    for j in range(3):
        a[ord(s[i+j])-ord("a")] += 1
    if max(a) >= 2:
        ans = 1
        start = i+1
        end = i+3
        break
        
print(start, end)

Measured memory_bytes: 72460
sx, sy, tx, ty = map(int, input().split())

ans = ''

ans += 'R' * (tx-sx)
ans += 'U' * (ty-sy)
ans += 'L' * (tx-sx)
ans += 'D' * (ty-sy)
ans += 'D'
ans += 'R' * (tx-sx+1)
ans += 'U' * (ty-sy+1)
ans += 'L'
ans += 'U'
ans += 'L' * (tx-sx+1)
ans += 'D' * (ty-sy+1)
ans += 'R'

print(ans)



Measured memory_bytes: 3060
#include <stdio.h>

int H, W, dp[2][10946][2][2], bits[10946], conv[1 << 19], maxbits;

char M[20][21];

int main()
{
	scanf("%d", &H);
	scanf("%d", &W);

	for (int i = 0; i < H; i++) scanf("%s", M[i]);

	if (M[0][0] == 'J' || M[0][0] == '?') dp[0][0][0][0] += 1;
	if (M[0][0] == 'O' || M[0][0] == '?') dp[0][0][1][0] += 1;
	if (M[0][0] == 'I' || M[0][0] == '?') dp[0][0][1][0] += 1;

	for (int i = 0; i < (1 << (W - 1)); i++)
	{
		bool ok = true;

		for (int j = 0; j < W - 2; j++)
		{
			if ((i & (1 << j)) && (i & (1 << (j + 1))))
			{
				ok = false; break;
			}
		}

		if (ok)
		{
			conv[i] = maxbits; bits[maxbits++] = i;
		}
	}

	int maxbit = 1 << (W - 1);

	for (int i = 0; i < H * W - 1; i++)
	{
		int s = i % 2;
		int t = (i + 1) % 2;

		for (int j = 0; j < maxbits; j++)
		{
			dp[t][j][0][0] = 0;
			dp[t][j][0][1] = 0;
			dp[t][j][1][0] = 0;
			dp[t][j][1][1] = 0;
		}

		char nowc = M[i / W][i % W];
		char nxtc = M[(i + 1) / W][(i + 1) % W];

		for (int j = 0; j < maxbits; j++)
		{
			int nxt = (bits[j] << 1) & (maxbit - 1);

			int sum0 = (dp[s][j][0][0] + dp[s][j][1][0]) % 100000;
			int sum1 = (dp[s][j][0][1] + dp[s][j][1][1]) % 100000;

			if (nxtc == 'J' || nxtc == '?')
			{
				dp[t][conv[nxt]][0][0] += sum0;
				dp[t][conv[nxt]][0][1] += sum1;
			}

			if (nxtc == 'O' || nxtc == '?')
			{
				if ((nowc == 'J' || nowc == '?') && i % W != W - 1)
				{
					dp[t][conv[nxt + 1]][1][0] += dp[s][j][0][0];
					dp[t][conv[nxt + 1]][1][1] += dp[s][j][0][1];

					dp[t][conv[nxt + 1]][1][0] %= 100000;
					dp[t][conv[nxt + 1]][1][1] %= 100000;

					dp[t][conv[nxt]][1][0] += dp[s][j][1][0];
					dp[t][conv[nxt]][1][1] += dp[s][j][1][1];
				}
				else
				{
					dp[t][conv[nxt]][1][0] += sum0;
					dp[t][conv[nxt]][1][1] += sum1;
				}
			}

			if (nxtc == 'I' || nxtc == '?')
			{
				if (bits[j] & (1 << (W - 2)))
				{
					dp[t][conv[nxt]][1][1] += sum0;
				}
				else
				{
					dp[t][conv[nxt]][1][0] += sum0;
				}

				dp[t][conv[nxt]][1][1] += sum1;
			}

			dp[t][conv[nxt]][1][0] %= 100000;
			dp[t][conv[nxt]][1][1] %= 100000;
		}
	}

	int ret = 0;

	for (int i = 0; i < maxbits; i++)
	{
		ret += dp[(H * W - 1) % 2][i][0][1];
		ret += dp[(H * W - 1) % 2][i][1][1];

		ret %= 100000;
	}

	printf("%d\n", ret);

	return 0;
}

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

int main(){
  vector<int> path(4);
  for(int i=0;i<3;i++){
    int a,b; cin>>a>>b;
    a--; b--;
    path[a]++;
    path[b]++;
  }sort(path.begin(),path.end());
  if(path[0]==1 && path[1]==1 && path[2]==2){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 1005;
int n, m, a, b;

int read() {
  if (scanf("%d%d%d%d", &n, &m, &a, &b) < 4) {
    return false;
  }
  return true;
}

char ans[maxn][maxn];

void solve() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans[i][j] = '.';
    }
    ans[i][m] = 0;
  }
  int n0 = n, m0 = m;
  if (n & 1) {
    for (int i = 0; i + 1 < m && a; i += 2) {
      ans[n - 1][i] = '<';
      ans[n - 1][i + 1] = '>';
      a--;
    }
    n--;
  }
  if (m & 1) {
    for (int i = 0; i + 1 < n && b; i += 2) {
      ans[i][m - 1] = '^';
      ans[i + 1][m - 1] = 'v';
      b--;
    }
    m--;
  }
  for (int i = 0; i < n; i += 2) {
    for (int j = 0; j < m; j += 2) {
      if (a == 1 && b == 1 && i + 2 == n && j + 2 == m && n < n0 && m < m0) {
        ans[i][j] = '^';
        ans[i + 1][j] = 'v';
        ans[i][j + 1] = '<';
        ans[i][j + 2] = '>';
        ans[i + 1][j + 1] = '.';
        ans[i + 1][j + 2] = '^';
        ans[i + 2][j + 2] = 'v';
        ans[i + 2][j] = '<';
        ans[i + 2][j + 1] = '>';
        a--;
        b--;
        continue;
      }
      if (a >= 2) {
        for (int it = 0; it < 2 && a; it++) {
          ans[i + it][j] = '<';
          ans[i + it][j + 1] = '>';
          a--;
        }
        continue;
      }
      if (b >= 2) {
        for (int it = 0; it < 2 && b; it++) {
          ans[i][j + it] = '^';
          ans[i + 1][j + it] = 'v';
          b--;
        }
        continue;
      }
      if (a) {
        for (int it = 0; it < 2 && a; it++) {
          ans[i + it][j] = '<';
          ans[i + it][j + 1] = '>';
          a--;
        }
        continue;
      }
      if (b) {
        for (int it = 0; it < 2 && b; it++) {
          ans[i][j + it] = '^';
          ans[i + 1][j + it] = 'v';
          b--;
        }
        continue;
      }
    }
  }
  if (a || b) {
    printf("NO\n");
    return;
  }
  printf("YES\n");
  for (int i = 0; i < n0; i++) {
    printf("%s\n", ans[i]);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 2176
/*Keyence Programming Contest 2020*/
/*D*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;

#define LL long long
#define DB double
#define MOD 59393
#define Pr pair<DB,int>
#define X first
#define Y second
#define MAXN 18
#define INF 1000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}

int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return 1LL*a*b%MOD;}

int n,a[MAXN+5],b[MAXN+5],ans;
struct node{
    int val,pos;
}A[MAXN+5],B[MAXN+5],C[MAXN+5];
bool cmp(node s1,node s2){
    if(s1.val==s2.val)return s1.pos<s2.pos;
    return s1.val<s2.val;
}

int lowbit(int x){return x&(-x);}
int bitcnt(int S){
    int res=0;
    while(S)res++,S-=lowbit(S);
    return res;
}

int main()
{
    n=read(),ans=INF;
    for(int i=1;i<=n;i++)
    a[i]=read();
    for(int i=1;i<=n;i++)
    {b[i]=read();if(i%2==0)swap(a[i],b[i]);}
    for(int S=0;S<(1<<n);S++){
        if(bitcnt(S)!=(n+1)/2)continue;
        int F=0,res=0,cnt1=0,cnt2=0;
        for(int i=1;i<=n;i++)
        if(S&(1<<(i-1)))A[++cnt1]=(node){a[i],i};
        else B[++cnt2]=(node){b[i],i};
        sort(A+1,A+cnt1+1,cmp);
        sort(B+1,B+cnt2+1,cmp);
        for(int i=1;i<=n;i++)
        if(i%2==1)C[i]=A[(i/2)+1];
        else C[i]=B[i/2];
        for(int i=2;i<=n;i++)
        if(C[i-1].val>C[i].val)
        {F=1;break;}
        if(F)continue;
        /*for(int i=1;i<=n;i++)
        printf("%d ",C[i].pos);puts("");*/
        for(int i=1;i<=n;i++)
            for(int j=1;j<i;j++)
            if(C[i].pos<C[j].pos)res++;
        ans=min(ans,res);
    }
    if(ans==INF)printf("-1\n");
    else printf("%d\n",ans);
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
# 整数の入力
k = int(input())
# スペース区切りの整数の入力
a, b = map(int, input().split())

d = a % k
e = k - d

if (a % k == 0) or ((a + e) <= b):
    print('OK')
else:
    print('NG')


Measured memory_bytes: 9072
#include <iostream>

using namespace std;

int main() {
  string s, pre, now;
  int ans = 1;
  cin >> s;
  pre = s[0];

  for (int i = 1; i < s.size(); i++) {
    now = s[i];
    if (pre == now) {
      i++;
      if (i == s.size()) break;
      pre = s.substr(i, 2);
    } else {
      pre = now;
    }
    //cout << i << ", " << pre << endl;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

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 = 1LL << 60;

int main(){
    int n,k;
    cin >>n>>k;
    vector <ll> h(100010);
    vector <ll> dp(100010);

    rep(i,n) cin >> h.at(i) ;
    rep(i,100010) dp.at(i) =INF;
    ll x;
    dp[0] = 0;

    for (int i = 1; i<n;++i){
        for(int j = 1;j<=k;j++){
            if(i-j < 0){
                break;
            }
            chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            x = dp[i];
        }
    }

    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1792
#ABC78
x, y = map(str, input().split())
x = int(x.replace("A","10").replace("B","11").replace("C","12").replace("D","13").replace("E","14").replace("F","15"))
y = int(y.replace("A","10").replace("B","11").replace("C","12").replace("D","13").replace("E","14").replace("F","15"))
if(x<y):
    print("<")
elif(x==y):
    print("=")
else:
    print(">")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll N;
    cin>>N;
    
    vector<ll> t(N);
    REP(i,N){
        cin>>t[i];
    }
    sort(ALL(t),greater<ll>());
    ll m=t[0];
    REP1(i,N-2){
        m+=t[(i+1)/2];
    }
    cout<<m;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

 using namespace std;
 int main() {
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   if (abs(a - c) <= d) cout << "Yes" << endl;
   else if (abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
   else cout << "No" << endl;
 }


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  float ans;
  ans = ((float) w*(float) h)/2;
  cout << (float) ans << " ";
  
  if(((w % 2) ==0) && ((h %2) ==0) && (x == (w/2)) && (y == (h/2))){
      cout << 1 << endl;
  }else{
      cout << 0 << endl;
  }
  return 0;
}  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		int n=sc.nextInt();
		int k=(int) Math.sqrt(2*n);
		while(true){
			int sum=(1+k)*k/2;
			if(sum<n)
				++k;
			else
				break;
		}
		System.out.println(k);
	}
}


Measured memory_bytes: 23892
#include<stdio.h>
int main(){
    char S[4];
    int count = 0;
    
    scanf("%s",S);
    for(int i = 0 ; i < 4 ; i++){
        if(S[i] == '+'){
            count++;
        }else{
            count--;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
    return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
    return n = n | (1LL << pos);
}

ll dp[3003][3003][4];
ll val[3003][3003];
ll r, c;

ll solve(ll rr, ll cc, ll took)
{
    ll &ret = dp[rr][cc][took];

    if(ret != -1) return ret;

    if(rr > r || cc > c) return ret = 0;

    if(val[rr][cc] == -1)
    {
		return ret = max(solve(rr + 1, cc, 0), solve(rr, cc + 1, took));

    }

    ret = 0;

    if(took != 3)
    {
        ret = max(ret, solve(rr, cc + 1, took + 1) + val[rr][cc]);
    }

    ret = max(ret, solve(rr, cc + 1, took));


    ret = max(ret, solve(rr + 1, cc, 0) + (took == 3 ? 0 : val[rr][cc]));


//	cout << rr << " " << cc << " " << took << " = " << ret << endl;

    return ret;
}

int main()
{
    ll i, j, k, l, m, n, o, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

	fastio;
    while(cin >> r >> c >> n)
    {
        memset(dp,-1,sizeof dp);
        memset(val,-1,sizeof val);

        for(ll i = 1; i <= n; i++)
        {
            ll x, y;

            cin >> x >> y >> val[x][y];
        }

        ans = solve(1,1,0);

        cout << ans << "\n";
    }


}





Measured memory_bytes: 356340
#include <iostream>
using namespace std;
 
int main(){
int a,b;
char op;
cin >> a >> op >>b;
while(op != '?'){
    switch(op){
        case '+':
            cout << a+b << endl;
            break;
        case '-':
            cout << a-b << endl;
            break;
        case '*':
            cout << a*b << endl;
            break;
        case '/':
            cout << a/b << endl;
            break;
    }
    cin >> a >> op >> b;
}
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	string a;
	int n, k; cin >> n >> k >> a;
	a[k - 1] += (int)('a') - 'A';
	cout << a << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String[] args) throws IOException {
        final String s;
        try (BufferedReader reader =
                 new BufferedReader (new InputStreamReader (System.in))) {
            s = reader.readLine();
        }
        int           N    = Integer.parseInt (s);
        StringBuilder sb   = new StringBuilder();
        int           base = 2;
        while (0 != N) {
            // base = 3 でうまくいかない
            // 例えば 7
            // base = 2 は OK
            // sb.insert (0, String.valueOf (Math.abs (N % base)));
            // N -= Math.abs (N % base);
            // N /= -base;

            // base = 3 でもうまくいく
            // 最小非負剰余
            sb.insert (0, String.valueOf ((N % base + base) % base));
            N -= (N % base + base) % base;
            N /= -base;
        }
        if (sb.length() == 0) sb.append ("0");
        System.out.println (sb);
    }
}


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

using namespace std;



int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, M, Q;
  cin >> N >> M >> Q;

  vector<vector<int>> endpoints(N+1);

  for (int i = 0; i < M; ++i)
  {
    int Li, Ri;
    cin >> Li >> Ri;
    endpoints[Li].push_back(Ri);
  }

  for (int i = 1; i <= N; ++i)
    sort(endpoints[i].begin(), endpoints[i].end());

  for (int i = 0; i < Q; ++i)
  {
    int pi, qi;
    cin >> pi >> qi;
    int res = 0;
    while (pi <= qi)
    {
      res += upper_bound(endpoints[pi].begin(), endpoints[pi].end(), qi) - endpoints[pi].begin();
      ++pi;
    }
    cout << res << "\n";
  }

  return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define MAXM 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m;
vector<int> G[MAXN];
int color[MAXN];
int iso,bip,nbip;
bool dfs(int v,int c)
{
    color[v]=c; bool f=true;
    for(auto to:G[v])
    {
        if(color[to]==c) f=false;
        if(!color[to]&&!dfs(to,-c)) f=false;
    }
    return f;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v); G[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
    {
        if(color[i]==0)
        {
            if((int)G[i].size()==0) iso++;
            else if(dfs(i,1)) bip++; else nbip++;
        }
    }
    ll ans=1LL*iso*(2*n-iso)+2LL*bip*nbip+2LL*bip*bip+1LL*nbip*nbip;
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 8448
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
char s[111];

int main() {
	scanf("%d", &n);
	
	int first_b = 0, end_a = 0, ans=0, f = 1;
	for(int i=0;i<n;i++) {
		scanf("%s", s);
		int l = strlen(s);
		
		int x = 0;
		if(s[0]=='B') { first_b ++; x ++; }
		if(s[l-1] == 'A') { end_a ++; x ++; }
		if(x==1) f = false;
		
		for(int j=1;j<l;j++)
			if(s[j-1]=='A' && s[j]=='B') ans++;
	}
	ans += max(0, min(first_b, end_a)-f);
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	stack
# CreatedDate:  2020-05-22 23:23:23 +0900
# LastModified: 2020-05-22 23:46:42 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    n,q = map(int,input().split())
    stack = [[] for _ in range(n)]
    for _ in range(q):
        order = list(map(int,input().split()))

        if order[0]==0:
            stack[order[1]].append(order[2])
        elif order[0]==1:
            if len(stack[order[1]])!=0:
                print(stack[order[1]][-1])
        else:
            if len(stack[order[1]])!=0:
                stack[order[1]].pop(-1)


if __name__ == "__main__":
    main()



Measured memory_bytes: 13704
S = input()
T = input()

found = []
for i in range(len(S) - len(T) + 1):
  for cs, ct in zip(S[i:], T):
    if cs != '?' and cs != ct:
      break
  else:
    found.append(i)

if not found:
  print("UNRESTORABLE")
  exit()

ans = 'z'  * 51

for i in found:
  tmp = S[:i] + T + S[i+len(T):]
  ans = min(ans, tmp.replace("?", "a"))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;


int main()
{	

	string date;
	cin >> date;
	//cout << date << "\n";
	date.erase(date.begin()+4);
	//cout << date << "\n";
	date.erase(date.begin()+6);
	//cout << date << "\n";


	int d = atoi(date.c_str());;
	//cout << d << "\n";

	if(d <= 20190430){
		cout << "Heisei\n";
	}
	else {
		cout << "TBD\n";
	}

	return 0;
}

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

int main(){
while(1){
int n;
scanf("%d",&n);
if(n==0)break;
char f[1002];
for(int i=0;i<1002;i++)f[i]=(char)i;
for(int i=0;i<n;i++){
char c,d;
scanf("\n%c %c",&c,&d);
f[(int)c] = d;
}
int m;
scanf("%d",&m);
for(int i=0;i<m;i++){
char c;
scanf("\n%c",&c);
printf("%c",f[(int)c]);
}
printf("\n");
}
}

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

int main(){
  int N;
  cin >> N;
  
  map<string, int> mp;
  int m = 0;
  for(int i = 0; i < N; i++){
    string a;
    cin >> a;
    mp[a]++;
    m = max(m,mp[a]);
  }
  
//  cout << m << endl;
  for(auto p : mp){
    auto k = p.first;
    auto v = p.second;
    if(v == m){
      cout << k << endl;
    }
  }
}

Measured memory_bytes: 25216
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const L = 18 , N = L + 2 , MASK = (1 << L) + 20 , inf = 1e9 + 20 ;
int n , a[MASK] ;
int mx1[N][MASK] , mx2[N][MASK] ;
int dp[N][MASK] ;

inline void add (int bit , int cur , int val) {
	mx2[bit][cur] = max(mx2[bit][cur] , val) ;
	if (mx2[bit][cur] > mx1[bit][cur]) swap(mx1[bit][cur] , mx2[bit][cur]) ;	
}

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

	for (int i = 0 ; i < N ; i ++) {
		fill(mx1[i] , mx1[i] + MASK , -inf) ;
		fill(mx2[i] , mx2[i] + MASK , -inf) ;
	}

	cin >> n ;

	for (int i = 0 ; i < (1 << n) ; i ++) {
		cin >> a[i] ;
		int cur = 0 ;

		for (int bit = n - 1 ; bit >= 0 ; bit --) {
			cur += (i & (1 << bit)) ;

			add(bit , cur , a[i]) ;
		}
	}

	for (int i = 0 ; i < n ; i ++) {
		for (int j = n - 1 ; j >= i ; j --) {
			for (int mask = 0 ; mask < (1 << n) ; mask ++) {
				if (mask & (1 << j)) {
					add(i , mask , mx1[i][mask ^ (1 << j)]) ;
					add(i , mask , mx2[i][mask ^ (1 << j)]) ;
				}
			}
		}
	}

	for (int k = 1 ; k < (1 << n) ; k ++) {
		int cur = 0 , ans = 0 ;

		for (int bit = n - 1 ; bit >= 0 ; bit --) {
			if (k & (1 << bit)) {
				ans = max(ans , mx1[bit][cur] + mx2[bit][cur]) ;
				cur += (1 << bit) ;
			}
		}
		
		ans = max(ans , mx1[0][cur] + mx2[0][cur]) ;
	
		cout << ans << '\n' ;
	}
}

Measured memory_bytes: 45056
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  int h[N];
  for (int i = 0; i < N; i++)
  {
    cin >> h[i];
  }
  sort(h, h + N);
  int ans = 1000000001;
  for (int i = 0; i <= N - K; i++)
  {
    int tmp = h[i + K - 1] - h[i];
    if (tmp < ans)
    {
      ans = tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    while (1) {
        int n; cin >> n;
        if (!n) break;

        vector<string> S(n);
        loop (n, i) cin >> S[i];

        vector<int> P(n), Ns(n), crr(n);
        loop (n, i) {
            int nst = 0;
            while (S[i][nst] == '.') nst++;
            Ns[i] = nst;
            if (nst) P[i] = crr[nst-1];
            else P[i] = -1;
            crr[nst] = i;

            loop (nst, j) S[i][j] = ' ';
            if (nst) S[i][nst-1] = '+';
        }

        loop (n, i) loop (n, j) {
            if (i >= j || P[i] != P[j]) continue;
            for (int k = i+1; k < j; k++) {
                if (P[i] != P[k]) S[k][Ns[P[i]]] = '|';
            }
        }

        for (auto s : S) cout << s << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long int lli;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

int main()
{
    fast;
    int t = 1;
    while (t--)
    {
        int h, w, m;
        cin >> h >> w >> m;

        vector<int> f1(h + 1);
        vector<int> f2(w + 1);
        unordered_map<int, unordered_set<int>> mp2;
        int maxx = 0, maxy = 0;
        for (int i = 0; i < m; i++)
        {
            int x, y;
            cin >> x >> y;
            mp2[x].insert(y);
            f1[x]++;
            f2[y]++;
            maxx = max(maxx, f1[x]);
            maxy = max(maxy, f2[y]);
        }
        int ans = maxx + maxy - 1;
        vector<int> v1, v2;
        for (int i = 1; i <= h; i++)
        {
            if (f1[i] == maxx)
                v1.push_back(i);
        }
        for (int i = 1; i <= w; i++)
        {
            if (f2[i] == maxy)
                v2.push_back(i);
        }
        bool f = 0;
        for (auto i : v1)
        {
            for (auto j : v2)
            {
                //cout << i << " " << j << "\n";
                if (mp2[i].find(j) == mp2[i].end())
                {
                    ans++;
                    f = 1;
                    break;
                }
            }
            if (f)
                break;
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 55980
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	if (n%10==2||n%10==4||n%10==5||n%10==7||n%10==9) cout<<"hon"<<endl;
	if (n%10==0||n%10==1||n%10==6||n%10==8) cout<<"pon"<<endl;
	if (n%10==3) cout<<"bon"<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll ab = a + b;
	ll r = 0;

	if (a == 0)
		r = 0;
	else if (a >= n || b == 0)
		r = n;
	else if (ab >= n)
		r = a;
	else
		r = ((n / ab) * a) + (n % ab > a ? a : n % ab);

	printf("%lld", r);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,t,l,b;
int f[150];//1:lose/2:restart/
double dp[150][150];
double ans;
void reset(){
	ans=0.0;
	for(int i=0;i<22500;i++)dp[i/150][i%150]=0;
	for(int i=0;i<150;i++)f[i]=0;
	dp[0][0]=1.0;
	for(int i=0,j;i<l;i++){
		cin>>j;
		f[j]=1;
	}
	for(int i=0,j;i<b;i++){
		cin>>j;
		f[j]=2;
	}
}

int main(){
	while(cin>>n>>t>>l>>b,n){
		reset();
		for(int i=0;i<t;i++){
			for(int j=0;j<n;j++){
				if(dp[i][j]<1e-9)continue;
				for(int d=1;d<=6;d++){
					int nxn=j+d,nxt=i+1;
					if(nxn>n)nxn=n+n-nxn;
					if(f[nxn]==1)nxt++;
					else if(f[nxn]==2)nxn=0;
					dp[nxt][nxn]+=dp[i][j]*(1.0/6.0);
				}
			}
		}
		for(int i=0;i<=t;i++)ans+=dp[i][n];
		printf("%.8f\n",ans);
	}
	
	return 0;
}


Measured memory_bytes: 1364
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <deque>
using namespace std;

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

class Edge{
public:
  int x;
  int y;
  ll d;
  Edge(){}
  Edge(int st, int go, ll dis):x(st),y(go),d(dis){}
  void set(int st, int go, ll dis){
    x=st;y=go;d=dis;
  }
  bool operator <(const Edge& f){return x<f.x;}
};

ll loc[100010]={};
bool used[100010]={};
queue<Edge> e[200010];
bool ans=true;


void dfs(int x){
  while(!e[x].empty()){
    Edge f;
    f=e[x].front();e[x].pop();
    if(!used[f.y]){
      used[f.y]=true;
      loc[f.y]=loc[x]+f.d;
      dfs(f.y);
    }else{
      if(loc[f.y]!=loc[x]+f.d){
         ans=false;
         return;
      }
    }
  }
  return;
}

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    ll d;
    cin>>x>>y>>d;
    Edge f(x, y, d);
    e[x].push(f);
    f.set(y,x,-d);
    e[y].push(f);
  }
  for(int x=0;x<n;x++){
    if(!used[x]){
      used[x]=true;
      loc[x]=0;
      dfs(x);
    }
  }
  cout<<(ans?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 140032
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!
ll N, K, dislike[11];

ll IROHA_not_like(ll N){
    while(N){
        ll x=N%10;
        if(dislike[x]==1) return 1;
        N /= 10;
    }
    return 0;
}
int main(void){
    ll d;
    scanf("%lld %lld", &N, &K);
    rep(i, K) {
        scanf("%lld", &d);
        dislike[d] = 1;
    }
    while(IROHA_not_like(N)) N++;
    printf("%lld\n", N);
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  vector<int> all;
  REP(i, N) REP(j, a[i]) all.push_back(i + 1);
  int ans[H][W];
  int cnt = 0;
  bool right = true;
  int y = 0, x = 0;
  REP(i, H * W) {
    ans[y][x] = all[i];
    if (right) {
      if (x != W - 1)
        x++;
      else {
        y++;
        right = false;
      }
    } else {
      if (x != 0)
        x--;
      else {
        y++;
        right = true;
      }
    }
  }
  REP(i, H) {
    REP(j, W) {
      if (j != 0) cout << " ";
      cout << ans[i][j];
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 512
// C - Green Bin

// Mapによるカウント

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string S[100001];
map<string, int> cnt;

int main(){
	int N;
	cin >> N;

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

	for (int i=0; i<N; i++) {
		sort(S[i].begin(), S[i].end());
	}

	ll ans = 0;

	for (int i=0; i<N; i++) {
		if (cnt[S[i]] > 0) {
			ans += cnt[S[i]];
		}

		cnt[S[i]]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 18176
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = list(map(int,input().split()))
uf = UnionFind(N)
for _ in range(M):
  A,B = list(map(int,input().split()))
  uf.union(A-1,B-1)
print(abs(min(uf.parents)))



Measured memory_bytes: 80268
#include<bits//stdc++.h>
using namespace std;
int main(){
	int n;
	int a[1000];
	while(cin>>n&&n!=0){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		int m=10000000;
		for(int i=1;i<n;i++){
			m=min(a[i]-a[i-1],m);
		}
		cout<<m<<endl;							
	}
}

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

int main(){

  int a,b,c;
  cin>>a>>b>>c;
  
  if(a>b){
    a += b;
    b = a-b;
    a -= b;
  }
  
  if(b>c){
    b += c;
    c = b-c;
    b -= c;
  }

  if(a>b){
    a += b;
    b = a-b;
    a -= b;
  }

  cout<<a<<" "<<b<<" "<<c<<endl;
  
  return 0;
}



Measured memory_bytes: 3100
def main():
    N, D = map(int, input().split())
    cnt = 0

    for _ in range(N):
        x, y = map(int, input().split())
        if x ** 2 + y ** 2 <= D ** 2:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
using System;
class main
{
    static void Main(string[] args)
    {
        int[] a = new int[10];

        for (int i = 0; i < a.Length; ++i)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(a);
        Array.Reverse(a);
        for (int i = 0; i < 3; ++i)
        {
            Console.WriteLine(a[i]);
        }
        //Console.ReadKey();
    }
}

Measured memory_bytes: 5756
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int d,g;
	cin>>d>>g;
	vector<int> p,c;
	for(int i=0;i<d;i++){
		int x,y;
		cin>>x>>y;
		p.pb(x);c.pb(y);
	}
	int ans = inf;
	for(int i=0; i < (1<<d) ; i++){
		int cur = i;
		int tmp = 0;
		int sc = 0;
		vector<int> used;
		for(int j=0;j<10;j++){
			used.pb(0);
		}
		for(int j=0;j<d;j++){
			if(cur % 2 == 1){
				tmp += p[j];
				sc += p[j] * 100 * (j+1);
				sc += c[j];
				used[j]=1;
			}
			cur = cur/2;
		}
		for(int j=d-1;j>=0;j--){
			if(used[j] == 0 && sc < g){
				int cnt = (g - sc) / (100 * (j+1) );
				if( (g-sc) % (100*(j+1)) != 0)cnt++;
				tmp += min( p[j], cnt);
				sc += min(p[j],cnt) * 100 * (j+1);
			}
		}
		if( tmp < ans )ans = tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int N,L,i;
    cin>>N>>L;
    string S[N];
    for(i=0;i<N;i++)
    {
        cin>>S[i];
    }
    sort(S,S+N);
    for(i=0;i<N;i++)
    {
        cout<<S[i];
    }
    cout<<endl;
}



Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<P> a;
  rep(i,n){
    int ai;
    cin >> ai;
    a.emplace_back(ai,i);
  }
  sort(a.rbegin(),a.rend());

  vector<ll> dp(n+1);
  rep(i,n){
    vector<ll> temp(n+1);
    rep(l,i+1){
      int r = i-l;
      temp[l+1] = max(temp[l+1],dp[l]+a[i].first*ll(a[i].second-l));
      temp[l] = max(temp[l],dp[l]+a[i].first*ll(n-r-1 - a[i].second));
    }
    swap(dp,temp);
  }
  ll ans = 0;
  rep(i,n+1) ans = max(ans,dp[i]);
  cout << ans << endl;
}


Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    vector<int> a(8);
    for(int i=0; i<8; i++) scanf("%1d",&a[i]);
    sort(a.begin(),a.end());
    int m = 0,M = 0;
    for(int i=0; i<8; i++){
      m = m*10+a[i];
      M = M*10+a[7-i];
    }
    cout <<M-m<<endl;
  }
  return 0;
}

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

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    n, y = MI()
    result = "-1 -1 -1"
    for i in range(n, -1, -1):
        a = i * 10000
        if a <= y:
            for j in range(n-i, -1, -1):
                b = a + j * 5000
                if b <= y:
                    if b + 1000 * (n-i-j) == y:
                        result = str(i)+" "+str(j)+" "+str(n-i-j)
                        print(result)
                        sys.exit()
    print(result)

main()

Measured memory_bytes: 39152