akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> water, sugar;
  for (int i = 0; 100*A*i <= F; i++) {
    for (int j = 0; 100*A*i + 100*B*j <= F; j++) {
      water.push_back(100*A*i + 100*B*j);
    }
  }
  for (int i = 0; C*i <= F; i++) {
    for (int j = 0; C*i + D*j <= F; j++) {
      sugar.push_back(C*i + D*j);
    }
  }
  sort(water.begin(), water.end());
  water.erase(unique(water.begin(), water.end()), water.end());
  water.erase(water.begin());
  sort(sugar.begin(), sugar.end());
  sugar.erase(unique(sugar.begin(), sugar.end()), sugar.end());

  double max_conc = 0;
  double limit = (double)E / (100 + E);
  int max_w = 0, max_s = 0;
  EACH(wp, water) {
    EACH(sp, sugar) {
      double conc = (double)(*sp) / (*wp + *sp);
      if (conc <= limit && *wp + *sp <= F && max_conc <= conc) {
        max_conc = conc;
        max_w = *wp;
        max_s = *sp;
      }
    }
  }

  cout << max_w + max_s << " " << max_s << endl;

  return 0;
}


Measured memory_bytes: 2420
import math

a,b,h,m = map(int,input().split())

al=math.radians((h*60+m)/2)
be=math.radians(m*6)

length=math.sqrt(pow(a*math.cos(al)-b*math.cos(be),2)+pow(a*math.sin(al)-b*math.sin(be),2))

print(length)

Measured memory_bytes: 9532
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String S1 = S.substring(0,1);
    String S2 = S.substring(1,2);
    String S3 = S.substring(2,3);
    String S4 = S.substring(3,4);
    if (S1.equals(S2) && S3.equals(S4) && !(S1.equals(S3))){
      System.out.println("Yes");
    }else if(S1.equals(S3) && S2.equals(S4) && !(S1.equals(S2))){
      System.out.println("Yes");
    }else if(S1.equals(S4) && S2.equals(S3) && !(S1.equals(S2))){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin>>n;
	if(n==1){
		cout<<"Hello World"<<'\n';
	}
	else{
		cin>>a>>b;
		cout<<a+b<<'\n';
	}
	return 0;
}

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

int main() {
long long int n;
  cin >>n;
  long long int i=1, sum = 0;
  while(i<=n){
    if(i%5!=0 && i%3!=0) sum+=i;
    ++i;
    
  }
  cout << sum << endl;
  
}


Measured memory_bytes: 3632
n,yen = map(int,input().split())
ans = [-1,-1,-1]

for x in range(n+1):
    for y in range(n+1-x):
        z= int(yen/1000) - 10*x - 5*y
        if (0<= z) and (z == n-x-y):
            #print(x,y,n-x-y,z)
            bol = True
            ans = [x,y,z]
            break

print(ans[0],ans[1],ans[2])
'''
        if 0<= yen/1000 + 12*x + 5*y <= n+1-x-y:
            print(x,y,z)
            break
'''


Measured memory_bytes: 3064
main=do
 s<-getLine
 putStrLn (f s (length s) "")
  where f _   0 a = a
        f "B" 1 a = g a
        f s   1 a = a++s
        f s n a = f (tail s) (n-1) (if s!!0=='B' then (g a) else a++[s!!0])
        g "" = ""
        g a  = init a

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

int main() {
	int Ninzuu;
	int AmeCount = 0;
	cin >> Ninzuu;
	for (int i = 1;i <= Ninzuu;i ++) {
		AmeCount +=i;
	}
	cout << AmeCount << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    int pos1;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        if(a[i] == 1) pos1 = i;
    }

    int cnt = 1;
    int now = k - 1;
    if(pos1 > now){
        cnt += (pos1 - now) / (k - 1);
        now += (cnt - 1) * (k - 1);
        if(now < pos1){
            now += k - 1;
            cnt++;
        }
    }

    int tmpCnt = (n - 1 - now) / (k - 1);
    now += tmpCnt * (k - 1);
    if(now < n - 1){
        tmpCnt++;
    }

    std::cout << cnt + tmpCnt << std::endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

class ABC{
    long A,B,C;
    public ABC(long a,long b,long c){
        A=a;
        B=b;
        C=c;
    }
}

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int Z = scan.nextInt();
        int N = X+Y+Z;

        ABC[] abc = new ABC[N];
        for(int i=0;i<N;++i){
            abc[i] = new ABC(scan.nextLong(),scan.nextLong(),scan.nextLong());
        }

        Arrays.sort(abc,(a,b)->(int)((b.A-b.B) - (a.A-a.B)));

        PriorityQueue<ABC> CA = new PriorityQueue<>((a,b) -> (int)((b.C-b.A) - (a.C-a.A)));
        PriorityQueue<ABC> CB = new PriorityQueue<>((a,b) -> (int)((b.C-b.B) - (a.C-a.B)));
        for(int i=0;i<X;++i)CA.add(abc[i]);
        for(int i=0;i<Y;++i)CB.add(abc[N-1-i]);

        long[] sumA = new long[N];
        long[] sumB = new long[N];
        sumA[0] = abc[0].A;
        for(int i=1;i<N;++i)sumA[i] = sumA[i-1]+abc[i].A;
        sumB[N-1] = abc[N-1].B;
        for(int i=N-2;i>=0;--i)sumB[i] = sumB[i+1]+abc[i].B;

        long[] maxAk = new long[N];
        long[] maxBk = new long[N];
        maxAk[X-1] = sumA[X-1];
        for(int i=X;i<X+Z;++i){
            CA.add(abc[i]);
            ABC maxca = CA.poll();
            maxAk[i] = maxAk[i-1] + abc[i].A + maxca.C - maxca.A;
        }
        maxBk[N-Y] = sumB[N-Y];
        for(int i=N-1-Y; i>=N-Y-Z;--i){
            CB.add(abc[i]);
            ABC maxcb = CB.poll();
            maxBk[i] = maxBk[i+1] + abc[i].B + maxcb.C - maxcb.B;
        }
        long ans = 0;
        for(int i=X-1;i<N-Y;++i){
            ans = Math.max(ans, maxAk[i] + maxBk[i+1]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 99104
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

int ar[500500], a[500500];

void solve(){
    int n;
    cin >> n;
    
    int cnt = 0;
    for(int i = 0; i < n; i++){
        char x;
        cin >> x;
        if(x == 'E'){
            cnt++;
            ar[i] = 1;
        }
        a[i] = cnt;
    }
    int ans = INT_MAX;
    for(int i = 0; i < n; i++){
        int tmp = i + 1 - a[i] + a[n - 1] - a[i];
        if(ar[i] == 0) tmp -= 1;
        ans = min(ans, tmp);
    }
    cout << ans;
}

int main(){
    barsik;
    int q = 1;

    //cin >> q;

    for(int i = 1; i <= q; i++){
//        cout << "Case " << i << ": ";
        solve();
    }
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
	static class Sushi {
		long x;
		long v;
		public Sushi(long x, long v) {
			this.x = x;
			this.v = v;
		}
		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long C = sc.nextLong();

		Sushi[] s = new Sushi[N];
		for(int i=0; i<N; i++)
			s[i] = new Sushi(sc.nextLong(), sc.nextLong());
		
		long ans = solve(s, C);
		Arrays.sort(s, new Comparator<Sushi>() {
			public int compare(Sushi s1, Sushi s2) {
				return - Long.compare(s1.x, s2.x);
			}
		});
		for(int i=0; i<N; i++)
			s[i].x = C-s[i].x;
		
		ans = Math.max(ans, solve(s, C));
		
		System.out.println(ans);
		sc.close();
	}
	
	static long solve(Sushi[] s, long C) {
		int N = s.length;
		long[] cwmax = new long[N+1];
		long sum = 0;
		for(int i=0; i<N; i++) {
			sum += s[i].v;
			cwmax[i+1] = Math.max(cwmax[i], sum - s[i].x);
		}
		
		long max = cwmax[N];
		sum = 0;
		for(int i=N-1; i>=0; i--) {
			sum += s[i].v;
			max = Math.max(max, sum - (C-s[i].x)*2 + cwmax[i]);
		}
		
		return max;
	}
}


Measured memory_bytes: 95076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int64_t A[N];
  rep(i, N){
    cin >> A[i];
  }
  sort(A, A+N);
  reverse(A, A+N);
  int64_t a = 0, b = 0;
  for(int i=1;i<N;i++){
    if(A[i] == A[i-1]){
      if(a != 0){
        b = A[i];
        break;
      }
      else{
        a = A[i];
        i++;
      }
    }
  }
  cout << a*b << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
	typedef long long ll;
	using namespace std;
	vector < int > st;
	int prime[1100001];
	void seive(){
		for(int i = 2 ; i * i <= 1100000 ; i++){
			if(!prime[i]){
				//cout << i << endl;
				for(int j = i * i ; j <= 1100000 ; j += i){
					prime[j] = 1;
				}
			}
		}
		for(int i = 2 ; i <= 200000 ; i++)
		{
			if(!prime[i])
				st.push_back(i);
		}
	}
	int main(){	
		ios_base::sync_with_stdio(false);
		    cin.tie(NULL);
		    string s;
		    cin >> s;
		    int x = s.size()/2;
		    int ans = 0;
		    for(int i = 0 ; i < x ; i++){
		    	if(s[i] != s[s.size() - i - 1])
		    		ans++;
		    }
		    cout << ans << endl;
		    return 0;
	}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,m;
vi x[200],d[200];
int dp[200][11][200];

int main2(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	if(cin>>n>>m,!n)return 1;
	x[0].pb(-INF);d[0].pb(-INF);
	x[n+1].pb(-INF);d[n+1].pb(-INF);
	rep2(i,1,n+1){
		int k;
		cin>>k;
		x[i].clear();
		d[i].clear();
		rep(j,k){
			int X,D;
			cin>>X>>D;
			x[i].pb(X),d[i].pb(D);
		}
	}
	rep(i,n+2)rep(j,10)rep(k,m+1)dp[i][j][k]=INF;
	dp[0][0][m]=0;
	rep(i,n+1)rep(j,sz(x[i]))rep(k,m+1){
		rep2(dy,1,3){
			int ni=i+dy;
			if(dy==2 && (i==n || k==0))continue;
			rep(nj,sz(x[ni])){
				int cost;
				if(i==0 || ni==n+1)cost=0;
				else cost=(d[i][j]+d[ni][nj])*abs(x[i][j]-x[ni][nj]);
				dp[ni][nj][k-(dy==2)]=min(dp[ni][nj][k-(dy==2)],dp[i][j][k]+cost);
			}
		}
	}
	int ans=INF;
	rep(k,m+1)ans=min(ans,dp[n+1][0][k]);
	cout<<ans<<endl;
	return 0;
}

int main(){
	while(!main2());
}

Measured memory_bytes: 2584
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scanf("%d", &x)

	money := 100
	year := 1
	for ; ; year++ {
		money = int(float64(money) * 1.01)
		if money >= x {
			break
		}
	}
	fmt.Printf("%d\n", year)
}


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

using namespace std;

#define N 300000

int n,lst[N][30],f[N];
vector<int> ans;
char s[N];

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	reverse(s+1,s+n+1);
	f[0]=1;
	for (int i=1;i<=n;++i){
		for (int j=0;j<26;++j) lst[i][j]=lst[i-1][j];
		lst[i][s[i]-'a']=i;
		f[i]=i+1;
		for (int j=0;j<26;++j){
			if (!lst[i][j]) f[i]=1;
			else f[i]=min(f[i],f[lst[i][j]-1]+1);
		}
	}
	for (int i=n;i>=0;--i){
		for (int j=0;j<26;++j){
			if (!lst[i][j]||f[i]==f[lst[i][j]-1]+1){
				ans.push_back(j);
				i=lst[i][j];
				break;
			}
		}
	}
	for (int i:ans) putchar(i+'a'); puts("");
	return 0;
}

Measured memory_bytes: 26496
#include <bits/stdc++.h>
using namespace std;
#define Maxn 107
int n,a[Maxn];
int m=0,ans[Maxn];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=n;i++)
        if (a[i]-i>0)
        {
            printf("%d\n",-1);
            return 0;
        }
    while (n>0)
    {
        int pos=-1;
        for (int i=n;i;i--)
            if (a[i]==i)
            {
                pos=i;
                break;
            }
        if (pos==-1)
        {
            printf("%d\n",-1);
            return 0;
        }
        ans[++m]=pos;
        for (int i=pos+1;i<=n;i++)
            a[i-1]=a[i];
        --n;
    }
    for (int i=1;i<m+1-i;i++)
        swap(ans[i],ans[m+1-i]);
    for (int i=1;i<=m;i++)
        if (ans[i]>i)
        {
            printf("%d\n",-1);
            return 0;
        }
    for (int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 3816
n,m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

k = 0
while a[0][k] == 0
  k += 1
end
if k == 0
  puts(0)
  exit
end
(1..(n-1)).each do |i|
  if a[i][0,k] != 0 || a[i][k] != 1
    puts(0)
    exit
  end
end

half_lcm = a.reduce(&:lcm)/2
tmp = m / half_lcm

puts((tmp+1) / 2)

Measured memory_bytes: 24544
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int h, a;
  cin >> h >> a;
  cout << (h + (a-1)) / a;
}

Measured memory_bytes: 3632
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	double t,x;
	
	//データの読み込み
	
	scanf("%lf %lf",&t,&x);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	
//	printf("計算部分終了\n");
	
	//出力
	
		printf("%lf",t/x);
	
	
	//('・ω・'）
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
x = input()
y = map(int,raw_input().split())
total = sum(y)
minn = 2147483647
flag1 = y[0]
total -= flag1
for i in range(1,len(y)):
    minn = min( minn, abs(flag1-total))
    flag1 += y[i]
    total -= y[i]
print minn

Measured memory_bytes: 18440
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
#define Okay_Bye return 0
#define fo(i,n) for(auto i=0;i<n;i++)
#define f1(i,a,n) for(auto i=a;i<n;i++)
#define pn printf("\n")
#define Yes printf("YES\n")
#define No printf("NO\n")
#define pb push_back

int cs=1;
int t[3007][3007];
void solve(){
    string n,m;
    cin>>n>>m;
    fo(i,n.size()+1){
        fo(j,m.size()+1){
            if(i==0 or j==0)t[i][j]=0;
            else if(n[i-1]==m[j-1]){
                t[i][j]=1+t[i-1][j-1];
            }else{
                t[i][j]=max(t[i-1][j],t[i][j-1]);
            }
        }
    }
    string s="";
    int i=n.size(),j=m.size();
    while(i>0&&j>0){
          if(n[i-1]==m[j-1])
          { s+=n[i-1];
          i--;j--;
          }
          else if(t[i][j-1]>t[i-1][j]){
              j--;
          }else{
              i--;
          }
        }
        for(i=s.size()-1;i>=0;i--)cout<<s[i];
        pn;
}

signed main()
{
	int t=1;
	//cin>>t;
	while(t--)solve();
	Okay_Bye;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int h,w;
string s[20];
int dist[20][20];
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
bool in(int x,int y){
	re (x>=0&&x<h&&y>=0&&y<w);
}
int bfs(int sx,int sy,int fx,int fy){
	queue<pii> q;
	memset(dist,-1,sizeof(dist));
	q.push(m_p(sx,sy));
	dist[sx][sy]=0;
	while(!q.empty()){
		int x=q.front().fr,y=q.front().se;
		q.pop();
		rep(i,4){
			int xx=x+dx[i],yy=y+dy[i];
			if(!in(xx,yy))
			continue;
			if(s[xx][yy]=='#')
			continue;
			if(dist[xx][yy]!=-1&&dist[xx][yy]<=dist[x][y]+1)
			continue;
			dist[xx][yy]=dist[x][y]+1;
			q.push(m_p(xx,yy));
		}
	}
	re dist[fx][fy];
}
int main(){
	ios::sync_with_stdio(0);
	cin>>h>>w;
	rep(i,h)
	cin>>s[i];
	int ans=0;
	rep(i,h)
	rep(j,w){
		if(s[i][j]=='#')
		continue;
		rep(i2,h)
		rep(j2,w){
			if(s[i2][j2]=='#')
			continue;
			ans=max(ans,bfs(i,j,i2,j2));
		}
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

inv_t = [0, 1] + [0] * (N - 1)
for i in range(2, N + 1):
    inv_t[i] = inv_t[MOD % i] * (MOD - MOD // i) % MOD

A.sort()
ans = 0
C = 1
for i in range(K, N + 1):
    ans += (A[i - 1] - A[N - i]) * C
    ans %= MOD
    C = C * i * inv_t[i - K + 1]
    C %= MOD
print(ans)


Measured memory_bytes: 14040
#include<stdio.h>
int main(void){
    int a,b;
    char op;

    while(1){
        scanf ("%d %c %d",&a,&op,&b);
        if (op=='?') break ;
        if (op=='+') printf("%d\n",a+b);
        if (op=='-') printf("%d\n",a-b);
        if (op=='*') printf("%d\n",a*b);
        if (op=='/') printf("%d\n",a/b);
    }

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll a, b, n; cin >> a >> b >> n;
	ll x=min(n,b-1);
	ll ans=(a*x)/b-a*(x/b);
	cout << ans << endl;
	return 0;
}

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int minv = min(a,b), maxv = b, ans = b - a;
	n-=2;
	while(n--) {
		cin >> a;
		if(a<minv) minv = a, maxv = INT_MIN;
		else if(a>maxv) { 
			maxv = a;
			ans = max(maxv - minv, ans);	
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int N = stdIn.nextInt();
	int o;
	if(N%2==0){
	    o = N/2;
	}else{
	    o = N/2+1;
	}
	double ans = (double)o/(double)N;
	System.out.println(ans);
    }
}


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

using namespace std;

struct pr{
	int i,b;
};

int r,c,n;
pr ar[200000];
int b[100000];
stack<int> q;

bool onedge(int y,int x){
	return ((x == 0)||(y == 0)||(x == c)||(y == r));
}

int crd(int y,int x){
	if(x == 0){
		return y;
	} else if(y == r){
		return r + x;
	} else if(x == c){
		return 2*r + c - y;
	} else {
		return 2*r + 2*c - x;
	}
}

bool cmp(pr a, pr b){
	return (a.i < b.i);
}

int main(){
	scanf("%d%d%d",&r,&c,&n);
	int ct = 0;
	for(int i = 0; i < n; i++){
		int ya,xa,yb,xb;
		scanf("%d%d%d%d",&ya,&xa,&yb,&xb);
		if(onedge(ya,xa) && onedge(yb,xb)){
			ar[ct].i = crd(ya,xa);
			ar[ct].b = ct/2;
			ar[ct+1].i = crd(yb,xb);
			ar[ct+1].b = ct/2;
			b[ct/2] = true;
			ct++;
			ct++;
		}
	}
	sort(ar,ar+ct,cmp);
	for(int i = 0; i < ct; i++){
		if(b[ar[i].b]){
			q.push(ar[i].b);
			b[ar[i].b] = false;
		} else {
			if(q.top() == ar[i].b){
				q.pop();
			} else {
				q.push(0);
				i = ct;
			}
		}
	}
	if(q.empty()){
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0&&W==0) break;
			for(int j=0;j<(H-H%2)/2;j++){
		    	for(int i=0;i<(W-W%2)/2;i++){
			    	System.out.print("#.");
			    	}
		    	if(W%2==1) System.out.print("#");
		    	System.out.println();
		    	for(int i=0;i<(W-W%2)/2;i++){
		    		System.out.print(".#");
		    		}
		    	if(W%2==1) System.out.print(".");
		    	System.out.println();
			}
			if(H%2==1){
				for(int i=0;i<(W-W%2)/2;i++){
			    	System.out.print("#.");
			    	}
		    	if(W%2==1) System.out.print("#");
		    	System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int d,t,s;
  cin>>d>>t>>s;
  if(d<=t*s) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        vector<int> a(100);
        int l; cin>>a[0]>>l;
        if(a[0] == 0 && l == 0) return 0;

        vector<int> digit(l, 0);
        int cnt=0;
        while(1){
            int num = a[cnt];
            for(int i=0; i<l; i++){
                digit[i] = num % 10;
                num /= 10;
            }

            int amax=0, amin=0;
            sort(digit.begin(), digit.end());

            int num2 = 1;
            for(int i=0; i<l; i++){
                amax += digit[i] * num2;
                amin += digit[l-1-i] * num2;
                num2 *= 10;
            }
        
            a[++cnt] = amax - amin;

            for(int i=cnt-1; i>=0; i--){
                if(a[i] == a[cnt]){
                    cout << i << " " << a[cnt] << " " << cnt - i << endl;
                    goto END;
                }
            }
        }

        END:;
    }
}


Measured memory_bytes: 3120
import itertools
L = [int(input()) for i in range(5)]
L = list(itertools.permutations(L))
ans = float('inf')
for i in range(len(L)):
    menu = L[i]
    time = 0
    j = 0
    while j < 5:
        if time % 10 == 0:
            time += L[i][j]
            j += 1
        else:
            time += 1
    #print(time)
    ans = min(ans,time)
print(ans)


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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int n, m;
	cin >> n >> m;
	vector<int> sum(m, 0);
	REP(i, n)
	{
		int k;
		cin >> k;
		REP(i, k)
		{
			int a;
			cin >> a;
			sum[a - 1]++;
		}
	}
	int ans = 0;
	REP(i, m)
	{
		if (sum[i] == n)
			ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,a,b=map(int,input().split())
print(min(a,b),max(0,(a+b)-n))

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

int cnt[2010];

int main() {
//	freopen("in.txt", "r", stdin);
	string s;
	cin >> s;
	int num = 0, t = 1, res = 0;
	cnt[0] = 1;
	for(int i = s.size() - 1; ~i; i--) {
		num = (num + (s[i] - '0') * t) % 2019;
		res += cnt[num]++;
		t = t * 10 % 2019;
	}
	printf("%d\n", res);
	return 0;
}


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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    char a;
    a = s.at(k - 1);
    string ans;
    rep(i, n) {
        if (s.at(i) == a) {
            ans += a;
        }
        else ans += '*';
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
import Data.Fixed (Micro)

calc :: String -> [Micro]
calc = foldl f [] . words
  where
    f (x:y:zs) "+" = (y + x):zs
    f (x:y:zs) "-" = (y - x):zs
    f (x:y:zs) "*" = (y * x):zs
    f (x:y:zs) "/" = (y / x):zs
    f xs y = read y : xs

main = do
  s <- getContents
  putStr $ unlines $ map show $ map head $ map calc $ lines s

Measured memory_bytes: 4408
n = int(input())
a = list(map(int, input().split()))
inf = 10**18
if n%2 == 0:
    dp = [[-inf]*2 for _ in range(n+2)]
    dp[-2][0] = 0
    for i in range(n):
        for j in range(2):
            for k in range(2):
                if j-k>=0:
                    dp[i][j] = max(dp[i][j], dp[i-k-2][j-k]+a[i])
    print(max(max(dp[n-1]), max(dp[n-2][:1])))
else:
    dp = [[-inf]*3 for _ in range(n+2)]
    dp[-2][0] = 0
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if j-k>=0:
                    dp[i][j] = max(dp[i][j], dp[i-k-2][j-k]+a[i])
    print(max(max(dp[n-1][1:]), max(dp[n-2][:2]), max(dp[n-3][:1])))




Measured memory_bytes: 114244
#include <iostream>
using namespace std;
int main(){
	
	int A,B,C,D,E;
	cin >> A >> B >> C >> D  >> E;

	int answer;
	if (A < 0){
		answer = -A * C + D + B * E;
	}

	if (A > 0){
		answer = (B -A) * E;
	}

	cout << answer << endl;


		

}


Measured memory_bytes: 3088
a, b, c, d = [int(i) for i in list(input())]

for j in range(8):
    op = [[1, "+"]] * 3
    for i in range(3):
        if (j >> i) & 1:
            op[i] = [-1, "-"]
    if a + b * op[0][0] + c * op[1][0] + d * op[2][0] == 7:
        print(f"{a}{op[0][1]}{b}{op[1][1]}{c}{op[2][1]}{d}=7")
        exit()

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    (a *= a) %= MOD;
    n >>= 1;
  }
  return res;
}

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n+1);
  map<ll,ll> m;
  ll x;
  rep(i,n+1){
    cin>>a[i];
    m[a[i]]++;
    if(m[a[i]]==2) x=a[i];
  }
  
  ll l,r;
  bool flg=false;
  rep(i,n+1){
    if(a[i]==x){
      if(!flg){
        flg=true;
        l=i;
      }else{
        r=i;
      }
    }
  }
  
  rep(i,n+1){
    // n+1個からi個選ぶ方法は comb(n+1,i+1) 通り（このiは0始まりなので+1）
    // この中から1組ある同じ値によってできる組合せの重複を排除する
    // 重複ができる場合を考える
    // 1組の同じ値の左側、右側をそれぞれl,rとすると
    // 選ぶi個のうち1個がl,rのいずれかで、残りのi-1個はlより左の要素、またはrより右側の要素から選ぶ場合が重複する場合となる
    // よって、(i,l,rは0始まりなので) comb(l+n-r,i) が重複がある通り数となるのでこれを全体から引く
    ll ans=(comb(n+1,i+1)-comb(l+n-r,i)+MOD)%MOD;
    // cout<<l+n-r<<' '<<i+1<<' '<<comb(n+1,i+1)<<' '<<comb(l+n-r,i)<<' '<<ans<<endl;
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 164480
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

template <class T>
vector<T> divisor(T n) {
    vector<T> r;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            r.push_back(i);
            if (i * i != n)
                r.push_back(n / i);
        }
    }
    sort(r.begin(), r.end());
    return r;
}

signed main() {
    int N;
    cin >> N;
    int cnt = 0;
    for (int n = 1; n < N; n++){
        auto v = divisor(n);
        cnt += v.size();
    }
    cout << cnt << endl;
}

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

int main(){
	int a[4];
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	if((a[1]==a[2]&&a[1]!=a[3])||(a[1]!=a[2]&&a[2]==a[3])) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	int x;
	cin >> x;
	for (int i = 0; i < 500; i++)
	{
		bool ok = true;
		int num = x + i;
		for (int j = 2; ok && j * j <= x; j++)
		{
			if (num % j == 0)
				ok = false;
		}
		if (ok)
		{
			cout << num;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
set_ = set([])
if n == 0:
    pass
else:
    set_ = set(list(map(int, input().split())))

diff = 10 ** 18
ans = -1
for num in range(-1000, 1000)[::-1]:
    if num in set_:
        continue
    if abs(num - x) <= diff:
        diff = abs(num - x)
        ans = num
print(ans)

Measured memory_bytes: 63416
P=[int(i) for i in input().split()]
V=[250, 500, 1000, 2000]
N=int(input())*1000

for i in range(1,4):
    P[i] = min(P[i-1]*2,P[i])

ans = 0
for i in range(3,-1,-1):
    ans += N //V[i] *P[i]
    N = N %V[i]

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  string S[2]; cin >> S[0] >> S[1];

  int x_pos = 0;
  vector<int> ord;
  while(x_pos < N) {
    if (S[0][x_pos] == S[1][x_pos]) { ord.push_back(1); x_pos += 1; }
    else { ord.push_back(2); x_pos += 2; }
  }

  ll result;
  if(ord[0]==1) result = 3;
  else result = 6;
  for(int i=1; i<ord.size(); i++) {
    if (ord[i-1]==1 && ord[i]==1) result *= 2;
    else if (ord[i-1]==1 && ord[i]==2) result *= 2;
    else if (ord[i-1]==2 && ord[i]==1) result *= 1;
    else if (ord[i-1]==2 && ord[i]==2) result *= 3;
    result %= MOD;
  }

  cout << result << endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

struct SegTree{
private:
    int n; //葉の数
    vector<bitset<26>> node;
public:
    SegTree(){}
    SegTree(vector<int> v){
        int sz = v.size();
        int height = ceil(log2(sz));
        n = (1 << height);
        node.resize(2*n-1, 0);
        rep(i, sz){
            node[i + (n-1)].set(v[i]);
        }
        for(int i = n-2; i >= 0; i--) node[i] = node[(i<<1)+1] | node[(i<<1)+2];
    }

    bitset<26> count(int a, int b, int k=0, int l=0, int r=-1){
        if(r == -1) r = n;
        if(r <= a || b <= l) return 0;
        else if(a <= l && r <= b) return node[k];
        else{
            bitset<26> v1 = count(a, b, (k<<1)+1, l, (l+r)/2);
            bitset<26> v2 = count(a, b, (k<<1)+2, (l+r)/2, r);
            return v1|v2;
        }
    }

    void change(int pos, int val){
        node[pos + (n-1)] &= 0;
        node[pos + (n-1)].set(val);
        int temp = pos + (n-1);
        while(temp > 0){
            temp = (temp-1)/2;
            node[temp] = node[(temp<<1) + 1] | node[(temp<<1) + 2];
        }
    }
};

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    vector<int> v(N); rep(i, N) v[i] = S[i]-'a';
    SegTree st(v);

    int Q; cin >> Q;
    rep(i, Q){
        int cmd; cin >> cmd;
        if(cmd == 1){
            int idx; char c; cin >> idx >> c;
            st.change(idx-1, c-'a');
        }
        else{
            int l, r; cin >> l >> r;
            l--;
            cout << st.count(l, r).count() << endl;
        }
    }
    return 0;
}

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

int main() {
	int n; cin >> n;
	deque<int>a;
	for (int i = 0,tmp; i < n; i++) {
		cin >> tmp;
		if (n % 2 == 0) {
			if (i % 2 == 0)a.push_back(tmp); else a.push_front(tmp);
		}
		else {
			if (i % 2 == 0)a.push_front(tmp); else a.push_back(tmp);
		}
	}
	for (auto&& x : a)cout << x << ' '; cout << endl;

	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main()
{
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


Measured memory_bytes: 2732
import itertools
n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
figlist = list(itertools.permutations(range(1,n+1)))
for i in range(len(figlist)):
  if a == figlist[i]:anum = i
  if b == figlist[i]:bnum = i
print(abs(anum-bnum))

Measured memory_bytes: 45424
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
typedef pair<int, int> P;
#define int long long
vector<int> G[200010];
int ans;
bool visited[200010];
int X[100010], Y[100010];
int cntX, cntY;
void dfs(int v) {
    if (visited[v]) return;
    visited[v] = true;
    if (v <= 100000) cntX++;
    else cntY++;
    for(auto to: G[v]) {
        dfs(to);
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N) {
        int s, t; cin >> s >> t;
        X[i] = s;
        Y[i] = t + 100000;
        G[s].push_back(100000 + t);
        G[100000 + t].push_back(s);
    }
    rep(i, N) {
        if (visited[X[i]]) continue;
        if (visited[Y[i]]) continue;
        cntX = cntY = 0;
        dfs(X[i]);
        ans += cntX * cntY;
    }
    cout << ans - N << endl;



    return 0;
}


Measured memory_bytes: 12928
'use strict'

const main = arg => {
    var input = arg.trim().split("\n");
    const lexico = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
    const turns = input[0];
    const compete = input.slice(1).slice(0, turns);
    var taro = 0;
    var hanako = 0;

    compete.forEach(str => {
        const cards = str.split(" ");
        const taroPower = lexico.indexOf(cards[0][0]);
        const hanakoPower = lexico.indexOf(cards[1][0]);

        if(cards[0] === cards[1]){
            taro++;
            hanako++;
        } else if(taroPower > hanakoPower){
            taro += 3;
        } else if(taroPower < hanakoPower){
            hanako += 3;
        } else {
            const longer = cards[0].length > cards[1].length ? cards[0] : cards[1];
            [...Array(longer.length)].some((theStr,i) => {
                if(cards[0].length < i){ hanako += 3;return true; }
                if(cards[1].length < i){ taro += 3;return true; }
                if(cards[0][i] !== cards[1][i]){
                    const theTaroPower = lexico.indexOf(cards[0][i]);
                    const theHanakoPower = lexico.indexOf(cards[1][i]);
                    if(theTaroPower > theHanakoPower){
                        taro += 3;
                        return true;
                    } else if(theTaroPower < theHanakoPower){
                        hanako += 3;
                        return true;
                    }        
                }
            });
        }
    });

    console.log(`${taro} ${hanako}`);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 17400
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()


int main(){
    int d;
    ll g;
    cin >> d >> g;
    vector<int> p(d);
    vector<ll> c(d);
    rep(i, d)cin >> p[i] >> c[i];

    ll res = 100000;
    rep(bit, (1<<d)){
        ll sum = 0;
        ll num = 0;
        rep(i, d)if(bit & (1<<i))sum += c[i] + p[i]*100*(i+1), num += p[i];
        if(sum >= g)res=min(res, num);
        else{
            for(int i = d-1; i >= 0; i--){
                if(bit & (1<<i))continue;
                rep(j, p[i]){
                    if(sum >= g)break;
                    sum += 100*(i+1);
                    num++;
                }
            }
            res = min(res, num);
        }
    }
    cout << res << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4){
    if(s[i]=='2'){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
    int n;
    std::cin >> n;
    std::vector<ll> a(n);
    ll cou=0;
    rep(i,n){
        std::cin >> a[i];
        if(a[i]<0ll){
            a[i]*=-1ll;
            cou++;
        }
    }
    sort(all(a));
    if(cou%2==1)a[0]*=-1ll;
    std::cout << sum(all(a),0ll) << std::endl;
}

Measured memory_bytes: 1024
object Main extends App {
  import scala.io.StdIn._
  def is_prime(p: Long):Boolean={
    if(p<=1) return false
    for {i <- 2L to(p) if(i * i <= p)} {
      if (p % i == 0) return false
    }
    return true
  }
  val x = readLong()
  var p = x
  while (!is_prime(p)) p+=1
  println(p)
}


Measured memory_bytes: 55776
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1int;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  reverse(all(v));
  vector<ll> v1;
  rep(i,0,n-1){
    if(v[i]==v[i+1]){
      v1.pb(v[i]);
      i++;
    }
  }
  sort(all(v1));
  reverse(all(v1));
  if(v1.sz<2){
    cout << 0 << endl;
  }
  else{
    printf("%lld\n",v1[0]*v1[1]);
  }
  return 0;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int red[maxn], green[maxn], white[maxn];
priority_queue<int, vector<int>, greater<int> >r,g,w;
bool cmp(int a,int b){return a > b;}
int main(){

	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	for(int i = 1 ; i <= a ; i++){
		cin >> red[i];
	}
	for(int i = 1 ; i <= b ; i++){
		cin >> green[i];
	}
	for(int i = 1 ; i <= c ; i++){
		cin >> white[i];
	}
	sort(red + 1, red + 1 + a, cmp);
	sort(green + 1, green + 1 + b, cmp);
	sort(white + 1, white + 1 + c, cmp);

	for(int i = 1 ; i <= x ; i++)r.push(red[i]);
	for(int i = 1 ; i <= y ; i++)g.push(green[i]);
	int cnt;
	for(int i = c ; i >= 1 ; i--){
		cnt = white[i];
		if(r.top() > g.top()){
			g.push(cnt);
			g.pop();
		}
		else{
			r.push(cnt);
			r.pop();
		}
	}
	long long ans = 0;
	while(!r.empty()){
		ans += r.top();
		r.pop();
	}
	while(!g.empty()){
		ans += g.top();
		g.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 2552
from collections import Counter


def solve(n, m, v, p, aaa):
    aaa.sort(reverse=True)
    count = Counter(aaa)
    scores = sorted(count.keys(), reverse=True)

    tmp_cnt = 0
    for pi, s in enumerate(scores):
        c = count[s]
        tmp_cnt += c
        if tmp_cnt >= p:
            ans = tmp_cnt
            rival = s
            htm_cnt = tmp_cnt - (p - 1)  # higher than me excluding top p-1
            htm_sum = s * htm_cnt
            break
    else:
        raise RuntimeError

    # print(ans)
    # print(rival)
    # print(htm_cnt, htm_sum)

    for s in scores[pi + 1:]:
        c = count[s]
        upper = s + m
        if upper < rival:
            break

        v4mtm = v - (n - htm_cnt)  # remaining vote for higher than s excluding top p-1
        if v4mtm <= 0:
            ans += c
        else:
            space = upper * htm_cnt - htm_sum
            if space >= m * v4mtm:
                ans += c

        htm_cnt += c
        htm_sum += s * c

    return ans


n, m, v, p = map(int, input().split())
aaa = list(map(int, input().split()))
print(solve(n, m, v, p, aaa))


Measured memory_bytes: 18912