akhauriyash/Code-Regression huggingface dataset:
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
bool flag[19999990];
int _prime[19999990];
void get_prime(int maxn)
{
    int i,j;
    for(i=2;i<=maxn;i++)
        if(!flag[i])
        {
            _prime[++_prime[0]]=i;
            for(j=i*i;j<=maxn;j+=i)
                flag[j]=true;
        }
}
int a[10101],b[10101];
int main()
{
	int n;
	cin>>n;
	
	int i;
	int s=0;
	for(i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(i=0;i<n-2;i++){
		if(a[i]==b[i]&&a[1+i]==b[i+1]&a[i+2]==b[i+2]){
			cout<<"Yes"<<endl;
			return 0;
		}
		
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3620
from operator import itemgetter
import sys
N=int(input())
A=[int(i) for i in input().split()]
B=[(A[i],i) for i in range(N)]
B=sorted(B,key=itemgetter(1))
B=sorted(B,key=itemgetter(0))
T=[0]*N
cos,pt=B.pop()
for i in range(1,N):
    cos2,pt2=B.pop()
    T[pt]+=(cos-cos2)*i
    pt=min(pt,pt2)
    cos=cos2
T[pt]+=cos*N
for i in T:
    print(i)


Measured memory_bytes: 77924
n=int(input())
a=list(map(int, input().split()))
zero=a.count(0)

Inf=10**18

if zero>=1:
    print(0)
else:
    ans=1
    a.sort(reverse=True)
    for num in a:
        ans*=num
        if ans>Inf:
            print(-1)
            exit()
    
    print(ans)

Measured memory_bytes: 84580
import math  # noqa: F401
from typing import Dict, List, Optional, Set, Tuple, Union  # noqa: F401


def rooting(N: int, A: List[int], B: List[int]) -> Dict[int, Set[int]]:
    R: Dict[int, Set[int]] = {k: {-1} for k in range(1, N + 1)}  # type: ignore
    for a, b in zip(A, B):
        if R[a] == {-1}:
            R[a] = {b}
        else:
            R[a] |= {b}
        if R[b] == {-1}:
            R[b] = {a}
        else:
            R[b] |= {a}
    return R


def main(N: int, M: int, H: List[int], A: List[int], B: List[int]):
    root: Dict[int, Set[int]] = rooting(N, A, B)
    ans = 0
    for k, v in root.items():
        if v == {-1}:
            ans += 1
        else:
            ans += all(H[v_ - 1] < H[k - 1] for v_ in v)
    print(ans)


if __name__ == "__main__":
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A, B = [], []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    main(N, M, H, A, B)


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

using namespace std;

int main()
{
    int N, Sum = 1;
    cin >> N;

    for (int i = 1; pow(2, i) < N + 1; i++)
    {
        Sum = pow(2, i);

        if (Sum >= N)
        {
            break;
        }
    }

    cout << Sum;
}


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

int gcd(int x, int y){
	if(x < y) swap(x, y);
	if(y == 0){
		return x;
	}
	return gcd(y, x%y);
}

int main(){
	int N, X;
	cin >> N >> X;
	int x[N], a[N];
	for(int i=0; i<N; i++){
		cin >> x[i];
		a[i] = abs(x[i] - X);
	}
	if(N == 1){
		cout << a[0] << endl;
		return 0;
	}
	int D = gcd(a[0], a[1]);
	for(int i=2; i<N; i++){
		D = gcd(D, a[i]);
	}
	cout << D << endl;
	return 0;
}

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

typedef long long ll;

int main()
{
	ll a, b, c, k, ans = 0;
	cin >> a >> b >> c >> k;

	ans += min(a, k);

	k = (k - a);

	if(k < 1){
		cout << ans << "\n";
		return 0;
	}

	k = (k - b);

	if(k < 1){
		cout << ans << "\n";
		return 0;
	}

	ans -= min(c, k);

	cout << ans << "\n";


}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;


int main() {
    long long a, b, n, x;
    scanf("%lld%lld%lld", &a, &b, &n);
    if(n < b) x = n;
    else x = b - 1;
    printf("%lld\n", a * x / b);
    
    return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,a[114][514]={0};
	cin>>n;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		for(int j=0;j<s.size();j++)a[i][s[j]-97]++;
	}
	for(int j=0;j<26;j++)
	{
		a[n][j]=810;
		for(int i=0;i<n;i++)
		{
			a[n][j]=min(a[n][j],a[i][j]);
		}
		for(int i=0;i<a[n][j];i++)cout<<(char)(97+j);
	}
  	cout<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	string s;
	cin >> s;

	int count = 0;
	string prev;
	prev.push_back(s[0]);
	count++;

	string temp;
	for (string::size_type i = 1; i < s.size(); i++) {		
		temp += s[i];
		if (temp != prev) {
			count++;
			prev = temp;
			temp.clear();
		}
	}


	cout << count << endl;

	return 0;

}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m, f, b;
    cin >> m >> f >> b;
    if (m >= b) cout << 0 << endl;
    if (m + f < b) cout << "NA" << endl;
    if (m < b && m + f >= b) cout << b - m << endl;
    
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  vector<double> X(N);
  vector<string> U(N);
  
  double total = 0;
  for( int i = 0; i < N; i++ ){
    cin >> X.at(i) >> U.at(i);
    if( U.at(i) == "BTC" ){
      X.at(i) = X.at(i) * 380000.0000;
    }
    total += X.at(i);
  }
  
  cout << total << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    cout << (b + a - 1) / a << endl;
    return 0;
}




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

int main(){
  string s;
  cin >> s;
  string t = s;
  int n = s.size();
  rep(i,n){
    t[i] = 'x';
  }
  cout << t << endl;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int N;
    cin >> N;
    if(N < 1000){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }

    return 0;
}


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

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

    int H, W;
    cin >> H >> W;
    char s[H][W];
    bool flag[H][W];
    int base = 0;
    rep(i,H){
        rep(j,W){
            cin >> s[i][j];
            flag[i][j] = false;
            if(s[i][j] == '#') base++;
        }
    }
    
    rep(i,H){
        rep(j,W){
            if(s[i][j] == '#'){
                // left
                if(j < W - 1 && s[i][j+1] == '#') flag[i][j] = flag[i][j+1] = true;
                // down
                if(i < H - 1 && s[i+1][j] == '#') flag[i][j] = flag[i+1][j] = true;
            }
        }
    }
    
    int count_true = 0;
    rep(i,H){
        rep(j, W){
            if(flag[i][j]) count_true++;
        }
    }
    
    string ans = "Yes";
    if(count_true < base){
        ans = "No";
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
 
 
 
int main(){
    
    ll n,l,r,f=1,s=1,tmp;
    
    cin>>n;
    rep(i,0,n){
        cin>>l>>r;
        tmp=max((ll)1,max(f/l,s/r));
        while(f>l*tmp||s>r*tmp)tmp++;
        f=tmp*l;
        s=tmp*r;
    }
    cout<<f+s<<endl;
    
    return 0;
}

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

#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    int d,g,a,ans=114514;
    cin>>d>>g;
    ll p[d],c[d];
    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
    }
    for(int bit=0;bit< (1<<d);bit++){
        map<int ,int>mp;
        ll sum=0;
        int num=0;
        for(int i=0;i<d;i++){
            if(bit&(1<<i)){
                sum+=(i+1)*100*p[i]+c[i];
                num+=p[i];
                mp[i]++;
            }
        }
        if(sum<g){
            for(int i=d-1;i>=0;i--){
                if(mp[i]==0){
                    a=(g-sum)/((i+1)*100);
                    if((g-sum)%((i+1)*100)!=0)a++;
                    if(a<=p[i]){
                        num+=a;
                        break;
                    }
                    else{
                        num=114514;
                        break;
                    }
                }
            }
        }
        ans=min(ans,num);
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int width = sc.nextInt();
		int height = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		sc.close();if(x + r > width || x - r  < 0 || y + r > height || y -r < 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 26420
import bisect
a,b,q=map(int,input().split())
INF=10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]

for k in range(q):
  x=int(input())
  i=bisect.bisect_right(s,x)
  j=bisect.bisect_right(t,x)
  d=INF
  for S in [s[i-1],s[i]]:
    for T in [t[j-1],t[j]]:
      d1=abs(S-x)+abs(S-T)
      d2=abs(T-x)+abs(S-T)
      d=min(d,d1,d2)
  print(d)



Measured memory_bytes: 12800
from itertools import product
N = int(input())
X = [chr(ord('a') + i) for i in range(N)]
first_presence = {x: i for x, i in zip(X, list(range(N)))}

ans = ['a']
R = ['a']
# 何文字目以降を変更するか
for i in range(1, N):
    nr = []
    for r in R:
        mr = max(r)
        for x in X:
            nr.append(r + x)
            if mr == x:
                break
        nr.append(r + chr(ord(mr) + 1))
    R = nr

ans = list(set(R))
ans.sort()
print(*ans, sep="\n")


Measured memory_bytes: 17904
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
bitset<46>a[M],kk;
int n,k,x,ses=0;
int c1[46],c2[46];
int dp[46][2];
int Magic(int pos,int is_sml)
{
    if(pos<0)return 0;
    int &ret=dp[pos][is_sml];
    if(ret!=(-1))return ret;
    ret=0;
    if(is_sml)
    {
        int c=max(c1[pos],c2[pos]);
        int cost=(c*(1LL<<pos));
        ret=cost+Magic(pos-1,is_sml);
    }
    else
    {
        if(kk[pos]==1)
        {
            int cost=c1[pos]*(1LL<<pos);
            ret=max(ret,cost+Magic(pos-1,1));
            cost=c2[pos]*(1LL<<pos);
            ret=max(ret,cost+Magic(pos-1,is_sml));
        }
        else
        {
            int c=c1[pos];
            int cost=c*(1LL<<pos);
            ret=cost+Magic(pos-1,is_sml);
        }
    }
    return ret;
}
 main()

{
    fast
    memset(dp,-1,sizeof dp);
    cin>>n>>k;
    f(i,1,n)
    {
        cin>>x;
        a[i]=x;
        f(j,0,45)
        {
            if(a[i][j])c1[j]++;
            else c2[j]++;
        }
    }
    kk=k;
    int mx_k=-1;
    f(j,0,45)
    {
        if(kk[j])mx_k=j;
    }
    rf(j,45,mx_k+1)
    {
        ses+=(c1[j]*(1LL<<j));
    }
    ses+=Magic(mx_k,0);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 1024
#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 repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    char c;
    cin >> c;
    if(c<='Z') cout << 'A' << endl;
    else cout << 'a' << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static ll n,l,t;
	static ll x[100010],w[100010];
	scanf("%lld%lld%lld",&n,&l,&t);
	rep1(i,n)scanf("%lld%lld",&x[i],&w[i]);
	
	static ll y[100010];
	rep1(i,n){
		if(w[i] == 1){
			y[i] = (x[i]+t)%l;
		}
		else {
			y[i] = (x[i]+l-t%l)%l;
		}
	}
	sort(y+1,y+n+1);
	
	ll d = 0;
	rep1(i,n){
		d += y[i]-x[i];
	}
	ll _d = 0;
	rep1(i,n){
		if(w[i] == 1)_d ++;
		else _d --;
	}
	_d *= t;
	int id = (_d-d)/l;
	id %= n;
	while(id < 0)id += n;
	
	rep1(i,n){
		if(i+id > n)printf("%lld\n",y[i+id-n]);
		else printf("%lld\n",y[i+id]);
	}
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int box[105],las[20005],edv[20005],cnt=0;
void adde(int u,int v)
{
	las[++cnt]=box[u];
	box[u]=cnt;
	edv[cnt]=v;//cout<<"ADDE"<<u<<" "<<v<<endl;
}
int n;
int xa[105],ya[105],xb[105],yb[105];
int mat[105];
bool vis[105];
int dfs(int now)
{
	for(int i=box[now];i;i=las[i])
		if(!vis[edv[i]])
		{
			vis[edv[i]]=1;
			if(!mat[edv[i]] || dfs(mat[edv[i]]))
			{
				mat[edv[i]]=now;
				return 1;
			}
		}
	return 0;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		read(xa[i]);
		read(ya[i]);
	}
	for(int i=1;i<=n;i++)
	{
		read(xb[i]);
		read(yb[i]);
		for(int j=1;j<=n;j++)
			if(xa[j]<xb[i] && ya[j]<yb[i])
				adde(i,j);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		if(dfs(i))
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N, K = map(int, input().split(' '))

counter = Counter()

for _ in range(N):
    a, b = map(int, input().split(' '))
    counter[a] += b

for a in sorted(counter.keys()):
    b = counter[a]
    if K <= b:
        print(a)
        break
    K -= b


Measured memory_bytes: 16412
def sq(x,y):
    tot = 0
    for i in range(D):
        tot += (x[i]-y[i])**2
    return tot
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        x = X[i]
        y = X[j]
        if abs(round(sq(x,y)**0.5,1)**2-sq(x,y))<10**(-8):
            cnt += 1
print(cnt)

Measured memory_bytes: 3188
#include <stdio.h>

int main() {
	int W,H,x,y,r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	// condition W
	if ( (x < r) || (W - x) < r) {
		printf("No\n");
		return 0;
	}
	// condition H
	if ( (y < r) || (H - y) < r) {
	 	printf("No\n");
		return 0;
    }
  	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 584
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100100;
int S[MAXN], T[MAXN];
int P[MAXN];
int N, M;
ll sumEven[MAXN], sumOdd[MAXN];

ll calc(int i) {
    int is = lower_bound(P, P+M, S[i]) - P;
    int it = lower_bound(P, P+M, T[i]) - P; it--;
    if (is == M || it == -1) return T[i] - S[i];
    ll ret = 0;
    if ((it-is)%2 == 0) {
        if (is%2) {
            ret = (sumOdd[it+2] - sumOdd[is]) - (sumEven[it+1] - sumEven[is+1]) - S[i];
        } else {
            ret = (sumEven[it+2] - sumEven[is]) - (sumOdd[it+1] - sumOdd[is+1]) - S[i];
        }
    } else {
        if (is%2) {
            ret = (sumOdd[it+1] - sumOdd[is]) - (sumEven[it+2] - sumEven[is+1]) + T[i] - S[i];
        } else {
            ret = (sumEven[it+1] - sumEven[is]) - (sumOdd[it+2] - sumOdd[is+1]) + T[i] - S[i];
        }
    }
    return ret;
}

ll solve() {
    memset(sumEven, 0, sizeof(sumEven));
    memset(sumOdd, 0, sizeof(sumOdd));
    for (int i = 0; i < M; i += 2) {
        sumEven[i+1] = sumEven[i];
        sumEven[i+2] = sumEven[i] + P[i];
    }
    for (int i = 1; i < M; i += 2) {
        sumOdd[i+2] = sumOdd[i] + P[i];
        sumOdd[i+1] = sumOdd[i+2];
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) if (S[i] < T[i]) {
        ll tmp = calc(i);
        ans += tmp;
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for (int i = 0; i < N; i++)
        cin >> S[i] >> T[i];
    for (int i = 0; i < M; i++) 
        cin >> P[i];
    sort(P, P+M);
    ll ans = solve();
    reverse(P, P+M);
    for (int i = 0; i < M; i++)
        P[i] *= -1;
    for (int i = 0; i < N; i++) {
        S[i] *= -1;
        T[i] *= -1;
    }
    ans += solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5912
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)



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

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    rep(i, n) rep(j, n) cin >> a[i][j];

    vector<ll> dp(1<<n, 0);

    dp[0]=1;
    repr(S, 1, 1<<n){
        int i=0;
        rep(j, 22) if(S&1<<j) ++i;
        rep(j, n) if(S&1<<j && a[i-1][j]==1){
            dp[S] += dp[S^(1<<j)];
            chmod(dp[S]);
        }
    }
    cout << dp[(1<<n)-1] << endl;
    

    return 0;
}



Measured memory_bytes: 16640
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A = [int(i) for i in read().split()]
for i in range(1, len(A) + 1):
    if A[i - 1] != 0:
        print(f'Case {i}: {A[i - 1]}')



Measured memory_bytes: 6468
s = input()
key = 'keyence'
if len(s) < len(key):
    print("NO")
elif s[:len(key)] == key:
    print("YES")
elif s[-len(key):] == key:
    print("YES")
else:
    for i in range(1, len(key)):
        head = s.startswith(key[0:i])
        hip = s.endswith(key[i:])
        if head and hip:
            print("YES")
            break
    else:
        print("NO")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define N 200005

int n, sol, flag;
int a[N];

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

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sol = 1;
    flag = 0;
    for(int i = 2; i <= n; i++) {
        if(!flag) {
            if(a[i] == a[i - 1]) flag = 0;
            if(a[i] < a[i - 1]) flag = -1;
            if(a[i] > a[i - 1]) flag = 1;
        } else if(flag == 1) {
            if(a[i] < a[i - 1]) {
                sol++;
                flag = 0;
            }
        } else if(flag == -1) {
            if(a[i] > a[i - 1]) {
                sol++;
                flag = 0;
            }
        }
    }
    cout << sol << "\n";
}

Measured memory_bytes: 3940
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
			int N=sc.nextInt();
			int A=sc.nextInt();
			int B=sc.nextInt();
			
			String v;
			int sum,ans=0;
			for(int i=1;i<=N;i++) {
				//p(i+"i");
				v=""+i;
				sum=0;
				for(int a=0;a<v.length();a++) {
					sum+=v.charAt(a)-48;
				}
				if(sum>=A&&sum<=B) {
					ans+=i;
					
				}
				
			}
			p(ans);
			
			
			
			
			
			
			
			
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 24148
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  long long n, a, b;
  cin >> n >> a >> b;

  if (a > b)
    cout << 0 << endl;
  else {
    long long l = b + (n-1) * a;
    long long h = a + (n-1) * b;
    cout << max(0LL, h-l+1) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
//ll visit[100001]={0};
//vector<ll> adj[1000001];

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll bin(ll n)
{
    int di= 0;
    while(n)
    {   di=di+n%10;
        n=n/10;
        
    }
    return di;
}

int main(){
   IOS;
ll t;t=1;//cin>>t;
while(t--){
ll n;cin>>n;
ll a[n+1];
for(ll i=1;i<n+1;i++) cin>>a[i];
ll dp[n+1];
dp[1]=0;
dp[2]=abs(a[2]-a[1]);

for(ll i=3;i<=n;i++){
    dp[i]=min((dp[i-2]+(abs(a[i]-a[i-2]))),dp[i-1]+abs(a[i]-a[i-1]));
}
    cout<<dp[n]<<"\n";
    
}
    
    
    
    





return 0;}


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

int main() {
    double a, b;
    int C;
    scanf("%lf %lf %d", &a, &b ,&C);
    double rad = (C/180.0)*M_PI;

    printf("%lf\n", a*b*sin(rad)/2);
    printf("%lf\n", a+b+sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(rad)));
    printf("%lf\n", 2*(a*b*sin(rad)/2)/a);
    return 0;
}


Measured memory_bytes: 3400
n, t_th = map(int, input().split())
c_min = 10000
for i in range(n):
    c, t = map(int, input().split())
    if t <= t_th and c < c_min:
        c_min = c
if c_min == 10000:
    print('TLE')
else:
    print(c_min)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S; cin >> S;
  if (S.find('a') != string::npos && S.find('b') != string::npos && S.find('c') != string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, adj[200001], vis[200001];
long long k;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> adj[i];
	int vtx = 1;
	vector<int> st, cyc;
	while(vis[vtx] < 2){
		vis[vtx]++;
		if(vis[vtx] == 1) st.push_back(vtx);
		else cyc.push_back(vtx);
		vtx = adj[vtx];
	}
	for(int i = 0; i < (int)cyc.size(); i++) st.pop_back();
	if(k < (int)st.size()){
		cout << st[k] << "\n";
		return 0;
	}else k -= (int)st.size();
	k %= (int)cyc.size();
	cout << cyc[k] << "\n";
	return 0;
}

Measured memory_bytes: 7108
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	double r;
	cin >> r;
	fcout << r * 2.0 * 3.14159265 << endl;
	return 0;
}

Measured memory_bytes: 3800
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M int
	ls := [][]int{}

	fmt.Scan(&N, &M)

	for i := 0; i < N; i++ {
		var s, t int
		fmt.Scan(&s, &t)
		ls = append(ls, []int{s, t})
	}


		sort.Sort(retLargest(ls))

	ans := 0
	count := 0
	for i := 0; i < N; i++ {
		//ls[i][0]: value, ls[i][1]: num
		if ls[i][1] < M-count {
			count += ls[i][1]
			ans += ls[i][0] * ls[i][1]
		} else {
			ans += ls[i][0] * (M - count)
			break
		}
	}

	fmt.Println(ans)
}

type retLargest [][]int

func (el retLargest) Len() int {
	return len(el)
}

func (el retLargest) Swap(i, j int) {
	el[i], el[j] = el[j], el[i]
}

func (el retLargest) Less(i, j int) bool {
	return el[i][0] < el[j][0]
}


Measured memory_bytes: 12032
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n, k;
    while (cin >> n >> k, n) {
        vector<int> ac(n+1, 0);
        for (int i=1; i<=n; ++i) {
            cin >> ac[i];
            ac[i] += ac[i-1];
        }
        int res = -INT_MAX;
        for (int i=k; i<=n; ++i) {
            res = max(res, ac[i] - ac[i-k]);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1532
#include <stdio.h>


 int main()
 {
   int n;
   long i,a,sum,min,max;


   scanf("%d\n",&n);


min =1000000;
max =-1000000;
sum = 0;

for (i = 0; i < n; i++) {
scanf("%ld",&a);

  if (a < min) {
      min = a;
    }

  if (a > max){

  max = a;
  }

    sum = sum+a;

  }

printf("%ld %ld %ld\n",min,max,sum);



return(0);
}

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

int main()
{
  int n ;
  cin >> n ;
  vector<int64_t> even ;
  vector<int64_t> odd ;
  for(int i = 0 ; i < n ; i++)
  {
    int64_t x ;
    cin >> x ;
    if(x % 2 == 0)
    {
      even.push_back(x) ;
    }
    else
    {
      odd.push_back(x) ;
    }
  }
  
  if(odd.size() % 2 != 0)
  {
    cout << "NO" << endl ;
  }
  else
  {
    cout << "YES" << endl ;
  }
  
}


Measured memory_bytes: 1276
N = int(input())
max_val_1 = 0
max_val_2 = 0
for i in range(N):
    A = int(input())
    if max_val_1 < A:
        max_val_2 = max_val_1
        max_val_1 = A
        max_num = i
    elif max_val_2 < A:
        max_val_2 = A
        
for i in range(N):
    if i == max_num:
        print(max_val_2)
    else:
        print(max_val_1)

Measured memory_bytes: 4540
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

typedef struct {
	int x, y;
}Loc;

int H, W;
string tile[100];
bool al[100][100];
Loc l = { 0,0 };


bool check()
{
	if (al[l.x][l.y])
	{
		cout << "LOOP" << endl;
		return true;
	}
	else
	{
		al[l.x][l.y] = true;
		return false;
	}
}

int main()
{
	while (cin >> H >> W && H != 0)
	{
		l = { 0,0 };
		for (int i = 0; i < H; i++) {
			cin >> tile[i];
			for (int j = 0; j < W; j++)
				al[i][j] = false;
		}
		al[0][0] = true;
		while (true) {
			if (tile[l.x][l.y] == '<')
			{
				l.y--;
				if (check())
					break;
			}
			else if (tile[l.x][l.y] == '>')
			{
				l.y++;
				if (check())
					break;
			}
			else if (tile[l.x][l.y] == 'v')
			{
				l.x++;
				if (check())
					break;;
			}
			else if (tile[l.x][l.y] == '^')
			{
				l.x--;
				if (check())
					break;
			}
			else
			{
				cout << l.y << " " << l.x << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		int[] m = new int[N];
		for (int i = 0; i < N; i++) {
			m[i] = K;
		}
		for (int i = 0; i < Q; i++) {
			int c = sc.nextInt();
			m[c - 1]++;
		}
		for (int i = 0; i < m.length; i++) {
			System.out.println((m[i] - Q) > 0 ? "Yes" : "No");
		}
		sc.close();
	}
}

Measured memory_bytes: 57672
#include<stdio.h>

int main(void)
{
  int h,w;
  for(;;)
  {
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }
    int i,j;
    for (i=0; i<h; ++i) {
      for (j = 0; j < w;  ++j) {
        if (i==0 || i==h-1 || j==0 || j==w-1) {
          putchar('#');
        }
        else{
          putchar('.');
        }
      }
      puts("");
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {

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

		boolean[] st = new boolean[30];
		
		for(int i = 0; i < 28; i++){
			st[sc.nextInt() - 1] = true;
		}
		
		for(int i = 0; i < 30; i++){
			if(!st[i]){
				System.out.println(i+1);
			}
		}

	}

}

Measured memory_bytes: 12000
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  string s;
  cin>>s;
  if(s=="AAA" || s=="BBB") out("No");
  else out("Yes");
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;

  ll x = 1, y = 1;

  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (x % a)
      x += (a - (x % a));
    if (y % b)
      y += (b - (y % b));

    ll v = x / a * b;
    if (v >= y) {
      y = v;
    } else {
      x = y / b * a;
    }
  }

  cout << x + y << endl;

  return 0;
}


Measured memory_bytes: 3656
main = do
    (n:_) <- (fmap read . words) <$> getLine
    str <- getLine

    -- break list
    let numList b = [(isElem c $ take b str) && (isElem c $ drop b str) | c<-['a'..'z']]
    let ansList = [count True $ numList b | b<-[1..n] ]
    print $ maximum ansList


count :: Eq a => a -> [a] -> Int
count c = length . filter (c==)

isElem :: Eq a => a -> [a] -> Bool
isElem _ [] = False
isElem c (x:xs)
    | c==x = True
    | otherwise =isElem c xs 

Measured memory_bytes: 764
import sys
I=sys.stdin.readlines()
N,M,L=map(int,I[0].split())
a,b,c=0,0,0
D=[[L+1]*N for i in range(N)]
for i in range(M):
  a,b,c=map(int,I[i+1].split())
  a,b=a-1,b-1
  D[a][b]=c
  D[b][a]=c
for i in range(N):
  D[i][i]=0
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j]=min(D[i][j],D[i][k]+D[k][j])
D2=[[N*N+2]*N for i in range(N)]
for i in range(N):
  D2[i][i]=0
  for j in range(N):
    if D[i][j]<=L:
      D2[i][j]=1
for k in range(N):
  for i in range(N):
    for j in range(N):
      D2[i][j]=min(D2[i][j],D2[i][k]+D2[k][j])
Q=int(I[M+1])
for i in range(Q):
  a,b=map(int,I[i+2+M].split())
  if N<D2[a-1][b-1]:
    print(-1)
  else:
    print(D2[a-1][b-1]-1)

Measured memory_bytes: 91416
s=input()
cnt={'R':0,'L':0}

l=[]
cnt=0
for i in range(len(s)):
    if i==len(s)-1:
        if s[i]==s[i-1]:
            l.append((s[i],cnt+1))
        else:
            l.append((s[i-1],cnt))
            l.append((s[i],1))

    elif i>=1 and s[i]!=s[i-1]:
        l.append((s[i-1],cnt))
        cnt=1
    elif i==0 or s[i]==s[i-1]:
        cnt+=1

#print(l)

ans=[0]*len(s)
index_num=-1
for i in range(len(l)):
    s,num=l[i]
    if i==0 and s=='L':
        ans[0]=num
        index_num+=num

    if s=='R':
        index_num+=num
        ans[index_num]+=(num-1)//2+1
        ans[index_num+1]+=num//2
    else:
        ans[index_num+1]+=(num-1)//2+1
        ans[index_num]+=num//2
        index_num+=num
    #print(ans,index_num)
print(*ans)

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

namespace ABC107B
{
    class ABC107B
    {
        static void Main(string[] args)
        {
            var dg = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
            var h = dg[0];
            var w = dg[1];

            var row = new bool[w];

            var map = new List<String>(h);

            for (int i = 0; i < h; ++i)
            {
                var a = Console.ReadLine();

                var emptyLine = true;
                for(int j = 0; j < w; ++j)
                {
                    if (a[j] == '#')
                    {
                        row[j] = true;
                        emptyLine = false;
                    }
                }

                if (!emptyLine)
                {
                    map.Add(a);
                }
            }

            foreach (var v in map)
            {
                for (int i = 0; i < w; ++i)
                {
                    if (row[i])
                    {
                        Console.Write(v[i]);
                    }
                }
                Console.WriteLine();
            }
        }
    }
}


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

using namespace std;

int main()
{
    string s;  cin >> s;
    int ans = 700;

    if (s[0] == 'o')    ans += 100;
    if (s[1] == 'o')    ans += 100;
    if (s[2] == 'o')    ans += 100;

    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
K = int(input())

ans = []
table ={}

for i in range(len(S)):
    for j in range(i, len(S)+1):
        if (j-i)>=6:
            break
        if i==j:
            s = S[i]
            if s in table:
                continue
            table[s] = 1
            ans.append(s)
            continue
        if S[i:j]=="":
            continue
        s = S[i:j]
        if s in table:
            continue
        table[s] = 1
        ans.append(s)

ans = sorted(ans)
print(ans[K-1])


Measured memory_bytes: 4872
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	result := 0
	a := make([]int, N)
	bs := make([]int, N)
	for b := 0; b < 60; b++ {
		for i := 0; i < N; i++ {
			a[i] = (A[i] >> uint(b)) & 1
		}

		bs[N-1] = a[N-1]
		for i := N - 2; i > -1; i-- {
			bs[i] = bs[i+1] + a[i]
		}

		t := 0
		for i := 0; i < N-1; i++ {
			if a[i] == 0 {
				t += bs[i+1]
			} else {
				t += (N - (i + 1)) - bs[i+1]
			}
			t %= 1000000007
		}
		B := (1 << uint(b)) % 1000000007
		result += (t * B) % 1000000007
		result %= 1000000007
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 13184
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    // dp[i][j] i番目からj番目までの最小値
    int n;
    cin >> n;
    vector<int> r(n), c(n);
    rep(i, n) cin >> r[i] >> c[i];
    vector<vector<int>> dp(n, vector<int>(n, 1e9));
    rep(i, n) dp[i][i] = 0;
    for (int w = 1; w < n; w++) {
        //cout << "w=" << w << " ";
        for (int a = 0; a + w < n; a++) {
            //cout << "a=" << a << " ";
            int d = 1e9;
            for (int b = a; b <= a + w - 1; b++) {
                //cout << "b=" << b << " ";
                d = min(d, dp[a][b] + dp[b + 1][a + w] + r[a] * c[b] * c[a + w]);
            }
            dp[a][a + w] = d;
            //cout << "dp[" << a << "][" << a + w << "]=" << dp[a][a + w] << "\n";
        }
    }
    cout << dp[0][n - 1] << "\n";
}


Measured memory_bytes: 3156
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();
        
        double xlength_pow = (x1-x2)*(x1-x2);
        double ylength_pow = (y1-y2)*(y1-y2);
        
        double p1p2length = Math.sqrt(xlength_pow + ylength_pow);
        
        System.out.println(String.format("%.8f", p1p2length));
    }
}



Measured memory_bytes: 28132
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL h = -1, w = -1;
		cin >> h >> w;
		if (h < 0) return 0;
		LL ans = 1;
		if (h > 1 && w > 1) {
			ans = h * (w / 2);
			if (w % 2) {
				ans += (h + 1) / 2;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256