akhauriyash/Code-Regression huggingface dataset:
def d_robot_arms(N, Pos):
    # 参考: http://drken1215.hatenablog.com/entry/2018/09/30/002900

    pos = []
    # すべての座標でパリティが一致しなければ、条件を満たす腕を選べない
    parity = (abs(Pos[0][0]) + abs(Pos[0][1])) % 2
    for x, y in Pos:
        parity_current = (abs(x) + abs(y)) % 2
        if parity != parity_current:
            return -1
        pos.append((x - y, x + y))
        # u=x-y, v=x+y とすると、 点(u, v)は
        # 原点周りに45度回転させて距離√2倍にする座標変換で点(x, y)から移される点
        # あるいはu軸, v軸はx軸, y軸をそれぞれ原点周りに-45度回転させた軸

    # log2(10**9)=29.90 なので、2**30以下の2の冪乗を適当に選べば
    # xy平面上の x+y が奇数である任意の座標に到達できる
    arms = [1 << k for k in range(30, -1, -1)]
    if parity % 2 == 0:
        arms.append(1)  # x+yが偶数である座標に到達するときに必要

    # 腕の数, 長さのリストを最初に格納する(任意の入力に対して固定)
    ans_tmp = [str(len(arms)), ' '.join(list(map(str, arms)))]

    for u_pos, v_pos in pos:
        # u, v座標はそれぞれ独立に見て構わない
        u_sum, v_sum = 0, 0
        tmp = ''
        for arm_len in arms:
            u_dir = 1 if u_sum <= u_pos else -1
            u_sum += u_dir * arm_len

            v_dir = 1 if v_sum <= v_pos else -1
            v_sum += v_dir * arm_len

            # uv平面で軸と平行にどちら向きに移動するかと
            # xy平面での移動モード(UDLR)との対応
            if u_dir == 1 and v_dir == 1:
                tmp += 'R'
            elif u_dir == 1 and v_dir == -1:
                tmp += 'D'
            elif u_dir == -1 and v_dir == -1:
                tmp += 'L'
            else:
                tmp += 'U'
        ans_tmp.append(''.join(tmp))
    ans = '\n'.join(ans_tmp)
    return ans

N = int(input())
Pos = [[int(i) for i in input().split()] for j in range(N)]
print(d_robot_arms(N, Pos))

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

vector<int> vi;

int main()
{
    int A, B, X;
    cin >> A >> B >> X;

    if (X < A)
    {
        cout << "NO" << endl;
    }
    else if (X < A + B)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while (1){
    C -= B;
    if(C <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if(A <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	ll ans=0;
	rep(i,1<<(n-1)){
		int pos=0;
		rep(j,s.size()-1){
			if(i&1<<j){
				ans+=stoll(s.substr(pos,j-pos+1));
				pos=j+1;
			}
		}
		ans+=stoll(s.substr(pos,s.size()-pos));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,K;
    cin >> N >> K;
    int ans = 1;
    vector<int> a(N),b(N);
    rep(i,N)cin >> a[i];
    b[0] = 1;
    for(int i=1;i<N;i++){
        if(a[i]>a[i-1])b[i] = b[i-1] + 1;
        else b[i] = 1;
    }
    set<int> st;
    rep(i,K)st.insert(a[i]);
    bool f = K==b[K-1];
    for(int i=K;i<N;i++){
        st.insert(a[i]);//i番目の数を入れる
        int mx = *st.rbegin();
        int mn = *st.begin();
        st.erase(a[i-K]);//一番左の数を捨てる
        
        if(mx==a[i] && mn == a[i-K])continue;
        if(b[i]!=K)ans++;
        else if(!f){
            ans++,f=1;
        } 
    }
    cout << ans << endl;
}


Measured memory_bytes: 11264
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N=100005;
typedef long long ll;
using namespace std;
int fs[N],nt[2*N],dt[2*N],n,m,sz[N],mw,mi,m2;
ll pr[2*N],ans;
void link(int x,int y,int z){nt[++m]=fs[x];dt[fs[x]=m]=y;pr[m]=z;}
void dfs(int k,int fa){
    sz[k]=1;int mx=0;
    for(int i=fs[k];i;i=nt[i]){
        int p=dt[i];
        if(p!=fa){
            dfs(p,k);
            sz[k]+=sz[p];
            mx=max(mx,sz[p]);
            ans+=(ll)min(sz[p],n-sz[p])*pr[i]*2ll;
        }
    }
    if(max(mx,n-sz[k])==mi)m2=k;
    if(max(mx,n-sz[k])<mi)mi=max(mx,n-sz[k]),mw=k,m2=0;
}
int main(){
    scanf("%d",&n);mi=n;
    for(int i=1,x,y,z;i<n;i++){
        scanf("%d%d%d",&x,&y,&z);
        link(x,y,z),link(y,x,z);
    }
    dfs(1,0);
    if(m2==0){
        mi=0x3f3f3f3f;
        for(int i=fs[mw];i;i=nt[i])mi=min(mi,(int)pr[i]);
        ans-=mi;
    }
    else
        for(int i=fs[mw];i;i=nt[i])
            if(dt[i]==m2){ans-=pr[i];break;}
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 9344
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,x,ans;
    cin >> n >> x;
    ans = n;
    vector<int> m(n);
    for(int i=0;i<n;i++){
            cin >> m[i];
            x-=m[i];
    }
    sort(m.begin(),m.end());
    ans += int(x/m[0]);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pp printf("Case %d: \n",t)
const unsigned int mod = 1e9+7;
const int mx=2005;
const int maxInt = 2147483647;
ll pascal[mx][mx];
ll k,n;
int main(){
  	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> n >> k;
	for(int i=0;i<mx;++i){
		pascal[i][0]=1;
		for(int j=1;j<=i;++j){		
			pascal[i][j]=(pascal[i-1][j]+pascal[i-1][j-1])%mod;
		}
	}
	for(int i=1;i<=k;++i){
		cout << (pascal[n-k+1][i]*pascal[k-1][i-1])%mod << endl;
	}
	return 0;
}


Measured memory_bytes: 30208
#!/usr/bin/env python3

import collections


def main():
    k, t = (int(x) for x in input().split())
    ctr = collections.Counter(dict(enumerate(int(a) for a in input().split())))
    pred = -1
    ans = 0
    sign = True
    for _ in range(k):
        if sign:
            mc = ctr.most_common()
        else:
            mc = ctr.most_common()[::-1]
        for k, v in mc:
            if k != pred and v > 0:
                pred = k
                ctr[k] = v - 1
                break
        else:
            ans += 1
            ctr[pred] -= 1
        sign = not sign
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count = 1;
    if (b != a) {
      count += 1;
    }
    if (c != a && c != b) {
      count += 1;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21972
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
let n = Number(input[0]);
input.shift();
let R = input.map(Number);
let maxv = R[1] - R[0];
let minv = R[0];
for(let j = 1; j <= n - 1; j++) {
    if (maxv < R[j] - minv) {
        maxv = R[j] - minv;
    }
    if (minv > R[j]) {
        minv = R[j];
    }
}
console.log(maxv);
 


Measured memory_bytes: 40656
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define INF 1000000000000LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	ll x,y;
	scanf("%lld %lld",&x,&y);
	ll ret=INF;
	if(x<=y) ret=min(ret,y-x);
	if(x<=-y) ret=min(ret,-y-x+1);
	if(-x<=y) ret=min(ret,y+x+1);
	if(-x<=-y) ret=min(ret,-y+x+2);
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio> 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
using namespace std;
/*---------------------------------------------------*/

int main(){
  int n,u,k,v;
  int g[105][105]={};
  scanf("%d",&n);
  rep(i,n){
    scanf("%d%d",&u,&k);
    rep(i,k){
      scanf("%d",&v);
      g[u][v]=1;
    }
  }
  REP(i,1,n+1){
    printf("%d",g[i][1]);
    REP(j,2,n+1){
      printf(" %d",g[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
typedef pair<int, int> P;

int n;

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

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

int power(int a, int n) {
	if (n == 0) return 1;
	if (n & 1) return a * power(a, n - 1);
	return power(a * a, n / 2);
}

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n & 1) return (a * powmod(a, n - 1, mod)) % mod;
	return powmod((a * a) % mod, n / 2, mod);
}

vector<P> factorize(int n) {
	int t = n;
	vector<P> ret;
	
	for (int i = 2; i * i <= t; i++) {
		int cnt = 0;
		while (t % i == 0) {
			t /= i;
			cnt++;
		}
		if (cnt > 0) {
			ret.push_back(P(i, cnt));
		}
	}
	if (t > 1) {
		ret.push_back(P(t, 1));
	}
	return ret;
}

signed main() {
	cin >> n;
	if (n == 2) { cout << 1 << endl; return 0; }
	else if (n % 2 == 0) { cout << -1 << endl; return 0; }
	for (int m = 2; m * m <= n; m++) { if (n % (m * m) == 0) { cout << -1 << endl; return 0; } }
	
	vector<P> p = factorize(n);
	int L = 1;
	for (int i = 0; i < p.size(); i++) L = lcm(L, p[i].first - 1);
	vector<P> q = factorize(L);
	
	int ans = 1;
	for (int i = 0; i < q.size(); i++) {
		int a = power(q[i].first, q[i].second);
		if (gcd(n, a) != 1) { cout << -1 << endl; return 0; }
		int eq = a - power(q[i].first, q[i].second - 1);
		//eq????´???°???????£?
		int minK = eq;
		for (int k = 1; k * k <= eq; k++) {
			if (eq % k != 0) continue;
			if (powmod((n % a), k, a) == 1) minK = min(minK, k);
			if (powmod((n % a), eq / k, a) == 1) minK = min(minK, eq / k);
		}
		//lcm?????????
		ans = lcm(ans, minK);
	}
	cout << ans << endl;
	return 0;
}

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


#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define ll long long
#define all(v) v.begin(), v.end()

#define si set<int>
#define sl set<long long>

#define pair(x,y) pair<x, y>

#define frt(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rew(i,a,b) for(int i=a;i>=b;i--)

#define mod %
#define pow ^

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test if(TEST == 1)

#define left (2*idx)+1
#define right (2*idx)+2

#define INF 1000000000000000000
#define MOD (ll)(1e9 + 7)
#define N 7001

ll powerf(ll a, ll b, ll c)
{
    ll ans = 1;
    
    while(b>0)
    {
        if(b & 1)
        {
            ans = (ans * a) % c;
        }
        b = b >> 1;
        a = (a * a) % c;
    }
    
    return ans;}

int main()
{

    FIO
    int TEST = 0;
    int t = 1;

    // cin >> t;

    while(t--)
    {
        int n;
        cin >> n;

        vl v;
        ll sum = 0;
        frt(i, 0, n)
        {
            ll x;
            cin >> x;
            v.pb(x);
            sum+=x;
        }

        sort(all(v));
        
        int sign[n];
        sign[0] = -1;
        sign[n-1] = +1;

        int last = 0;
        frt(i, 1, n-1)
        {
            if(v[i] > 0)
            {
                sign[i] = 1;
            }
            else
            {
                last = i;
                sign[i] = -1;
            }
        }

        ll ans = 0;
        for(int i=0; i<n; i++)
        {
            ans+=(sign[i] * v[i]);
        }
        cout << ans << "\n";

        for(int i=last+1; i<n-1; i++)
        {
            cout << v[0] << " " << v[i] << "\n";
            v[0]-=v[i];
        }

        for(int i=1; i<=last; i++)
        {
            cout << v[n-1] << " " << v[i] << "\n";
            v[n-1]-=v[i];
        }

        cout << v[n-1] << " " << v[0] << "\n";


    }  
}




Measured memory_bytes: 3188
/*    BAJUKA     */
#include<bits/stdc++.h>
#define lld long long int
#define ve vector
#define rep(i,a,b) for(i=a;i<b;i++) 
#define per(i,a,b) for(i=b;i>=a;i--)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair


using namespace std;





int main()
{
	
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lld n,i,c,r,s,t[100003],a[100003],b[100003];
    cin>>n;
    t[0]=0;a[0]=0;b[0]=0;
    rep(i,1,n+1)
    {
    	cin>>t[i]>>a[i]>>b[i];
    }
    rep(i,1,n+1)
    {
       r=a[i]-a[i-1];
       s=b[i]-b[i-1];
       lld sm=r+s;
       lld tm=t[i]-t[i-1];
       if((r*r+s*s)>tm*tm)
       	{cout<<"No";exit(0);}
       if(sm%2==0)
       {
       	if(tm%2!=0)
       		{cout<<"No";exit(0);}
       }
       else
       {
       	if(tm%2==0)
       		{cout<<"No";exit(0);}
       }
    }
    cout<<"Yes";

    
}

Measured memory_bytes: 2560
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    aList := scanSpaceSpeparatedNumbers(n + 1)
    bList := scanSpaceSpeparatedNumbers(n)

    huntCount := 0
    for i, v := range bList {
        if v <= aList[i] {
            // 勇者が倒せる数がi町のモンスター以下の場合は勇者が倒せる数がその勇者の最大値
            huntCount += v
        } else {
            if v - aList[i] < aList[i + 1] {
                huntCount += v
                // 勇者がi町のモンスター以上を倒せる場合,i+1町のモンスターも余剰分倒すので数を変更する
                aList[i + 1] = (aList[i] + aList[i + 1]) - v
            } else {
                huntCount += aList[i] + aList[i + 1]
                // i, i+1の町モンスターが勇者が倒せるモンスターより少ない場合は町にいるモンスターの数すべて倒すので0に変更
                aList[i + 1] = 0
            }
        }
    }
    fmt.Println(huntCount)
}

func scanSpaceSpeparatedNumbers(n int) []int {
    aList := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&aList[i])
    }
    return aList
}



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

int main()
{
  string S, T;
  cin >> S >> T;

  bool ans = true;

  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) != T.at(i))
      ans = false;
  }

  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=200005,P=998244353;
char a[maxn];
int n,f[maxn][3][3][2],sum;

bool Allsame(){
  for(int i=2;i<=n;i++) if(a[i]!=a[i-1]) return false;
  return true;
}
bool NoAdjsame(){
  for(int i=2;i<=n;i++) if(a[i]==a[i-1]) return false;
  return true;
}
int main(){
  scanf("%s",a+1); n=strlen(a+1);
  if(Allsame()) return puts("1"), 0;
  if(n<=3){
    if(n==2) puts("2");
    else{
      if(a[1]!=a[2]&&a[1]!=a[3]&&a[2]!=a[3]) puts("3");
      else if(a[1]==a[3]) puts("7");
      else puts("6");
    }
    return 0;
  }
  for(int i=1;i<=n;i++) sum=(sum+a[i]-'a')%3;
  for(int i=0;i<=2;i++) f[1][i][i][0]=1;
  for(int i=1;i<=n-1;i++)
    for(int j=0;j<=2;j++)
      for(int k=0;k<=2;k++)
	for(int t=0;t<=1;t++)
	  for(int l=0;l<=2;l++) (f[i+1][l][(k+l)%3][t|(j==l)]+=f[i][j][k][t])%=P;
  printf("%d\n",((LL)f[n][0][sum][1]+f[n][1][sum][1]+f[n][2][sum][1]+NoAdjsame())%P);
  return 0;
}


Measured memory_bytes: 14464
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int printi(ll val){
	char ch;
	cout<<"? "<<val<<endl;
	cin>>ch;
	if(ch=='Y')
		return 1;
	return 0;
}
ll haha[100],lol[100];
int doreg(){
	ll low=0;
	ll high=9;
	ll mid;
	ll ans=0;
	while(low<=high){
		mid=(low+high)/2;
		if(printi(haha[mid])){
			ans=mid;
			//cout<<mid<<endl;
			low=mid+1;
		}
		else{
			high=mid-1;
		}
	}
	//cout<<ans<<endl;
	low=haha[ans];
	high=haha[ans+1]-1;
	while(low<=high){
		mid=(low+high)/2;
		if(printi(mid*10)){
			
			ans=mid;
			high=mid-1;
		}
		else{

			low=mid+1;
		}
	}
	cout<<"! "<<ans<<endl;
	return 0;

}
int brutecheck(){
	ll pres=9;
	//ll ans=1;
	ll i;
	rep(i,10){
		lol[i]=printi(pres);
		pres*=10;
		pres+=9;
	}

	rep(i,10){
		if(lol[i]==1)
			break;
	}
	cout<<"! "<<haha[i]<<endl;
	return 0;
}
int main(){
    std::ios::sync_with_stdio(false);
	ll inff=inf,i;
	inff-=5;
	inff*=10;
	haha[0]=1;
	f(i,1,11){
		haha[i]=haha[i-1]*10;
	}

	int val=printi(inff);     
    if(val==0){
    	doreg();
    	return 0;
    }
    else{
    	brutecheck();
    	return 0;
    }
}



Measured memory_bytes: 596
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int [] a=new int [n-1];
		for(int i=0;i<n-1;i++)
		{
		    a[i]=in.nextInt();
		}
		int ans=a[n-2];
		for(int i=n-2;i>0;i--)
		{
		    ans=ans+Math.min(a[i],a[i-1]);
		}
		ans=ans+a[0];
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

vector<string> lst={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
signed main() {
	string str;
	cin>>str;
	int pos=find(lst.begin(),lst.end(), str)-lst.begin();
	pos=-pos;
	pos+=7;
	pos%=7;
	if(pos==0) pos=7;
	cout<<pos<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = (ll)9223372036854775807;

ll H, W;

int main() {
    cin >> H >> W;
    ll prod = H*W;
    ll ans = inf;
    vector<ll> sum(3);
    if (!(H%3) || !(W%3)) {
        cout << 0 << endl;
        return 0;
    }

    ans = min(ans, H); ans = min(ans, W);

    ll temp = H - H/3;
    sum[0] = W*(H/3);
    sum[1] = (W/2)*temp;
    sum[2] = W*temp - sum[1];
    sort(sum.begin(), sum.end());
    ans = min(ans, sum[2]-sum[0]);

    temp -= 1;
    sum[0] = W*((H/3)+1);
    sum[1] = (W/2)*temp;
    sum[2] = W*temp - sum[1];
    sort(sum.begin(), sum.end());
    ans = min(ans, sum[2]-sum[0]);

    temp = W - W/3;
    sum[0] = H*(W/3);
    sum[1] = (H/2)*temp;
    sum[2] = H*temp - sum[1];
    sort(sum.begin(), sum.end());
    ans = min(ans, sum[2]-sum[0]);

    temp -= 1;
    sum[0] = H*((W/3)+1);
    sum[1] = (H/2)*temp;
    sum[2] = H*temp - sum[1];
    sort(sum.begin(), sum.end());
    ans = min(ans, sum[2]-sum[0]);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define M 1000000000
void printprecise(double l,ll precision)
{
    std::cout << std::fixed;
    std::cout << std::setprecision(precision);
    std::cout << l;
}

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

void initialize(ll ar[],ll n)
{
	for(ll x=0;x<n;x++)
		ar[x] = x;
}

void printarray(ll ar[],ll n)
{
	for(ll x=0;x<n;x++)
		cout<<ar[x]<<" ";
	cout<<endl;
}

void printvector(vector <char> v)
{
	for(ll x=0;x<v.size();x++)
	{
		cout<<v[x]<<" ";
	}
	cout<<endl;
}

ll root(ll i,ll ar[])
{
	while(ar[i]!=i)
	{
		ar[i] = ar[ar[i]];
		i = ar[i];
	}
	return i;
}

void unione(ll a,ll b,ll ar[])
{
	ll p = root(a,ar);
	ll q = root(b,ar);
	ar[p] = ar[q];
}

ll bfs(ll n,ll vis[],vector <ll> v[],ll level[])
{
	list <ll> g;
	g.pb(n);
	vis[n]=1;
	level[n]=1;
	while(!g.empty())
	{
		ll a = g.front();
		g.pop_front();
		for(ll x=0;x<v[a].size();x++)
		{
			if(vis[v[a][x]]==1 && v[a][x] != a) 
			{
				return level[a]-level[v[a][x]]+1;
			}
			else
			{
				g.pb(v[a][x]);
				vis[v[a][x]]=1;
				level[v[a][x]] = level[a]+1;
			}
		}
	}
	return 10000000;
}


int main()
{
	ll n;
	cin>>n;
	ll ar[3][n+1];
	for(ll x=1;x<=n;x++)
	{
		for(ll y=0;y<3;y++)
		{
			cin>>ar[y][x];
		}
	}

	for(ll x=n-1;x>=1;x--)
	{
		ar[0][x] = ar[0][x] + max(ar[1][x+1],ar[2][x+1]);
		ar[1][x] = ar[1][x] + max(ar[0][x+1],ar[2][x+1]);
		ar[2][x] = ar[2][x] + max(ar[1][x+1],ar[0][x+1]);
	}

	cout<<max(ar[0][1],max(ar[1][1],ar[2][1]));
}

	 	

Measured memory_bytes: 2560
import numpy as np
N = int(input())

Number_to_divide = []
for i in range(1,int(np.sqrt(N))+1):
    if (N % i == 0)and((N / i) > (i + 1)):
        Number_to_divide.append((N / i) - 1)
print(int(sum(Number_to_divide)))



Measured memory_bytes: 21664
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long N, M;
    cin >> N >> M;
    if (2 * N < M) {
        long n = (M - 2 * N) / 4;
        cout << N + n << endl;
    } else {
        cout << M / 2 << endl;
    }
    return 0;    
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
int modpow(int x, int n, int m) {
    if (n == 0) return 1%m;
    long long u = modpow(x,n/2,m);
    u = (u*u)%m;
    if (n%2 == 1) u = (u*x)%m;
    return u;
}
*/
const int MAX = 200005;
int fac[MAX], inv[MAX], finv[MAX];

void pre(){
  inv[1]=1;
  for (int i = 2; i <MAX ; i++)
  {
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  }
  fac[0]=finv[0]=1;
  for (int i = 1; i < MAX; ++i)
  {
    fac[i]=fac[i-1]*i%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
int ncr(int n, int r){
  if(r<0||r>n)return 0;
  return fac[n]*finv[r]%mod*finv[n-r]%mod;
}

int n,k;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  pre();
  cin >> n >> k;
  int ans = 0;
  for(int i=0;i<=min(n,k);i++){
    int cur = ncr(n,i)*ncr(n-1,(n-i-1))%mod;
    ans = (ans+cur)%mod;
    // cout << cur << endl;
  }
  cout << ans << endl;

return 0;
}
///....


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

int main() {
  while(true) {
    int n;
    int s[200];
    int max = 0;
    int min = 1000;
    int total = 0;
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; ++i) {
      cin >> s[i];
      if(s[i] > max) max = s[i];
      if(s[i] < min) min = s[i];
      total += s[i];
    }
    cout << ((total - max - min) / (n - 2)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>

int main() {
    int n, m;
    scanf("%d", &n);
    scanf("%d", &m);
    int num;
    int ac = 0, wa = 0;
    char ans[10];

    int WA[100007];
    bool AC[100007];
    for(int i = 1; i <= n; i++) {
        AC[i] = 0;
        WA[i] = 0;
    }
    while(m--){
        scanf("%d", &num);
        scanf("%s", ans);
        if (AC[num]) {
            continue;
        }
        if (ans[0] == 'A') {
            AC[num] = true;
            ac++;
            wa += WA[num];
        } else if (ans[0] == 'W'){
            WA[num] += 1;
        }
    }
    printf("%d %d\n", ac, wa);
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  vector<string> v(3);
  rep(i, 0, 3) { cin >> v[i]; }
  cout << v[0][0] << v[1][1] << v[2][2] << endl;

  return 0;
}


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

int main() {
    int N;
    long long x;
    cin >> N >> x;
    long long a[110];
    int ans = 0;

    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N);
    for(int i = 0; i < N; i++) {
        x -= a[i];
        if(x >= 0) {
        ans++;
        }
    }
    if(x > 0) {
        ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, answer;
    int i, j, k, l;

    while (scanf("%d", &n) != EOF) {
        answer = 0;
        for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) for (k = 0; k < 10; k++) for (l = 0; l < 10; l++) if (i + j + k + l == n) answer++;
        printf("%d\n", answer);
    }
    return 0;
}


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

int main(){
int a,b,c,k;
    cin>>a>>b>>c>>k;
  	if(k <= a)
      cout << k << endl;
  	else if(k <= a+b)
      cout << a <<endl;
  	else
      cout << a - (k - a - b) << endl;

return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        int yono = 0;
        for(int i = 1 ; i <= n ; i++){
            if(i / 10000 + ((i / 1000) % 10) + ((i / 100) % 10) + ((i / 10) % 10) + i % 10 >= a && i / 10000 + ((i / 1000) % 10) + ((i / 100) % 10) + ((i / 10) % 10) + i % 10 <= b) yono += i;
        }
        System.out.println(yono);
    }
}

Measured memory_bytes: 35668
#include "bits/stdc++.h"
using namespace std;
long long a[100000];
vector<pair<long long, long long>> b;
int main()
{
	int n, total = 0, left = 0;	
	long long asum = 0, bsum = 0, d;
	scanf("%d", &n);
	b.resize(n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%lld", &a[i]);
		asum += a[i];
	}
	for(int i = 0; i < n; ++i)
	{
		scanf("%lld", &d);
		bsum += d;
		b[i].first = a[i] - d;
		b[i].second = a[i] - d;
	}
	if(asum < bsum)
	{
		printf("-1\n");
		return 0;
	}
	sort(b.begin(), b.end());
	for(int i = n - 1; i >= 0; --i)
	{
		for(; b[i].first > 0; )
		{
			if(b[left].first >= 0)
			{
				goto esc;
			}
			if(b[left].first + b[i].first > 0)
			{
				b[i].first += b[left].first;
				b[left].first = 0;
				++left;
			}
			else
			{
				b[left].first += b[i].first;
				b[i].first = 0;
			}
		}
	}
	esc:
	for(int i = 0; i < n; ++i)
	{
		total += b[i].first != b[i].second;
	}
	printf("%d\n", total);
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
//ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,res,c1,x,y,c2;
    ci>>n;
    co<<n*n;
}



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

#print(seq)

if X not in seq:
    print(X)
    exit()

for i in range(1, 100):
    if X-i not in seq:
        print(X-i)
        exit()
    elif X+i not in seq:
        print(X+i)
        exit()

Measured memory_bytes: 9208
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	ll A, B;
	cin >> A >> B;
	ll ans = 0;

	if (B - A < 1000) {
		for (ll i = A; i <= B; i++)ans ^= i;
	}
	else {
		ll L = 4 * ((A + 3) / 4);
		ll R = 4 * (B / 4);
		for (ll i = A; i < L; i++)ans ^= i;
		for (ll i = R; i <= B;i++)ans ^= i;
	}
	puts(ans);

	return 0;
}



Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
for k in a:
	ans *= k
	if ans > 1000000000000000000:
		print(-1)
		sys.exit()
	if k == 0:
		print(0)
		sys.exit()
print(ans)

Measured memory_bytes: 21748
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int n;
  cin>>n;
  int os=0;
  rep(i, n){
    int p;
    cin>>p;
    if(p%2==1){
      os++;}
  }
  
  if(os%2==1){
    cout<<"NO"<<endl;}
  else{
    cout<<"YES"<<endl;}
    
  
  
  
}


Measured memory_bytes: 256
mod = 10**9 + 7
def binomial_coefficients(n, k):
  if k==0 or k==n:
    return 1
  modinv_table = [-1] * (k+1)
  modinv_table[1] = 1
  for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod
  ans = 1
  for i in range(k):
    ans *= n-i
    ans *= modinv_table[i + 1]
    ans %= mod
  return ans

N,K=map(int,input().split())
R=N-K
for i in range(1,K+1):
  if R<i-1:
    print(0)
  else:
    r=binomial_coefficients(R+1, i)
    b=binomial_coefficients(K-1, i-1)
    print((r*b)%1000000007)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")

//#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x%N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x)%N;
		y = y >> 1;
		x = (x * x)%N;
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	string flag = "No";
	rf(i, 9, 1)
	{
		if (n % i == 0)
		{
			n /= i;
			flag = "Yes";
			break;
		}
	}
	if (flag == "No")
		cout << "No";
	else if (n < 10 &&n>0)
	{
		cout << "Yes";
	}
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
x = list(map(int,input().split()))
ans=float("inf")

for i in range(N-K+1):
    if i + K == N+1:
        break
    else:
        a = min(abs(x[K+i-1]),abs(x[i])) 
        ans = min(ans,x[K+i-1]-x[i]+a)
print(ans)

Measured memory_bytes: 14392
import Control.Applicative
import Data.Function
import Control.Monad
import Data.List
import Data.Char
import Text.Printf

md :: Double -> [Double] -> [Double] -> Double
md p xs ys = (sum $ zipWith (\x y -> (abs (x-y))**p) xs ys) ** (1/p)

md' :: [Double] -> [Double] -> Double
md' xs ys = maximum $ zipWith (\x y -> abs (x-y)) xs ys

main :: IO ()
main = do
    _ <- getLine
    xs <- map read . words <$> getLine
    ys <- map read . words <$> getLine
    forM_ [1,2,3] $ \i ->
        printf "%.10f\n" $ md i xs ys
    printf "%.10f\n" $ md' xs ys


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define MAX_N 100002
using namespace std;
typedef long long ll;

vector<pair<int,int>> edge[MAX_N];
bool visited[MAX_N] = {false,};
int pos[MAX_N] = {0,};

bool dfs(int n, int d){
    visited[n] = true;
    pos[n] = d;
    for(int i = 0; i < edge[n].size(); i++){
        int dst = edge[n][i].first;
        int d2 = edge[n][i].second;
        if(visited[dst] == false){
            if(dfs(dst,d+d2) == false){return false;}
        }else{
            if(d+d2 != pos[dst]){return false;}
        }
    }
    return true;
}

int main(){
    int n, m;
    cin >> n >> m;
    int l, r, d;
    for(int i = 0; i < m; i++){
        cin >> l >> r >> d;
        l--; r--;
        edge[l].push_back(make_pair(r,d));
        edge[r].push_back(make_pair(l,-d));
    }


    for(int i = 0; i < n; i++){
        if(visited[i] == false){
            pos[i] = 0;
            if(dfs(i,0) == false){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
ll n,c,k;
struct node
{
	ll t,id;
}s[120000];
inline bool cmp(node a,node b)
{
	return a.t<b.t;
}
int main()
{
	n=read();
	c=read();
	k=read();
	for(rg int i=1;i<=n;++i)
	{
		s[i].t=read();
		s[i].id=i; 
	}
	stable_sort(s+1,s+1+n,cmp);
	int tot=0;
	int cnt=1;//当前第几个客人 
	double h=0;
	while(1)
	{
		if(cnt > n)
		{
			break;
		}
		int l=s[cnt].t;//最开始的这名客人的起始时间 
		int r=l+k;//终止时间 
		int hh=cnt;//保存开始这名客人的标号 
		ll sum=0;//累加这辆车坐的人数 
		for(rg int i=hh;i<=n;++i)
		{
			if(sum<c&&s[i].t<=r)
			{
				sum++;
			}
			else
			{
				break;
			}
		}
//		cout<<sum<<endl;
		cnt+=sum;
		tot++;
	}
	cout<<tot;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int 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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	rep(i,n) cin >> a[i] >> b[i];
	rep(i,m) cin >> c[i] >> d[i];
	rep(i,n){
		int ans = 1, mi = 1e9;
		rep(j,m){
			if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < mi){
				mi = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans = j+1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int n, a, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int j;
        cin >> a;
        for (j = 2; j * j <= a; ++j) {
            if (a % j == 0) break;
        }
        if (a < j * j) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3068
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, m;
vector<vector<int>> edges;

vector<int> sub, ans;


void init(int V) {
	edges.assign(V, vector<int>());
	sub.resize(V);
	ans.resize(V);
}

int dfs1(int u, int par = -1) {
	int ret = 1;
	for (int v : edges[u])if (v != par) {
		ret = ret * (dfs1(v, u) + 1LL) % m;
	}
	return sub[u] = ret;
}

void dfs2(int u, int par = -1, int parv = 0) {
	int e = edges[u].size();
	vector<int> left, right;
	vector<int> dest;
	left.reserve(e);
	right.reserve(e);
	dest.reserve(e);

	for (int v : edges[u])if (v != par) {
		dest.push_back(v);
		int subtree = (sub[v] + 1) % m;
		left.push_back(subtree);
		right.push_back(subtree);
	}
	for (int i = 1; i < left.size(); i++) {
		left[i] = (int64_t)left[i] * left[i - 1] % m;
	}
	for (int i = right.size() - 2; i >= 0; i--) {
		right[i] = (int64_t)right[i] * right[i + 1] % m;
	}

	ans[u] = 1;
	ans[u] = ans[u] * (parv + 1LL) % m;
	if (!right.empty())ans[u] = (int64_t)ans[u] * right[0] % m;

	for (int i = 0; i < left.size(); i++)if (dest[i] != par) {
		int ret = 1;
		ret = ret * (parv + 1LL) % m;
		if (0 < i)ret = (int64_t)ret * left[i - 1]  % m;
		if (i + 1 < left.size())ret = (int64_t)ret * right[i + 1] % m;
		dfs2(dest[i], u, ret);
	}
}


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

	cin >> n >> m;
	init(n);
	rep(i,n-1) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}

	dfs1(0);
	dfs2(0);
	rep(i,n) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    int diff,same;
    int ans;

    if(max(X,Y) == X){
        diff = X - Y;
        same = Y;
        if(2 * C < A + B){
            ans = 2 * C * same;
        }else{
            ans = (A + B) * same;
        }

        if(2 * C < A){
            ans += 2 * C * diff; 
        }else{
            ans += A * diff;
        }
    }else{
        diff = Y - X; 
        same = X;
        if(2 * C < A + B){
            ans = 2 * C * same;
        }else{
            ans = (A + B) * same;
        }

        if(2 * C < B){
            ans += 2 * C * diff; 
        }else{
            ans += B * diff;
        }
    }

    
    cout << ans << endl;
}

Measured memory_bytes: 3464
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
 long long int  a,b;
      
  cin >> a >> b;
  
 
  if((a>0)||((b<0) &&(b-a)%2 != 0)){
    cout << "Positive" << endl;
  }
  
  else if((b<0) &&(b-a)%2 == 0){
    cout << "Negative" << endl;
}
  else{
    cout <<"Zero" << endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int fac[10000005],invfac[10000005];
int dp[2005][2005],N,K,sum[2005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int Query(int n,int m) {
    return C(n + m - 1,m - 1);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
void Solve() {
    read(N);read(K);
    if(K == 1) {puts("1");return;}
    fac[0] = 1;
    for(int i = 1 ; i <= 10000000 ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[10000000] = fpow(fac[10000000],MOD - 2);
    for(int i = 9999999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    dp[1][0] = 1;
    for(int i = 2 ; i <= N ; ++i) {
	int t = (i - 1) * K + 1;
	for(int j = N ; j >= 0 ; --j) sum[j] = inc(sum[j + 1],dp[i - 1][j]);
	for(int j = 0 ; j <= i ; ++j) {
	    update(dp[i][j],mul(sum[max(0,j - 1)],Query(K - 2,t - j)));
	}
    }
    int ans = 0;
    for(int j = 0 ; j <= N ; ++j) update(ans,mul(dp[N][j],fac[N]));
    out(ans);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int main(){
    int n,m,s[200001],g[200001],i,ans=0,x,y;
    for(i=0;i<200001;i++){
        s[i] = 0;
        g[i] = 0;
    }
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&x,&y);
        if(x==1){
            s[y] ++;
        }
        if(y==n){
            g[x] ++;
        }
    }
    for(i=1;i<n;i++){
        if((s[i]==1) && (g[i]==1)){
            ans = 1;
            break;
        }
    }
    if(ans == 1){
        printf("POSSIBLE\n");
    } else {
        printf("IMPOSSIBLE\n");
    }
}

Measured memory_bytes: 1792
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> II;
typedef pair<LL, II> III;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int h = -1, w, k, sx, sy, gx, gy;
		LL ans = -1;
		cin >> h >> w >> k >> sy >> sx >> gy >> gx;
		--sx, --sy, --gx, --gy;
		if (h < 0) return 0;
		vector<string> b(h);
		for (int i = 0; i < h; ++i) {
			cin >> b[i];
		}
		priority_queue<III, vector<III>, greater<>> q;
		vector<int> dist(h * w, 1 << 30);
		q.emplace(III(0, II(sy, sx)));
		dist[sy * w + sx] = 0;
		while (!q.empty()) {
			III top = q.top();
			q.pop();
			int y = top.second.first, x = top.second.second;
			if (x == gx && y == gy) {
				ans = top.first;
				break;
			}
			const int dx[4] = { -1,1,0,0 };
			const int dy[4] = { 0,0,-1,1 };
			for (int dir = 0; dir < 4; ++dir) {
				for (int d = 1; d <= k; ++d) {
					int nx = x + dx[dir] * d, ny = y + dy[dir] * d;
					if (nx < 0 || nx >= w || ny < 0 || ny >= h) break;
					if (b[ny][nx] != '.') break;
					int cost = top.first + 1;
					if (cost > dist[ny * w + nx]) break;
					if (cost < dist[ny * w + nx]) {
						dist[ny * w + nx] = cost;
						q.emplace(III(cost, II(ny, nx)));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10576