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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long 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;
}

int main() {
    // 前処理
    COMinit();

    ll n;
    cin>>n;
    ll a[n];
    map<ll,int> d;
    int f,s;
    rep(i,n+1){
        cin>>a[i];
        if(d.count(a[i])){
            f=d[a[i]];
            s=i;
        }
        else{
            d[a[i]]=i;
        }
    }
    ll d1=s-f-1;

    for (int i=1;i<n+2;i++){
        if (i==1){
            cout<<n<<endl;
        }
        else if (i==n+1){
            cout<<1<<endl;
        }
        else{
            ll ans1=0,ans2=0;
            ans1=COM(n+1,i);
            if (n+1-d1-2>=i-1){
                ans2+=COM(n+1-d1-2,i-1);
            }
            cout<<(ans1-ans2+MOD)%MOD<<endl;

            /*ll ans1=0,ans2=0,ans0=0;
            ans0+=COM(n-1,i);
            ans2+=COM(n-1,i-2);
            for (int j=1;j<min(i-1,int(d1))+1;j++){
                if (n-d1-2>=i-j-1){
                ans1+=COM(d1,j)*COM(n-d1-2,i-j-1)*2;
                ans1%=MOD;
                }
            }
            if (n-d1-2>=i-1){
                ans1+=COM(n-d1-2,i-1);
                ans1%=MOD;
            }
            ll ans=(ans0+ans1+ans2)%MOD;
            cout<<ans<<endl;*/
            }



    }

    

    return 0;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y){
 int tmp;
 int r;
 if(x > y){
    tmp = x;
    x = y;
    y = tmp;
  }
  r = y % x;
  while(r!=0){
    y = x;
    x = r;
    r = y % x;
  }
  return x;
}
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    int MIN=a[1];
    int GCD=gcd(a[0],a[1]);
    for(int i=2;i<n;i++)GCD=gcd(GCD,a[i]);
    int flag=0;
    int ans;
    for(int i=MIN/GCD;i>0;i--){
        flag=0;
        for(int j=0;j<n;j++){
            if(a[j]%(i*GCD)!=0)flag++;
            if(flag>1)break;
        }
        if(flag<2){
            ans=GCD*i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

void eratosthenes(vector<int> &prime)
{
    rep(0, i, 10000010) prime.at(i) = 1;
    prime.at(0) = prime.at(1) = -1;
    rep(2, i, 10000010)
    {
        if (prime.at(i) == 1)
        {
            for (int j = i; j < 10000010; j += i)
            {
                if (prime.at(j) == 1)
                {
                    prime.at(j) = i;
                }
            }
        }
    }
}

int main()
{
    ll X;
    cin >> X;
    vector<int> prime(10000010);
    eratosthenes(prime);
    ll ans = 1;
    for (ll i = 2; i <= X; i++)
    {
        ll x = i;
        ll tmp = 1;
        ll t = 1;
        ll p = 2;
        while (prime.at(x) != -1)
        {
            if (prime.at(x) != p)
            {
                p = prime.at(x);
                t *= tmp;
                tmp = 1;
            }
            x /= prime.at(x);
            tmp++;
        }
        t *= tmp;
        ans += t * i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 42312
# -*- coding: utf-8 -*-
#mitsui c
import sys
import math
import collections
#sys.setrecursionlimit(100000)

x=int(input())

#tmp = input().split()
#a,b = list(map(lambda a: int(a), tmp))
#tmp = input().split()
#c,d = list(map(lambda a: int(a), tmp))


if(x>2100):
	print(1)
	sys.exit()

tmpa=x//100
tmpb=x%100
if(tmpb<=tmpa*5):
	print(1)
else:
	print(0)
sys.exit()



Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <ios>
#include <iomanip>
#include <limits>
#include <algorithm>
#include <sstream>
#include <bitset>
#define REP(i, n) for(int i=0; i<n; i++)
#define FOR(i, s, n) for(int i=s; i<n; i++)

using namespace std;

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int W = 0;
    int E = 0;
    int ans = 0;
    int minans = 0;

    REP(i, N){
        if (S[i] == 'W') W++;
        else E++;
    }
    if (S[0] == 'W') ans = E;
    else ans = E - 1;
    minans = ans;

    char pre;
    pre = S[0];
    FOR(i, 1, N){
        if (pre == 'W' && S[i] == 'W'){
            ans++;
        }else if (pre == 'E' && S[i] == 'E'){
            ans--;
        }
        minans = min(ans, minans);
        pre = S[i];
    }

    cout << minans << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    ll sum=0;
    for(int i=0; i<n; i++) sum+=a[i];
    double fourm=sum/(4.0*m);
    int cnt=0;
    for(int i=0; i<n; i++){
        if(fourm<=a[i]) cnt++;
    }
    if(cnt>=m) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
int main(){
  int a,b,A[MAX],B[MAX],count=0,i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
  }
  
  for(i=0;i<b;i++){
    for(j=0;j<a;j++){
      if(A[j]==B[i]){count++;break;}
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 644
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
	int n,a,b,ans,k;
	cin>>n>>a>>b>>k;
	int p[1001]={0};
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(p[i]<p[j]){
				swap(p[i],p[j]);
			}
		}
	}
	ans=k/a;
	int sum=k;
	int c=a;
	for(int i=0;i<n;i++){
		sum+=p[i];
		c+=b;
		ans=max(ans,sum/c);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    int N, K;
    cin>>N>>K;
    vector<int> H(N);
    REP(i,0,N) cin >> H[i];
    sort(H.rbegin(), H.rend());
    long ans = 0;
    REP(i, K, N){
        ans += H[i];
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int arr[5];

    while(scanf("%d %d %d",&arr[0],&arr[1],&arr[2])==3)
    {
        sort(arr,arr+3);

        if((arr[0]+arr[1])==arr[2])
            printf("Yes\n");

        else
            printf("No\n");
    }

    return (0);
}


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

int main() {
    string s;
    cin >> s;
    int n, aIndex = 500000, zIndex = 0;
    n = s.length();
        
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            if (i < aIndex) aIndex = i;
        }
        else if (s[i] == 'Z') {
            if (i > zIndex) zIndex = i;
        }
    }
    int res = zIndex - aIndex + 1;
    cout << res << endl;
    return 0;
}


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

int main() {

  int n, k;
  string s;
  cin >> n >> s >> k;
  char a = s.at(k-1);
  
  for (int i = 0; i < n; i++) {
    if (s.at(i) != a) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}


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

int main(){
  int a,b,c,cou,m[10001];
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>m[i];
  }
  cin>>b;
  cou=0;
  for(int i=0;i<b;i++){
    cin>>c;
    for(int j=0;j<a;j++){
      if(c==m[j]){
	cou++;
	break;
      }
    }
  }
  cout<<cou<<endl;
  return 0;
}
  

Measured memory_bytes: 1196
a, b = map(int, input().split())
c = min(a,b)
s = [1]
i = 2
while i <= c**0.5+1:
  if a%i==0 and b%i==0:
    a //= i
    b //= i
    if not(i in s):
      s.append(i)
  else:
    if a%i==0: a//=i
    if b%i==0: b//=i
    i += 1
  c = min(a,b)
if c!=1 and max(a,b)%c==0 and all([i==1 or c%i>0 for i in s]):
  s.append(c)
print(len(s))

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

int main() {
    //ifstream cin("testD.in");
    int n, m; cin >> n >> m;
    
    vector<vector<int>> r(m);

    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        r[x % m].push_back(x);
    }
    
    int ans = 0;
    
    vector<int> taken(m, 0);
    
    for(int i = 1; i <= m / 2 - (1 - m % 2); ++i) {
        int temp = min(r[i].size(), r[m - i].size());
        taken[i] = taken[m - i] = temp;
        ans += temp;
    }
    
    for(int i = 0; i < m; ++i) {
        if(i == 0 || (m % 2 == 0 && i == m / 2)) {
            ans += r[i].size() / 2;
            continue;
        }

        map<int, int> f;
        for(auto temp : r[i])
            f[temp]++;

        int all = 0, singles = 0;

        for(auto temp : f)
            if(temp.second >= 2) {
                all += temp.second - temp.second % 2;
                singles += temp.second % 2;
            } else {
                singles++;
            }

        int rem = max(0, (taken[i] - singles));

        
        ans += (all - rem) / 2;
    }

    cout << ans << "\n";
}

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

int main() {
    ll n, p;
    cin >> n;
    vector<ll> a(n);
    ll minus_cnt = 0;
    ll abs_total= 0;
    ll min_abs = 1e9 + 1;
    for (ll i = 0; i < n; ++i) {
        cin >> p;
        if (p < 0) minus_cnt++;
        abs_total += abs(p);
        min_abs = min(min_abs, abs(p));
        a.at(i) = p;
    }
    ll ans = abs_total;
    if (minus_cnt % 2 == 1) ans -= min_abs * 2;
    cout << ans << endl;
}


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

signed main(void)
{
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> v(n);
	for(int i = 0; i < n; i++)
	{
		string s;
		int p;
		cin >> s >> p;
		v[i] = make_pair(make_pair(s, -p), i + 1);
	}
	sort(v.begin(), v.end());
	rep(i, n) cout << v[i].second << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())
A = list(map(int, input().split()))

# 求解処理
pos = 1000
stock = 0
for i in range(N):
    if i == N - 1:
        pos += stock * A[i]
        stock = 0
    else:
        today = A[i]
        tomorrow = A[i + 1]
        if today < tomorrow:
            stock += pos // today
            pos %= today
        else:
            pos += stock * today
            stock = 0

# 結果出力
print(pos)


Measured memory_bytes: 9176
#include <iostream>
#include <stdio.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  string s;
  if((a+b)>(c+d))s="Left";
  if((a+b)==(c+d))s="Balanced";
  if((a+b)<(c+d))s="Right";
  cout<<s<<endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = B[A[0] - 1]

for i in range(1, N):
    ans += B[A[i] - 1]
    if A[i - 1] + 1 == A[i]:
        ans += C[A[i - 1] - 1]
print(ans)


Measured memory_bytes: 3064
use std::io::{stdin, Read};
use std::str::FromStr;
use std::cmp::Reverse;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: i64 = read().unwrap();
    let mut ls: Vec<i64> = Vec::new();
    for _i in 0..n {
        let l: i64 = read().unwrap();
        ls.push(l);
    }
    ls.sort_by_key(|&x| Reverse(x));
    let maxl: i64 = ls[0];
    let suml = ls.iter().skip(1).fold(0, |acc, i| acc + i);
    if maxl < suml {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2112
'use strict'

const main = input => {
	const args = input.trim().split('\n')
	const n = parseInt(args[0], 10)
	const a = args[1].split(' ').map(Number)
	let min = 1000000001
	let max = 0

	for (let i = 0; i < n; i++) {
		min = Math.min(min, a[i])
		max = Math.max(max, a[i])
	}

	console.log(max - min)
}

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


Measured memory_bytes: 7496
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<bits/stdc++.h> 
using namespace std; 

int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int a, b;
    cin>>a>>b;
    int ar[4]={0};
    ar[a]=1;
    ar[b]=1;
    for(int i=1; i<4; i++)
    {
    	if(!ar[i])
    	{
    		cout<<i<<endl;
    		break;
		}
	}
    
	return 0;
}


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

int main(){
  int a,b;
  cin>>a>>b;
  int N;
  cin>>N;
  int tmp_s,tmp_e;
  bool flag=false;
  for(int i=0;i<N;i++){
    cin>>tmp_s>>tmp_e;
    if(a<tmp_e&&b>tmp_s)flag=true;
    else if(a==tmp_e&&b==tmp_s)flag=true;
  }
  cout<<flag<<endl;
}



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

int main() {
	string text1, text2, text3;
	
	cin >> text1 >> text2 >> text3;
	cout << text1.substr(0,1) << text2.substr(0,1) << text3.substr(0,1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int n;
	cin >> n;
	dump(n / 3) ;
}


Measured memory_bytes: 256
def ceil(n, m):
    return -(-n // m)

N = int(input())
C, S, F = zip(*[[int(x) for x in input().split()] for _ in range(N - 1)])

t = [0] * N
for i in range(N - 1):
    # 駅iから出発する人
    for j in range(i, N - 1):
        t[i] = F[j] * ceil(t[i], F[j])  # 駅jから出発する時刻（S[j]=0の場合）
        t[i] = max(S[j], t[i]) # 駅jから出発する時刻
        t[i] = t[i] + C[j] # 駅j+1に到着する時刻

for i in range(N):
    print(t[i])

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

using namespace std;

int main() {
	int H, W, h, w, Swap = 0;
	cin >> H >> W >> h >> w;
	if(H % h == 0 && W % w == 0) {
		puts("No");
	} else {
		puts("Yes");
		int val = (h * w - 1) * 500 + 1;
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++) {
				if(i % h == 0 && j % w == 0)
					printf("%d ", -val);
				else
					printf("500 ");
			}
			puts("");
		}
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 200005;
const int M = 205;
// const int V = 207;
// const int E = 60007;
const int INF = 0x3f3f3f3f;
const double inf = 2e9;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-8;
int n,m;
char s[N];
int vis[N];
int main()
{
    while (~scanf("%s",s))
    {
        memset(vis,0,sizeof vis);
        int l = strlen(s);
        for (int i=0;i<l;i++)
            vis[s[i]-'a']++;
        sort(vis,vis+3);
        int a = vis[0];
        int b = vis[1];
        int c = vis[2];
        if (b>a+1 || c>a+1)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
/*

abac

aba

babacccabab

*/

Measured memory_bytes: 1152
s = input()

checker = ''

if len(s) == 2:
    if s[0] == s[1]:
        print(1, 2)
        checker += '*'
    else:
        print(-1, -1)
        checker += '*'


if checker == '':
    for a, b in zip(range(len(s)-1), range(1,len(s))):
        if s[a] == s[b]:
            print(a+1, b+1)
            checker += '*'
            break

if checker == '':
    for a, c in zip(range(len(s)-2), range(2, len(s))):
        if s[a] == s[c]:
            print(a+1, c+1)
            checker += '*'
            break

if checker == '':
    print(-1, -1)

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

using namespace std;

int main()
{
	map<int,int> m;
	int n,k,q;
	cin>>n>>k>>q;
	
	int id;
	for(int i = 0; i<q; i++)
	{
		cin>>id;
		m[id]+=1;
	}

	for(int i = 1; i<=n; i++)	
	{
		if(k-q+m[i]<=0)
				cout<<"No\n";
		else
				cout<<"Yes\n";
	}
}


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

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int p[n];
    
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int tmp;
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
          if (p[i] > p[j]) {
            tmp =  p[i];
            p[i] = p[j];
            p[j] = tmp;
          }
        }
    }
    int ans=0;
    for(int i=0;i<k;i++){
        ans=ans+p[i];
    }
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
int main(){
  string s; cin >>s;
  int n=s.length();

  int max=0;

  for(int i=0; i<n;i++){
    int cnt=0;
    while(s[i]=='A' || s[i]=='C' || s[i]=='G' ||s[i]=='T'){
    cnt++; i++;
    }
    if(max<cnt) max=cnt;
  }

  cout<<max<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

int k(int a) {
	if (a == 0)return 0;
	if (a < 0)return -1;
	return 1;
}
int main() {
	int a, b;
	cin >> a >> b;
	if ((k(a)&k(b))&&k(a)==k(b)) {
		if (k(a) == 1) {
			puts("Positive");
		}
		else {
			if (abs(a - b) & 1)puts("Positive");
			else puts("Negative");
		}
	}
	else {
		puts("Zero");
	}
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n << endl;
	else cout << 2 * n << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

s_len = len(S)
t_len = len(T)

if s_len != t_len-1:
    print('No')
elif S != T[:s_len]:
    print('No')
elif str.islower(T[s_len]) != True:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 8984
s = input()
n = len(s)
def dfs(i, l):
    if i == n-1:
        return sum(list(map(int, l.split("+"))))
    return dfs(i+1, l+s[i+1]) + dfs(i+1, l+"+"+s[i+1])

print(dfs(0, s[0]))


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
  int n,l,r,i,ans=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d %d",&l,&r);
      ans += (r-l) + 1;
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
/*
      author : nishi5451
      created: 11.08.2020 20:07:18
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  string s;
  cin >> s;
  ll count = 0;
  ll b = 0;
  rep(i,s.size()){
    if(s[i] == 'B'){
      b++;
    }else{
      count += b;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
# input
S = input()
x, y = S[:2], S[2:]

# check
not_MM_x = (int(x) >= 13)
not_MM_y = (int(y) >= 13)
zero_x = (x == "00")
zero_y = (y == "00")
checker = [not_MM_x, not_MM_y, zero_x, zero_y]

if checker in [[True, False, False, False], [False, False, True, False]]:
    print("YYMM")
elif checker in [[False, True, False, False], [False, False, False, True]]:
    print("MMYY")
elif checker == [False, False, False, False]:
    print("AMBIGUOUS")
else:
    print("NA")

Measured memory_bytes: 3064
if __name__ == '__main__':
    n = int(input())
    hs = list(map(int, input().split()))
    height = hs[0]
    count=0
    for h in hs[1:]:
        if height>h:
            count+=height-h
            height=h
        else:
            height=h
    print(int(count+height))


Measured memory_bytes: 3060
#include <stdio.h>

int gcd(int m, int n)
{
    int r;
    
    while (n != 0){
        r = m % n;
        m = n;
        n = r;
        
    }
    return (m);
}

int lcd(int m, int n)
{
   return ((m / gcd(m, n)) * n);
}

int main(void)
{
    int m, n;
    int r, q;
    
    while (scanf("%d %d", &m, &n) != EOF){
       printf("%d %d\n", gcd(m, n), lcd(m, n));
    }
    
    
    
    return (0);
}

Measured memory_bytes: 596
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
inline int read(){
    int x(0),w(1); char c = getchar();
    while(c^'-' && (c<'0'||c>'9')) c = getchar(); if(c == '-') w = -1, c = getchar();
    while(c>='0' && c<='9') x = (x<<3) + (x<<1) + c - '0', c = getchar();
	return x*w;
}
int n,m,ans,x;
int k[110],p[110],cnt[110];
vector <int> a[110];
inline bool ON(int sta, int P){
	int res;
	res = (sta >> (P-1));
	return res % 2;
}
inline bool check(){
	for(int i = 1; i <= m; ++i){
		if(cnt[i] % 2 != p[i]) return 0;
	}
//	printf("FIT!\n");
	return 1;
}
int main(){
//	freopen(".in","r",stdin);
	n = read(), m = read();
	for(int i = 1; i <= m; ++i){
		k[i] = read();
		for(int j = 1; j <= k[i]; ++j){
			x = read();
			a[x].push_back(i);
		}
	}
	for(int i = 1; i <= m; ++i) p[i] = read();
/*	for(int i = 1; i <= n; ++i){
		printf("%d: ",i);
		for(int p = 0; p < a[i].size(); ++p){
			printf("%d, ",a[i][p]);
		}
		printf("\n");
	}*/
	for(int sta = 0; sta < (1<<n); ++sta){
		memset(cnt,0,sizeof(cnt));
//		printf("sta = %d\n",sta);
		for(int j = 1; j <= n; ++j){
			if(ON(sta,j)){
				for(int p = 0; p < a[j].size(); ++p){
					++cnt[a[j][p]];
				}
			}
		}
		if(check()) ++ans;
	}
	printf("%d",ans);
	return 0;
}

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

int h, w, k;
char s[51][51];
int dp[51][51][1 << 12][4], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
bool used[51][51];
void mark(int x, int y, int t, int s) {
	used[x][y] = true;
	if (s == 0)return;
	int a = ((t >> 1 & 1) << 1) + (t & 1);
	x -= dx[a], y -= dy[a];
	t >>= 2;
	mark(x, y, t, s - 1);
}
int rec(int x, int y, int t, int a, int cnt) {
	if (dp[x][y][t][a] != -1)return dp[x][y][t][a];
	int res = -INF;
	rep(i, 4) {
		if (i % 2 && !a)continue;
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#')continue;
		int v = 0;
		memset(used, 0, sizeof(used));
		mark(x, y, t, cnt);
		if (used[nx][ny] == false) {
			if ('1' <= s[nx][ny] && s[nx][ny] <= '9')v = s[nx][ny] - '0';
		}
		int p = (t >> (k * 4 - 2)) << (k * 4 - 2); p = t - p;
		p = (p << 2) + i; int b = cnt; if (b < 2 * k)b++;
		int o = rec(nx, ny, p, a - i % 2, b);
		if (o != -INF)res = max(res, o + v);
	}
	if (x == h - 1 && y == w - 1 && res == -INF) {
		return dp[x][y][t][a] = 0;
	}
	return dp[x][y][t][a] = res;
}
int main() {
	scanf("%d%d%d", &h, &w, &k);
	rep(i, h)scanf("%s", s[i]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", rec(0, 0, 0, k, 0));
}

Measured memory_bytes: 169624
#include<bits/stdc++.h>
using namespace std;
const long long md=998244353;
long long n,a[202020],w[1010101],sum,mx,cnt[1010101],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mx=max(a[i],mx);
		cnt[a[i]]++;
	}
	w[1]=1;
	for(int i=2;i<=mx;i++)
	{
		w[i]=(md-md/i)*w[md%(i*1ll)]%md;
	}
	for(int i=1;i<=mx;i++)
	{
		for(int j=i*2;j<=mx;j+=i)
		{
			w[j]-=w[i];
			w[j]+=md;
			w[j]%=md;
		}
	}
	for(int i=1;i<=mx;i++)
	{
		sum=0;
		for(int j=i;j<=mx;j+=i)
		{
			ans+=(sum*j%md*cnt[j]%md+cnt[j]*(cnt[j]-1)/2ll%md*j%md*j%md)*w[i]%md;
			ans%=md;
			sum+=j*cnt[j]%md;
			sum%=md;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

n, x, y = map(int, input().split())
ans = [0] * (n - 1)
for i in range(n):
    check = 0
    for j in range(i + 1, n):
        check += 1
        if x - 1 <= i:
            a = i - x + 1
        else:
            a = x - 1 - i
        if y - 1 <= j:
            b = j - y + 1
        else:
            b = y - 1 - j
        cnt = min(check, a + b + 1)
        ans[cnt - 1] += 1
for i in range(n - 1):
    print(ans[i])


Measured memory_bytes: 48220
// D.

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

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	int n, ans = 0;
	set<int> s;
	map<int, int> m;
	cin >> n;
	vector<int> a(n), af(1000001), ac(1000001), ng(1000001);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		ac[a[i]] += 1;
		int x = a[i];
		for (int j = 2; j * j <= x; ++j) {
			if ((x % j) == 0) {
				af[j] += 1;
				int b = x / j;
				if (j != b) {
					af[x / j] += 1;
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		int x = a[i];
		if (af[x]) {
			ng[x] = 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		int x = a[i];
		if (ac[1]) {
			if (x > 1) continue;
		}
		bool ok = ac[x] == 1;
		for (int j = 2; j * j <= x; ++j) {
			if ((x % j) == 0) {
				if (ng[j]) {
					ok = false;
				}
				if (ng[x / j]) {
					ok = false;
				}
			}
		}
		ans += ok;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll H;
    cin >> H;
    ll k = 1;
    ll t = 0;
    while (H > 0) {
        t += k;
        H /= 2;
        k *= 2;
    }
    cout << t << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	map<char, int> mp[50];
	REP(i, n) {
		string s;
		cin >> s;
		REP(j, s.size()) {
			mp[i][s[j]]++;
		}
	}
	REP(i, 26) {
		int mi = 1000000000;
		REP(j, n) {
			mi = min(mi, mp[j][(char)('a' + i)]);
		}
		REP(j, mi) {
			cout << (char)('a' + i);
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  float x1,y1,x2,y2,x3,y3,x4,y4;
  double dm,dn;
  int i,n;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);

    dm=(y2-y1)/(x2-x1);
    dn=(y4-y3)/(x4-x3);

    if(dm == dn){
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    for(int i=0; i<s.length();i++){
        if(i%2==0){
            if(s[i]=='L'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(s[i]=='R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
  int i,k,a,b,c;
  char number[3][100];

  i = 0;
  k = 0;
  while((c = getchar()) != EOF) {
    if(c == ' ') {
      k++;
      i = 0;
    }else{
      number[k][i] = c;
      i++;
    }
  }
  a = atoi(number[0]);
  b = atoi(number[1]);
  c = atoi(number[2]);

  if(a < b && b < c) {
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_N = 55;

int par[MAX_N];
int depth[MAX_N];

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        depth[i] = 1;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (depth[x] > depth[y]) {
        par[y] = x;
    } else {
        par[x] = y;
        if (depth[x] == depth[y]) 
            depth[y]++;
    }
}

bool is_bridge(int n) {
    for (int i = 0; i < n - 1; i++) {
        if (!same(i, i + 1)) {
            return true;
        }
    }
    return false;
}

int main(){
    int N, M; cin >> N >> M;
    vector<int> a;
    vector<int> b;
    rep(i, M) {
        int t1, t2; cin >> t1 >> t2;
        a.push_back(t1);
        b.push_back(t2);
    }
    
    int count = 0;
    for (int i = 0; i < M; i++) {
        init(N);
        // view(par, N);
        for (int j = 0; j < M; j++) {
            if (j == i) continue;
            unite(a[j] - 1, b[j] - 1);
        }
        // view(par, N);
        // cout << endl;
        if (is_bridge(N)) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    Q = [A[i][j] * x for j, x in enumerate(B)]
    if sum(Q) + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {

		// --- input ---
		int[] L1 = getNums(in.readLine().split(" "));
		int[][] data = getData(L1[2]);
		in.close();

		// --- resolv ---
		int white_w_start = 0;
		int white_h_start = 0;
		int white_w_end = L1[0];
		int white_h_end = L1[1];

		for(int[] d : data) {
			if(d[2] == 1) {
				if(white_w_start < d[0])white_w_start = d[0];
			} else if(d[2] == 2) {
				if(white_w_end > d[0])white_w_end = d[0];
			} else if(d[2] == 3) {
				if(white_h_start < d[1])white_h_start = d[1];
			} else if(d[2] == 4) {
				if(white_h_end > d[1])white_h_end = d[1];
			}
		}

		if( (white_w_end - white_w_start < 0) || (white_h_end - white_h_start) < 0) {
			System.out.println(0);
		} else {
			System.out.println((white_w_end - white_w_start) * (white_h_end - white_h_start));
		}
	}

	public static int[][] getData(int num) throws Exception{

		int[][] data = new int[num][];
		for(int i=0; i < num; i++) {
			data[i] = getNums(in.readLine().split(" "));
		}
		return data;
	}

	public static int[] getNums(String[] vals) {
		int[] vAry = new int[vals.length];
		for(int i=0; i < vals.length; i++) {
			vAry[i] = Integer.parseInt(vals[i]);
		}
		return vAry;
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
#define S 0
using namespace std;
const int SZ=1<<19,N=2009,M=2*N*N;
int T,p=1,a[N],b[N],he[N],ne[M],to[M],f[M],d[N],q[N],cur[N];
bitset<10000009>np;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
	G;while(*ip<'-')G;
	R x=*ip&15;G;
	while(*ip>'-'){x*=10;x+=*ip&15;G;}
	return x;
}
inline void add(R x,R y){
	ne[++p]=he[x];he[x]=p;to[p]=y;f[p]=1;
	ne[++p]=he[y];he[y]=p;to[p]=x;
}
bool dfs(R x){
	if(x==T)return 1;
	for(R&i=cur[x];i;i=ne[i])
		if(f[i]&&d[to[i]]==d[x]+1&&dfs(to[i]))
			return f[i]^=1,f[i^1]^=1,1;
	return 0;
}
int main(){
	R n=in(),m=0,lst=0,ans=0;
	for(R i=1;i<=n;++i)b[i]=in();
	sort(b+1,b+n+1);
	for(R i=1;i<=n;++i){
		if(b[i]!=lst){
			if(lst)a[++m]=lst;
			a[++m]=b[i];
		}
		lst=b[i]+1;
	}
	a[++m]=lst;
	for(R i=2,lim=sqrt(lst)+1;i<lim;++i)
		if(!np[i])for(R j=i*i;j<lst;j+=i)np[j]=1;
	np[1]=np[2]=1;
	T=m+1;
	for(R i=1;i<=m;++i){
		1&a[i]?add(S,i):add(i,T);
		for(R j=1;j<i;++j)
			if(!np[a[i]-a[j]])1&a[i]?add(i,j):add(j,i);
	}
	while(1){
		memset(d+1,1,4*T);
		for(R h=0,t=0;h<=t;++h)
			for(R i=he[q[h]],dd=d[q[h]]+1;i;i=ne[i])
				if(f[i]&&d[to[i]]>dd)
					q[++t]=to[i],d[to[i]]=dd;
		if(d[T]==0x01010101)break;
		memcpy(cur,he,4*(T+1));
		while(dfs(S))++ans;
	}
	lst=ans;
	for(R i=he[S];i;i=ne[i])ans+=f[i];
	ans+=1&(ans-lst);
	for(R i=he[T];i;i=ne[i])ans+=f[i^1];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5632
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long bank = 100;
		long count = 0;
		for(long i = bank;i < X;bank += bank / 100,count++) {
			if(bank >= X) {
				System.out.println(count);
				break;
			}
		}
	}
}

Measured memory_bytes: 35748
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/dp/tasks/dp_c
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[][] h = new int[N][3];
        for (int i = 0; i < N; i++) {
            h[i][0] = in.nextInt();
            h[i][1] = in.nextInt();
            h[i][2] = in.nextInt();
        }
        System.out.println(maxHappiness(h, N));
    }

    public static int maxHappiness(int[][] h, int N) {
        int[] dp = h[0];
        for (int i = 1; i < N; i++) {
            int[] c = new int[3];
            c[0] = h[i][0] + Math.max(dp[1], dp[2]);
            c[1] = h[i][1] + Math.max(dp[0], dp[2]);
            c[2] = h[i][2] + Math.max(dp[0], dp[1]);
            dp = c;
        }
        return Math.max(dp[0], Math.max(dp[1], dp[2]));
    }
}


Measured memory_bytes: 97592
import numpy as np
a = np.array(input().split(), dtype='int')
b = np.array(input().split(), dtype='int') - a
c = np.array(input().split(), dtype='int') - a

if np.all(b == b[0]) and np.all(c == c[0]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27232
#include<bits/stdc++.h>
#define IL inline
#define _ 800005
#define ll long long
using namespace std ;

#define int ll 

IL int gi(){
    int data = 0 , m = 1; char ch = 0;
    while(ch!='-' && (ch<'0'||ch>'9')) ch = getchar();
    if(ch == '-'){m = 0 ; ch = getchar() ; }
    while(ch >= '0' && ch <= '9'){data = (data<<1) + (data<<3) + (ch^48) ; ch = getchar(); }
    return (m) ? data : -data ; 
}

int seqL[_] , seqR[_] , n , K , cov[_ << 2] , A[_] , B[_] , X[_ << 1] , xox , nL ;
ll Ans  , f[_] , SUM ; 

IL void PushDown(int o) {
	if(!cov[o]) return ;
	cov[o << 1] = cov[o] ; cov[o << 1 | 1] = cov[o] ; cov[o] = 0 ; return ;
}
void Insert(int o , int l , int r , int ql , int qr , int v) {
	if(ql > qr) return ;
	if(ql <= l && r <= qr) {cov[o] = v ; return ; }
	int mid = (l + r) >> 1 ;
	PushDown(o) ;
	if(ql <= mid) Insert(o << 1 , l , mid , ql , qr , v) ;
	if(qr  > mid) Insert(o << 1 | 1 , mid + 1 , r , ql , qr , v) ;
	return ; 	
}
int Query(int o , int l , int r , int ps) {
	if(l == r) return cov[o] ;
	int mid = (l + r) >> 1 ; PushDown(o) ;
	return ps <= mid ? Query(o << 1 , l , mid , ps) : Query(o << 1 | 1 , mid + 1 , r , ps) ;
}

IL void Init() {
	n = gi() ; K = gi() ;
	for(int i = 1; i <= n; i ++) A[i] = gi() , B[i] = gi() ;
	for(int i = 1; i <= n; i ++) if(2 * A[i] > K && B[i] == 1) {puts("-1") ; exit(0) ; } 
	for(int i = 1; i <= n; i ++) SUM += A[i] , A[i] = (A[i] + A[i - 1]) % K  ;
	nL = 0 ;
	for(int i = 1; i <= n; i ++)
		if(B[i] == 1) {
			seqL[i] = ((-2ll * A[i - 1]) % K + K) % K ;
			seqR[i] = ((-2ll * A[i]) % K + K) % K ; 
		}
		else seqL[i] = 0 , seqR[i] = K - 1 ; 
	for(int i = 1; i <= n; i ++) X[++xox] = seqL[i] , X[++xox] = seqR[i] ;
	sort(X + 1 , X + xox + 1) ; xox = unique(X + 1 , X + xox + 1) - X - 1 ;
	for(int i = 1; i <= n; i ++) {
		seqL[i] = lower_bound(X + 1 , X + xox + 1 , seqL[i]) - X ;
		seqR[i] = lower_bound(X + 1 , X + xox + 1 , seqR[i]) - X ; 
	}
	return ;
}

IL int Dist(int u , int v) {return (v + K - u) % K ; }


ll ask(ll pos){
    ll choose=Query(1,1,xox,pos);
    if(!choose) return 0;
    return (f[choose]+(X[seqL[choose]]-X[pos]+K)%K) ;
}

#undef int

int main() {
	Init() ; 
	f[n + 1] = 0 ;
	/*
	Insert(1 , 1 , xox , 1 , xox , n + 1) ;
	for(int i = n,v; i >= 1; i --) {
		f[i] = f[v = Query(1 , 1 , xox , seqL[i])] + 1ll * (v <= n) * Dist(X[seqL[i]] , X[seqL[v]]) ;
		if(seqL[i] > seqR[i]) Insert(1 , 1 , xox , seqR[i] + 1 , seqL[i] - 1 , i) ;
		else if(seqL[i] < seqR[i]) {
			Insert(1 , 1 , xox , 1 , seqL[i] - 1 , i) ;
			Insert(1 , 1 , xox , seqR[i] + 1 , xox , i) ;
		} 
	}
	*/
	for(int i=n;i>=1;i--){
        f[i]=ask(seqL[i]);
        if(seqL[i]>seqR[i]) Insert(1,1,xox,seqR[i]+1,seqL[i]-1,i);
        else Insert(1,1,xox,1,seqL[i]-1,i),Insert(1,1,xox,seqR[i]+1,xox,i);
    }
	Ans = f[1] ;
	/*
	for(int i = 1,v; i <= xox; i ++) 
		Ans = min(Ans , f[v = Query(1 , 1 , xox , i)] +  1ll * (v <= n) * Dist(X[i] , X[seqL[v]])) ;
	*/
	
    for(int i=xox;i>=1;i--) Ans=min(Ans,ask(i));
	Ans = Ans + 2ll * SUM ; 
	cout << Ans << endl ; return 0 ; 
}


Measured memory_bytes: 15488
N, K = map(int, input().split())
k2num = {}
for k in map(int, input().split()):
    if k in k2num:
        k2num[k] += 1
        continue
    k2num[k] = 1

ans = 0
num_ball = sorted(k2num.values(), key=lambda x: x)
for i, num in enumerate(num_ball):
    if len(num_ball)-i <= K:
        break
    ans += num
print(ans)


Measured memory_bytes: 41120
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
// #define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int A, B;
  cin >> A >> B;
  if (B % A) {
    cout << B - A << endl;
  } else {
    cout << B + A << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int		main(void)
{
	int		n;
	int		k;
	int		i;

	if((scanf("%d %d", &n, &k)) < 2)
		return (-1);
	i = 0;
	while (n)
	{
		n /= k;
		i++;
	}
	printf("%d", i);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
struct dice{
	int up;
	int down;
	int east;
	int west;
	int north;
	int south;
};
dice a, b;
dice d[100];
char s[101]="NNNNENWNNNNENWNNNNENWNNNNENWENNNNWWNNNNE";
int x;
dice  input(){
	dice c;
	scanf("%d", &x);
	c.up = x;
	scanf("%d", &x);
	c.south = x;
	scanf("%d", &x);
	c.east = x;
	scanf("%d", &x);
	c.west = x;
	scanf("%d", &x);
	c.north = x;
	scanf("%d", &x);
	c.down = x;
	return c;
}
void nr(){
			x = a.north;
			a.north = a.up;
			a.up = a.south;
			a.south = a.down;
			a.down = x;
			return;
}
void sr(){
			x = a.south;
			a.south = a.up;
			a.up = a.north;
			a.north = a.down;
			a.down = x;
			return;
}
void er(){
	x = a.east;
	a.east = a.up;
	a.up = a.west;
	a.west = a.down;
	a.down = x;
	return;
}
void wr(){
	x = a.west;
	a.west = a.up;
	a.up = a.east;
	a.east = a.down;
	a.down = x;
	return;
}
bool comp(){
	if (a.up == b.up&&a.north == b.north&&a.east == b.east&&a.down == b.down&&a.south == b.south&&a.west == b.west)return true;
	else return false;
}
int main(void){
	int n,m;
	scanf("%d", &m);
	f(i, m)d[i] = input();
	n = strlen(s);
	bool ans = false;
	for (int j = 0; j < m; j++){
		for (int k = j + 1; k < m; k++){
	a = d[j];
	b = d[k];
f(i, n){
		if (s[i] == 'N'){
			nr();
		}
		else if (s[i] == 'S'){
			sr();
		}
		else if (s[i] == 'E'){
			er();
		}
		else if (s[i] == 'W'){
			wr();
		}
		ans = comp();
		if (ans == true)break;
	}
if (ans == true)break;
		}
if (ans == true)break;
	}
		if(ans==true)printf("No\n");
		else printf("Yes\n");

	return 0;
}

Measured memory_bytes: 2616
#include <stdio.h>
#include <math.h>
int c;
void bubbleSort(int x[], const int y) //バブルソート部
{
  int flag,tmp,j;

  flag=1;
  do {
      flag=0;
      for(j=y-1;j>=1;j--) {
          if(x[j] < x[j-1]) {
              tmp=x[j];
	          x[j]=x[j-1];
	          x[j-1]=tmp;
	          c++;
	          flag=1;
          }
      }
  }while(flag==1);
}


int main(void)
{
  int a[100]={0};
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&a[i]);
  }
 
    bubbleSort(a,n);
    
  printf("%d",a[0]);
  for(i=1;i<n;i++) {
    printf(" %d",a[i]);
  }
  printf("\n");
  printf("%d\n",c);
  return(0);
}



Measured memory_bytes: 2692
import scala.io.StdIn._

/**
 * ABC109B
 */
object Main extends App {

  val n = readInt()
  val strs = (0 until n).map(_ => readLine()).toSeq

  val f = (strs: Seq[String]) => {
    val set = scala.collection.mutable.Set[String]()
    var past: String = strs(0)(0).toString()
    var flag = true

    for (s <- strs) {
      if (set.contains(s)) flag = false
      set += s
      if (past(past.length() - 1) != s(0)) flag = false
      past = s
    }
    if (flag) "Yes"
    else "No"
  }

  val ans = f(strs)

  println(ans)
}


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

using namespace std;

int N, M, K, v[600009];
const int mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[1000009], inv[1000009], p3[1000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=1; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d", &N, &M, &K), Prec (900003), p3[0] = 1;
for (int i=1; i<=900000; i++)
    p3[i] = add (add (p3[i - 1], p3[i - 1]), p3[i - 1]);
/*for (int i=0; i<=M; i++)
    for (int j=0; j<=K; j++)
        adto (v[i + j], comb (i + j, i));*/
/*
sa consideram un dreptunghi cu un colt in (0, 0) si unul in (M, K)
pentru fiecare diagonala secundara, vrem sa stim numarul de drumuri
care duc in diagonala aia
*/
v[0] = 1;
if (M > K) swap (M, K); ///M <= K
for (int i=1; i<=M + K; i++)
{
    v[i] = add (v[i - 1], v[i - 1]);
    if (i > M) v[i] = subtract (v[i], comb (i - 1, M));
    if (i > K) v[i] = subtract (v[i], comb (i - 1, K));
}
int ans = 0;
for (int i=0; i<=M + K; i++)
{
    v[i] = mul (v[i], p3[M + K - i]);
    adto (ans, mul (v[i], comb (i + N - 1, N - 1)));
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 14336