akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

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

    vector<vector<int>> W(h + 10, vector<int>(w + 10, 0));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '.') W[i + 1][j + 1] = W[i + 1][j] + 1;
        }

        int Wmax = W[i + 1][w];
        for(int j=w-1; j>=0; j--){
            if(j + 1 < w && s[i][j] == '.' && s[i][j + 1] == '#') Wmax = W[i + 1][j + 1];
            W[i + 1][j + 1] = Wmax;
        }
    }

    /*
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout << W[i][j] << " ";
        }
        cout << endl;
    }*/

    vector<vector<int>> H(h + 10, vector<int>(w + 10, 0));
    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if(s[j][i] == '.') H[j + 1][i + 1] = H[j][i + 1] + 1;
        }

        int Hmax = H[h][i + 1];
        for(int j=h-1; j>=0; j--){
            if(j + 1 < h && s[j][i] == '.' && s[j + 1][i] == '#') Hmax = H[j + 1][i + 1];
            H[j + 1][i + 1] = Hmax;
        }
    }

    /*
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout << H[i][j] << " ";
        }
        cout << endl;
    }*/

    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '#') continue;
            //cout << i << " " << j << endl;
            //cout << W[i + 1][j + 1] + H[i + 1][j + 1] - 1 << endl;
            ans = max(ans, W[i + 1][j + 1] + H[i + 1][j + 1] - 1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 36096
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

VI g[100010];
int cnt[100010];
signed main(void)
{
	int n;
	cin >> n;
	REP(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].PB(b);
		g[b].PB(a);
		cnt[a]++;
		cnt[b]++;
	}

	set<int> s;
	REP(i, n) if(cnt[i] == 1) s.insert(i);

	bool used[100010] = {false};
	while(s.size()) {
		int h = *s.begin(); s.erase(s.begin());
		REP(i, g[h].size()) {
			if(used[g[h][i]]) continue;
			used[h] = used[g[h][i]] = true;
			REP(j, g[h].size()) if(!used[g[h][j]]) {
				cnt[g[h][j]]--;
				if(cnt[g[h][j]] == 0) {cout << "First" << endl; return 0;}
				if(cnt[g[h][j]] == 1) {s.insert(g[h][j]);}
			}
			REP(j, g[g[h][i]].size()) if(!used[g[g[h][i]][j]]) {
				cnt[g[g[h][i]][j]]--;
				if(cnt[g[g[h][i]][j]] == 0) {cout << "First" << endl; return 0;}
				if(cnt[g[g[h][i]][j]] == 1) {s.insert(g[g[h][i]][j]);}
			}
			break;
		}
	}
	cout << "Second" << endl;
	return 0;
}


Measured memory_bytes: 8704
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int N,K;
    int A[200010]={0};
    int An[200010]={0};
    cin>>N>>K;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }

    int i=1;
    int n=1;
    K--;
    while(K>=0){
        if(An[n]!=0){
            int diff=i-An[n];
            K%=diff;
        }
        An[n]=i;
        i++;
        K--;
        n=A[n];
    }

    cout<<n<<endl;
}


Measured memory_bytes: 6312
/*
 * C.cpp
 *
 *  Created on: 2017/07/09
 *      Author: aihara
 */
#include <bits/stdc++.h>
//#define MYDEBUG
#ifdef MYDEBUG
#define dbp(a) cout<<#a<<": "<<a<<endl
#define dbp2(a,b) cout<<#a<<","<<#b<<": "<<a<<","<<b<<endl
#define dbp3(a,b,c) cout<<#a<<","<<#b<<","<<#c<<": "<<a<<","<<b<<","<<c<<endl
#define dbp4(a,b,c,d) cout<<#a<<","<<#b<<","<<#c<<","<<#d<<": "<<a<<","<<b<<","<<c<<","<<d<<endl
#else
#define dbp(a)
#define dbp2(a,b)
#define dbp3(a,b,c)
#define dbp4(a,b,c,d)
#endif
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define rep(i,from,to) for(ll i=from; i<to; ++i)
#define REP(i,from,to) for(ll i=from; i<=to; ++i)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i] << endl;
	}
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
	out << "[";
	size_t last = v.size() - 1;
	for (size_t i = 0; i < v.size(); ++i) {
		out << v[i];
		if (i != last) {
			out << ",";
		}
	}
	out << "]";
	return out;
}
template<typename T>
ostream& operator<<(ostream& out, const pair<T, T>& p) {
	cout << "(" << p.first << ", " << p.second << ")";
	return out;
}

bool cmp(P p1, P p2) {
	return p1.first * p1.second < p2.first * p2.second;
}
static const ll MAX_N = 110;
static const ll MAX_W = 110;
int N, W, D;
vector<P> cake;

PP cut(P c, int s) {
	int w = c.first;
	int d = c.second;
	int pos = s % (w + d);
	if (pos < w) { //   |
		int w1 = pos, d1 = d;
		int w2 = w - w1, d2 = d;
		P p1 = P(w1, d1);
		P p2 = P(w2, d2);
		if (cmp(p1, p2)) {
			return PP(p1, p2);
		} else {
			return PP(p2, p1);
		}
	} else { // ----
		int w1 = w, d1 = pos - w;
		int w2 = w, d2 = d - d1;
		P p1 = P(w1, d1);
		P p2 = P(w2, d2);
		if (cmp(p1, p2)) {
			return PP(p1, p2);
		} else {
			return PP(p2, p1);
		}
	}

}

void solve() {
	while (cin >> N >> W >> D, N || W | D) {
		cake = vector<P>();
		cake.push_back(P(0, 0));
		cake.push_back(P(W, D));
		rep(i,0,N)
		{
			int p, s;
			cin >> p >> s;
			P target = cake[p];
			PP split = cut(target, s);
			dbp3(p, target.first, target.second); dbp(cake);
			cake.erase(cake.begin() + p, cake.begin() + p + 1);
			dbp(cake);
			cake.push_back(split.first);
			cake.push_back(split.second);
			dbp(cake);
		}
		sort(all(cake), cmp);
		dbp(cake);
		size_t last = cake.size() - 1;
		for (size_t i = 1; i < cake.size(); ++i) {
			cout << cake[i].first * cake[i].second;
			if (i != last) {
				cout << " ";
			}
		}
		cout << endl;
	}
}

int main() {
	solve();

}

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

int main(){
    int n,ma,mb;
    cin>>n>>ma>>mb;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[410][410];
    int INF=1e9;
    for(int i=0;i<410;i++)for(int j=0;j<410;j++) dp[i][j]=INF;
    dp[0][0]=0;

    for(int i=0;i<n;i++)for(int j=400;j>=a[i];j--)for(int k=400;k>=b[i];k--){
        dp[j][k]=min(dp[j][k],dp[j-a[i]][k-b[i]]+c[i]);
    }

    int ans=INF;
    for(int i=1;i*max(ma,mb)<=400;i++){
        ans=min(ans,dp[ma*i][mb*i]);
    }
    if(ans==INF){
        cout<<-1<<endl;
        return 0;
    }

    cout<<ans<<endl;

    
}

Measured memory_bytes: 896
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> h[i];
  for (int i = 0; i < n; ++i) {
    if (h[i]) {
      swap(x[0], x[i]);
      swap(y[0], y[i]);
      swap(h[0], h[i]);
      break;
    }
  }
  for (int i = 0; i <= 100; ++i) {
    for (int j = 0; j <= 100; ++j) {
      int H = h[0] + abs(x[0] - i) + abs(y[0] - j);
      bool ok = true;
      for (int k = 1; k < n; ++k) {
        if (max(H - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << i << " " << j << " " << H << endl;
        return 0;
      }
    }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];

    vector<ll> s(n+1);
    s[0] = a[0];
    for(ll i = 1; i < n; i++){
        s[i] = s[i - 1] + a[i];
    }

    map<ll, ll> m;
    m[0] = 1;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        ans += m[s[i]];
        m[s[i]]++;
    }

    cout << ans << endl;
    return 0;
}

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

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

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

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

void Solve(){
    int n; cin >> n;
    vll a(n); rep(i, n) cin >> a[i];
    string s; cin >> s;
    
    vll bases;
    
    rep3rev(i, n-1, 0){
        for(auto base : bases){
            chmin(a[i], a[i]^base);        
        }
        if(a[i]){
            if(s[i] == '0'){
                bases.pb(a[i]);
            }else{
                cout << 1 << endl;
                return;
            }
        }
    }
    cout << 0 << endl;
    return;
}    

void Main() {
    // AGC045 - A - Xor Battle //
    int t; cin >> t;
    while(t--){
        Solve();
    }
	return;
}

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

Measured memory_bytes: 3624
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
LL a , b;
void init(){
  a = getint();
  b = getint();
}
LL go( int bt , LL l , LL r ){
  l %= (1ll << (bt + 1));
  r %= (1ll << (bt + 1));
  if( bt == 0 ) return r - l + 1;
  if( ( ( l >> bt ) & 1ll ) ==
      ( ( r >> bt ) & 1ll ) )
    return go( bt - 1 , l , r );
  LL ret = (1ll << bt) - l;
  int lst = -1;
  for( int j = bt - 1 ; j >= 0 ; j -- )
    if( ( r >> j ) & 1ll ){
      lst = j;
      break;
    }
  l %= (1ll << bt);
  //printf( "%d %lld %lld ret=%lld lst=%d\n" ,
          //bt , l , r , ret , lst );
  if( lst == -1 ){
    ret ++;
    return ret + go( bt - 1 , l , (1ll << bt) - 1 );
  }
  LL cc = (1ll << ( bt - lst - 1 )) - ( l >> ( lst + 1 ) );
  ret += cc * (1ll << (lst + 1));
  //printf( "%d %lld %lld ret=%lld lst=%d cc=%lld\n" ,
          //bt , l , r , ret , lst , cc );
  if( ( l >> ( lst + 1 ) ) ){
    ret += go( lst , l % (1ll << (lst + 1)) ,
                     ( l % (1ll << (lst + 1)) ) |
                     ( (1ll << (lst + 1)) - 1) );
  }
  return ret;
}
void solve(){
  cout << go( 59 , a , b ) << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
//Author:: Pham Ngoc Minh- Chuyen Thai Binh
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
int const maxn=1e5+5;
int n,dp[5][maxn],a,b,c;
int main()
{
    bost
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>b>>c;
        dp[1][i]=max(dp[2][i-1],dp[3][i-1])+a;
        dp[2][i]=max(dp[1][i-1],dp[3][i-1])+b;
        dp[3][i]=max(dp[1][i-1],dp[2][i-1])+c;
    }
    cout<<max(dp[1][n],max(dp[2][n],dp[3][n]));
    return 0;
}
// I love Chuyen Thai Binh Verry much ! Now, you alaways in my code of me <3
// Chuyen Thai Binh La Nha :>>


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> d(k);
	for(int i = 0; i < k; i++){
		cin >> d[i];
	}

	for(int x = n; x < 100000; x++){
		int tmp = x;
		set<int> s;
		while(tmp!=0){
			s.insert(tmp%10);
			tmp /= 10;
		}
		bool flag = true;
		
		for(int i = 0; i < k; i++){
			if(s.count(d[i])) flag = false;
		}
		if(flag){
			cout << x << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

class Eratosthenes{
public:
    vector<bool>is_prime;
    vector<int> P;
    Eratosthenes( const int N )
    {
        is_prime.resize(N+3);
        for( int i = 0; i <= N; i++ )
        {
            is_prime[ i ] = true;//初期化
        }    
        for( int i = 2; i <= N; i++ )
        {
            if( is_prime[ i ] )
            {
                for( int j = 2 * i; j <= N; j += i )
                {
                    is_prime[ j ] = false;
                }
                P.emplace_back( i );
            }
        }
    }
};

int main(){
    init();
	ll N;cin>>N;
	
	vector<ll>count(N+1,0);
	for(int i=1;i<=N;i++){
		ll num=i;
		ll index=2;
		while(num!=1){
			if(num%index==0){
				num/=index;
				count[index]++;
			}else index++;
		}
	}
	ll count2=0;
	ll count4=0;
	ll count14=0;
	ll count24=0;
	ll count74=0;
	for(int i=0;i<=N;i++){
		if(count[i]>=2)count2++;
		if(count[i]>=4)count4++;
		if(count[i]>=14)count14++;
		if(count[i]>=24)count24++;
		if(count[i]>=74)count74++;
	}
	ll ans=0;
	ans+=count74;
	ans+=(count24*(count2-1));
	ans+=(count14*(count4-1));
	ans+=(count4*(count4-1)/2*(count2-2));
	cout<<ans<<endl;
			
}

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

#define db double
const db eps = 1e-6;
int sgn(db a, db b = 0) {
	a -= b;
	return (a > eps) - (a < -eps);
}

struct poi {
	db x, y;
	void r() { cin >> x; cin >> y; }
	void w() { cout << x << ' ' << y << '\n'; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	poi operator +(poi p) {
		return {x + p.x, y + p.y};
	}
	poi operator *(db d) {
		return {x * d, y * d};
	}
	poi operator /(db d) {
		return {x / d, y / d};
	}
	bool operator ==(poi p) {
		return !sgn(x, p.x) && !sgn(y, p.y);
	}
	db dot(poi p) {
		return x * p.x + y * p.y;
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
	db len2() { return x * x + y * y; }
	poi proj(poi p, poi q) {
		db s = (*this - p).dot(q - p) / (q - p).len2();
		return p + (q - p) * s;
	}
};
db xmul(poi a, poi b, poi c) {
	return (b - a).cross(c - a);
}

int ccw(poi a, poi b, poi c) {
	poi u = b - a, v = c - a;
	if(u.cross(v) > eps) return 1;
	if(u.cross(v) < -eps) return -1;
	if(u.dot(v) < -eps) return -2;
	if(u.len2() + eps < v.len2()) return 2;
	return 0;
}
bool si(poi a, poi b, poi c, poi d) {
	return ccw(a, b, c) * ccw(a, b, d) <= 0 &&
		ccw(c, d, a) * ccw(c, d, b) <= 0;
}
poi li(poi a, poi b, poi c, poi d) {
	db u = xmul(c, d, a), v = xmul(c, d, b);
	return (a * v - b * u) / (v - u);
}

int main() {
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int T; cin >> T;
	while(T --) {
		poi p0, p1, p2, p3; p0.r(); p1.r(); p2.r(); p3.r();
		if(p0 == p2 || p0 == p3) p0.w();
		else if(p1 == p2 || p1 == p3) p1.w();
		else
			li(p0, p1, p2, p3).w();
	}

	return 0;
}

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



int main() 
{ 
	
	string s;
	cin>>s;
	int n = s.size();
	char mev[s.size()+1];
	strcpy(mev, s.c_str());
	int pal = 1;
	for(int i= 0;i<(n-1)/2;i++){
		if(mev[i]!=mev[((n-1)/2)-i-1]){
			pal  = 0;
			break;
		}
	}
	for(int i= 0;i<n;i++){
		if(mev[i]!=mev[n-i-1]){
			pal  = 0;
			break;
		}
	}
	if(pal){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
    return 0; 
} 


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % nmax, N / 2) % nmax;
  else return A * Pow(A * A % nmax, N / 2) % nmax;
}

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

  vector <ll> cnt(1e6);
  for (int i = 0; i < N; i++){
    ll num = A[i];
    for (int j = 2; j * j <= A[i]; j++){
      ll now = 0;
      while (num % j == 0){
        now++; num /= j;
      }
      cnt[j] = max(cnt[j], now);
    }
    cnt[num] = max(cnt[num], 1ll);
  }

  ll ans = 1;
  for (ll i = 2; i < 1e6; i++){
    ans *= Pow(i, cnt[i]);
    ans %= nmax;
  }
  
  ll now = 0;
  for (int i = 0; i < N; i++){
    now += Pow(A[i], nmax - 2);
    now %= nmax;
  }
  ans = ans * now;
  ans %= nmax;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
const int MAXA = 26;
const int MAXN = 1e4+5;
char S[MAXN];
int N;

char advance(char c) {
  return ((c - 'A') + N) % MAXA + 'A';
}

int main() {
  scanf(" %d%s", &N, S);
  for (char *ptr = S; *ptr; ++ptr) {
    *ptr = advance(*ptr);
  }
  puts(S);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define X first
#define Y second
 
 
int main() {
ll n;
cin>>n;
vector<pair<ll,ll>> ans;
ll a[n];
for(int i=0;i<n;i++)
    cin>>a[i];
sort(a,a+n);
if(a[0]>=0)
{
    for(int i=1;i<n-1;i++)
    ans.pb({a[0],a[i]}),a[0]-=a[i];
    ans.pb({a[n-1],a[0]});
}
else if(a[n-1]<=0)
{
    for(int i=n-2;i>0;i--)
        ans.pb({a[n-1],a[i]}),a[n-1]-=a[i];
    ans.pb({a[n-1],a[0]});
}
else
{
    for(int i=1;i<n-1;i++)
        if(a[i]>0)
            ans.pb({a[0],a[i]}),a[0]-=a[i];
        else
            ans.pb({a[n-1],a[i]}),a[n-1]-=a[i];
    ans.pb({a[n-1],a[0]});
}
auto z=ans.back();
 cout<<z.first-z.second<<endl;
 for(auto i:ans)
 {
     cout<<i.first<<" "<<i.second<<endl;
 }
return 0;
}

Measured memory_bytes: 4336
<?php
/*
    Problem URL : http://abc056.contest.atcoder.jp/tasks/abc056_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%s %s", $a, $b);

switch ($a) {
    case "H":
        $a = true;
        break;
    case "D":
        $a = false;
        break;
}
if ($b == "D") {
    $a = !$a;
}
echo $a === true ? "H\n" : "D\n";


Measured memory_bytes: 4604
let modulo = 1000000007
let (+@) a b = (a + b) mod modulo
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let b = Array.make (n+1) 0 in
  a |> Array.iter (fun v -> b.(v) <- -1);
  b.(0) <- 1;
  for i = 1 to n do
    if b.(i) >= 0 then begin
      if i > 1 then b.(i) <- b.(i) +@ b.(i-2);
      b.(i) <- b.(i) +@ b.(i-1)
    end else b.(i) <- 0
  done;
  Printf.printf "%d\n" b.(n)


Measured memory_bytes: 5376
def combinations(n,k,mod):
    x,y = 1,1
    for i in range(k):
        x = (x*(n-i))%mod
        y = (y*(i+1))%mod
    return (x*pow(y,mod-2,mod))%mod
    

div = 10**9+7
n,a,b = map(int,input().split())

cn = pow(2,n,div)-1
ca = combinations(n,a,div)
cb = combinations(n,b,div)

print((cn-ca-cb)%div)

Measured memory_bytes: 38512
#include <stdio.h>

using namespace std;

void data_print(int A[], int N) {
	for (int i = 0; i < N; i++) {
		if (i>0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}
void sort(int A[], int N) {
	int i, j;
	for (i = 1; i < N; i++) {
		int v = A[i];
		j = i - 1;
		while ((A[j] > v) && j >= 0) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		data_print(A, N);
	}
}
int main()
{
	int N;
	int A[100];

	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	data_print(A, N);
	sort(A, N);

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    vector<pair<ll,ll>> p;
    ll N;
    cin >> N;
    for(ll i=0;i<N;i++){
        ll A,B;
        cin >> A >> B;
        p.push_back(make_pair(A,i*2+0));
        p.push_back(make_pair(B,i*2+1));
    }
    sort(p.begin(),p.end());

    bool allsame=true;
    bool checked[100000];
    ll sum=0;
    for(int i=0;i<N;i++) checked[i]=false;
    for(ll i=0;i<N;i++){
        allsame=(allsame && (p[0].second%2)==(p[i].second%2));
        checked[p[i].second/2]=true;
        sum+=p[i].first;
    }
    for(int i=0;i<N;i++){
        if(checked[i]==false){
            cout << sum << endl;
            return 0;
        }
    }
    if(allsame){
        cout << sum << endl;
        return 0;
    }
    if(p[N-1].second/2!=p[N].second/2){
        cout << sum-p[N-1].first+p[N].first << endl;
    }else{
        cout << min(sum-p[N-1].first+p[N+1].first,sum-p[N-2].first+p[N].first) << endl;
    }

    
    return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
int a[100000 + 5], b[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int amax = 0;
    int bmin = 1e10;
    rep(i, n) {
        cin >> a[i] >> b[i];
        amax = max(amax, a[i]);
        bmin = min(bmin, b[i]);
    }
    cout << amax + bmin << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
char a[50] ;
char b[50];
char c[50];
int main()
{
    int l1,l2,l3;
    scanf("%s %s %s",a,b,c);
    l1= strlen(a);
    l2=strlen(b);
    l3=strlen(c);

    if(a[l1-1]==b[0] && b[l2-1]==c[0])
        printf("YES\n");
    else
       printf("NO\n");

}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x,y,z,y1,x1;
    scanf("%d",&x);
    y=x/60;
    z=y/60;
    y1=y%60;
    x1=x%60;

    printf("%d:%d:%d\n",z,y1,x1);
    
    return 0;
}


Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
using namespace std;
int main() {
	while (true) {
		int n;
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0;i < n;++i) {
			int m, e, j;
			scanf("%d%d%d", &m, &e, &j);
			if (m == 100 || e == 100 || j == 100 || (m + e) / 2 >= 90 || (m + e + j) / 3 >= 80) {
				printf("A\n");
			}
			else if ((m + e + j) / 3 >= 70 || ((m + e + j) / 3 >= 50 && (m >= 80 || e >= 80))) {
				printf("B\n");
			}
			else {
				printf("C\n");
			}
		}
	}
}


Measured memory_bytes: 1168
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    y = sorted(x)
    r = y[n // 2]
    l = y[n // 2 - 1]
    
    for i in range(n):
        if x[i] <= l:
            yield r
        else:
            yield l

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 25052
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll N, K;
	cin >> N >> K;
	vector<ll> A(N, 0LL);
	vector<ll> imos(N + 1, 0LL);
	rep(i, N){
		cin >> imos[i];
	}
	vector<ll> imos2(N + 1, 0LL);
	rep(i, min(1000LL, K)){
		rep(j, N){
			ll l = j - imos[j];
			ll r = min(j + imos[j] + 1, N);
			l = max(l, 0LL);
			// print(l, r);
			imos2[l]++;
			imos2[r]--;
		}
		rep(j, N){
			imos2[j+1] += imos2[j];
		}
		rep(j, N+1){
			imos[j] = imos2[j];
			imos2[j] = 0;
		}
	}

	rep(j, N){
		if(j) cout << " ";
		cout << imos[j];
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 7912
#include <stdio.h>
int A[51];
void make_table();
int main(){


	int a;
	make_table();
	while((scanf("%d",&a))!=EOF)printf("%d\n",A[a]);

	return 0;
}

void make_table(){

	int i,j,k,l;
	for(i=0;i<=9;i++){
	for(j=0;j<=9;j++){
	for(k=0;k<=9;k++){
	for(l=0;l<=9;l++){
		A[i+j+k+l]++;
	}
	}
	}
	}
}

Measured memory_bytes: 596
#include <algorithm>
 #include <iostream>
 #include <vector>
 using namespace std;
 typedef long long ll;
 const int INF = 1 << 30;
 const ll INFll = 1ll << 60;
 
 int main() {
	int p, q, r;
	cin >> p >> q >> r;

	int ans = min({p+q, q+r, r+p});

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
typedef long long ll;
ll source[200005],tmp[200005];
ll co=0;
void mergesort(int st,int mid,int en)
{
    int i=st,j=mid+1,k=st;
    while(i!=mid+1&&j!=en+1)
    {
        if(source[i]<=source[j]) tmp[k++]=source[i++];
        else
        {
            tmp[k++]=source[j++];
            co+=i-st;
        }
    }
    while(i!=mid+1)
        tmp[k++]=source[i++];
    while(j!=en+1)
    {
        tmp[k++]=source[j++];
        co+=i-st;
    }
    for(i=st;i<=en;++i)
        source[i]=tmp[i];
}
void merge_sort(int st,int en)
{
    if(st<en)
    {
        int mid=(st+en)/2;
        merge_sort(st,mid);
        merge_sort(mid+1,en);
        mergesort(st,mid,en);
    }
}
int main()
{
    int n,k,f;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&f);
        source[i]=f-k+source[i-1];
    }
    merge_sort(0,n);
    cout<<co<<endl;
    return 0;
}


Measured memory_bytes: 3328
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), count = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            if (a != b) {
                count = 0;
                continue;
            }
            count++;
            if (count == 3) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
	}
}

Measured memory_bytes: 36000
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
#define INF 1 << 30
using namespace std;
typedef pair<int, int> PII;
typedef priority_queue<PII, vector<PII>, greater<PII> > PQ;

int root[101][101], n, k; //not use 0;

void newboat()
{
	int c, d, e;
	cin >> c >> d >> e;
	if (root[c][d] > e)	root[c][d] = root[d][c] = e;
	return;
}

int solve()
{
	int a, b, ans = INF;
	cin >> a >> b;
	bool though[101][101], cost[101]; //not use 0;
	PQ cand;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++) though[i][j] = false;
		cost[i] = false;
	}

	cand.push(make_pair(0, a));
	while (!cand.empty()){
		PII now = cand.top();
		cand.pop();
		if (cost[now.second]) continue;
		if (now.second == b) return now.first;
		cost[now.second] = true;

		for (int i = 1; i <= n; i++){
			if (root[now.second][i] != INF && !though[now.second][i] && !cost[i]){
				though[now.second][i] = though[i][now.second] = true;
				cand.push(make_pair(now.first + root[now.second][i], i));
			}
		}
	}
	return -1;
}

int main()
{
	while (true){
		cin >> n >> k;
		if (!n && !k) break;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				root[i][j] = INF;
			}
		}
		for (int i = 0; i < k; i++){
			bool in;
			cin >> in;
			if (in) newboat();
			else cout << solve() << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1264
/*
Author: Fuadul Hasan(fuadul202@gmail.com)
BSMRSTU,Gopalganj
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
//#include<bits/stdc++.h>
using namespace std;
 
int         cinn()              {int x; scanf("%d", &x); return x;}
long long   scll()              {long long x; scanf("%lld", &x); return x;}
double      scd()               {double x; scanf("%lf", &x); return x;}
void        coutt(int x)        {printf("%d ", x);}
 
#define  scll                   scll()
#define  gcd(a,b)               __gcd(a,b)
#define  lcm(a,b)               (a*b)/gcd(a,b)
#define  PI                     acos(-1.0)
#define  vi                     std::vector<int>
#define  vll                    std::vector<ll>
#define  vit                    vector<int> :: iterator
#define  sit                    set<int> :: iterator
#define  mpsi                   std::map<string, int>
#define  pb                     push_back
#define  ll                     long long int
#define  ld                     long double
#define  ull                    unsigned long long int
#define  min3(a,b,c)            min(a,min(b,c))
#define  min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define  max3(a,b,c)            max(a,max(b,c))
#define  max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define  nl                     printf("\n");
#define  no                     printf("No");
#define  yes                    printf("Yes");
#define  F                      first
#define  S                      second

typedef pair<int,int> ii;
typedef std::vector<ii> vii;
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
//const int N             = 1e6 + 5;
const int nn           = 3e5 + 5;

int a[nn];
int t[nn];

int solve()
{
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string s1;
	cin>>s1;
	if(s1==s){
		a--;
	}else {
		b--;
	}
	cout<<a<<" "<<b<<endl;
}

int main()
{
    int test = 1, tc = 0;
    //scanf("%d", &test);
   // (void)getchar();
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
 
    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[] a;
        a = new int[100];

        int[] b;
        b = new int[100];

        int i = 0;
        while(true){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();

            if(a[i]==0 && b[i]==0)
                break;

            i++;
        }

        i=0;
        while(true){
            for(int j = 0;j<a[i];j++){
                for(int k = 0;k<b[i];k++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
            i++;
            if(a[i]==0 && b[i]==0)
                break;
        }
    }
}



Measured memory_bytes: 34428
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int N; cin >> N;
    vec A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    int ans = 0;
    IREP(i, N){
        int tmp = (ans + A[i] + B[i] - 1) / B[i] * B[i];
        ans += tmp - (ans + A[i]);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int A,B,H,M;
    cin >> A >> B >> H >> M;
    double pi=M_PI;
    double b=2*pi*M;
    b = b/60;
    double a=2*pi*(H*60+M);
    a = a/(60*12);
    double c;
    if(a>b) c=a-b;
    else c=b-a;
    if(c>pi) c=2*pi-c;
    c=cos(c);
    double d=A*A+B*B;
    d = d-2*A*B*c;
    double e=pow(d,0.5);
    cout << fixed << setprecision(24);
    cout << e << endl;
    return 0;
}

Measured memory_bytes: 4312
import numpy as np

N, M = list(map(int, input().split()))

lst = [[] for i in range(N)]
for i in range(M):
  p, S = input().split()
  p = int(p) - 1
  lst[p].append(S == 'AC')

ac = 0
wa = 0
for Q in lst:
  tmp_wa = 0
  for q in Q:
    if q == True:
      ac += 1
      wa += tmp_wa
      break
    else:
      tmp_wa += 1

print('{:d} {:d}'.format(ac, wa))

Measured memory_bytes: 23776
#include<iostream>
using namespace std;
int main(){
	int M,N;
	cin>>M>>N;
	int K[M];
	int ANS[N];
	int intoA[30][30];
	for(int i = 0; i < N; i++){
		ANS[i] = 0;
	}
	for(int i = 0; i < M; i++){
		cin>>K[i];
		for(int j = 0; j < K[i]; j++){
			cin>>intoA[j][i];
		}
	}
	int out[N];
	int p = 0;
	for(int i = 0; i < N; i++){
		out[i] = 0;
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			for(int l = 0; l < K[j]; l++){
				if(intoA[l][j] == i+1){
					ANS[i]++;
				}
			}
		}
		if(ANS[i] == M){
			out[p] = i - 1;
			p++;
		}
	}
	
		cout<<p<<endl;
	
	
	return 0;
}

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

map<int,int>mp;
const int maxn = 100005;
int x[maxn],y[maxn],t[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    x[0]=0;
    y[0]=0;
    t[0]=0;
    for(int i=1; i<=n; i++)
    {   int diff = t[i]-t[i-1];
        int spend = abs(x[i-1]-x[i]) + abs(y[i-1]-y[i]);
        if(spend >diff)
        {
            printf("No\n");
            return 0;
        }
        else if(spend == diff ||(spend%2 == diff%2))
        {
           continue;
        }
        else {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 100005, M = 1000000007, BIG = 0x3f3f3f3f;

int n;
string s;

void Process() {
  n = s.length();
  bool a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A')
      a = 1;
    else
      b = 1;
  }
  if (a && b)
    cout << "Yes\n";
  else
    cout << "No\n";
}

int main() {
  FASTIO();

  while (cin >> s) {
    Process();

    if (cin.eof())
      break;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    ll x,y;
    cin>>x>>y;
    int ans=1;
    while(x*2<=y){
        ans++;
        x*=2;
    }
    fin(ans);
}



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

#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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

const int N = 2010;
const int MOD = 1e9 + 7;

int n, k, C[N][N], F[N][N], sF[N][N];

void add(int &x, int y){
    x += y;
    x -= (x >= MOD) * MOD;
}

void sub(int &x, int y){
    x -= y;
    x += (x < 0) * MOD;
}

int powMod(int n, int k){
    assert(n >= 0);
    if (k == 0)
        return 1;
    int res = powMod(n, k >> 1);
    res = (ll) res * res % MOD;
    if (k & 1)
        res = (ll) res * n % MOD;
    return res;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;

    FOR(i, 0, n){
        C[i][0] = 1;
        FOR(j, 1, i){
            add(C[i][j], C[i - 1][j]);
            add(C[i][j], C[i - 1][j - 1]);
        }
    }

    F[0][0] = 1;
    sF[0][0] = 1;

    FOR(i, 1, n){
        FOD(j, i, 1){
            add(F[i][j], sF[i - 1][j]);
            add(F[i][j], F[i - 1][j - 1]);

            add(sF[i][j], sF[i][j + 1]);
            add(sF[i][j], F[i][j]);
        }
        sF[i][0] = sF[i][1];
    }

    cout << (ll) sF[n - 1][n - k] * powMod(2, max(0, n - k - 1)) % MOD;

    return 0;
}

Measured memory_bytes: 45020
#include <iostream>
#include <cmath>
#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

constexpr int INF = 1 << 30;

Graph<> tree;
std::vector<int> ls, rs, vs;

void dfs(int v, int p = -1) {
    for (auto e : tree[v]) {
        int u = e.dst;
        if (u == p) continue;

        ls[u] = std::max(ls[u], ls[v] - 1);
        rs[u] = std::min(rs[u], rs[v] + 1);

        dfs(u, v);

        ls[v] = std::max(ls[v], ls[u] - 1);
        rs[v] = std::min(rs[v], rs[u] + 1);
    }
}

void fdfs(int v, int p = -1) {
    int x = vs[v];
    for (auto e : tree[v]) {
        int u = e.dst;
        if (u == p) continue;

        vs[u] = (x - 1 >= ls[u] ? x - 1 : x + 1);
        fdfs(u, v);
    }
}

void solve() {
    int n;
    std::cin >> n;

    tree.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        tree[u].emplace_back(u, v);
        tree[v].emplace_back(v, u);
    }

    ls.assign(n, -INF);
    rs.assign(n, INF);

    int k;
    std::cin >> k;
    while (k--) {
        int v, x;
        std::cin >> v >> x;
        --v;
        ls[v] = rs[v] = x;
    }

    dfs(0);

    vs.resize(n);
    vs[0] = ls[0];
    fdfs(0);

    for (int v = 0; v < n; ++v) {
        if (vs[v] < ls[v] || rs[v] < vs[v]) {
            std::cout << "No" << std::endl;
            return;
        }

        for (auto e : tree[v]) {
            int u = e.dst;
            if (std::abs(vs[v] - vs[u]) != 1) {
                std::cout << "No" << std::endl;
                return;
            }
        }
    }

    std::cout << "Yes" << std::endl;
    for (auto x : vs) std::cout << x << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 15360