akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[][] arr = new int[n][2];

        for (int i=0; i<n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        Arrays.sort(arr, (x, y) -> x[0] - y[0]);

        long ret = 0;

        int sum = 0;
        for (int i=0; i<n; i++) {
            sum += arr[i][1];
            if (m <= sum) {
                ret += (long)(m + arr[i][1] - sum) * arr[i][0];
                break;
            } else {
                ret += (long)arr[i][1] * arr[i][0];
            }
        }

        System.out.println(ret);

    }


}



Measured memory_bytes: 91044
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
s = sum(d)
for i in range(1, n+1):
    if max(a[i-1:i+2]) == a[i] or min(a[i-1:i+2]) == a[i]:
        tmp = abs(d[i]-d[i-1])
        print(s - d[i-1] - d[i] + tmp)
    else:
        print(s)
            

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

int main()
{
  int n;
  cin >> n;
  if(n == 1)
  {
    cout << "Hello World" << endl;
  }
  else
  {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin>>k>>s;
  int x=s.size();
  if(x>k){
    for(int i=0;i<k;i++){
      cout<<s.at(i);}
    cout<<"..."<<endl;
  }
  else {cout<<s<<endl;}
}

Measured memory_bytes: 3636
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e[7:-1])
  else:
   if' '==e[6]:
    m=e[7:-1]
    if m in d:d.remove(m)
   elif'i'==e[7]:d.popleft()
   else:d.pop()
 print(*d)
if'__main__'==__name__:s()


Measured memory_bytes: 69736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 51;
const int MAXV = 1 << 18;
int a[MAXN], b[MAXN];
int cnt[MAXV];
ll dp[MAXV], C[MAXN][MAXN];
int main() {
    for (int i = 0; i <= 50; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
    for (int i = 1; i <= 50; i++)
        for (int j = 1; j <= i; j++) C[i][j] += C[i][j - 1];

    int n, k, S, T; scanf("%d %d %d %d", &n, &k, &S, &T);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int bit = 0; bit < 18; bit++) {
        int s = (S >> bit & 1), t = (T >> bit & 1);
        if (s == 1 && t == 0) {
            puts("0");
            return 0;
        }
        for (int i = 1; i <= n; i++) {
            int x = (a[i] >> bit & 1);
            if (s == t && x != s) {
                swap(a[i], a[n]);
                n--;
                i--;
            }
        }
    }
    int bc = 0;
    for (int bit = 0; bit < 18; bit++) {
        int s = (S >> bit & 1), t = (T >> bit & 1);
        if (s == 0 && t == 1) {
            for (int i = 1; i <= n; i++) b[i] |= (a[i] >> bit & 1) * (1 << bc);
            bc++;
        }
    }
    ll ans = 0;
    vector<int>vec;
    for (int s = 0; s < (1 << bc); s++) {
        vec.clear();
        for (int i = 1; i <= n; i++) {
            if (!cnt[s & b[i]]) vec.push_back(s & b[i]);
            cnt[s & b[i]]++;
        }
        for (int x : vec) {
            dp[s] += C[cnt[x]][min(cnt[x], k)] - 1;
            cnt[x] = 0;
        }
        __builtin_popcount(s) & 1 ? ans -= dp[s] : ans += dp[s];
    }
    printf("%lld\n", ans);
    return 0;
}

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

Measured memory_bytes: 56796
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{
	auto line = readln().split(); 
	if (line.length < args.length) return;
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
const coin = [10,50,100,500];
void main(){	
	int total;
	for(read(total); total ; read(total), write(total ? "\n":"")){
		auto have = new int[4];
		readArray(have);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach (I;cartesianProduct(iota(have[0]+1),iota(have[1]+1),iota(have[2]+1),iota(have[3]+1))){
			auto tmpuses = [I[0],I[1],I[2],I[3]];
			auto pay = coin.dotProduct(tmpuses);	
			if (pay < total) continue;
			int tmpHowMany = have.sum + howManyCoins(pay - total) - tmpuses.sum;
			if (tmpHowMany < howMany ){
				howMany = tmpHowMany;
				uses = tmpuses;
			}
		}
		foreach(i,u;uses){if(u >0)writeln(coin[i]," ",u);}
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}

Measured memory_bytes: 3228
import sys
input = sys.stdin.readline

mod = int(1e9+7)

N,M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
if len(set(A)) < N or len(set(B)) < M:
  print(0)
  exit(0)

A.append(0)
B.append(0)
ai,bi = 0,0
ans = 1
for i in range(N*M,0,-1):
  if i == A[ai] and i == B[bi]:
    ai += 1
    bi += 1
  elif i == A[ai]:
    ans *= bi
    ai += 1
  elif i == B[bi]:
    ans *= ai
    bi += 1
  else:
    if min(ai,N) * min(bi,M) - (N*M - i) > 0:
      ans *= (min(ai,N) * min(bi,M) - (N*M - i))
    else:
      #print(0,i,ai,bi)
      print(0)
      exit(0)
  ans %= mod
  
print(ans)

Measured memory_bytes: 69148
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int counter[n][26] = {};
	for (int i = 0; i < n; i++) {
		string S; cin >> S;
		for (int j = 0; j < S.size(); j++) {
			counter[i][S[j] - 'a']++;
		}
	}
	int MINI[26] = {};
	for (int i = 0; i < 26; i++) {
		int mini = 100;
		for (int j = 0; j < n; j++) {
			if (counter[j][i] < mini) mini = counter[j][i];
		}
		MINI[i] = mini;
	}
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < MINI[i]; j++) {
			printf("%c", i + 'a');
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>




int main()
{
	long long int A=0,B=0,C=0,K=0;
	
	scanf("%lld %lld %lld %lld",&A,&B,&C,&K);
	
	
	
	
	
	
	if(A<=K&&K<=A+B){
		printf("%lld",A);
	}
	else if(K<A){
		printf("%lld",K);
	}
	else{
		printf("%lld",A-(K-A-B));
	}
	
	return 0;
}


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

int main()
{
    int a, b;
    char op;
    
    while(1)
    {
        cin >> a >> op >> b;
        switch(op)
        {
            case '+':
            cout << a + b << endl;
            break;
            
            case '-':
            cout << a - b << endl;
            break;
            
            case '*':
            cout << a * b << endl;
            break;
            
            case '/':
            cout << a / b << endl;
            break;
        }
        if(op == '?') break;        
    }
    return 0;
}


Measured memory_bytes: 3108
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        final String[] sl = s.split(" ");
        long X = Long.parseLong(sl[0]);
        long Y = Long.parseLong(sl[1]);

        int len = 0;

        do {
            X = X << 1;
            len++;
        } while (X <= Y);

        out.println(len);

        out.flush();
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}

};
vector<ll> TopologicalSort(ConnectNodeInfo& connect){
	int N=connect.size();
	stack<ll> vertex;
	vector<ll> input(N),sorted;
	REP(i,N){
		for(auto& x:connect[i]) input[x.first]++;
	}
	REP(i,N){
		if(input[i]==0) vertex.push(i);
	}
	while(!vertex.empty()){
		auto v=vertex.top();vertex.pop();
		sorted.push_back(v);
		for(auto& x:connect[v]){
			input[x.first]--;
			if(!input[x.first]) vertex.push(x.first);
		}
	}
	if(sorted.size()!=N) sorted.clear();
	return sorted;
}

vll dist;
ll dfs(int child,int D,ConnectNodeInfo& connect){
	if(dist[child]>=0) return dist[child];
	ll ans = D;

	for(auto& x:connect[child]){
		if(dist[x.first]<ans+1){
			ll V = dfs(x.first,D+1,connect);
			ans = max(ans,V);
		}
	}

	dist[child] = ans;
	return ans;
}

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

	int N=in();
	vvll L(N,vll(N,-1));
	int index=0;
	REP(i,N){
		FOR(j,i+1,N){
			L[i][j] = index++;
			L[j][i] = L[i][j];
		}
	}
	ConnectNodeInfo connect(index);
	REP(i,N){
		ll s=in()-1;
		REP(j,N-2){
			ll t=in()-1;
			connect.AddDirectionalConnection(L[i][s],L[i][t],1);
			s = t;
		}
	}
	auto DAG = TopologicalSort(connect);
	if(DAG.empty()){
		out(-1);
		return 0;
	}

	dist.resize(index,-1);
	ll maxD=0;
	REP(i,index){
		if(dist[DAG[i]]<0) dist[DAG[i]] = 0; 
		for(auto& x:connect[DAG[i]]){
			dist[x.first] = max(dist[x.first],dist[DAG[i]]+x.second);
			maxD = max(maxD,dist[x.first]);
		}
	}
	out(maxD+1);
	return 0;
}


Measured memory_bytes: 54512
n = int(input())
dp = [1]*(n + 1)
ans = 0
# エラストテネスの箒
for i in range(2, n + 1):
    div = 1
    while i * div <= n:
        dp[i * div] += 1
        div += 1
# dp[1]から１個飛ばしで表示
print(dp[1::2].count(8))

Measured memory_bytes: 38256
#include<cstdio>
#include<algorithm>
using namespace std;
int N,K;
long long ans=0;
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&K);
	if(K==0)ans=1ll*N*N;
	else {
		for(int b=K+1;b<=N;b++) {
			int x1=b-K;
			int x2=N/b;
			int k=N-x2*b;
			if(k>=K)ans+=k-K+1;
			ans+=x1*x2;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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


int main(){
  int n,q,j,cnt;
  cin >> n;
  vector<int> s(n+1);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  }
  cin >> q;
  vector<int> t(q);
  for(int i=0;i<q;i++){
    cin >> t.at(i);
  }
  
  for(int i=0;i<q;i++){
    s[n] = t[i];
    j=0;
    while(s[j]!=t[i])
      j++;
    if(j!=n)
      cnt++;
  }
   
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  int n,m;
  cin>>n>>m;
  bool even[n];
  REP(i,n){
    even[i] = true;
  }
  int a,b;
  REP(i,m){
    cin>>a>>b;
    a--;b--;
    even[a] = !even[a];
    even[b] = !even[b];
  }
  
  bool flag = true;
  REP(i,n){
    flag = flag && even[i];
  }
  if(flag){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<int> p(n+5,0);
    rep(i,105){
        rep(j,105){
            rep(k,105){
                int a=(i+1)*(i+1)+(j+1)*(j+1)+(k+1)*(k+1)+(i+1)*(j+1)+(j+1)*(k+1)+(k+1)*(i+1);
                if(a<=n+4){
                    p[a]++;
                }
            }
        }
    }
    rep(i,n){
        cout<<p[i+1]<<endl;
    }
}

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string s;
    cin >> s;
    ll ans=0;
    for (int bit = 0; bit < (1<<(s.size()-1));bit++){
        bool z[s.size()];
        fill(z,z+s.size(),false);
        for (ll i=0;i<s.size();i++){
            if (bit & (1<<i)) {
                z[i]=true;
            }
        }
        ll count=s[0]-'0';
        for (ll i=1;i<s.size();i++){
            if (z[i-1]){
                count=count*10+(s[i]-'0');
            }else{
                ans+=count;
                count=s[i]-'0';
            }
        }
        ans+=count;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define N 7

using namespace std;

int cost[N][N];
int dis[N][N];

void InitCost(){
  for(int i=0; i<N; i++) cost[i][i] = 0;

  cost[0][1] = 300;
  cost[0][2] = 500;
  cost[0][3] = 600;
  cost[0][4] = 700;
  cost[0][5] = 1350;
  cost[0][6] = 1650;

  cost[1][2] = 350;
  cost[1][3] = 450;
  cost[1][4] = 600;
  cost[1][5] = 1150;
  cost[1][6] = 1500;

  cost[2][3] = 250;
  cost[2][4] = 400;
  cost[2][5] = 1000;
  cost[2][6] = 1350;

  cost[3][4] = 250;
  cost[3][5] = 850;
  cost[3][6] = 1300;

  cost[4][5] = 600;
  cost[4][6] = 1150;

  cost[5][6] = 500;

  cost[1][0] = 300;
  cost[2][0] = 500;
  cost[3][0] = 600;
  cost[4][0] = 700;
  cost[5][0] = 1350;
  cost[6][0] = 1650;

  cost[2][1] = 350;
  cost[3][1] = 450;
  cost[4][1] = 600;
  cost[5][1] = 1150;
  cost[6][1] = 1500;

  cost[3][2] = 250;
  cost[4][2] = 400;
  cost[5][2] = 1000;
  cost[6][2] = 1350;

  cost[4][3] = 250;
  cost[5][3] = 850;
  cost[6][3] = 1300;

  cost[5][4] = 600;
  cost[6][4] = 1150;

  cost[6][5] = 500;
}

void InitDistance(){
  for(int i=0; i<N; i++) dis[i][i] = 0;

  dis[0][1] = 6;
  dis[0][2] = 13;
  dis[0][3] = 18;
  dis[0][4] = 23;
  dis[0][5] = 43;
  dis[0][6] = 58;

  dis[1][2] = 7;
  dis[1][3] = 12;
  dis[1][4] = 17;
  dis[1][5] = 37;
  dis[1][6] = 52;

  dis[2][3] = 5;
  dis[2][4] = 10;
  dis[2][5] = 30;
  dis[2][6] = 45;

  dis[3][4] = 5;
  dis[3][5] = 25;
  dis[3][6] = 40;

  dis[4][5] = 20;
  dis[4][6] = 35;

  dis[5][6] = 15;

  dis[1][0] = 6;
  dis[2][0] = 13;
  dis[3][0] = 18;
  dis[4][0] = 23;
  dis[5][0] = 43;
  dis[6][0] = 58;

  dis[2][1] = 7;
  dis[3][1] = 12;
  dis[4][1] = 17;
  dis[5][1] = 37;
  dis[6][1] = 52;

  dis[3][2] = 5;
  dis[4][2] = 10;
  dis[5][2] = 30;
  dis[6][2] = 45;

  dis[4][3] = 5;
  dis[5][3] = 25;
  dis[6][3] = 40;

  dis[5][4] = 20;
  dis[6][4] = 35;

  dis[6][5] = 15;
}

int WhatTime(int h, int m){
  if(h < 17 || (h == 17 && m < 30)) return -1;
  if(h > 19 || (h == 19 && m > 30)) return 1;
  return 0;
}

int HighwayToll(int n, int h1, int m1, int m, int h2, int m2){
  int ans;
  ans = cost[n][m];

  if(dis[n][m] <= 40){
    if((WhatTime(h1, m1) == 0 && WhatTime(h2, m2) == 0) ||
       (WhatTime(h1, m1) == -1 && WhatTime(h2, m2) == 0) ||
       (WhatTime(h1, m1) == 0 && WhatTime(h2, m2) == 1)){
      ans /= 2;
      if(ans%50 != 0) ans = ans - ans%50 + 50;
    }
  }
  return ans;
}

int main(){
  int n, m;
  int h1, m1, h2, m2;

  InitCost();
  InitDistance();

  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> h1 >> m1;
    cin >> m;
    cin >> h2 >> m2;
    --n;
    --m;
    cout << HighwayToll(n, h1, m1, m, h2, m2) << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout,"");
//copy(v.beg,v.en,outp);
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
ll min(ll a, ll b){
    if(a>b){
        return b;
    }
    return a;
}
 
ll max(ll a, ll b){
    if(a>b){
        return a;
    }
    return b;
}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//const int mod=1e9 +7;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	forl(i,0,n) cin>>arr[i];
	int dp[n];
	dp[0]=0;
	forl(i,1,n)
	{
		dp[i]=min(dp[max(i-1,0)]+abs(arr[i]-arr[max(i-1,0)]),dp[max(i-2,0)]+abs(arr[i]-arr[(max(i-2,0))]));
	}
	cout<<dp[n-1]<<endl;
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;

int H, W,K;
char S[11][1001];

int cnt[10];
int ans=INF;

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


	cin >> H >> W>>K;



	FOR(i, 0, H)FOR(j, 0, W)cin >> S[i][j];

	FOR(i, 0, 1 << H) {//横方向の割り方を決定
		int tate = 0,yoko=0;
		bool canflag = true;
		FOR(j, 0, 10)cnt[j] = 0;

		
		FOR(j, 0, W) {//縦方向は貪欲に左から
			bool flag = false;//縦方向に部屋を割るかどうかのフラグ
			int cur = i;//横方向の部屋割り情報

			int R = 0;
			
			int tatecnt = 0;
			int tatemax = 0;
			FOR(k, 0, H) {
				if (S[k][j] == '1') { cnt[R]++; tatecnt++; tatemax = max(tatecnt, tatemax); }
				if (cnt[R] == K+1)flag = true;

				if (cur % 2 == 1) { R++; if (j == 0)yoko++; tatecnt = 0; }
				cur /= 2;
			}
			if (tatemax > K) { canflag = false; break; }

			if (flag) {
				tate++;
				j--;
				FOR(j, 0, 10)cnt[j] = 0;
			}

		}
		if(canflag)ans = min(ans, tate + yoko);

	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX_V 500
struct edge { int to,cap,rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap>0&&level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t) return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    bfs(s);
    if(level[t]<0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int main(){
  int v,e,a,b,c,i;
  cin>>v>>e;
  for(i=0;i<e;i++){
    cin>>a>>b>>c;
    add_edge(a,b,c);
  }
  cout << max_flow(0,v-1) << endl;
  return 0;
}


Measured memory_bytes: 3196
b = list(input())
ans = list()
for i in range(len(b)):
    if b[i] == "A":
        ans.append("T")
    elif b[i] == "T":
        ans.append("A")
    elif b[i] == "C":
        ans.append("G")
    else:
        ans.append("C")
print("".join(ans))

Measured memory_bytes: 3060
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

idx = int(input())

print(a[idx - 1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 30
#define MOD 998244353
char s[MAX];
int main()
{
    int A,B,M;
    scanf("%d %d %d",&A,&B,&M);
    int i;
    int refrigerators[A],microwaves[B];
    int coupons[M][3];
    int ans=1000000;
    int a=1000000,b=1000000;
    for(i=0;i<A;i++)
    {
        scanf("%d",&refrigerators[i]);
        a=min(a,refrigerators[i]);
    }
    for(i=0;i<B;i++)
    {
        scanf("%d",&microwaves[i]);
        b=min(b,microwaves[i]);
    }
    ans=a+b;
    for(i=0;i<M;i++)
    {
        scanf("%d %d %d",&coupons[i][0],&coupons[i][1],&coupons[i][2]);
        coupons[i][0]--;
        coupons[i][1]--;
        int current=refrigerators[coupons[i][0]]+microwaves[coupons[i][1]]-coupons[i][2];
        ans=min(ans,current);
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;

typedef long long int64;

const int maxn = 1e5 + 9;
int64 result[maxn];

struct dsu {
	vector<int> parent, size;
	dsu(int n) : parent(n + 1), size(n + 1, 1) {
		for (int i = 0; i < n + 1; i++) {
			parent[i] = i;
		}
	}
	int find(int u) {
		if (u == parent[u]) return u;
		return parent[u] = find(parent[u]);
	}
	int64 merge(int u, int v) {
		u = find(u); v = find(v);
		if (u == v) return -1LL;
		long long ret = size[u] * (size[u] - 1LL) * 1LL / 2LL + size[v] * (size[v] - 1LL) * 1LL / 2LL;
		parent[u] = v;
		size[v] += size[u];
		size[u] = 0;
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> edges;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		edges.push_back(make_pair(a, b));
	}
	int64 inf = n * (n - 1LL) * 1LL / 2LL, tmp = inf;
	dsu uf(n);
	for (int i = 0; i < m; i++) {
		result[m - i - 1] = tmp;
		pair<int, int> edge = edges[m - i - 1];
		int64 d = uf.merge(edge.first, edge.second);
		if (d == -1LL) continue;
		tmp += d;
		int size = uf.size[uf.find(edge.first)];
		tmp -= size * (size - 1LL) * 1LL / 2LL;
	}
	for (int i = 0; i < m; i++) {
		cout << result[i] << '\n';
	}
	
	return 0;
}



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



string st(int i){
    return to_string(i);
}


int main() {
    int H, W; cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    vector<string> ans;
    
    for(vector<int> &v:A)
        for(int &a:v) cin >> a;
    
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(i==H-1 && j==W-1) break;
            if(A[i][j]%2 && i<H-1){
                ans.push_back(st(i+1) + " "  + st(j+1) + " " + st(i+2) + " " + st(j+1));
                A[i+1][j]++;
            }
            if(A[i][j]%2 && i==H-1){
                ans.push_back(st(i+1) + " "  + st(j+1) + " " + st(i+1) + " " + st(j+2));
                A[i][j+1]++;
            }
        }
    }
    
    cout << ans.size() << endl;
    for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 11892
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
       	ll ans = min(k, a);
	k-=ans;
	if(k>0){
		ll w = min(b, k);
		k-=w;
	}
	if(k>0){
		ll w = min(c, k);
		k-=w;
		ans-=w;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>

bool BinarySearch(const std::vector<int> &s, const int key){
    int left = 0;
    int right = static_cast<int>(s.size());
    while(left < right){
        int mid = (left + right) / 2;
        if(s.at(mid) == key){
            return true;
        }else if(key < s.at(mid)){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    return false;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n, q;
    std::cin >> n;
    std::vector<int> s(n);
    for(int i=0; i<n; ++i)
        std::cin >> s.at(i);
    std::cin >> q;
    int count = 0;
    for(int i=0; i<q; ++i){
        int key;
        std::cin >> key;
        if(BinarySearch(s, key))
            count += 1;
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=200005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

int n,cnt=0,num=0,B=0;
vi x,y,ax,ay,vis,b,c,d,used;
vl dp;
vvi g,G;
vvp X,Y;

int dfs(int v,int w){
	b.push_back(v);
	vis[v]++;cnt++;
	if(!ax[x[v]]) num++,ax[x[v]]=1;
	if(!ay[y[v]]) num++,ay[y[v]]=1;
	int t=-1;
	for(auto u:g[v]) if(u!=-1&&u!=w){
		if(vis[u]&&!B){
			int I=d.size()-1;
			pip p={{x[u],y[u]},u};
			while(I>=0&&d[I]!=u){
				int u_=d[I--];
				p=min(p,{{x[u_],y[u_]},u_});
			}
			t=p.second;
			B=1;
		}
		else if(!vis[u]){
			d.push_back(u);
			int t_=dfs(u,v);
			if(t_!=-1) t=t_;
			d.pop_back();
		}
	}
	return t;
}

void DFS(int v,int I){
	int u=g[v][I];
	if(u==-1||c[u]!=-1) return;
	c[u]=1-I%2;
	for(int i=0;i<4;i++){
		int w=g[u][i];
		if(w!=-1&&c[w]==-1) DFS(u,i);
	}
}

pll Rec(int v){
	ll res=1,S=0;
	for(auto u:G[v]){
		pll p=Rec(u);
		ll T=p.second;
		res=Div(res*p.first%mod,F[T]);
		S+=T;
	}
	(res*=F[S])%=mod;
	return {res,S+1};
}

ll f(int v,int t){
	c[v]=t;
	for(int i=0;i<4;i++) DFS(v,i%2*2+abs(i/2-t));
	for(auto i:b){
		int u=g[i][c[i]];
		while(u!=-1){
			G[i].push_back(u);
			used[u]=1;
			u=g[u][c[i]];
		}
	}
	for(auto i:b) if(!used[i]) G[n].push_back(i);
	ll res=Rec(n).first;
	for(auto i:b){
		c[i]=-1;
		used[i]=0;
		G[i].clear();
	}
	G[n].clear();
	return res;
}

int main(){
	Init();
	cin>>n;
	n*=2;
	x=y=ax=ay=vis=used=vi(n);
	c=vi(n,-1);
	X=Y=vvp(n);
	g=vvi(n,vi(4,-1));
	G=vvi(n+1);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		x[i]--;y[i]--;
		X[x[i]].push_back({y[i],i});
		Y[y[i]].push_back({x[i],i});
	}
	for(int i=0;i<n;i++){
		sort(X[i].begin(),X[i].end());
		sort(Y[i].begin(),Y[i].end());
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<X[i].size();j++){
			int u=X[i][j-1].second,v=X[i][j].second;
			g[u][3]=v;g[v][1]=u;
		}
		for(int j=1;j<Y[i].size();j++){
			int u=Y[i][j-1].second,v=Y[i][j].second;
			g[u][2]=v;g[v][0]=u;
		}
	}
	ll res=F[n];
	for(int i=0;i<n;i++) if(!vis[i]){
		cnt=0;num=0;B=0;
		b.clear();d.clear();
		d.push_back(i);
		int v=dfs(i,-1);
		d.pop_back();
		res=(cnt==num?Div((f(v,0)+f(v,1))%mod*res%mod,F[cnt]):0);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 50288
/******************
*  Author: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

int n,k;
int h[100005],dp[100005];

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		dp[i]=1e9;
	}
	dp[1]=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=min(n,i+k);j++){
			dp[j]=min(abs(h[j]-h[i])+dp[i],dp[j]);
		}
	}
	cout<<dp[n]<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N;
int A[200005];
vector<int> sa;
vector<int > wa;
signed main(){
    scanf("%lld",&N);
    rep(i,N){
       scanf("%lld",&A[i]);
       sa.pb(i+1-A[i]);
       wa.pb(i+1+A[i]);
    }
    sort(wa.begin(),wa.end());
    int ans=0;
    rep(i,sa.size()){
        int s=sa[i];
        auto waitr=lower_bound(wa.begin(), wa.end(), s);
        auto waitr2=lower_bound(wa.begin(), wa.end(), s+1);
        ans+=waitr2-waitr;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7660
x,y,u;
p(a,b){for(;b--;)putchar(a+68);}
main(v){
    scanf("%d%d%d%d",&u,&v,&x,&y);
    x-=u;
    y-=v;
    p(17,y);
    p(14,x+1);
    p(0,y+1);
    p(8,x+1);
    p(17,1);
    p(8,1);
    p(17,y+1);
    p(14,x+1);
    p(0,y+1);
    p(8,x);
}

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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

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

    int a,b,c;

    cin >> a >> b >> c;

    cout << max(c - (a-b), 0);

    return 0;
}


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

class state{
public:
    int a,b;
    state(int a=0, int b=0):a(a),b(b){}
    bool operator < (const state &s) const {
        if(a == s.a) return b > s.b;
        return a < s.a;
    }
};

state v[100];

int main(){
    int n,m;
    while(cin >> n >> m){
        int ans = 0;
        bool f = false;
        for(int i=0;i<m;i++) cin >> v[i].a >> v[i].b;
        sort(v,v+m);
        if(v[0].a == 1){
            for(int i=0;i<m;i++){
                if(v[i].b == n){
                    ans++;
                    f = true;
                    break;
                }
                //int a = lower(-1,m,v[i].b+1);
                //a = min(a,m-1);
                int maxb = -1, maxi = -1;
                for(int j=m-1;j>i;j--){
                    if(maxb < v[j].b && v[j].a <= v[i].b + 1){
                        maxb = v[j].b;
                        maxi = j;
                    }
                }
                ans++;
                i = maxi - 1;
                if(maxi == -1){
                    break;
                }
            }
        }

        if(!f) cout << "Impossible" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


long double dp[3500][3500];
int main() {
  ll n;
  cin>>n;
  vector<long double> p(n);
  dp[0][0]=1;
  rep(i,n){
    cin>>p[i];
    rep(j,i+2){
      if(j!=0){
        dp[i+1][j]=dp[i][j-1]*p[i]+dp[i][j]*(1.0-p[i]);
      }else{
        dp[i+1][j]=dp[i][j]*(1.0-p[i]);
      }
    }
  }
  long double ans=0;
  rep(i,n+1){
    if(i>n-i){
      ans+=dp[n][i];
    }
  }
  cout << fixed << setprecision(11) << ans << endl;
  return 0;
}



Measured memory_bytes: 164352
from sys import exit

n = int(input())
num_list = [int(i) for i in input().split()]
if 0 in num_list:
    print(0)
    exit()
ans = 1
for i in range(n):
    ans *= num_list[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21392
n, y = [int(e) for e in input().split()]

for xi in range(n + 1):
    for yi in range(n - xi + 1):
        zi = n - xi - yi
        if y == xi * 10000 + yi * 5000 + zi * 1000:
            print(xi, yi, zi)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 40684
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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



	ll R, D, X;
	cin >> R >> D >> X;

	rep(i, 10) {
		X = R * X - D;
		cout << X << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int T[N];
  int A[N];
  for(int i=0;i<N;i++)cin>>T[i]>>A[i];
  lint t=1;
  lint a=1;
  for(int i=0;i<N;i++){
    lint k=max(((t-1)/T[i]+1),((a-1)/A[i]+1));
    t=k*T[i];
    a=k*A[i];
    // cout<<t<<" "<<a<<endl;
  }
  cout<<t+a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=1005;
int n,x[maxn],y[maxn],vis[10];
double ans;
void dfs(int node,int cnt,double tmp){
	if(cnt==n-1) {
		ans+=tmp;
		return ;
	}
	vis[node] = 1;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			double tm=sqrt(1.0*((x[node]-x[i])*(x[node]-x[i])+(y[node]-y[i])*(y[node]-y[i])));
			dfs(i,cnt+1,tmp+tm);
			vis[i]=0;
		}
	}
}
int main(){
	scanf("%d",&n);
	int ma=1;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		ma*=i;
	}
	ans = 0.0;
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		dfs(i,0,0.0);
	}
	printf("%.7lf\n",ans/(1.0*ma));
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    while(true) {
        auto n = readLong();
        if(n == 0) {
            return;
        }
        long[] t;
        t.reserve(n.to!size_t);
        foreach(i; iota(1, n)) {
            t ~= i*i%n;
        }
        t.sort();
        auto u = t.uniq.array;
        auto ans = new long[](n.to!uint);
        foreach(i; iota(u.length)) {
            foreach(j; iota(u.length)) {
                if(i == j) {
                    continue;
                }
                auto m = u[i] - u[j];
                if(m < 0) {
                    m += n;
                }
                if(m > (n-1)/2) {
                    m = n-m;
                }
                ++ans[m.to!uint];
            }
        }
        foreach(i; iota(1, (n-1)/2 + 1)) {
            writeln(ans[i.to!uint]);
        }
    }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  string s;
  int n;
  cin >> n >> s;
  
  if(n % 2 == 0 & s.substr(0,n/2) == s.substr((n+1)/2))
    cout << "Yes" << endl;
  else cout << "No" << endl;  
}

Measured memory_bytes: 3600
while True:
    x, y, s = map(int, input().split())
    if x == 0 and y == 0 and s == 0:
        break
    maxsum = 0
    for one in range(1, s):
        for two in range(1, s):
            if one*(100+x)//100 + two*(100+x)//100 == s:
                maxsum = max(maxsum, one*(100+y)//100 + two*(100+y)//100)
    print(maxsum)




Measured memory_bytes: 5592
#include <stdio.h>

int main()
{
  int n;
  scanf("%d", &n);
  int a[200000];
  long long unsigned int totalsum = 0;
  for (int i = 0; i < n; ++i)
  {
    scanf("%d", &a[i]);
    totalsum += a[i];
    totalsum %= 1000000007;
  }
  long long unsigned int ans = 0;
  for (int i = 0; i < n-1; ++i)
  {
    if (a[i] < totalsum)
    {
    	totalsum -= a[i];
    }
    else
    {
      totalsum = 1000000007 - a[i] + totalsum;
    }
    ans += a[i] * totalsum;
    ans = ans % 1000000007;
  }
  printf("%d", ans);
  return 0;
}


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

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


# 実装を行う関数
def resolve(test_def_name=""):
    n_s = list(input())

    ans = 0
    for n in n_s:
        ans += int(n)

    if ans % 9 == 0:
        print("Yes")
    else:
        print("No")


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

    def test_input_1(self):
        test_input = """123456789"""
        output = """Yes"""
        self.assertIO(test_input, output)

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

    def test_input_3(self):
        test_input = """31415926535897932384626433832795028841971693993751058209749445923078164062862089986280"""
        output = """No"""
        self.assertIO(test_input, output)

    # 自作テストパターン
    def test_original(self):
        pass


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

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


Measured memory_bytes: 81792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001;
ll  power(ll  i,ll  j)
{
    if(j==0)
    return 1 ;
    ll t=power(i,j/2)%maa ;
    if(j%2==0)
    return (t%maa*t%maa)%maa ;
    else
    return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
}
ll bit[N] ;
void up(ll i)
{
    while(i<N)
    {
        bit[i]++ ;
        i+=(i&(-i)) ;
    }
}
ll get(ll i)
{
    ll x=0 ;
    while(i>0)
    {
        x+=bit[i] ;
        i-=(i&(-i)) ;
    }
    return x ;
}
int main()
{
   fast ;
   memset(bit,0,sizeof(bit)) ;
   ll ans=0 ;
   ll n ;
   cin>>n ;
   for(ll i=0;i<n;i++)
   {
       ll x ;
       cin>>x ;
       if(get(x)==0)
        ans++ ;

       up(x) ;
   }
   cout<<ans ;



}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
	ll n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	string ans="";
	for(ll i=0;i<n;i++){
		ans+=a[i];
		ans+=b[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256