akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, string>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

string solve(string& a, string& b){
    P p1(a.size(), a);
    P p2(b.size(), b);
    if(p1 == p2){
        return "EQUAL";
    }else if(p1 > p2){
        return "GREATER";
    }else{
        return "LESS";
    }
}


int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string a, b;
    cin >> a >> b;
    cout << solve(a, b) << "\n";

    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        d: [(i64, i64); n],
    };
    let mut p = vec![(0, 0), (0, 0)];
    p[0] = d[0];
    p[1] = d[1];
    for &(d_i_1, d_i_2) in d.iter().skip(2) {
        if p[0].0 == p[0].1 && p[1].0 == p[1].1 && d_i_1 == d_i_2 {
            println!("Yes");
            return;
        }
        p[0] = p[1];
        p[1] = (d_i_1, d_i_2);
    }
    println!("No");
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<climits>
#include<set>
#include<map>
#include<stack>
#define ll long long
using namespace std;

int main() {
    ll n,T,sum=0;
    cin>>n>>T;
    vector<ll>t(n);
    cin>>t[0];
    for(ll i=1;i<n;i++){
        cin>>t[i];
        if(t[i]-t[i-1]<T){
            sum+=t[i]-t[i-1];
        }
        else{
            sum+=T;
            //cout<<"0"<<endl;
        }
    }
    sum+=T;
    cout<<sum<<endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // number of vertexes
    int N; cin >> N;

    // input graph
    Graph G(N);
    vector<int> deg(N, 0);
    for (int i = 0; i < N; ++i) {
        int a, b; cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
        ++deg[a], ++deg[b];
    }

    // insert leaves into queue
    queue<int> que;
    for (int v = 0; v < N; ++v) if (deg[v] == 1) que.push(v);

    // explore
    vector<bool> ispushed(N, false);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        ispushed[v] = true;
        for (auto nv : G[v]) {
            --deg[nv];
            if (deg[nv] == 1) que.push(nv);
        }
    }

    // answer to query
    int Q; cin >> Q;
    for (int _ = 0; _ < Q; ++_) {
        int a, b; cin >> a >> b; --a, --b;
        if (!ispushed[a] && !ispushed[b]) cout << 2 << endl;
        else cout << 1 << endl;
    }
}


Measured memory_bytes: 8612
#include<iostream>
#define Number 1000000
using namespace std;
int main(){
  int n;
  int table[Number]={0};
  for(int i=2;i<Number;i++){
    if(table[i]==0){
      for(int j=2*i;j<Number;j+=i){
	table[j]=1;
      }
    }
    table[i]=(table[i]?0:1)+table[i-1];
  }
  while(cin>>n){
    cout<<table[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5072
#include<stdio.h>
int main()
{
  int i,arr[3],temp=0,j,k;
  for(i=0;i<3;i++){
  scanf("%d",&arr[i]);
  }
  scanf("%d",&k);
  for(i=0;i<3;i++){
  if(arr[i]>temp){
   temp=arr[i];
    j=i;
  }
  }
  for(i=0;i<k;i++){
   temp=temp*2;
  }
  arr[j]=temp;
  k=arr[0]+arr[1]+arr[2];
  printf("%d",k);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  if(s[0] == s[2])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000

typedef struct{
  int p,l,r;
}Node;

Node tree[MAX];

int n;

void pre(int u){
  if(u==-1) return;

  printf(" %d",u);

  pre(tree[u].l);
  pre(tree[u].r);
}

void in(int u){
  if(u==-1) return;

  in(tree[u].l);

  printf(" %d",u);

  in(tree[u].r);
}

void post(int u){
  if(u==-1) return;

  post(tree[u].l);
  post(tree[u].r);

  printf(" %d",u);
}

int main(){

  int i,v,l,r,root;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    tree[i].p=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);

    tree[v].l=l;
    tree[v].r=r;

    if(l!=-1){
      tree[l].p=v;
    }
    if(r!=-1){
      tree[r].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(tree[i].p==-1){
      root=i;
    }
  }
  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 616
N = int(input())
A = [int(i) - 1 for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
pre = -2
for a in A:
    ans += B[a]
    if pre == a - 1:
        ans += C[pre]
    pre = a

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 10000007

typedef  long long ll;

using namespace std;

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

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  
  return i;
}
bool judge(string s){
  bool ret = false;
  string t = s;
  reverse(t.begin(), t.end());
  if(s == t){
    ret = true;
  }
  return ret;
}

//map<ll,ll> m;
void solve(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b;
}


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


Measured memory_bytes: 256
// unihernandez22
// https://atcoder.jp/contests/abc126/tasks/abc126_a
// implementation

import std.stdio: writeln, readf, readln;
import std.string: chomp;
import std.ascii: toLower;

void main() {
	int n, k;
	"%d %d\n".readf(&n, &k);

	char[] s = readln.chomp.dup;

	s[k-1] = s[k-1].toLower;

	s.writeln;
}


Measured memory_bytes: 3164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int N, i, digisum=0;
  scanf("%d%d%d", &N);
  
  for(i=10;;i=i*10){
    digisum+=(N%i)/(i/10);
    if(N/i==0)break;
  }
  
  if(N%digisum)
    printf("No\n");
  else
    printf("Yes\n");
  
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	double v;
	while( cin >> v ){
		double t = v / 9.8;
		double y = 4.9 * t * t;
		int N = 1;
		while(1){
			if( (5 * N - 5) > y) break;
			N++;
		}
		cout << N << endl;
	}
}

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

int a, b, c, x, ans = 0;

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

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			int num = 500 * i + 100 * j;
			if (x - num >= 0 && c * 50 >= x - num){
				ans++;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll X, N;
  cin >> X >> N;

  map<ll, bool> ok;
  REP(i, -210, 210){
    ok[i] = true;
  }

  rep(i, N){
    ok[il()] = false;
  }

  rep(i, 150){
    if (ok[X-i]){
      cout << X-i << endl;
      return 0;
    }
    else if (ok[X+i]){
      cout << X+i << endl;
      return 0;
    }
  }





}

Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


signed main()
{
	std::cin.sync_with_stdio(false);
	std::cin.tie(0);

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

	if (a + b == 15) {
		cout << "+" << endl;
	}
	else if (a*b == 15) {
		cout << "*" << endl;
	}
	else {
		cout << "x" << endl;
	}




	return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
s=input()
c=0
d=0
for i in range(n):
  if s[i]=='a':
    if c+d<a+b:
      print('Yes')
      c+=1
    else:
      print('No')
  elif s[i]=='b':
    if c+d<a+b and d<b:
      print('Yes')
      d+=1
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 9312
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) cin >> s[i];

	for (int i = 0; i < (w + 2); i++)cout << "#";
	cout << "\n";
	for (int i = 0; i < h; i++) {
		cout << "#" << s[i] << "#" << "\n";
	}
	for (int i = 0; i < (w + 2); i++)cout << "#";
	return 0;
}

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

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define endl '\n'
#define EPS 1e-9
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SQ(a) (a)*(a)
#define debg(x) cout<<#x<<' '<<x<<endl;
#define INF 10e9 + 7
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
typedef long double ld;
#define REP(i, a, b) for(ll i=a; i<b; ++i)

using namespace std;

int count_ones(int n){
	int ans = 0;
	while(n){
		if(n&1)
			ans++;
		n>>=1;
	}
	return ans;
}

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

bool is_coprime(ull a, ull b){
	if(gcd(a, b) == 1)
		return true;
	return false;
}

void print_vector_pair(auto &inv){
	for(auto x: inv)
		cout<<x.F<<' '<<x.S<<endl;
	cout<<endl;
}

void print_vector(auto &inv){
	for(auto x: inv)
		cout<<x<<' ';
	cout<<endl;
}

void print_vector_vector(auto sorted_by_x){
	for(auto x: sorted_by_x){
		for(auto i: x)
			cout<<i<<' ';
		cout<<endl;
	}
	
}

bool chk(auto a, auto b){
	int s = a.size();
	bool res = true;
	for(int i=0; i<s; ++i){
		if(a[i] != b[i])
			res = false;
	}
	return !res;
}

typedef struct cord{
	int x, y;
}cord;

long double dist(cord pt1, cord pt2){
	long double x = abs(pt1.x - pt2.x);
	long double y = abs(pt1.y - pt2.y);
	return sqrt((x*x*(ld)1) + (y*y*(ld)1));
}

std::vector<bool> v(10000000);

void sieve(){
	for(ll i=0; i<10000000; ++i)
		v[i] = true;	
	v[0] = false;
	v[1] = false;
	
	for(ll i=4; i<10000000; i+=2)
		v[i] = false;

	for(ll i=3; i<10000000; i+=2){
		if(v[i]){
			for(ll j=(2*i); j<10000000; j+=i)
				v[j] = false;
		}
	}

}

ull fact(int n){
	ull f[n+1] = {0};
	f[0] = 1;
	for(int i=1; i<=n; ++i){
		f[i] = i*f[i-1];
	}
	return f[n];
}

ull ncr(ull n, ull r){
	return ((ull)fact(n) / ((ull)fact(r) * (ull)(fact(n-r))));
}

ull choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

ll binpow_without_recursion(ll a, ll b){ // faster than previous
	ll res = 1;
	while(b){
		if(b&1)
			res = res*a;
		a *= a;
		b >>= 1;
	}
	return res;
}
	
ll f(int l, int r, std::vector<ll> &a, std::vector<ll> &b){
	ll mul = 0;
	for(int i=l; i<=r; ++i)
		mul += a[i]*b[i];
	return mul;
}


int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//fast;
	int n, k;
	cin>>n>>k;
	vi a(n, 0);
	vi dp(n, INF);
	dp[0] = 0;
	REP(i, 0, n)	cin>>a[i];
	for(int i=0; i<n; ++i){
		for(int j=i+1; j<=(i+k); ++j){
			if(j >= n)
				break;

			dp[j] = min(dp[j], abs(a[i] - a[j]) + dp[i]);
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}



Measured memory_bytes: 2304
# ABC140 B

def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    satisfaction = 0

    for i in range(n):
        satisfaction += B[A[i] - 1]
        if 0 < i < n and A[i] == A[i-1] + 1:
            satisfaction += C[A[i]-2]
    
    print(satisfaction)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
tot = sum(A)
Q = int(input())
for i in range(Q):
    f, t = map(int, input().split())
    dis = t - f
    num = c[f]
    tot += num * dis
    print(tot)
    c[f] = 0
    if t in c:
        c[t] = c[t] + num
    else:
        c[t] = num

Measured memory_bytes: 24252
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int W = stdin.nextInt();
    int H = stdin.nextInt();
    int x = stdin.nextInt();
    int y = stdin.nextInt();
    int r = stdin.nextInt();

    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

}

Measured memory_bytes: 17332
#include<stdio.h>

int main(){
  char s[4];
  int check_a = 0, check_b = 0, check_c = 0, i;
  
  scanf("%s", s);
  for (i = 0; i < 3; i++){
    if(s[i] == 'a'){
      check_a = 1;
    }
    if(s[i] == 'b'){
      check_b = 1;
    }
    if(s[i] == 'c'){
      check_c = 1;
    }
  }
    
    if(check_a == 1 && check_b == 1 && check_c == 1){
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }

Measured memory_bytes: 128
n=int(input())
s=input()
m=i=d=n//2
a=0
for _ in range(m):
    left=set(s[:i])
    right=set(s[i:])
    b=len(left&right)
    if a<b:
        a=b
    left=set(s[:d])
    right=set(s[d:])
    b=len(left&right)
    if a<b:
        a=b
    i=i+1
    d=d-1
print(a)

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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


main(){
	ll n,h,w;
	cin >> n >> h >> w;
	int ans = 0;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		if(a>=h && b>=w){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int xkaisu(int n){
  int x = 0;
  while(n>=9){
    x += n%9;
    n /=9;
  }
  x += n;
  return x;
}
int kaisu(int n){
  int x = 0;
  while(n>=6){
    x += n%6;
    n /=6;
  }
  x += n;
  return x;
}




int main(void){
  int N;
  scanf("%d",&N);
  int min = N;
  for(int i=0;i<=N;i++){
    int x=0;
    x +=xkaisu(i);
    x +=kaisu(N-i);
    if(x<min){
      min = x;
    }
  }
  printf("%d",min);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
int main(int argc, const char * argv[]) {
    double r, S, L ,t ;
    scanf("%lf",&r);
    t = 3.141592653589;
    S=t*r*r;
    L=2*t*r;
    printf("%f %f\n",S,L);
    
    // insert code here...
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int A[16];
    int x[16][16];
    int y[16][16];
    REP(i,N){
        cin>>A[i];
        REP(j,A[i]){
            cin>>x[i][j]>>y[i][j];
        }
    }
    int ans;ans=0;
    REP(bit,1<<N){
        bool f;
        f=true;
        REP(j,N){
            if(bit&(1<<j)){
                REP(k,A[j]){
                    if(y[j][k]!=(1&(bit>>(x[j][k]-1)))){
                        f=false;
                        break;
                    }
                }
            }
        }
        if(f)ans=max(ans,counter(bit));
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int M1,D1;
	cin >> M1 >> D1;
	int M2, D2;
	cin >> M2 >> D2;

	if (M1 + 1 == M2 && D2 == 1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M,sum=0;
  cin>>N>>M;
  vector<int>vec(M);
  for(int i=0;i<N;i++){
    int K;
    cin>>K;
    for(int j=0;j<K;j++){
      int A;
      cin>>A;
      vec.at(A-1)++;
    }   
  }
  for(int i=0;i<M;i++){
    if(vec.at(i)==N)sum++;
    else continue;
  }
  cout<<sum<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a[3];
  rep(i, 3) cin >> a[i];

  sort(a, a+3);

  cout << a[2] - a[0] << endl;

  return 0;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

int n,m;
long long ans;

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> n >> m;
    n++ , m++;
    ans = n*m;
    ans -= 2*m + 2*(n-2);
    cout << ans;
}


Measured memory_bytes: 256
def main
  ball_num = gets.chomp.to_i
  return 1 if ball_num == 1
  
  ball_position = []
  ball_diff_info = []
  ball_num.times { |_i| ball_position << gets.chomp.split(' ').map(&:to_i) }
  
  ball_position.each_with_index do |(x,y),idx|
    ball_position_2 = ball_position.dup
    ball_position_2.delete_at(idx)
    
    ball_position_2.each do |a,b|
      ball_diff_info << [a-x, b-y]
    end
  end
  
  cost_zero_num = ball_diff_info.group_by{|e| e}.sort_by{|k,v| -v.size}.first.last.size
  
  ball_num - cost_zero_num
end

puts main

Measured memory_bytes: 3960
input = gets
a = input.split(' ')[0].to_i
b = input.split(' ')[1].to_i
c = input.split(' ')[2].to_i
input = gets
k = input.to_i

arr = [a, b, c]

while k > 0
  max = arr.max
  idx = arr.find_index(max)
  arr[idx] = max * 2
  k = k - 1
end

p arr.inject(0) {|sum, x| sum = sum + x }

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>

#define pb push_back

using namespace std;

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

struct node
{
	int x;
	int y;
	int dis;
};

int kyori(node a,node b)
{
	return abs(a.x-b.x)+abs(a.y-b.y);
}

int main(void)
{
	int w,h;
	string s;
	int i1,i2,i3;
	int gx,gy;
	int temp;
	int maxx;
	node n;

	while(1){
		cin>>w>>h;
		if(w+h==0) break;

		vector<node> v[3000];
		maxx=0;

		for(i1=0;i1<h;i1++){
			for(i2=0;i2<w;i2++){
				cin>>s;
				if(s==".") {}
				else if(s=="S") {
					n.x=i2;
					n.y=i1;
					n.dis=0;
					v[0].pb(n);
				}
				else if(s=="G") {
					gx=i2;
					gy=i1;
				}
				else {
					istringstream istr(s);
					istr>>temp;
					n.x=i2;
					n.y=i1;
					n.dis=100000;
					v[temp].pb(n);
					if(maxx<temp) maxx=temp;
				}
			} 
		}
		n.x=gx;
		n.y=gy;
		n.dis=100000;
		v[maxx+1].pb(n);

		for(i1=1;i1<=maxx+1;i1++){
			for(i3=0;i3<v[i1].size();i3++){
				for(i2=0;i2<v[i1-1].size();i2++){
					v[i1][i3].dis=min(v[i1][i3].dis,kyori(v[i1-1][i2],v[i1][i3])+v[i1-1][i2].dis);
					
				}
				//cout<<i1<<" "<<i3<<"     "<<v[i1][i3].x<<" "<<v[i1][i3].y<<" "<<v[i1][i3].dis<<endl;
			}
		}
		cout<<v[maxx+1][0].dis<<endl;


	}
	return 0;

} 

Measured memory_bytes: 1428
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for h in range(H):
        for w in range(W):
            if (h + w) % 2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
 
 
int main(void)
{
  int n;
  cin>>n;
  ll ans = 1;
  bool ng = 0;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    if(a == 0){
    	cout << 0 << endl;
    	return 0;
    }
    // (a*ans > INF) -> NG
    // INF/a == (INF - INF%a) / a

    if(ans > (INF/a)) {
    	ng = 1;
    }
    ans *= a;
  }
  if(ng)ans=-1;
  cout << ans << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    double a, b, x;
    cin >> a >> b >> x;

    x /= a;

    double p=3.14159265358979;



    double ans = atan2(0.5 * a * a, (a * b - x));

    if(ans<atan2(a, b)){
        ans = 0.5*p-atan2(2 * x, b * b);
    } else {
        ans = 0.5 * p - ans;
    }

    ans = ans * 180.0 / p;
    printf("%.9lf\n", ans);
}

Measured memory_bytes: 640
#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;
	int c_0 = 0, c_1 = 0;
	int ans = 0;
	rep(i, s.size()){
		if (s[i] == '0') c_0++;
		if (s[i] == '1') c_1++;
	}
	ans = min(c_0, c_1);
	ans *= 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3668
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, a, N);
    RSORT(a);
    ll ans = 0;
    REP(i, N)
    {
        if (i & 1)
        {
            ans -= a[i];
        }
        else
        {
            ans += a[i];
        }
    }
    OUT(ans);
}

Measured memory_bytes: 256
N=int(input())
*A,=map(int,input().split())
A.sort()

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

Measured memory_bytes: 20080
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    string s;
    cin>>s;
    if(s=="RRR"){
        cout<<3<<endl;
        return 0;
    }else if(s=="SSS"){
        cout<<0<<endl;
        return 0;
    }else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R')){
        cout<<2<<endl;
        return 0;
    }else{
        cout<<1<<endl;
        return 0;
    }
}

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

using namespace std;

int N,T[110],M,P[110],X[110];

int main()
{
	scanf("%d",&N);
	int ans = 0;
	for (int i=1;i<=N;i++)
	{
		scanf("%d",&T[i]);
		ans+=T[i];
	}
	scanf("%d",&M);
	int save = 10000000;
	for (int i=1;i<=M;i++)
	{
		scanf("%d%d",&P[i],&X[i]);
		printf("%d\n",ans + X[i] - T[P[i]]);
	}
	//printf("%d\n", ans-save);
}

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

MAX = 3*10**5+1

H, W, M = map(int, input().split())

A = [set() for _ in range(MAX)]
B = [set() for _ in range(MAX)]
for _ in range(M):
    h, w = map(int, input().split())
    A[h].add(w)
    B[w].add(h)

B.sort(key=lambda x : len(x), reverse=True)
L = len(B[0])
P = []
for b in B:
    if len(b) == L:
        P.append(b)

ans = 0
for h in range(MAX):
    score = len(A[h]) + L - 1
    for p in P:
        if not h in p:
            score += 1
            break
    ans = max(ans, score)

print(ans)

Measured memory_bytes: 273880
n,m = map(int,input().split())
cnt = 0
grid = [list(input()) for i in range(n)]
grid2 = [[]]*n
for i in range(n):
  cnt += "".join(grid[i]).count("#")
  grid2[i] = ["#"] + grid[i] + ["#"]
  
grid2.insert(0,["#"]*(m+2))
grid2.append(["#"]*(m+2))
grid2[1][1] = 0
loc =[[1,1]]

for k in range(1,n*m):
  next_loc = []
  for y,x in loc:
    for i,j in ([-1,0],[1,0],[0,-1],[0,1]):
      if grid2[y+i][x+j] == ".":
        grid2[y+i][x+j] = k
        next_loc.append([y+i,x+j])
  loc = next_loc
#  print(loc,k)
  if [n,m] in loc:
    break

ans = n*m - (k+1+cnt)

print(ans if ans >= 0 else -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int a, b, k, A, B;
    cin >> a >> b >> k;
    if (a + b <= k)
        A = 0, B = 0;
    else if (a < k)
        A = 0, B = a + b - k;
    else
        A = a - k, B = b;
    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

const long long mod = 1000000007;
int n,k,a[200200];
long long inv[200200]={0,1},fact[200200]={1,1},ifact[200200]={1,1};

int main()
{
  scanf ("%d %d",&n,&k);
  for (int i=0;i<n;i++) scanf ("%d",&a[i]);
  
  for (int i=2;i<200200;i++){
inv[i] = (mod - mod / i) * inv[mod % i]%mod;
    fact[i] = fact[i-1] * i % mod;
    ifact[i] = ifact[i-1] * inv[i]%mod;
  }
  
  sort(a,a+n);
  long long ans = 0;
  for (int i=k-1;i<n;i++){
    long long c = fact[i] * ifact[k-1] % mod * ifact[i-k+1]%mod;
ans = (ans + mod + c*(a[i]-a[n-i-1])%mod) % mod;
  }
  printf ("%lld\n",ans);
return 0;
}


Measured memory_bytes: 8272
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e5 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];
map<ll, ll> mp;
void sol()
{
    cin >> n;
    ll mx = 1e16;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = i; j >= 0; j --)
        {
            if(i == n - 1)f[i][j] = (j == 0 ? a[i] : 0);
            else
                f[i][j] = min(a[i] + f[i+1][a[i] > 100 ? j + 1 : j], j > 0 ? f[i+1][j-1] : mx);
        }
    }
    cout << f[0][0];
}
deque<char>st;
char ch;
void test()
{
    cin >> k >> n >> m;
    t = n / k;
    if(n % k == 0)
    {
        cout << "OK";
        return;
    }
    else
    {
        if(m >= (t + 1) * k)
        {
            cout << "OK";
            return;
        }
        else
        {
            cout << "NG";
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}


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

int main() {
  string O, E;
  cin >> O >> E;
  string ans;
  for (int i = 1; i <= O.length() + E.length(); i++) {
    if (i % 2 == 1) {
      ans += O[i/2];
    }
    else {
      ans += E[i/2 - 1];
    }
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
solve :: [Float] -> String
solve [a,b,c,d,e,f,g,h]	
  | (d-b)/(c-a) == (h-f)/(g-e) = "YES"
  | otherwise =	"NO"

main = getContents >>= mapM_ putStrLn . map solve . tail . map (map read . words) . lines

Measured memory_bytes: 4308
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(abs(X[0]-x))
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)



Measured memory_bytes: 14480
N, K = map(int, input().split())
hs = []
for n in range(N):
    h = int(input())
    hs.append(h)
hs.sort()
ret = hs[-1] - hs[0] 
for i in range(0, N - K + 1):
    hmin = hs[i]
    hmax = hs[i + K - 1]
    ret = min(ret, hmax - hmin)

print(ret)


Measured memory_bytes: 7508
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int h, best = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (best <= h) {
      best = h;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

   return 0;
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> x[i];
  }
  vector<int> origin(x);
  sort(x.begin(), x.end());
  ll midl = x[n / 2 - 1];
  ll midr = x[n / 2];

  for(const auto& v : origin)
  {
    cout << (v <= midl ? midr : midl) << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

int main() {
    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string str;
    cin >> str;
    string t;
    ll ans = 0;
    for (ll i=0; i<k; i++) {
        t = "";
        ll cur = i;
        while (cur < n) {
            t.push_back(str.at(cur));
            cur += k;
        }
        ll cnt = 1;
        for (ll j=1; j<t.size(); j++) {
            if (t.at(j) == t.at(j-1)) {
                cnt++;
            } else {
                ll tmp;
                if (t.at(j-1) == 'r') tmp = p;
                else if (t.at(j-1) == 's') tmp = r;
                else tmp = s;
                ans += tmp * (cnt/2 + cnt%2);
                cnt = 1;
            }
        }
        ll tmp;
        if (t.back() == 'r') tmp = p;
        else if (t.back() == 's') tmp = r;
        else tmp = s;
        ans += tmp * (cnt/2 + cnt%2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

bool dp[366][9][7][7][7][7];
int main(void) {
    while(1) {
        ll n;
        cin >> n;
        if(!n) break;
        vector<vector<ll>> v(n, vector<ll>(16));
        REP(i, n) REP(j, 16) cin >> v[i][j];

        // REP(i, n) {
        //     cerr << "i:" << i << endl;
        //     REP(j, 4) {
        //         REP(k, 4) cerr << v[i][j*4+k] << " ";
        //         cerr << endl;
        //     }
        // }

        if(v[0][5] || v[0][6] || v[0][9] || v[0][10]) {
            cout << 0 << endl;
            continue;
        }

        REP(i, n) REP(j, 9) REP(d0, 7) REP(d1, 7) REP(d2, 7) REP(d3, 7) {
            dp[i][j][d0][d1][d2][d3] = false;
        }
        dp[0][4][1][1][1][1] = true;
        FOR(i, 1, n) REP(j0, 9) {
            const ll j = j0 + j0/3;
            const ll x = j%4, y = j/4; 
            REP(d0, 7) REP(d1, 7) REP(d2, 7) REP(d3, 7) {
                if(!dp[i-1][j0][d0][d1][d2][d3]) continue;
                REP(nj0, 9) {
                    const ll nj = nj0 + nj0/3;
                    const ll nx = nj%4, ny = nj/4;
                    if(abs(x-nx) + abs(y-ny) > 2) continue;
                    if(x!=nx && y!=ny) continue;
                    if(v[i][nj] || v[i][nj+1] || v[i][nj+4] || v[i][nj+5]) continue;

                    if(nj == 0 && d1<6 && d2<6 && d3<6) {
                        dp[i][nj0][0][d1+1][d2+1][d3+1] = true;
                    } else if(nj == 2 && d0<6 && d2<6 && d3<6) {
                        dp[i][nj0][d0+1][0][d2+1][d3+1] = true;
                    } else if(nj == 8 && d0<6 && d1<6 && d3<6) {
                        dp[i][nj0][d0+1][d1+1][0][d3+1] = true;
                    } else if(nj == 10 && d0<6 && d1<6 && d2<6) {
                        dp[i][nj0][d0+1][d1+1][d2+1][0] = true;
                    } else if(d0<6 && d1<6 && d2<6 && d3<6) {
                        dp[i][nj0][d0+1][d1+1][d2+1][d3+1] = true;
                    }
                }
            }
        }

        ll ret = 0;
        REP(i, 9) REP(d0, 7) REP(d1, 7) REP(d2, 7) REP(d3, 7) {
            if(dp[n-1][i][d0][d1][d2][d3]) {
                ret = 1;
            }
        }
        cout << ret << endl;
    }

    return 0;
}


Measured memory_bytes: 10928
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int main(void){
   int N,W;
   cin>>N>>W;
   vector<int> w(N),v(N);
   for(int i=0;i<N;i++){
      cin>>w[i]>>v[i];
   }
   vector<vector<long long>> dp(N+1,vector<long long>(100007));
   for(int i=0;i<=N;i++){
      for(int j=0;j<100007;j++){
         dp[i][j]=1000000007;
      }
   }
   dp[0][0]=0;
   for(int i=0;i<N;i++){
      for(int j=0;j<100007;j++){
         if(v[i]<=j){
            dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
         }else{
            dp[i+1][j]=dp[i][j];
         }
      }
   }
   int ans=-1;
   for(int i=0;i<=N;i++){
      for(int j=0;j<=100000;j++){
         if(dp[i][j]<=W){
            ans=j;
         }
      }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 80256
#include <cmath>
#include <iomanip>
#include <iostream>
#include <utility>

using namespace std;

#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
  double x, y;
  Point() {};
  Point(double x, double y): x(x), y(y) {}

  Point operator + (const Point &p) { return Point(x + p.x, y + p.y); }
  Point operator - (const Point &p) { return Point(x - p.x, y - p.y); }
  Point operator * (double d) { return Point(d * x, d * y); }
  Point operator / (double d) { return Point(x / d, y / d); }

  bool operator < (const Point &p) const {
    return (x == p.x ? y < p.y : x < p.x);
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

  friend ostream& operator << (ostream &os, Point &p) {
    return os << "Point(" << p.x << ", " << p.y << ")";
  }
};

class Circle {
public:
  Point center;
  double radius;
  Circle(double x, double y, double r): center(x, y), radius(r) {}
};

typedef Point Vector;

struct Segment {
  Point p1, p2;
};

double norm(Point p) {
  return p.x * p.x + p.y * p.y;
}

double abs(Point p) {
  return sqrt(norm(p));
}

double dot(Vector v1, Vector v2) {
  return v1.x * v2.x + v1.y * v2.y;
}

Point project(Segment s, Point p) {
  Vector base = s.p2 - s.p1;
  double r = dot(p - s.p1, base) / norm(base);
  return s.p1 + base * r;
}

pair<Point, Point> cross_points(Circle c, Segment s) {
  Vector pr = project(s, c.center);
  Vector unit_v = (s.p2 - s.p1) / abs(s.p2 - s.p1);
  double base = sqrt(c.radius * c.radius - norm(pr - c.center));

  Point cp0 = pr + unit_v * base;
  Point cp1 = pr - unit_v * base;

  if (cp0.x < cp1.x || (cp0.x == cp1.x && cp0.y <= cp1.y))
    return make_pair(cp0, cp1);

  return make_pair(cp1, cp0);
}

int main() {
  int x, y, r; cin >> x >> y >> r;
  Circle c(x, y, r);

  int q; cin >> q;

  while (q--) {
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    Segment s;
    s.p1 = Point(x1, y1);
    s.p2 = Point(x2, y2);

    pair<Point, Point> ps = cross_points(c, s);

    cout << fixed << setprecision(10)
         << ps.first.x << ' ' << ps.first.y
         << ' ' << ps.second.x << ' ' << ps.second.y
         << endl;
  }
}

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

using namespace std;

#define int long long
string n;
int d,f[20004][2][205],base=1e9+7;
int F(int i,int ok,int du)
{
	if(f[i][ok][du]!=-1) return f[i][ok][du];
	else if(i==n.length()+1) 
	{
		if(du==0) return 1;
		else return 0;
	}
	else
	{
		int res=0;
		if(ok==0)
		{
			for(int j=0;j<(int)(n[i-1]-'0');j++)
			{
				res=(res+F(i+1,1,(du+j)%d))%base;
			}
			res=(res+F(i+1,0,(du+(int)(n[i-1]-'0'))%d))%base;
		}
		else
		{
			for(int j=0;j<=9;j++)
			{
				res=(res+F(i+1,1,(du+j)%d))%base;	
			}
		}
		f[i][ok][du]=res;
		return res;
	}
}
main()
{
	cin>>n>>d;
	memset(f,-1,sizeof(f));
	cout<<(F(1,0,0)-1+base)%base;
}

Measured memory_bytes: 65152
#include <stdio.h>
#include <string.h>

int main(){
    int K;
    char S[105], partS[105];

    scanf("%d", &K);
    scanf("%s", S);
    int len = strlen(S);

    if(len <= K){
        printf("%s", S);
    }else{
        strncpy(partS, S, K);
        partS[K] = '.';
        partS[K+1] = '.';
        partS[K+2] = '.';
        partS[K+3] = '\0';
        printf("%s", partS);
    }
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long N,M;
  in(N,M);
  map<long,vector<long>>m;
  long a,b;
  rep(i,N){
    in(a,b);
    m[a].pb(b);
  }
  long ans=0;
  priority_queue<long>q;
  up(i,1,M){
    for(auto e:m[i])q.push(e);
    if(!q.empty()){
      ans+=q.top();
      q.pop();
    }
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

int A[200005];

int main() {
    int N, K, a, k;
    k = 0;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a);
        a--;
        if (A[a] == 0) k++;
        A[a]++;
    }
    sort(A, A+N);
    int ans = 0;
    
    for (int i = 0; i < N; i++) {
        if (K >= k) break;
        ans += A[i];
        if (A[i] != 0) k--;
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024