akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define F first 
#define S second
/*----------------------------------------*/

 

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;

    while(T--){
       
       string s;
       cin>>s;
       
       string t;
       cin>>t;
       
       int n=t.length();
       string s1;
       rep(i,n-1){
           s1.pb(t[i]);
       }
       
       if(s1==s) cout<<"Yes";
       else cout<<"No";
       
    }
    return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, 0), f(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    f[a[i]]++;
  }
  int ver = 1;
  if(n & 1)
  {
    if(f[0] != 1) ver = 0;
    for(int i = 1; i < n; i++)
    {
      if(i % 2 == 1 && f[i] != 0) ver = 0;
      else if(i % 2 == 0 && f[i] != 2) ver = 0;
    }
  }
  else
  {
    for(int i = 0; i < n; i++)
    {
      if(i % 2 == 1 && f[i] != 2) ver = 0;
      else if(i % 2 == 0 && f[i] != 0) ver = 0;
    }
  }
  for(int i = 0; i < (n / 2); i++)
  {
    (ver *= 2) %= MOD;
  }
  cout << ver << endl;
  return 0;
}


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

typedef struct Node {
    int parent, left, right;
} Node;

Node T[1000000];

void pre_order(int i){
    if (i == -1) return;
    cout <<" " << i;
    pre_order(T[i].left);
    pre_order(T[i].right);
}

void in_order(int i){
    if (i == -1) return;
    in_order(T[i].left);
    cout <<" " << i;
    in_order(T[i].right);
}

void post_order(int i){
    if (i == -1) return;
    post_order(T[i].left);
    post_order(T[i].right);
    cout <<" " << i;
}

int main(){
    int n, node, left, right;
    cin >> n;
    for (int i = 0; i<n; i++){
        T[i].parent = -1;
    }

    for (int i = 0; i<n; i++){
        cin >> node >> left >> right;
        T[node].left = left;
        T[node].right = right;
        if (left != -1){
            T[left].parent = node;
        }
        if (right != -1){
            T[right].parent = node;
        }
    }

    int root;
    for (int i = 0; i<n; i++){
        if (T[i].parent == -1) root = i ;
    }
    cout << "Preorder" << endl;
    pre_order(root);
    cout << endl;
    cout << "Inorder" << endl;
    in_order(root);
    cout << endl;
    cout << "Postorder" << endl;
    post_order(root);
    cout << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <math.h>

void walk(double current_point[2], int r, int sum_theta) {
	double pi = 3.14159265358979; 
	double rad = ((double)sum_theta / 180) * pi;
	current_point[0] += r * sin(rad);
	current_point[1] += r * cos(rad);
}

int main() {
	int r;
	int theta;
	int sum_theta = 0;
	double current_point[2] = {0, 0};

	do {
		scanf("%d,%d", &r, &theta);

		walk(current_point, r, sum_theta);
		sum_theta += theta;
	} while(r || theta);

	printf("%d\n", (int)current_point[0]);
	printf("%d\n", (int)current_point[1]);

	return 0;
}

Measured memory_bytes: 1032
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n[100000], cnt, ans = 0, num[2];
    num[0] = 0, num[1] = 0;

    for (int i = 0; i < 100000; i++)
    {
        if ((n[i] = getchar()) == '\n')
        {
            cnt = i;
            break;
        }

        if (n[i] == 48)
        {
            num[0]++;
        }
        else
        {
            num[1]++;
        }
    }

    if (num[0] <= num[1])
    {
        ans = 2 * num[0];
    }
    else
    {
        ans = 2 * num[1];
    }

    printf("%d\n", ans);

    return 0;
    //0が48 1が49に対応
}

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

int get(int x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

int main()
{
    int n;
    scanf("%d",&n);
    int ans=1000;
    for(int i=1;i<n;i++)
    {
        ans=min(ans,get(i)+get(n-i));
    }
    printf("%d\n",ans);
}

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

int main() {
  int N;
  cin >> N;
  
  int maxcount = 0;
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    int x = i;
    int count = 0;
    
    while (x % 2 == 0) {
      count++;
      x /= 2;
    }
    
    if (count > maxcount) {
      maxcount = count;
      ans = i;
    }
  }
  
  
  cout << ans << endl;
}

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

int cake[400][400];
int cn[400];
int ans[400][400];

int main(){
    int h,w,k; cin >> h >> w >> k;
    int num=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin >> c;
            if(c=='#'){
                cn[i]++;
                cake[i][j]=num;
                num++;
            }else{
                cake[i][j]=0;
            }
        }
    }
    int from=0,to;
    int now=1;
    for(int i=0;i<h;i++){
        if(cn[i]==0) continue;
        to=i;
        for(int l=i+1;l<h;l++){
            if(cn[l]!=0) break;
            to=l;
        }
        for(int j=0;j<w;j++){
            if(cake[i][j]!=0) now=cake[i][j];
            for(int k=from;k<=to;k++){
                ans[k][j]=now;
            }
        }
        now=now+1;
        from=i+1;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << ans[i][j];
            if(j!=w-1) cout << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1664
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] e=new int[m];
		boolean[] check1=new boolean[n],check2=new boolean[n];
		for(int i=0;i<n;i++){
			check1[i]=true;
			check2[i]=true;
		}
		for(int i=0;i<m;i++){
			e[i]=sc.nextInt();
			check1[e[i]-1]=false;
		}
		for(int i=m-1;i>=0;i--){
			if(check2[e[i]-1]==true){
				System.out.println(e[i]);
				check2[e[i]-1]=false;
			}
		}
		for(int i=0;i<n;i++){
			if(check1[i]==true){
				System.out.println(i+1);
			}
		}
	}
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> P(M);
  for(int i = 0; i < M; ++i) cin >> P[i], --P[i];
  vector<long long> A(N-1), B(N-1), C(N-1);
  for(int i = 0; i < N-1; ++i) cin >> A[i] >> B[i] >> C[i];
  vector<int> imos(N+1,0);
  for(int i = 1; i < M; ++i){
    int p = min(P[i-1],P[i]), q = max(P[i-1],P[i]);
    ++imos[p];
    --imos[q];
  }
  for(int i = 1; i <= N; ++i) imos[i] += imos[i-1];
  long long ans = 0;
  for(int i = 0; i < N-1; ++i){
    ans += min(A[i]*imos[i],B[i]*imos[i]+C[i]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 5996
import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.System.*;
public class Main
{
public static void  main (String args[])throws Exception
{
Scanner sc=new Scanner(in);
int n=sc.nextInt();
int m=sc.nextInt();
int arr[][]=new int[n][2];
int brr[][]=new int[m][2];
for(int i=0;i<n;i++)
{
	arr[i][0]=sc.nextInt();
	arr[i][1]=sc.nextInt();
}
for(int i=0;i<m;i++)
{
	brr[i][0]=sc.nextInt();
	brr[i][1]=sc.nextInt();
}
int k=0;
int ans[]=new int[n];
for(int i=0;i<n;i++)
{
	ans[i]=Math.abs(arr[i][0]-brr[0][0]) + Math.abs(arr[i][1]-brr[0][1]);
	k=1;
	//out.println(Math.abs(arr[i][0]-brr[0][0]) + Math.abs(arr[i][1]-brr[0][1]));
	for(int j=m-1;j>=0;j--)
	{

		if((Math.abs(arr[i][0]-brr[j][0]) + Math.abs(arr[i][1]-brr[j][1]))<=ans[i])
		{k=j+1;ans[i]=Math.abs(arr[i][0]-brr[j][0]) + Math.abs(arr[i][1]-brr[j][1]);}
	}
	out.println(k);
}


}
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(a);
  IN(b);
  vector<int> list = {a, a-1, b, b-1};
  sort(ALL(list));
  cout<<list[2]+list[3]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int divisor(int n){
    int res = 0;
    for (int i = 1; i*i < n; i++) {
        if(n % i == 0) {
            res += 1;
        } 
    }
    return res;
}

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

    int count = 0;
    for (int i = 1; i <= n; i++) {
        if((i % 2 == 1) && (pow(2,divisor(i)-1) == 8)) {
            count += 1;
        } 
    }
    
    cout << count << endl;
    
    return 0;
}

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


typedef pair<int,int> pii;
vector< vector<pii> > edges;
vector<bool> used;

int solve() {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    for(int i=0; i<used.size(); i++)used[i] = false;
  
    que.push( make_pair(0,0) );
    int ret = 0;
    
    while(!que.empty()) {
        int cost = que.top().first, v = que.top().second;
        que.pop();
	
        if(used[v]) continue;
        used[v] = true;
        ret += cost;
        for(int i = 0; i < edges[v].size(); i++)
            que.push(pii(edges[v][i].first, edges[v][i].second));
    }
    return ret;
}


int main(){

  int V,E;
  
  cin >> V >> E;

  edges.resize(V);
  
  used.resize(V);

  for(int i=0; i<E; i++){
    int s,t,w;
    cin >> s >> t >> w;
    edges[s].push_back( make_pair(w,t) );
    edges[t].push_back( make_pair(w,s) );
  }

  cout << solve() << endl;

  return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,5){
        int a; cin>>a;
        if (a==0){
            cout<<i+1<<endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3648
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String x = sc.next();
		String y = sc.next();

                String ret = null;
                try {
                    int convertedX = Integer.parseInt(x, 16);
                    int convertedY = Integer.parseInt(y, 16);
                    if (convertedX > convertedY) {
                        ret = ">";
                    } else if(convertedX < convertedY) {
                        ret = "<";
                    } else if(convertedX == convertedY) {
                        ret = "=";
                    } else {
                        ret = "error!";
                    }
                } catch (NumberFormatException e) {
                    ret = "NumberFormatException";
                }
               
		// 出力
		System.out.println(ret);
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;

pair<ll, ll> dp[4000][4000];
vector<ll> a(4000);

pair<ll, ll> solve1(ll l, ll r);
pair<ll, ll> solve2(ll l, ll r);

pair<ll, ll> solve1(ll l, ll r) {
    if (l == r) {
        return {a[l], 0};
    }
    if (dp[l][r] != make_pair(0ll, 0ll)) {
        return dp[l][r];
    }
    auto c = solve2(l + 1, r);
    auto d = solve2(l, r - 1);
    c.first += a[l];
    d.first += a[r];
    if (c.first - c.second >= d.first - d.second) {
        dp[l][r] = c;
    } else {
        dp[l][r] = d;
    }
    return dp[l][r];
}

pair<ll, ll> solve2(ll l, ll r) {
    if (l == r) {
        return {0, a[l]};
    }
    if (dp[l][r] != make_pair(0ll, 0ll)) {
        return dp[l][r];
    }
    auto c = solve1(l + 1, r);
    auto d = solve1(l, r - 1);
    c.second += a[l];
    d.second += a[r];
    if (c.first - c.second <= d.first - d.second) {
        dp[l][r] = c;
    } else {
        dp[l][r] = d;
    }
    return dp[l][r];
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    cout.precision(20); cout << fixed;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto ans = solve1(0, n - 1);
    cout << ans.first - ans.second;
}


Measured memory_bytes: 188544
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll x(n), y(n);
  REP(i, n) cin >> x.at(i) >> y.at(i);
  map<P<ll, ll>, ll> pqmap;
  REP(i, n) REP(j, n) {
    if (i == j) continue;
    pqmap[{x.at(i)-x.at(j), y.at(i)-y.at(j)}]++;
  }
  ll ans = 0;
  for (auto pq: pqmap) {
    ans = max(ans, pq.second);
  }
  cout << n - ans << endl;
  return 0;
}


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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1.at(0)) << (char)toupper(s2.at(0)) << (char)toupper(s3.at(0)) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int mod = 1000000007;

vector<int> G[100100];
int N; long long D[100100], U[100100], A[100100];

void go(int x, int l)
{
	D[x] = 1;

	auto I = find(G[x].begin(), G[x].end(), l);
	if (I != G[x].end()) G[x].erase(I);

	for (auto &y : G[x]){
		go(y, x);
		D[x] = D[x] * (D[y] + 1) % mod;
	}
}

void go2(int x)
{
	int n = G[x].size();
	if (n){
		vector<long long> L(n); L[0] = 1;
		vector<long long> R(n); R.back() = 1;
		for (int i=1;i<n;i++) L[i] = L[i-1] * (D[G[x][i-1]] + 1) % mod;
		for (int i=n-2;i>=0;i--) R[i] = R[i+1] * (D[G[x][i+1]] + 1) % mod;
		for (int i=0;i<n;i++){
			int y = G[x][i];
			U[y] = (U[x] + 1) * L[i] % mod * R[i] % mod;
			go2(y);
		}
	}
	A[x] = D[x] * (U[x] + 1) % mod;
}

int main()
{
	scanf("%d %d", &N, &mod);
	for (int i=1;i<N;i++){
		int x, y; scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}

	go(1, 0);
	go2(1);

	for (int i=1;i<=N;i++) printf("%lld\n", A[i]);

	return 0;
}

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

int main(){
   ll n;
   cin>>n;
   vector<double> prob(n+1,0);
   
   
   for(int i=1;i<=n;i++){
       cin>>prob[i];
   }
    double dp[n+1][n+1] ;
   
   memset(dp,0,sizeof(dp));
   dp[0][0] = 1;
   for(int i=1;i<=n;i++){
       
       dp[0][i] = (1-prob[i])*dp[0][i-1];
       
       for(int j=1;j<=i;j++){
             
             dp[j][i] = prob[i] * dp[j-1][i-1] + (1-prob[i])*dp[j][i-1] ; 
       }
   }
   double ans =0;
   
   for(int i= n/2 +1;i<=n;i++){
       ans += dp[i][n] ;
   }
   cout<<setprecision(9)<<ans;
   
}

Measured memory_bytes: 70528
#include <iostream>

using namespace std;



#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

	cin >> n; 
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " "; 
  	cout << A[i];   }
  cout << endl; 
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 6948
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using lint = long int;
using llint = long long int;
using namespace std;

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

    double a, b, C;
    cin >> a >> b >> C;

    double rad(M_PI / 180.0);
    double S = (a * b) * sin(rad * C) / 2;
    double c = sqrt(a * a + b * b - 2 * a * b * cos(rad * C));
    double L = a + b + c;
    double h = b * sin(rad * C);

    cout << fixed << setprecision(10) << S << endl;
    cout << fixed << setprecision(10) << L << endl;
    cout << fixed << setprecision(10) << h << endl;
}


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


int main(){
	char s[10];
    int  t[10];
    for (int i=0;i<10;i++){
        cin >> s[i];
        t[i] = s[i] - '0';
    }

	if(t[0]*1000+t[1]*100+t[2]*10+t[3] <= 2019){
        if(t[5]*10+t[6]*1 <= 4){
            cout << "Heisei" << endl;
            return 0; 
        }
    }

    cout << "TBD" << endl;
    return 0; 

}

Measured memory_bytes: 256
/* ex4_3
    riverstone*/

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

int main(void){

    int height_West, height_East;
    int ans;
    scanf("%d %d",&height_West, &height_East);//西と東の雪の高さを計算

    ans=snowfall(height_West, height_East);//関数snowfallで計算した結果をansに代入
    printf("%d\n",ans);//ansを出力
    return 0;

}

//関数の定義
int snowfall(int height_a, int height_b){
    //雪の深さは以下のように定義される
    int snow_height=(height_b-height_a)*(height_b-height_a +1)/2 -height_b;
    return snow_height;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int mx=405;
typedef long long ll;
const ll INF=1e18+5LL;
ll dp[mx][mx];// dp[i][j] - min cost to merge range i to j in one slime
int main()
{
	int n;
	cin>>n;
	ll a[n],sum[n]={};
	for(int i=0;i<n;i++){ cin>>a[i];if(i>0)sum[i]=sum[i-1]+a[i];else sum[i]=a[i]; }
	for(int i=n-1;i>=0;i--)
	{
		for(int j=i;j<n;j++)
		{
			if(i==j)dp[i][j]=0;
			else 
			{
				dp[i][j]=INF;
				for(int k=i;k<j;k++)
				{
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]) ;
				}
				dp[i][j]+=sum[j]-( (i>0)?sum[i-1]:0);
			}
		}
	}
	/*
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cout<<dp[i][j]<<" ";
		}cout<<"\n";
	}
	*/
	printf("%lld",dp[0][n-1]);
}

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

typedef long long ll;
int n;
ll S, x[100233], p[100233], ans;
int main() {
  scanf("%d%lld", &n, &S);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &p[i]);
  }
  int l = 1, r = n;
  while (x[l] < S && x[r] > S) {
    ans += x[r] - x[l];
    if (p[l] >= p[r]) {
      while (p[l] >= p[r] && x[r] > S) {
        p[l] += p[r--];
      }
    } else {
      while (p[l] < p[r] && x[l] < S) {
        p[r] += p[l++];
      }
    }
  }
  ans += max(abs(S - x[l]), abs(S - x[r]));
  printf("%lld\n", ans);
}


Measured memory_bytes: 1920
#include <stdio.h>

int main() {
    /*
    変数定義するよ。
    n:行列あAの行数
    m:行列AとベクトルBの列数
    i:ループ用変数
    j:ループ用変数
    */
    int n = 0;
    int m = 0;
    int i = 0;
    int j = 0;
    int ans = 0;

    /*
    行列のサイズを読み込むよ。
    */
    scanf("%d %d",&n,&m);

    /*
    行列を定義するよ
    */
    int matrixa[100][100]={0};
    int matrixb[100]={0};
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&matrixa[i][j]);
        }
    }
    
    for(i=0;i<m;i++){
        scanf("%d",&matrixb[i]);
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            ans += matrixa[i][j] * matrixb[j];
        }
        printf("%d\n",ans);
        ans = 0;
    }
    
    return 0;
}


Measured memory_bytes: 2084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007)

#define REP(i,m,M) for(int i=m; i<M; i++)
#define REPR(i,M,m) for(int i=M; i>m; i—-)
#define REPLL(i,m,M) for(ll i=m; i<M; i++)
#define REPLLR(i,M,m) for(ll i=M; i>m; i—-)
#define ALL(v) v.begin(),v.end()

ll pow(ll n, ll x){
    if (x == 0LL) return 0LL;
    if(x == 1LL) return n;
    if(x%2==0){
        ll tmp = pow(n, x/2);
        return (tmp*tmp) % MOD;
    }
    else return (n*pow(n,x-1)) % MOD;
}

ll fact[100002], invFact[100002];

void fillFact(int n){
    fact[0] = 1LL;
    for(int i=1; i<=n+1; i++){
        fact[i] = (i*fact[i-1])%MOD;
    }
}

void fillInvFact(int n){
    invFact[0] = 1LL;
    for(int i=1; i<= n+1; i++){
        invFact[i] = (pow(i, MOD-2)*invFact[i-1])%MOD;
    }
}

ll C(int n, int m){
    if(n<m) return 0;
    ll tmp = fact[n];
    tmp = (tmp*invFact[m])%MOD;
    tmp = (tmp*invFact[n-m])%MOD;
    return tmp;
}


int place[100002];

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    vi v;
    int x, y;
    int i, tmp=0;
    for(i=0; i<n+1; i++){
        cin >> tmp;
        if(place[tmp]==0) place[tmp] = i+1;
        else break;
    }
    x = place[tmp]-1;
    y = n-i;
    //cerr << x << " " << y << endl;
   
    fillFact(n);
    fillInvFact(n);
    
    for(int k=1; k<=n+1; k++){
        printf("%lld\n",(C(n+1,k)+MOD-C(x+y,k-1))%MOD);
    }


    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ld N,M,D;
    cin >>  N >> M >> D;
    if(D==0){
        cout << stpr(10) << (M-1)/N << endl;
    }
    else{
        cout << stpr(10) << (N-D)/N*(M-1)/N*2 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int r;
    cin >> r;
    COUT(r*r);

}




Measured memory_bytes: 256
using System;

class Program {
  static void Main() {
    var s = new string[3];
    int t = 0;
    for (int i = 0; i < 3; i++) {
      s[i] = Console.ReadLine();
    }
    while (true) {
      if (s[t].Length == 0) break;
      int u = s[t][0] - 'a';
      s[t] = s[t].Substring(1);
      t = u;
    }
    Console.WriteLine((char)('A' + t));
  }
}

Measured memory_bytes: 13140
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    b = list(map(int, input().split()))
    b.insert(0,INF)
    b.append(INF)
    ans = []
    for i in range(len(b)-1):
        ans.append(min(b[i],b[i+1]))
    print(sum(ans))


if __name__=="__main__":
    main()


Measured memory_bytes: 9408
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

int n, a[100005];
int indeg[100005];
int cnt[100005];
vector<int> gph[100005];
vector<int> v;

int dfs2(int x, int p){
	vector<int> v;
	for(auto &i : gph[x]){
		if(indeg[i] || i == p) continue;
		v.push_back(dfs2(i, x) + 1);
	}
	if(v.size() >= 2) return 1e8;
	if(v.size() == 0) return 0;
	if(v.size() == 1) return v[0];
}

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}

int rv[100005], lb[100005];

lint solve(int x){
	queue<int> que;
	for(auto &i : v){
		if(indeg[i] == 0) que.push(i);
	}
	while(!que.empty()){
		int x = que.front();
		que.pop();
		indeg[a[x]]--;
		if(indeg[a[x]] == 0) que.push(a[x]);
	}
	vector<int> w;
	lint ret = 1;
	for(auto &i : v){
		if(indeg[i] == 1){
			w.push_back(i);
			for(int j=a[i]; j!=i; j=a[j]){
				w.push_back(j);
			}
			reverse(w.begin(), w.end());
			for(int i=0; i<w.size(); i++){
				rv[w[i]] = i;
				lb[w[i]] = dfs2(w[i], -1);
				if(lb[w[i]] > 1e7) return 0;
			}
			for(int i=0; i<w.size(); i++){
				if(lb[w[i]] > 0){
					int brk = 0;
					for(int j=i+1; j<=i+w.size(); j++){
						if(lb[w[j%w.size()]] > 0){
							brk = j - i;
							break;
						}
					}
					if(brk < lb[w[i]]) return 0;
					if(brk > lb[w[i]]) ret *= 2;
					ret %= mod;
				}
			}
			break;
		}
	}
	return ret;
}

int vis[100005];
void dfs(int x){
	v.push_back(x);
	vis[x] = 1;
	for(auto &i : gph[x]){
		if(!vis[i]) dfs(i);
	}
}

lint fact[100005], invf[100005], invp[100005];

lint match(int x, int k){
	return (fact[x] * invf[x-2*k] % mod) * (invf[k] * invp[k] % mod) % mod;
}


int main(){
	scanf("%d",&n);
	fact[0] = invf[0] = invp[0] = 1;
	for(int i=1; i<=n; i++){
		fact[i] = fact[i-1] * i % mod;
		invf[i] = ipow(fact[i], mod-2);
		invp[i] = invp[i-1] * (mod + 1) / 2;
		invp[i] %= mod;
	}
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		indeg[a[i]]++;
		gph[i].push_back(a[i]);
		gph[a[i]].push_back(i);
	}
	lint ret = 1;
	for(int i=1; i<=n; i++){
		if(vis[i]) continue;
		v.clear();
		dfs(i);
		int notsimple = 0;
		for(auto &i : v){
			if(indeg[i] != 1){
				notsimple = 1;
			}
		}
		if(!notsimple){
			cnt[v.size()]++;
		}
		else{
			lint w = solve(i);
			ret *= w;
			ret %= mod;
		}
	}
	for(int i=1; i<=n; i++){
		if(cnt[i] >= 1){
			lint tmp = 0;
			for(int j=0; j<=cnt[i]/2; j++){
				lint tmp2 = match(cnt[i], j) * ipow(i, j)% mod;
				if(i > 2 && i % 2 == 1) tmp2 *= ipow(2, cnt[i] - 2 * j) % mod;
				tmp += tmp2;
				tmp %= mod;
			}
			ret *= tmp;
			ret %= mod;
		}
	}
	cout << ret;
}


Measured memory_bytes: 15608
#include <vector>
#include <iostream>
using namespace std;
long long sum[2001][2001];
long long MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    for (int i =0; i < N; i++) cin >> S[i];
    for (int j= 0; j < M;j ++) cin >> T[j];

    sum[0][0] = 1;
    for (int i = 0; i <= N; i++) for (int j = 0; j <= M; j++) {
        if (j-1 >= 0) (sum[i][j] += sum[i][j-1]) %= MOD;
        if (i-1 >= 0) (sum[i][j] += sum[i-1][j]) %= MOD;
        if (j-1 >= 0 && i-1 >= 0) (sum[i][j] += MOD - sum[i-1][j-1]) %= MOD;

        if (i-1 >= 0 && j-1 >= 0 && S[i-1] == T[j-1]) {
            sum[i][j] += sum[i-1][j-1];
            sum[i][j] %= MOD;
        }
    }
    cout << sum[N][M] << endl;
}

Measured memory_bytes: 34744
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
	cin>>N;
	ll a=2,b=1;
	fx(N){
		ll k=a+b;
		a=b;
		b=k;
	}
	ce(a)
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

int n;
string group[1010];
vector< set< string > > member;

vector< string > split(string s, string t) {
	vector< string > res;
	for (int p = 0; (p = s.find(t)) != -1;) {
		res.push_back(s.substr(0, p));
		s = s.substr(p + size_of(t));
	}
	res.push_back(s);
	return res;
}

void rec(int p) {
	for_(i,0,n) {
		if (member[p].find(group[i]) != member[p].end()) {
			member[p].erase(group[i]);
			rec(i);
			
			set< string >::iterator it = member[i].begin();
			for (; it != member[i].end(); ++it) {
				member[p].insert(*it);
			}
		}
	}
}

void solve() {
	member.assign(n, set< string >());
	for_(i,0,n) {
		vector< string > gsplit = split(group[i], ":");
		group[i] = gsplit[0];
		vector< string > mems = split(gsplit[1], ",");
		
		int m_size = size_of(mems);
		for_(j,0,m_size) member[i].insert(mems[j]);
		
		/*
		set< string >::iterator it = member[i].begin();
		for(; it != member[i].end(); ++it) cout << *it << " ";
		cout << endl;
		*/
	}
	
	rec(0);
	
	cout << size_of(member[0]) << endl;
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) {
			cin >> group[i];
			group[i] = group[i].substr(0, size_of(group[i]) - 1);
		}
		solve();
	}
	return 0;
}

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

typedef long long int   ll;
#define int             ll
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%lld",&n)
#define pb              push_back
#define PI              3.1415926535897932384626433832795
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    int t=1;
//    scan(t);
    while(t--){
        char ch;cin>>ch;
        if(ch>='a' and ch<='z') cout<<"a";
        else cout<<"A";
    }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)

// maskの位置に＋を入れて演算を行うbit探索、以下写経
// 引用：http://mmxsrup.hatenablog.com/entry/2016/09/12/213643

bool check(int mask, int point){
    if((mask & (1 << point)) != 0) return true;
    else return false;
}

int main(){
    string s; cin >> s;
    int n = s.size() - 1;

    ll sum = 0;
    for(int mask = 0; mask < (1 << n); ++mask){
        int l = 0; // left
        int r; // right
        ll tmp = 0;
        for(r = 0; r < n; ++r){
            if(check(mask, r)){
                string t = s.substr(l, r - l + 1);
                ll num = stoll(t);
                tmp += num;
                l = r + 1;
            }
        }
        string t = s.substr(l, r - l + 1);
        ll num = stoll(t);
        tmp += num;
        sum += tmp;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n;
	cin>>n;
	long int i,x=0,a[n+1];
	for(i=1;i<n+1;i++)
	{
		cin>>a[i];
	}
	i=1;
	while(1)
	{
	
		if(i==2)
		{
			cout<<x<<endl;
			return 0;
		}
		if(x>n)
		{
			cout<<-1<<endl;
			return 0;
		}	
		x++;
		i=a[i];		
	}
}

Measured memory_bytes: 4324
import collections

ab = []
for i in range(3):
    a, b = [int(s) for s in input().split()]
    ab.append((a, b))

count = collections.Counter()
for a, b in ab:
    count[a] += 1
    count[b] += 1

cnt = 0
for key, value in count.items():
    if value >= 2:
       cnt += 1
if cnt >= 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3316
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
int x;
if(b < a){
x = a;
a = b;
b = x;
}
if(c < b){
x = b;
b = c;
c = x;
}
if(b < a){
x = a;
a = b;
b = x;
}
System.out.println(a +" "+ b +" "+ c);
}
}


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

// a=97
int main(void) {
  char s[100001];
  int x, i = 0;
  int bool[27] = {};  //配列の初期化
  scanf("%s", s);
  while (s[i] != '\0') {
    x = (int)s[i] - 97;
    bool[x] = 1;
    i++;
  }
  for (i = 0; i < 27; i++) {
    if (bool[i] == 0) {
      if (i < 26) {
        printf("%c\n", 'a' + i);
        break;
      } else {
        printf("None\n");
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
    int main(){
        int n,A[100];
        cin>>n;
        
        for(int i=0;i<n;i++)cin>>A[i];
        
        for(int j=n-1;j>=0;j--){
            if(j!=n-1)cout<<" ";
            cout<<A[j];
        }
        cout<<endl;
    return 0;
}


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

void hanafuda_set(vector<int>& ary,int& n);
void hanafuda_shuffle(vector<int>& ary,int& r);

int main()
{
	int n;	//山の枚数
	int r;	//カット操作の回数

	vector<int> ary;	//山札

	while(true)
	{
		cin>>n>>r;

		//終了
		if(n==0 && r==0)	break;

		//山札セット
		hanafuda_set(ary,n);

		//山札シャッフル
		hanafuda_shuffle(ary,r);

		//山の一番上の札を出力
		cout<<ary[0]<<endl;		

		//山札の初期化
		ary.clear();
	}
}

//山札セット関数
void hanafuda_set(vector<int>& ary,int& n)
{
	for(int i=n;i>>0;i--)
	{
		ary.push_back(i);
	}
}

//山札シャッフル関数
void hanafuda_shuffle(vector<int>& ary,int& r)
{
	int p;		//p番目の札から
	int c;		//c枚の札を抜き取る
	vector<int> tmp;	//退避配列

	for(int i=0;i<r;i++)
	{
		cin>>p>>c;
		
		//カット内容記録および消去
		for(int j=0;j<c;j++)
		{
			vector<int>::iterator it = ary.begin();
			tmp.push_back(ary[p-1]);
			ary.erase(it+(p-1));
		}
		//一番上に挿入
		for(int j=c;j>0;j--)
		{
			vector<int>::iterator it = ary.begin();
			ary.insert(it,tmp[j-1]);
		}
		//退避内容クリア
		tmp.clear();
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long in,n,k,ans=0;
    cin>>n>>k;
    vector<long long int>array;
    for(int i=0;i<n;i++){
        cin>>in;
        array.push_back(in);
    }
    sort(array.begin(), array.end(), greater <>());
    for(int i=k;i<n;i++){
        ans+=array[i];
    }
    cout<<ans<<endl;
    return 0;


}


Measured memory_bytes: 2420
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

long long solve0(long long l1, long long r1, long long l2, long long r2) {
	long long l = max(l1, l2);
	long long r = min(r1, r2);
	if (l <= r) {
		long long m = (l + r) / 2;
		return m * (l + r - m);
	}
	return l * r;
}

long long solve1(long long l1, long long m1, long long r1, long long l2, long long r2) {
	long long p = m1 - l1;
	long long q = r1 - m1;
	long long sp = p == 0 ? 0 : solve0(l1, l1 + p - 1, r2 - p + 1, r2);
	long long sq = q == 0 ? 0 : solve0(r1 - q + 1, r1, l2, l2 + q - 1);
	return max(sp, sq);
}

long long solve2(long long l1, long long m1, long long r1, long long l2, long long m2, long long r2) {
	if (l1 == m1)
		return solve1(l2, m2, r2, l1 + 1, r1);
	if (m1 == r1)
		return solve1(l2, m2, r2, l1, r1 - 1);
	if (l2 == m2)
		return solve1(l1, m1, r1, l2 + 1, r2);
	if (m2 == r2)
		return solve1(l1, m1, r1, l2, r2 - 1);
	long long p = min(m1 - l1, r2 - m2);
	long long q = min(r1 - m1, m2 - l2);
	long long sp = p == 0 ? 0 : solve0(l1, l1 + p - 1, r2 - p + 1, r2);
	long long sq = q == 0 ? 0 : solve0(r1 - q + 1, r1, l2, l2 + q - 1);
	long long so = solve2(l1 + p, m1, r1 - q, l2 + q, m2, r2 - p);
	return max(so, max(sp, sq));
}

long long solve(long long n, int a, int b) {
	if (n < a && n < b)
		return solve0(1, n, 1, n);
	if (n >= a && n >= b)
		return solve2(1, a, n + 1, 1, b, n + 1);
	return solve1(1, min(a, b), n + 1, 1, n);
}

int main() {
	int q; cin >> q;
	while (q--) {
		int a, b; cin >> a >> b;
		long long s = (long long) a * b;
		long long upper = 1;
		while (solve(upper, a, b) < s)
			upper *= 2;
		long long lower = upper / 2;
		while (upper - lower > 1) {
			long long n = (lower + upper) / 2;
			if (solve(n, a, b) < s)
				lower = n;
			else
				upper = n;
		}
		cout << lower << '\n';
	}
	return 0;
}


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

int main(){
  vector<int> vec(3);
  for(int i=0; i<3; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  cout << 10*vec.at(2) + vec.at(1) + vec.at(0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c;
	for(a=1;a<10;a++){
            for(b=1;b<10;b++){
	      c=a*b;
	      printf("%dx%d=%d\n",a,b,c);
        }
    }
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
  cin>>n;
  set<string> s;
  while(n--)
  {
     string str;
    cin>>str;
    s.insert(str);
  }
  cout<<s.size()<<endl;
}

Measured memory_bytes: 19108
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

class PrimeUtil {

	private static boolean[] sieve;

	static {
		int sieveSize = 10000007;
		sieve = new boolean[sieveSize + 1];
		Arrays.fill(sieve, 2, sieveSize + 1, true);

		for (int i = 2; i * i <= sieveSize; i += (i > 2) ? 2 : 1) {
			if (!sieve[i]) {
				continue;
			}

			for (int j = i * i; j <= sieveSize; j += i) {
				sieve[j] = false;
			}
		}
	}

	public static boolean isPrimeBySieve(int n) {
		return sieve[n];
	}

	public static boolean isPrime(long n) {
		if (n < 2L) {
			return false;
		} else if (n == 2L) {
			return true;
		}

		for (long i = 3L; i * i <= n; i += 2) {
			if (n % i == 0L) {
				return false;
			}
		}
		return true;
	}

	public static HashMap<Long, Long> factorize(long n) {
		HashMap<Long, Long> res = new HashMap<Long, Long>();
		for (long i = 2L; i * i <= n; i += (i > 2L) ? 2L : 1L) {
			if (!isPrimeBySieve((int) i)) {
				continue;
			}

			long cnt = 0;
			while (n % i == 0L) {
				n /= i;
				++cnt;
			}

			if (cnt > 0) {
				res.put(i, cnt);
			}
		}

		if (n > 1L) {
			res.put(n, 1L);
		}
		return res;
	}

}

public class Main {

	public static void main(String[] args) {
		long[] y = new long[50];
		for (int i = 1; i < 50; ++i) {
			y[i] = i + y[i - 1];
		}

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		HashMap<Long, Long> factorMap = PrimeUtil.factorize(n);

		long ans = 0;
		for (long base : factorMap.keySet()) {
			long index = factorMap.get(base);
			for (int i = 49; i >= 0; --i) {
				if (index < y[i]) {
					continue;
				}

				ans += i;
				break;
			}
		}

		System.out.println(ans);
	}

}


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

typedef long long int ll;
int main(){
    ll N;
    cin >> N;
    vector<string> S(N);
    vector<pair<string,int>> L;
    for(int i = 0;i < N;i++){
       cin >> S[i];
       sort(S[i].begin(),S[i].end());
    }
    sort(S.begin(),S.end());
    ll ans = 0;
    L.push_back(make_pair(S[0],0));
    int memo = 0;
    for(int i = 0;i < N;i++){
        if(S[i] == L[memo].first){
            ans += L[memo].second;
            L[memo].second++;
        }else{
            memo++;
            L.push_back(make_pair(S[i],1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9464
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007LL;
in p2(in a){
  return (1LL<<a);
}
in pw(in a, in b, in lm=62){
  a%=mdl;
  if(a<0)
    a+=mdl;
  in r=1;
  for(in i=lm;i>=0;--i){
    r=r*r%mdl;
    if(b&p2(i))
      r=r*a%mdl;
  }
  return r;
}
in inv(in a){
  a%=mdl;
  if(a<0)
    a+=mdl;
  assert(a!=0);
  return pw(a,mdl-2,30);
}
VI fc,invfc;
in ncr(in a, in b){
  if(b==0 || b==a)
    return 1;//even if a<0
  if(b<0 || b>a)
    return 0;
  return fc[a]*invfc[b]%mdl*invfc[a-b]%mdl;
}
void inifc(){
  const in mxfc=1001000;
  fc.resize(mxfc);
  invfc.resize(mxfc);
  fc[0]=fc[1]=invfc[0]=invfc[1]=1;
  for(in i=2;i<mxfc;++i){
    fc[i]=fc[i-1]*i%mdl;
    invfc[i]=invfc[mdl%i]*(mdl-mdl/i)%mdl;
  }
  for(in i=2;i<mxfc;++i){
    invfc[i]*=invfc[i-1];
    invfc[i]%=mdl;
  }
}

string s;
VI l,r;
VI wys[2];
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  inifc();
  in n,m;
  cin>>n>>m;
  cin>>s;
  in tl,tr;
  in prr=-3;
  forn(z,m){
    cin>>tl>>tr;
    --tl;
    --tr;
    if(tr<=prr)
      continue;
    prr=tr;
    l.PB(tl);
    r.PB(tr);
  }
  l.PB(n);
  r.PB(n-1);
  forn(z,2)
    wys[z].resize(n+3);
  in nw=0;
  in sw=1;
  wys[nw][0]=1;
  in cl=0;
  in cr=0;
  in nus;
  forv(z,l){
    swap(nw,sw);
    forn(i,n+1){
      wys[sw][i]%=mdl;
      wys[nw][i]=0;
    }
    if(cr<=l[z]){
      nus=0;
      for(in i=l[z];i<=r[z];++i){
	if(s[i]=='1')
	  ++nus;
      }
      forn(i,n+1){
	wys[nw][nus]+=wys[sw][i]*ncr(cr-cl,i);
	wys[nw][nus]%=mdl;
      }
      cl=l[z];
      cr=r[z]+1;
      continue;
    }
    in csz=cr-cl;
    if(cl<l[z]){
      forn(i,csz+1){
	if(i)
	  wys[nw][i-1]+=wys[sw][i];
	if(i!=csz)
	  wys[nw][i]+=wys[sw][i];
      }
      ++cl;
      --z;
      continue;
    }
    if(cr<=r[z]){
      forn(i,csz+1){
	wys[nw][i+(s[cr]=='1')]+=wys[sw][i];
      }
      ++cr;
      --z;
      continue;
    }
    forn(i,csz+1)
      wys[nw][i]=wys[sw][i];
  }
  in sm=wys[nw][0];
  sm%=mdl;
  if(sm<0)
    sm+=mdl;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 16000
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-8;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=10010;
ll a[N],b[N],n;
ll c;
signed main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=n;i++) read(b[i]);
	for(int i=1;i<=n;i++) {
		if(a[i]<b[i]) {
			c+=(b[i]-a[i])/2;
		} else {
			c-=a[i]-b[i];
		}
	}
	puts(c>=0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <float.h>
using namespace std;

int main()
{
	int a, b, k;

	cin >> a >> b >> k;

	for( int i = a; i <= b; i++ ) {
		if( i < a + k || b - k < i ) {
			cout << i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
N, M, C = map(int,input().split())
lst_b = list(map(int,input().split()))

count = 0

for i in range(N):
  sigma = 0
  total = 0
  lst_a = list(map(int, input().split()))
  for k in range(M):
    multi = lst_a[k] * lst_b[k]
    sigma += multi
    total = sigma + C
  if total > 0:
    count += 1
print(count)
 

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
	int w,n,i,l,a[30],b[30],ans[30],ans2[30];
	
	scanf("%d",&w);
	scanf("%d",&n);
	
	for(i=0;i<n;i++)scanf("%d,%d",&a[i],&b[i]);
	
	for(i=0;i<w;i++){
		ans[i]=i+1;
		for(l=0;l<w;l++){
			if(ans[i]==a[l]){
				ans[i]=b[l];
				continue;
			}
			if(ans[i]==b[l]){
				ans[i]=a[l];
				continue;
			}
		}
	}
	
	for(i=0;i<w;i++)ans2[ans[i]-1]=i+1;
	for(i=0;i<w;i++)printf("%d\n",ans2[i]);
	
	return 0;
}

Measured memory_bytes: 0