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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int x,y,z;

main() {
    cin >> x >> y >> z;
    ct((x-z)/(y+z))
}







Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/31/2018
 
 24:40-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
//LL A[MAX_N];
LL H,W;
const LL Inf=1e11;
LL f() {
  LL res=Inf;
  FOR(h,1,H) {
    LL s1=W*h;
    LL hh=H-h;
    if(hh>1) {
      LL h1=hh/2,h2=hh-h1;
      LL s2=W*h1,s3=W*h2;
      LL x=max({s1,s2,s3})-min({s1,s2,s3});
      SMIN(res,x);
    }
    LL w1=W/2,w2=W-w1;
    LL s2=hh*w1,s3=hh*w2;
    LL x=max({s1,s2,s3})-min({s1,s2,s3});
    SMIN(res,x);
  }
  return res;
}

LL solve() {
  LL res=f();
  swap(H,W);
  SMIN(res,f());
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>H>>W;
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int w = int.Parse(s[0]);
            int h = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);
            if ((x - r >= 0) && (x + r <= w) && (y - r >= 0) && (y + r <= h))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 8976
N = raw_input()
N = int(N)

sum_n = 0
for i in range(N):
	s_input = raw_input()
	s_input = s_input.split(' ')
	s_input = [int(d) for d in s_input]
	sum_n += s_input[1] - (s_input[0] - 1)

print(sum_n)

Measured memory_bytes: 2568
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,k;
double ans;
void saiki(int kai,int sum){
  if(kai == n) ans += max(1,sum-k);
  if(kai < n) {
  for(int i=1;i<=m;i++) {
    saiki(kai+1,sum+i);
  }
  }

}

int main() {

  while(1) {
    cin >> n >> m >> k;
    if(n==0 && m==0 && k==0) break;
    ans = 0;
    saiki(0,0);
    int t = 1;
    for(int i=0;i<n;i++) t*=m;
    printf("%.8f\n",ans/t);
    
  }

  return 0;
}

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

using namespace std;
priority_queue<int,vector<int>,greater<int> > qe;
int main()
{
    int n;
    cin >> n;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        if(!qe.size() || qe.top()>=t)
        {
            qe.push(t);
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,string> P;
int bnf();
set<P> used;
map<char,int> M;
string S;
int idx,valid;
char ch[8]={'0','1','+','-','*','(',')','='};
int ord[8];
 
bool check(string a){//??????????????????°???¨???????????????????????¢????
  int par=0;
  for(char s:a){
    par += (s == '(') - (s == ')');
    if(s == '=') return 0;
    if(par < 0) return 0;
  }
  return par==0;
}
 
int getNum(){ //???????????????°????????????
  int res = 0;
  if(S[idx] == '0' && isdigit(S[idx+1])) valid  = 0;
  while(isdigit(S[idx]))res = res*2 + S[idx++]-'0';
  return res;
}
 
int cal(){
  char ch = S[idx];
  int res = 0,sign = 1;
  if(ch=='+'||ch=='*'||ch==')'){ valid = 0;return 0;}
 
  while(S[idx] == '-') idx++, sign *= -1;
  ch = S[idx];
 
  if(isdigit(ch)){
    res = sign*getNum();
    if(S[idx] == '*'){idx++; return res * cal();}
    return res;
  }
  else if(ch == '(') {
    idx++;res = sign*bnf();idx++;
    return res;
  }
 
  valid = 0;
  return 0;
}
 
int bnf(){
  int res = cal();
  while(idx<(int)S.size()){
    if(valid == 0) return -1;
    char ch = S[idx];
    if(ch == '('){valid = 0;}
    else if(ch == '*'){idx++;res *= cal();}
    else if(ch == '+'){idx++;res += cal();}
    else if(ch == '-'){idx++;res -= cal();}
    else if(ch != ')') valid = 0;
    else break;
  }
  if(valid ==0) return -1;
  return res;
}
 
string mkS(string a){
  string res;
  for(char s:a){
    if(isalpha(s))res += ch[ ord[ M[s] ] ];
    else res += s;
  }
  return res;
}
 
int calc(string A,string B){
  if(A.size()==0 || B.size()==0) return 0;
  if(used.count(P(A,B)))return 0;
  used.insert(P(A,B));
  valid = check(A) && check(B);
  idx = 0;
  S = A;
  int ra = bnf();
  idx = 0;
  S = B;
  int rb = bnf();
  //if(valid)cout<<A<<"="<<B<<" "<<valid<<" "<<ra<<" "<<rb<<endl;
  return ra == rb && valid;
}
 
int calc(string s){
  s = mkS(s);
  for(int i=0;i<(int)s.size();i++)
    if(s[i]=='=') return calc(s.substr(0,i),s.substr(i+1,s.size()-i-1));
  return 0;
}
 
int dfs(int num,string &s){
  if(num == 8) return calc(s);
   
  int res = 0;
  for(int i=0;i<8;i++){
    if(ord[i] != -1)continue;
    ord[i] = num;
    res +=dfs(num+1,s);
    ord[i] = -1;
  }
  return res;
}
 
 
int main(){
  string str;
  cin>>str;
  if(str.size()<3)cout<<0<<endl,exit(0);
 
  map<char,int> cnt;
  for(int i=0;i<(int)str.size();i++)if(isalpha(str[i]))cnt[str[i]]++;
  if(cnt.size()>8)cout<<0<<endl,exit(0);
 
  int c = 0;
  for(pair<char,int> p:cnt)if(isalpha(p.first)) M[p.first] = c++;
   
  memset(ord,-1,sizeof(ord));  
  cout<<dfs(0,str)<<endl;
  return 0;
}

Measured memory_bytes: 10040
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();

    println!(
        "{}",
        if n % 2 == 0 {
            n / 2
        } else {
            n / 2 + 1
        }
    );
}


Measured memory_bytes: 4352
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		for (int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}

		int[] dp = new int[N];
		Arrays.fill(dp,Integer.MAX_VALUE);
		dp[0]=0;
		dp[1]=Math.abs(h[1]-h[0]);
		int c=0;
		for (int i=2;i<N;i++) {
			for (int k=1;k<=Math.min(i,K);k++) {
				dp[i] = Math.min(dp[i],dp[i-k]+Math.abs(h[i]-h[i-k]));
			}
		}
		System.out.println(dp[N-1]);
	}
}

Measured memory_bytes: 51112
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mpp make_pair
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 998244353
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
#define MAXN 200008
#define MAXI 10000000000007

 
signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n, i;
    cin>>n;
    set<int> s;
    for(i=1;i*i<=n;i++){
    	if(n%i==0){
    		if(i==1){
    			if(n!=1)
    				s.insert(n);
    		}
    		else{
    			int x = i;
    			int num = n;
    			while(num%x==0){
    				num=num/x;
    			}
    			if(num%x==1&&i!=1)
    				s.insert(i);
    			x = n/i;
    			num = n;
    			while(num%x==0){
    				num=num/x;
    			}
    			if(num%x==1&&x!=1)
    				s.insert(n/i);
    		}
    	}
    }
    int r = n-1;
    for(i=1;i*i<=n;i++){
    	if(r%i==0){
    		if(i!=1)
    			s.insert(i);
    		if((r/i)!=1)
    			s.insert(r/i);
    	}
    }
    // for(auto it=s.begin();it!=s.end();it++){
    // 	cout<<*it<<" ";
    // }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 998244353;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e5 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int a[105];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            for(int k=j;k<n;k++){
                if(a[i]==a[j]||a[i]==a[k]||a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	public static class Cake implements Comparable<Cake>{
		int w, d;

		public Cake(int w, int d) {
			super();
			this.w = w;
			this.d = d;
		}

		@Override
		public int compareTo(Cake arg0) {
			return this.w * this.d - arg0.w * arg0.d;
		}
		
		@Override
		public String toString(){
			return this.w + " " + this.d;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int w = sc.nextInt();
			final int d = sc.nextInt();
			
			if(n == 0 && w == 0 && d == 0){
				break;
			}
			
			ArrayList<Cake> list = new ArrayList<Cake>();
			list.add(new Cake(w,d));
			
			for(int i = 0; i < n; i++){
				//System.out.println(list);
				final int p = sc.nextInt() - 1;
				final Cake cut = list.remove(p);
				//System.out.println(cut.w + " " + cut.d);
				final int s = sc.nextInt() % (2 * cut.w + 2 * cut.d);

				//System.out.println(s);
				
				Cake one,two;
				
				int rest = s;
				if (rest < cut.w) {
					one = new Cake(cut.w - rest, cut.d);
					two = new Cake(rest, cut.d);
				} else {
					rest -= cut.w;

					if (rest < cut.d) {
						one = new Cake(cut.w, cut.d - rest);
						two = new Cake(cut.w, rest);
					} else {
						rest -= cut.d;

						if (rest < cut.w) {
							one = new Cake(cut.w - rest, cut.d);
							two = new Cake(rest, cut.d);
						} else {
							rest -= cut.w;
							one = new Cake(cut.w, cut.d - rest);
							two = new Cake(cut.w, rest);
						}

					}
				}
				/*
				System.out.print(one.w + " " + one.d);
				System.out.print(", " + two.w + " " + two.d);
				System.out.println();
				*/
				if(one.compareTo(two) > 0){
					list.add(two);
					list.add(one);
				}else{
					list.add(one);
					list.add(two);
				}
				
			}
			
			Collections.sort(list);
			boolean first = true;
			for(Cake c : list){
				if(first){
					first = false;
					System.out.print(c.w * c.d);
				}else{
					System.out.print(" " + (c.w * c.d));
				}
			}
			System.out.println();
		}
		
		
	}

}

Measured memory_bytes: 13000
#include<iostream>
main(){
int n,m,i,a,c[1000001];
for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))
for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;
}

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

int main(){
    string str;
    getline(cin,str);
    for(int i = 0; i < str.size();i++){
        if(isalpha(str[i])){
            if(isupper(str[i])){
                str[i] = str[i] + 32;
            }else if(islower(str[i])){
                str[i] = str[i] - 32;
            }
        }
    }
    cout << str << endl;
    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int n=0;bool b=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')b=1;c=getchar();}
	while(c>='0'&&c<='9')n=(n<<3)+(n<<1)+(c^48),c=getchar();
	return b?-n:n;
}

int n,m,x,c[14],a[14][14],ans=INT_MAX,t[14];

void dfs(int now,int cd)
{
	if(now==n)
	{
		memset(t,0,sizeof t);
//		cout<<"dd:"<<cd<<endl;
		for(int i=0;i<n;++i)
		{
			if(cd&(1<<i))
			{
				for(int j=1;j<=m;++j)t[j]+=a[i+1][j];
			}
		}
//		for(int i=1;i<=m;++i)cout<<t[i]<<"  ";puts("");
//		puts("");
		for(int i=1;i<=m;++i)if(t[i]<x)return;
		int tt=0;
		for(int i=0;i<n;++i)if(cd&(1<<i))tt+=c[i+1];
//		cout<<"tt:"<<tt<<endl;
		ans=min(ans,tt);
		return;
	}
	dfs(now+1,cd);
	dfs(now+1,cd|(1<<now));
}

main()
{
	n=read();m=read();x=read();
	for(int i=1;i<=n;++i)
	{
		c[i]=read();
		for(int j=1;j<=m;++j)
		{
			a[i][j]=read();
		}
	}
	dfs(0,0);
	if(ans==INT_MAX)	puts("-1");
	else				cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
string s,t;
vector <string> v;
cin >> s>>t;
bool flag=true;
for(int i=0;i<s.size();i++){
    for(int j=0;j<t.size();j++){
      if(s[i+j]!=t[j]&&s[i+j]!='?'){
          flag=false;break;
      }
    }
    if(flag){
      string h;
      for(int j=0;j<s.size();j++){
        if(j==i) {
          h+=t;j+=(t.size()-1);
        }
        else if(s[j]=='?') h+='a';
        else h+=s[j];
      }
       v.push_back(h);
    }
    flag=true;
  }
if(v.empty()) cout <<"UNRESTORABLE"<<endl;
else{
  sort(v.begin(),v.end());
  cout << v[0]<<endl;
}
}


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

using namespace std;
typedef long long ll;


int n, w;
int a[100100][2];
ll dp[110][100100];

ll f(int idx, int curw)
{
    if (curw < 0) return -1e18;
    if (!curw) return 0;
    if (idx == n) return 0;
    ll &ret = dp[idx][curw];
    if (~ret) return ret;
    return ret = max(f(idx+1, curw), f(idx+1, curw-a[idx][0]) + a[idx][1]);
}
int main()
{
    memset(dp, -1, sizeof dp);

    scanf("%d%d", &n, &w);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < 2; ++j)
            scanf("%d", &a[i][j]);
//    ll ans = 0 ;
//    for (int i = n-1; i >= 0; --i)
//    {
//        dp[i][0] = 0;
//        for (int j = 1; j <= w; ++j)
//        {
//            dp[i][j] = dp[i+1][j];
//            if (j-a[i][0] >= 0)
//                dp[i][j] = max(dp[i+1][j-a[i][0]] + a[i][1], dp[i][j]);
//            ans = max(ans, dp[i][j]);
//        }
//    }

    printf("%lld\n", f(0, w));
//    printf("%lld\n", ans);

    return 0;
}


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


int main() {
    int64_t x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    int64_t res = 0;
    if (x /d > k) {
        res =  x - k * d;
        cout << res << endl;
        return 0;
    }

    //　原点はさんでちょこまかするパタン
    k = k - x / d;
    x = x - x / d * d;
    if (k % 2 == 0) {
        res = x;
    } else {
        res = abs(x - d);
    }
    cout << res << endl;
    return 0;


}


Measured memory_bytes: 3612
n = int(input())
t = list(map(int,input().split()))
sumt = sum(t)
m = int(input())
l = []
for i in range(m):
    p, x = map(int,input().split())
    a = sum(t)+x-t[p-1]
    l.append(a)
for o in l:
    print(o)

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# include <deque>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n=0, k=0, mini = 999999999;
	ll grid[3][3];
	bool flag = false;
	rep(i, 3) {
		rep(j, 3) {
			cin >> grid[j][i];
		}
	}
	ll  n1 = grid[0][0], n2 = grid[1][0], n3 = grid[2][0];
	if (grid[0][1] - n1 == grid[1][1] - n2 && grid[1][1]-n2 == grid[2][1]-n3) {
		if (grid[0][2] - n1 == grid[1][2] - n2 && grid[1][2] - n2 == grid[2][2] - n3) {
			flag = true;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

x = sorted(a)[::-1]
sum_al = 0
sum_bb = 0
for i in range(N):
    if i % 2 ==0:
        sum_al += x[i]
    else:
        sum_bb += x[i]

print(sum_al - sum_bb)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<set>
#define ll long long
using namespace std;
int main(){
   ll t;
   cin >>t;
   ll num=0;
   map<string , int> a;
   while(t--){
    string s;
    cin >>s;
    sort(s.begin(),s.end());
    num +=a[s]++;
   }
   cout<<num<<endl;
     return 0;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
const ll inf=100000000000000000;
int h[maxn],go[maxn*2],nxt[maxn*2],dis[maxn*2],size[maxn];
ll dep[maxn];
ll ans,sum,mi,se;
bool czy;
int i,j,k,l,r,t,n,m,tot,root;
void add(int x,int y,int z){
	go[++tot]=y;
	dis[tot]=z;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x,int y){
	int t=h[x];
	while (t){
		if (go[t]!=y){
			dfs(go[t],x);
			size[x]+=size[go[t]];
		}
		t=nxt[t];
	}
	size[x]++;
}
void dg(int x,int y){
	int t=h[x];
	while (t){
		if (go[t]!=y){
			dep[go[t]]=dep[x]+(ll)dis[t];
			dg(go[t],x);
		}
		t=nxt[t];
	}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d%d",&j,&k,&l);
		add(j,k,l);add(k,j,l);
	}
	dfs(1,0);
	root=1;t=0;
	while (1){
		r=h[root];
		while (r){
			if (go[r]!=t&&size[go[r]]==n/2&&n%2==0){
				czy=1;
				mi=dis[r];
			}
			if (go[r]!=t&&size[go[r]]>n/2){
				t=root;
				root=go[r];
				break;
			}
			r=nxt[r];
		}
		if (!r) break;
	}
	dg(root,0);
	fo(i,1,n) sum+=dep[i];
	if (!czy){
		mi=inf;
		fo(i,1,n)
			if (i!=root) mi=min(mi,dep[i]);
	}
	ans=sum*2;
	ans-=mi;
	printf("%lld\n",ans);
}

Measured memory_bytes: 8064
N = int(input())
k = "abcdefghij"
A = []
Q = [(1,1,"a")]
while Q:
    q = Q.pop()
    if q[0]==N:
        A.append(q[2])
        continue
    for i in range(q[1]+1):
        Q.append((q[0]+1,max(q[1],i+1),q[2]+k[i]))
A.sort()
for a in A:print(a)

Measured memory_bytes: 12708
#include <iostream>
#include <cstdio>

using namespace std;

void solve(int a, int b, int c, int d, int e, int f) {
	double x = (f - (double)e*c/b) / (d - (double)e*a/b);
	double y = (c - a*x) / b;
	if (x == 0) x = 0.000;
	if (y == 0) y = 0.000;
	printf("%4.3f %4.3f\n", x, y);
}

int main() {
	int a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		solve(a,b,c,d,e,f);
	}
	return 0;
}



Measured memory_bytes: 3052
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static List<List<char>> squares;

        static void Main(string[] args)
        {
            //[summary]C - Grid Repainting 2
            var lines = ReadLines<int>(1).ToList();
            int h = lines[0][0];
            int w = lines[0][1];

            //マス目の状態を取得
            squares = ReadLines<char>(h).ToList();

            if (IsAchieveGoal(h, w))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static bool IsAchieveGoal(int h, int w)
        {
            for(int i = 0; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    if (squares[i][j] == '#')
                    {
                        if (!IsRepainting(i, j))
                        {
                            return false;
                        }
                    }                    
                }
            }

            return true;
        }

        static bool IsRepainting(int y, int x)
        {
            if (IsBlack(y - 1, x) | IsBlack(y + 1, x) | IsBlack(y, x -1) | IsBlack(y, x + 1))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static bool IsBlack(int y, int x)
        {
            try
            {
                if (squares[y][x] == '#')
                {
                    return true;
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            return false;
        }
                               
        static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }

            for (int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //char型のときは1文字ずつに分割
                if (typeof(T) == typeof(char))
                {
                    var list = line.ToCharArray().ToList();
                    yield return (List<T>)(object)list;
                }
                else
                {
                    //読み込んだ値を"separator"で区切る
                    var list = line.Split(separator).ToList();

                    //int型のときは数値に変換
                    if (typeof(T) == typeof(int))
                    {
                        var numbers = list.ConvertAll(int.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else
                    {
                        yield return (List<T>)(object)list;
                    }
                }
            }
        }
    }
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

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

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

signed main() {
  int n, k, q;
  std::cin >> n >> k >> q;
  vi scores(n, k - q);
  REP(i, q) {
    int a = read();
    scores[a - 1] += 1;
  }
  REP(i, n) {
    if (scores[i] <= 0)
      std::cout << "No" << std::endl;
    else
      std::cout << "Yes" << std::endl;
  }
}


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

int n,t;
int a[100010];

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

Measured memory_bytes: 1152
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


def prepareSimple(n, mod=pow(10, 9) + 7):
    # n! の計算
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= mod
    fn = f

    # n!^-1 の計算
    inv = pow(f, mod - 2, mod)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= mod
        invs[m - 1] = inv
    return fn, invs


def prepare(n, mod=pow(10, 9) + 7):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= mod
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, mod - 2, mod)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= mod
        invs[m - 1] = inv

    return factorials, invs


# 実装を行う関数
def resolve(test_def_name=""):
    x, y = map(int, input().split())

    all_move_count = (x + y) // 3

    x_move_count = all_move_count
    y_move_count = 0

    x_now = all_move_count * 2
    y_now = all_move_count

    canMake= False
    for i in range(all_move_count+1):
        if x_now == x and y_now == y:
            canMake = True
            break

        x_move_count -= 1
        y_move_count += 1
        x_now -= 1
        y_now += 1

    if not canMake:
        print(0)
        return

    fn, invs = prepareSimple(all_move_count)
    ans = (fn * invs[x_move_count] * invs[all_move_count - x_move_count]) % (pow(10, 9) + 7)

    print(ans)
    # fn, invs = prepareSimple(10)
    # ans = (fn * invs[3] * invs[10 - 3]) % (pow(10, 9) + 7)
    # print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 3"""
        output = """2"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2 2"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """999999 999999"""
        output = """151840682"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 82184
void main() {
  problem();
}

void problem() {
  auto N = scan!int;
  auto A = scan!long(N).sort().reverse();

  long solve() {
    long ans;
    foreach(i; 1..N) {
      ans += A[i/2];
    } 
    return ans;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Queue = Tuple!(long, "from", long, "to");

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


Measured memory_bytes: 10168
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> a;
int b[200005],c[200005];
int main(){
	int n,k,x,p=0,sum=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
	 	scanf("%d",&x);
	 	if(a[x]==0)
	 		b[++p]=x;
	 	a[x]++;
	}
	for(int i=1;i<=p;i++)
		c[i]=a[b[i]];
	sort(c+1,c+p+1);
	for(int i=1;i<=p-k;i++)
		sum+=c[i];
	printf("%d\n",sum);
	return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define all(x) x.begin(), x.end()

typedef pair<int, int> pi;
typedef long long ll;
const int MAX_INT = 2000000000;

ll maxVal[100001];

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

    FOR(i, 1, W)
    {
        maxVal[i] = -1;
    }
    int w, val;
    FOR(j, 1, N)
    {
        cin >> w >> val;

        for (int i = W; i >= 0; i--)
        {
            if (maxVal[i] != -1 && i + w <= W && maxVal[i] + val > maxVal[i + w])
                maxVal[i + w] = maxVal[i] + val;
        }
    }

    ll ans = -1;
    FOR(i, 0, W)
    {
        ans = max(ans, maxVal[i]);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 1152
n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]

for i in r:
	i[0],i[1] = i[1],i[0]
r,b = sorted(r)[::-1],sorted(b)

answer = 0
for i in b:
	for j in r:
		if i[0]>j[1] and i[1]>j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, y, m; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct flow_network {
	int n;
	struct edge { int v; ll c; int rev; int i; };
	vector< vector<edge> > G;
	flow_network(int _n) : n(_n), G(_n) {}
	void add_edge(int u, int v, ll c, int i) {
		edge e = {v, c, G[v].size(), i}, _e = {u, 0, G[u].size(), -1};
		G[u].push_back(e); G[v].push_back(_e);
	}
	ll dfs(int u, int t, ll f, vector<bool>& vis) {
		if (u == t) return f;
		vis[u] = true;
		for (int i = 0; i < G[u].size(); i++) {
			edge& e = G[u][i];
			if (vis[e.v] || e.c == 0) continue;
			ll d = min(e.c, dfs(e.v, t, min(f, e.c), vis));
			if (d == 0) continue;
			e.c -= d;
			G[e.v][e.rev].c += d;
			return d;
		}
		return 0;
	}
	ll max_flow(int s, int t) {
		ll res = 0;
		for (;;) {
			vector<bool> vis(n);
			ll f = dfs(s, t, LLONG_MAX, vis);
			if (f == 0) return res;
			res += f;
		}
	}
};

int main() {
	int N, M; cin >> N >> M;
	flow_network fn(N);
	for (int i = 0; i < M; i++) {
		int X, Y; cin >> X >> Y;
		X--; Y--;
		fn.add_edge(X, Y, 1, i);
		fn.add_edge(Y, X, 1, i + M);
	}
	int S, T; cin >> S >> T;
	S--; T--;
	cout << fn.max_flow(S, T) << endl;
	vector<bool> v(M, true);
	for (int u = 0; u < N; u++) {
		for (int j = 0; j < fn.G[u].size(); j++) {
			flow_network::edge& e = fn.G[u][j];
			if (e.i >= 0 && e.i < M && e.c == 0) v[e.i] = false;
			if (e.i >= M && e.c == 1) v[e.i - M] = false;
		}
	}
	vector<int> w;
	for (int i = 0; i < M; i++)
		if (v[i]) w.push_back(i);
	cout << w.size() << endl;
	for (int j = 0; j < w.size(); j++)
		cout << w[j] + 1 << endl;
}

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

int main() {
    string s;
    cin >> s;
    bool ok = true;
    rep(i,s.size()) {
        if ((i+1)%2==1) {
            if (!(s[i]=='R' || s[i]=='U' || s[i]=='D')) ok = false;
        } else {
            if (!(s[i]=='L' || s[i]=='U' || s[i]=='D')) ok = false;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N;
    double T,A;
    cin >> N >> T >> A;
    double H[1000];
    for (int i=0;i<N;i++){
        cin >> H[i];
    }
    double X[1000];
    for (int i=0;i<N;i++){
        X[i]=abs(A-T+H[i]*0.006);
    }
    double Y=X[0];
    int j=0;
    for (int i=0;i<N;i++){
        if (X[i]<Y){
            Y=X[i];
            j=i;
        }
    }
    cout << j+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H=in();
    int N=in();
    int a[N];
    int b[N];
    vector<ll> d(H+1,INF);
    REP(i,N){
        cin>>a[i]>>b[i];
    }
    REP(i,N){
        if(a[i]>=H){
            REP1(j,H){
                if(d[j]>b[i]){
                    d[j]=b[i];
                }
            }
        }
        else{
            REP1(j,a[i]){
                if(d[j]>b[i]){
                    d[j]=b[i];
                }
            }
            for(int j=a[i]+1;j<=H;j++){
                if(d[j]>d[j-a[i]]+b[i]){
                    d[j]=d[j-a[i]]+b[i];
                }
            }
        }
    }
    cout<<d[H]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vll vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ull unsigned long long
#define ss second
const int N=1000005;
ll mod = 1e9+7;
ll GCD(ll x,ll y){if(!y)return x; return GCD(y,x%y);}
ll LCM(ll x,ll y){ return (x*y)/GCD(x,y);}
ll a[N];
ll vis[N]={};
vll primes;
void sieve (const ull& n)
{
    primes.resize(n + 1,0);
    primes[1] = 1;
    ull p = 2;
    for(; p * p < n + 1; ++p)
    {
        if(primes[p] == 0)
        {
            primes[p] = p;
            for(ull q = p * p; q < n + 1; q += p)
            primes[q] = p;
        }
    }
    for(; p <= n; ++p)
        if(primes[p] == 0)
            primes[p] = p;
}
void fact(ll n) 
{ 
    ll p=1; 
    while(n>1)
    { 
        p=primes[n]; 
        if(n%p==0) 
        { 
            vis[primes[n]]++; 
            n=n/primes[n]; 
        } 
        while(n%p==0) 
            n/=p; 
    } 
} 

void solve()
{
    ll n,m=0,k=0,i=1,j,p,f,x, y, z;
    ll ans=0,sum=0;
    sieve(1e6);
    //for(i=0;i<10;i++)cout<<primes[i]<<" ";cout<<endl;
    cin>>n;
    ll g, l;
    cin>>a[0];
    g=a[0],l=a[0];
    for(i=1;i<n;i++)
    {
        cin>>a[i];
        g=GCD(g, a[i]);
        fact(a[i]);
    }
    //cout<<g;
    if(g!=1)
    {
        cout<<"not coprime";
        return;
    }
    bool flag=0;

    for(i=0;i<n;i++)
    {
        ll t=a[i];
        ll p; 
        while(t>1) 
        { 
            p=primes[t]; 
            if (t%p==0&&vis[p] > 1) 
                flag=1;
            while(t%p==0) t/=p;
        } 
    } 
    if(flag) cout<<"setwise coprime";
    else cout<<"pairwise coprime";
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 26668
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(), vec.end()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define repc(bit, k, n) for (ll bit = (1 << k) - 1; bit < (1 << n); bit = next_combination(bit))
#define repi(itr, vec) for (auto itr = vec.begin(); itr != vec.end(); ++itr)
using namespace std;
using Graph = vector<vector<ll>>;

bool is_graph(ll v, const Graph &G, vector<ll> &seen, ll flag)
{
  if (seen[v] > 0)
    return seen[v] == flag;
  else
    seen[v] = flag;

  for (auto g : G[v])
  {
    if (flag == 2)
    {
      if (!is_graph(g, G, seen, 1))
        return false;
    }
    else if (flag == 1)
    {
      if (!is_graph(g, G, seen, 2))
        return false;
    }
  }
  return true;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  Graph G(n);
  rep(i, m)
  {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> seen(n);
  if (is_graph(0, G, seen, 1))
  {
    cout << count(ALL(seen), 2LL) * count(ALL(seen), 1LL) - m << endl;
  }
  else
  {
    cout << n * (n - 1) / 2 - m << endl;
  }

  return 0;
}


Measured memory_bytes: 10272
import math

N = int(input())
vals = list(map(int, input().split()))


def chmin_orig(i1, i2):
    if dp[i1] > (dp[i2] + abs(vals[i1]-vals[i2])):
        dp[i1] = dp[i2] + abs(vals[i1]-vals[i2])
        return True
    return False


dp = [float('inf')] * 100010
dp[0] = 0
for i in range(N):
    chmin_orig(i, i-1)
    if i > 1:
        chmin_orig(i, i-2)

print(dp[N-1])


Measured memory_bytes: 14104
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

constexpr int64_t mod = 1000000007;
 
int main() 
{
    int64_t N;
    std::cin >> N;
 
    int64_t ans = 0;
    for (int64_t i = 1; i <= 1000000; ++i) {
        int64_t div = N / i;
        if (N % i == 0) div--;
        ans += div;
    }

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


Measured memory_bytes: 3632
double*p,v,atof();main(c,t){for(p=t;t=0,~scanf("%s%c",&t,&c);c&2&&printf("%f\n",*p))t<48?v=*p--,*p=t&1?t&2?t&4?*p/v:*p+v:*p-v:*p*v:(*++p=atof(&t));}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	long long a=2,b=1,c=3,n,i;
	cin >> n;
	for(i=0;i<n;i++)
	{
		a=b;
		b=c;
		c=a+b;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n, d; cin >> n >> d;
    vector<vint> x(n, vint(d));
    rep(i, n) rep(j, d) cin >> x[i][j];
    int cnt = 0;
    rep(y, n) FOR(z, y+1, n) {
        if(y == z) continue;
        int dist = 0;
        rep(j, d) dist += pow(x[y][j] - x[z][j], 2);
        for(int m = 0; m * m < 16001; m++) {
            if(m * m == dist) {
                cnt++;
                // fprintf(stderr, "(%d, %d): %d\n", y, z, d);
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num_ = br.readLine();
		int num = Integer.parseInt(num_);
		num = num*num*num;
		System.out.println(num);
	}
}

Measured memory_bytes: 16860
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }



}


int main(){

    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3596
MOD = 10**9 + 7
N,K = map(int, input().split())
es = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

MAXN = K+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def nPr(n,r):
    if n < r:
        return 0
    return fac[n] * finv[n-r]

# 「距離が２以内は異なる色 = あるノードとそれに隣接するノードはそれぞれ異なる色」の言い換えがポイント
# 根はK通り、根の子の数をmとすると、根の子の塗り方は、K-1個の中からm個並べる方法なので、nPr(K-1, m)通り
# それ以降についてあるノードを見るとき、そのノードと親には既に色が塗られている場合を考える。
# 親とその親の２色は使われてるから、そのノードのこの塗り方はK-2のうちから子の数だけ並べるときなので、nPr(K-2, 子の数)


ans = (K * nPr(K-1, len(es[0]))) % MOD
stack = []
for nxt in es[0]:
    stack.append(nxt)

checked = [False] * N
checked[0] = True

# ノード0の子から見ていって、その子の塗り方をかけ合わせていく
while stack:
    curr = stack.pop()
    checked[curr] = True
    # currの親はすでに塗ってあるので、r = len(es[curr])-1
    ans *= nPr(K-2, len(es[curr])-1)
    ans %= MOD
    for nxt in es[curr]:
        if not checked[nxt]:
            stack.append(nxt)

print(ans % MOD)

Measured memory_bytes: 35384
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

bool dp[6000][1<<13];

ull p[6000], thash[6000];
ull shash[13];

int n,m;
int len;
char t[6000];
char ss[13][22];
int sslen[13];

int solve(){
    rep(i,n){
        ull x = 0;
        for(int j=0;ss[i][j];j++) x = x*3 + ss[i][j];
        shash[i] = x;
    }
    p[0] = 1;
    thash[0] = 0;
    rep(i,len) thash[i+1] = thash[i]*3 + t[i];

    rep(i,len+1)rep(j,1<<n) dp[i][j] = false;
    rep(i,len+1) dp[i][0] = true;
    rep(pos,len){
        rep(mask,1<<n){
            if(!dp[pos][mask]) continue;
            rep(i,n){
                if(mask>>i&1) continue;
                if(pos+sslen[i] > len) continue;
                ull h1 = shash[i];
                ull h2 = thash[pos+sslen[i]] - thash[pos] * p[sslen[i]];
                // if(h1 != h2) continue;
                dp[pos+sslen[i]][mask|1<<i] |= h1 == h2; // t.substr(pos,ss[i].size()) == ss[i];
            }
        }
    }

    int ans = 0;
    rep(i,len+1){
        if(dp[i][(1<<n)-1]){
            ++ans;
        }
    }
    return ans;
}

signed main(){
    p[0] = 1;
    rep(i,5001) p[i+1] = p[i]*3;

    while(scanf("%d%d",&n,&m), n){
        len = 0;
        rep(i,n){
            scanf("%s",ss[i]);
            sslen[i] = strlen(ss[i]);
        }
        rep(i,m){
            static char buf[22];
            scanf("%s",buf);
            int l;
            for(l=0; buf[l]; l++) t[l+len] = buf[l];
            len += l;
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 42156