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

public class Main {
private static int[][]daoyu;
private static int count;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (true) {
            int x = input.nextInt();
            int y = input.nextInt();
            if (x == 0 && y == 0) {
            	break;
            	}
            daoyu = new int [y+2][x+2];
            for(int i = 1;i<=y;i++) {
            	for(int j = 1;j<=x;j++) {
            		daoyu[i][j]=input.nextInt();
            		}
            }
            for (int i=0; i<y+2; i++){
            	daoyu[i][0] = daoyu[i][x+1] = 0;
         
            for (int j=0; j<x+2; j++){
            	daoyu[0][j] = daoyu[y+1][j] = 0;
 
            count = 0;
            }
        }
        for (int i = 1; i <= y; i++) {
            for (int j = 1; j <=x; j++) {
                if (daoyu[i][j] == 1) {
                    count++;
                    lj(i, j);
                }
            }
        } 
        System.out.println(count);
        daoyu=null;
    }
    }
    private static void lj(int i, int j) {
    	 daoyu[i][j] = 2;
         if (i - 1 >= 0 && daoyu[i - 1][j] == 1)
             lj(i - 1, j);//上
         if (i + 1 < daoyu.length && daoyu[i + 1][j] == 1)
             lj(i + 1, j);//下
         if (j - 1 >= 0 && daoyu[i][j - 1] == 1)
             lj(i, j - 1);//左
         if (j + 1 < daoyu[i].length && daoyu[i][j + 1] == 1)
             lj(i, j + 1);//右
         if (i - 1 >= 0 && j-1>=0 && daoyu[i - 1][j-1] == 1)
             lj(i - 1, j-1);//左上
         if (i - 1 >= 0 && j+1<daoyu[i-1].length && daoyu[i - 1][j+1] == 1)
             lj(i - 1, j+1);//右上错误
         if (i + 1 < daoyu.length && j-1>=0 && daoyu[i + 1][j-1] == 1)
             lj(i + 1, j-1);//左下
         if (i + 1 < daoyu.length && j+1<daoyu[i+1].length &&daoyu[i + 1][j+1] == 1)
             lj(i+1, j+1);//右下
     }
 
}


Measured memory_bytes: 43976
#include<stdio.h>
    #include<string.h>
    int main(void){
    int A,B,C,D,E,N,M,x,y,i,j,cou=0,cou2=99999999,v[1000000],w[1000000],min_i,min,en=0;
        char S[100],W[100],s[10],X,Y;
    scanf("%s",&S);
   A=strlen(S);
   for(j=0;j<A;j++){
   for(i=j;i<A;i++){
       if(S[i]=='A'){
           v[j]++;
       }else if(S[i]=='T'){
           v[j]++;
       }else if(S[i]=='G'){
           v[j]++;
       }else if(S[i]=='C'){
           v[j]++;
       }else{
           i=A-1;
       }

   }

   }
    min=v[0];
   for(i=1;i<A;i++){
       if(min<v[i]){
           min=v[i];
       }
   }
   printf("%d",min);
    
    return 0;
    }

Measured memory_bytes: 128
from collections import deque
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def bfs(field,s):
  MOVE=[(0,1),(1,0),(0,-1),(-1,0)]
  q=deque([(0,s)])
  dist=[[-1]*W for _ in range(H)]
  d,i,j=-1,-1,-1
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni,nj=i+di,j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if dist[ni][nj]!=-1:
        continue
      if field[ni][nj]=='#':
        continue
      q.append((d+1,(ni,nj)))
  return d
ans=0
H,W=MI()
field=[input() for _ in range(H)]
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)

Measured memory_bytes: 9416
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    string S;
    cin >> S;

    string hi = "hi";
    int i = 0;
    while(i<5){
        if(hi == S){
            break;
        }
        hi += "hi";
        i++;
    }
    string ans = "Yes";
    if(i == 5){
        ans = "No";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    fastio;
    ll a,b,k;
    cin>>a>>b>>k;
    if(k<a){
        cout<<a-k<<" "<<b<<endl;
    }
    else if(k<a+b){
        k-=a;
        cout<<"0 "<<b-k<<endl;
    }
    else{
        cout<<"0 "<<"0"<<endl;
    }
}


Measured memory_bytes: 256
N = int(input())
x = []
y = []
h = []
for i in range(N):
    a, b, c = map(int, input().split())
    x.append(a)
    y.append(b)
    h.append(c)
    if c >= 1:
        xt = a
        yt = b
        ht = c

for Cx in range(101):
    for Cy in range(101):
        H = max(ht + abs(Cx - xt) + abs(Cy - yt), 0)
        for i in range(N):
            Z = max(H - abs(Cx - x[i]) - abs(Cy - y[i]), 0)
            if h[i] != Z:
                break
        else:
            res = [str(Cx), str(Cy), str(H)]

print(" ".join(res))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int A, B, ans1, ans2, ans3;
	cin >> A >> B;
	ans1 = A + B;
	ans2 = A - B;
	ans3 = A * B;
	cout << max({ ans1,ans2,ans3 }) << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ans = []
count = 0

for i in range(k):
  d = int(input())
  l = list(map(int, input().split()))
  for j in range(d):
    if l[j] not in ans:
      ans.append(l[j])

for i in range(n):
  if i+1 not in ans:
    count += 1
  
print(count)

Measured memory_bytes: 9200
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var expression = Console.ReadLine().Split();

            var capacity = 0;
            if (expression.Length <= 100)
            {
                capacity = expression.Length;
            }
            else
            {
                capacity = 100;
            }
            Stack<int> stack = new Stack<int>(capacity);
            foreach (var item in expression)
            {
                if (char.IsDigit(item[0]))
                {
                    stack.Push(int.Parse(item));
                }
                else
                {
                    switch (item)
                    {
                        case "+":
                            stack.Push(stack.Pop() + stack.Pop());
                            break;
                        case "-":
                            var temp = stack.Pop();
                            stack.Push(stack.Pop() - temp);
                            break;
                        case "*":
                            stack.Push(stack.Pop() * stack.Pop());
                            break;
                    }
                }
                
            }

            Console.WriteLine(stack.Pop());
            Console.Read();
        }


    }
    class Stack<T>
    {
        private T[] array;
        private int index = 0;

        public Stack(int capacity)
        {
            array = new T[capacity];
        }
        public void Push(T item)
        {
            array[index++] = item;
        }
        public T Pop()
        {
            return array[--index];
        }
    }
}

Measured memory_bytes: 15876
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}
void solve(long long N, std::vector<long long> A){
    map<LL, LL > m;
    map<LL, LL> m_;
    rep(i, N){
        m_[A[i]]=0;
        m[A[i]]=0;
    }
    rep(i, N){
        m[A[i]]++;
    }
    LL sum =0;
    rep(i, N){
        if(m_[A[i]]==0){
            m_[A[i]] = max(m[A[i]]*(m[A[i]]-1)/2, 0LL);
            sum += m_[A[i]];
        }
    }
    rep(i, N){
        cout<<sum - m_[A[i]] + max((m[A[i]]-2)*(m[A[i]]-1)/2, 0LL)<<endl;
    }return;
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 18996
s = gets.to_i
t = s / 100
u = s % 100

if t > 0 && t < 13
  if u > 0 && u < 13
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if u > 0 && u < 13
    puts "YYMM"
  else
    puts "NA"
  end
end

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

int n;
vector<int> A(50);

int solve(int i ,int m) {
  if(m == 0) return 1;
  if(i >= n)  return 0;
  int res = solve(i + 1,m)||solve(i + 1,m - A.at(i));
  return res;
}

int main() {

  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> A.at(i);
  }

  int q,m;
  cin >> q;
  for(int i = 0; i < q;i++) {
    cin >> m;
    if(solve(0,m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }

 
}



Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,a[100],i,A=0,B=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  if(n%2==0){
    for(i=0;i<n;i++){
    A+=a[i];i++;B+=a[i];
    }
  }
  else if(n%2==1){
      for(i=0;i<n-1;i++){
    A+=a[i];i++;B+=a[i];
    }
    A+=a[i];
  }
  cout << A-B << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    int cnt, res = 0;
    for (int i=1; i<=N; i+=2) {
        cnt=0;
        for (int j=1; j<=N; j++) {
            if (i%j==0) cnt++;
        }
        if (cnt==8) res++;
    }
    cout << res;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};



int main() {
    int N,K; cin>>N>>K;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    ll ans=0ll;
    for (int i = 0; i < N - K; ++i) {
       ans+=(ll)h[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int M=0;
int n;
int A[1000];
void dfs(int k){
	int f3=0,f5=0,f7=0;
	long long num=0;
	for(int i=0;i<k;i++){
		num=num*10+A[i];
		if(A[i]==3)
			f3=1;
		else if(A[i]==5)
			f5=1;
		else if(A[i]==7)
			f7=1;
	}
	if(num>n) return;
	if(f3*f5*f7==1)
		M++;
	A[k]=3;
	dfs(k+1);
	A[k]=5;
	dfs(k+1);
	A[k]=7;
	dfs(k+1);
}
int main(){
	cin>>n;
	dfs(0);
	cout<<M;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

#define int long long

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

    int n, d, a;
    cin >> n >> d >> a;

    vector<pair<int, int>> as;

    for (int i = 0; i < n; i++) {
        int x, h;
        cin >> x >> h;
        as.emplace_back(x, h);
    }
    sort(as.begin(), as.end());
    int ans = 0;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> que;
    int damage = 0;
    for (auto& p : as) {
        int x = p.first, h = p.second;
        while (que.size() && que.top().first < x) {
            auto t = que.top();
            que.pop();
            damage -= t.second;
        }
        h -= damage;
        if (h > 0) {
            int need = (h + a - 1) / a;
            ans += need;
            damage += need * a;
            que.emplace(x + 2 * d, need * a);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7532
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int n;
  cin >> n;
  vector<ll> v(n,0);
  int countA = 0;
  int countB = 0;
  int countC = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    if (v[i] % 4 == 0){
      countA++;
    }else if (v[i] % 2 == 0){
      countB++;
    }else{
      countC++;
    }
  }

  if (countB >= 1)
  {
    countC++;
  }

  if (countC <= countA + 1)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int64_t S; cin >> S;
int64_t x = (INF - S%INF) % INF ,y = (S + x) / INF;

cout << 0 << ' ' << 0 << ' ' << INF << ' ' << 1 <<  ' ' << x << ' ' << y << "\n";


}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll l[5000];

ll doko(ll x,ll n, ll k)
{
  ll g=0;
  for(g=k; g<n; g++)
  {
    if(l[g]!=x)
    {
      return g;
    }
  }
}

ll count(ll max,ll place,ll n,ll k)
{
  if(l[place]>=max)
  {
    return 0;
  }

if(l[n-1]<max)
{
  return n-1-place;
}

  for(k=n-1; k>place; k--)
  {
    if(l[k]<max)
    {
      return k-place;
    }
  }

  return 0;
}


int main() {
   ll i,j,k=0;
    ll n,num=0,tmp;
    cin >> n;
    for(i=0; i<n; i++)
    {
      cin >> l[i];
    }

for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (l[i] > l[j]) {
        tmp =  l[i];
        l[i] = l[j];
        l[j] = tmp;
      }
    }
  }

for(i=0; i<n; i++)
{
  for(j=i+1; j<n; j++)
  {
    num+=count(l[i]+l[j],j,n,k);
  }
}
  cout << num << endl;
}


Measured memory_bytes: 256
def main():
    num = 2
    i = 3
    for _ in range(1500//2):
        num *= i
        i += 2

    n = int(input())
    print(num+2)
    for i in range(n):
        a = i+2
        if i%2 == 0:
            a = 2
        print(a)

if __name__ == '__main__':
    main()



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a,b;
    cin >> a >> b;
    if(a == b) cout << "Draw\n";
    else if(a == 1) cout << "Alice\n";
    else if(b == 1) cout << "Bob\n";
    else if(a < b) cout << "Bob\n";
    else if(a > b) cout << "Alice\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
using namespace std;
const int maxN=1e6+5;
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int s=a+b+c;
    if(s>=22)printf("bust\n");
    else printf("win\n");
}

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

int main(){
	while(1){
		int m,t,p,r;
		cin>>m>>t>>p>>r;
		if(m==0&&p==0&&t==0&&r==0) break;
		int score[51],stats[51][11],time[51];
		lp(i,51){
			score[i]=0;
			time[i]=0;
			lp(j,11){
				stats[i][j]=0;
			}
		}
		lp(i,r){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			if(d!=0){
				stats[b][c]++;
			}
			else{
				score[b]++;
				time[b]+=a+stats[b][c]*20;
			}
		}
		tuple<int,int,int> ans[50];
		lp(i,t){
			ans[i]=make_tuple(score[i+1],-time[i+1],i+1);
		}
		sort(ans,ans+t);
		reverse(ans,ans+t);
		int ans1,memo,memo2,memo3,memo4;
		lp(i,t){
			ans1=get<2>(ans[i]);
			memo=get<0>(ans[i]);
			memo3=get<1>(ans[i]);
			if(i==0){
				cout<<ans1;
			}
			else{
				if(memo==memo2&&memo3==memo4){
					cout<<"=";
				}
				else cout<<",";
				cout<<ans1;
			}
			memo2=memo;
			memo4=memo3;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3008
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
from collections import defaultdict
d = defaultdict(int)
for a in A:
  d[a]+=1
ans=sum(A)
for q in range(Q):
  b,c=map(int,input().split())
  ans+=(c-b)*d[b]
  d[c]+=d[b]
  d[b]=0
  print(ans)

Measured memory_bytes: 23816
#include <iostream>
#include <vector>
using namespace std;
int main(){
    string s;
    int n,i,ne=0,nw=0,ce=0,cw=0,min=1001000;
    cin>>n;
    cin>>s;
    for(i=0;i<n;i++){
        if(s[i]=='E'){
            ne++;
        }
        else{
            nw++;
        }
    }
    for(i=0;i<n;i++){
        if(s[i]=='E'){
            if(cw+ne-ce-1<min){
                min=cw+ne-ce-1;
            }
            ce++;
        }
        else{
            if(cw+ne-ce<min){
                min=cw+ne-ce;
            }
            cw++;
        }
    }
    cout<<min;
}


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

int main()
{
  int N, t, res;
  string s, X;
  cin >> N;
  vector<pair<string, int>> st(0);
  for (int i = 0; i < N; i++)
  {
    cin >> s >> t;
    st.push_back(make_pair(s, t));
  }
  cin >> X;
  for (int i = N - 1; i >= 0; i--)
  {
    if (st.at(i).first == X)
    {
      break;
    }
    else
    {
      res += st.at(i).second;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int check(ll n) {
	ll ok = 0, ng = 1e9;
	while(ng-ok > 1){
		ll mid = (ng + ok) / 2;
		if (mid*mid <= n)ok = mid;
		else ng = mid;
	}
	return ok * ok == n;
}

int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>>x;
	rep(i, 0, n) {
		vector<int>tmp(d);
		rep(j, 0, d)cin >> tmp[j];
		x.pb(tmp);
	}

	int cnt = 0;
	rep(i, 0, n)rep(j, i + 1, n) {
		ll sqdist = 0;
		rep(k, 0, d)sqdist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
		//puts(sqdist)
		if (check(sqdist))cnt++;
	}
	puts(cnt);

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int d;
    cin >> d;
    if(d==25) cout <<"Christmas" <<endl;
    if(d==24) cout <<"Christmas Eve"<<endl;
    if(d==23) cout <<"Christmas Eve Eve"<<endl;
    if(d==22) cout <<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <numeric>
#include <vector>

using namespace std;

typedef long long ll;

vector<ll> parent, urank, connected;

ll root(ll x) { return (parent.at(x) == x ? x : parent.at(x) = root(parent.at(x))); }

ll size(ll x) { return connected.at(root(x)); }

bool in_same(ll x, ll y) { return root(x) == root(y); }

void unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x != y) {
        if (urank.at(x) < urank.at(y)) {
            parent.at(x) = y;
            connected.at(y) += connected.at(x);
        }
        else {
            parent.at(y) = x;
            if (urank.at(x) == urank.at(y)) ++(urank.at(x));
            connected.at(x) += connected.at(y);
        }
    }
}

int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    parent.resize(n + 1);
    urank.resize(n + 1);
    connected = vector<ll>(n + 1, 1);
    iota(parent.begin(), parent.end(), 0);
    vector<ll> ans(m + 1), a(m + 1), b(m + 1);
    for (ll i = 1; i <= m; ++i) scanf("%lld%lld", a.begin() + i, b.begin() + i);
    for (ll i = m; i >= 1; --i) {
        ans.at(i) = in_same(a.at(i), b.at(i)) ? 0 : size(a.at(i)) * size(b.at(i));
        unite(a.at(i), b.at(i));
    }
    for (auto i = ans.begin() + 1; i != ans.end(); ++i) printf("%lld\n", *i += *(i - 1));
    return 0;
}


Measured memory_bytes: 6016
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
fac = {0: 1, 1: 1}
finv = {0: 1, 1: 1}
inv = {1: 1}
a.sort()
mi = [0] * n
ma = [0] * n
s_mi = 0
s_ma = 0

def comb_init():
    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

comb_init()

for i in range(n):
    nn = n - i - 1
    if nn < k - 1:
        break
    else:
        mi[i] = comb(nn, k - 1)
        ma[-(i + 1)] = mi[i] 
    s_mi = (s_mi + mi[i] * a[i]) % mod
    s_ma = (s_ma + ma[-(i + 1)] * a[-(i + 1)]) % mod
print((s_ma - s_mi) % mod)

Measured memory_bytes: 44348
def main():
    S = input()
    S_list = [str(c) for c in S]

    max_count = 0
    for i, c in enumerate(S_list):
        counter = 0
        for j in range(i, len(S_list)):
            if S_list[j] == "A" or S_list[j] == "C" or S_list[j] == "G" or S_list[j] == "T":
                counter += 1
            else:
                break
        if max_count < counter:
            max_count = counter

    print(max_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
#define N 100000
#define Q 50000

int main(){
  int n,s[N],q,t[Q],i,j,sum=0,m,l,key,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&t[i]);
  
  for(i=0;i<q;i++){
    l=0;
    r=n;
    key = t[i];
    while(l<r){
      m = (l+r)/2;
      if(key==s[m]){
	sum++;
	break;
      }
      if(key > s[m])l=m+1;
      else if(key < s[m])r=m;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 1188
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""

#B
"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""

#C
"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""

#D
"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
    d[i+1].insert(0,0)
for i in range(n):
    for j in range(n):
        d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]

for a in range(n+1):
    for b in range(n+1):
        for c in range(a):
            for e in range(b):
                ans[(a-c)*(b-e)] = max(ans[(a-c)*(b-e)],d[a][b]-d[c][b]-d[a][e]+d[c][e])

for i in p:
    an = 0
    for a in range(i+1):
        an = max(an, ans[a])
    print(an)
"""
#E

"""
s = list(S())
ans = -1
s.insert(0,0)
d = 0
for i in range(1,len(s)):
    if s[i] != d:
        d = s[i]
        ans += 1
print(ans)
"""

#F
n = II()
x,y = LI()
for _ in range(n-1):
    a,b = LI()
    if a == b:
        x = max(x,y)
        y = x
    else:
        i = max(x//a,y//b)
        while 1:
            if a*i >= x and b*i >= y:break
            i += 1
        x = a*i
        y = b*i
print(x+y)
#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39280
def match(x, y):
    """
    １文字x, yが一致するか少なくとも一方が？であればTrueを返す。
    """
    return x == y or x == "?" or y == "?"


def func(a, b, c, la, lb, lc):
    """
    文字列の並びがa->b->cの場合を仮定して考える。
    aに対するb, cの配置が高々2000 * 2000通りあるので、文字列が一致するかの判定はO(1)でしないとTLE。
    これは先にaとb、bとc、aとcに対して文字列の一致を前処理確認しておけばOK <= 思いつかなかったので反省。

    ab[i] = (b[0]をa[i]から重ねたとき、合成文字列は一致するか)
    bc[i] = (c[0]をb[i]から重ねたとき、合成文字列は一致するか)
    ac[i] = (c[0]をa[i]から重ねたとき、合成文字列は一致するか)
    とおく。後ろに[True] * 2000を付け加えているのはaとbがdisjointな場合を考慮するため。
    """
    ab = [True] * (la + 4000)
    bc = [True] * (lb + 4000)
    ac = [True] * (la + 4000)

    for i in range(la):
        for j in range(min(la - i, lb)):
            if not match(a[i + j], b[j]):
                ab[i] = False
                break

    for i in range(lb):
        for j in range(min(lb - i, lc)):
            if not match(b[i + j], c[j]):
                bc[i] = False
                break

    for i in range(la):
        for j in range(min(la - i, lc)):
            if not match(a[i + j], c[j]):
                ac[i] = False
                break
    #print("ab={}".format(ab[:la]))
    #print("bc={}".format(bc[:lb]))
    #print("ac={}".format(ac[:la]))
    """
    前処理終わり。これより実際の比較を行う。
    """
    ans = la + lb + lc
    for i in range(la + 1):
        for j in range(max(lb + 1, la - i + 1)): # A上でBとCがdisjointに乗っかっている場合、j <= lbだと不十分(ex: A = "qaawbbe", B = "aa", C = "bb")
            if ab[i] and bc[j] and ac[i + j]:
                preans = max(la, i + lb, i + j + lc) # ここ(i + lb)入れないと、Bが一番長い場合が抜け落ちる
                ans = min(ans, preans)
    #print("{}->{}->{}: ans={}".format(a, b, c, ans))
    return ans


def main():
    a = input()
    b = input()
    c = input()
    la = len(a)
    lb = len(b)
    lc = len(c)
    ans = func(a, b, c, la, lb, lc)
    ans = min(ans, func(a, c, b, la, lc, lb))
    ans = min(ans, func(b, a, c, lb, la, lc))
    ans = min(ans, func(b, c, a, lb, lc, la))
    ans = min(ans, func(c, a, b, lc, la, lb))
    ans = min(ans, func(c, b, a, lc, lb, la))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 50184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi v(n), c(n);
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  int ans = -1e9;
  rep(i, 1 << n) {
    int num = 0;
    rep(j, n) if(i >> j & 1) num += v[j] - c[j];
    ans = max(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      String T = sc.next();
      
      String s=S;
      String t=T;
      
      System.out.println(t+s);
    }
}

Measured memory_bytes: 20688
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int unsigned long long

using namespace std;

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

    int n;
    cin >> n;

    vector<int> v(n);

    for (auto& i : v)
    {
        cin >> i;
    }

    sort(v.begin(), v.end());
    cout << v.back() - v.front() << endl;
}

Measured memory_bytes: 256
fn main() {
    let s: String = read();
    let mut v: Vec<char> = s.chars().collect();
    v.sort();

    if v[0] == v[1] && v[1] != v[2] && v[2] == v[3] {
        println!("Yes");
    } else {
        println!("No");
    }
}





//**********************************************************************************************************************************************//

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 4352
import numpy as np

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()

zero = a[a==0]
pos = a[a>0]
neg = a[a<0]

l = -10**18
r = 10**18

# 二分探索
# x以下になる組み合わせがいくつあるか計算する
while l+1<r:
    x = (l + r) // 2
    cnt = 0

    # 0になる組み合わせの個数のカウントを追加
    if x >= 0:
        cnt += n * len(zero)

    cnt += a.searchsorted(x//pos,side='right').sum()
    cnt += (n-a.searchsorted(-(-x//neg),side='left')).sum()
    cnt -= np.count_nonzero(a*a<=x)
    cnt//=2

    if cnt >= k:
        r = x
    else:
        l = x

print(r)


Measured memory_bytes: 32300
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    itn n,m;
    cin >> n >> m;
    int cnt = 0;
    int sum = 0;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    REP(i,n){
        if(double(a[i]) >= double(sum / (4.0 * m)))
            cnt++;
    }
    if(cnt >= m)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;

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

    ll n1=s.length();
    ll n2=(n1-1)/2,n3=(n1+3)/2;
    bool p1=1,p2=1,p3=1;;

    for(int i=0;i<n1-i;i++)
        if(s[i]!=s[n1-i-1]){
            p1=0;
            cout<<"No\n";
            break;
        }

    if(p1){
        for(int i=0;i<n2-i-1;i++)
            if(s[i]!=s[n2-i-1]){
                p2=0;
                cout<<"No\n";
                break;
            }
        if(p2){
            for(int i=n3;i<n1-i-1;i++)
                if(s[i]!=s[n1-i-1]){
                    p3=0;
                    cout<<"No\n";
                    break;
                }
            if(p3)
                cout<<"Yes\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;

long long int N,M,s,w,res=0;

int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 1; i <= N; i++){
        for(long long int j = 1; j <= N; j++){
            for(long long int k = 1; k <= N; k++){
                res+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define INF 0x3f3f3f3f
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
using namespace std;


int main()
{
  ll n;
  cin >> n;
  ll k;
  cin >> k;
  ll arr[n];
  fr(i,0,n)cin >> arr[i];
  bool dp[k+1];
  dp[0]=false;
  fr(i,1,k+1)
  {
       bool res = false;
       fr(j,0,n)
       {
          if((i-arr[j])>=0&&dp[i-arr[j]]==false)
         {
             res=true;
             break;
         }
       }
       dp[i]=res;
      // cout << dp[i] << " ";
  }
  if(!dp[k])
  {
      cout << "Second";
  }
  else
  {
      cout << "First";
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll k, s; cin >> k >> s;
    ll cnt = 0;
    for(ll x = 0; x <= k; ++x){
        for(ll y = 0; y <= k; ++y){
            ll tmp = s - x - y;
            if(tmp >= 0 && tmp <= k) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

template<class T>
constexpr T gcd(T a, T b) {
    if (a < b) gcd(b, a);
    T r = 0;
    while ((r = a % b)) { a = b; b = r; }
    return b;
}
template<class T>
constexpr T lcm(T a, T b) {
    T g = gcd<T>(a, b);
    return a / g * b;
}


int n;
bool ans[305];
void solve() {
    cin >> n;
    rep(i, n) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;

        if (a<b || b>d) {
            ans[i] = false;
        }
        else if (b <= c) {
            ans[i] = true;
        }
        else {
            auto g = gcd(b, d);
            if (c < a % g + b - g) ans[i] = false;
            else ans[i] = true;
        }
    }

    rep(i, n) cout << (ans[i] ? "Yes" : "No") << endn;
}

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


Measured memory_bytes: 256
n, m = map(int, input().split())
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [1]*n
        self.size = [1]*n
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]
    def unite(self, x, y):
        x = self.find(x); y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    def group_size(self, x):
        return self.size[self.find(x)]
uf = UnionFind(n); x = []
for _ in range(m):
    a, b = map(int, input().split()); a -= 1; b -= 1
    uf.unite(a, b)
for i in range(n): x.append(uf.find(i))
print(len(set(x))-1)

Measured memory_bytes: 23112
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    bool ok = (in == "AAA" or in == "BBB");

    cout << (ok ? "No":"Yes") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <set>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    string str;
    set<int> canmove;
    cin >> n >> m;
    cin >> str;
    if(str.find(string(m, '1')) != string::npos){
        cout << "-1\n";
        return 0;
    }
    if(m == 1){
        string ans = "1";
        for(int i = 1; i < n; i++){
            ans += " 1";
        }
        cout << ans << "\n";
        return 0;
    }
    for(int i = 0; i <= n; i++){
        if(str[i] == '1') continue;
        canmove.insert(i);
    }
    map<int, int> tomove;
    auto ep = end(canmove);
    list<int> ans;
    int p = n;
    while(p > 0){
        auto bp = canmove.lower_bound(p - m);
        ans.push_front(p - *bp);
        p = *bp;
        canmove.erase(bp, canmove.end());
    }
    while(ans.size() > 1){
        cout << ans.front() << " ";
        ans.pop_front();
    }
    cout << ans.back() << "\n";
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, c; cin >> n >> c;
    vi sum(200010, 0);
    map<ll, vector<pair<ll, ll>>> prog;
    rep(i, n){
        ll s, t, c;
        cin >> s >> t >> c;
        prog[c].emplace_back(make_pair(s, t));
    }
    for(auto &p: prog){
        sort(all(p.second));
        ll size = p.second.size();
        for(ll i=0; i<size; i++){
            ll s = p.second[i].first;
            ll t = p.second[i].second;
            if(i == 0){
                sum[s*2-1]++;
                sum[t*2+1]--;
            }
            else{
                // 前の番組から連続して録画したほうが良い場合
                if(s == p.second[i-1].second){
                    sum[s*2+1]++;
                    sum[t*2+1]--;
                }
                // 連続撮影しない場合
                else{
                    sum[s*2-1]++;
                    sum[t*2+1]--;
                }
            }
        }
    }

    ll ans = 0;
    repf(i, 200000){
        sum[i+1] += sum[i];
        chmax(ans, sum[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7356
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}




int main(void) {
	LL s;
	cin >> s;
	map<LL, LL>m;
	m[s]++;
	LL i = 1;
	while (true) {
		i++;
		if (s % 2 == 0) {
			s /= 2;
		}
		else {
			s = 3 * s + 1;
		}
		if (m[s] > 0) {
			cout << i;
			return 0;
		}
		else {
			m[s]++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll cnt_01 = 0, cnt_10 = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] == '0') {
                cnt_01++;
            } else {
                cnt_10++;
            }
        } else {
            if (s[i] == '0') {
                cnt_10++;
            } else {
                cnt_01++;
            }
        }
    }
    cout << min(cnt_01, cnt_10) << endl;
    return 0;
}

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

class union_find {
	vector<int> data;
	
public:
	union_find(int size) {
		data.assign(size, -1);
	}
	
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	
	int find(int k) {
		if (data[k] <	0) return k;
		return data[k] = find(data[k]);
	}
	
	int size(int k) {
		return -data[find(k)];
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main(void) {
	i64 n, m;
	vector<pair<i64, i64>> b;
	cin >> n >> m;
	vector<i64> ans(m);
	union_find zohe(n);
	for (i64 i = 0; i < m; i++) {
		i64 x, y;
		cin >> x >> y;
		x--; y--;
		b.push_back({x, y});
	}
	for (i64 i = m; i >= 1; i--) {
		if (i == m) {
			ans[i - 1] = n * (n - 1) / 2;
			continue;
		}
		if (zohe.same(b[i].first, b[i].second)) ans[i - 1] = ans[i];
		else ans[i - 1] = ans[i] - zohe.size(b[i].first) * zohe.size(b[i].second);
		zohe.unite(b[i].first, b[i].second);
	}
	for (i64 i = 0; i < m; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4208