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

int main() {
    // insert code here...
    double a,b,c,d,oc,od;
    double answer,number1,number2;
    cin>>a>>b>>c>>d;

    number1=double (fabs(d-b));
    number2=double (fabs(c-a));
    answer=double (sqrt(number1*number1+number2*number2));
    
    printf("%lf\n",answer);
    return 0;
}





Measured memory_bytes: 3288
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;


signed main(){
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	int ans = 0;
	int t = min(A,K);
	ans += t;
	K -= t;
	t = min(B,K);
	K -= t;
	t = min(C,K);
	ans -= t;
	out(ans);
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int itemNum, popItemNum, totalVotes = 0;
    double quaterVotes = 0;
    
    scanf("%d %d", &itemNum, &popItemNum);
    int votesArray[100];
    
    // Counting total number of votes, also creating an array with single votes
    for(int i = 0; i < itemNum; i++)
    {
        int partVotes;
        scanf("%d", &partVotes);
        totalVotes += partVotes;
        votesArray[i] = partVotes;
    }
    
    quaterVotes = totalVotes * (1.0 / (4 * popItemNum));
    
    /* Using popItemNum(M) as counter to judge if the requirement of task is fulfilled.
     If goes beyond 0, then it means M popular items can be selected. */
    
    for(int i = 0; i < itemNum; i++)
    {
        if(votesArray[i] >= quaterVotes)
        {
           popItemNum--;
        }
    }
    
    if(popItemNum <= 0)
    {
        printf("Yes \n");
    }
    else
    {
        printf("No \n");
    }
    
    return 0;
}

Measured memory_bytes: 1644
def sisoku(kigou):
    if kigou=='+':return 0
    if kigou=='-':return 1
    if kigou=='*':return 2
    if kigou=='/':return 3


while(1):
    try:
        line=input("").split()
        prnd=[int(i) if i[0]=='-' and i[1:].isdigit() or i.isdigit()  else i for i in line ]
        ans,j=0,0
        while(1):
            j+=1
            if j==len(prnd):break
            if 'int' not in str(type(prnd[j])) :
                kigou=sisoku(prnd[j])
                if kigou==0: ans=prnd[j-2] +prnd[j-1]
                if kigou==1: ans=prnd[j-2] -prnd[j-1]
                if kigou==2: ans=prnd[j-2] *prnd[j-1]
                if kigou==3: ans=prnd[j-2] /prnd[j-1]
                del prnd[j-2:j]
                j=j-2
                prnd[j]=ans
        
        print('{0:.5f}'.format(prnd[0]))
        prnd=[]
    except: break



Measured memory_bytes: 5628
N = int(input())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if not d in Dic:
        Dic[d] = 1
    else:
        Dic[d] += 1

Data2 = []
for k,d in Dic.items():
    if d >= 4:
        Data2.append(k)
        Data2.append(k)
    elif d >= 2:
        Data2.append(k)

Data2.sort(reverse=True)

if len(Data2) >= 2:
    print( Data2[0]*Data2[1])
else:
    print(0)

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

string s;
long long dfs (int a, long long b, long long c) {
  if (a == s.length()) {
    return b + c;
  }
  return dfs(a + 1, b, c * 10 + (s[a] - '0')) + dfs(a + 1, b + c, s[a] - '0');
}

int main(void) {
  cin >> s;
  int len = s.length();
  long long ans = 0LL;
  cout << dfs(1, 0LL, 1LL * (s[0] - '0')) << endl;
  return 0;
}

Measured memory_bytes: 256
n,m,l=map(int, input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for i in range(m)]
c=[]


for ki in range(n):
    j=[]
    for ko in range(l):
        k=0
        for no in range(m):
            k+=a[ki][no]*b[no][ko]
        j.append(k)
    c.append(j)
    
for i in range(n):
    for j in range(l):
        print(c[i][j], end="")
        if j<l-1:
            print(" ", end="")
    print("")


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

#define int long long

using namespace std;

int a[100001];

 main () {
 	int n, c, k;
 	cin >> n >> c >> k;
 	for (int i = 1;i <= n;i ++) cin >> a[i];
 	sort (a + 1, a + n + 1);
 	int last = 0, ans = 0;
 	a[last] = 1e17 + 7;
 	for (int i = 1;i <= n;) {
 		int j = i;
 		ans ++;
 		while (j <= n && a[j] <= a[i] + k && j - i + 1 <= c) {
 			j ++;
 		}
 		i = j;
 	}
 	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int a[n],t[n-1]={};
  int ans=0, b, c;
  cin >> a[0];
  a[0]--;
  for(int i=1; i<n; i++){
    cin >> a[i];
    a[i]--;
    if(a[i]==a[i-1]+1) t[a[i-1]]=1;
  }
  for(int i=0; i<n; i++){
    cin >> b;
    ans += b;
  }
  for(int i=0; i<n-1; i++){
    cin >> c;
    ans += c*t[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

if S == 'RRR':
    print(3)
    exit()

if S == 'SRR' or S == 'RRS':
    print(2)
    exit()

if S == 'RSR' or S == 'SRS' or S == 'RSS' or S == 'SSR':
    print(1)
    exit()

print(0)


Measured memory_bytes: 8964
N,M=map(int,input().split())
ks=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))

judge=[0]*M
swich=0
count=0

for i in range(2**N):
    swich=str(bin(i)).rjust(N+2,"0")
    judge=[0]*M
    for j in range(M):
        base=0
        for k in ks[j][1:]:
            #print(swich[k+1])
            if swich[k+1]=="1":
                base+=1
        if base%2==1:
            judge[j]=1
    #print(judge)
    if judge==p:
        count+=1

print(count)


Measured memory_bytes: 3064
function main (input) {
	var price = 700;
	var input = input.split('');
	var count = 0;

	for (var i = 0; i < input.length; i++) {
		if (input[i] === 'o') {
			count++
		}
	}
	console.log(700 + 100 * count);

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


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    priority_queue<int>que;
    int ans = 0;
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] < B[i]) {
            ans++;
            sum += B[i] - A[i];
        } else {
            que.push(A[i]-B[i]);
        }
    }
    if (sum == 0) {
        cout << 0 << endl;
        return 0;
    }

    while (!que.empty()) {
        int x = que.top();
        que.pop();
        sum -= x;
        ans++;
        if (sum <= 0) {
            break;
        }
    }
    if (sum > 0) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	printf("%d\n",A*B-(A+B-1));

	return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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 ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int n;
int solve(){
    int ans=0;
    return ans;
}


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

    //while(cin >> n){
        cin >> n;
        ll ans = 0;
        vi a(n),cnt(100001);
        rep(i,n){
            cin >> a[i];
            cnt[a[i]]++;
            ans+=a[i];
        }
        int q;
        cin >> q;
        vi b(q),c(q);
        rep(i,q){
            cin >> b[i] >> c[i];
            int sa = c[i]-b[i];
            ans += (sa*cnt[b[i]]);
            cnt[c[i]] += cnt[b[i]];
            cnt[b[i]] = 0;
            cout << ans << endl;
        }

        //cout << solve() << endl;
        //cout << ans << endl;
    //}
    return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200){
    cout << s << "\n";
  }
  else{
    cout << "red\n";
  }
  return 0; 
}

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

typedef long long int ll;

const int  N = 100;
bool Visit[N];
void dfs(int n, int i, string S);

ll ans;

int main()
{
	string S;

	cin >> S;

	int len = S.length();

	dfs(len, 0, S);

	ans += stol(S);
	cout << ans << endl;

	return 0;
}

void dfs(int n, int i, string S)
{
	if (i >= n) {
		return;
	}
	else {
		string temp = "";

		if (i > 0) {
			for (int a = 0; a < n; a++) {
				temp += S[a];
				if (Visit[a]) {
					ans += stoll(temp);
					temp = "";
				}
			}
			ans += stoll(temp);
			temp = "";
		}

		for (int a = i; a < n; a++) {
			if (!Visit[a]) {
				Visit[a] = true;
				dfs(n, a + 1, S);
				Visit[a] = false;
			}
		}
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int PLUS = 10000;

    static boolean check(int start, int x, List<Integer> a) {
        boolean[] dp = new boolean[20002];
        dp[start] = true;

        for (int i = 0; i < a.size(); i++) {
            boolean[] next_dp = new boolean[20002];
            for (int j = 0; j < 20002; j++) {
                if (!dp[j]) {
                    continue;
                }
                next_dp[j + a.get(i)] = true;
                next_dp[j - a.get(i)] = true;
            }
            dp = Arrays.copyOf(next_dp, 20002);
        }
        return dp[x];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            String s = sc.next();
            int x = sc.nextInt() + PLUS;
            int y = sc.nextInt() + PLUS;

            List<Integer> ax = new ArrayList<>();
            List<Integer> ay = new ArrayList<>();

            boolean isOdd = false;

            for (int i = 0; i < s.length(); i++) {
                int cnt = 0;
                while (i < s.length() && s.charAt(i) == 'F') {
                    cnt++;
                    i++;
                }
                if (isOdd) {
                    ay.add(cnt);
                } else {
                    ax.add(cnt);
                }
                isOdd = !isOdd;
            }

            int nowX = PLUS + ax.get(0);
            int nowY = PLUS;

            if (check(nowX, x, ax.subList(1, ax.size())) && check(nowY, y, ay)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 87620
//41
#include<iostream>

using namespace std;

int n;

int d(int p,int i){
  int j=i*2;
  return (p%2)?j/10+j%10:i;
}

int main(){
  char ID[100001];
  int m;
  int a[10];
  cin>>n>>ID>>m;
  for(int i=0;i<m;i++){
    cin>>a[i];
  }
  static int dp[100001][10];
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      if(ID[n-1-i]!='*'){
	dp[i+1][(j+d(i,ID[n-1-i]-'0'))%10]+=dp[i][j];
      }else{
	for(int k=0;k<m;k++){
	  dp[i+1][(j+d(i,a[k]))%10]+=dp[i][j];
	}
      }
    }
  }
  cout<<dp[n][0]<<endl;
  return 0;
}
      

Measured memory_bytes: 5160
N = int(input())
S = input()
E = [0] * N
t = 0
for i, s in enumerate(S[len(S)-1:0:-1]):
    if s == 'E':
        t += 1
    E[-i-2] = t
    
t = 0
for i, s in enumerate(S[:len(S) - 1]):
    if s == 'W':
        t += 1
    E[i+1] += t
    
print(min(E))

Measured memory_bytes: 15476
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,sum, min = 1e9;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    sum = 0;
    if(i == 0 || n-i == 0) continue;
    string s = to_string(i);
    string t = to_string(n-i);
    for(int j = 0; j < s.size(); j++) {
      sum += s.at(j)-'0';
    }
    for(int j = 0; j < t.size(); j++) {
      sum += t.at(j)-'0';
    }
    if(min > sum) min = sum;
  }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    vector<int> v(3);
    rep(i,3){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    cout<<v[0]+v[1]<<endl;
    
    
 
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		double[] A = new double[N];
		double sum=0;
		
		for(int i=0;i<N;i++) {
			A[i]=sc.nextDouble();
			sum+=(1/A[i]);
		}
		
		System.out.println(1/sum);
		
	}
}


Measured memory_bytes: 23252
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,fractions
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
def inpl_str(): return list(sys.stdin.readline().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

h,w = inpl()
ans = h*w
for i in range(1,h):
    sa = i*w
    sb = math.floor((h-i)/2) * w
    sc = math.ceil((h-i)/2) * w
    dif_1 = max(sa,sb,sc) - min(sa,sb,sc)
    sb = math.floor(w/2) * (h-i)
    sc = math.ceil(w/2) * (h-i)
    dif_2 = max(sa,sb,sc) - min(sa,sb,sc)
    ans = min(ans,dif_1,dif_2)
for i in range(1,w):
    sa = i*h
    sb = math.floor((w-i)/2) * h
    sc = math.ceil((w-i)/2) * h
    dif_3 = max(sa,sb,sc) - min(sa,sb,sc)
    sb = math.floor(h/2) * (w-i)
    sc = math.ceil(h/2) * (w-i)
    dif_4 = max(sa,sb,sc) - min(sa,sb,sc)
    ans = min(ans,dif_3,dif_4)
print(ans)


Measured memory_bytes: 69204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,h; cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    ll n;
    cin >> n;
    v_ll a(n);
    v_ll b(n);

    irep(i, n) {
        cin >> a[i];
    }
    
    ll start = n/2;
    b[start] = a[0];

    ll l_i = 1;
    ll r_i = 1;
    irep2(i, 1, n) {
       if(i % 2 != 0) {
            b[start - l_i] = a[i]; 
            l_i++;
       } else {
            b[start + r_i] = a[i]; 
            r_i++;
       }
    }
    
    if(n % 2 == 0) { 
        irep(i, n) {
            cout << b[i] << " ";
        } cout << endl;
    } else {
        irep(i, n) {
            cout << b[n-1-i] << " ";
        } cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25


int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if (abs(a-b) % 2 == 1) {
		cout << "Borys" << endl;
	} else {
		cout << "Alice" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	string a[h] = {};
	for (int i = 0 ; i < h ; i++) cin >> a[i];
	for (int i = 0 ; i < w + 2 ; i++) cout << "#";
	cout << endl;
	for (int i = 0 ; i < h ; i++) cout << "#" << a[i] << "#" << endl;
	for (int i = 0 ; i < w + 2 ; i++) cout << "#";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    string s;
    cin >> s;

    if(s=="Sunny") cout << "Cloudy";
    else if(s=="Cloudy") cout << "Rainy";
    else cout << "Sunny";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,t[4][3][10],b,f,r,v;

	for (int a = 0;a < 4;a++){
		for (int b = 0; b < 3; b++){
			for (int c = 0; c < 10; c++){
				t[a][b][c] = 0;
			}
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		int x, y, z;
		x = b - 1;
		y = f - 1;
		z = r - 1;
		t[x][y][z] += v;
	}


	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 10; k++)
			{
				cout <<" "<< t[i][j][k];
			}
			cout << endl;
		}
		if (i  != 3)cout << "####################" << endl;
	}
	cin >> n;

	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const ll MAX = 5*1e5+1;
const ll MOD = 1e9 + 7;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

#define mulmod(a,b,c,d) ((((a*b)%MOD)*((c*d)%MOD))%MOD)
int main(){
    COMinit();
    ll n,m;
    cin >> n >> m;
    ll cnt = 0;
    rep0(k,n){
        if(k % 2 == 1) cnt += -mulmod(COM(n,k), PER(m,k), PER(m-k,n-k), PER(m-k,n-k));
        else cnt += mulmod(COM(n,k), PER(m,k), PER(m-k,n-k), PER(m-k,n-k));
        cnt = (cnt + MOD) %MOD;
    }
    cout << cnt <<endl;
    return 0;
}

Measured memory_bytes: 14916
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 307;

int n, m, k;
char a[N][N];
int ans[N][N], rectCnt;
vector < int > pos[N];

void markRectangle(int r1, int r2, int c1, int c2, int num) {
  for(int i=r1;i<=r2;i++) {
    for(int j=c1;j<=c2;j++) {
      ans[i][j] = num;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin>>n>>m>>k;
  for(int i=1;i<=n;i++) {
    cin>>(a[i] + 1);

    for(int j=1;j<=m;j++) {
      if(a[i][j]=='#') {
        pos[i].push_back(j);
      }
    }
  }

  int r1 = 1, r2 = 1;
  
  while(r1<=n) {
    while(pos[r2].empty()) {
      ++r2;
    }

    int row = r2;

    while(r2<n && pos[r2 + 1].empty()) {
      ++r2;
    }

    int i;

    for(i=0;i+1<(int)(pos[row].size());i++) {
      markRectangle(r1, r2, i==0 ? 1 : pos[row][i - 1] + 1, pos[row][i], ++rectCnt);
    }

    for(;i<(int)(pos[row].size());i++) {
      markRectangle(r1, r2, i==0 ? 1 : pos[row][i - 1] + 1, m, ++rectCnt);
    }

    r1 = r2 + 1;
    r2 = r1;
  }

  for(int i=1;i<=n;i++) {
    for(int j=1;j<=m;j++) {
      if(j>1) {
        cout<<' ';
      }
      
      cout<<ans[i][j];
    }

    cout<<endl;
  }

  return 0;
}


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



int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	int n;
   	cin>>n;
   	std::vector<long long> v(n+1);

   	v[0] = 2;
   	v[1] = 1;

   	for(int i = 2; i <= n; i++) {
   		v[i] = v[i-1] + v[i-2];
   	}

   	cout<<v[n];

   	
	return 0;		
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
using llint = long long int;
int n;
vector<int> va;
using vecitr = vector<int>::iterator;

int nearest(vecitr begin, vecitr end, int x)
{
  bool first = true;
  for (; begin != end; begin++)
  {
    if (*begin >= x)
    {
      int res = *begin;
      if (!first)
      {
        int diff = res - x;
        if (diff > x - *(begin - 1))
        {
          res = *(begin - 1);
        }
      }
      return res;
    }
    first = false;
  }
  return *(end - 1);
}

int main()
{
  cin >> n;
  va.reserve(n);
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    va.push_back(a);
  }
  sort(va.begin(), va.end());

  llint max = 0;
  pair<int, int> ans;
  int b = nearest(va.begin(), va.end() - 1, va.back() / 2);
  cout << va.back() << " " << b << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan

    long long int n,d; cin >> n >> d;
    vector< pair< long long int , long long int > > st;
    for(int i=0;i<n;i++)
    {
        long long int a,b; cin >> a >> b;
        st.push_back(make_pair(a,b));
    }
    int counter = 0;
    //cout << st.size() << endl;
    for(pair< long long int , long long int > x : st)
    {
        long long int dist = (x.first*x.first)+(x.second*x.second);
        //cout << dist << endl;
        if(dist<=d*d)
            counter++;
    }
    cout << counter << endl;
    return 0;
}


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

int Q, Ai, Bi, Ci, Di;
char f(int a, int b, int i){
	int d = max((a + b) / (b + 1), (a + b) / (a + 1));
	int x = d, y = 1;
	
	if(1LL * d * a < b){
		int nb = b - 1LL * d * a;
		if(i <= nb)return 'B';
		
		i -= nb;
		b -= nb;
		y = nb;
	}
	
	while(true){
		if(a == 0)return 'B';
		if(b == 0)return 'A';
		
		int n = min(a / x, b / y);
		if(1LL * d * x - y > 0)n = min(1LL * n, (1LL * d * a - b) / (1LL * d * x - y));
		if(1LL * d * y - x > 0)n = min(1LL * n, (1LL * d * b + d - a) / (1LL * d * y - x));
		
		if(n > 0){
			if(i <= (x + y) * n){
				if((i - 1) % (x + y) < x)return 'A';
				else return 'B';
			}
			
			i -= (x + y) * n;
			a -= x * n;
			b -= y * n;
		}else{
			int na = min(1LL * d, (1LL * d * a + d - b) / d);
			if(i <= na)return 'A';
			
			i -= na;
			a -= na;
			x = na;
			
			int nb = max(1LL, b - 1LL * d * a);
			if(i <= nb)return 'B';
			
			i -= nb;
			b -= nb;
			y = nb;
		}
	}
}

int main(){
	scanf("%d", &Q);
	while(Q--){
		scanf("%d %d %d %d", &Ai, &Bi, &Ci, &Di);
		
		for(int i = Ci; i <= Di; i++)
			printf("%c", f(Ai, Bi, i));
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 384
#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 = 998244353;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	if(n==3||n==5||n==7){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
const ll mod = 1e9 + 7;
 
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll M = 400 + 10;
const ll N = 40 * 100 + 10;
 
ll a[N];
 
int main()
{
	faster();
	int n = 3;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < 3; i++)
	{
		if(a[i] % 2)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	for (int t = 0; t < 10000000; t++)
	{
		ll b[3];
		fill(b, b + 3, 0);
		for (int i = 0; i < 3; i++)
		{
			b[i] = a[i];	
		}
		for (int i = 0; i < 3; i++)
		{
			a[i] = 0;
			for (int j = 0; j < 3; j++)
			{
				if(i == j)
					continue;
				a[i] += b[j] / 2;
			}
			if(a[i] % 2 == 1)
			{
				cout << t + 1 << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
}

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

int main(void) {
    string S;
    cin >> S;

    int ans = 0;
    char x[200], y[200];
    for (int i = 0; i < S.size(); i++) {
        for (int j = 0; j <= i/2; j++) {
            x[j] = S.at(j);
        }
        for (int j = i/2 + 1; j <= i; j++) {
            y[j-((i/2)+1)] = S.at(j);
        }
        int count = 0;
        for (int j = 0; j <= i/2; j++) {
            if (x[j] == y[j]) {
                count++;
            }
        }
        if (count*2 != S.size() && count == (i/2)+1) {
            ans = max (ans, count*2);
        }
    }

    cout << ans << endl;
}

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

using namespace std;



int main() {

	long long n, k, counter = 0, toBeRemoved = 0;
	vector<long long> myVec;
	cin >> n >> k;
	
	
	for (int i = 0; i < n; i++) {
		long long value;
		cin >> value;
		counter += value;
		myVec.push_back(value);
	}
	if (k >= n) {
		cout << 0;
	}
	else {
		sort(myVec.begin(), myVec.end());

		reverse(myVec.begin(), myVec.end());

		for (int i = 0; i < k; i++) {
			toBeRemoved += myVec[i];
		}

		cout << counter - toBeRemoved;

	}
}

Measured memory_bytes: 2420
#include <iostream>
#include<vector>
#include<map>
using namespace std;
vector < vector < int > > V ;
map< pair<int , int > , bool > mp ; 
void f(int & sz , int & root , int & end , int & u){
    // cout<<sz <<" "<< root << " " << end << " "<<u <<endl;
    int y = u - sz ;
        sz++;
        V[root].push_back(end+1);
        V[end+1].push_back(root) ;
        root = end+1 ; 
        end++;    
    for(int i=0 ; i < y-1 ; i++){
        sz++;
        V[root].push_back(end+1);
        V[end+1].push_back(root) ;
        end++;
        
    }
    // root = end;
    
}
int main() {
    string s ;
    cin>>s;
    int  n = s.size() ; 
    
    
    if(s[0]!='1'|| s[n-1] != '0'){
        cout<<-1 ;
        return  0 ; 
        
    }
    V.resize(n+1) ; 
    for(int i=0 ; i < s.size()-1 ; i++){
        if(s[i]=='1' ){
            
            if(s[n-i-2]!='1'){
                cout<<-1;
                return  0 ;
            }
        }
    }
    int sz = 1 ;
    int root = 1 ; 
    int end = 1 ;
    // V[1].push_back(2);
    // V[2].push_back(1);
    
    for(int  i= n /2 ; i<n ; i++){
        if(s[i-1]=='1' ){
                f(sz , root , end , i) ;
                s[n-i-1] = '0'; 
        }
    }

    for(int  i=end+1 ;i <=n ; i++){
        V[i].push_back(root) ;
        V[root].push_back(i) ;
        
    }
    for(int i=1 ; i<= n ; i++){
        
        for(int  j=0 ; j < V[i].size() ; j++){
        if(!mp[{i , V[i][j]}])
            cout<<i<<" "<< V[i][j]<<"\n"; 
            mp[{i , V[i][j]}]=1;
            mp[{V[i][j] , i}]=1;
        
            
        }
    }
    
    return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b,c;
    cin >> a >> b>>c;
    cout << ((b/a <= c)?b/a:c) << endl;
    return 0;
}


Measured memory_bytes: 256
(defn split-space [s]
  (map #(Long/parseLong %) (.split s " ")))

(defn read-n [n]
  (for [i (range n)] (split-space (read-line))))

(defn square [x]
  (* x x))

(defn distance [d [xi yi] xs]
  (if (zero? (count xs))
    d
    (recur (reduce (fn [acc [xj yj]]
                     (+ acc (Math/sqrt (+ (square (- xi xj))
                                          (square (- yi yj)))))) d xs)
           (first xs)
           (rest xs))))

(defn average-length []
  (->>
   (Long/parseLong (read-line))
   ((fn [n]
      (->>
       (read-n n)
       ((fn [xs] (distance 0 (first xs) (rest xs))))
       ((fn [s] (/ (* 2 s) (* n)))))))))

(println (average-length))

Measured memory_bytes: 69344
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 600031;

int pr[N];
vector<int> primes;
int n;

int found;
vector<int> cur;
int ans[N];

bool invalid(){
	for (int i=0;i<cur.size();i++){
		for (int j=i+1;j<cur.size();j++){
			for (int q=j+1;q<cur.size();q++){
				for (int w=q+1;w<cur.size();w++){
					for (int e=w+1;e<cur.size();e++){
						int here=cur[i]+cur[j]+cur[q]+cur[w]+cur[e];
						if (pr[here]==0)
							return true;
					}
				}
			}
		}
	}
	return false;
}

void backtrack(int ptr){
	if (found)
		return;
	if (invalid())
		return;
	if (cur.size()==n){
		found=1;
		for (int i=0;i<cur.size();i++){
			ans[i]=cur[i];
		}
		return ;
	}
	for (int i=ptr;i<=55555;i++){
		if (pr[i]==0){
			if (i%10!=1)
				continue;
			cur.push_back(i);
			backtrack(i+1);
			cur.pop_back();
		}
	}
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	pr[1]=1;
	for (int i=2;i<=500000;i++){
		if (pr[i]==0)
			for (int j=i*2;j<=500000;j+=i)
				pr[j]=1;
	}

	for (int i=2;i<=500000;i++){
		if (pr[i]==0)
			primes.push_back(i);
	}

	cin>>n;

	backtrack(10000);

	for (int i=0;i<n;i++){
		if (i)
			cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;


//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 2944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int x = 0;
            int y = 0;
            boolean flag = true;
            for (int i = 0; i < n; i++) {
                String str[] = br.readLine().split(" ");
                int t = Integer.parseInt(str[0]);
                int xi = Integer.parseInt(str[1]);
                int yi = Integer.parseInt(str[2]);
                int temp = Math.abs(x - xi) + Math.abs(y - yi);
                if (temp > t) {
                    flag = false;
                    break;
                }
                if (temp % 2 == 0 && t % 2 == 0) {
                    continue;
                } else if (temp % 2 != 0 && t % 2 != 0) {
                    continue;
                } else {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 43380
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int n = Integer.parseInt(br.readLine());
            if (n == 0) { break; }
             
            Map<String, Long> data = new HashMap<>(n);
            List<String> out = new ArrayList<>();
            for (int i=1; i <= n; i++) {
                String[] st = br.readLine().split(" ");
                String e = st[0];
                Long p = Long.parseLong(st[1]);
                Long q = Long.parseLong(st[2]);
                Long total = data.getOrDefault(e, 0L) + p * q;
                data.put(e, total);
                if (total >= 1_000_000L) {
                    if (out.contains(e) == false) {
                        System.out.println(e);
                        out.add(e);
                    }
                }
            }
            if (out.isEmpty()) {
                System.out.println("NA");
            }
        }
    }
}

Measured memory_bytes: 27288
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
long long MOD = 1000000007;
long long MODPOW(long long inv,long long pow, long long mod){
    if(pow == 1) return inv % mod;
    else{
        if(pow % 2) return inv * MODPOW(inv, pow -1, mod) % mod;
        long long res = MODPOW(inv, pow/2, mod);
        return res * res % mod; 
    }
}

long long COMMOD(int a, int b){
    long long res=1; long long resinv = 1;
    for(int i = a; i>a-b; i--){
        res = res * i % MOD;
        resinv = resinv*(a-i+1) % MOD;
    }
    return res*MODPOW(resinv, MOD-2, MOD) % MOD;
}

int main() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long ans = 0;
    ans = COMMOD(r2 + c2 + 2, c2 + 1) - COMMOD(r1 + c2 + 1, c2 + 1) - (COMMOD(r2 + c1 + 1, c1) - COMMOD(r1 + c1, c1));
    if(ans < 0) ans += MOD * 2;
    ans %= MOD;
    cout << ans << endl;
}

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

  string S;

  cin >> A >> B ;

  cin >> S ;

  bool ans=true;
  for(int i=0;i<A+B+1;i++){
    if(i==A) continue;
    else if(S.at(i)=='-') ans=false;
  }

  if(S.at(A)!='-') ans=false;

  if(ans) cout << "Yes" << endl;

  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
K=int(input())
for i in range(K-1):
  x=q.popleft()
  y=x%10
  if y>0:
    q.append(10*x+y-1)
  q.append(10*x+y)
  if y<9:
    q.append(10*x+y+1)
print(q.popleft())

Measured memory_bytes: 18868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

// 素集合データ構造
struct UnionFind
{
    // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
    vector<ll> par;
    // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
    vector<ll> sizes;

    UnionFind(ll n) : par(n), sizes(n, 1)
    {
        // 最初は全てのデータiがグループiに存在するものとして初期化
        rep(i, n) par[i] = i;
    }

    // データxが属する木の根を得る
    ll find(ll x)
    {
        if (x == par[x])
            return x;
        return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す
    }

    // 2つのデータx, yが属する木をマージする
    void unite(ll x, ll y)
    {
        // データの根ノードを得る
        x = find(x);
        y = find(y);

        // 既に同じ木に属しているならマージしない
        if (x == y)
            return;

        // xの木がyの木より大きくなるようにする
        if (sizes[x] < sizes[y])
            swap(x, y);

        // xがyの親になるように連結する
        par[y] = x;
        sizes[x] += sizes[y];
        // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
    }

    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(ll x, ll y)
    {
        return find(x) == find(y);
    }

    // データxが含まれる木の大きさを返す
    ll size(ll x)
    {
        return sizes[find(x)];
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    vi A(M), B(M);
    rep(i, M)
    {
        cin >> A[i] >> B[i];
    }
    UnionFind tree(N);
    vll ans(M);
    ans[M-1] = N*(N-1)/2;
    for(int i = M-1; i >= 1; i--)
    {
        if (tree.same(A[i]-1, B[i]-1))
        {
            ans[i - 1] = ans[i];
        }
        else
        {
            ans[i - 1] = ans[i] - tree.size(A[i]-1) * tree.size(B[i]-1);
            tree.unite(A[i]-1, B[i]-1);
        }
    }
    rep(i, M)
        cout << ans[i] << endl;
}

Measured memory_bytes: 4480
class PQue

  def create_que(num=0)
    num.times do |i|
      eval("@qnum_#{i} = Array.new()")
    end
  end

  def qnum(num=0)
    eval("@qnum_#{num}")
  end

  def insert(num=0, x)
    que = eval("@qnum_#{num}")
    que << x
    que_idx = que.size - 1

    while que_idx != 0
      prt_idx = (que_idx - 1) / 2

      if que[prt_idx] < que[que_idx]
        que[prt_idx], que[que_idx] = que[que_idx], que[prt_idx]
      end

      que_idx = prt_idx
    end
  end

  def getmax(num=0)
    que = eval("@qnum_#{num}")
    puts(que[0]) unless que.empty?
  end

  def deletemax(num=0)
    que = eval("@qnum_#{num}")
    
    unless que.empty?
      lst_idx = que.size - 1

      if lst_idx == 0
        que.clear

      else
        que[0] = que.pop
        prt_idx = 0

        while (chr_idx = prt_idx * 2 + 1) < lst_idx

          unless que[chr_idx+1].nil?
            chr_idx += 1 if que[chr_idx] < que[chr_idx+1]
          end

          if que[chr_idx] > que[prt_idx]
            que[chr_idx], que[prt_idx] = que[prt_idx], que[chr_idx]
          end
          
          prt_idx = chr_idx
        end
      end
    end
  end

end

nq = gets.split.map(&:to_i)
que = PQue.new
que.create_que(nq[0])

nq[1].times do
  o, t, x = gets.split.map(&:to_i)
  case o
  when 0
    que.insert(t, x)
  when 1
    que.getmax(t)
  when 2
    que.deletemax(t)
  end
end


Measured memory_bytes: 9184
// be name khoda
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e9 + 10;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int y = n/1000;
    y++;
    if (n%1000==0) cout<<0;
    else {
        cout<<1000*y-n;
    } 
    return 0;
}

Measured memory_bytes: 3648
'use strict'

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines.shift());
  const tasks = []
  for(let i=0;i<N;i++){
    tasks.push( lines[i].split(' ').map( x => parseInt(x) ) );
  }

  tasks.sort( (a,b) => a[1]-b[1])

  let result = 'Yes';
  let sum = 0
  for(let i=0;i<N;i++){
    sum += tasks[i][0]
    if(sum > tasks[i][1]){
      result = 'No';
      break;
    }
  }

  console.log(result);
}

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


Measured memory_bytes: 68192
n = int(input())
l = [int(input()) for _ in range(n)]
_l = l.copy()
_l.sort(reverse=True)
lmax = _l[0]
lsec = _l[1]

for i in range(n):
    if l[i] == lmax:
        print(lsec)
    else:
        print(lmax)

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    
    ini(n);
    vi morty;
    if(n <=2){out(0);return 0;}
    for(int i = 2;i*i<=n;i++){
        if(n%i == 0){
            morty.push_back(i);
            if(n/i!=i)morty.push_back(n/i);
        }
    }
    int tmp = 0;
    FOR(i,0,morty.size()){
        int x = morty[i]-1;
        if(n/x == n%x)tmp+=x;
    }
    out(tmp+n-1);
}


Measured memory_bytes: 384
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

inline unsigned long long rdtsc(){
    #ifdef __amd64
    unsigned long long a, d;
    __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
    return (d << 32) | a;
    #else
    unsigned long long x;
    __asm__ volatile ("rdtsc" : "=A" (x));
    return x;
    #endif
}
inline double gettime(){return rdtsc()/2793344000.0;}
inline double elapsed(double st){return gettime()-st;}

uint32_t xor128() { //128とは言ってない
  static uint64_t x = 88172645463325252ULL;
  x ^= (x << 13); x ^= (x >> 7);
  return x ^= (x << 17);
}

int n;
using tP = complex<double>;
vector<tP> p;
tP c;
double r;
double x,y;
int counter = 0;

double calc(tP c){
    double ret = 0;
    for(auto pp: p) ret = max(ret, norm(pp-c));
    return ret;
}

signed main(){
    double st = gettime();
    cin >> n;
    REP(i,n){
        cin >> x >> y;
        p.pb( tP(x,y) );
    }
    c = {500,500};
    r = calc(c);
    double tm = elapsed(st);
    while(tm < 1.98){
        double ratio = exp((0.3-tm) * 10);
        REP(_,50){
            tP dx = { (double)xor128()/UINT32_MAX - 0.5, (double)xor128()/UINT32_MAX - 0.5 };
            
            double tempr = calc(c + dx * ratio);
            if (tempr < r){
                r = tempr;
                c += (dx * ratio);
            }
        }
        tm = elapsed(st);
        // cerr << tm << " " << sqrt(r) << " " << ratio << endl;

    }

    printf("%.9f\n", sqrt(r));
}


Measured memory_bytes: 768
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int no_of_dice_faces, minimum_score;
    cin >> no_of_dice_faces >> minimum_score;

    long double winning_probability = 0;
    for(int i = 1; i <= no_of_dice_faces; i++)
    {
        if(i >= minimum_score)
        {
            winning_probability += 1.0/(no_of_dice_faces*1.0);

            continue;
        }

        int no_of_heads_required = 0;
        int face = i;

        while(face < minimum_score)
        {
            face *= 2;
            no_of_heads_required++;
        }

        long long no_of_outcomes = (1LL << no_of_heads_required);

        winning_probability += 1.0/(no_of_dice_faces*1.0*no_of_outcomes);
    }

    cout << setprecision(12) << winning_probability;
    return 0;
}


Measured memory_bytes: 256