akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	int mod=1000000000+7;
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[]t=new int[n];
		int[]a=new int[n];
		for(int i=0;i<n;i++) {
			t[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		boolean[] fixed_T=new boolean[n];
		boolean[] fixed_A=new boolean[n];
		fixed_T[0]=true;
		fixed_A[n-1]=true;
		for(int i=0;i<n-1;i++) {
			if(t[i+1]>t[i])fixed_T[i+1]=true;
			else if(t[i+1]==t[i])continue;
			else {
				System.out.println(0);
				return;
			}
		}
		for(int i=n-1;i>0;i--) {
			if(a[i]<a[i-1])fixed_A[i-1]=true;
			else if(a[i]==a[i-1])continue;
			else {
				System.out.println(0);
				return;
			}
		}
		long unfixedCount=0;
		long ans=1;
		for(int i=0;i<n;i++) {
			if(fixed_T[i] && fixed_A[i]) {
				if(t[i]==a[i])ans*=1;
				else ans*=0;
			}else if(fixed_T[i]) {
				if(a[i]>=t[i])ans*=1;
				else ans*=0;
			}else if(fixed_A[i]) {
				if(a[i]<=t[i])ans*=1;
				else ans*=0;
			}else {
				ans*=Math.min(a[i], t[i]);
			}
			ans%=mod;
		}
		System.out.println(ans);	
	}
}

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

int main()
{
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  
  vector<int> ACs(100010, 0);
  for (int i = 1, j = 0; i < N; i++)
  {
    if (S.at(i - 1) == 'A' && S.at(i) == 'C') 
    {
      j++;
      ACs.at(i) = j;
    } else ACs.at(i) = j;
    //cout << ACs.at(i) << endl;
  }
  
  for (int i = 0; i < Q; i++) 
  {
    int l, r;
    cin >> l >> r;
    int ans = ACs.at(r - 1) - ACs.at(l - 1);
    cout << ans << endl;
  }
}

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

int main(){
    long long int n;
    cin >> n;

    vector<long long int> div1;
    for (long long int i=1; i*i<=n-1; i++){
        if ((n-1) % i == 0){
            div1.push_back(i);

            long long int j = (n-1) / i;
            if (j != i) div1.push_back(j);
        }
    }
    long long int ans = div1.size() - 1;
    vector<long long int> div2;
    for (long long int i=2; i*i<=n; i++){
        if (n % i == 0) div2.push_back(i);
    }

    int m = div2.size();
    for(int i=0; i<m; i++){
        long long int a = n;
        while(a > 0){
            if(a % div2[i] == 0) a /= div2[i];
            else break;
        }
        if(a % div2[i] == 1) ans += 1;
    }
    ans += 1;// self
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
using namespace std;
// Problem https://atcoder.jp/contests/abc125/tasks/abc125_c
// Reference http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
// を参照しながら編集したが testcase07,08,12でWAとなるのでチェックさせて頂きました
#include <iostream>
#include <vector>
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

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

    // 累積 GCD (左と右両方)
    vector<int> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
    for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
    
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	ll int n,m,l,i,j,k;
	cin>>n>>m>>l;
	ll int dp1[n+1][n+1];
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			if(i==j)
			dp1[i][j]=0;
			else
			dp1[i][j]=mod;
		}
	}
	ll int dp2[n+1][n+1];
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			if(i==j)
			dp2[i][j]=0;
			else
			dp2[i][j]=mod;
		}
	}
	for(i=0;i<m;i++){
		ll int a,b,c;
		cin>>a>>b>>c;
		dp1[a][b]=c;
		dp1[b][a]=c;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				dp1[j][k]=min(dp1[j][k],dp1[j][i]+dp1[i][k]);
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(i==j)
			continue;
			else{
				if(dp1[i][j]<=l)
				dp2[i][j]=1;
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				dp2[j][k]=min(dp2[j][k],dp2[j][i]+dp2[i][k]);
			}
		}
	}
	ll int q;
	cin>>q;
	for(i=0;i<q;i++){
		ll int s,t;
		cin>>s>>t;
		if(dp2[s][t]!=mod)
		cout<<dp2[s][t]-1<<"\n";
		else
		cout<<"-1\n";
	}
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


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

struct test {
    int N, K;
    long H[200000];
    long ans;
} td[] =
    {
        {
            3, 1,
            {4, 1, 5},
            5,
        },
        {
            8, 9,
            {7, 9, 3, 2, 3, 8, 4, 6},
            0,
        },
        {
            3, 0,
            {1000000000, 1000000000, 1000000000},
            3000000000,
        }
    };

int
cmp(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

void
solver(int n, int k, long *h)
{
    int i;
    long sum;

    qsort(h, n, sizeof(long), cmp);
    sum = 0;
    for (i=k; i<n; i++)
        sum += h[i];
    printf("%ld\n", sum);
}

int
main(int argc, char *argv[])
{
    int N, K;
    long H[200000];
    int tt;
#if 0
    for(tt=0;tt<sizeof(td)/sizeof(struct test); tt++) {
        solver(td[tt].N, td[tt].K, td[tt].H);
        printf("%ld\n",td[tt].ans);
    }
    return 0;
#endif
    scanf("%d%d", &N, &K);
    for (tt=0; tt<N; tt++)
        scanf("%ld", H+tt);
    solver(N, K, H);
    return 0;
}

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

int main(){
    int n, k, x, y;
    cin >> n >> k;
    for(int i = 0;i<k;i++){
        cin >> x >> y;
        cout << (min(min(x, n-x+1),min(y,n- y+1))-1) % 3 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int main() {
  ll n; cin >> n;
  vector<ll> X,Y;
  loop(i,0,n) {
    ll x,y;
    cin >> x >> y;
    X.push_back(x);
    Y.push_back(y);
  }
  set<ll> A, B, C, D;

  ll ans = 0;
  loop(i,0,n) {
    if (i!=0) {
      ll a1 = X[i]+Y[i];
      ll b1 = X[i]-Y[i];
      ll c1 = -X[i]+Y[i];
      ll d1 = -X[i]-Y[i];
      ll a2 = *A.rbegin();
      ll b2 = *B.rbegin();
      ll c2 = *C.rbegin();
      ll d2 = *D.rbegin();
      chmax(ans, a1 + d2);
      chmax(ans, b1 + c2);
      chmax(ans, c1 + b2);
      chmax(ans, d1 + a2);
    }

    A.insert(X[i]+Y[i]);
    B.insert(X[i]-Y[i]);
    C.insert(-X[i]+Y[i]);
    D.insert(-X[i]-Y[i]);
  }

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


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/05/19  Problem: ABC 126 F / Link: http://abc126.contest.atcoder.jp/tasks/abc126_f  ----- */


void test(int M, int K) {
	VI a(2 << M, 0);
	FOR(i, 0, 2 << M) {
		a[i] = i / 2;
	}
	int N = 2 << M;
	bool ex = 0;
	VI b;
	do {
		VI pa(1 << M, 0);
		FOR(i, 0, N) {
			FOR(j, i + 1, N) {
				if (a[i] == a[j]) {
					LL x = 0;
					FOR(k, i + 1, j) {
						x ^= a[k];
					}
					if (x == K) {
						pa[a[i]] = 1;
					}
				}
			}
		}
		LL s = accumulate(ALL(pa), 0LL);
		if (!ex && s == 1 << M) {
			ex = 1, b = a;
			/*for (auto it : b) {
				cout << it << " ";
			}cout << endl;*/
			break;
		}

	} while (next_permutation(ALL(a)));
	if (ex)DD(de(M, K, ex));
	if (ex) {
		for (auto it : b) {
			cout << it << " ";
		}cout << endl;
	}
}

long long xorxor(long long  val) {
	long long ret = ((val + 1) / 2) % 2;
	for (int i = 0; i <= 59; i++) if ((val >> i) % 2) ret |= (1 ^ (val % 2)) << i;
	return ret;
}

// 実験してちゃんと仮説を検証すること !!!
// 実験: した
// 検証: 雑すぎ
//       - 二山位あれば良さそう
//       - こういうときに1山にしたくならないとダメ
// 

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int M, K; cin >> M >> K;
	if (pow(2, M) - 1 < K) {
		cout << "-1" << endl;
		return 0;
	}
	DD(de(xorxor(2 << M)));
	if (M == 1 && K == 1) {
		cout << "-1" << endl;
		return 0;
	}
	if (K == 0) {
		FOR(i, 0, 1 << M) {
			cout << i << " "<< i<<" ";
		}cout << endl;
		return 0;
	}
	VI ans;
	ans.push_back(K);
	FOR(i, 0, 1 << M) {
		if (i == K)continue;
		ans.push_back(i);
	}
	ans.push_back(K);
	FORR(i, (1 << M) - 1, 0 - 1) {
		if (i == K)continue;
		ans.push_back(i);
	}
	for (auto it : ans) {
		cout << it << " ";
	}cout << endl;

	//FOR(k, 0, 10) {
	//	test(0, k);
	//}
	//FOR(k, 0, 10) {
	//	test(1, k);
	//}
	//FOR(k, 0, 10) {
	//	test(2, k);
	//}
	//FOR(k, 0, 10) {
	//	test(3, k);
	//}

	return 0;
}


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

int main(){
	//freopen("/home/byte001/Code/Input/1.txt","r",stdin);
	vector<int >a(9,0);
	for(int i=0;i<9;i++) cin>>a[i];
	int n; cin>>n;
	bool isTrue = false;
	vector<int >b(9,0);
	while(n--){
		int x; cin>>x;
		for(int i=0;i<9;i++) if(a[i]==x) b[i]=1; 
	}

	if( (b[0]==1&&b[1]==1&&b[2]==1)||(b[3]==1&&b[4]==1&&b[5]==1)||(b[6]==1&&b[7]==1&&b[8]==1)||(b[0]==1&&b[3]==1&&b[6]==1)||(b[1]==1&&b[4]==1&&b[7]==1)||(b[2]==1&&b[5]==1&&b[8]==1)||(b[0]==1&&b[4]==1&&b[8]==1)||(b[2]==1&&b[4]==1&&b[6]==1) ) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
		

}


Measured memory_bytes: 256
k,a,b = map(int, input().split())

if b - a >= 3:
    #print((b-a)*((k-(a-1))//2)+a)
    #print((b-a)*((k-(a-1))//2)+1+a)
    if (k-(a-1))%2==0:
        print((b-a)*((k-(a-1))//2)+a)
    else:
        print((b-a)*((k-(a-1))//2)+1+a)

else:print(k+1)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define INT long long int
#define MOD 1000000007
using namespace std;

INT h, w, n, all, sum, ans[10];
map<pair<int, int>, int> check;
int main()
{
    cin>>h>>w>>n;
    while( n-- )
    {
        int x, y;
        scanf("%d%d", &x, &y);
        for(int i = -2 ; i <= 0 ; i++ )
            for(int j = -2 ; j <= 0 ; j++)
                if( 1 <= x+i&&x+i <= h-2 &&
                    1 <= y+j&&y+j <= w-2 )
                        check[make_pair(x+i,y+j)]++;
    }
    for(map<pair<int,int>,int>::iterator i = check.begin() ; i != check.end() ; i++ )
        ans[i->second]++;
    ans[0] = (w-2)*(h-2);
    for(int i = 1 ; i <= 9 ; i++ ) ans[0] -= ans[i];
    for(int i = 0 ; i <= 9 ; i++ )
        printf("%lld\n", ans[i]);
    return 0;
}


Measured memory_bytes: 56448
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<int> ts(N), as(N);
    for (auto &ti : ts) cin >> ti;
    for (auto &ai : as) cin >> ai;
    // 各山の高さhiについて取りうる値の範囲を計算していく
    vector<pair<int, int>> tHiRanges(N), aHiRanges(N);
    int maxHi = 0;
    for (int i = 0; i < N; ++i)
    {
        int ti = ts[i];
        if (ti > maxHi)
        {
            maxHi = ti;
            tHiRanges[i] = { ti, ti };
        }
        else
        {
            tHiRanges[i] = { 1, maxHi };
        }
    }
    maxHi = 0;
    for (int i = N - 1; i >= 0; --i)
    {
        int ai = as[i];
        if (ai > maxHi)
        {
            maxHi = ai;
            aHiRanges[i] = { ai, ai };
        }
        else
        {
            aHiRanges[i] = { 1, maxHi };
        }
    }
    // 各山について高さの範囲の和集合を取っていく:O(N)
    LLONG ans = 1;
    for (int i = 0; i < N; ++i)
    {
        const auto tRange = tHiRanges[i];
        const auto aRange = aHiRanges[i];
        // 和集合が空になるときはゼロを出力
        if (tRange.second < aRange.first || aRange.second < tRange.first)
        {
            ans = 0;
            break;
        }
        pair<int, int> range = 
            { max(tRange.first, aRange.first),
              min(tRange.second, aRange.second) };
        ans *= (range.second - range.first + 1);
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  int swater, sugar;
  swater = sugar = 0;
  double max_con = -1;

  for (int a = 0; a <= F; a += 100 * A) {
    for (int b = 0; a + b <= F; b += 100 * B) {
      if (a + b == 0) continue;
      int meltable = E * (a + b) / 100;
      for (int c = 0; a + b + c <= F; c += C) {
        if (c > meltable) break;
        for (int d = 0; a + b + c + d <= F; d += D) {
          if (c + d > meltable) break;
          double con = 100 * (c + d) / static_cast<double>(a + b + c + d);
          if (con > max_con) {
            swater = a + b + c + d;
            sugar = c + d;
            max_con = con;
          }
        }
      }
    }
  }

  cout << swater << ' ' << sugar << endl;

  return 0;
}


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

int main() {
    int n,d;
    cin>>n>>d;
    int a[n][d];
    for (int i=0;i<n;i++)
        for (int j=0;j<d;j++)
            cin>>a[i][j];
    int ans=0;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++) {
            int sm=0;
            for (int k=0;k<d;k++)
                sm+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            int l=1;
            while (l*l<sm)
                l++;
            if (l*l==sm)
                ans++;
        }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#from collections import deque, Counter
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
#N = int(input())
N, M = map(int, input().split())


### https://note.nkmk.me/python-union-find/

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n 
    # 各要素の親要素の番号を格納するリスト 
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する

  def find(self, x): # 要素xが属するグループの根を返す
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y): # 要素xが属するグループと要素yが属するグループとを併合する
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x): # 要素xが属するグループのサイズ（要素数）を返す
    return -self.parents[self.find(x)]

  def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
    return self.find(x) == self.find(y)

  def members(self, x): # 要素xが属するグループに属する要素をリストで返す
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self): # すべての根の要素をリストで返す
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self): #グループの数を返す
    return len(self.roots())

  def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    #print()での表示用
    #ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す

town = UnionFind(N)
for k in range(M):
  A, B = map(int, input().split())
  town.union(A-1, B-1)
print(town.group_count()-1)

#A = list(map(int, input().split()))
#flag = True
#for k in range(N):
#ans = 0
#print(ans)
#print('Yes')
#print('No')

Measured memory_bytes: 75480
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF 2147483600
const ll V=110;
ll d[V][V];
ll n;
void Warshall_Floyd(){
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(d[i][j]>(d[i][k]+d[k][j])){
          d[i][j]=d[i][k]+d[k][j];
        }
      }
    }
  }
}
int main(){
  ll e;cin>>n>>e;
  fill(d[0],d[101],1e18);
  ll s,t,w;
  rep(i,e){
    cin>>s>>t>>w;
    d[s][t]=w;
  }
  rep(i,n){
    d[i][i]=0;
  }
  Warshall_Floyd();
  rep(i,n){
    if(d[i][i]<0){
      cout<<"NEGATIVE CYCLE"<<endl;
      return 0;
    }
  }
  rep(i,n){
    rep(j,n){
      if(j!=n-1){
        if(d[i][j]>1e10){
          cout<<"INF"<<" ";
        }else{
          cout<<d[i][j]<<" ";
        }
      }else{
        if(d[i][j]>1e10){
          cout<<"INF";
        }else{
          cout<<d[i][j];
        }
      }
    }
    cout<<endl;
  }
  return 0;
}


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

int main() {
  int H, N;
  long X, total = 0;
  cin >> H >> N;
  
  if (H <= N) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<int> vec(H);
  
  for (int i = 0; i<H; ++i) {
    cin >> X;
    total += X;
  	vec.at(i) = X;
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i = 0; i<N; ++i) {
    total -= vec.at(i);
  }
  
  cout << total << endl;
}

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

int main()
{
   //C
   int sum=0;
   int n;
   int count=0;
   cin>>n;
   int a[n];
   int b[n-1];
   for(int i=0;i<n-1;i++)
   {
       cin>>b[i];
   }

   a[0]=b[0]; 
   for(int i=1;i<n-1;i++)
   {
       a[i]=min(b[i-1],b[i]);
   }
   a[n-1]=b[n-2];

    for(int i=0;i<n;i++)
   {
       sum+=a[i];
   } 

   cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
fun main() {
    val (c11, c12, c13) = readLine()!!.split(" ").map { it.toInt() }
    val (c21, c22, c23) = readLine()!!.split(" ").map { it.toInt() }
    val (c31, c32, c33) = readLine()!!.split(" ").map { it.toInt() }

    for (a1 in (0..100)) {
        for (b1 in (0.. 100)) {
            if (a1 + b1 == c11) {
                for(a2 in (0..100)) {
                    for (b2 in (0..100)) {
                        if (a1 + b2 == c12 && a2 + b1 == c21 && a2 + b2 == c22) {
                           for (a3 in (0..100)) {
                               for (b3 in (0..100)) {
                                   if (a3 + b1 == c31 &&
                                       a3 + b2 == c32 &&
                                       a1 + b3 == c13 &&
                                       a2 + b3 == c23 &&
                                       a3 + b3 == c33) {
                                       print("Yes")
                                       return
                                   }
                               }
                           }
                        }
                    }
                }

            }
        }
    }

    print("No")
}

Measured memory_bytes: 37976
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    string s, t = ""; cin>>s;
    int n = s.size();
    for(int i =0; i<n; i++)
        if(s[i]!='B')t.pb(s[i]);
        else if(!t.empty())t.pop_back();
    cout<<t;
	return 0;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i=0; i<n; i++) list.add(sc.nextInt());
        Collections.sort(list);

        while (1 < list.size()) {
            for (int i=1; i<list.size(); i++) {
                int tmp = list.get(i);
                tmp %= list.get(0);
                if (tmp == 0) {
                    list.remove(i);
                    i--;
                } else {
                    list.set(i, tmp);
                }
            }
            Collections.sort(list);
//            System.out.println(list);
        }

        System.out.println(list.get(0));

    }

}



Measured memory_bytes: 59308
N, M = map(int, input().split())
a_list = []
b_list = []
for i in range(M):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

par = [i for i in range(N+1)]
rank = [0]*(N+1)
size = [1] * (N + 1)

def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x_par = find(x)
    y_par = find(y)
    if x_par == y_par:
        return
    if rank[x_par] < rank[y_par]:
        par[x_par] = y_par
        size[y_par] += size[x_par]
    else:
        par[y_par] = x_par
        size[x_par] += size[y_par]
        if rank[x_par] == rank[y_par]:
            rank[x_par] += 1


def bool_func(x, y):
    if find(x) == find(y):
        return True
    else:
        return False


ans_list = []      
ans = int(N*(N-1)/2)
for i in range(M):
    ans_list.append(ans)
    a = a_list[M-1-i]
    b = b_list[M-1-i]
    p = size[find(a)]
    q = size[find(b)]
    if bool_func(a, b):
        pass
    else:
        ans -= p*q
        unite(a, b)

for i in range(M):
    print(ans_list[M-1-i])
    


Measured memory_bytes: 19392
#include<bits/stdc++.h>
#define ll long long

using namespace std;


int main()
	{
		int mat[3][3];
		for(int i=0;i<3;i++)
			{
			for(int j=0;j<3;j++)
				{
				scanf("%d",&mat[i][j]);	
				}	
			}
		if(mat[0][0]+mat[2][2]!=mat[0][2]+mat[2][0])
			{printf("No\n");return 0;}	
			for(int i=0;i<3;i++)
			{
			for(int j=0;j<3;j++)
				{
				if(mat[i%3][j%3]+mat[(i+1)%3][(j+1)%3]!=mat[(i)%3][(j+1)%3]+mat[(i+1)%3][j%3])
					{printf("No\n");return 0;}
				}	
			}
		printf("Yes\n");
		return 0;		
	}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N;
vector<int> A;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  A.resize(N);

  rep(i,N){
    cin >> A[i];
  }
  int max,min;
  sort(A.begin(),A.end());
  min = A[0];
  sort(A.begin(),A.end(),greater<int>());
  max = A[0];
  cout << max - min << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
main(){int N,A,B,C,X,Y,y,f;for(;std::cin>>N>>A>>B>>C>>X,N||A||B||C||X;f>10000?puts("-1"):printf("%d\n",f))for(f=0,y=-1;N-->0;y=Y){std::cin>>Y;if(Y==y){X=(A*X+B)%C;f++;}for(;X!=Y&f<10001;f++)X=(A*X+B)%C;}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc;
    cin>>n;
    vector<LL> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    LL sum=0;
    sort(all(v));
    LL rem=n-1;
    for(i=n-1;i>=0;i--)
    {
        //debug(i);
       // debug(v[i]);
        LL allowed=2;
        if(i==n-1)
        {
            allowed=1;
        }
        LL given=min(rem,allowed);
        
        //debug(given);
        sum+=given*v[i];
        rem-=given;
        if(rem==0)
        {
            break;
        }
       // part;
    }
    cout<<sum<<endl;
    

    return 0;
}


Measured memory_bytes: 4780
/* ex3-1
    kas056 */

#include<stdio.h>
#include<math.h>

//構造体生成
typedef struct{
    int x_elem;
    int y_elem;
}point;

point shift_point(point p1, point p2){
    point p;
    int lenx, leny;

    /*正方形なので、二点間の距離のx成分、
    y成分で次の点を計算できる。*/

    //差分を符号付きで求める。
    lenx = p2.x_elem - p1.x_elem;
    leny = p2.y_elem - p1.y_elem;

    //直近の点からy軸、x軸成分の差分を加えて求める
    p.x_elem = p2.x_elem + (-leny);
    p.y_elem = p2.y_elem + lenx;
    return p;
}

int main(void){
    int x1, y1,x2,y2, x3,y3,x4,y4;
    point point1, point2, point3, point4;


    //入力読み込み
    scanf("%d %d %d %d", &x1,&y1,&x2,&y2);

    //点1、2に代入
    point1.x_elem = x1;
    point1.y_elem = y1;
    point2.x_elem = x2;
    point2.y_elem = y2;

    
    //point3,4を計算、代入。
    point3 = shift_point(point1, point2);
    point4 = shift_point(point2, point3);

    //各値代入。
    x3 = point3.x_elem;
    y3 = point3.y_elem;
    x4 = point4.x_elem;
    y4 = point4.y_elem;

    //出力
    printf("%d %d %d %d\n", x3,y3,x4,y4);
    return 0;
}

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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;

int count_factors(int n)
{   
    int count=0;

    for(int i=1;i*i<n;i++)
    {
        if(n%i==0)
        count+=2;
    }

    int x=sqrt(n);
    if(x*x==n)
    count++;

    return count;
}

int main()
{
    int n;
    scf(n);

    int ans=0;

    for(int i=1;i<n;i++)
    {
        int x=n-i;

        ans+=count_factors(x);
    }

    prin(ans);
return 0;
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

    static int makePond(int[][] g, int a, int b, int c, int d){
        int max = 0;
        for(int i=a;i<=c;i++){
            for(int j=b;j<=d;j++){
                max = Math.max(g[i][j], max);
            }
        }
        int min = 9;
        for(int j=b-1;j<=d+1;j++){
            if(g[a-1][j] <= max || g[c+1][j] <= max) {
                return 0;
            }
            min = Math.min(min, Math.min(g[a-1][j], g[c+1][j]));
        }
        for(int i=a-1;i<=c+1;i++){
            if(g[i][b-1] <= max || g[i][d+1] <= max) {
                return 0;
            }
            min = Math.min(min, Math.min(g[i][b-1], g[i][d+1]));
        }
        int sum = 0;
        for(int i=a;i<=c;i++){
            for(int j=b;j<=d;j++){
                sum += Math.abs(min - g[i][j]);
            }
        }
        return sum;
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int d = sc.nextInt();
            int w = sc.nextInt();
            if(d + w == 0) break;
            int[][] garden = new int[d][w];
            for(int i=0;i<d;i++){
                for(int j=0;j<w;j++){
                    garden[i][j] = sc.nextInt();
                }
            }
            int max = 0;
            for(int i=1;i<d-1;i++){
                for(int j=1;j<w-1;j++){
                    for(int k=i;k<d-1;k++){
                        for(int l=j;l<w-1;l++){
                            max = Math.max(makePond(garden, i, j, k, l), max);
                        }
                    }
                }
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 37392
import java.util.Scanner;
import java.util.Arrays;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
		long K = sc.nextLong();

		int a;
		int b;

		long[] array = new long[100001];
		for(int i=1; i<=100000; i++){
			array[i] = 0;
		}

		for(int i=0; i<N; i++){
			a = sc.nextInt();
			b = sc.nextInt();
			array[a] += b;
		}

		int ans = 0;
		for(int i=1; i<=100000; i++){
			K -= array[i];
			if(K<=0){
				ans = i;
				break;
			}
		}

    System.out.print(ans);

	}

}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  i32 n;
  cin >> n;

  vector<array<i32, 3>> h;

  rep(i, n) {
    i32 ai, bi, ci;
    cin >> ai >> bi >> ci;
    h.push_back({ai, bi, ci});
  }

  vector<vector<u64>> dp(n, vector<u64>(3));

  dp[0][0] = h[0][0];
  dp[0][1] = h[0][1];
  dp[0][2] = h[0][2];

  for (i32 i = 1; i < n; i++) {
    rep(j, 3) {
      rep(k, 3) {
        if (k == j)
          continue;
        dp[i][j] = max(dp[i][j], dp[i - 1][k] + h[i][j]);
      }
    }
  }

  cout << *max_element(dp[n - 1].begin(), dp[n - 1].end());

  return 0;
}


Measured memory_bytes: 9788
from collections import deque
N = int(input())
A = list(map(int,input().split()))
d = deque()
for i in range(N):
  if N%2==0:
    if i%2==0: d.append(A[i])
    else: d.appendleft(A[i])
  else:
    if i%2==0: d.appendleft(A[i])
    else: d.append(A[i])
print(*d)

Measured memory_bytes: 25532
#include<bits/stdc++.h>
#define ll long long int

using namespace std;



int main()
{
    ll n,t,a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)cout<<k;
    else if(k<=a+b)cout<<a;
    else if(k<=a+b+c)cout<<a-(k-a-b);
    else cout<<a+c;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn=1e5+2;

struct T
{
    int u, v, w;
};
vector<T> a;

void Enter()
{
    int n=1, l;
    cin>>l;
    int s=1;
    while(s*2<=l)
    {
        n++;
        s*=2;
    }
    for(int i=1;i<n;i++)
    {
        a.push_back({i,i+1,0});
        a.push_back({i,i+1,1<<(i-1)});
    }
    int b=l-(1<<(n-1)), h=1<<(n-1);
    for(int i=0;(1<<i)<=b;i++)
        if(((b>>i)&1)==1)
        {
            a.push_back({i+1,n,h});
            h+=(1<<i);
        }
    cout<<n<<" "<<a.size()<<'\n';
    for(T i:a)
        cout<<i.u<<" "<<i.v<<" "<<i.w<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Enter();
}


Measured memory_bytes: 256
while True:
    n=int(input())
    if n==0:
        break
    dolls=[]
    for i in range(n):
        h,r=[int(j) for j in input().split(" ")]
        dolls.append((h,r))
    m=int(input())
    for j in range(m):
        h,r=[int(j) for j in input().split(" ")]
        dolls.append((h,r))

    dolls=sorted(dolls,key=lambda w:(w[0],-1*w[1]))
    r=[i[1] for i in dolls]

    table=[1 for i in range(len(r))]
    for i in range(len(r)):
        for j in range(i):
            if r[j]<r[i]:
                table[i]=max(table[i],table[j]+1)

    print(max(table))



Measured memory_bytes: 5608
#include <cmath>
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

const string YES = "Yes";
const string NO = "No";

void solve(ll a, ll b) {
  int c = stoi(to_string(a) + to_string(b));
  int sqrtc = sqrt(c);
  bool pred = c == sqrtc * sqrtc;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  solve(a, b);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int d[51];
    int ans = 0;

    rep(i, n)cin >> d[i];

    rep(i, n-1){
        for(int j = i+1; j < n; j++){
            ans += d[i]*d[j];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

ll modpow(int a, int b) { //aのb乗
	if (!b)return 1;
	if (b % 2)return modpow(a, b - 1) * a %mod;
	ll memo = modpow(a, b / 2);
	return memo * memo %mod;
}

int main(){
  ll N,A[300000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>A[i];
  ll ans(0);
  for (int i(0);i<=60;i++){
    ll tmp(0),cnt0(0),cnt1(0);
    for (int j(0);j<N;j++){
      if (A[j]>>i & 1) cnt1++;
      else cnt0++;
    }
    //cout <<i <<  " "<<cnt0 << " " << cnt1 << endl;
    tmp = (cnt0*cnt1)%mod*modpow(2,i);
    tmp %= mod;
    ans += tmp;
    ans %= mod;
  }
  cout << ans << endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int root(vector<int> &par, int x) {
  if (par[x] == x) {
    return x;
  }
  else {
    return par[x] = root(par, par[x]);
  }
}

bool same(vector<int> &par, int x, int y) {
  return root(par, x) == root(par, y);
}

void unite(vector<int> &par, int x, int y) {
  int rootx = root(par, x);
  int rooty = root(par, y);

  if (rootx == rooty) {
    return;
  }
  else {
    par[rootx] = rooty;
  }
}

int main() {

  int n, m;
  //n: node, m: edge
  cin >> n >> m;

  vector<vector<int>> edge(m, vector<int>(3));
  //0, 1: node, 2: cost

  int tmp0, tmp1;
  for (int i = 0; i < m; i++) {
    cin >> edge[i][0] >> edge[i][1] >> edge[i][2];
  }

  sort (
    edge.begin(),
    edge.end(),
    [](vector<int> x, vector<int> y){return x[2] < y[2];}
  );

  vector<int> par(n);
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {

    int tmpx = edge[i][0];
    int tmpy = edge[i][1];

    if (!same(par, tmpx, tmpy)) {
      unite(par, tmpx, tmpy);
      ans += edge[i][2];
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 8440
N = int(input())
A, W, T, R = 0, 0, 0, 0
for i in range(N):
  S = input()
  if S == "AC":
    A += 1
  elif S == "WA":
    W += 1
  elif S == "TLE":
    T += 1
  else:
    R += 1
print("AC x  "+str(A))
print("WA x  "+str(W))
print("TLE x  "+str(T))
print("RE x  "+str(R))

Measured memory_bytes: 69852
#include <stdio.h>

int main(void)
{
	int W=0, H=0, x=0, y=0,r=0;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r<0||y-r<0||x+r>W||y+r>H)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 584
import Control.Applicative
import System.IO
import Control.Monad
 
main = do
    n <- read <$> getLine
    putStrLn $ show $ sum $ [max 0 ((min (a+1) (2001-a) ) * (min (n-a+1) (2001 - n + a))) | a <- [0 .. min n 2000]]
    eof <- isEOF
    unless eof main

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

int func(int d, int a)
{
  int num = 1;
  int ret = 1;
  while(true)
  {
    if(num + a > d)
    {
      return ret;
    }
    num += a;
    ret++;
  }
}

int main()
{
  int n, d, x;
  cin >> n;
  cin >> d >> x;
  int a[n];
  for(int i = 0; i < n; ++i) cin >> a[i];
  
  int num = 0;
  for(int i = 0; i < n; ++i) num += func(d, a[i]);
  cout << num + x << endl;
}

Measured memory_bytes: 3580
A,B = map(int,raw_input().split())

S = raw_input()

data = [str(i) for i in range(10)]

mozi = 'Yes'
if S[A] == '-':
    for i in range(A+B+1):
        if i == A:
            continue
        if S[i] not in data:
            mozi = 'No'
else:
    mozi = 'No'

print mozi

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

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

    string s = "";
    int ans = 0, tmp;
    rep2(i, a, b + 1)
    {
        tmp = i;
        s = "";
        while (tmp)
        {
            s += tmp % 10 + '0';
            tmp /= 10;
        }
        string t = s;
        reverse(all(s));
        if (s == t)
        {
            ans++;
        }
    }

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


Measured memory_bytes: 3628
#include <stdio.h>

int main() {
        int m, f, r;

        while(1) {
                scanf("%d %d %d", &m, &f, &r);


                if (m == -1 && f == -1 && r == -1) {
                        break;
                }

                if (m == -1 || f == -1) {
                    printf("F\n");
                    continue;
                }

                if (m == -1) {
                        m = 0;
                }

                if (f == -1) {
                        f = 0;
                }

                if (m + f >= 80) {
                        printf("A\n");
                } else if (m + f >= 65 && m + f < 80) {
                        printf("B\n");
                } else if ((m + f >= 50 && m + f < 65)
                          || (m + f >= 30 && m + f < 50 && r >= 50)) {
                        printf("C\n");
                } else if (m + f >= 30 && m + f < 50) {
                        printf("D\n");
                } else {
                        printf("F\n");
                }
        }
}


Measured memory_bytes: 2028
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Pair implements Comparable<Pair> {
		long time, deadline;

		Pair(long time, long deadline) {
			this.time = time;
			this.deadline = deadline;
		}

		@Override
		// 締め切りが早いもの -> 長さが長いもの
		public int compareTo(Pair o) {
			if (this.deadline < o.deadline) {
				return -1;
			} else if (this.deadline > o.deadline) {
				return 1;
			} else {
				if (this.time > o.time) {
					return -1;
				} else if (this.time < o.time) {
					return 1;
				} else {
					return 0;
				}
			}
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		List<Pair> tasks = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			tasks.add(new Pair(Long.parseLong(tokens[0]), Long.parseLong(tokens[1])));
		}
		Collections.sort(tasks);
		long time = 0;
		boolean result = true;
		for (int i = 0; i < tasks.size(); ++i) {
			Pair task = tasks.get(i);
			time += task.time;
			if (time > task.deadline) {
				result = false;
				break;
			}
		}
		String str = result ? "Yes" : "No";
		System.out.println(str);

		in.close();
	}

}


Measured memory_bytes: 65404
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new AOJ0069().doIt();
	}
	
	class AOJ0069{
		int n,start,atari,d;
		char[][] map;
		void solve(){
			int[] a = new int[d+1];
			int[] b = new int[d+1];
			int current = atari;
			a[d] = current;
			for(int i=d-1;i>=0;i--){
				if(current < n-1 && map[i][current]=='1')current++;
				else if(current-1>=0&&map[i][current-1]=='1')current--;
				a[i] = current;
			}
//			System.out.println(Arrays.toString(a));
			b[0] = start;
			current = start;
			for(int i=1;i<=d;i++){
				if(current < n-1 && map[i-1][current]=='1')current++;
				else if(current-1>=0&&map[i-1][current-1]=='1')current--;
				b[i] = current;
			}
//			System.out.println(Arrays.toString(b));
			if(a[0]==b[0]){
				System.out.println(0);return;
			}
			
//			for(int i=0;i<=d;i++){
//				System.out.println(a[i]+" "+b[i]);
//			}
			for(int i=0;i<d;i++){
//				System.out.println(a[i]+" "+b[i+1]);
				if(Math.abs(a[i]-b[i+1])==1){
					int min = Math.min(a[i], b[i+1]);
					int max = Math.max(a[i], b[i+1]);
					if(min==0||map[i][min-1]=='0')
						if(max==n-1||map[i][max]=='0')
							if(map[i][min]=='0'){
								System.out.println((i+1)+" "+max);return;
							}
				}
			}
			System.out.println(1);
		}
		
		void doIt(){
			while(in.hasNext()){
				n = in.nextInt();
				if(n==0)break;
				start = in.nextInt()-1;
				atari = in.nextInt()-1;
				d = in.nextInt();
				map = new char[d][n-1];
				for(int i=0;i<d;i++)map[i] = in.next().toCharArray();
//				for(int i=0;i<d;i++){
//					for(int s=0;s<n-1;s++)System.out.print(map[i][s]+" ");System.out.println();
//				}
				solve();
			}
		}
	}
	
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int x[111], y[111], h[111], z;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i]) z = i;
	}
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {
			int a = 1, b = 1e9 + 1000;
			while (a + 1 < b) {
				int c = (a + b) / 2;
				if (c - abs(x[z] - i) - abs(y[z] - j) > h[z])
					b = c;
				else a = c;
			}
			for (int k = 0; k < n; k++)
				if (max(a - abs(x[k] - i) - abs(y[k] - j), 0) != h[k])
					goto q;
			cout << i << ' ' << j << ' ' << a << endl;
			return 0;
		q:;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Pll> points(n);
    ll  x, y;
    for(int i=0;i<n;++i) {
        cin >> x >> y;
        points[i] = Pll(x+y, x-y);
    }
    sort(points.begin(), points.end());
    ll ans = abs(points[n-1].first - points[0].first);
    sort(points.begin(), points.end(), [](Pll p, Pll q) { return (p.second == q.second) ? p.first < q.first : p.second < q.second; });
    ans = max(ans, abs(points[n-1].second - points[0].second));

    cout << ans << endl;
}


Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
struct Node{
	int x,y;
};
int H,W;
int sx,sy,ex,ey;
char c[N][N];
bool vis[N][N];
int flag[N][N];
int movex[4]={0,0,-1,1};
int movey[4]={1,-1,0,0};
int BFS()
{
	deque<Node> q;
	q.push_front({sx-1,sy-1});
	flag[sx-1][sy-1] = 0;
	//vis[sx][sy] = true;
	
	while(!q.empty())
	{
		Node k = q.front();
		q.pop_front();
		//vis[k.x][k.y] = true;
		if(ex-1 == k.x && ey-1 == k.y)	return flag[k.x][k.y];
		for(int i=0;i<4;i++)
		{
			int dx = k.x+movex[i];
			int dy = k.y+movey[i]; 
			if(c[dx][dy] == '#'||dx<0||dx>=H||dy<0||dy>=W)	continue;
			if(flag[dx][dy] == -1||flag[dx][dy] > flag[k.x][k.y])	
			{
				//vis[dx][dy] = true;
				flag[dx][dy] = flag[k.x][k.y];
				q.push_front({dx,dy});
			}
			
			
			
		}
		for(int i=k.x-2;i<=k.x+2;i++)
		for(int j=k.y-2;j<=k.y+2;j++)
		{
			if(c[i][j] == '#'||i<0||j<0||i>=H||j>=W)	continue;
			if(flag[i][j] == -1)
			{
				flag[i][j] = flag[k.x][k.y] + 1;
				q.push_back({i,j});
			}
			//vis[i][j] = true;
			
			
		}
	}
	return -1;
}

int main()
{
	scanf("%d%d%d%d%d%d",&H,&W,&sx,&sy,&ex,&ey);
	for(int i=0;i<H;i++)
		scanf("%s",c[i]);
	memset(flag,-1,sizeof(flag));
	printf("%d\n",BFS());
	
	
	return 0;
}

Measured memory_bytes: 8724
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=1E5+10;

int n,m,a[MAXN];
vector<int> g[MAXN],f[MAXN],glo;
bool vis[MAXN];
ll Ans;

void dfs(int x,int fa,vector<int> &ve)
{
	ve.push_back(a[x]);
	vis[x]=1;
	for(int v:g[x])
		if(v!=fa)
			dfs(v,x,ve);
}

int main()
{
	scanf("%d%d",&n,&m);
	if(m==n-1) return puts("0"),0;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d",&u,&v),++u,++v,g[u].push_back(v),g[v].push_back(u);
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			++cnt;
			dfs(i,0,f[i]);
			sort(f[i].begin(),f[i].end());
			Ans+=f[i][0];
			for(int j=1;j<f[i].size();j++)
				glo.push_back(f[i][j]);
		}
	if(((cnt-1)<<1)>n) return puts("Impossible"),0;
	sort(glo.begin(),glo.end());
	for(int i=0;i<cnt-2;i++)
		Ans+=glo[i];
	printf("%lld\n",Ans);
}

Measured memory_bytes: 9724
from math import ceil

N = int(input())
stas = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(N-1):
  t = stas[i][0] + stas[i][1]
  for j in range(i+1,N-1):
    if t <= stas[j][1]:
      t = stas[j][0] + stas[j][1]
    else:
      n = ceil((t-stas[j][1])/stas[j][2])
      t = stas[j][0] + stas[j][1] + stas[j][2]*n
    #print(i,j,t)
  print(t)
print(0)

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

int main() {
	ios_base::sync_with_stdio(false);
	int k; cin >> k;
	vector<int> a(k);
	for (int i = 0; i < k; ++i) cin >> a[i];
	long long mn = 2, mx = 2;
	for (int i = k - 1; i >= 0; --i) {
		mn = (mn + a[i] - 1) / a[i];
		mx /= a[i];
		if (mn > mx) return cout << -1 << '\n',0;
		mn *= a[i];
		mx = (mx + 1) * a[i] - 1;
	}
	cout << mn << ' ' << mx << '\n';
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N;
string s;
int main(void){
    cin >> N;
    cin >> s;
    string t1, t2;
    if(N%2 == 0){
        t1 = s.substr(0, N/2);
        t2 = s.substr(N/2, N/2);
        if(t1==t2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256