akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<int> A(N);
  for(int i = 0;i < N;i++) cin >> A.at(i);

  if(A.at(0) != 0) {
    cout << -1 << endl;
    return 0;
  }

  long long ans = 0;
  for(int i = 0;i < N-1;i++) {
    if(A.at(i+1)-A.at(i) > 1) {
      cout << -1 << endl;
      return 0;
    }
    if(A.at(i) + 1 == A.at(i+1)) ans++;
    else ans += A.at(i+1);
  }

  cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main() {
  ll X;cin >> X;
  ll K;cin >> K;
  vll r(K+1,0);
  repeat(t,K){
    cin >> r[t+1];
  }
  vll a(K+1,0),b(K+1,X),c(K+1,0);
  repeat(t,K){
    ll dif =  r[t+1]-r[t];
    if(t&1){
      c[t+1] = min(X,a[t]+c[t]+dif)-a[t];
      a[t+1] = a[t];
      b[t+1] = min(b[t],X-c[t+1]);
    }else{
      c[t+1] = max(0ll,b[t]+c[t]-dif)-b[t];
      a[t+1] = max(a[t],-c[t+1]);
      b[t+1] = b[t];
    }
  }
  /*
  debugArray(a,K+1);
  debugArray(b,K+1);
  debugArray(c,K+1);
  */
  ll Q;cin >> Q;
  repeat(q,Q){
    ll t,x;
    cin >> t >> x;
    ll pt = upper_bound(r.begin(),r.end(),t)-r.begin()-1;
    ll dif = t-r[pt];
    debug(dif);
    if(!(pt&1)) dif *= -1;
    ll ans=c[pt];
    if(x<a[pt]){
      ans += a[pt];
    }else if(x<b[pt]){
      ans += x;
    }else{
      ans += b[pt];
    }
    ans = max(0ll,min(X,ans+dif));
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

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

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans=1;
	while(a>0 && c>0) {
		if(ans==1) {
			c-=b;
		}else {
			a-=d;
		}
		ans=1-ans;
	}
	
	cout<<(ans?"No":"Yes")<<"\n";

	return 0;
}


Measured memory_bytes: 3652
program sequence_growing_easy
  implicit none
  integer :: n, a(200000), i
  integer(8) :: m
  a = 0
  read(*,*) n
  do i = 1, n
    read(*,*) a(i)
  end do
  if (a(1).ne.0) then
    write(*,'(i0)') -1
    stop
  end if
  do i = 1, n-1
    if (a(i+1).gt.a(i).and.a(i+1).ne.a(i)+1) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  m = 0_8
  do i = 2, n
    if (a(i).gt.0) then
      m = m+1_8
      if (a(i).le.a(i-1)) m = m+int(a(i)-1,8)
    end if
  end do
  write(*,'(i0)') m
  stop
end program sequence_growing_easy

Measured memory_bytes: 1536
if __name__=='__main__':
    a = [int(i) for i in input().split(' ')]
    n = a[0]
    k = a[1]
    s = input()
    cnt = 0
    ans = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            cnt += 1
        else:
            ans += 1
    if cnt > 2*k:
        ans += k*2
    if cnt <= 2*k:
        ans = len(s)-1
    print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,x,y;
    cin>>n>>x>>y;
    x--,y--;
    vector<vector<int> > v(n);
    int dis[n][n];
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		if(i==j)dis[i][j]=0;
    		else dis[i][j]=1e9;
    	}
    }
    for(int i=1;i<n;i++){
    	v[i].pb(i-1);
    	v[i-1].pb(i);
    }
    v[x].pb(y);
    v[y].pb(x);
    for(int i=0;i<n;i++){
    	bool maki[n];
    	memset(maki,0,sizeof(maki));
    	queue<pair<int,int> > q;
    	q.push({i,0});
    	maki[i]=true;
    	while(!q.empty()){
    		int now=q.front().first;
    	    int count=q.front().second;
    	    q.pop();
    	    dis[i][now]=min(dis[i][now],count);
    	    for(auto& j:v[now]){
    	    	if(maki[j]){
    	    		continue;
    	    	}

    	        maki[j]=true;
    	    	q.push({j,count+1});
    	    }
    	}
    }
    int num[n];
    memset(num,0,sizeof(num));
    for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
    		//cout << dis[i][j] <<" ";
    	}
    	//cout << endl;
    }
    for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
    	num[dis[i][j]]++;
    }
    for(int i=1;i<n;i++){
    	cout << num[i] <<endl;
    }
    return 0;
}

Measured memory_bytes: 16000
n = int(input())

if 400 <= n <= 599:
    print (8)
elif 600 <= n <= 799:
    print (7)
elif 800 <= n <= 999:
    print (6)
elif 1000 <= n <= 1199:
    print (5)
elif 1200 <= n <= 1399:
    print (4)
elif 1400 <= n <= 1599:
    print (3)
elif 1600 <= n <= 1799:
    print (2)
else:
    print (1)


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

int in()
{
	int aa=0,ff=1;char cc=getchar();
	for(;!isdigit(cc);cc=getchar())if(cc=='-')ff=-1;
	for(;isdigit(cc);cc=getchar())aa=(aa<<1)+(aa<<3)+(cc&15);
	return aa*ff;
}

string s;

int main()
{
	cin>>s;
	cout<<s[0]<<s.length()-2<<s[s.length()-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new TEST().doIt();
    }
    class TEST{
        void doIt(){
        	while(true){
        		int n = sc.nextInt();
        		int m = sc.nextInt();
        		if(n + m == 0)break;
        		for(int i = 0;i < n;i++){
        			for(int j = 0;j < m;j++){
        				if(i == 0 || j == 0 || i == (n-1) || j == (m-1))System.out.print("#");
        				else System.out.print(".");
        			}
        			System.out.println();
        		}
        		System.out.println();
        	}
        }
    }
}

Measured memory_bytes: 36852
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    set<int> s;
    vector<int> v;

    for(int i=0;i<t;i++)
    {
        int n;
        cin>>n;
        s.insert(n);
        v.push_back(n);
    }
    if(s.size()==v.size())
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 10356
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        int tmp=0;
        for(int j=1;j<=i;j+=2) if(!(i%j)) tmp++;
    if(tmp==8) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N, M; cin >> N >> M;
    vi L(M), R(M), D(M);
    REP(i, M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }
    
    vvi es(N);
    map<pii, ll> ds;
    REP(i,M) {
        es[L[i]].push_back(R[i]);
        ds[pii(L[i], R[i])] = D[i];
        es[R[i]].push_back(L[i]);
        ds[pii(R[i], L[i])] = -D[i];
    }

    bool ok = true;
    vb vis(N, false);
    vl x(N, 0);
    REP(i, N) {
        if (vis[i]) continue;
        vis[i] = true;

        queue<int> que;
        que.push(i);        
        while(!que.empty()) {
            int j = que.front(); que.pop();
            for(int k : es[j]) {
                ll d = ds[pii(j, k)];
                if (vis[k]) {
                    if (x[k] == x[j] + d) continue;
                    else {
                        ok = false;
                        break;
                    }
                }

                x[k] = x[j] + d;
                vis[k] = true;
                que.push(k);
            }
            if (!ok) break;
        }
    }

    string ans = ok ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35200
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
typedef int64_t ll;

int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> a(n),b(m);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  vector<ll> cv=atcoder::convolution<998244353>(a,b);
  for(int i=0;i<n+m-1;i++)cout<<cv[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 27188
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
dp = ["Second"] + ["First"]*k
for i in range(1,k+1):
    win = "Second"
    for j in range(n):
        if i-A[j] >= 0 and dp[i-A[j]] == "Second":
            win = "First"
    dp[i] = win
print(dp[k])

Measured memory_bytes: 42220
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var s = 0;
        var result = 0;
        for(var i = 0; i < str.Length; i++)
        {
            if (str[i] == 'S') s++;
            else
            {
                if (s == 0) continue;
                else { s--; result++; }
            }
        }
        WriteLine(str.Length-2*result);
    }
}


Measured memory_bytes: 11092
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long sum = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            sum += a;
            map.merge(a, 1, Integer::sum);
        }
        int q = Integer.parseInt(sc.next());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            if (map.containsKey(b)) {
                int num = map.get(b);
                sum += (c - b) * num;
                int cnt = map.remove(b);
                map.merge(c, cnt, Integer::sum);
            }
            sb.append(sum);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 65816
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll inf = 998244353;

vector<vector<ll>> dp0(100000+1,vector<ll>(300+2,0)),dp1(100000+1,vector<ll>(300+2,0));
vector<vector<int>> v(100000+1);
vector<int> s(100000+1,0);


void dfs(int n,int m,int K){//,vector<int>& s,vector<vector<int>>& v,vector<vector<ll>>& dp0, vector<vector<ll>>& dp1){
    dp1[n][1] = 1;
    dp0[n][0] = 1;
    s[n] = 1;
    for(auto x:v[n]) if(x!=m){
        dfs(x,n,K);//,s,v,dp0,dp1);
        vector<ll> merge0(K+2,0),merge1(K+2,0);
        for(int i=0;i<=s[n];i++) for(int j=0;j<=s[x];j++){
            if(i+j>=K+2) break;
            (merge0[i+j] += dp0[n][i]*(dp0[x][j]+dp1[x][j])%inf)%=inf;
            (merge1[i+j] += dp1[n][i]*(dp0[x][j]+dp1[x][j])%inf)%=inf;
            if(j>=1){
                (merge1[i+j-1] += dp1[n][i]*dp1[x][j]%inf)%=inf;
            }
        }
        s[n] += s[x];
        s[n] = min(s[n],K+1);
        for(int i=1;i<=K+1;i++){
            dp0[n][i] = merge0[i];
            dp1[n][i] = merge1[i];
        }
    }
}

int main(){
    int N,K;
    cin >> N >> K;
/*    vector<vector<ll>> dp0(N+1,vector<ll>(K+2,0)),dp1(N+1,vector<ll>(K+2,0));
    vector<vector<int>> v(N+1);
    vector<int> s(N+1,0);
*/    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,0,K);//,s,v,dp0,dp1);
    cout << (dp0[1][K]+dp1[1][K])%inf << endl;
}


Measured memory_bytes: 502188
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func mathRound(f float64) float64 {
	return math.Floor(f + .5)
}

func round(x float64) float64 {
	if math.Abs(x) < 0.001 {
		return 0
	}
	return mathRound(x*1000) / 1000
}

func main() {
	scanner.Split(bufio.ScanWords)
	for {
		a, err := nextFloat64()
		if err != nil {
			break
		}
		b, _ := nextFloat64()
		c, _ := nextFloat64()
		d, _ := nextFloat64()
		e, _ := nextFloat64()
		f, _ := nextFloat64()

		detA := a*e - b*d
		x := (c*e - b*f) / detA
		y := (a*f - c*d) / detA

		fmt.Printf("%.3f %.3f\n", round(x), round(y))
	}
}



Measured memory_bytes: 1124
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 12;
const int MAX_LEN = MAX_N + MAX_M - 1;

/* typedef */

/* global variables */

int n, m, len, mbits;
int ls[MAX_N], ks[MAX_LEN];

/* subroutines */

bool check_ls(int bits) {
  int c = 0;
  for (int i = 0; i < m; i++, bits >>= 1)
    if ((ks[i] = bits & 1)) c++;
  if (ls[0] != c) return false;

  for (int j = 1; j < n; j++) {
    if (ks[j - 1]) c--;
    if (ls[j] == c) ks[j + m - 1] = 0;
    else if (ls[j] == c + 1) ks[j + m - 1] = 1, c++;
    else return false;
  }
  return true;
}

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < n; i++) cin >> ls[i];

    len = n + m - 1;
    mbits = (1 << m) - 1;
    bool found = false;
    
    for (int bits = 0; ! found && bits <= mbits; bits++)
      found = check_ls(bits);

    if (found) {
      for (int i = 0; i < len; i++) cout << ks[i];
      cout << endl;
    }
    else
      cout << "Goofy" << endl;
  }

  return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>
long long int dp[1001][1001];//動的計画法の表
int main(void){
    int i,j,n,m,d[1001],c[1001];//n=都市の数,m=日数,d=都市間の距離,c=天候
    long long int min,M;//min=最小値
    M=922337203685477580;//最大値代入
    scanf("%d %d",&n,&m);//都市の数と日数の入力
	//↓表のすべての場所にM代入
    for(i=0;i<=m;i++){
        for(j=0;j<=n;j++) dp[i][j]=M;
    }
    for(i=0;i<n;i++) scanf("%d",&d[i]);//都市間の距離の入力
    for(i=0;i<m;i++) scanf("%d",&c[i]);//天候の入力
    dp[0][0]=0;//スタート位置に0代入
    for(i=0;i<m;i++){
        for(j=0;j<=n;j++){
            if(dp[i][j]!=M){
                if(dp[i+1][j]>dp[i][j]) dp[i+1][j]=dp[i][j];//縦方向に疲労度比べて代入
                if(dp[i+1][j+1]>dp[i][j]+d[j]*c[i]) dp[i+1][j+1]=dp[i][j]+d[j]*c[i];//斜め方向に
            }
        }
    }
    min=M;//minにM代入
 /*   for(i=0;i<=m;i++){
        if(min>dp[i][n]) min=dp[i][n];//minと比べて更新
    }*/
    printf("%lld\n",dp[m][n]);//最小の疲労度出力
    return 0;
}

Measured memory_bytes: 8428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define For(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool f=0;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return f?-x:x;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);putchar(x%10+'0');
}
void writeln(ll x){write(x);puts("");}
void writep(ll x){write(x);putchar(' ');}
int const Mo=1e9+7;
int const N=1e7+3;
ll n,m,fac[N],inv[N];
ll ksm(ll x,ll q){
	ll sum=1;
	while (q){
		if (q&1) sum=sum*x%Mo;
		x=x*x%Mo;
		q>>=1;
 	}
 	return sum;
}
ll C(ll n,ll m){
	if(m>n) return 0;
	if(m==n) return 1;
	return fac[n]*inv[n-m]%Mo*inv[m]%Mo;
}
int main(){
	n=read();m=read();
	fac[0]=1;
	for (int i=1;i<=n;i++)
	  fac[i]=fac[i-1]*i%Mo;
	inv[n]=ksm(fac[n],Mo-2);
	for (int i=n-1;i>=0;i--)
	  inv[i]=inv[i+1]*(i+1)%Mo;
	for (int i=1;i<=m;i++)
	  writeln(C(n-m+1,i)*C(m-1,i-1)%Mo);
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int gcd(int a, int b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最小公倍数

int main(){
  int N;
  string s;
  cin>>N>>s;
  ll cntr(0),cntg(0),cntb(0);
  for(int i(0);i<N;i++){
    if(s[i] == 'R') cntr++;
    if(s[i] == 'G') cntg++;
    if(s[i] == 'B') cntb++;
  }
  ll ans = cntr*cntg*cntb;
  for(int i(0);i<N;i++){
    for(int j(i+1);j<N;j++){
      int sa = j-i;
      if(j+sa < N){
        if(s[i] != s[j] && s[i] != s[j+sa] && s[j] != s[j+sa]) ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const double eps=1e-9;
const int maxn=1e5+10;
const int maxm=2e5+10;
int fa[maxn],dis[maxn];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int find(int x){
	if(fa[x]==x)return x;
	int tmp=fa[x];
	fa[x]=find(fa[x]);
	dis[x]+=dis[tmp];
	return fa[x];
}
int main(){
	int i,j,k,m,n;
	n=read();m=read();
	for(i=1;i<=n;i++)fa[i]=i;
	for(i=1;i<=m;i++){
		int x=read(),y=read(),z=read();
		int u=find(x),v=find(y);
		if(u==v){
			if(dis[y]-dis[x]!=z){
				puts("No");
				return 0;
			}
		}
		else{
			int tmp=dis[y]-dis[x]-z;
			if(tmp>0)swap(u,v);
			dis[v]=abs(tmp);fa[v]=u;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <limits>
#include <limits.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;


int main()
{
	int A, B, C, X, Y;
	std::cin >> A >> B >> C >> X >> Y;

	int maxXY = max(X, Y);
	int min_money = INT_MAX;
	for (int ab = 0; ab <= maxXY*2; ab+=2)
	{
		int a = max(X - ab / 2, 0);
		int b = max(Y - ab / 2, 0);
		int money = A * a + B * b + C * ab;
		min_money = min(min_money, money);
	}

	std::cout << min_money;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
count = 1
ans = 0
for i in range(1,N):
    if A[i - 1] == A[i]:
        count += 1
    else:
        if count % 2 == 1:
            ans += 1
        count = 1
if count % 2 == 1:
    ans += 1
print(ans)

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

int main() { 
  int a,b,c;
  cin >> a >> b >> c;
  
  if (a+b == c || a+c == b || b+c == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;
	ll k;
	ll o=0;
	ll ans=0;

	cin>>s;
	cin>>k;

	rep(i,s.size()){
		if(s[i]=='1'){
			o++;
		}else  break;

		if(ans==1){
		cout<<s[0]<<endl;
		}
	}

	if(o>=k){
		cout<<"1"<<endl;

	}else{
		cout<<s[o]<<endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  
  int s = A + B + C;
  int g0 = 3 * max({A, B, C});
  int g1 = g0 + 3;
  int ans;
  if (s % 2 == g0 % 2) ans = (g0 - s) / 2;
  else ans = (g1 - s) / 2;

  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n, u, v = map(int, raw_input().split())
    u -= 1
    v -= 1
    tree = {i: [] for i in xrange(n)}
    for _ in xrange(n - 1):
        a, b = map(int, raw_input().split())
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    dist = [None] * n
    dist[v] = 0
    stack = [[v, 0]]
    while stack:
        node, d = stack.pop()
        d += 1
        for nex in tree[node]:
            if dist[nex] is None:
                dist[nex] = d
                stack.append([nex, d])
    
    stack = [[u, 0]]
    visited = [False] * n
    visited[u] = True
    best = 0
    while stack:
        node, d = stack.pop()
        d += 1
        for nex in tree[node]:
            if dist[nex] >= d and not visited[nex]:
                if dist[nex] > d:
                    stack.append([nex, d])
                visited[nex] = True
                if dist[nex] < dist[node]:
                    best = max(best, dist[node] - 1)
                else:
                    best = max(best, dist[node])
    print best


main()


Measured memory_bytes: 57320
#include <iostream>
#include <cstdio>
#define NMAX 100000
using namespace std;
int main(){
	int N,A[NMAX] = {},B[NMAX] = {},sup = 0,ans;
	scanf("%d",&N);
	for (int i = 0; i < N; ++i) {
		scanf("%d",&A[i]);
		B[A[i]]++;
		if(B[A[i]] >=2){
			sup++;
		}
	}
	ans = N - (sup/2*2 + sup%2 * 2);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1152
C(b,n,s,c){c=!n&!s;for(s-=b;n&&b<=9&&s>=0;)c+=C(++b,n-1,s--);return c;}main(n,s){for(;~scanf("%d%d",&n,&s);)n&&printf("%d\n",C(0,n,s));}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(void){
  int H,N; cin >> H >> N;
  int sum = 0;
  for(int i = 0; i < N; i++){ 
    int a; cin >> a; sum += a;
  }
  
  if( sum >= H ){ cout << "Yes" << endl;}
  else{ cout <<"No" << endl;}

  return 0;
}

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

int main() {
	int a[5],b[5];
	int amari = 0;
	int time = 0;
	for(int i=0;i<5;i++){
		cin >> a[i];
		b[i] = (a[i]+9)/10;
		if((b[i]*10-a[i])>amari){
			amari = b[i]*10-a[i];
		}
		time = time + b[i]*10;
	}
	
	cout << time - amari << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            iA = iA == 1 ? 14 : iA;
            iB = iB == 1 ? 14 : iB;
            string sOut = "Draw";
            if (iA > iB) { sOut = "Alice"; }
            if (iA < iB) { sOut = "Bob"; }

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

#define _CRT_SECURE_NO_DEPRECATE 
#define endl "\n"
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define sz(x) ((int)x.size())

typedef long long       ll;
typedef vector<int>     vi;
typedef pair<int, int>  ii;
typedef vector<ii>     vii;
typedef set<int>        si;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define IT(it, x) for(auto it : x)

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
int main()
{
   ll a, b;
   cin >> a >> b;
   ll ans = 1LL*a*b/__gcd(a, b);
   cout << ans << endl;     
   return 0;
}

Measured memory_bytes: 256
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std; 
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mi             1000001

vll prime(mi,1);

void seive()
{
    prime[0]=0;
    prime[1]=1;

    for(ll i=2;i*i<=mi;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<=mi;j+=i)   prime[j]=0;
        }
    }
}

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
  

void solve()
{

    ll a,b,ans=1;

    cin>>a>>b;

    ll tt=__gcd(a,b);

    for(int i=1;i<=sqrt(tt);i++)
    {
        if(tt%i==0)
        {
            if(isPrime(i))          ans++;

            if(tt/i!=i)
            {
                if(isPrime(tt/i))   ans++;
            }
        }
    }

    cout<<ans;
}
 
signed main(){
 
    fast;

    seive();
 
    ll t=1;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 8064
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll x=ceil(c/(1.0*b));
ll y=ceil(a/(1.0*d));
if(x<=y)
{
    cout<<"Yes"<<endl;
}else
{
    cout<<"No"<<endl;
}
return 0;
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> a(n, vector<int>(n)), c(m, vector<int>(m));
	for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
	for (int i = 0; i < m; i++) cin >> c[i][0] >> c[i][1];

	for (int i = 0; i < n; i++) {
		int min = INT_MAX;
		int idx = 0;
		for (int j = 0; j < m; j++) {
			int d = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]);
			if (min > d) {
				min = d;
				idx = j + 1;
			}
		}
		cout << idx << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		int[] a = arrayInt(sc, n);
		sc.close();
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];
		}
		System.out.println(sum >= h ? "Yes" : "No");
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}

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

int main(){
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    for (int i=0; i<A; i++) cin >> p.at(i);
    for (int i=0; i<B; i++) cin >> q.at(i);
    for (int i=0; i<C; i++) cin >> r.at(i);
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());
    vector<ll> pqr(X+Y+C);
    for (int i=0; i<X; i++) pqr.at(i) = p.at(i);
    for (int i=X; i<X+Y; i++) pqr.at(i) = q.at(i-X);
    for (int i=X+Y; i<X+Y+C; i++) pqr.at(i) = r.at(i-(X+Y));
    sort(pqr.begin(), pqr.end(), greater<int>());
    ll sum = 0;
    for (int i=0; i<X+Y; i++) sum += pqr.at(i);
    cout << sum << endl;
}

Measured memory_bytes: 4864
# coding: utf-8
# Your code here!

try:
   while True:
      n = int(input())
      if n == 0: break
   
      a = 1
      for i in range(1, n + 1):
         a *= i
      
      cnt = 0
      while(a % 10 == 0):
            cnt += 1
            a //= 10
         
      print(cnt)

except EOFError:
   pass



Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,h,w;
	ll a[1001],b[1001];
	ll total=0;

	cin>>n>>h>>w;

	rep(i,n){
		cin>>a[i]>>b[i];
		if(a[i]>=h&&b[i]>=w){
			total++;
		}
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    typedef long long ll;
    ll n, m, a[210000], b[210000], x, y, res;
    int main(void){
        // Your code here!
        cin >> n >> m;
        for (ll i = 1; i <= n; i++) a[i] = 1;
        b[1] = 1;
        for (ll j = 0; j < m; j++) {
            cin >> x >> y;
            if (b[x] == 1) {
                b[y] = 1;
                if (a[x] == 1) b[x] = 0;
            }
            a[x]--; a[y]++;
        }
        for (ll i = 1; i <= n; i++) res += b[i];
        cout << res << endl;
    }

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
#a=a[::-1]
ans=0
pos=n
pre=0
b=a[0]
for i in range(n):
    x=a.pop()
    if x==0 and pre<=1:
        continue
    elif x>pos-1:
        ans=-1
        break
    else:
        if x==pre-1:
            pre=x
            continue
        else:
            if x>=pre:
                pre=x
                ans+=x
            else:
                ans=-1
                break
    pos-=1
if b>0:
    ans=-1
print(ans)


Measured memory_bytes: 59320
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
typedef long long ll;

int main()
{
	int year, month, day;
	scanf("%d/%d/%d", &year, &month, &day);

	if (year > 2019) cout << "TBD";
	else if (month > 4) cout << "TBD";
	else if (day > 30) cout << "TBD";
	else cout << "Heisei";
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

double mat[100][100];
double dp[2][100]; //[phase][prev]

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N, M;
        cin >> N >> M;
        if(!N && !M) break;
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                cin >> mat[i][j];
            }
        }
        for(int i = 0; i < N; ++i) {
            dp[0][i] = 1.0;
        }
        for(int i = 1; i < M; ++i) {
            const int cur = i & 1;
            const int prev = cur ^ 1;
            for(int j = 0; j < N; ++j) {
                dp[cur][j] = 0.0;
                for(int last = 0; last < N; ++last) {
                    dp[cur][j] = max(dp[cur][j], dp[prev][last] * mat[last][j]);
                }
            }
        }
        double ans = 0.0;
        for(int i = 0; i < N; ++i) {
            ans = max(ans, dp[(M-1)&1][i]);
        }
        printf("%.2f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1352
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }



struct C
{
	ll x = 0;
	ll y = 0;
	ll z = 0;
	ll value() { return abs(x) + abs(y) + abs(z); }
	ll value(int mode) const {
		ll result = 0;
		result += (mode & 1) ? x : -x;
		result += (mode & 2) ? y : -y;
		result += (mode & 4) ? z : -z;
		return result;
	}
};

int main(int argc, char* argv[])
{
	for (;;) {
		int N, M;

		cin >> N >> M;
		if (cin.fail()) break;

		vector<C> V(N);
		for (int i = 0; i < N; i++) {
			cin >> V[i].x >> V[i].y >> V[i].z; 
		}
		ll result = 0;
		for (int mode = 0; mode < 8; mode++) {
			auto compare = [mode](const C& a, const C& b) {
				return a.value(mode) > b.value(mode);
			};
			sort(V.begin(), V.end(), compare);
			C value;
			for (int i = 0; i < M; i++) {
				value.x += V[i].x;
				value.y += V[i].y;
				value.z += V[i].z;
			}
			result = max(result, abs(value.x) + abs(value.y) + abs(value.z));
		}
		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n,p=map(int,input().split())
c=collections.Counter(prime_factorize(p))
a=list(c.keys())
b=list(c.values())
ans=1
if n==1:print(p)
else:
    for i in range(len(b)):
        c=0
        while b[i]>=n:
            c+=1
            b[i]-=n
        ans*=a[i]**c
    print(ans)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
	long long n;
	cin >>n;
	long long  m=n/11;
	if(n%11==0){
		cout <<2*m<<endl;
	}else{
		if(n<=11*m+6){
			cout <<2*m+1;
		}else if(n<=11*m+10){
			cout <<2*m+2<<endl;
		}
	}
}


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

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

    ll n, m;
    cin >> n >> m;

    // mem[x] : x 日後に報酬がもらえる仕事の集合. 値は報酬額
    vvll mem(m + 1);
    ll a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        if (a > m) continue; // 最速で始めても M 日目に間に合わない仕事は無視
        mem[a].push_back(b);
    }

    // 期限がカツい日にできる仕事は限定的なので後ろ側からどの仕事をいれたら良いか考える
    // que : その日入れられる仕事の報酬リスト
    // mem を参照してギリ M 日目に間に合う案件の報酬を que に追加していく
    priority_queue<ll> que;
    ll res = 0;
    for (int d = m - 1; d >= 0; d--) {
        // mem[m - d] : d 日目に始めたらちょうど M 日目に報酬が降ってくる仕事の集合(b はその個々の報酬額)
        for (auto b : mem[m - d]) que.push(b);
        if (!que.empty()) {
            res += que.top();
            que.pop();
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5632
import copy

h, w, k = map(int, input().split())
grid = []
for _ in range(h):
    curRow = list(input())
    grid.append(curRow)

def countBlack(g):
    result = 0
    for row in g:
        result += row.count("#")
    return result

choices = list(range(h)) + list(range(w))


def checkChoice(path):
    curGrid = copy.deepcopy(grid)
    for i in range(h):
        if path[i]:
            for j in range(w):
                curGrid[i][j] = "r"
    for j in range(h, len(choices)):
        if path[j]:
            curCol = j - h
            for i in range(h):
                curGrid[i][curCol] = "r"
    return countBlack(curGrid) == k

result = 0
def solve(i, path):
    global result
    if i == len(choices):
        result += checkChoice(path)
    else:
        path.append(True)
        solve(i + 1, path)
        path.pop()
        path.append(False)
        solve(i + 1, path)
        path.pop()

solve(0, [])
print(result)

Measured memory_bytes: 77136
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int n;
double ans = 0;
vector<int> x, y;

void dfs(vector<bool> check, int now, double sum) {
    check[now] = true;
    bool goal = true;
    for (int i=0; i<n; i++) {
        if (!check[i]) {
            goal = false;
            dfs(check, i, sum+sqrt(pow(x[now]-x[i], 2) + pow(y[now]-y[i], 2)));
        }
    }

    if (goal)
        ans += sum;
}

int main() {
    cin >> n;
    int nn = 1;
    
    for (int i=0; i<n; i++) {
        int in_x, in_y;
        cin >> in_x >> in_y;
        x.push_back(in_x);
        y.push_back(in_y);
        nn *= i+1;
    }

    vector<bool> check(n, false);
    for (int i=0; i<n; i++)
        dfs(check, i, 0);

    printf("%.10lf\n", ans/nn);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    p = inputList()
    
    tmp = 0
    tona = 0
    flg = False
    for i, val in enumerate(p):
        if i+1 == val:
            tmp += 1
            if flg == True:
                tona += 1
                flg = False
            else:
                flg = True
        else:
            flg = False
            
    print(tmp-tona)
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 56304
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int N;
    cin >> N;
    int x[100001],y[100001],t[100001];
    x[0] = 0; y[0] = 0; t[0] = 0;
    for(int i = 1; i <= N; ++i) cin >> t[i] >> x[i] >> y[i];

    for(int i = 1; i <= N; ++i){
        int time = t[i] - t[i-1];
        int difx = abs(x[i] - x[i-1]);
        int dify = abs(y[i] - y[i-1]);
        if(time < difx + dify){
            cout << "No" << endl;
            return 0;
        }else if(time % 2 == (difx+dify)%2){
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;

    for (int i = s.size() - 2; i >= 2; i -= 2) {
        if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
            cout << i << endl;
            return 0;
        }
    }
}


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

long greedy(long s, int i, int a[], int n) {
    if (i >= n)
        return 0;
    long ns = s + a[i];
    if (ns * s < 0)
        return greedy(ns, i + 1, a, n);
    if (s > 0)
        return ns + 1 + greedy(-1, i + 1, a, n);
    return - ns + 1 + greedy(1, i + 1, a, n);
}

long solve(int a[], int n) {
    return min(max(1 - a[0], 0) + greedy(max(a[0], 1), 1, a, n), max(a[0] + 1, 0) + greedy(min(a[0], -1), 1, a, n));
}

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << solve(a, n) << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int N;
    cin >> N;
    map<int, int> m;
    rep(i,N - 1){
        int num;
        cin >> num;
        m[num]++;
    }
    for(int i = 1; i < N + 1; i++)cout << m[i] << endl;
}

Measured memory_bytes: 13008
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *S,=ST()
    *T,=ST()
    S.sort()
    T.sort(reverse=True)
    S="".join(S)
    T="".join(T)
    print("YNeos"[S>=T::2])
if __name__ == '__main__':
    main()

Measured memory_bytes: 63596