akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

struct BIT{
    int n;
    vector<int> d;
    BIT(int n=0):n(n),d(n+1) {}
    void add(int i, int x=1){
        for(int a=i; a<=n; a+=a&-a){
            d[a]+=x;
        }
    }
    int sum(int i){
        int res=0;
        for(int a=i; a>0; a-=a&-a){
            res+=d[a];
        }
        return res;
    }
};

int main(){
    int n,q; cin >> n >> q;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> pi(n+1,-1);
    vector<vector<int> > p(n+1);
    rep(i,n){
        int l=pi[a[i]];
        if(l!=-1) p[l].emplace_back(i);
        pi[a[i]]=i;
    }
    vector<vector<P> > qs(n);
    rep(i,q){
        int l,r; cin >> l >> r;
        l--; r--;
        qs[l].emplace_back(r,i);
    }

    vector<int> ans(q);
    BIT b(n);
    for(int x=n-1; x>=0; --x){
        for(int y : p[x]) b.add(y,1);
        for(P query : qs[x]){
            int r=query.first, i=query.second;
            ans[i]=r-x+1-b.sum(r);
        } 
    }

    rep(i,q) cout << ans[i] << endl;
return 0;
}

Measured memory_bytes: 59932
#include<iostream>
#include<algorithm>
#include<functional>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int max_n = 1e5 + 100;
pii a[max_n];
int n;
ll ans = 0;

int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i].first;
		a[i].second = i;
	}sort(a, a + n, greater<pii>());
	set<ll> myset;
	for (int i = 0;i < n;i++) {
		if (myset.empty()) {
			myset.insert(a[i].second);
			continue;
		}
		if (myset.size() == 1) {
			ll x = *myset.begin();
			ll y = a[i].second;
			if (x > y) { x = x ^ y;y = x ^ y;x = x ^ y; }
			ans += (x + 1) * (n - y) * a[i].first;
			myset.insert(a[i].second);
			continue;
		}
		set<ll>::iterator fr = myset.lower_bound(a[i].second);
		if (fr == myset.end()) {
			set<ll>::iterator be = --fr;
			ll right = n;ll x = *be;
			ll left = *(--be);ll y = a[i].second;
			ans += (x - left) * (right - y) * a[i].first;
		}
		else if (fr == myset.begin()) {
			ll left = -1;ll x = a[i].second;
			ll y = *fr;ll right = *(++fr);
			ans += (x - left) * (right - y) * a[i].first;
		}
		else {
			set<ll>::iterator be = --fr;fr++;
			ll behind = *be;ll front = *fr;
			ll left;ll right;
			if (be == myset.begin())left = -1;
			else left = *(--be);
			if (fr == --myset.end())right = n;
			else right = *(++fr);
			ll x = behind;ll y = a[i].second;
			ans += (x - left) * (front - y) * a[i].first;
			x = a[i].second;y = front;
			ans += (x - behind) * (right - y) * a[i].first;
		}myset.insert(a[i].second);
	}cout << ans << endl;
}

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

int main() {
	long long int x,y,a,b,c,u;
	vector<long long int> vec1;
	vector<long long int> vec2;
	vector<long long int> vec3;
	vector<long long int> vec;
	
	long long int ans = 0; 
	
	cin>>x>>y>>a>>b>>c;
	
	for(int i=0;i<a;i++){
	    cin>>u;
	    
	    vec1.push_back(u);
	}
	
	for(int i=0;i<b;i++){
	    cin>>u;
	    
	    vec2.push_back(u);
	}
	
	for(int i=0;i<c;i++){
	    cin>>u;
	    
	    vec3.push_back(u);
	}
	
	sort(vec1.begin(),vec1.end());
	sort(vec2.begin(),vec2.end());
	sort(vec3.begin(),vec3.end());
	
	reverse(vec1.begin(),vec1.end());
	reverse(vec2.begin(),vec2.end());
	reverse(vec3.begin(),vec3.end());
	
	for(int i=0;i<x;i++){
	    vec.push_back(vec1[i]);
	}
	
	for(int i=0;i<y;i++){
	    vec.push_back(vec2[i]);
	}
	
	for(int i=0;i<(int)min(x+y,(long long int)vec3.size());i++){
	    vec.push_back(vec3[i]);
	}
	
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	
	for(int i=0;i<(int)x+y;i++) ans+=(vec[i]);
	
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8560
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

$same = false;
for($i =  0; $i < strlen($a) ;$i++){
    if($a == $b)$same = true;
    $a = substr($a,1). $a[0];
}
echo $same ? "Yes" : "No";

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define mod 10e+7+7
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); 
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#endif
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}
ll w[100];
ll v[100];
ll dp[100][1000001];
ll infinity=1e18;
void solve()
{
	ll n,W;
	cin>>n>>W;
	rep(i,0,n)
	cin>>w[i]>>v[i];
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=1000*n;j++)
		{
			dp[i][j]=infinity;
		}
	}
	dp[0][0]=0;
	dp[0][v[0]]=w[0];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=0;
		for(int j=1 ;j<=1000*n;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>=v[i])
			dp[i][j]=min(dp[i][j],w[i]+dp[i-1][j-v[i]]);

		}
	}

	long long an;
	for(int j=1000*n;j>=0;j--)
	{
		if(dp[n-1][j]<=W)
		{
			an=j;
			break;
		}
	}
	cout<<an;

	
}

Measured memory_bytes: 82320
#include<bits/stdc++.h>
using namespace std;
/*6 5
4 7 10 6 5*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,num; cin>>num>>n;
    set<int> set;
    for(int i=0;i<n;i++)
    {
        int a; cin>>a;
        set.insert(a);
    }
    int ans=0,i=0;
    while(1)
    {
        if(set.find(num-i)==set.end())
        {
            ans=num-i;
            break;
        }
        if(set.find(num+i)==set.end())
        {
            ans=num+i;
            break;
        }
        i++;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
typedef long long ll;

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

    vector<int> evenNum(N);

    for(int i = 0 ; i < N; i++){
        if(A[i] % 2== 0)evenNum[i] = 1;
        else evenNum[i] = 2;
    }
    ll ans = 0;
    for(int i = 0; i < N ; i++){
        int a = 1;
        for(int j = 0; j < N; j++){
            if(j < i) a *= (3-evenNum[j]);
            else if( j == i) a *= evenNum[j];
            else a *= 3;
        }
        ans += a;
    }

    cout<< ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, L = map(int, input().split())

taste = [(L + i) for i in range(N)]
# print(taste)
minnum = 10000
sumtaste = sum(taste)
# print(sumtaste)
for i in range(N):
    if abs(minnum) > abs(taste[i]):
        minnum = taste[i]
# print("minnum")
# print(minnum)
print(sumtaste-minnum)


Measured memory_bytes: 3060
n = (int)(input())
A, B = (list)(map(int, input().split()))
scores = (list)(map(int, input().split()))

cand1 = sum(x <= A for x in scores)
cand3 = sum(x >= B+1 for x in scores)
cand2 = n - cand1 - cand3

print(min(cand1, cand2, cand3))


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> array = new ArrayList<>();
		int point = 1;
		Scanner scan = new Scanner(System.in);
		
		for(int i = 0; i < 3; i++) {
			array.add(scan.nextInt());
		}
		
		Collections.sort(array, Comparator.reverseOrder());
		
		for(int search : array) {
			if(search == 5) {
				point *= 5;
			}
			else if(search == 7) {
				point *= 7;
			}
		}
		if(point == 5 * 5 * 7) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
      	int a[] = new int[n];
      	int ans = Integer.MAX_VALUE;
      	for(int i=0;i<n;i++){
        	a[i] = in.nextInt();
        }
      	for(int i=-100;i<=100;i++){
        	int ans1 =0;
          	for(int j =0; j < n ;j++){
            	ans1+=(i-a[j])*(i-a[j]);
            }
          	ans = Math.min(ans,ans1);
        }
   		System.out.println(ans);
    }

}

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);



int main(){
    SPEED
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}


Measured memory_bytes: 256
import bisect
primes = [0, 0] + [1] * 49999
for i in range(2, 225):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0
values = [i for i, k in enumerate(primes) if k]
while True:
    n = int(input())
    if n == 0:
        break
    I = bisect.bisect(values, n//2)
    print(sum(1 for v in values[:I] if primes[n-v]))

Measured memory_bytes: 8276
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

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

    if(b-a == c-b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    long ans;
    while (0 < N)
        N /= K, ans++;
    writeln(ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[1000];
int main()
{
	int num, gen;
	cin >> num >> gen;
	int r = 0;
	for (int i = 0; i < num; i++)
	{
		int z;
		cin >> z;
		r += min(z, gen - z) * 2;
	}
	cout << r << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int maxn=200000;

int n,c[maxn+5],ans[maxn+5],ID[maxn+5];pair<int,int> p[maxn+5];
int E,lnk[maxn+5],nxt[(maxn<<2)+5],son[(maxn<<2)+5];
int Head,Tail,que[maxn+5];bool vis[maxn+5];

void Insert(int x,int y) {for (int i=x;i<=n;i+=i&-i) c[i]=max(c[i],y);}
int Max(int x) {int MAX=0;for (int i=x;i;i-=i&-i) MAX=max(MAX,c[i]);return MAX;}
inline bool cmp(const int &a,const int &b) {return p[a]<p[b];}
#define Add(x,y) (son[++E]=(y),nxt[E]=lnk[x],lnk[x]=E)
int main(){
	scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d%d",&p[i].fr,&p[i].sc),ID[i]=i;
	sort(ID+1,ID+1+n,cmp);
	for (int i=1;i<=n;i++){
		int lst=Max(p[ID[i]].sc-1);
		if (lst) Add(ID[lst],ID[i]),Add(ID[i],ID[lst]);
		Insert(p[ID[i]].sc,i);
	}
	for (int i=1;i<=n;i++) c[i]=0;
	for (int i=n;i;i--){
		int lst=Max(n-p[ID[i]].sc);
		if (lst) Add(ID[lst],ID[i]),Add(ID[i],ID[lst]);
		Insert(n-p[ID[i]].sc+1,i);
	}
	for (int i=1;i<=n;i++){
		if (!vis[i]){
			int now=0;Head=Tail=0;que[++Tail]=i;vis[i]=true;
			while (Head!=Tail){
				int x=que[++Head];now++;
				for (int j=lnk[x];j;j=nxt[j])
					if (!vis[son[j]]) que[++Tail]=son[j],vis[son[j]]=true;
			}
			for (int i=1;i<=Tail;i++) ans[que[i]]=now;
		}
		printf("%d\n",ans[i]);
	}
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0) return 0;
    int ans=0;
    vector<int> a(11,0);
    int d,p;
    for(int i=0;i<n;i++){
      cin >> d >> p;
      a[p]+=d;
    }
    int tmp;
    for(int i=10;i>0;i--){
      tmp=min(m,a[i]);
      a[i]-=tmp;
      m-=tmp;
    }
    for(int i=0;i<=10;i++){
      ans+=i*a[i];
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = list(map(int,readline().split()))

b = [0]*(n+1)
b[-1] = a[-1]
for i in range(n-1,-1,-1):
  b[i] = b[i+1]+a[i]
#print(b)
c = [1]*(n+1)
for i in range(n):
  c[i+1] = (c[i]-a[i])*2
#print(c)
ans = 0
for i in range(n+1):
  m = min(b[i],c[i])
  ans += m
  
if m < 0 or a[0] != 0 or c[-1] < a[-1]:
  ans = -1

if n == 0 and a[0] == 1:
  ans = 1
  
print(ans)

Measured memory_bytes: 679936
#include <iostream>

using namespace std;

void output(int n1, int n2, int n3) {
  cout << n1 << ' ' << n2 << ' ' << n3 << endl;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a < b) {
    if (b < c)      output(a, b, c);
    else if (a < c) output(a, c, b);
    else            output(c, a, b);
  } else {
    if (a < c)      output(b, a, c);
    else if (b < c) output(b, c, a);
    else            output(c, b, a);
  }

  return 0;
} 



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;

int main(){
  string s;
  int n;
  int count = 0;
  cin >> n;
  cin >> s;
  bool b1,b2,b3;
  for(int i1 = 0;i1<10;i1++){
    b2 = false;
    for(int i2 = 0;i2<10;i2++){
      for(int i3 = 0;i3<10;i3++){
        for(int i = 0; i < n;i++){
          if(b2 && ((char)(i3+48)==s[i])){
            count++;
            break;
          }
          if(b1 && ((char)(i2+48)==s[i])) b2 = true;
          if((char)(i1+48)==s[i]) b1 = true;
        }
        b1 = b2 = b3 = false;
      }
    }
  }
  cout << count;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int f, s, c = 0;
	bool an = false;
	for (int i = 0; i < n; i++) {
		cin >> f >> s;
		if (f == s) {
			c++;
			if (c == 3) {
				an = true;
				break;
			}
		}
		else {
			c = 0;
		}
	}
	if (an) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < 100; i++) {
    s = s.substr(1, 100) + s[0];
    if(s == t) return (cout << "Yes" << endl, 0);
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for i in range(1, len(c)):
    ss = c[i - 1][0] - c[i][0]
    for j in range(1, len(c[i])):
        if ss != c[i - 1][j] - c[i][j]:
            print('No')
            sys.exit(0)

for i in range(1, len(c[0])):
    ss = c[0][i - 1] - c[0][i]
    for j in range(1, len(c)):
        if ss != c[j][i - 1] - c[j][i]:
            print('No')
            sys.exit(0)
print('Yes')


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

char hand[100005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    ll ans = 0;
    rep(i,n){
        if(t[i] == 'r'){
            if(i-k < 0 || hand[i-k] != 'p'){
                hand[i] = 'p';
                ans += p;
            }
            else{
                hand[i] = '?';
            }
        }
        else if(t[i] == 's'){
            if(i-k < 0 || hand[i-k] != 'r'){
                hand[i] = 'r';
                ans += r;
            }
            else{
                hand[i] = '?';
            }
        }
        else{
            if(i-k < 0 || hand[i-k] != 's'){
                hand[i] = 's';
                ans += s;
            }
            else{
                hand[i] = '?';
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;

int digit(long n) {
	int ans = 1;
	while (n >= 10) {
		n = n / 10;
		ans++;
	}
	return ans;
}

int main() {
	long long n;
	int ans = 810;
	cin >> n;
	for (long i = 1; i < 100000; i++) {
		if (n%i == 0) {
			ans = min(max(digit(n / i), digit(i)), ans);
		}
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
first = 0
second = 0
third = 0
forth = 0
for i in range(3):
    p = input().split()
    a = p[0]
    if a == "1":first += 1
    if a == "2":second += 1
    if a == "3":third += 1
    if a == "4":forth += 1
    a = p[1]
    if a == "1":first += 1
    if a == "2":second += 1
    if a == "3":third += 1
    if a == "4":forth += 1
c = 0
if first % 2 == 1:c += 1
if second % 2 == 1:c += 1
if third % 2 == 1:c += 1
if forth % 2 == 1:c += 1
if c == 2 or c == 0:
    print("YES")
else:
    print("NO")

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

char m[1010][1010];
int dist[1010][1010];
int main() {
	int h,w;
	cin >> h >> w;
	rep(i,1010) rep(j,1010) dist[i][j] = -1;
	queue<P> q;
	rep(i,h) rep(j,w) {
		cin >> m[i][j];
		if (m[i][j] == '#') {
			q.push({i,j});
			dist[i][j] = 0;
		}
	}

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

	while (!q.empty())
	{
		int x=q.front().first, y=q.front().second;
		q.pop();
		rep(i,4) {
			int nx=x+dx[i], ny=y+dy[i];
			if (nx<0||nx>=h||ny<0||ny>=w) continue;
			if (m[nx][ny]=='#'||dist[nx][ny]!=-1) continue;
			
			dist[nx][ny] = dist[x][y] + 1;
			m[nx][ny] = '#';
			q.push({nx,ny});
		}
	}
	int ans = 0;
	rep(i,h) rep(j,w) ans = max(ans, dist[i][j]);
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n, k; cin >> n >> k;

    double tot = 0;
    rep3(i, 1, n){
        int ii = i;
        double p = 1.0;
        while(ii < k){
            ii *= 2;
            p /= 2.0;
        }
        tot += p;        
    }    

    tot /= n;
    cout << tot << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int main() {
  int a,b;
  string op;
  cin >> a >> op >> b;
  if (op == "+") {
    /* code */
    std::cout << a+b << '\n';
  }
  else{
    std::cout << a-b << '\n';
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i, m) cin >> a[i];

    int sum = 0;
    rep(i, m) sum += a[i];
    if (sum > n) {
        cout << -1 << endl;
    }
    else {
        cout << n - sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
///////////////////////

ld const PI = acos(-1.0);
int const N = 2e5 + 41;

int n;
vector<pii> p;
int x2, y2, x3, y3;

int getLIS(){
	vector<int> v;
	fr(i, 0, sz(p)){
		int l = -1;
		int r = sz(v);
		while(r-l>1){
			int m = (l+r)/2;
			if(v[m] > p[i].second) r = m;
			else l = m;
		}
		if(r == sz(v)) v.pb(p[i].second);
		else v[r] = p[i].second;
	}
	return sz(v);
}

void solve(){
	cin >> x2 >> y2 >> x3 >> y3;
	cin >> n;
	fr(i, 0, n){
		int x, y;
		cin >> x >> y;
		if(x >= min(x2, x3) && x <= max(x2, x3)){
			if(y >= min(y2, y3) && y <= max(y2, y3)){
				p.pb(mp(x, y));
			}
		}
	}

	sort(p.begin(), p.end());
	if( (x2 == min(x2, x3)) ^ (y2 == min(y2, y3)) ){
		reverse(p.begin(), p.end());
	}
	ld ans;
	ld dx = max(x2, x3) - min(x2, x3);
	ld dy = max(y2, y3) - min(y2, y3);
	ans = (dx + dy) * 100;
	int cnt = getLIS();
	ans -= cnt * 20.0;
	if(cnt == max(y2, y3) - min(y2, y3) + 1 || cnt == max(x2, x3) - min(x2, x3) + 1) ++cnt;
	ans += PI * 5 * cnt;

	printf("%.15Lf\n",ans);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();



	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <deque>
int main(){
    int n,m;
    std::cin>>n>>m;
    std::vector<std::unordered_map<int,std::vector<int>>> a(n+1);
    for(int i=0;i<m;i++){
        int p,q,c;
        std::cin>>p>>q>>c;
        a[p][c].push_back(q);
        a[q][c].push_back(p);
    }
    std::deque<std::tuple<int,int,int>> d;
    for(auto e:a[1])
        d.emplace_back(1,1,e.first);
    std::vector<std::unordered_set<int>> s(n+1);
    while(!d.empty()){
        int v=std::get<0>(d.front());
        int p=std::get<1>(d.front());
        int c=std::get<2>(d.front());
        d.pop_front();
        if(p==n){
            std::cout<<v<<std::endl;
            return 0;
        }
        if(s[p].count(c))
            continue;
        if(s[p].empty()){
            for(auto e:a[p]){
                if(e.first==c)
                    continue;
                for(int q:e.second)
                    d.emplace_back(v+1,q,e.first);
            }
        }
        for(int q:a[p][c])
            d.emplace_front(v,q,c);
        s[p].insert(c);
    }
    std::cout<<-1<<std::endl;
    return 0;
}

Measured memory_bytes: 61824
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

void chmax(ll &a,ll b){a = max(a,b) ;}

int main(){
	ll q ; cin >> q ;
	for(int tt=0;tt<q;tt++){
		string s,t ;
		cin >> s >> t ;
		vvll dp(s.size()+1,vll(t.size()+1,0)) ;
		for(int i=1;i<=s.size();i++){
			for(int j=1;j<=t.size();j++){
				chmax(dp.at(i).at(j),dp.at(i-1).at(j)) ;
				chmax(dp.at(i).at(j),dp.at(i).at(j-1)) ;
				if(s.at(i-1)==t.at(j-1)) chmax(dp.at(i).at(j),dp.at(i-1).at(j-1)+1) ;
			}
		}
		cout << dp.at(s.size()).at(t.size()) << endl ;
	}
}



Measured memory_bytes: 10828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		long A[] = new long[N];

		for (int i = 0; i < N; i++) {
			A[i] = scan.nextLong();
			if (A[i] == 0) {
				// 0が含まれてたら終了
				System.out.println(0);
				return;
			}
		}

		long ans = A[0];
		for (int i = 1; i < N; i++) {
			if (A[i] <= (1000000000000000000L / ans)) {
				ans *= A[i];
			} else {
				// 10の18乗超えた
				System.out.println(-1);
				return;
			}
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 49788
#include <bits/stdc++.h>
using namespace std;
#define si(x)       scanf("%d",&x)
#define su(x)       scanf("%u",&x)
#define sll(x)      scanf("%lld",&x)
#define sl(x)       scanf("%ld",&x)     
#define sc(x)       scanf("%c",&x)
#define ss(x)       scanf("%s",x)
#define sf(x)       scanf("%f",&x)
#define slf(x)      scanf("%lf",&x)
#define pri(x)      printf("%d\n",x)
#define prl(x)      printf("%lld\n",x)
#define ll          long long int
#define mod(x,n)    (x+n)%n
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define pll         pair<long long,long long>
#define pil         pair<int,long long>
#define pli         pair<long long,int>
#define vi          vector<int>
#define vl          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define M           1000000007
 
ll dis[250][250];
int rarr[10];
int n,m,r; 
ll ans;

void compute(int*p,int k){
	if(k==r){
		ll cost=0;
		for(int i=1;i<r;i++) cost+=(dis[rarr[p[i]]][rarr[p[i+1]]]);
		ans=min(ans,cost);
	}
	else{
		for(int i=1;i<=r;i++){
			swap(p[k],p[i]);
			compute(p,k+1);
			swap(p[k],p[i]);
		}
	}
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	si(n); si(m); si(r);
	for(int i=1;i<=r;i++) si(rarr[i]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j) dis[i][j]=0;
			else dis[i][j]=1e17;
		}
	}
	for(int i=1;i<=m;i++){
		int temp1,temp2,temp3; si(temp1); si(temp2); si(temp3);
		 dis[temp1][temp2]=temp3; dis[temp2][temp1]=temp3;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(dis[i][j]>(dis[i][k]+dis[k][j])) dis[i][j]=dis[i][k]+dis[k][j];
			}
		}
	}
	ans=1e17;
	int p[10];
	for(int i=1;i<=r;i++) p[i]=i;
	compute(p,1);
	prl(ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//printf("%.12lf\n",mid);
//const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2))));
/*
// get part of decimal
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
const long long mod = 1000000007;
const double eps = .0000000001;
inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};

int main(){
    prep();
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int cnt = 0;
    for (int i=0; i<n; i++){
      if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]){
        cnt += 2;
      }else if (a[i] == b[i] && a[i] == c[i]){
        
      }else{
        cnt++;
      }
    }
    cout << cnt;
    return 0;
}      

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

int main() {
  int N;
  string S;
  bool p, w, g, y;
  
  cin >> N;
  
  for (int i=0; i<N; i++) {
    cin >> S;
    if (p=(S=="P")||p);
    if (w=(S=="W")||w);
    if (g=(S=="G")||g);
    if (y=(S=="Y")||y);
  }
  if ( p && w && g && y ) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
//
// Created by user on 3/9/2020.
//
#include <bits/stdc++.h>
//#define endl '\n'
using namespace std;

int main() {
    ios_base :: sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;

    for (int i = 1; i <= 10000; ++i) {
        cerr << i << " " << (int)(i * 0.08) << " " << (int)(i * 0.1) << endl;
        if ( (int)(i * 0.08) == a and (int)(i * 0.1) == b) {
            cout << i;
            return 0;
        }
    }
    cout << -1;

}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

static MODC:u64 = 1000000007;
fn powm(xx:u64, yy:u32) -> u64 {
    let mut x = xx;
    let mut y = yy;
    let mut result = 1;
    while y > 0 {
        if y & 1 != 0 {
            result *= x;
            result %= MODC;
        }
        x *= x;
        x %= MODC;
        y >>= 1;
    }
    result
}

fn main() {
    input! {
        n: usize,
        o: [i32; n],
    }

    let n1:u64 = (n-1)as u64;
    let mut cy: u64 = 0;
    let mut g: Vec<Vec<usize>> = Vec::new();
    let mut r = vec![-1;n];
    let mut u: Vec<usize> = Vec::new();
    for i in 0..n {
        if o[i] < 0 {
            u.push(i);
        } else {
            let e = (o[i]-1) as usize;
            if r[i] < 0 {
                if r[e] < 0 {
                    r[i] = g.len() as i32;
                    r[e] = g.len() as i32;
                    g.push(vec![i,e]);
                } else {
                    r[i] = r[e];
                    g[r[e] as usize].push(i);
                }
            } else if r[e] < 0 {
                r[e] = r[i];
                g[r[i] as usize].push(e);
            } else if r[i] != r[e] {
                let t = if r[i] < r[e] {r[i]} else {r[e]};
                let a = if r[i] < r[e] {r[e]} else {r[i]};
                for c in 0..n {
                    if r[c] == a {
                        r[c] = t;
                    } else if r[c] > a {
                        r[c] -= 1;
                    }
                }
                let mut v = g.remove(a as usize);
                g[t as usize].append(&mut v);
            } else {
                cy += 1;
            }
        }
    }
    //p [g,r,u]
    let mut ans:u64 = 0;
    let k = u.len();
    if k != 0 {
        let mut s : Vec<usize> = vec![0; k];
        for i in 0..k {
            if r[u[i]] < 0 {
                s[i] = 1;
            }
            else {
                s[i] = g[r[u[i]] as usize].len();
                //g.remove_item(r[u[i]]);
            }
        }
        let mut dp : Vec<u64> = vec![0; k];
        for e in s.iter() {
            let mut i = k;
            while i > 0 {
                i -= 1;
                if i == 0 {
                    dp[i] += *e as u64;
                }
                else {
                    dp[i] += dp[i-1] * (*e as u64);
                }
                dp[i] %= MODC;
            }
        }
        dp[0] -= s.len() as u64;
        let mut fact:u64 = 1;
        for i in 0..k {
            if i > 0 { fact = fact * (i as u64) % MODC; }
            ans += dp[i] * fact % MODC * powm(n1,(k-i-1) as u32) % MODC;
            ans %= MODC;
        }
    }
    ans += cy * powm(n1, k as u32);
    ans %= MODC;
    ans = n as u64 * powm(n1, k as u32) + MODC - ans;
    ans %= MODC;
    println!("{}", ans);
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K, x=0;
  cin >> N >> K;
  vector<int> p(N);
  for(int i=0;i<N;i++) {
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  for(int i=0;i<K;i++) {
    x += p.at(i);
  }
  cout << x << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();
    	int M=sc.nextInt();
    	int K=sc.nextInt();

    	int num=0;
    	for(int k=0;k<=N;k++) {
    		for(int l=0;l<=M;l++) {

    			num=k*(M-l)+l*(N-k);

    			if(num==K) {
    				System.out.println("Yes");
    				return;
    			}

    		}
    	}

    	System.out.println("No");

    }

}



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

int main(){
 int N;
 double ans = 0.0, A;
 cin >> N;
 for(int i = 1; i <= N; ++i){
 cin >> A;
 ans += 1.0 / A;
 }
 ans = 1.0 / ans;
 cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 3780
k, n = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)

a << a[0] + k
dist = []
for i in 0...n do
  dist << a[i+1] - a[i]
end

dist.sort!.reverse!.shift
print(dist.reduce(:+), "\n")


Measured memory_bytes: 20608
using System;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().ToCharArray();
            var a = int.Parse(_[0].ToString());
            var b = int.Parse(_[1].ToString());
            var c = int.Parse(_[2].ToString());
            var d = int.Parse(_[3].ToString());

            var op = new string[]{"+", "-"};
            for(var i = 0; i < 2; i++){
                for(var j = 0; j < 2; j++){
                    for(var k = 0; k < 2; k++){
                        var x = Calc(a, b, op[i]);
                        var y = Calc(x, c, op[j]);                        
                        var z = Calc(y, d, op[k]);   

                        if(z == 7){
                            Console.WriteLine(
                                string.Format("{0}{1}{2}{3}{4}{5}{6}=7"
                                ,a,op[i],b,op[j],c,op[k],d));
                                return;
                        }                     
                    }
                }
            }

            Console.WriteLine("Hello World!");
        }

        static int Calc(int x, int y, string op){
            if(op.Equals("+")){
                return x + y;
            }else{
                return x - y;
            }
        }
    }
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;

    if(s.at(0)==s.at(1) && s.at(2)==s.at(3) && s.at(0)!=s.at(2) ||
    s.at(0)==s.at(2) && s.at(1)==s.at(3) && s.at(0)!=s.at(1) ||
    s.at(0)==s.at(3) && s.at(1)==s.at(2) && s.at(0)!=s.at(1))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define inf 9223372036854775807
#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#define spd  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ll h,w,m,i,hi,wi,r,c,mxr=0,ans=0,mxc=0;

    cin>>h>>w>>m;

    map<ll,ll>row,col;
    map<ll,map<ll,ll>>mp;
    vector<ll>vr,vc;

    for(i=0;i<m;i++)
    {
        cin>>hi>>wi;
        mp[hi][wi] = 1;
        row[hi]++;
        col[wi]++;
    }

    for(i=1;i<=h;i++)
    {
        if(row[i]>mxr)
        {
            mxr = row[i];

            r = i;
        }
    }


    for(i=1;i<=w;i++)
    {
        if(col[i]>mxc)
        {
            mxc = col[i];
            c = i;
        }
    }

    for(i=1;i<=h;i++)
    {
        if(mxr==row[i])
        {
            vr.push_back(i);
        }
    }

    for(i=1;i<=w;i++)
    {
        if(mxc==col[i])
        {
            vc.push_back(i);
        }
    }

    for(i=0;i<vr.size();i++)
    {
        for(int j=0;j<vc.size();j++)
        {
            if(!mp[vr[i]][vc[j]])
            {
               cout<<mxr+mxc<<endl;
               return 0;
            }
        }
    }

    cout<<mxr+mxc-1<<endl;
}


Measured memory_bytes: 95936
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N, bp,pp, b, p, sum1, sum2, ans;
  while(cin >> N) {
    while(N--){
      cin >> bp >> pp >> b >> p;
      sum1 = bp*b + pp*p;
      sum2 = (bp*max(5, b) + pp*max(2, p))*80/100;
      ans = min(sum1, sum2);	
      cout << (int)ans << endl;
      
    }
  }
  
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
using namespace std;
vector<int> gr[11000];
vector<int> igr[11000];
vector<int> ban;

int v,e;
int visit[11000]={0},gro[11000]={0};

void dfs(int i){
	if(visit[i]==0){
		visit[i]=1;
		for(int k=0;k<gr[i].size();k++) dfs(gr[i][k]);
		ban.push_back(i);
	}
}

void idfs(int i,int h){
	if(visit[i]==0){
		visit[i]=1;
		gro[i]=h;
		for(int k=0;k<igr[i].size();k++) idfs(igr[i][k],h);
	}
}

void kyouren(){
	for(int i=0;i<v;i++){
		dfs(i);
	}
	for(int i=0;i<v;i++) visit[i]=0;
	for(int i=v-1;i>=0;i--){
		idfs(ban[i],ban[i]);
	}


}




int main(){
int s,t,q,aa,aaa;
cin>>v>>e;
for(int i=0;i<e;i++){
cin>>s>>t;
gr[s].push_back(t);
igr[t].push_back(s);
}
kyouren();
cin>>q;
for(int i=0;i<q;i++){
cin>>aa>>aaa;
if(gro[aa]==gro[aaa]) cout<<"1"<<endl;
else cout<<"0"<<endl;
}


return 0;
}

Measured memory_bytes: 2856
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a, b;
        a = scan.nextInt();
        b = scan.nextInt();

        System.out.printf("%d %d %.10f\n", a / b, a % b, (double) a / (double) b);

    }
}


Measured memory_bytes: 26632
#include <iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

struct point{
  int x,y,b=0;
};

bool cmp2(point p,point q){
  return p.x<q.x ;
}

bool cmp3(point p,point q){
  return p.y<q.y ;
}

point red[200],blue[200];
int chk[200],n,tmp;

int solve(){
  int ans=0;
  for(int i=0;i<n;i++){
    chk[i] = 0;
  }

  for(int i=n-1;i>=0;i--){
    tmp=-1;
    for(int j=0;j<n;j++){
      if(blue[j].x>red[i].x&&blue[j].y>red[i].y&&!chk[j]){
        ans++;
        chk[j]=1;
        break;
      }
    }
  }
  return ans;
}

int main() {
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&red[i].x,&red[i].y);
  }
  for(int i=0;i<n;i++){
    scanf("%d%d",&blue[i].x,&blue[i].y);
    
    for(int j=0;j<n;j++){
      if(blue[i].x>red[j].x&&blue[i].y>red[j].y)
        red[j].b++;
        blue[j].b++;
    }
  }
  int ans=0;
  sort(red,red+n,cmp3);
  sort(blue,blue+n,cmp2);
  ans = max(ans,solve());
  printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w,a[10][10],sum,x;
int main(){
  cin>>h>>w;
  r(i,10)r(j,10)cin>>a[i][j];
  r(o,10)r(i,10)r(j,10)a[i][j]=min(a[i][j],a[i][o]+a[o][j]);
  r(i,h)r(j,w){
    cin>>x;
    if(x!=-1)sum+=a[x][1];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
s = gets.chomp.split("")
if s[k-1] == "A"
  s[k-1] = "a"
elsif s[k-1] == "B"
  s[k-1] = "b"
elsif s[k-1] == "C"
  s[k-1] = "c"
end
puts s.join

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int d[k];
    int sunuke[n];
  	for(int i=0; i<n; i++){
		sunuke[i]=0;	
    }
    for(int i=0; i<k; i++){
        cin >> d[i];
        int a;
        for(int j=0; j<d[i]; j++){
            cin >> a;
            sunuke[a-1]++;   
        }
    }
    int count = 0;
    for(int i=0; i<n; i++){
        if(sunuke[i] == 0) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>

int number_a[105][105],number_b[10050];

int main()
{
    int h,m;
    while(scanf("%d %d",&h,&m)!=EOF)
    {
        int i,j,t,k=0;
        scanf("%d",&t);
        for(i=0; i<t; i++)
            scanf("%d",&number_b[i]);
        for(i=0; i<h; i++)
        {
            if(i%2==0)
                for(j=0; j<m; j++)
                {
                    number_a[i][j]=k+1;
                    number_b[k]--;
                    if(number_b[k]==0)
                        k++;
                }
            if(i%2==1)
                for(j=m-1; j>=0; j--)
                {
                    number_a[i][j]=k+1;
                    number_b[k]--;
                    if(number_b[k]==0)
                        k++;
                }
        }
        for(i=0; i<h; i++)
        {
            for(j=0; j<m-1; j++)
                printf("%d ",number_a[i][j]);
            printf("%d\n",number_a[i][m-1]);
        }
    }
}


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

using namespace std;
typedef long long ll;

queue<int> defeat[100001];
priority_queue<int> dp[100001];
int a[100001];

int dfs(int p) {
    if(defeat[p].empty()) return 0;

    while(!defeat[p].empty()) {
        dp[p].push(dfs(defeat[p].front()));
        defeat[p].pop();
    }

    int res = -1;
    for(int i=1; !dp[p].empty(); i++) {
        res = max(res, dp[p].top() + i);
        dp[p].pop();
    }

    return res;
}

int main(void) {
    int N;
    scanf("%d", &N);
    for(int i=2; i<=N; i++) {
        int winner;
        scanf("%d", &winner);
        defeat[winner].push(i);
    }

    return !printf("%d\n", dfs(1));
}

Measured memory_bytes: 79872
N = int(input())
S, T = input().split()

Slist = []
Tlist = []
result= []

for c in S:
    Slist.append(c)
for c in T:
    Tlist.append(c)

for i in list(range(N)):
    result.append(Slist[i])
    result.append(Tlist[i])

s = "".join(result)

print(s)

Measured memory_bytes: 3060
#include<stdio.h>

#define MAX 200000
#define SENTINEL 1200000000

typedef long long hyper;
hyper cnt = 0;

void Merge(int* A, int left, int mid, int right)
{
    int L[MAX], R[MAX];
    int i, j, k, n1, n2;
    n1 = mid - left;
    n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[i + left];
    for(j = 0; j < n2; j++) R[j] = A[j + mid];

    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    i = j = 0;

    // sorting.
    for(k = left; k < right; k++){

        if(L[i] <= R[j]){ A[k] = L[i]; i++; }

        else{ A[k] = R[j]; j++; cnt = cnt + n1 - i; } // add n1 - i.
    }
}

void MergeSort(int* A, int left, int right)
{
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
}

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

    MergeSort(A, 0, n);
    printf("%lld\n", cnt);

    return 0;
}

Measured memory_bytes: 2596
until (n = gets.to_i).zero?
  student = n.times.map{gets.split.map(&:to_i)}
  student.map! do |d, v| [d / d.gcd(v), v / d.gcd(v)] end
  lcm = 1
  gcd = student[0][1]
  student.each do |d, v|
    lcm = lcm.lcm(d)
    gcd = gcd.gcd(v)
  end
  puts student.map{|d, v| lcm * v / d / gcd}
end

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

int main(){
  string Sa,T,S;
  cin>>Sa>>T;
  vector<string> ass;
  int ss=Sa.size();
  int ts=T.size();
  for(int i=0;i<=ss-ts;i++){
    bool jd=false;
    S=Sa;
    for(int j=0;j<ts;j++){
      if(Sa[i+j]!=T[j] && Sa[i+j]!='?'){
        jd=true;
        break;
      }
    }
    if(jd) continue;
    for(int j=0;j<ts;j++){
      S[i+j]=T[j];
    }
    for(int j=0;j<ss;j++){
      if(S[j]=='?')
        S[j]='a';
    }
    ass.push_back(S);
  }
  if(ass.empty()){
    cout<<"UNRESTORABLE"<<endl;
  }else{
    sort(ass.begin(),ass.end());
    cout<<ass[0]<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
LL n;
inline LL calc(LL n){
	LL res = 0; n /= 5;
	while(n){
		res += n; n /= 5;
	}
	return res;
}
int main(){
	scanf("%lld", &n);
	if(n & 1) puts("0");
	else printf("%lld\n", calc(n >> 1));
}

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

using namespace std;


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

int main() {

	int n;
	cin >> n;

	vector<int> v;

	const int m = 300000;
	vector<pair<int, int>> s0(m, pair<int, int>(0, 0));
	vector<pair<int, int>> s1(m, pair<int, int>(0, 0));
	rep(i, m) {
		s0[i].second = i;
		s1[i].second = i;
	}

	rep(i, n) {
		int t;
		cin >> t;
		v.push_back(t);

		if (i % 2) {
			s0[t].first++;
		} else {
			s1[t].first++;
		}
	}

	sort(s0.begin(), s0.end());
	reverse(s0.begin(), s0.end());
	sort(s1.begin(), s1.end());
	reverse(s1.begin(), s1.end());

	vector<int> q;
	rep(i, 2) {
		if(s0[i].first) {
			q.push_back(s0[i].second);
		}
		if(s1[i].first) {
			q.push_back(s1[i].second);
		}
	}

	int ans = 1e9;


	rep(j, q.size()) rep(k, q.size()) if(j != k){

			int s00c = 0, s10c = 0;
			int s01c = 0, s11c = 0;
			int s0oc = 0, s1oc = 0;
		rep(i, n) {
			if (i % 2 == 0) {
				if (v[i] == q[j]) {
					s00c++;
				} else
				if (v[i] == q[k]) {
					s01c++;
				} else {
					s0oc++;
				}
			}
			else {
				if (v[i] == q[j]) {
					s10c++;
				} else
				if (v[i] == q[k]) {
					s11c++;
				} else {
					s1oc++;
				}
			}

		}

			ans = min({ans, s01c + s0oc + s10c + s1oc,  s11c + s1oc + s00c + s0oc});
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 5628
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  long long a;
  cin>>a;
  cout<<"ABC"<<a<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const LL mod=998244353;
const int inf=1e9;
const double INF=1e9;
const int maxn=120;
int min(int a,int b) {return a<b?a:b;}
int main()
{
    int n,m;
    int vis[40];
    scanf("%d%d",&n,&m);
    mem(vis,0);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int k;
        scanf("%d",&k);
        for(int j=1;j<=k;j++)
        {
            int x;
            scanf("%d",&x);
            vis[x]++;
            if(vis[x]==n) ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
I = list(map(int, input().split()))
b = 0
for m in range(0, I[0] + 1):
    if b == 1:
        break
    for g in range(0, I[0] + 1 - m):
        s = I[0] - m - g
        if b == 1:
            break
        elif 10000 * m + 5000 * g + 1000 * s == I[1]:
            print("{} {} {}".format(m, g, s))
            b = 1
            break
if b == 0:
    print("-1 -1 -1")

Measured memory_bytes: 3064