akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
ll a[200000];

int main() {
    init();
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < 5; i++) {
		if (a[i] == 0) ans = i;
	}
	cout << ans + 1 << endl;


    return 0;
}

Measured memory_bytes: 3600
n,a,b = map(int,input().split())
H = [int(input()) for _ in range(n)]

def ok(x):
    cnt = 0
    for h in H:
        cnt += max(0, (h - b*x-1)//(a-b)+1)
    return cnt <= x

top = 10**9
bottom = 0
while top - bottom > 1:
    mid = (top + bottom)//2
    if ok(mid):
        top = mid
    else:
        bottom = mid
print(top)


Measured memory_bytes: 7072
def f(n):
    if n % 2 == 0:
        return n /2 
    else:
        return 3 * n + 1

def ans1(s):
    a = list()
    a.append(s)
    a.append(f(s))

    while True:
        x = f(a[-1])
        if x in a:
            return len(a) + 1
        else:
            a.append(x)

def ans2(s):
    if s == 1:
        return 4
    
    if s == 2:
        return 4
    
    n = s
    i = 0
    while n != 4:
        n = f(n)
        i += 1
    return i + 4

s = int(input())
print(ans2(s))


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

using namespace std;

#define int long long

int a, b, c, d;

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

	cin >> a >> b >> c >> d;
	cout << max(a * c, max(a * d, max(b * c, b * d)));
}

Measured memory_bytes: 3688
#include<stdio.h>
 
int main(){
  int X,Y;
  int A,B;
  while(scanf("%d %d",&X,&Y)==0);
    
  //A=2*X-Y/2;
  //B=(Y-2*X)/2;
  
  if(2*X>Y)
    printf("No\n");
   else if(Y%2!=0)
    printf("No\n");
  else if((Y<2*X)||(Y>4*X))
    printf("No\n");
  else
    printf("Yes\n");
  
  return 0;
}

Measured memory_bytes: 1644
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
    	break
    while b[j] > K - a[i]:
    	j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47612
import java.util.Scanner;

public class Main {

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

    int num = sc.nextInt();
    while (num != 0) {
      int cnt = -0;
      for (int i = 1; i < num + 1; i++) {
        int sum = 0;
        for (int j = i; j < num + 1; j++) {
          sum += j;
          if (sum == num) {
            cnt++;
            break;
          } else if (sum > num) {
            continue;
          }
        }
      }
      System.out.println(cnt - 1);
      num = sc.nextInt();
    }

    sc.close();
  }

}

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

typedef vector<vector<int> > Graph;
struct Node{
  int ord, min_ord;
};
class ArticulationFind{
public:
  ArticulationFind(Graph _g){
    g = _g;
    node.resize(g.size(), Node{-1, (int)1e9});
  }
  vector<int> find(){
    if(v_ord == 0)dfs();
    return articulation;
  }
private:
  void dfs(int v  = 0,
           int previous = -1){
    int to, cnt = 0;
    node[v].ord = node[v].min_ord = v_ord++;
    bool isAP = false;
    for (int i = 0; i < g[v].size(); i++) {
      to = g[v][i];
      if(previous == to)continue;
      cnt += (node[to].ord == -1);
      if(node[to].ord == -1){
        dfs(to, v); 
        node[v].min_ord = min(node[v].min_ord,
                              node[to].min_ord);
        isAP |= ((node[v].ord != 0) and
                 (node[v].ord <= node[to].min_ord));
      }
      node[v].min_ord = min(node[v].min_ord,
                            node[to].ord);
    }
    if(cnt > 1 and node[v].ord == 0)isAP = true;
    if(isAP)articulation.emplace_back(v);
  }
  int v_ord = 0;
  vector<int> articulation;
  Graph g;
  vector<Node> node;
};

int main(int argc, char *argv[]){
  int n, m;
  std::cin >> n >> m;
  Graph g(n, vector<int>());
  for (int i = 0; i < m; i++) {
    int to, from;
    std::cin >> to >> from;
    g[to].push_back(from);
    g[from].push_back(to);
  }
  ArticulationFind af(g);
  vector<int> articulation = af.find();
  sort(articulation.begin(), articulation.end());
  for (int i = 0; i < articulation.size(); i++) {
    std::cout << articulation[i] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int fac[1000010], facinv[1000010];
int n, m;
inline int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
inline int C(int n, int m) {
    if (m > n || m < 0) return 0;
    return 1ll * fac[n] * facinv[m] % mod * facinv[n - m] % mod;
}
int main() {
    scanf("%d%d", &n, &m);
    if (n > m) swap(n, m);
    fac[0] = facinv[0] = facinv[1] = 1;
    for (int i = 2; i <= n + m; i++) facinv[i] = 1ll * (mod - mod / i) * facinv[mod % i] % mod;
    for (int i = 1; i <= n + m; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
    for (int i = 1; i <= n + m; i++) facinv[i] = 1ll * facinv[i - 1] * facinv[i] % mod;
    int ans = 0;
    for (int i = 1; i <= n; i++) ans = (ans + 1ll * C(i + i, i) * C(n + m - i - i, n - i) % mod * power(C(n + m, n), mod - 2)) % mod;
    ans = 1ll * ans * power(2, mod - 2) % mod;
    return cout << (ans + m) % mod << endl, 0;
}

Measured memory_bytes: 8064
# 04.77 sec -> Time Limit Exceeded?
import sys
import math

# Sieve of Eratosthenes
N = 50021
searchList = list(range(3, N + 1, 2))
primes = [2]
while True:
  top = searchList.pop(0)
  primes.append(top)
  if top > math.sqrt(N):
    break
  searchList = [s for s in searchList if s % top != 0]
primes.extend(searchList)

# solve
for line in sys.stdin:
  try:
    n = int(line)
    pre = 2
    for p in primes:
      if p < n:
        pre = p
      if p > n:
        print(pre, p)
        break
  except:
    break

Measured memory_bytes: 6656
n = input()
mark = ['S', 'H', 'C', 'D']
cards = ["{} {}".format(mark[i], j+1) for i in range(4) for j in range(13)]
for i in range(n):
	cards.remove(raw_input())
while len(cards) != 0:
	print cards.pop(0)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

const ll mod = 1e9+7;

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    vector<ll> SA(N+1);
    for (int i = N-1; i >= 0; i--)
    {
        SA[i] = SA[i+1] + A[i];
        SA[i] %= mod;
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += A[i]*SA[i+1];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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

typedef long long LL;

const int N=5000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);;return res;}

int n,a,b;

void into(){
  scanf("%d%d%d",&n,&a,&b);
}

int f[N+9][2],g[N+9];

void Get_g(){
  if (a>b) swap(a,b);
  if (b==1) return;
  g[0]=f[0][0]=f[0][1]=1;
  for (int i=1;i<=n;++i){
	for (int j=1;j<=i;++j){
	  sadd(f[i][1],f[i-j][0]);
	  if (j>=a) sadd(f[i][0],f[i-j][1]);
	}
	g[i]=add(f[i][0],f[i][1]);
  }
}

int dp[N+9][2],sum[N+9],ans;

void Get_dp(){
  if (b==1) return;
  for (int i=1;i<n;++i){
	if (i<a) dp[i][0]=1;
	for (int j=1;j<i&&j<a;++j) sadd(dp[i][0],dp[i-j][1]);
	if (i<b) dp[i][1]=g[i-1];
	for (int j=1;j<i&&j<b;++j) sadd(dp[i][1],mul(dp[i-j][0],j==1?1:g[j-2]));
	if (n-i<b) sadd(ans,mul(dp[i][0],g[n-i-1]));
	if (n-i<a) sadd(ans,dp[i][1]);
  }
}

void work(){
  Get_g();
  Get_dp();
}

void outo(){
  printf("%d\n",sub(Power(2,n),ans));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main(){
	int N, K, i, j;
	scanf("%d%d", &N, &K);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	int *dp = (int *)malloc(sizeof(int) * (K + 1));
	for(i = 0; i <= K; i++){
		dp[i] = 0;
	}
	for(i = 1; i <= K; i++){
		for(j = 0; j < N && a[j] <= i; j++){
			dp[i] |= (dp[i - a[j]] ^ 1);
		}
	}
	if(dp[K] == 0){
		printf("Second\n");
	}
	else{
		printf("First\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<string>
#define f first
#define s second
using namespace std;
 
int T(string s){
  int time=0;
  string s1=s.substr(0,2);
  string s2=s.substr(3,2);
  time+=(60)*atoi(s1.c_str());
  time+=atoi(s2.c_str());
  return time;
}
 
int main()
{
  int N,n;
  string s1,s2;
  char c;
 
  while(1){
    cin>>N;
    if(N==0)break;
    int S[1000]={};
    vector<vector<pair<string,pair<int,int> > > > V(1000);
    for(int i=0;i<N;i++){
      cin>>s1>>s2>>c>>n;
      if(c=='I')S[n]=T(s2);
      else {
    V[n].push_back(make_pair(s1,make_pair(S[n],T(s2))));
    S[n]=0;
      }
    }
    for(int i=0;i<1000;i++)S[i]=0;
    for(int k=1;k<1000;k++){
      if(V[k].empty())continue;
      for(int i=0;i<V[0].size();i++){
    for(int j=0;j<V[k].size();j++){
      if(V[0][i].f!=V[k][j].f)continue;
      //0 1 1 0
      if(V[0][i].s.f<=V[k][j].s.f && V[k][j].s.s<=V[0][i].s.s){
        S[k]+=(V[k][j].s.s-V[k][j].s.f);
      }
      //1 0 0 1
      else if(V[k][j].s.f<=V[0][i].s.f && V[0][i].s.s<=V[k][j].s.s){
        S[k]+=(V[0][i].s.s-V[0][i].s.f);
      }
      //0 1 0 1
      else if(V[0][i].s.f<=V[k][j].s.f && V[k][j].s.f <=V[0][i].s.s){
        S[k]+=(V[0][i].s.s-V[k][j].s.f);
      }
      //1 0 1 0
      else if(V[0][i].s.f<=V[k][j].s.s && V[k][j].s.s <=V[0][i].s.s){
        S[k]+=(V[k][j].s.s-V[0][i].s.f);
      }
    }
      }
    }
    int ans=0;
    for(int i=1;i<1000;i++)ans=max(ans,S[i]);
    cout<<ans<<endl;
/*
    for(int k=0;k<5;k++){
      for(int i=0;i<V[k].size();i++)cout<<V[k][i].f<<" "<<V[k][i].s.f<<" "<<V[k][i].s.s<<" "<<k<<endl;
      }*/
  }
  return 0;
}


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

int main()
{
    vector<int> v = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int k;
    cin >> k;
    cout << v[k-1] << endl;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118B();
	}
}

class Calc{
  void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	}
}

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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2 + y1 - y2 << " " << y2 + x2 - x1 << " " << x1 + y1 - y2 << " " << y1 + x2 - x1 << endl;
}

Measured memory_bytes: 256
from itertools import product

H, W, K = list(map(int, input().split()))
# 黒なら1
board = [[1 if x == '#' else 0 for x in list(input())] for _ in range(H)]

ans = 0
# 塗らないなら1
for row in product([0, 1], repeat=H):
    for col in product([0, 1], repeat=W):
        # 元が黒でタテヨコ塗らないマスを数える
        blacks = sum([board[h][w] * row[h] * col[w] for h in range(H) for w in range(W)])
        if blacks == K:
            ans += 1
print(ans)


Measured memory_bytes: 74096
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    use std::iter;

    let (a, b) = get_tuple!(usize, usize);
    let (min, max) = if a < b { (a, b) } else { (b, a) };

    // min を max 回繰り返したものが答えになるはず
    // let ans = min.to_string().repeat(max as usize);
    let ans: String = iter::repeat(min.to_string()).take(max).collect();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
    int n, l;
    cin >> n >> l;
    int arr[200], i, j, arr1[n]={0}, sum=0, low=100000, s;
    for(i=0, j=1; i<200; i++){
        arr[i]=j;
        j++;}
    for(i=0; i<n; i++){
        arr1[i]=l+i;
        sum=sum+arr1[i];}
    for(i=0; i<n; i++){
        s = sum-arr1[i];
        if(sum-s<abs(low))
            low=sum-s;
    }
    cout << sum-low;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <list>



int main()
{
	int n, a, b;
	std::cin >> n >> a >> b;
	int result;
	result = (n * a > b) ? b : a * n;
	std::cout << result;

    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    {
        //! 偶数番目に犬
        ll a = 1;
        ll n = N, m = M;
        REP(i, N + M)
        {
            if (i % 2 == 0)
                a *= n--;
            else
                a *= m--;
            a %= MOD;
        }
        ans += a;
    }
    {
        //! 偶数番目に猿
        ll a = 1;
        ll n = N, m = M;
        REP(i, N + M)
        {
            if (i % 2 == 0)
                a *= m--;
            else
                a *= n--;
            a %= MOD;
        }
        ans += a;
    }
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(){
    int h,n,x,s=0;
    cin>>h>>n;
    for(int i=1;i<=n;i++){
    	cin>>x;
    	s+=x;
    }
    if(s>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
//BECAUSE ONE TRUTH PREVAILS
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
int main() {
    LL N;
    cin>>N;
    vector<LL> arr(N);
    for(auto &it:arr)
    {
        cin>>it;
    }
    unordered_map<LL,LL> Hash;
    for(auto it:arr)
        Hash[it]+=1;
    LL sum=0;
    for(auto it:arr)
    {
        sum+=it;
    }
    LL Q;cin>>Q;while(Q--)
    {
        LL L , R;
        cin>>L>>R;
        LL count=Hash[L];
        sum=sum-L*count + R*count;
        Hash[L]=0;
        Hash[R]+=count;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 7916
package main

import (
	"fmt"
	"sort"
)

func main() {
	var k, n int
	fmt.Scan(&k, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	d := make([]int, n)
	for i := 1; i < n; i++ {
		d[i-1] = a[i] - a[i-1]
	}
	d[n-1] = (k - a[n-1]) + a[0]
	sort.Ints(d)

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += d[i]
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 6656
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int passed = 0, overseas = 0;
	for(auto &c : s)
	{
		if(c == 'a')
		{
			if(passed < a + b)
			{
				++passed;
				cout << "Yes\n";
			}
			else cout << "No\n";
		}
		else if(c == 'b')
		{
			if(passed < a + b && overseas < b)
			{
				++passed;
				++overseas;
				cout << "Yes\n";
			}
			else cout << "No\n";
		}
		else cout << "No\n";
	}
}

Measured memory_bytes: 3812
class Node:
    def __init__(self, parent, left, right):
        self.parent, self.left, self.right = parent, left, right

N = int(input())
T = [Node(None, None, None) for _ in range(N)]
for t in T:
    i, left, right = map(int, input().split())
    if left != -1:
        T[i].left = left
        T[left].parent = i
    if right != -1:
        T[i].right = right
        T[right].parent = i

def preorder(i):
    if i == None:
        return
    print(' {}'.format(i), end='')
    preorder(T[i].left)
    preorder(T[i].right)

def inorder(i):
    if i == None:
        return
    inorder(T[i].left)
    print(' {}'.format(i), end='')
    inorder(T[i].right)

def postorder(i):
    if i == None:
        return
    postorder(T[i].left)
    postorder(T[i].right)
    print(' {}'.format(i), end='')

root = 0
for i, t in enumerate(T):
    if t.parent == None:
        root = i

print('Preorder')
preorder(root)
print()
print('Inorder')
inorder(root)
print()
print('Postorder')
postorder(root)
print()


Measured memory_bytes: 5616
a,b=map(int,input().split())
c=[]
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
d=gcd(a,b)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors
e=make_divisors(d)
y=0
n=len(e)
for i in range(n):
    x=0
    for j in range(n):
        if e[i]%e[j]!=0:
            x+=1
        elif e[j]!=1 and i!=j:
            break
    if x==n-2:
        y+=1
print(y+1)

Measured memory_bytes: 3272
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	ll n, x;

	cin >> n >> x;

	vector<ll> v(n, 0);

	REP(i, n) {
		cin >> v[i];
	}

	ll ans = 0;
	ll now = 0;

	REP(i, n + 1) {
		if (now > x) {
			break;
		}
		ans++;
		now += v[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n;
cin>>n;
vector<ll>v;
ll sum=0;
unordered_map<ll,ll>mp;
for(ll i=0;i<n;i++)
{
    ll a;
    cin>>a;
    v.pb(a);
    sum+=a;
    mp[a]++;
}
ll q;
cin>>q;
while(q--)
{
    ll b,c;
    cin>>b>>c;
    if(mp.count(b))
    {
        ll x=mp[b];
        sum=sum-x*b;
        sum=sum+x*c;
        mp[c]+=x;
        mp.erase(b);
    }
    cout<<sum<<endl;
}
return 0;
}


Measured memory_bytes: 7460
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))
    l = permutations(list(range(1, n+1)))
    if p == q:
        print(0)
    else:
        for idx, item in enumerate(l):
            if item == p:
                idp = idx
            elif item == q:
                idq = idx
        print(abs(idp - idq))

if __name__ == '__main__':
    main()

Measured memory_bytes: 64876
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int k=sc.nextInt();
    String s=sc.next();
    if(s.length()<=k)
	System.out.println(s);
    else
    {
      String x="";
      for(int i=0;i<k;i++)
        x+=s.charAt(i);
      x+="...";
      System.out.println(x);
    }
 
    
    
  }
}

Measured memory_bytes: 27100
# -*- coding:utf-8 -*-
# /usr/bin/python3

from heapq import heappush, heappop

def main():
  n, m = map(int, input().strip().split(' '))
  liAB = [tuple(map(int, input().strip().split(' '))) for _ in range(n)]
  liAB.sort(key=lambda x:x[0])

  k = 1
  top = []
  s = 0
  for a, b in liAB:
    if a >= m+1:
      break

    if k < a:
      s += (-sum([heappop(top) for _ in range(a-k) if len(top) != 0]))
      k = a
    heappush(top, -b)

  s += (-sum([heappop(top) for _ in range(m-k+1) if len(top) != 0]))
  print(s)

if __name__=='__main__':
  main()



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

const int MOD = (int)1e9+7;

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

	int aa=0;
	for(int i=0;i<N;i++){
		aa=aa^a.at(i);
	}
	if(aa==0)	cout << "Yes" << endl;
	else	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int ans = 0;
        for (int i = 1; i < N; i++) {
            int C = 0;
            String S1 = S.substring(0, i + 1);
            String S2 = S.substring(i + 1, N);
            for (char c = 'a'; c <= 'z'; c++) {
                if (S1.contains(String.valueOf(c))&&S2.contains(String.valueOf(c))) {
                    C++;
                }
            }
            ans=Math.max(C,ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 256
while True:
    Ascore = 0
    Bscore = 0
    n = int(input())
    if n == 0:
        break 
    for _ in range(n):
        a,b = map(int,input().split())
        if a > b:
            Ascore += a+b
        elif a < b:
            Bscore += a+b
        else:
            Ascore += a
            Bscore += b
    print(Ascore,Bscore)


Measured memory_bytes: 5616
N = int(input())
S = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(N-1,0,-1):
        if S[j-1] > S[j]:
            S[j-1], S[j] = S[j], S[j-1]
            count += 1

for i in range(N):
    if i==N-1:
        print(S[i])
    else:
        print(S[i],end=' ')
print(count)


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
bool exist[108][108];
int main(){  
	int n, w, h, x, y, s, t;
	while(cin >> n, n){
		cin >> w >> h;
		for(int i = 0;i <= 100;i++)
			for(int j = 0;j <= 100;j++)
				exist[i][j] = false;
		for(int i = 0;i < n;i++){
			cin >> x >> y;
			exist[x][y] = true;
		}
		cin >> s >> t;
		int res = 0;
		for(int i = 0;i + s - 1<= w;i++){
			for(int j = 0;j + t - 1<= h;j++){
				int tmp = 0;
				for(int k = i;k < i + s;k++){
					for(int l = j;l < j + t;l++){
						if(exist[k][l])tmp++;
					}
				}
				res = max(res, tmp);
			}
		}
		cout <<res << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    map<ll, int> A;
    map<ll, int> B;
    vector<ll> X;
    REP(i,N){
        ll a;
        cin >> a;
        A[a]++;
        B[a]++;
        if(A[a] == N/3) {
            X.push_back(a);
            A[a] = 0;
        }
    }

    bool ans = true;

    if(N % 3 != 0) ans = false;

    if(X.size() != 3) ans = false;

    //for(auto&& p : A){
    //    X.push_back(p.first);
    //    if(p.second != N/3) ans = false;
    //}

    if(ans && ((X[0] ^ X[1]) != X[2])){
        //cout << "ok" << endl;
        //REP(i,3) cout << X[i] << endl;
        ans = false;
    }

    if(B[0] == N) ans = true;

    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }




    return 0;
}


Measured memory_bytes: 9856
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    String r, g, b;

    AtCoder(FastScanner sc) {
        r = sc.next();
        g = sc.next();
        b = sc.next();
    }

    void solve(PrintWriter out) {
        String s = r + g + b;
        out.println(Integer.valueOf(s) % 4 == 0 ? "YES" : "NO");
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    bool operator==(const mint& m){
        return n == m.n;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if((t & 1) == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N;
ll A[100010];
ll d[100010];

mint f[100010];
mint inv[100010];

mint comb(ll a, ll b){
    if(a < b) return mint(0);
    return f[a] * inv[b] * inv[a-b];
}

int main(){
    cin >> N;
    ll l,r;
    for(int i=0;i<N+1;i++) cin >> A[i];
    for(int i=0;i<N+1;i++){
        if(d[A[i]] == 0){
            d[A[i]] = i+1;
            continue;
        }
        l = d[A[i]]-1;
        r = N - i;
    }
    f[0] = mint(1);
    for(int i=1;i<=N+3;i++) f[i] = f[i-1] * mint(i);
    for(int i=0;i<=N+3;i++) inv[i] = f[i].inv();
    for(int k=1;k<=N+1;k++){
        if(k == 1){
            cout << N << endl;
            continue;
        }
        cout << comb(N+1,k) - comb(l+r,k-1)<< endl;
    }
    return 0;
}

Measured memory_bytes: 6532
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:continue
        for i in range(1,s):
            x = pow(x,2,n)
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    else:
        d,s = n-1, 0
        while not d%2:d,s = d>>1,s+1
        return maybe_prime(d,s,n)

cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Measured memory_bytes: 7768
#include <iostream>
#include <algorithm> 

using namespace std;

#define MAX 100000

struct Card 
{
	char suit;
	int value;
};

int partition(Card A[], int p, int r);
void quick_sort(Card A[], int p, int q);
bool compare(const Card & A, const Card & B);
bool is_stable(Card A[], Card B[], int n);

int main()
{
	Card A[MAX], B[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i].suit >> A[i].value;
	
	for (int i = 0; i < n; i++) B[i] = A[i];
	
	quick_sort(A, 0, n-1);
	stable_sort(B, B+n, compare);
	
	if (is_stable(A, B, n)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	
	for (int i = 0; i < n; i++)
	{
		cout << A[i].suit << ' ' << A[i].value << endl;
	}
	
	return 0;
}


int partition(Card A[], int p, int r)
{
	int key = A[r].value, i = p-1;
	for (int j = p; j < r; j++)
	{
		if (A[j].value <= key) swap(A[j], A[++i]);
	}
	swap(A[++i], A[r]);
	return i;
}


void quick_sort(Card A[], int p, int q)
{
	if (p < q)
	{
		int r = partition(A, p, q);
		quick_sort(A, p, r-1);
		quick_sort(A, r+1, q);
	}
}

bool compare(const Card & A, const Card & B)
{
	if (A.value < B.value) return true;
	return false;
}


bool is_stable(Card A[], Card B[], int n)
{
	for (int i = 0; i < n; i++)
	{
		if (A[i].suit != B[i].suit) return false;
	}
	return true;
}


Measured memory_bytes: 4656
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0, ans = 0;
    rep(i, n){
        sum = 0;
        if(a[i] > 0){
            while(i < n and a[i] > 0){
                sum += a[i];
                i++;
            }
        }
        ans += (sum / 2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  string T;
  cin >> T;
  ll lcm = N * M / __gcd(N, M);
  map<ll, char> X;
  ll cnt = 0;
  while (lcm / M * cnt < lcm) {
    X[lcm / M * cnt] = T[cnt];
    cnt += 1;
  }
  cnt = 0;
  while (lcm / N * cnt < lcm) {
    if (X[lcm / N * cnt] == '\0') {
      cnt += 1;
      continue;
    }
    else {
      if (X[lcm / N * cnt] != S[cnt]) {
        cout << "-1" << "\n";
        // cout << S[cnt] << ' ' << X.at(lcm / N * cnt) << "\n";
        return 0;
      }
    }
    cnt += 1;
  }
  cout << lcm << "\n";
}


Measured memory_bytes: 10880
N = int(input())

memo1 = []
memo2 = []
for i in range(N):
  S = input()
  sum_n = min_n = 0
  for s in S:
    if s == ')':
      sum_n -= 1
      min_n = min(min_n, sum_n)
    else:
      sum_n += 1
  if sum_n >= 0:
    memo1.append([min_n, sum_n])
  else:
    memo2.append([min_n-sum_n, -sum_n])

memo1.sort(reverse=True)
left = 0
for min_n, sum_n in memo1:
  if left + min_n < 0:
    print('No')
    quit()
  else:
    left += sum_n

memo2.sort(reverse=True)
right = 0
for min_n, sum_n in memo2:
  if right + min_n < 0:
    print('No')
    quit()
  else:
    right += sum_n

if left == right:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 186864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int, int, int> ti;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    ti d[n];
    for (int i = 0; i < n; i++) {
        d[i] = make_tuple(a[i] + b[i], a[i], b[i]);
    }
    sort(d, d + n);
    reverse(d, d + n);

    ll ascore = 0, bscore = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) ascore += get<1>(d[i]);
        else bscore += get<2>(d[i]);
    }

    cout << ascore - bscore << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;cin >> n >> q;
	string s;cin >> s;
	vector<char> t(q),d(q);
	rep(i,q) cin >> t.at(i) >> d.at(i);
	int l=-1,r=n;
	while(r-l>1){
		int mid=(r+l+1)/2;
		bool flg=false;
		rep(i,q){
			if(mid>=0 && mid<n && t.at(i)==s.at(mid)){
				if(d.at(i)=='L') mid--;
				else mid++;
			}
			if(mid<0){
				flg=true;
				break;
			}
			if(mid>=n) break;
		}
		if(flg) l=(r+l+1)/2;
		else r=(r+l+1)/2;
	}
	int l1=l;
	l=-1;r=n;
	while(r-l>1){
		int mid=(r+l+1)/2;
		bool flg=false;
		rep(i,q){
			if(mid>=0 && mid<n && t.at(i)==s.at(mid)){
				if(d.at(i)=='L') mid--;
				else mid++;
			}
			if(mid>=n){
				flg=true;
				break;
			}
			if(mid<0) break;
		}
		if(flg) r=(r+l+1)/2;
		else l=(r+l+1)/2;
	}
	l=l1;
	if(l>=r) cout << 0 << endl;
	else cout << n-l-(n-(r))-1 << endl;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define sz(x)       int(x.size())
//#define int         long long

using namespace std;

typedef pair<int, int> pii;
const int N = int(2e5 + 5);
const int inf = (int)1e9 + 7;

int n, m, l, r, b[N], cnt[N], f, g;
vector<int> q[N];
struct TSegment {
    vector<int> l, h;
    vector<pii> st;
    void build(int x, int low, int high) {
        l[x] = low, h[x] = high, st[x] = {inf, inf};
        if(l[x] == h[x]) return;
        int mid = (low + high) >> 1;
        build(x << 1, low, mid);
        build(x << 1 | 1, mid + 1, high);
    }
    void init(int n) {
        st.resize(4 * n + 8);
        l.resize(st.size()), h.resize(st.size());
        build(1, 0, n);
    }
    void upd(int x, int pos, int val) {
        if(l[x] > pos || h[x] < pos) return;
        if(l[x] == pos && h[x] == pos) {
            st[x].fi = min(st[x].fi, val);
            if(pos) st[x].se = min(st[x].se, val - pos + 2 * cnt[pos]);
            return;
        }
        upd(x << 1, pos, val);
        upd(x << 1 | 1, pos, val);
        st[x].fi = min(st[x << 1].fi, st[x << 1 | 1].fi);
        st[x].se = min(st[x << 1].se, st[x << 1 | 1].se);
    }
    int get(int x, int low, int high, bool type) {
        if(l[x] > high || h[x] < low) return inf;
        if(low <= l[x] && h[x] <= high) return (type? st[x].se: st[x].fi);
        return min(get(x << 1, low, high, type), get(x << 1 | 1, low, high, type));
    }
} it;

int diff(int l, int r) {
   return 2 * (cnt[r] - (l? cnt[l - 1]: 0)) - (r - l + 1);
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> b[i];
        cnt[i] = cnt[i - 1] + b[i];
    }
    cin >> m;
    for(int i = 1; i <= m; ++i) {
        cin >> l >> r;
        q[l].pb(r);
    }
    it.init(n); it.upd(1, 0, diff(1, n));
    for(int i = 1; i <= n; ++i) {
        sort(q[i].begin(), q[i].end());
        f = it.get(1, 0, i - 1, 0);
        for(int r: q[i]) {
            g = it.get(1, i - 1, r - 1, 1) - 2 * cnt[r] + r;
            it.upd(1, r, min(f - diff(i, r), g));
        }
    }
    cout << it.get(1, 0, n, 0) + n - cnt[n];
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll w, h, x, y;

int main(void) {
  // Here your code !
  scanf("%lld %lld %lld %lld", &w, &h, &x, &y);

  printf("%.10lf %d\n", double(w) * double(h) / 2.0, 2LL * x == w && 2LL * y == h);

  return 0;
}


Measured memory_bytes: 256