akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int dp[200100];
int main(){
  ios::sync_with_stdio(0);cin.tie(0);

  string s;cin>>s;
  int N=s.size();

  ll res = 0;
  bool cc=0;
  for (int i=N-1;i>=0;i--) {
    if (i<N-1 && s[i]=='B' && s[i+1]=='C') dp[i] = dp[i+2]+1;
    else if (s[i]=='A') dp[i] = dp[i+1], res += dp[i];
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1300
n, s = [input() for i in range(2)]
n = int(n)
words = [w for w in s]

cnt = 0
for i in range(n-2):
  if (words[i] == 'A' and words[i+1] == 'B' and words[i+2] == 'C'):
    cnt += 1

print(cnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, d, x;
  cin >> n >> d >> x;
  vector<vector<int>> p(d, vector<int>(n));
  for (int i = 0; i < d; i++){
    for (int j = 0; j < n; j++){
      cin >> p[i][j];
    }
  }
  for (int i = 0; i < d - 1; i++){
    vector<int> dp(x + 1, 0); 
    for (int j = 0; j <= x; j++){
      dp[x] = x;
    }
    for (int j = 0; j < n; j++){
      for (int k = p[i][j]; k <= x; k++){
        dp[k] = max(dp[k], dp[k - p[i][j]] + p[i + 1][j]);
      }
    }
    int tmp = 0;
    for (int j = 0; j <= x; j++){
      tmp = max(tmp, x - j + dp[j]);
    }
    x = tmp;
  }
  cout << x << endl;
}


Measured memory_bytes: 3192
//26
#include<iostream>

using namespace std;

long long gcd(long long a,long long b){
  return b?gcd(b,a%b):a;
}

int main(){
  for(int n;cin>>n,n;){
    int d[10],v[10];
    for(int i=0;i<n;i++){
      cin>>d[i]>>v[i];
    }
    int m[9];
    for(int i=0;i<n-1;i++){
      m[i]=d[i+1]*v[0]/gcd(d[0]*v[i+1],d[i+1]*v[0]);
    }
    long long f=1;
    for(int i=0;i<n-1;i++){
      f=f*m[i]/gcd(f,m[i]);
    }
    cout<<f<<endl;
    for(int i=1;i<n;i++){
      cout<<f*d[0]*v[i]/v[0]/d[i]<<endl;
    }
  }
  return 0;
}
	  

Measured memory_bytes: 1156
while 1:
    try:
        s=input()
        s_r=""
        c1=[" ","'",",","-",".","?","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
        c2=["101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"]
        c3=[" ",".",",","-","'","?"]
        for i in s:
            s_r+=c2[c1.index(i)]
        while len(s_r)%5>0:s_r+="0"
        ans=""
        for i in range(len(s_r)//5):
            s_r_n=int(s_r[:5],2)
            if s_r_n<26:
                ans+=chr(65+s_r_n)
            else:
                ans+=c3[s_r_n-26]
            s_r=s_r[5:]
        print(ans)
    except:break


Measured memory_bytes: 5584
import math

a, b, C = map(int, raw_input().split())

S = a * b * math.sin(math.radians(C)) / 2
L = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))) + a + b
h = 2*S/a

print S
print L
print h

Measured memory_bytes: 6720
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>>A(N);

	for (int i = 0; i < N; i++)
	{
		int a, b;
		cin >> a >> b;
		A[i] = make_pair(a, b);
	}
	int ans = 1e9;

	for (int i = 0; i < N; i++)
	{
		if (A[i].second <= T) {
				ans = min(ans, A[i].first);
		}
	}
	if (ans == 1e9){
		cout << "TLE" << endl;
		return 0;
    }
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(ll i = a; i < (ll)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
const int num = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    ll ans = 1;
    FOR(i, 1, n + 1) {
      ans = (ans * i) % num;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> cnt(26, INF);
    rep(i, n)
    {
        string s;
        cin >> s;
        vector<int> tmp(26, 0);
        rep(i, s.size()) tmp[s[i] - 'a']++;
        rep(i, 26) cnt[i] = min(cnt[i], tmp[i]);
    }
    rep(i, 26) rep(j, cnt[i]) cout << (char)('a' + i);
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a <= c && c <= b || b<= c&& c <= a) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
int MOD = 998244353;

vector<ll> divisor(ll n){
    vector<ll> v1;
    for(ll i=1; i <= sqrt(n); i++){
        if( n%i == 0 ){
            v1.push_back(i);
            if( i*i != n ) v1.push_back(n/i);
        }
    }
    return v1;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n;
	cin >> n;
	int ans = 0;
	set<ll> s1;
	for(auto c: divisor(n-1) ){
        if( c != 1 ) s1.insert(c);
	}
	//ans += divisor(n-1).size() - 1;
	for(auto c: divisor(n)){
        if( c == 1 ) continue;
        ll tmp = n;
        while( tmp %c == 0 ) tmp /= c;
        if( tmp % c == 1 ) { s1.insert(c);
            ++ans;
        }
	}
	cout << s1.size() << endl;
	//cout << ans << endl;




}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdio>
#include<stdio.h>
#include<string.h>

int main(void){
    int n, i;
    char str[250];
    scanf("%s", str);

    n = strlen(str);
    for (i = n - 2; i;i -=2){

        if( strncmp(str,str+i/2,i/2)==0){
            printf("%d\n", i);
            return 0;
        }
    }
        return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      String S = sc.next();
      int min =753;
      for (int i=0; i<S.length()-2; i++) {
        String SS = S.substring(i,i+3);
        int num = Integer.parseInt(SS);
        min = Math.min(Math.abs(753 - num),min);
      }
      System.out.println(min);
    }
}

Measured memory_bytes: 22612
/**
    And in the end, the love you take is equal to the love you make.

        I LOVE YOU LAURA.
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_DISABLE_PERFCRIT_LOCKS

#define findOrder find_by_order
#define orderKey order_of_key

#define isOn(mask, i) (mask & (1 << i))
#define turn(mask, i) (mask |= (1 << i))
#define switch(mask, i) (mask &= ~(1 << i))
#define change(mask, i) (mask ^= (1 << i))
#define lowbit(mask) (mask & (-mask))
#define turnAll(mask, n) (mask = (1 << n) - 1)
#define switchLastBit(mask) (mask & (mask - 1))
#define turnLastZero(mask) (mask | (mask + 1))
#define modulo(x, mod) ((x) & (mod - 1))
#define log2(x) (31 - __builtin_clz(x))

#define mkp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define ins insert
#define rsz resize
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define debug(x) (cerr << x << " ")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdb;
typedef pair<int, ii> tri;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vdb;
typedef vector<cd> vcd;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vll> matrix;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_tree;

const ll mod = 1e9+7;
const int maxn = 105;
const int pi = 2 * acos(0.0);
const db eps = 1e-9;

ll w[maxn], v[maxn];
ll dp[(int)1e5+2];

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

    int n, W; cin >> n >> W;

    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= 2; j++){
            if (j == 1){
                cin >> w[i];
            }
            else if (j == 2){
                cin >> v[i];
            }
        }
    }

    dp[0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = W; j >= w[i]; j--){
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    ll ans = 0;
    for (int i = W; i >= 0; i--){
        ans = max(ans, dp[i]);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)
ll dp[100010] = { -1 };
ll num[4] = { 0 };

int main(void) {
	ll n;
	cin >> n;
	vector<ll>a(n+1);
	for (ll i = 1;i <= n;i++) {
		cin >> a[i];
		num[a[i] % 4]++;
	}
	if (num[1] == 0 && num[3] == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		if (num[1] > 0)dp[1] = 1, num[1]--;
		else {
			if (num[3] > 0)dp[1] = 3, num[3]--;
		}
	}
	for (ll i = 2;i <= n;i++) {
		if (dp[i-1] == 1 || dp[i-1] == 3) {
			if (num[0] > 0) {
				num[0]--;
				dp[i] = 0;
			}
			else {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (dp[i-1] == 2) {
				if (num[2] > 0) {
					dp[i] = 2;
					num[2]--;
				}
				else {
					if (num[0] > 0) {
						dp[i] = 0;
						num[0]--;
					}
					else {
						cout << "No" << endl;
						return 0;
					}
				}
			}
			else {
				if (num[1] > 0) {
					dp[i] = 1;
					num[1]--;
				}
				else {
					if (num[3] > 0) {
						dp[i] = 3;
						num[3]--;
					}
					else {
						if (num[2] > 0) {
							dp[i] = 2;
							num[2]--;
						}
						else {
							dp[i] = 0;
							num[0]--;
						}
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1792
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

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

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------


int main(void){
	vector<int> a(3);
	for(int i = 0; i < 3; i++){
		cin >> a[i];
	}
	int k;
	cin >> k;

	sort(a.begin(), a.end(), greater<int>());

	for(int i = 0; i < k; i++){
		a[0] *= 2;
	}

	int ans = 0;
	for(int i = 0; i < 3; i++){
		ans += a[i];
	}

	cout << ans << endl;


}



Measured memory_bytes: 256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    if (A==B) cout << C << endl;
    if (B==C) cout << A << endl;
    if (A==C) cout << B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, z, mult, cont = 0;
    scanf("%d %d %d", &a, &z, &mult);
    
    for (int i = a; i < z+1; ++i){
        if (i%mult == 0)
            cont += 1;
    }
    
    printf("%d\n", cont);

    return 0;
}



Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, b[100005] = {};
    vector<int> c = {};
    ll z = 0, y = 0, w = 0;
    multiset<int, greater<int>> t = {0};
    pii a[100005] = {};
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i].second >> a[i].first;
    sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        if (!b[a[i].second] && c.size() < k) c.push_back(a[i].first), y += a[i].first;
        else t.insert(a[i].first);
        b[a[i].second] = 1;
    }
    sort(c.begin(), c.end()); reverse(c.begin(), c.end());
    int m = (int)c.size();
    while (m < k) y += *t.begin(), t.erase(t.begin()), m++;
    z = y + 1ll * c.size() * c.size();
    for (int i = (int)c.size() - 1; i >= 0 && !t.empty(); i--) {
        y -= c[i];
        y += *t.begin();
        t.erase(t.begin());
        z = max(z, y + 1ll * i * i);
    }
    cout << z;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long n,k,ans=0;
    cin >> n>> k;
    if(k==0) ans=n*n;
    else
    {
        for(int b=k+1;b<=n;b++)
        {
        ans+=(n/b)*(b-k);
        if(n%b>=k) ans+=n%b-k+1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <cstdint>
#include <cstring>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main()
{
	int N;
	cin >> N;
	
	int p[255];
	int c[255];

	for (int i =0; i<N; i++){
			cin >> p[i];
	}

	memcpy(c, p, 255);
	sort(p, p + N);

	int counter = 0;

	for (int i = 0; i < N; i++){
		//cout << c[i] << "," << p[i] << endl;
		if (c[i] != p[i]){
			++counter;
		}
	}

	if (counter <= 2){
				cout << "YES" << endl;
				
	}
	else{
		cout << "NO" << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int main()
{
	scanf("%d%d",&m,&k);
	if(k>=(1<<m)){puts("-1");return 0;}
	n=(1<<m+1);
	if(m==1&&k==1){puts("-1");return 0;}
	if(!k)
	{
		for(int i=1;i<=n;i++)printf("%d ",(i-1)/2);
		return 0;
	}
	printf("0 %d 0",k);
	for(int i=1;i<(1<<m);i++)if(i!=k)printf(" %d",i);
	printf(" %d",k);
	for(int i=(1<<m)-1;i;i--)if(i!=k)printf(" %d",i);
}

Measured memory_bytes: 1792
N=int(input())
S=str(input())
M=len(S)
T=''
Al='ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(M):
  for j in range(26):
    if S[i]==Al[j]:
      T +=str(Al[j+N])
      break
print(T)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvl vector<vector<ll>> 
#define vl vector<ll> 
#define vpll vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(ll i = 0; i < n; ++i)
#define PI 3.14159265 
ll mod=1e9+7;

 int main(){
     fastt;
     ll i,j,k;
   ll n,m;
   cin>>n>>m;
   ll sum=0;
   for(i=0;i<m;i++){
       cin>>j;
        sum+=j;
   }
    if(n>=sum)cout<<n-sum<<enl;
    else{
        cout<<-1<<enl;
    }
 }


Measured memory_bytes: 3616
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
same = 0
diff = 0
 
for i in range(N):
  for j in range(N):
    if A_list[i] > A_list[j]:
      if i < j:
        same += 1
        diff += 1
      elif i>j:
        diff += 1
 
ans = (same*K) + (diff*((K * (K-1))//2))
print(ans%(10**9 + 7))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.max(0, a-2*b));
	}

}


Measured memory_bytes: 21716
#include<stdio.h>
int main(void)
{
  char a[3];
  int cnt=0;
  scanf("%s",a);
  if(a[0]=='1') cnt++;
  if(a[1]=='1') cnt++;
  if(a[2]=='1') cnt++;
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
int a[1000];
int n;

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

int j;
for(j=n-1;j > -1; j=j-1)
{cout<<a[j];
if(j>0){cout<<" ";}
if(j==0){cout<<endl;}
}
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    vector<P> d(n);
    rep(i,n){
        int p; cin >> p;
        d.emplace_back(p,i+1);
    }
    sort(all(d));
    reverse(all(d));
    
    multiset<int> left,right;
    ll ans=0;

    left.insert(0);
    left.insert(0);
    left.insert(-d[0].second);
    right.insert(d[0].second);
    right.insert(n+1);
    right.insert(n+1);

    for(int i=1; i<n; i++){
        ll now=d[i].first;
        int id=d[i].second;
        int l1=*left.lower_bound(-id);
        left.erase(left.find(l1));
        int l2=*left.lower_bound(-id);
        left.insert(l1);
        int r1=*right.lower_bound(id);
        right.erase(right.find(r1));
        int r2=*right.lower_bound(id);
        right.insert(r1);
        //cout << l1 << l2 << r1 << r2 << endl;
        l1*=-1;
        l2*=-1;
        ans+=now*((ll)(id-l1)*(r2-r1)+(ll)(r1-id)*(l1-l2));
        left.insert(-id);
        right.insert(id);
    }

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

Measured memory_bytes: 15680
#include <stdio.h>
#include <string.h>

int main(void) {
	char buff[10000];
	int i, l;
	gets(buff);
	l = strlen(buff);
	
	for(i=0;i<l;i++) {
		if('a'<=buff[i] && buff[i]<='z') {
			putchar(buff[i] + 'A' - 'a');
		} else {
			putchar(buff[i]);
		}
	}
	putchar('\n');
	
	return 0;
}

Measured memory_bytes: 524
N,M=map(int,input().split())
d={} #正解の辞書
e={} #誤答の辞書
f={} #ペナの辞書
for _ in range(M):
    p,s=input().split()
    d.setdefault(p,0)
    e.setdefault(p,0)
    f.setdefault(p,0)
    if s=="WA" and d[p]==0:
        e[p]+=1
    elif s=="AC":
        d[p]=1
        f[p]=e[p]

print(sum(d.values()),sum(f.values()))



Measured memory_bytes: 29428
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int n,m;
	cin>>n>>m;

	vector<int> arr(n);
	repf(i,0,m){
		cin>>arr[i];
	}

	int sum=accumulate(arr.begin(),arr.end(),0);
	if(sum>n){
		cout<<-1<<endl;
	}
	else{
		int ans=n-sum;
		cout<<ans<<endl;
	}
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	if(fopen("input.txt", "r")){
	    freopen("input.txt", "r", stdin),
	    freopen("output.txt", "w", stdout);
	}
	
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n); std::vector<int> c(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		
		c[i]--;
	}

	const int M = 2e5 + 10;
	std::vector<int> latte(M, -1);
	std::vector<int> vec(n, -1);
	for(int i = 0; i < n; i++) {
		if(latte[c[i]] != -1 and latte[c[i]] + 1 != i) {
			vec[latte[c[i]]] = i;
		}
		
		latte[c[i]] = i;
	}
	
	const int MOD = 1e9 + 7;
	std::vector<int> dp(n + 1, 0); dp[0] = 1;
	for(int i = 0; i < n; i++) {
		(dp[i + 1] += dp[i]) %= MOD;
		
		if(vec[i] != -1) (dp[vec[i]] += dp[i]) %= MOD;
	}
	printf("%d\n", dp[n]);
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<algorithm>
#define Max 1000
using namespace std;

int main(){
	int n,a[Max],i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	double sum = 0;
	for(i=0;i<n;i++){
		if(i==0)
			sum = a[i];
		else
			sum = (sum + a[i])/2;
	}

	printf("%lf\n",sum);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> n;
    int in;
    for (int i = 0; i < 3; i++)
    {
        cin >> in;
        n.emplace_back(in);
    }

    vector<int>::iterator maxitr = max_element(n.begin(), n.end());
    int max = *maxitr;

    for (vector<int>::iterator itr = n.begin(); itr != n.end(); itr++)
    {
        *itr -= max;
    }
    
    sort(n.begin(), n.end());

    int ans = 0;
    int d = (abs(n[0]) - abs(n[1]));
    ans += abs(n[1]);
    ans += d / 2;
    if (d % 2 != 0) ans += 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A =list(map(int, input().split()))
minus = [i for i in A if i < 0]
if len(minus) % 2 == 0:
  max_num = [abs(i) for i in A]
  print(sum(max_num))
else:
  max_num = [abs(i) for i in A]
  if min(max_num) in A:
    print(sum(max_num) - 2*min(max_num))
  else:
    print(sum(max_num) + -(2*min(max_num)))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const double pi = acos(-1);
int main()
{
    Hello
    int r;
    cin >> r;
    double area = pi * r * r;
    cout << fixed << setprecision(0) << (area/pi);
    return 0;
}

Measured memory_bytes: 3784
H, N = map(int, input().split())
A = sorted([int(x) for x in input().split()])
#print(A)
ATK=0

for i in range(N):
	ATK+=A[(N-1)-i]
	#print(i,ATK)

if ATK>=H:
	print("Yes")
else:
	print("No")

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef pair<string,int> psi;

bool cmp(psi x, psi y){
	return x.second > y.second;
}

void Main()
{
    int n;
    cin >> n;
  	vector<string> s(n);
  	rep(i,n) cin >> s[i];
    
  	sort(all(s));
  	vector<psi>data;
  	int count = 1;
  
    rep(i,n-1){
      	if(s[i] == s[i+1]) {
          	count++;
        }
		else{
        	data.emplace_back(s[i], count);
          	count = 1;
        }
    }
	if(s[0] != s[n-1]) data.emplace_back(s[n-1],count);
  	else{
    	cout << s[0] << endl;
      	return;
    }
  	stable_sort(all(data), cmp);
  
  	/*
  	rep(i,data.size()){
    	cout << data[i].first << ": " << data[i].second << endl;
    }
    //*/
	int temp = data.size();
	rep(i,data.size()-1){
    	if(data[i].second != data[i+1].second) {
          	temp = i+1; 
      		break;
        }
    }
  	rep(i,temp) cout << data[i].first << endl;
	return;
}

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

Measured memory_bytes: 17772
//---------- Begin IO utilities ----------
#[macro_use]
#[allow(dead_code, unused_macros)]
mod io {
    // Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
    macro_rules! input {
        ($($r:tt)*) => {
            let s = {
                use std::io::Read;
                let mut s = String::new();
                std::io::stdin().read_to_string(&mut s).unwrap();
                s
            };
            let mut iter = s.split_whitespace();
            input_inner!{iter, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($iter:expr) => {};
        ($iter:expr, ) => {};
        ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
            let $var = read_value!($iter, $t);
            input_inner!{$iter $($r)*}
        };
    }
    macro_rules! read_value {
        ($iter:expr, ( $($t:tt),* )) => {
            ( $(read_value!($iter, $t)),* )
        };
        ($iter:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        };
        ($iter:expr, chars) => {
            read_value!($iter, String).chars().collect::<Vec<char>>()
        };
        ($iter:expr, usize1) => {
            read_value!($iter, usize) - 1
        };
        ($iter:expr, $t:ty) => {
            $iter.next().unwrap().parse::<$t>().expect("Parse error")
        };
    }

    macro_rules! p {
        ($v:expr) => {
            println!("{}", $v);
        };
        ($v:expr, $($t:expr),*) => {
            print!("{}", $v);
            ($(print!(" {}", $t)),*);
            println!();
        }
    }

    macro_rules! ps {
        ($v:expr) => {
            println!("{}", $v.iter().collect::<String>());
        };
        ($v:expr, $($t:expr),*) => {
            print!("{}", $v.iter().collect::<String>());
            ($(print!(" {}", $t.iter().collect::<String>())),*);
            println!();
        }
    }

    pub fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
        let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
        println!("{}", s);
    }

    pub fn pvs(v: &[Vec<char>], sep:&str) {
        let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
        println!("{}", s);
    }
}
//---------- End IO utilities ----------

//---------- Start solve ----------
#[allow(unused_imports)]
use io::*;
fn main() {
    input!{
        x: f64
    }
    let mut s = 100.0;
    for i in 0..99999999 {
        if s >= x {
            p!(i);
            return;
        }
        s = ((s * 1.01) as usize) as f64;
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back 
#define mp make_pair
typedef long long ll;

ll modulo=1000000007;

vector<ll> primes;
vector<bool> isp;

ll mul(ll a,ll b, ll c){
	ll ans=0;
	while(b>0){
		if(b&1) ans=(ans+a)%c;
		a=(a+a)%c;
		b>>=1;
	}
	return ans;
}

ll ex2(ll a,ll b,ll c){
	ll ans=1;
	while(b>0){
		if(b&1) ans=mul(ans,a,c);
		a=mul(a,a,c);
		b>>=1;
	}
	return ans;
}

void generate(){
	primes.resize(1e6+10,0);
	isp.resize(1e6+10,1);
	primes[1]=1;
	for(int i=2;i<=1e6;i++){
		if(!isp[i]) continue;
		primes[i]=i;
		for(int j=2;i*j<=1e6;j++){
			isp[i*j]=false;
			if(primes[i*j]==0) primes[i*j]=i;
		}
	}
}



int main(){
	int n; cin>>n;
	generate();
	ll A[n+5]; 
	for(int i=0;i<n;i++) cin>>A[i];
	map<ll,ll> lcm;
	
	for(int i=0;i<n;i++){
		map<ll,ll> div;
		int temp=A[i];
		while(temp!=1){
			ll factor=primes[temp];
			div[factor]++;
			temp/=factor;
		}
		for(auto j:div) lcm[j.first]=max(lcm[j.first],j.second);
	}
	
	ll LCM=1;
	
	for(auto i: lcm)
		LCM=mul(LCM,ex2(i.first,i.second,modulo),modulo);
	
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=mul(LCM,ex2(A[i],modulo-2,modulo),modulo);
		ans%=modulo;
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 8832
N,M = map(int,input().split())
K = []
ans = 0
for n in range(N):
    K.append(list(map(int,input().split())))

for m in range(1,M+1):
    for k in K:
        if not m in k[1:]:
            break
    else :
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
#ifdef _WIN32
#include <windows.h>
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, string NAME)
{
#ifndef ONLINE_JUDGE /// ONLINE_JUDGE IS DEFINED ON CODEFORCES
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, 10);
    cerr << NAME << " = " << VARIABLE;
    SetConsoleTextAttribute(hConsole, 7);
    cerr << '\n';
#endif
}
#else
#define print(x) 0
#endif
struct pair_hash
{
    template<typename T1, typename T2>
    size_t operator () (const pair<T1, T2> &p) const
    {
        auto h1 = hash<T1> {}(p.first);
        auto h2 = hash<T2> {}(p.second);
        return h1 ^ h2;
    }
};
typedef long long ll;
typedef unsigned long long ull;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
//ifstream fin(".in");
//ofstream fout(".out");
void die()
{
    cout << "-1\n";
    exit(0);
}
const int NMAX = 1e6 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

int n, m, k;

int main()
{
    FASTIO;
    cin >> n >> m >> k;
    for0(i, n + 1) for0(j, m + 1)
    {
        if(m * i + (n - i) * j - i * j == k) return cout << "Yes",0;
    }
    cout << "No";

    return 0;
}


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

const int mod = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


long long ten(long long n){
    long long ans = 1;
    for(int i = 0;i < n;i++){
        ans =  (ans*10)%mod;
        ans %= mod;
    }

    return ans;
}

long long nine(long long n){
    long long ans = 1;
    for(int i = 0;i < n;i++){
        ans = (ans*9)%mod;
        ans %= mod;
    }

    return ans;
}

long long eight(long long n){
    long long ans = 1;
    for(int i = 0;i < n;i++){
        ans = (ans*8)%mod;
        ans %= mod;
    }

    return ans;
}

int main(){
    long long n;
    cin >> n;
    //long long ans = ten(n) - 2*nine(n) + eight(n);

    long long x = modpow(10, n, 1000000007);
    long long y = modpow(9, n, 1000000007);
    long long z =  modpow(8, n, 1000000007);

    long long ans = (x  + z)%mod - (y*2)%mod;

    if(ans < 0) ans += mod;

    cout << ans << endl;

    //cout << modpow(10, n, 1000000007) - 2*modpow(9, n, 1000000007) + modpow(8, n, 1000000007) << endl;

    //cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;


public class Main {

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

		int N = 0;
		while ((N = sc.nextInt()) != 0) {
			int A = 0, B = 0;
			for (int i = 0 ; i < N ; i++) {
				int a = sc.nextInt(), b = sc.nextInt();
				if (a == b) {
					A += a; B += b;
				} else if (a < b) {
					B += a+b;
				} else {
					A += a+b;
				}
			}
			System.out.println(A+" "+B);
		}
	}
}

Measured memory_bytes: 51652
using System;
using System.Linq;

namespace ALDS1_1A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var A = sr.Next<int>(N);

            for(var i = 0; i < N; i++){
                var v = A[i];
                var j = i - 1;
                for(; j >= 0 && v < A[j]; j--){
                    A[j + 1] = A[j];
                }
                A[j + 1] = v;
                Console.WriteLine(string.Join(" ", A.Select(x => x.ToString()).ToArray()));
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 10456
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = 1000000007;
ll CaseN=1;
const ld PI = 22/7.0;

bool mycmp(string s,string t)
{
if(s.size()<t.size())
{
return true;	
}		
return false;
}


void solve()
{
	ll n,k,x,y,ans=0;
	cin>>n>>k>>x>>y;
	
	ans += (min(n,k)*x);
	n -= k;
	if(n>0)
	{
	ans+=(n*y);
		
	}
	
	cout<<ans<<endl;
 // cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
    
return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 256
c=[0,2,5,5,4,5,6,3,7,6]
N,M=gets.split.map &:to_i
a=gets.split.map &:to_i
d=Array.new(N+1,p)
d[0]=0
0.upto(N){|i|
    q=[]
    M.times{|m|c[a[m]]<=i&&d[i-c[a[m]]]&&q<< d[i-c[a[m]]]*10+a[m]}
    q.size>0&&d[i]=q.max
}
p d[N]

Measured memory_bytes: 36732
import math
from itertools import accumulate
N = int(input())
X = []
Y = []
for _ in range(N):
  x, y = map(int, input().split())
  X.append(x)
  Y.append(y)

# x軸との反時計回りになす角の順にソート
arr = []
for x, y in zip(X, Y):
  arr.append((math.atan2(y, x), x, y))
arr.sort()
accX = list(accumulate([a[1] for a in arr]))
accY = list(accumulate([a[2] for a in arr]))

ans = float('-inf')
for f in range(N):
  for t in range(N):
    if f <= t:
      tmpX = accX[t] - (accX[f-1] if f > 0 else 0)
      tmpY = accY[t] - (accY[f-1] if f > 0 else 0)
      tmp = tmpX**2 + tmpY**2
      ans = ans if ans > tmp else tmp
    else:
      tmpX = accX[N-1] - (accX[f-1] if f > 0 else 0) + accX[t]
      tmpY = accY[N-1] - (accY[f-1] if f > 0 else 0) + accY[t]
      tmp = tmpX**2 + tmpY**2
      ans = ans if ans > tmp else tmp
print(math.sqrt(ans))

Measured memory_bytes: 3188
N = int(input())
count, bre = 0, 0
for i in range(N):
  a, b = map(int, input().split())
  if a==b:
    count += 1
  else:
    count = 0
  if count==3:
    print('Yes')
    bre = 1
    break
if bre==0:
  print('No')


Measured memory_bytes: 9168
var ab=[];
for(var i=0;i<=2000;i++)ab[i]=0;
for(var i=0;i<=1000;i++){
   for(var j=0;j<=1000;j++){
      ab[i+j]++;
   }
}
var arr=[];
for(var i=0;i<=4000;i++)arr[i]=0;
for(var i=0;i<ab.length;i++){
   for(var j=0;j<ab.length;j++){
      arr[i+j]+=ab[i]*ab[j];
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(Arr.length!=0){
   console.log(arr[Arr.shift()-0]);
}

Measured memory_bytes: 8712
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
      int A,B;
      cin >> A >> B;
      int zero = false;
      if(A - B <= 0)zero = true;
      if(zero)cout << "0" << endl;
      else cout << A - B << endl;
        return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());

	double ans_d = 0.0;
	double ans_i = 0;

	for (int i = 0; i < n; i++)
	{
	    var t = ReadLine().Split();
	    string s = t[0];
	    string u = t[1];

	    if (u == "JPY")
	    {
		ans_i += int.Parse(s);
	    }
	    else
	    {
		ans_d += double.Parse(s);
	    }
	}


	WriteLine((double) ans_i + 380000.0 * ans_d);
    }
}


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

const double pi = 3.1415926535898;

int main () {
	double a, b, c, d; cin >> a >> b >> c >> d;
	c += d / 60;
	double t1 = 2 * pi / 12 * c, t2 = 2 * pi / 60 * d;
	double the = abs(t1 - t2); the = min(the, 2 * pi - the);
	printf("%.12f\n", sqrt(a * a + b * b - 2 * a * b * cos(the)));
	return 0;
}


Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    long long int k;
    cin >> S >> k;
    for(long long int i=0;i<S.length();i++){
        if(S[i]!='1'){
            cout << S[i] << endl;
            return 0;
        }
        else if(S[i]=='1' && i==k-1){
            cout << '1' << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
function Main(arg) {
    var arg = arg.trim().split(' ');
    let x = Number(arg[0]);
    let y = Number(arg[1]);
    
    if(y%2 != 0 || x > y){
      console.log("No");
      return;
    } else if (x*2 <= y && x*4 >= y){
      let a = (4*x - y)/2;
      let b = x - a;
      if (a + b == x ){
        console.log("Yes");
        return;
      }
    }
    console.log("No");
    return;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
#line 1 "../lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

void dfs(int cur, int par, const vector<vi> &g, vi &tmp, vi &ans) {
  if (par != -1)
    ans[cur] = ans[par] + tmp[cur];
  for (const auto v : g[cur]) {
    if (v == par)
      continue;
    dfs(v, cur, g, tmp, ans);
  }
}

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

  int n, q;
  cin >> n >> q;
  vector<vector<int>> g(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vi tmp(n, 0);
  REP(i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    tmp[p] += x;
  }

  vi ans(n, 0);
  ans[0] = tmp[0];
  dfs(0, -1, g, tmp, ans);

  REP(i, n) { cout << ans[i] << (i == n - 1 ? "\n" : " "); }

  return 0;
}


Measured memory_bytes: 30592
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 17:07:34 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))
  l_s = []
  for i in range(M):
    l_s.append(list(map(int, input().split()))[1:])
  P = list(map(int, input().split()))

  ans = 0
  for bit in range(1 << N):
    # loop for light
    for lidx, ss in enumerate(l_s):

      num_on_s = 0
      for s in ss:
        mask = (1 << (s-1))
        if bit & mask:
          num_on_s += 1
      if num_on_s % 2 == P[lidx]:
        continue
      break
    else:
      ans += 1
  print(ans)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 70756
#ABC131 C
import fractions

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = int(X // C)
    XmodD = int(X // D)
    CD_lcm = int(C * D / fractions.gcd(C, D))
    XmodCD = int(X // CD_lcm)
    return X - (XmodC + XmodD - XmodCD)
ans = ad(B) - ad(A - 1)
print(ans)

Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 15;
const int mod = 1000000007;

int p[maxn];

int solve(vector<int>& a){
  int n = a.size();
  int ret = 0;
  for(int i=0;i+1<n;i++){
    vector<int>b;
    for(int j=i;j<n;j++)b.push_back(a[j]);
    sort(b.begin(),b.end());
    int pos = 0;
    for(int j=0;j<b.size();j++){
      if(a[i]==b[j]){
        pos = j;
        break;
      }
    }
    ret += pos * p[n-i-1];
  }
  //bug(ret)
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  p[1] = 1;
  for(int i=2;i<maxn;i++)p[i] = p[i-1] * i;
  int n;
  cin>>n;
  vector<int>a,b;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    a.push_back(x);
  }
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    b.push_back(x);
  }
  cout<<abs(solve(a) - solve(b))<<endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

n, q = map(int, input().split())
edges = list(tuple(map(int, input().split())) for _ in range(n-1))
adj = [[] for _ in range(n+1)]
cnt = [0] * n
for u, v in edges:
    adj[u].append(v)
    adj[v].append(u)

def dfs(p, u):
    vis = [0] * n
    stk = [(p, u)]
    while stk:
        p, u = stk[-1]
        stk.pop()
        if vis[u-1]:
            continue
        for v in adj[u]:
            if v != p:
                cnt[v-1] += cnt[u-1]
                stk.append((u, v))

quries = list(tuple(map(int, input().split())) for _ in range(q))
for u, p in quries:
    cnt[u-1] += p
dfs(-1, 1)
print(*cnt)

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

int main() 
{
	int H,W;
	
	while(1){
		
		cin>>H>>W;
		if(H==0 && W ==0) break;
		for(int i = 0; i<H;i++){
			
			for( int j =0;j<W;j++){
				if(i%2==1 && j%2==1){
					cout <<"#";
					}
				if(i%2==1 && j%2==0){
					cout << ".";
					}
				if(i%2==0 & j%2==1){
					cout << ".";
					}
				if(i%2==0 && j%2==0){
					cout << "#";
					}
					}
				cout << "\n";
				}
				cout << endl;
				}
				}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, P, A[51];
LL cou[2];

int main()
{
	in >> N >> P;
	rep(i, N) { in >> A[i]; }

	rep(i, N) { ++cou[A[i] % 2]; }
	
	if (cou[1]) { out << (1LL << (N - 1)) << std::endl; }
	else { out << (P ? 0 : (1LL << N)) << std::endl; }
	return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <iostream>
#include <cstdio>
#include <stack>

#define N_max 2000000

using namespace std;


int main() {
    int n;
    int colum[N_max];
    int countOne = 0;
    for (int i=0; i<N_max; i++) {
        colum[i] = 0;
    }
    stack<int> s;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        int num;
        scanf("%d", &num);
        s.push(num);
    }
    while (s.empty() == false) {
        int countNum = 0;
        int mag = s.size() - 1;
        for (int i = mag; i < n; i += (mag+1)) {
            countNum += colum[i];
        }
        countNum %= 2;
        if (countNum == s.top())
            colum[mag] = 0;
        else {
            colum[mag] = 1;
            countOne++;
        }
        s.pop();
    }

    cout << countOne << endl;
    for (int i=0; i<n; i++) {
        if (colum[i] == 1)
            cout << i+1 << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int d, l;

int main() {
	cin >> d >> l;
	cout << d / l + d % l << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
int main(void){   
   int a,b;
   scanf("%d",&a);
   scanf("%d",&b);
   if (a>b) {
    puts("a > b");
} else if ( a<b ) {
    puts("a < b");
} else if ( a==b ) {
    puts("a == b");
}
       
   
   
   return 0;
}


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

string a[100],b[100],c[100],d[100];

int calc(string s){
	return ((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+s[4]-'0';
}

int main(){
	int N,T;
	cin >> N >> T;
	int cnt = 0;
	for(int i = 0 ; i < N ; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		if(i){
			if( calc(a[i])-calc(c[i-1]) >= T ){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	for(int i = 0 ; i < N ; i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		if(i){
			if( calc(a[i])-calc(c[i-1]) >= T ){
				cout << b[i] << " " << calc(a[i])-calc(c[i-1]) << endl;
			}
		}
	}
}
	

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

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> table(26, vector<int>(n, 0));
    for (int i = 0; i < n; i++)
    {
        string S;
        cin >> S;
        for (int j = 0; j < S.size(); j++)
            table[S[j] - 'a'][i]++;
    }
    string ans = "";
    for (int i = 0; i < 26; i++)
    {
        int maxn = *min_element(table[i].begin(), table[i].end());
        for (int j = 0; j < maxn; j++)
            ans += char(i + 'a');
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256