akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DAxisParallelRectangle solver = new DAxisParallelRectangle();
        solver.solve(1, in, out);
        out.close();
    }

    static class DAxisParallelRectangle {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            int k = in.nextInt();
            ArrayList<GridPoint> al = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                al.add(new GridPoint(in.nextInt(), in.nextInt()));
            }

            long res = Long.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    for (int l = 0; l < n; l++) {
                        for (int m = 0; m < n; m++) {
                            long xl = al.get(i).x;
                            long xr = al.get(j).x;
                            long yl = al.get(l).y;
                            long yh = al.get(m).y;
                            int cnt = 0;
                            for (GridPoint gp : al) {
                                if (xl <= gp.x && gp.x <= xr && yl <= gp.y && gp.y <= yh) {
                                    cnt++;
                                }
                            }
                            if (cnt == k) {
                                res = Math.min(res, (xr - xl) * (yh - yl));
                            }
                        }
                    }
                }
            }
            out.println(res);

        }

    }

    static class GridPoint {
        public long x;
        public long y;

        public GridPoint(long x, long y) {
            this.x = x;
            this.y = y;
        }

        public String toString() {
            return "grid:(" + x + ", " + y + ')';
        }

    }
}



Measured memory_bytes: 59828
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,k;
double ans;

int main()
{
	cin>>n>>k;
	repn(i,n)
	{
		if(i>=k)
		{
			ans+=(1.0)/(double)(n);
			continue;
		}
		int p=i,t=1;
		while(p<k) p*=2,t*=2;
		ans+=(1.0)/(double)(t*n);
		//cout<<t<<endl;
	}
	printf("%.12lf\n",ans);
	rt0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

using namespace std;



signed main(){
    
    int n;
    set<int> s;
    cin>>n;
    rep(i,n){
        int b;
        cin>>b;
        s.insert(b);
    }
    if(s.size()%2==1)cout<<s.size()<<endl;
    else cout<<s.size()-1<<endl;
    
    
    
    
}

Measured memory_bytes: 4992
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for(auto &x:A){
    cin >> x;
  }
  set<int>st;
  for(int i=0;i<1<<n;i++){
    int ret = 0;
    for(int j=0;j<n;j++)if((i>>j)&1)ret+=A[j];
    st.insert(ret);
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int m;
    cin >> m;
    if(st.find(m)!=st.end())cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}


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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 1005;
const int p = 1e9 + 7;

bool a[N][N];
int dp[N][N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            char c;
            cin >> c;
            if (c == '#') a[i][j] = 1;
        }
    }
    dp[1][1] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            if (!a[i][j] && !(i == 1 && j == 1)) {
                dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % p;
            }
        }
    }
    cout << dp[n][m] << "\n";
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


int main() {
	cout << fixed << setprecision(18);
	string s,t;
	//cin>>s>>t;
	while(s!="."){
		cin>>s;
		if(s=="."){return 0;}
		cin>>t;
		if(s==t){cout<<"IDENTICAL"<<endl;continue;}
		string stmp,ttmp;
		queue<string>sq,tq;
		long long int stime=0,ttime=0;
		for(int i=0;i<s.length();i++){
			if(s[i]=='"'){
				long long int id=i+1,len=0;
				i++;
				while(s[i]!='"'){
					i++;
					len++;
				}
				sq.push(s.substr(id,len));
				stmp.push_back('"');
				stmp.push_back('"');
			}else{
				stmp.push_back(s[i]);
			}
		}
		for(int i=0;i<t.length();i++){
			if(t[i]=='"'){
				long long int id=i+1,len=0;
				i++;
				while(t[i]!='"'){
					i++;
					len++;
				}
				tq.push(t.substr(id,len));
				ttmp.push_back('"');
				ttmp.push_back('"');
			}else{
				ttmp.push_back(t[i]);
			}
		}

		if(stmp!=ttmp){
			cout<<"DIFFERENT"<<endl;
			continue;
		}
			long long int cou=0;
		while(!sq.empty()){
			if(sq.front()!=tq.front()){cou++;}
			sq.pop();
			tq.pop();
		}
		if(cou>=2){cout<<"DIFFERENT"<<endl;}
		else{cout<<"CLOSE"<<endl;}
		
		
	}
} 



Measured memory_bytes: 3076
<?php
 fscanf(STDIN, "%d %d %d", $a, $b, $c);
$array = array($a, $b, $c);
$count = array_count_values($array);
if($count[7] == 1 && $count[5] == 2){
    print 'YES';
}else{
    print 'NO';
}

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

int main()
{
	int r, c;
	int table[100][100];
	cin >> r >> c;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> table[i][j];
		}
	}

	int rsum;
	for(int i = 0; i < r; i++){
		rsum = 0;
		for(int j = 0; j < c; j++){
			cout << table[i][j] << ' ';
			rsum += table[i][j];
		}
		cout << rsum << endl;
	}
	int total = 0;
	int csum;
	for(int i = 0; i < c; i++){
		csum = 0;
		for(int j = 0; j < r; j++){
			csum += table[j][i];
		}
		cout << csum << ' ';
		total += csum;
	}
	cout << total << endl;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int n, a, b;

int main(int argc, char **argv) {
	cin >> n;
	int ma = 0, res = 0;
	REP(i, n) {
		cin >> a >> b;
		if (a >= ma) res = a + b;
		ma = max(ma, a);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
// URLD
long double dx[4]={0,1,-1,0};
long double dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

long double f(long double x,long double y){
    return x*x+y*y;
}

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

    
   int n;
   cin>>n;
   array<long double,3> a[n];
   for(int i=0;i<n;i++){
       long double x,y;
       cin>>x>>y;
       a[i] = {atan2(y,x),x,y};
   }
   sort(a,a+n);
   int r = 0;
   long double x=0,y=0;
   long double ans = 0;
   long double now = 0;

   for(int i=0;i<n;i++){
       x=0,y=0;
       for(int j=i;j<n+i;j++){
           if(now > f(a[j%n][1]+x,a[j%n][2]+y))continue;
           x += a[j%n][1];
           y += a[j%n][2];
           chmax(ans,f(x,y));
       }
   }
   cout << sqrt(ans) << endl;

}


Measured memory_bytes: 3876
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    bool ka = false;
    if (a == b && a != c) ka = true;
    if (a == c && a != b) ka = true;
    if (c == b && a != c) ka = true;
    string s = ka ? "Yes" : "No";
    cout << s << endl;
    return 0;
}



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

int N,Ma,Mb;
const int MAX_N = 45;
const int INF = 1e9;
int a[MAX_N], b[MAX_N], c[MAX_N];

int dp[MAX_N][MAX_N*10][MAX_N*10];

int gcd(int x,int y){
    return y?gcd(y,x%y):x;
}

int solve(int x,int A,int B){
    int g = gcd(A,B);
    if(g!=0 && A/g==Ma && B/g==Mb){
        return 0;
    }
    if(x==N){
        return INF;
    }

    int& ret = dp[x][A][B];
    if(~ret)return ret;
    ret = solve(x+1, A, B);
    ret = min(ret, solve(x+1, A+a[x], B+b[x]) + c[x]);
    return ret;
}

int main(){
    scanf("%d%d%d",&N,&Ma,&Mb);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }

    memset(dp,-1,sizeof(dp));
    int ans = solve(0,0,0);
    if(ans >= INF){
        puts("-1");
    }else{
        printf("%d\n",ans);
    }
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;

int main(){
	getline(cin,s);
  ll n=s.size();
  stack<ll> st;
  rep(i,n){
    char c=s[i];
    if('0'<=c&&c<='9'){
      int j=i;
      while(j<n&&'0'<=s[j]&&s[j]<='9')j++;
      st.push(stoi(s.substr(i,j-i)));
      i=j;
    }else{
      ll l=st.top();
      st.pop();
      ll r=st.top();
      st.pop();
      if(c=='+')st.push(l+r);
      if(c=='-')st.push(r-l);
      if(c=='*')st.push(l*r);
    }
    i++;
    while(i<n&&s[i]==' ')i++;
    i--;
  }
  cout<<st.top()<<endl;
	return 0;
}

Measured memory_bytes: 3156
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc  = new Scanner(System.in);
      	int n = sc.nextInt();
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int total = 0;
      	for(int i = 1; i <= n; i++){
        	int sum = calcSum(i);
          	if(sum >= a && sum <= b) total += i;
        }
      	System.out.println(total);
    }
  	//nの各桁の和
  	public static int calcSum(int n){
      	int sum = 0;
      	while(n > 0){
        	sum += n % 10;
          	n /= 10;
        }
      	return sum;
    }
}

Measured memory_bytes: 35464
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int n, m, q;
vector<int> a, b, c, d;

ll score (const vector<int> &A) {
    ll res = 0;
    for(int i = 0; i < q; i++) {
        if (A[b[i]] - A[a[i]] == c[i]) res += d[i];
    }
    return res;
}

ll dfs(vector<int> &A) {
    if (A.size() == n) {
        return score(A);
    }

    ll res = 0;
    int prev_last = (A.empty() ? 1 : A.back());
    for (int v = prev_last; v <= m; v++) {
        A.push_back(v);
        res = max(res, dfs(A));
        A.pop_back();
    }

    return res;
    
}

int main() {

    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);    
    REP(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    vector<int> A;
    cout << dfs(A) << endl;

    return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>

int main(void)
{
	int a,b,n,keta;
		
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		keta=0;
		n=a+b;
		do{
			n/=10;
			keta++;
		}while(n!=0);
		
		printf("%d\n",keta);
	}
	return 0;
}

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

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var n = int.Parse(s);
        var sL = s.Length;
        if (sL <= 2) { Console.WriteLine(0); goto exit; }
        var ans = getAns(sL, n);
        Console.WriteLine(ans);
        exit:;
    }
    static int getAns(int sL, int n)
    {
        var st = new Stack<string>();
        var a357 = new string[] { "3", "5", "7" };
        var count = 0;
        foreach (var x in a357) st.Push(x);
        while (st.Count() > 0)
        {
            var w = st.Pop();
            if (w.Length < sL)
            {
                foreach (var x in a357) st.Push(w + x);
                if (w.Contains("3") && w.Contains("5") && w.Contains("7")) count++;
            }
            else if (w.Contains("3") && w.Contains("5") && w.Contains("7") &&
                        int.Parse(w) <= n) count++;
        }
        return count;
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A,B,C;
    int count=0;
    cin>>A>>B>>C;
    if(C>=1+(A+B)){
        count+=(A+B)+1+B;
    }
    else{
        count+=(B+C);
    }
    cout<<count;
return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define re(i,n) for(int i=0; i < n; i++)
 using namespace std;
int main(){
  int N;
  cin >> N;
  int L[N];
  re(i,N){cin >> L[i];}
  int max=0;
  re(i,N){
    if(L[i] > max) max = L[i];
  }
  int sum=0;
  re(i,N){sum += L[i];}
  if(max >= (sum-max)) cout << "No" << endl;
  else cout << "Yes" << endl;
}
  

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

int main(){
	string a;
	cin >> a;
	if(((a[0]-48)*1000+(a[1]-48)*100+(a[2]-48)*10+(a[3]-48))<=2019){
		if(((a[5]-48)*10+a[6]-48)<=4){
			if(((a[8]-48)*10+a[9]-48)<=30){
				cout << "Heisei";
			}
			else{
				cout << "TBD";
			}
		}
		else{
			cout << "TBD";
		}
	}
	else{
		cout << "TBD";
	}
	return 0;
}

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

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

flag = 0

if(a < 1 or 3 < a or b < 1 or 3 < b):
    exit()

for i in range(1, 4):
    if((a*b*i)%2 == 1):
        print('Yes')
        flag = 1
        break

if(flag == 0):
    print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,m,a[100][100],b[100];
    cin>>n>>m;
    rep(i,n)rep(j,m)cin>>a[i][j];
    rep(i,m)cin>>b[i];
    rep(i,n){
        int sum=0;
        rep(j,m)sum+=b[j]*a[i][j];
        cout<<sum<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	string s;
	cin>>s;
	ll q;
	cin>>q;
	bool rev = 0;
	string fr,ls;
	FOR(i,0,q)
	{
		ll a;
		cin>>a;
		if(a == 1)
		{
			rev^=1;
			continue;
		}
		ll b;
		cin>>b;
		char c;
		cin>>c;
		ll pos = (b-1)^rev;
		if(pos == 0)fr.insert(fr.begin(),c);
		else ls+=c;
	}
	s = fr+s+ls;
	if(rev)reverse(all(s));
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 4308
use v6;

my Int ($n, $m) = get.words>>.Int;
my Int $made = 0;
if 2 * $n >= $m {
  $made = $m div 2;
}
else {
  $made = $n;
  $m -= 2 * $n;
  $made += $m div 4;
}

say $made;


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

void insertionSort(int A[], const int n, const int g, int *cnt)
{
    for( int i = g; i < n; ++i ){
        int tmp = A[i];
        int j = i - g;
        while( -1 < j && tmp < A[j] ){
            //cout << A[j+g] << "<-->" << A[j] << endl;
            A[j+g] = A[j];
            j = j - g;
            ++*cnt;
        }
        A[j+g] = tmp;
    }
}

void shellSort(int A[], const int n)
{
    int cnt = 0;
    int m;
    int G[100];
    for( int i = 0; i < 100; ++i ){
        if( i == 0 ) G[i] = n / 2 + 1;
        else G[i] = G[i-1] / 2 - 1;
        if( G[i] < 0 ){
            G[i-1] = 1;
            G[i] = 0;
            m = i;
            break;
        }
    }

    for( int i = 0; i < m; ++i )
        insertionSort(A, n, G[i], &cnt);

    //出力
    printf("%d\n", m);
    for( int i = 0; i < m; ++i ){
        if( i ) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n%d\n", cnt);
    for( int i = 0; i < n; ++i )
        printf("%d\n", A[i]);
}

int main()
{
    //入力
    int n;
    scanf("%d", &n);
    int A[n];
    for( int i = 0; i < n; ++i )
        scanf("%d", &A[i]);

    //シェルソート
    shellSort(A, n);

    return 0;
}


Measured memory_bytes: 7140
class Main
    @dice
    @sum
    @first_flag
    @end_flag
    def main
        @sum        = 1 
        @end_flag   = 0 
        @first_flag = 1 
        while input = gets
            input.chomp!

            if @end_flag == 0
                if @first_flag == 1
                    @sum = 1 
                    @dice = Dice.new
                    @first_flag = 0 
                else
                    puts @sum
                    @sum = 1 
                    @dice = Dice.new
                end 
            end 

            @end_flag -= 1

            if input == "North"
                @dice.moveNorth
                @sum += @dice.getUpside
                next
            end 


            if input == "South"
                @dice.moveSouth
                @sum += @dice.getUpside
                next
            end

            if input == "East"
                @dice.moveEast
                @sum += @dice.getUpside
                next
            end

            if input == "West"
                @dice.moveWest
                @sum += @dice.getUpside
                next
            end

            if input == "Right"
                @dice.moveRight
                @sum += @dice.getUpside
                next
            end

            if input == "Left"
                @dice.moveLeft
                @sum += @dice.getUpside
                next
            end
            if input.to_i === 0
                exit
            end

            @end_flag = input.to_i
        end
    end
end

class Dice
    @upside
    @downside
    @east
    @west
    @north
    @south

    def initialize
        @upside   = 1
        @downside = 6
        @east     = 3
        @west     = 4
        @north    = 5
        @south    = 2
    end

    def moveRight
        temp      = @north
        @north    = @west
        @west     = @south
        @south    = @east
        @east     = temp
    end

    def moveLeft
        temp      = @north
        @north    = @east
        @east     = @south
        @south    = @west
        @west     = temp
    end

    def moveWest
        temp      = @upside
        @upside   = @east
        @east     = @downside
        @downside = @west
        @west     = temp
    end

    def moveEast
        temp      = @upside
        @upside   = @west
        @west     = @downside
        @downside = @east
        @east     = temp
    end

    def moveSouth
        temp      = @upside
        @upside   = @north
        @north    = @downside
        @downside = @south
        @south    = temp
    end

    def moveNorth
        temp      = @upside
        @upside   = @south
        @south    = @downside
        @downside = @north
        @north    = temp
    end

    def getUpside
        return @upside
    end
end

Main.new.main

Measured memory_bytes: 6116
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int x_diff = sx-tx;
  int y_diff = sy-ty;
  // 1回目
  if(y_diff < 0){
    cout << string(abs(y_diff), 'U');
  }else{
    cout << string(abs(y_diff), 'D');
  }
  if(x_diff < 0){
    cout << string(abs(x_diff), 'R');
  }else{
    cout << string(abs(x_diff), 'L');
  }
  // 1回目往復
  if(y_diff > 0){
    cout << string(abs(y_diff), 'U');
  }else{
    cout << string(abs(y_diff), 'D');
  }
  if(x_diff > 0){
    cout << string(abs(x_diff), 'R');
  }else{
    cout << string(abs(x_diff), 'L');
  }

  // 2回目
  if(x_diff > 0){
    cout << 'R';
  }else{
    cout << 'L';
  }

  if(y_diff < 0){
    cout << string(abs(y_diff)+1, 'U');
  }else{
    cout << string(abs(y_diff)+1, 'D');
  }
  if(x_diff < 0){
    cout << string(abs(x_diff)+1, 'R');
  }else{
    cout << string(abs(x_diff)+1, 'L');
  }

  if(y_diff > 0){
    cout << 'U';
  }else{
    cout << 'D';
  }

  // 2回目往復
  if(x_diff < 0){
    cout << 'R';
  }else{
    cout << 'L';
  }

  if(y_diff > 0){
    cout << string(abs(y_diff)+1, 'U');
  }else{
    cout << string(abs(y_diff)+1, 'D');
  }
  if(x_diff > 0){
    cout << string(abs(x_diff)+1, 'R');
  }else{
    cout << string(abs(x_diff)+1, 'L');
  }

  if(y_diff < 0){
    cout << 'U';
  }else{
    cout << 'D';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    string res = "";

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

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

# factorials
_nfact = 2 * (10 ** 5) + 10
facts = [0] * _nfact
facts[0] = 1
for i in range(1, _nfact):
    facts[i] = (facts[i - 1] * i) % MOD
ifacts = [0] * _nfact
ifacts[-1] = INV(facts[-1])
for i in range(_nfact - 1, 0, -1):
    ifacts[i - 1] = (ifacts[i] * i) % MOD

def binomial(m, n):
    return facts[m] * ifacts[n] * ifacts[m - n]

def main():
    N, A, B, C = LI()
    D = DIV(100, 100 - C)
    ans = 0
    ap, bp, abp = [1], [1], [POW(A + B, N)]
    for _ in range(0, N + 1):
        ap.append(ap[-1] * A % MOD)
        bp.append(bp[-1] * B % MOD)
        abp.append(abp[-1] * (A + B) % MOD)
    for m in range(N, 2 * N):
        x = binomial(m - 1, N - 1) * DIV(
            ap[N] * bp[m - N] + ap[m - N] * bp[N],
            abp[m - N]) % MOD
        y = (m * D) % MOD
        ans = (ans + (x * y) % MOD) % MOD
    return ans

print(main())

Measured memory_bytes: 31044
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, A, COUNT[60] = {};
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		for (int j = 0; j < 60; j++) {
			COUNT[j] += A % 2;
			A /= 2;
		}
	}
	long long ANS = 0;
	for (long long i = 0; i < 60; i++) {
		ANS += (((COUNT[i] * (N - COUNT[i])) % 1000000007) * ((1LL << i) % 1000000007)) % 1000000007;
		ANS %= 1000000007;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
N = int(input())

ABlist = []

for i in range(N):
    A, B = map(int, input().split())
    ABlist.append((A, B))

ABlist = sorted(ABlist, key = lambda x: x[1])

ans = "Yes"
Asum = 0

for i in ABlist:
    Asum += i[0]
    if(Asum > i[1]):
        ans = "No"
        break
    
print(ans)

Measured memory_bytes: 33468
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int m1,m2,d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  COUT( m1 < m2 ? 1 : 0 );

  return 0;
}

Measured memory_bytes: 3556
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t a, b, c;

	scanf("%zu\n%zu\n%zu", &a, &b, &c);

	if (a == b && b == c) {
		puts("1");
	}
	else if (a == b || b == c || c == a) {
		puts("2");
	}
	else {
		puts("3");
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define re register
using namespace std;
const int maxn=1e5+10;
template<typename T> void read(T &x){
	T f=1;x=0;
	char c=getchar();
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	x*=f;
}
int n;
int a[maxn][3];
int f[maxn][3];
int main(){
	read(n);
	for(re int i=1;i<=n;i++){
		read(a[i][0]);read(a[i][1]);read(a[i][2]);
	}
	for(re int i=1;i<=n;i++){
		for(re int j=0;j<3;j++){
			for(re int k=0;k<3;k++){
				if(j!=k){
					f[i][j]=max(f[i][j],f[i-1][k]+a[i][j]);
				}
			}
		}
	}
	cout<<max(f[n][0],max(f[n][1],f[n][2]));
	return 0;
}


Measured memory_bytes: 2560
S = input()

if S == "SAT":
    print(1)
elif S == "FRI":
    print(2)
elif S == "THU":
    print(3)
elif S == "WED":
    print(4)
elif S == "TUE":
    print(5)
elif S == "MON":
    print(6)
else:
    print(7)
 


Measured memory_bytes: 2940
#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() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, t) cin >> a[i];

  sort(a.rbegin(), a.rend());
  int ans = 0;
  for(int i = 1; i < t; ++i){
    ans += a[i];
  }
  ans = max(0, a[0] - ans - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  string S;cin>>S;
  vector<int> num(S.size());
  REP(i,0,S.size()){
    num[i]=S[i]-'0';
  }
  int n=S.size();
  int ans=-1;
  vector<vector<int>> dp(n,vector<int>(2,0));
  dp[0][0]=num[0];dp[0][1]=num[0]-1;
  REP(i,1,n){
    dp[i][0]=dp[i-1][0]+num[i];
    if(num[i]>0){
      dp[i][1]=max(dp[i-1][1]+9,dp[i-1][0]+num[i]-1);
    }
    else{
      dp[i][1]=dp[i-1][1]+9;
    }
  }
  print(max(dp[n-1][0],dp[n-1][1]));

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

struct edge{
    int to, cap, rev;
};

int H, W;
const int MAX_V = 3e4;
vector<edge> es[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap = 1){
    edge e1 = {to, cap, (int)es[to].size()}, e2 = {from, cap, (int)es[from].size()};
    es[from].pb(e1), es[to].pb(e2);
}

int dfs(int now, int goal, int flow){
    if(now == goal) return flow;
    used[now] = true;
    for(auto &e: es[now]){
        if(used[e.to] || e.cap == 0) continue;
        int d = dfs(e.to, goal, min(flow, e.cap));
        if(d > 0){
            e.cap -= d;
            es[e.to][e.rev].cap += d;
            return d;
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    while(true){
        fill(used, used+MAX_V, false);
        int f = dfs(s, t, inf);
        if(f == 0) break;
        flow += f;
    }
    return flow;
}

int main(){
    int H, W;
    cin >> H >> W;
    string a[H];
    rep(i, H) cin >> a[i];
    int s, t;
    rep(i, H) rep(j, W){
        if(a[i][j] == 'S') s = W*i+j;
        if(a[i][j] == 'T') t = W*i+j;
        if(a[i][j] != '.') add_edge(W*i+j, H*W + W*i+j);
    }
    if(s%W == t%W || s/W == t/W){
        cout << -1 << endl;
        return 0;
    }
    rep(i, H){
        vector<int> v;
        rep(j, W){
            if(a[i][j] != '.') v.pb(j);
        }
        rep(p, v.size()) rep2(q, p+1, v.size()-1){
            add_edge(W*i+v[p], W*i+v[q]);
        }
    }
    rep(j, W){
        vector<int> v;
        rep(i, H){
            if(a[i][j] != '.') v.pb(i);
        }
        rep(p, v.size()) rep2(q, p+1, v.size()-1){
            add_edge(H*W + W*v[p]+j, H*W + W*v[q]+j);
        }
    }
    add_edge(s, 2*H*W, inf), add_edge(s+H*W, 2*H*W, inf);
    add_edge(t, 2*H*W+1, inf), add_edge(t+H*W, 2*H*W+1, inf);
    cout << max_flow(2*H*W, 2*H*W+1) << endl;
}

Measured memory_bytes: 32384
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;

//B. Qualification simulator //
int main() {
	//receive N, A, B, and a string of N with a, b,c
	int numPpl, a, b;
	string s;
	cin >> numPpl >> a >> b >> s;
	int aCount = 0, bCount = 0, sum = a+b;
	vector<string> ret(numPpl, "No");

	for (int i = 0; i < numPpl; i++) {
		if (s[i] == 'a' && (aCount + bCount) < sum) {
			ret[i] = "Yes";
			aCount++;
		}
		else if (s[i] == 'b' && (aCount +bCount) < sum && bCount < b) {
			ret[i] = "Yes";
			bCount++;
		}
		else
			continue;
	}

	for (int i = 0; i < numPpl; i++) {
		cout << ret[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 100000000
using namespace std;

int N, T[20][20];
int dp[1 << 20];

int cost(int s, int n) {
  int ret = INF;
  REP(i, 0, N + 1) if(s & (1 << i)) ret = min(ret, T[n][i]);
  return ret;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 1, N + 1) REP(j, 0, N + 1) cin >> T[i][j];
    REP(i, 0, 1 << (N + 2)) dp[i] = INF;
    dp[1] = 0;
    REP(i, 1, 1 << (N + 2)) {
      if((i & 1) == 0) continue;
      REP(j, 1, N + 1) if((i & (1 << j)) == 0) {
        dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost(i, j));
      }
    }
    cout << dp[(1 << (N + 1)) - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 4024
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String []s = br.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);

        s = br.readLine().split(" ");
        int []h = new int[N];
        for(int i=0; i < N; ++i)
            h[i] = Integer.parseInt(s[i]);

        int []dp = new int[N];
        Arrays.fill(dp, Integer.MAX_VALUE);

        dp[0] = 0;
        dp[1] = Math.abs(h[0] - h[1]);

        for(int i=2; i < N; ++i)
            for(int j = (i-K < 0 ? 0 : i - K); j < i; ++j)
                dp[i] = Math.min(dp[i], dp[j] + Math.abs(h[i] - h[j]));

        System.out.println(dp[N-1]);
    }
}

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

int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	rep(i, n) cin >> a[i];
  	
  	ll x = 1000;
  	rep(i, n-1){
    	int s = a[i];
      	int t = a[i+1];
      	if(s < t){
        	ll k = x / s;
          	x %= s;
          	x += k*t;
        }
    }
  	
  	cout << x << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	vector<int> val;
	// 初期化
	UF(int n):par(n),sz(n),val(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
			val[y] += val[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			val[x] += val[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
	int value(int n){return val[find(n)];}
};

const ll N = 5005;
ll dp[N][N];
ll kaijo[N];
ll kake[N];

void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll n;cin >> n;

	kaijo[0] = 1;
	for(ll i = 1;i < N;i++)kaijo[i] = kaijo[i-1] * i % MOD;
	kake[0] = 1;
	REP(i, N - 1)kake[i+1] = kake[i] * (n-1) % MOD;

	ll k = 0;
	UF uf(n);
	vector<ll> v(n);REP(i, n)cin >> v[i];

	REP(i, n){
		if(v[i] != -1)continue;
		uf.val[i] = 1;
		k++;
	}

	REP(i, n){
		if(v[i] == -1)continue;

		v[i]--;
		uf.unite(i, v[i]);
	}

	ll ans = 0;
	ll base = n;
	vector<ll> ki;
	REP(i, n){
		if(uf.find(i) != i)continue;
		if(uf.value(i) == 0){
			base--;
			continue;
		}
		ki.PB(uf.size(i));
	}

	mod_add(ans, base * kake[k]);

	dp[0][0] = 1;
	REP(i, ki.size()){
		REP(j, i+1){
			mod_add(dp[i+1][j+1], dp[i][j] * ki[i]);
			mod_add(dp[i+1][j], dp[i][j]);
		}
	}

	ll mai = 0;
	REP(i, ki.size()){
		mod_add(mai, (ki[i] - 1) * kake[k-1]);
	}

	REP(i, k+1){
		if(i < 2)continue;
		mod_add(mai, ((dp[ki.size()][i] * kaijo[i-1]) % MOD) * kake[k - i]);
	}

	mod_add(ans, MOD - mai);
	cout << ans << endl;

	return 0;
}


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

int main(void){
    ll n, h;
    cin>>n>>h;
    vector<ll> v1(n);
    vector<ll> v2(n);
    rep(i, n) cin>>v1[i]>>v2[i];
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    ll mx=v1[v1.size()-1];
    auto itr=upper_bound(v2.begin(), v2.end(), mx);
    ll idx=itr-v2.begin();
    reverse(v2.begin(), v2.end());
    ll now=0;
    ll num=0;
    bool ok=false;
    rep(i, n-idx){
        now+=v2[i];
        num++;
        if(now>=h) {
            ok=true;
            break;
        }
    }
    ll ans=num;
    if(ok){
        cout<<ans<<endl;
        return 0;
    }
    else {
        while(now<h){
            now+=mx;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<tuple<string, int, int>>v(n);
	for (int i = 0; i < n; i++) {
		string s;
		int p;
		cin >> s >> p;
		v.at(i) = make_tuple(s, -1*p, i + 1);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		int x = get<2>(v.at(i));
		cout << x << endl;
	}
}

Measured memory_bytes: 256
from collections import defaultdict

def f(x,y,z):
  return x**2 + y**2 + z**2 + x*y + y*z + z*x

N = int(input())

i = 1
dic = defaultdict(lambda: set())
dic[6].add((1,1,1))

while i <= N:
  if i in dic:
    print(len(dic[i]))
    for trio in dic[i]:
      x,y,z = trio
      dic[f(x,y,z+1)].add((x,y,z+1))
      dic[f(x,y+1,z)].add((x,y+1,z))
      dic[f(x+1,y,z)].add((x+1,y,z))
  else:
    print(0)
  i += 1

Measured memory_bytes: 42616
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,k;
    cin >> n >> k;

    if(n%k == 0){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 764
N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
S, T = map(int, input().split())

if 0 == M:
	print(-1)
	exit()

graph = [set() for _ in range(N)]
for u, v in UV:
	graph[u - 1] |= {v - 1}

INF = 10 ** 12
depths = [[INF, INF, INF] for _ in range(N)]

def bfs(start, end):
	depth = 0
	nodes = {start}
	while nodes:
		if (0 == depth % 3) and (end in nodes):
			return depth // 3
		next_nodes = set()
		for node in nodes:
			if depths[node][depth % 3] <= depth:
				continue
			depths[node][depth % 3] = depth
			next_nodes |= graph[node]
		nodes = next_nodes
		depth += 1
	return -1

print(bfs(S - 1, T - 1))


Measured memory_bytes: 100696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll t;
    t=1;
    while(t--) /// get diameter nothing else
    {
        ll n,x,y;
        cin>>n>>x>>y;
        x--;y--;
        ll dp[n][n];/// to store minimum distance between i and j
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                dp[i][j]=abs(j-i);
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                    ll p=dp[i][x]+1+dp[y][j];
                    ll q=dp[i][y]+1+dp[x][j];
                    dp[i][j]=min(dp[i][j],min(p,q));
            }
        }
        map<ll,ll> mp;
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
            mp[dp[i][j]]++;
        for(int i=1;i<n;i++)
            cout<<mp[i]<<"\n";
    }
}


Measured memory_bytes: 31616
#include<stdio.h>
int main()
{
  int n,i,a;
  scanf("%d",&n);
  int x[100];
    
  for(i=0;i<=n-1;i++){
    scanf("%d",&x[i]);
  }

  for(a=n-1;a>=0;a--){
    if(a==0) { printf("%d",x[a]);
    }else  printf("%d ",x[a]);
   }
    printf("\n");    









    return 0;
  }

Measured memory_bytes: 600
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

flag = False
for i in range(3):
    if a[i][0] in b and a[i][1] in b and a[i][2] in b:
        flag = True
        break
    if a[0][i] in b and a[1][i] in b and a[2][i] in b:
        flag = True
        break
if a[0][0] in b and a[1][1] in b and a[2][2] in b:
    flag = True
if a[2][0] in b and a[1][1] in b and a[0][2] in b:
    flag = True
    
print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll N, K;


int main(){
	cin >> N >> K;
	
	vector<ll> A(N);
	for ( int i = 0; i < N; i++ ){
		cin >> A[i];
	}
	sort(A.begin(),A.end());
	
	
	ll l = -1000000000LL*1000000000-1;
	ll h =  1000000000LL*1000000000+1;
	
	// 積がh以下になるペアはK個以上あり、l以下になるペアはK個より少ない
	while ( h-l > 1 ){
		ll m = l + (h-l)/2;
		ll less_than_or_eq_m = 0;
		for ( int i = 0; i < N; i++ ){
			if ( A[i] < 0 ){
				int ct = A.end() - partition_point(A.begin(),A.end(),[&](ll a){return m<a*A[i];});
				less_than_or_eq_m += ct;
			}
			else if ( A[i] == 0 ){
				if ( 0 <= m )
					less_than_or_eq_m += N;
			}
			else {
				int ct = partition_point(A.begin(),A.end(),[&](ll a){return a*A[i]<=m;}) - A.begin();
				less_than_or_eq_m += ct;
			}
			
			if ( A[i]*A[i] <= m )
				less_than_or_eq_m--;
		}
		less_than_or_eq_m /= 2;
		//cout << "ct(A*A <= " << m << ") = " << less_than_or_eq_m << endl;
		
		if ( K <= less_than_or_eq_m )
			h = m;
		else
			l = m;
	}
	
	cout << h << endl;
	
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e9 + 7)
#define pi acos(-1)
#define eps 0.000001
using namespace std;

int n, m, sum[100005 * 4], lazy[100005 * 4], ans;

struct node
{
    int l, r;
}nd[300005];

bool cmp(const struct node & a, const struct node & b)
{
    return a.r - a.l < b.r - b.l;
}

void build(int l, int r, int nn)
{
    sum[nn] = 0;
    lazy[nn] = 0;
    if(l == r)
        return;
    int mid = (l + r) / 2;
    build(l, mid, nn * 2);
    build(mid + 1, r, nn * 2 + 1);
}

void update(int l, int r, int nn, int ll, int rr)
{
    if(l >= ll&&r <= rr)
    {
        sum[nn]++;
        lazy[nn]++;
        return;
    }
    if(l > rr||r < ll)
        return;
    if(lazy[nn])
    {
        lazy[nn * 2] += lazy[nn];
        lazy[nn * 2 + 1] += lazy[nn];
        sum[nn * 2] += lazy[nn];
        sum[nn * 2 + 1] += lazy[nn];
        lazy[nn] = 0;
    }
    int mid = (l + r) / 2;
    update(l, mid, nn * 2, ll, rr);
    update(mid + 1, r, nn * 2 + 1, ll, rr);
}

void get(int l, int r, int nn, int ll)
{
    if(l == ll&&r == l)
    {
        ans = sum[nn];
        return;
    }
    if(l > ll||r < ll)
        return;
    if(lazy[nn])
    {
        lazy[nn * 2] += lazy[nn];
        lazy[nn * 2 + 1] += lazy[nn];
        sum[nn * 2] += lazy[nn];
        sum[nn * 2 + 1] += lazy[nn];
        lazy[nn] = 0;
    }
    int mid = (l + r) / 2;
    get(l, mid, nn * 2, ll);
    get(mid + 1, r, nn * 2 + 1, ll);
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1;i <= n;i++)
        scanf("%d%d", &nd[i].l, &nd[i].r);
    build(1, m, 1);
    sort(nd + 1, nd + 1 + n, cmp);
    int nn = 0, maxs = 0;
    for(int i = 1;i <= m;i++)
    {
        while(nd[nn + 1].r - nd[nn + 1].l + 1 <= i&&nn < n)
            nn++, update(1, m, 1, nd[nn].l, nd[nn].r), maxs = max(maxs, nd[nn].r);
        int res = 0;
        for(int j = i;j <= maxs;j += i)
        {
            ans = 0;
            get(1, m, 1, j);
            res += ans;
        }
        printf("%d\n", res + n - nn);
    }
    return 0;
}

Measured memory_bytes: 5376