akhauriyash/Code-Regression huggingface dataset:
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [N, M, C] = input[0].split(' ').map(x => parseInt(x))
  const Bs = input[1].split(' ').map(x => parseInt(x))

  let count = 0
  for (let i = 0; i < N; i++) {
    let sum = 0
    const srcCode = input[i + 2].split(' ').map(x => parseInt(x))
    for (let j = 0; j < M; j++) {
      sum += srcCode[j] * Bs[j]
    }
    if (sum + C > 0) {
      count++
    }
  }

  console.log(count)
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

using namespace std;

int main() {
    int orank = 0;
    int ncs = 0;

    int N,A,B;cin>>N>>A>>B;
    string s;
    cin>>s;

    for(int i=0;i<N;i++) {
        if(s[i] == 'a') {
            if(ncs < A+B) {
                ncs++;
                cout<<"Yes"<<endl;
            } else cout<<"No"<<endl;
        } else if(s[i] == 'b') {
            orank++;
            if(ncs < A+B and orank <= B) {
              cout<<"Yes"<<endl;
              ncs++;
            } else cout<<"No"<<endl;
        } else cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include<string>
#include <complex>
using namespace std;

#define ll long long
#define f first
#define s second
typedef pair<int , int > pii;
const ll MOD = 1e9+7;


void min_self(ll &a , ll b){
    a=min(a,b);
}

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

ll add(ll x, ll y)
{
    return (x + y) % MOD;
}

ll sub(ll x, ll y)
{
    return add(x, MOD - y);
}

ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x, ll y)
{
    ll z = 1;
    while(y > 0)
    {
        if(y % 2 == 1)
            z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}
const int MXN = 1e6+10;
ll fact[MXN];
void fac_pre()
{
    fact[0]=1;
    for(ll i=1; i<MXN; i++){
        fact[i]=mul(fact[i-1],i);
    }
}
ll C(ll n, ll k)
{
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}

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

}
// BIT //
const int MAXN=2*1e5+10;
vector<int> bit(MAXN,0);
int sump(int idx) {
    int ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx)
        ret += bit[idx];
    return ret;
}

int sum(int l, int r) {
    return sump(r) - sump(l - 1);
}

void upd(int idx, int delta) {
    for (++idx; idx < MAXN; idx += idx & -idx)
        bit[idx] += delta;
}
/////-----//////

int  main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    /* KEEP IN MIND
     * take care when sorting a 1 based indexed vector
     * const int N is defined way above in the starting
    */
    int n ; cin>>n;
    vector<int> a(n);
    map<int,int> cnt;
    for(int i=0; i<n; i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    int MAX=1e6+10;
    vector<int> div_count(MAX,0);
    for(auto pp : cnt){
        int i=pp.first;
        int c=pp.second;
        for(int j=1; j*i<MAX; j++){
            div_count[j*i]+=c;
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        if(div_count[a[i]] == 1 ) ans++;
    }
    cout<<ans<<endl;

    return 0;
}








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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

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

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

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String turn = "A";
		int cnt = 0;
		while(true) {
			if(turn.equals("A")) {
				if(a + 1 == b) {
					a--;
				} else {
					a++;
				}
				if(a == 0) {
					System.out.println("Borys");
					return;
				}
				turn = "B";
			} else {
				if(b - 1 == a) {
					b++;
				} else {
					b--;
				}
				if(b == n + 1) {
					System.out.println("Alice");
					return;
				}
				turn = "A";
			}
			cnt++;
			if(cnt == 1000000) {
				System.out.println("Draw");
				return;
			}
		}
	}
}


Measured memory_bytes: 21972
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;}
#[allow(unused_macros)]
macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base <cmp_max {$base =cmp_max ;true } else {false } } } ;}

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }
    let ans = max!(a*c, a*d, b*c, b*d);
    println!("{}", ans);
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, n);
	VAR(string, s);

	int l = 0, r = 0, cnt = 0;
	EACH(si, s) {
		if (si == '(') {
			cnt++;
		} else {
			cnt--;
			if (cnt < 0) {
				l++;
				cnt = 0;
			}
			
		}
	}
	if (cnt > 0) r = cnt;
	if (cnt < 0) l += cnt;

	OUT(string(l, '('));
	OUT(s);
	OUT(string(r, ')'))BR;
  
  return 0;
}


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

using namespace std;
int main(){
    int n;
    cin >> n;
    string s,t;
       cin >> s >> t;
    for(int i=0; i<n; i++){
       cout << s[i];
       cout << t[i];}
    cout << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int N, a[2][102], dp[2][102];

int func(int r, int c){
	if(r == 1 && c == N - 1)	return a[r][c];
	int &ret = dp[r][c];
	if(ret != -1)	return ret;
	ret = 0;
	if(r < 1)	ret = func(r + 1, c) + a[r][c];
	if(c < N - 1)	ret = max(ret, func(r, c + 1) + a[r][c]);
	return ret;
}

int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &N);
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < N; j++)
			scanf("%d", &a[i][j]);
	printf("%d\n", func(0, 0));
	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m, 0), b(m, 0);
    rep(i, m) cin >> a[i] >> b[i];
    vector<bool> stt(m, false), goal(m, false);
    rep(i, m)
    {
        if (a[i] == 1)
        {
            stt[b[i]] = true;
        }
    }
    rep(i, m)
    {
        if (b[i] == n)
        {
            if (stt[a[i]] == true)
            {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a,b,n;
  cin >> a >> b >> n;
  
  if(a==0&&b==0) {
    cout << 1 << endl;
    return 0;
  }
  
  if(a==0) {
    cout << b/n + 1 << endl;
    return 0;
  }
  
  cout << -(a-1)/n + b/n << endl;
}

Measured memory_bytes: 256
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

char s[15];

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int f=1;
    scanf("%s",s);
    for(int i=0;i<strlen(s)&&i+1<strlen(s);i=i+2)
    {
        if(s[i]!='h'||s[i+1]!='i')
        {
            f=0;break;
        }
    }
    if(!f||strlen(s)&1)printf("No\n");
    else printf("Yes\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char **argv)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if ( a < b && b < c ) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int nm(int a,int b){
    if(a<b) swap(a,b);
    return (a-1)*(a-2)/2+b-1;
}

class ELeague {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,m;
        in>>n;
        m=n*(n-1)/2;
        vector<int> h(m);
        vector<vector<int>> a(n+1,vector<int>(n-1));
        vector<vector<int>> v(n*(n-1)/2),iv(n*(n-1)/2);
        Fr(i,n) fr(j,n-1) in>>a[i][j];
        Fr(i,n){
            fr(j,n-2){
                v[nm(i,a[i][j])].emplace_back(nm(i,a[i][j+1]));
                iv[nm(i,a[i][j+1])].emplace_back(nm(i,a[i][j]));
            }
        }
        stack<int> st;
        fr(i,m) if((h[i]=iv[i].size())==0) st.push(i);
        vector<int> ts;
        while(!st.empty()){
            int i=st.top();st.pop();
            ts.emplace_back(i);
            for(auto&j:v[i]){
                --h[j];
                if(h[j]==0) st.push(j);
                if(h[j]<0){

                }
            }
        }
        if(ts.size()!=m){
            out<<-1<<endl;
            return;
        }
        vector<int> it(m);
        fr(i,m) it[ts[i]]=i;
        vector<int> dp(m);
        int ans=0;
        fr(i,m){
            ans=max(ans,dp[i]);
            for(auto j:v[ts[i]]){
                dp[it[j]]=max(dp[it[j]],dp[i]+1);
            }
        }
        out<<ans+1<<endl;
    }
};

int main() {
    ELeague solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 66804
k, t = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * t
for i in range(t):
    cnt[i] += sum(a[:i])
    if i != t - 1:
        cnt[i] += sum(a[i + 1:])
ans = -1
for i in range(t):
    if a[i] > cnt[i]:
        ans += a[i] - cnt[i]
print(max(ans, 0))

Measured memory_bytes: 3064
s = input()
t = input()
s,t = s[::-1],t[::-1]
if len(s)<len(t):
	print("UNRESTORABLE")
else:
	for i in range(len(s)-len(t)+1):
		if all(s[i+j]=="?" or s[i+j]==t[j] for j in range(len(t))):
			s = s[:i]+t+s[(i+len(t)):]
			break
	if t not in s:
		print("UNRESTORABLE")
	else:
		answer = s.replace("?","a")[::-1]
		print(answer)

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

using namespace std;

int A[100007];
int n;

void init(){

}

void solve(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    sort(A, A+n);
    int p = A[n/2-1];
    int q = A[n/2];
    printf("%d\n", q-p);

}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
#define endl '\n'

using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    int l = a.length();
    int count = 0;
    for (int i = 0; i < l;i++){
        if(a[i]==b[i]){
            count++;
        }
    }
    if(count==l && b.length()==l+1){
        cout << "Yes";
    }else{
        cout << "No";
    }
        return 0;
}

Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

//各点からpow(2, k)　日進んだ時に行ける点を持っておけば、二部探索できる！！！！！
//ダブリング（初期化O(nlogn),各クエリO(logn)）

void solve() {
	int n; cin >> n;
    vector<int> x(n);
    rep(i, n) {
        cin >> x[i];
    }
    int l, q; cin >> l >> q;
    int r[20][100100], b[30][100100];
    //尺取り法
    int j = 0;
    rep(i, n) {
        while(j < n && x[j] - x[i] <= l) j++;
        r[0][i] = j - 1;
    }
    j = n - 1;
    per(i, n) {
        while(j > -1 && x[i] - x[j] <= l) j--;
        b[0][i] = j + 1;
    }
    //　実は前に進もうが、後ろに進もうが、考えた結果は同じでは？　<- ほんと？？
    for(int k = 0; k + 1 < 20; ++k) {
        rep(i, n) {
            r[k + 1][i] = r[k][r[k][i]];
            b[k + 1][i] = b[k][b[k][i]];
        }
    }
    //1日で確実に1つはいどうする！！
    while(q--) {
        int x, y; cin >> x >> y;
        --x; --y;
        int res = 0;
        if(x < y) {
            for(int k = 19; k >= 0; --k) {
                if(r[k][x] < y) {
                    res += (1<<k);
                    x = r[k][x];
                }
            }
        } else {
            for(int k = 19; k >= 0; --k) {
                if(b[k][x] > y) {
                    res += (1<<k);
                    x = b[k][x];
                }
            }
        }
        cout << res + 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 18560
#include<iostream>
using namespace std;
int main()
{
	int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
if(x+r>w||y+r>h||x<0||y<0)
cout<<"No"<<endl;
else 
cout<<"Yes"<<endl;
return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n;
int f[maxn<<1];
int sum[maxn<<1][2];
inline int find(int x){
	if(f[x]==x) return x;
	return f[x]=find(f[x]);
}
inline void unionn(int x,int y){
	x=find(x);
	y=find(y);
	if(x!=y) f[y]=x;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<maxn<<1;i++) f[i]=i;
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		y+=maxn;
		unionn(x,y);
	}
	for(int i=1;i<maxn<<1;i++) sum[find(i)][i/maxn]++;
	ll ans=0;
	for(int i=1;i<maxn<<1;i++) ans+=(ll)sum[i][0]*sum[i][1];
	printf("%lld\n",ans-n);
	return 0;
}

Measured memory_bytes: 2560
#!/usr/bin/python2

import sys

n = int(sys.stdin.readline())
A = B = 1

for _ in xrange(n):
    a, b = map(int, sys.stdin.readline().split())
    k = max(B/b, A/a)
    while k * b < B or k * a < A:
        k += 1
    A = k * a
    B = k * b
print A + B


Measured memory_bytes: 2568
n, k = list(map(int, input().split()))

w = [0 for i in range(n)]
v = [0 for i in range(n)]

for i in range(n):
    w[i], v[i] = list(map(int, input().split()))


dp = []

for i in range(n+1):
    temp = []
    for j in range(k+1):
        temp.append(0)
    dp.append(temp)


for i in range(1, n+1):
    for j in range(1, k+1):
        if w[i-1] <= j:
            dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])

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

int check(char s[], char t[], int len);

int main(void){
    char s[100] = {'\0'};
    char t[100] = {'\0'};
    int len;
    scanf("%s %s", s, t);
    len = strlen(s);
    if(check(s, t, len)){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

int check(char s[], char t[], int len){
    char tmp;
    int i;
    int j = 0;
    while ( j < len ) {
        if ( !strcmp(s, t) ) {
            return 1;
        }
        tmp = s[0];
        for ( i = 1; i < len; i++ ) {
            s[i-1] = s[i];
        }
        s[len-1] = tmp;
        j++;
    }
    return 0;
}


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

using namespace std;

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

  return gcd(b, a % b);
}

int main(void){
  long long K;
  cin >> K;

  long long ans = 0;

  for (long long ki = 1; ki <= K; ki++) {
    for (long long kj = 1; kj <= K; kj++) {
      long long tmp = gcd(kj, ki);
      for (long long kk = 1; kk <= K; kk++){
        long long tmp2 = gcd(tmp, kk);
        ans += tmp2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
    //Ans+= (ceil(X[i])-1/len);
  }
  return Ans;
}
int main()
{
  long long K;
  cin>>N>>K;
  for(int i=0;i<N;i++)
{
	cin>>X[i];
	//X[i]-=0.1;
}
  long double l=1,r=1e9;
  //while(l<r-0.1)//なぜかOK
	//for(int i=0;i<35;i++)//OK log2(10^9)
  //while(((long long)(r)-(long long)(l)) > 1)
  //while(!((ceil(r)-ceil(l)) == 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  while(!((floor(r)-floor(l)) == 0))//https://atcoder.jp/contests/abc174/submissions/15672399
  {
    //long double mid=(l+r+0.1)/2;
    long double mid=(l+r)/2;
  //  cout<<l<<" "<<r<<" "<<mid<<endl;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
    //else	l=mid+0.01;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}


Measured memory_bytes: 6788
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int a = 1;
  REP(i,N){
    if(A.at(i) == a){
      a++;
    }
  }
  if(a == 1){
    cout << -1 << endl;
  }else{
    cout << N - a + 1 << endl;
  }
}

Measured memory_bytes: 1152
use proconio::marker::*;
use proconio::*;

type Link = Option<Box<Node>>;

const F: usize = 26;

#[derive(Default)]
struct Node {
    cnt: [u32; F],
    next: [Link; F],
}

impl Node {
    fn insert(&mut self, s: &[u8]) -> (usize, usize) {
        if s.is_empty() {
            return (0, 0);
        }
        let k = (s[0] - b'a') as usize;
        let (mut bit, mut ans) = self.next[k]
            .get_or_insert_with(|| Box::new(Node::default()))
            .insert(&s[1..]);
        if s.len() == 1 {
            ans += self.cnt[k] as usize;
        }
        bit |= 1 << k;
        for (i, c) in self.cnt.iter_mut().enumerate() {
            *c += (bit >> i & 1) as u32;
        }
        (bit, ans)
    }
}

fn run() {
    input! {
        n: usize,
        mut s: [Bytes; n],
    }
    let mut root = Box::new(Node::default());
    s.sort_by_key(|s| s.len());
    let mut ans = 0;
    for s in s.iter_mut().rev() {
        s.reverse();
        ans += root.insert(s).1;
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 1 << 29;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| run()).unwrap().join().unwrap();
}


Measured memory_bytes: 661652
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll to, cost;
	bool operator<(const edge& right) const {
		return cost == right.cost ? to < right.to : cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll H, W, N;
vector<point> PV;
set<point> PM;
set<point> visited;
ll ans[10];

ll solv(ll x, ll y) {
	ll count = 0;
	if (x > 1 && x < H && y>1 && y < W) {
		repi(i, 0, 9) {
			point tp;
			tp.x = x + m9x[i], tp.y = y + m9y[i];
			if (PM.find(tp) != PM.end()) count++;
		}
	}
	return count;
}

int main() {
	cin >> H >> W >> N;
	repi(i, 0, N) {
		point P;
		cin >> P.x >> P.y;
		PV.push_back(P);
		PM.insert(P);
	}
	repi(i, 0, N) {
		repi(j, 0, 9) {
			point tp;
			tp.x = PV[i].x + m9x[j], tp.y = PV[i].y + m9y[j];
			if (visited.find(tp) == visited.end()) {
				ll tsum = solv(tp.x, tp.y);
				ans[tsum]++;
				visited.insert(tp);
			}
		}
	}
	ans[0] = (H - 2)*(W - 2);
	repi(i, 1, 10) ans[0] -= ans[i];
	repi(i, 0, 10) wrln(ans[i]);
	return 0;
}


Measured memory_bytes: 64368
#include<stdio.h>
#include<stdlib.h>
#define N 2000

int A[N],n;

int solve(int i,int A[],int m,int B)
{
  int res;
  if(B==0) return 1;

  else if(m >= n) return 0;

  return (solve(n,A,m+1,B) || solve(n,A,m+1,B-A[m]));
}

int main()
{
  int i,j,m,B[200],sum;

  scanf("%d",&n);
  if(n > 20) exit(3);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&m);  
  for(j=0; j<m; j++){
    scanf("%d",&B[j]);    
  }

  for(i=0; i<m; i++){
    sum = solve(n,A,0,B[i]);
    if(sum == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  ll sum=0;
  sum+=1*min(a,k);
  if(k>a)
  { k=k-a;
    sum+=0*min(b,k);
   	if(k>b)
    {
      k=k-b;
      sum+=(-1)*min(c,k);
    }
  }
  cout<<sum<<endl;
}


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

int main() {
  char c;
  cin >> c;
  if ( c == 'a' ) {
    cout << "vowel" << endl;
  }
  else if ( c == 'u' ) {
    cout << "vowel" << endl;
  }
  else if ( c == 'i' ) {
    cout << "vowel" << endl;
  }
  else if ( c == 'e' ) {
    cout << "vowel" << endl;
  }
  else if ( c == 'o' ) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	int target[3];
	cin >> n;
	for(int i = 0; i < 3; i++){
		cin >> target[i];
	}
	int l[10];
	for(int i = 0; i < n; i++){
		cin >> l[i];
	}
	int ans = mod;
	for(int i = 0; i < (1 << (2 * n)); i++){
		int now[3] = {};
		int cnt = 0;
		for(int j = 0; j < n; j++){
			int tmp = (i >> 2 * j) % 4;
			if(tmp == 3) continue;
			now[tmp] += l[j];
			cnt++;
		}
		if(now[0] == 0 || now[1] == 0 || now[2] == 0) continue;
		int res = 0;
		for(int j = 0; j < 3; j++){
			res += abs(target[j] - now[j]);
		}
		res += 10 * (cnt - 3);
		ans = min(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    if N % 2:
        print(0)
        return

    ans = N // 10
    p = 50
    while True:
        tmp = N // p
        if tmp == 0:
            break
        ans += tmp
        p *= 5

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61924
N, M, X = gets.chomp.split(" ").map(&:to_i)
B = Array.new(N).map{
  gets.chomp.split(" ").map(&:to_i)
}

ans = []
(1...(1<<N)).each{|n|
  wk = Array.new(M+1, 0)
  (0..N).each{|k|
    if n[k] == 1 then
      (0..M).each{|m| wk[m] += B[k][m]}
    end
  }
  ans << wk[0] if wk[1..M].all?{|w| w >= X}
}

puts ans.empty? ? -1 : ans.min


Measured memory_bytes: 14384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    string a,b;
    cin >> a >> b;
    if(a=="H"){
        if(b=="H"){
            cout << "H"<<endl;
        }
        else{
            cout << "D"<<endl;
        }
    }
    else{
        if(b=="H"){
            cout << "D"<<endl;
        }
        else{
            cout << "H"<<endl;
        }

    }
    return 0;
}

Measured memory_bytes: 256
fh=int(input())
oh=int(input())
ft=int(input())
x=int(input())
ans=0
for i in range(fh+1):
  for j in range(oh+1):
    for k in range(ft+1):
      if 500*i+100*j+50*k==x:
        ans+=1
print(ans)

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

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, t;
	cin >> n >> t;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int res = 1;
	int mpr = INT_MIN;
	int ma = INT_MAX;
	for (int i = 0; i < n; i++) {
		ma = min(ma, a[i]);
		int diff = a[i] - ma;
		if (diff > mpr) {
			mpr = diff;
			res = 1;
		} else if (diff == mpr) {
			res++;
		}
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359



int main() {
	ll N,M;
	cin >> N >> M;
	cout << (N - 1)*(M - 1) << endl;

	return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,x;cin>>n>>x;
    vector<int>m(n);
    for(int i=0;i<n;i++)
        cin>>m[i];
    int ans=n;
    sort(all(m));
    int sum=0;
    for(int i=0;i<n;i++)
        sum+=m[i];
    cout<<ans+(x-sum)/m[0]<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

#define PI 3.14159265358979323846

typedef complex<double> P;

int H,R,U,M,S,T;
P h[111];
double du,dm,ds;
P t[33];
double d[33];
double w[111],a[111];
int day[111];

bool reach(P house,P tree,double D,double dir,double dist){
	if(abs(house-tree) > dist)return false;
	double ang = arg(house-tree);
	if(ang<0)ang+=2*PI;
	double dif = abs(ang-dir);
	dif = min(dif, 2*PI - dif);
	if(dif > D/2)return false;
	return true;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>H>>R && H){
		fill(day,day+H,0);
		rep(i,H)cin>>h[i].real()>>h[i].imag();
		
		cin>>U>>M>>S>>du>>dm>>ds;
		T=U+M+S;
		rep(i,T){
			cin>>t[i].real()>>t[i].imag();
			if(i<U) d[i]=du;
			else if(i<U+M) d[i]=dm;
			else d[i]=ds;
			d[i]*=PI/180;
		}
		t[T].real()=t[T].imag()=0;
		d[T]=du*PI/180;
		
		rep(i,R){
			cin>>w[i]>>a[i];
			w[i]*=PI/180;
		}
		
		rep(i,H){
			rep(j,R){
				if(!reach(h[i],t[T],d[T],w[j],a[j]))continue;
				int ok=1;
				rep(k,T){
					if(reach(h[i],t[k],d[k],w[j],a[j])){
						ok=0;break;
					}
				}
				day[i]+=ok;
			}
		}
		
		int max=*max_element(day,day+H);
		if(max==0)cout<<"NA"<<endl;
		else{
			vi ans;
			rep(i,H)if(day[i]==max)ans.pb(i+1);
			rep(i,sz(ans))cout<<ans[i]<<(i==sz(ans)-1?"\n":" ");
		}
	}
}

Measured memory_bytes: 1340
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n];
	input(arr,n);
	ll sum=0,val=0,ans=1e18;
	for(ll i=0;i<n;i++)
	sum+=arr[i];
	for(ll i=1;i<n;i++)
	{
		val+=arr[i-1];
		ans=min(ans,abs(sum-2*val));
	}
	cout<<ans;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
else:
    c=[0 for i in range(n)]
    for j in range(n):
        c[j]=a[j]-b[j]
    c=sorted(c,reverse=True)
    d=c.copy()
    first=0
    second=n-1
    flag=True
    while flag:
        if c[second]>=0:
            flag=False
        else:
            if c[first]>=-c[second]:
                c[first]+=c[second]
                c[second]=0
                second-=1
            elif c[first]<-c[second]:
                c[second]+=c[first]
                c[first]=0
                first+=1
    ans=0
    for k in range(n):
        if d[k]!=c[k]:
            ans+=1
    print(ans)

Measured memory_bytes: 18356
def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append([x[i]+l[i], x[i]-l[i]])
    hoge.sort()
    t = -1000000000000000000000
    ans = 0
    for i in range(n):
        if t <= hoge[i][1]:
            ans += 1
            t = hoge[i][0]
    print(ans)
    return 0
 
if __name__ == "__main__":
    solve()

Measured memory_bytes: 27952
#include <bits/stdc++.h> using namespace std;
int main (){
	int A; int B; int X;
	scanf("%d%d%d", &A, &B, &X);
	if (X>=A && B>=(X-A)) {
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())

C = [0] * N
S = [0] * N
F = [0] * N

for i in range(N - 1):
    c, s, f = map(int, input().split())
    C[i] = c
    S[i] = s
    F[i] = f

for i in range(N - 1):
    arrive = S[i] + C[i]
    for j in range(i + 1, N - 1):
        if arrive < S[j]:
            arrive = S[j] + C[j]
        elif arrive % F[j] == 0:
            arrive += C[j]
        else:
            w = F[j] - (arrive % F[j])
            arrive += C[j] + w
    print(arrive)
print(0)



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

int a[100010];

int main() {
	// your code goes here
	int i, j, k, n, ans=0;
	cin>>n;
	for(i=1; i<=n; ++i) {
		cin>>a[i];
	}
	for(i=1; i<=n; ++i) {
		if(a[a[i]]==i) {
			ans++;
		}
	}
	cout<<ans/2;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
int h,w;
char table[110][110];
int cnt = 0;



int main(){
   queue<ll>a;
  ll k;  cin >> k;
  
  for(int i=1;i<10;i++)a.push(i);

  while(1){
     ll x = a.front(); a.pop();
     cnt++;
     if(cnt == k){
        cout << x << endl;
        return 0;
     }

     if((x%10)-1>=0)a.push( x*10+(x%10-1) ) ;
     a.push( 10*x+x%10 );
     if((x%10)+1<=9)a.push( x*10+(x%10+1) );
     
     }

   
  }

  
  




Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int n = s.length();
    int a, z;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = n-1; i >= 0; --i) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    int ans = z-a+1;
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 640
od ="RUD"
ev="LUD"
res = "Yes"
s = raw_input()
for i in xrange(len(s)):
    if i%2 ==0 :
        if s[i] not in od:
            res = "No"
            break
    else:
        if s[i] not in ev:
            res = "No"
            break
print res

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

using ll = long long;

const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++)
        cin >> P[i];
    for (int i = 0; i < N; i++)
        cin >> Q[i];
    vector<int> perm(N);
    iota(perm.begin(), perm.end(), 1);
    int a, b;
    int i = 0;
    do {
        if (perm == P)
            a = i;
        if (perm == Q)
            b = i;
        i++;
    } while (next_permutation(perm.begin(), perm.end()));
    cout << abs(a - b) << endl;
}

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

#define fi first
#define se second

const int N = 4020;
const int mod = 998244353;

using namespace std;

void add(int &x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        } else if(x < 0){
                x += mod;
        }
}

int n, k;
int p[N];
int c[N][N];

int get(int a, int b, int n)
{
        int res = 0;
        for(int i = 0; i <= a; i++){
                int cur = p[i] * 1ll * c[a][i] % mod;
                //cout << cur << ' ';
                cur = 1ll * cur * c[n + b - 1][i + b - 1] % mod;
                //cout << cur << "\n";
                add(res, cur);
        }
        return res;
}

int solve(int X)
{
        int A = 0, B = 0, C = 0;
        for(int i = 1; i <= k; i++){
                int j = X - i;
                if(j >= 1 && j <= k){
                        if(i == j){
                                C = 1;
                        } else{
                                A += 1;
                        }
                } else{
                        B += 1;
                }
        }
        int res = 0;
        //cout << A << " " << B << " " << C << "\n";
        add(res, get(A / 2, B, n));
        //cout << res << endl;
        //exit(0);
        if(C){
                add(res, get(A / 2, B, n - 1) % mod);
        }
        return res;
}

int main()
{
        ios_base::sync_with_stdio(false);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        p[0] = 1;
        for(int i = 1; i < N; i++){
                p[i] = p[i - 1];
                add(p[i], p[i]);
        }
        for(int i = 0; i < N; i++){
                c[i][0] = c[i][i] = 1;
                for(int j = 1; j < i; j++){
                        c[i][j] = c[i - 1][j];
                        add(c[i][j], c[i - 1][j - 1]);
                }
        }


        cin >> k >> n;

        //cout << solve(3) << endl;
        //return 0;

        for(int i = 2; i <= 2 * k; i++){
                cout << solve(i) << "\n";
        }
}


Measured memory_bytes: 61952
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
int main(){
	int a,b;
  	cin >> a >> b;
	if(a < 10 and a > 0 and b < 10 and b > 0)
    	cout << a*b;
	else
      	cout <<"-1";
 
	return 0;
}


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

using namespace std;

const int limit = 1000000;
int N, A, B, C;
int l[8];

int dfs(int n, int a, int b, int c) {
    int result = limit;
    if (n == N) {
        if (a > 0 && b > 0 && c > 0) {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        }
        return result;
    }
    result = min(result, dfs(n + 1, a, b, c));
    result = min(result, dfs(n + 1, a + l[n], b, c) + 10);
    result = min(result, dfs(n + 1, a, b + l[n], c) + 10);
    result = min(result, dfs(n + 1, a , b, c+ l[n]) + 10);
    return result;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; ++i) {
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    StringBuilder ans = new StringBuilder();
    for(int cnt = 1; cnt<=s.length(); cnt++){
      ans.append("x");
    }
    System.out.println(ans.toString());
  }
}

Measured memory_bytes: 21332
n = gets.chomp.to_i
data = []
n.times do |i|
    data[i] = []
    a = gets.chomp.to_i
    a.times do
        x, y = gets.chomp.split.map(&:to_i)
        data[i].push([x-1, y == 1])
    end
end

ans = 0
[true, false].repeated_permutation(n) do |bit|
    next_flag = false
    bit.each_with_index do |bool, index|
        remarks = bool ? data[index] : []
        next_flag = true if remarks.any? { |x, y| bit[x] != y  }
    end
    next if next_flag
    ans = [ans, bit.count(true)].max
end

puts ans


Measured memory_bytes: 1788
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    ls=[input() for i in range(n)]
    m=int(input())
    lt=[input() for i in range(m)]
    lbutu=list(set(ls)|set(lt))
    kosu=len(lbutu)
    lnum=[0]*kosu
    for j in ls:
        for k in range(kosu):
            if j==lbutu[k]:
                lnum[k]+=1
    for j in lt:
        for k in range(kosu):
            if j==lbutu[k]:
                lnum[k]-=1
    if max(lnum)<0:
        print(0)
    else:
        print(max(lnum))

resolve()

Measured memory_bytes: 38640
N, Q = map(int, input().split())
S = input()

A = [0]
for s in range(1, N):
  if S[s] == "C" and S[s-1] == "A":
    A.append(A[-1] + 1)
  else:
    A.append(A[-1])

A.insert(0, 0)

for q in range(Q):
  s, t = map(int, input().split())
  print(A[t]-A[s])

Measured memory_bytes: 6100
#include<stdio.h>
int main(){
	int a[5];
	int i,j,tmp;
	for(i=0;i<5;i++)
		scanf("%d",&a[i]);
	for(i=0;i<4;i++){
		for(j=i+1;j<5;j++){
			if(a[i]<a[j]){
				tmp=a[i];
				a[i]=a[j];
				a[j]=tmp;
			}
		}
	}
	for(i=0;i<4;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[4]);
	return 0;
}

Measured memory_bytes: 596
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

x = III()

ans = 0
while 1:
    x.sort()
    if x[0]==x[2]:
        break
    elif x[1]!=x[2]:
        x[0] += 1
        x[1] += 1
        ans += 1
    else:
        x[0] += 2
        ans += 1

print(ans)

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

int main() {
  long long N;
  cin >> N;
  long long a = 0;
  for (long long i = 1; i * i <= N; ++i)
    if (N % i == 0)
      a = i;
  cout << a + N / a - 2 << endl;
}

Measured memory_bytes: 256