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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

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

const int N = 1e6 + 5;

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

ll X[N], Y[N]; 
int F[2];

bool isValid(ll x, ll y, int p) {
	return abs(x) + abs(y) < (1LL<<p);
}

string solve_for(ll x, ll y, int p) {
	if(p < 0) return "";
	if(isValid(x - (1LL<<p), y, p)) return solve_for(x - (1LL<<p), y, p-1) + 'R';
	if(isValid(x + (1LL<<p), y, p)) return solve_for(x + (1LL<<p), y, p-1) + 'L';
	if(isValid(x, y - (1LL<<p), p)) return solve_for(x, y - (1LL<<p), p-1) + 'U';
	if(isValid(x, y + (1LL<<p), p)) return solve_for(x, y + (1LL<<p), p-1) + 'D';
	return "";
}

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>X[i]>>Y[i];
		F[(X[i]+Y[i]) % 2]++;
	}
	if(F[0] and F[1]) {
		cout<<"-1\n";
		return 0;
	}
	bool even = true;
	if((X[1] + Y[1]) & 1) even = false;

	cout<<31 + even<<"\n";

	for(int i=0; i<31; i++) {
		cout<<(1 << i)<<" ";
	}
	if(even) cout<<1<<" ";
	cout<<"\n";

	string ed = "";
	if(even) ed += 'R';

	for(int i=1; i<=n; i++) {
		if(even) X[i]--;
		string ans = solve_for(X[i], Y[i], 30) + ed;
		cout<<ans<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 2304
#include "bits/stdc++.h"
using namespace std;

typedef pair <int, int> pii;
const int maxn = 2e5 + 10;

int n, m, M;

vector <int> adj[2][maxn];

int cur;
int idx[2][maxn];

map <pii, int> Map;

void dfs(int id, int v) {
	idx[id][v] = cur;

	for(auto u: adj[id][v])
		if(!idx[id][u])
			dfs(id, u);
}

void solve() {
	for(int id = 0; id <= 1; ++id)
		for(int i = 1; i <= n; ++i) 
			if(!idx[id][i]) {
				++cur;
				dfs(id, i);
			}

	for(int i = 1; i <= n; ++i)
		++Map[{idx[0][i], idx[1][i]}];
}

int main() {
	scanf("%d %d %d", &n, &m, &M);

	for(int i = 1; i <= m; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);

		adj[0][a].push_back(b);
		adj[0][b].push_back(a);
	}

	for(int i = 1; i <= M; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);

		adj[1][a].push_back(b);
		adj[1][b].push_back(a);
	}

	solve();

	for(int i = 1; i <= n; ++i)
		printf("%d ", Map[{idx[0][i], idx[1][i]}]);

	return 0;
}

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

int main()
{
	int n; cin >> n;
	vector<int> x(n);
	for(auto&& i: x)
	{
		cin >> i;
	}

	int ans = 1e9;
	for(int i = 0; i <= 100; i++)
	{
		int sum = 0;
		for(auto&& a: x)
		{
			sum += (a - i)*(a - i);
		}
		ans = min(ans, sum);
	}

	cout << ans << endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
int main(){
  long long int a,b,c,ans;
  scanf("%lld %lld %lld\n",&a,&b,&c);
  if(c>a+b){
    ans=a+b+b+1;
  }
  else if(c==a+b){
    ans=a+b+b;
  }
  else{
    ans=c+b;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define ll long long
#define P pair<int,int>

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

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i] == a[i-1]){
            a[i] = -1;
            ans++;
        }
    }
    cout << ans << endl;
}

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

int count;

void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];

    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] = SIGNAL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        count++;
    }
}

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

int main() {
    int n;
    count = 0;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    mergeSort(A, 0, n);

    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int a;

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

	cin >> a;

	cout << "ABC" << a << endl;

	return 0;
}

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

int main(){
  int A,B; cin >> A >> B;
  char N[20];
  int ans = 0;
  for(int i=0;i<A+B+1;i++)
    cin >> N[i];
  for(int i=0;i<A;i++){
    if(N[i] == '-'){
      ans++;
      break;
    }
  }
  for(int i=A+1;i<B+A+1;i++){
    if(N[i] == '-'){
      ans++;
      break;
    }
  }
  if(N[A] != '-')
    ans++;
  if(ans == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
  
  
  
    
  

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    s=input()
    r=s.count("R")
    b=N-r
    
    if r>b:
        print("Yes")
    else:
        print("No")

main()


Measured memory_bytes: 61856
// in the name if Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll INF = 1<<30 ;
const ll N= 1e6 ;
#define f first
#define s second
ll a , b , c ;
map<ll,ll> m , h ;
vector<ll> v ;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> c ;
 v.push_back(a) ;
  v.push_back(b);
  v.push_back(c) ;
  sort(v.begin(),v.end());
  cout << v[0]+v[1] ;
  return 0;
}

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

const int N=100000+50;

signed main(){
    ios::sync_with_stdio(false);
    string t;
    cin>>t;
    int n=t.size();
    for(int i=0;i<n;i++){
        if(t[i]=='?'){
            t[i]='D';
        }
    }

    cout<<t;
}
/*

Mistakes to take care of-

1. For string s, s+=a is similar to appending to s. s = s + a takes O|s| + O|a| time. 
Relevant problem where I made mistake - https://codeforces.com/contest/1326/problem/D2

2. Try using constant value of N to declare arrays, etc. Else you might get hacked / FST.
Relevant problem where I made a mistake - https://codeforces.com/contest/1307/problem/D

3. While exponentiation, avoid modding the exponent. Or mod with mod-1.
Relevant problem where I made a mistake - https://codeforces.com/contest/1332/problem/E

4. modulo operator (%) in c++ returns the sign of the divisor.
Eg. (-1%8) = -1
Relevant problem where I made a mistake - https://codeforces.com/contest/1345/submission/79809463
*/

Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println( Math.min(a, b) +" "+ Math.max(0, n - (n - a) -  (n -b)));
		
	}
}


Measured memory_bytes: 21972
#include <iostream>

int main() {
    long int n;
    std::cin >> n;
    
    long int m = n  / 11 * 2;
    if ( n % 11 > 0 ) {
        m++;
        if ( n%11 > 6 ) m++;
    }
    std::cout << m << std::endl;
}

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

int main() {
    char o[51], e[51];
    scanf("%s\n%s", o, e);
    int i;
    for (i = 0; e[i]; i++) {
        putchar(o[i]);
        putchar(e[i]);
    }
    if (o[i]) {
        putchar(o[i]);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;

             
        
int main() {
			//    fast
            //    #ifndef ONLINE_JUDGE
            //    freopen("input.txt","r",stdin);
            //    freopen("output.txt","w",stdout);
            //    #endif
               
                   ll r;
                   cin>>r;
                   double ans=2.0 *(double)r*3.14159;
                   cout<<fixed<<setprecision(10)<<ans;
                

                return 0;
            }


Measured memory_bytes: 3780
#include<stdio.h>
int main(){
	int n,a1,a2,a3;
	scanf("%d", &n);
	
	a3=n % 10;
	a2=(n/10)%10;
	a1= n/100;
	
	if(a3==7){
	puts("Yes");
}
	else if(a2==7){
	puts("Yes");
}
	else if(a1==7){
	puts("Yes");
}
	else{
	puts("No");
}
	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    vector<pair<int,int>> vp;

    for (int i = 1;i < n;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
        vp.emplace_back(a,b);
    }

    vector<int> use(n,0);
    vector<int> color(n,0);
    map<pair<int,int>,int> c;
    queue<int> que;
    que.push(0);
    use[0] = 1;

    int k = 0;

    while(!que.empty()){
        int v = que.front();
        que.pop();
        
        int cur = 1;
        if (k < g[v].size()) k = g[v].size();

        for (auto u : g[v]){
            if (use[u] == 1){
                continue;
            }

            if (cur == color[v]){
                cur++;
            }

            color[u] = c[make_pair(u,v)] = c[make_pair(v,u)] = cur++;
            use[u] = 1;
            que.emplace(u);
        }
    }

    cout << k << endl;
    for (auto p : vp) cout << c[p] << endl;

    return 0;
}

Measured memory_bytes: 20084
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut x: i64 = read();
    let mut mseq = vec![0 as i64; n];
    let mut min_value = i64::max_value();
    for i in 0..n {
        mseq[i] = read();
        x -= mseq[i];
        min_value = std::cmp::min(min_value, mseq[i]);
    }
    println!("{}", n as i64 + x / min_value);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>
#include <string.h>
int main (void){
char a[11],b[11],c[11];
char x,y,z;
scanf("%s %s %s",a,b,c); 
if (a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0]) {
printf("YES\n");
 } else {
printf("NO\n");
}
return 0;
}

Measured memory_bytes: 128
N, M, Q = map(int,input().split())
m =  [[0 for y in range(N+1)] for x in range(N+1)]
m2 =  [[0 for y in range(N+1)] for x in range(N+1)]
m3 =[[0 for y in range(N+1)] for x in range(N+1)]

for i in range(M):
    l, r = map(int,input().split())
    m[l][r]+=1

for j in range(1, N+1):
    s=0
    for i in range(1, N+1):
        s+=m[i][j]
        m2[i][j]=s

for i in range(1, N+1):
    s=0
    for j in range(i, N+1):
        s+=m2[j][j]-m2[i-1][j]
        m3[i][j]=s

for i in range(1,Q+1):
    l, r = map(int,input().split())
    print(m3[l][r])


Measured memory_bytes: 17396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

int main() {
   int n, k, x, y;
   cin >> n >> k >> x >> y;

    if (n > k) {
        cout << k * x + (n - k) * y << endl;
    } else {
        cout << n * x << endl;
    }
}

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

using namespace std; 

typedef long long ll; 

#define fo(i,n) for(int i=0;i<n;i++) 
#define ms(i,a) memset(a,i,sizeof(a)) 
#define mod 1000000007
#define maxn 2003

int n,m,f[maxn],cnt,tin[maxn],tout[maxn],vis[maxn<<1],pw[maxn<<1],eq,bigger,fa[maxn][10],dist[maxn][10],nedge,head[maxn]; 
ll x; 

struct Edge{
	int to,next,w;  
}edge[maxn<<1]; 

struct E{
	int x,y,z; 
	bool operator < (const E & rhs) const{
		return z<rhs.z; 
	}
}t[maxn<<1]; 

ll inline read(){
	ll x=0,w=0;char ch=0; 
	while (ch<'0' || ch>'9') w+=ch=='-',ch=getchar(); 
	while (ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); 
	return w? -x:x; 
}

void addedge(int a,int b,int c){
	edge[nedge].to=b; 
	edge[nedge].w=c; 
	edge[nedge].next=head[a]; 
	head[a]=nedge++; 
}

int gf(int k){
	return k==f[k]? k: f[k]=gf(f[k]); 
}

void dfs(int k,int father,int d){
	tin[k]=++cnt; 
	fa[k][0]=father; 
	dist[k][0]=d; 
	for(int i=head[k];i!=-1;i=edge[i].next){
		int v=edge[i].to; 
		if(v==father) continue; 
		dfs(v,k,edge[i].w); 
	}
	tout[k]=++cnt; 
}

int ancestor(int x,int y){
	return tin[x]<=tin[y] && tout[y]<=tout[x]; 
}

int lca(int x,int y){
	if(ancestor(x,y)) return x; 
	if(ancestor(y,x)) return y; 
	for(int i=9;i>=0;i--)
		if(!ancestor(fa[x][i],y)) 
			x=fa[x][i]; 
	return fa[x][0]; 
}

int calc(int x,int y){
	if(x==y) return 0;
	int ret=0; 
	for(int i=9;i>=0;i--)
		if(!ancestor(fa[x][i],y)){
			ret=max(ret,dist[x][i]); 
			x=fa[x][i]; 
		}
	return max(ret,dist[x][0]); 
}

int main(){
	n=read(); 
	m=read(); 
	x=read(); 
	pw[0]=1; 
	fo(i,2000) pw[i+1]=pw[i]*2 % mod; 
	fo(i,m){
		t[i].x=read(); 
		t[i].y=read(); 
		t[i].z=read(); 
		t[i].x--;
		t[i].y--; 
	}
	sort(t,t+m); 
	fo(i,n) f[i]=i; 
	ll  mst=0,num=0; 
	nedge=0;ms(-1,head); 
	fo(i,m){
		int fa=gf(t[i].x); 
		int fb=gf(t[i].y); 
		if(fa!=fb){
			f[fa]=fb; 
			addedge(t[i].x,t[i].y,t[i].z); 
			addedge(t[i].y,t[i].x,t[i].z); 
			num++; mst+=t[i].z; 
			vis[i]=1; 
		}
		if(num==n-1) break; 
	}
	if(mst>x) {
		puts("0");
		return 0; 
	}
	dfs(0,0,0); 
	fo(j,9) fo(i,n) fa[i][j+1]=fa[fa[i][j]][j],dist[i][j+1]=max(dist[i][j],dist[fa[i][j]][j]);
	ll  d=x-mst,ans=0; 
	fo(i,m){
		if(vis[i]) continue; 
		int v=lca(t[i].x,t[i].y); 
		int me=max(calc(t[i].x,v),calc(t[i].y,v)); 
		if(t[i].z-me==d) eq++;
		else if(t[i].z-me>d) bigger++; 
	}
	if(d==0) ans=(1LL*(pw[n-1]-2)*pw[m-n+1] % mod +mod ) % mod; 
	ans=(ans+ 2LL*(pw[eq+bigger]-pw[bigger]) % mod +mod ) % mod; 
	printf("%lld\n",ans); 
	return 0; 
}

Measured memory_bytes: 512
# すぬけ君は 1 〜 N の整数が等確率で出る N 面サイコロと表と裏が等確率で出るコインを持っています。
# すぬけ君は、このサイコロとコインを使って今から次のようなゲームをします。
# まず、サイコロを 1 回振り、出た目を現在の得点とする。
# 得点が 1 以上 K−1 以下である限り、すぬけ君はコインを振り続ける。
# 表が出たら得点は 2 倍になり、裏が出たら得点は 0 になる。
# 得点が 0 になった、もしくは K 以上になった時点でゲームが終了する。
# このとき、得点が K 以上である場合すぬけ君の勝ち、 0 である場合すぬけ君の負けである。
# N と K が与えられるので、このゲームですぬけ君が勝つ確率を求めてください。

input = gets.chomp.split
n = input[0].to_i
k = input[1].to_i

probability_sum = 0

n.times do |i|
  point = i + 1

  double_count = 0
  while point < k
    point *= 2
    double_count += 1
  end
  
  probability = (1.0 / n) * ((1.0 / 2.0) ** double_count)
  probability_sum += probability
end

puts probability_sum

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    vector<string> s(N);
    cin>>s;
    auto t=s;
    sort(ALL(t));
    t.pb("5.000");
    REP(i,N){
        int a = (distance(t.begin(),upper_bound(ALL(t),s[i])));//<=s[i]
        int b = (distance(t.begin(),lower_bound(ALL(t),s[i])));//<s[i]
        cout<<a+b*2-1<<endl;
        
    }
    return 0;
}

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

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

    vector<int> X(N);
    for (int i = 0; i < N; i++)
        cin >> X[i];
    sort(X.begin(), X.end());

    int pay = X[N-1]/2;
        
    for (int i = 0; i < N-1 ; i++)
            pay+= X[i];
    cout << pay << endl;
    return 0;
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",if a==b{a+b}else if a<b{b*2-1}else{a*2-1})
}

Measured memory_bytes: 4352
n = int(input())
a = list(map(int, input().split()))

f = 0
d = 0
for x in a:
    if x % 4 == 0:
        f += 1
    elif x % 2 == 0:
        d += 1

if 0 < d < n:
    d -= 1

if n > f * 2 + 1 + d:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 14252
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 7
# 1 2 3 4 5 6 7



# 4
# 2 2 1 3

# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################
N = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)
_p(A)

if N==1:
  print(0)
  exit()

if N==2:
  print(A[0])
  exit()

if N==3:
  print(A[0]+A[1])
  exit()


from collections import deque
Q = deque()
Q.append(A[0])

ans = 0
for a in A[1:]:
  q = Q.popleft()
  ans += q
  Q.append(a)
  Q.append(a)
  # _p("a,q=",a, q, " ansans=",ans)

print(ans)





Measured memory_bytes: 31328
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math

# pascal = [[] for _ in range(4005)]

# pascal_triangle = [
#     [0 for _ in range(1 + i)] for i in range(4005)
#     # [0 for _ in range(1 + i)] for i in range(10)
# ]

def init():
    # pascal_triangle[0][0] = 1
    # for i in range(1, len(pascal_triangle)):
    #     for j in range(len(pascal_triangle[i])):
    #         new_value = 0
    #         if j < len(pascal_triangle[i-1]):
    #             new_value += pascal_triangle[i-1][j]
    #         if 0 <= j - 1:
    #             new_value += pascal_triangle[i-1][j-1]
    #         pascal_triangle[i][j] = new_value
    pass


# x 個の玉を y グループに分ける場合の数 (1個以上の玉のグループ)
def f2(x, y):
    # return pascal_triangle[x + y - 1][y - 1]
    n = x + y - 1
    r = y - 1
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


# x 個の玉を y グループに分ける場合の数 (0個以上の玉のグループ)
def f(x, y):
    if x < y:
        return 0
    if x == 0 and y == 0:
        return 1
    if x == 0:
        return 0
    if y == 0:
        return 0
    return f2(x - y, y)


init()

# N = 5, K = 3
N, K = list(map(int, input().split()))

for i in range(1, K + 1):
    result = f(K, i) * (
        f(N - K, i - 1) +
        f(N - K, i) +
        f(N - K, i) +
        f(N - K, i + 1)
    )
    # print('0', i)
    # print('1', f(K, i))
    # print('2', f(N - K, i - 1))
    # print('3', f(N - K, i))
    # print('4', f(N - K, i + 1))
    print(result % 1000000007)
    # print("")

# for line in pascal_triangle:
#     print(line)

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int n; scanf("%d",&n);
    string str; getline(cin,str);
    set<string> log;
    for (int i=0; i<n; i++) {
        getline(cin,str);
        if (log.find(str)!=log.end()) puts("Yes");
        else {
            log.insert(str);
            puts("No");
        }
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int t;
ll a, b, c, d;
map<ll,ll> mp[10];

ll f(ll n){
	if(mp[t][n]!=0)
		return mp[t][n];
	if(n<=1)
		return d*n;
	ll cost=d*n;
	if(cost<0)
		cost=INF;
	if(n%2==0)
		cost=min(cost,f(n/2)+a);
	else{
		cost=min(cost,f((n-1)/2)+a+d);
		cost=min(cost,f((n+1)/2)+a+d);
	}
	if(n%3==0)
		cost=min(cost,f(n/3)+b);
	else if(n%3==1)
		cost=min(cost,f((n-1)/3)+b+d);
	else
		cost=min(cost,f((n+1)/3)+b+d);
	if(n%5==0)
		cost=min(cost,f(n/5)+c);
	else if(n%5<=2)
		cost=min(cost,f((n-n%5)/5)+c+d*(n%5));
	else
		cost=min(cost,f((n+5-n%5)/5)+c+d*(5-n%5));
	return mp[t][n]=cost;
}

int main(){
	cin >> t;
	while(t--){
		ll n; cin >> n;
		cin >> a >> b >> c >> d;
		cout << f(n) << endl;
	}
	return 0;
}

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

int main(void){
  double highest = 0.0, lowest = 1.797693e+308, now;
  while(cin >> now){
    if(now > highest) highest = now;
    else if(now < lowest) lowest = now;
  }
  printf("%.1f\n", highest - lowest);
  return 0;
}

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

int main(){
  int h,w; cin>>h>>w;
  vector<vector<char>> data(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)
      cin>>data[i][j];
  }
  vector<int>tate(w);
  vector<int>yoko(h);
  
  for(int i=0;i<h;i++){
    int countw=0;
    for(int j=0;j<w;j++){
      if(data[i][j]=='#')
        countw++;
    }
    if(countw==0)
      yoko[i]++;
  }
  
  for(int i=0;i<w;i++){
    int counth=0;
    if(data[0][i]=='.'){
      for(int j=0;j<h;j++){
        if(data[j][i]=='.')
          counth++;
      }
      if(counth==h){
        tate[i]++;
      }
    }
  }
  
  for(int i=0;i<h;i++){
    bool t=true;
    for(int j=0;j<w;j++){
      if(yoko[i]==1){
        t=false;
        break;
      }
      if(tate[j]==1)
        continue;
      cout<<data[i][j];
    }
    if(t)
      cout<<endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

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

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


inline int mul (int a, int b, int m = MOD) {
    return ((ll)a * b) % m;
}

inline int binpow (int a, int n, int m = MOD) {
    int ans = 1;
    for (; n; n >>= 1) {
        if (n & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
    }
    return ans;
}

inline void add (int &a, int x, int m = MOD) {
    a += x;
    if (a >= m) a -= m;
    if (a < 0) a += m;
}

inline int sum (int a, int b, int m = MOD) {
    a += b;
    if (a >= m) a -= m;
    if (a < 0) a += m;
    return a;
}

inline int inv (int x, int m = MOD) {
    return binpow(x, m - 2, m); /// only if m is prime
}

vector <int> f, fi;

inline void precalc_f (int n, int m = MOD) {
    f.resize(n);
    fi.resize(n);
    f[0] = 1;
    for (int i = 1; i < n; i++) {
        f[i] = mul(f[i - 1], i, m);
    }
    fi[n - 1] = inv(f[n - 1], m);
    for (int i = n - 2; i >= 0; i--) {
        fi[i] = mul(fi[i + 1], i + 1, m);
    }
}

inline int A (int n, int k, int m = MOD) {
    return mul(f[n], fi[n - k], m);
}

inline int C (int n, int k, int m = MOD) {
    return mul(A(n, k), fi[k], m);
}

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    umin(k, n - 1);
    precalc_f(n + 1);
    int ans = 1;
    for (int i = 1; i <= k; i++) {
        int can = C(n, i);
        add(ans, mul(can, C(n - 1, i)));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    int arr[n]={0};
    for(int i=1;i<n;i++)
    {
    for(int j=i+1;j<=n;j++)
    {
    int k=min(j-i,abs(x-i)+1+abs(j-y));
    arr[k]++;
    }
    }
    for(int i=1;i<n;i++)
    cout<<arr[i]<<endl;
	return 0;
}

Measured memory_bytes: 3612
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        final int N = Integer.parseInt(in.readLine());
        String[] S = new String[N];
        int endWithA = 0;
        int beginWithB = 0;
        int eAbB = 0;
        int ab = 0;
        for (int i = 0; i < N; i++) {
            S[i] = in.readLine();
            if (S[i].charAt(0) == 'B') {
                beginWithB++;
            }
            if (S[i].charAt(S[i].length() - 1) == 'A') {
                endWithA++;
            }
            if (S[i].charAt(0) == 'B' && S[i].charAt(S[i].length() - 1) == 'A') {
                eAbB++;
            }
            for (int j = 0; j < S[i].length() - 1; j++) {
                if (S[i].charAt(j) == 'A' && S[i].charAt(j + 1) == 'B') {
                    ab++;
                }
            }
        }
        int ans = 0;
        if (endWithA > 0 && endWithA == beginWithB && endWithA == eAbB) {
            ans = ab + endWithA - 1;
        } else {
            ans = ab + Math.min(endWithA, beginWithB);
        }

        System.out.println(ans);

    }

    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

Measured memory_bytes: 24404
n=int(input())
word=[]
for i in range(n):
  if i==0:
    word.append(input())
    continue
  k=input()
  if k in word:
    print("No")
    exit()
  a=list(word[-1])
  b=list(k)
  word.append(k)
  if a[-1]==b[0]:
    pass
  else:
    print("No")
    exit()
print("Yes")

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

int main(void){
    int X,Y,n;
    cin >> X >> Y >> n;
    vector<int> block(X+2, Y+1);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        block[x] = min(block[x], y);
    }
    int maxY = 1;
    for(int x = 2; x <= X; x++){
        if(block[x] <= maxY){
            cout << x - 1 << endl;
            return 0;
        }
        if(block[x] > maxY + 1){
            maxY++;
        }
    }
    cout << X << endl;
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
    ll N, K;
    vector<ll> x;
    cin >> N >> K;
    rep(i, 0, N){
        ll temp;
        cin >> temp;
        x.push_back(temp);
    }
    ll ans = 0;
    rep(i, 0, N){
        ans += abs(x[i]) <= abs(K - x[i]) ? abs(x[i]) : abs(K - x[i]);
    }
    cout << ans * 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
 public static void main(String args[])
 {
  int number,i,j,n;
  String pattern;
  int [][] card = new int [4][13];
  for(i=0;i<4;i++)
  {
   for(j=0;j<13;j++)
    card[i][j]=0;
  }
  Scanner sc = new Scanner(System.in);
  n=sc.nextInt();
  for(i=0;i<n;i++)
  {
   pattern=sc.next();
   number=sc.nextInt();
   switch(pattern.charAt(0))
   {
    case 'S':
     card[0][number-1]=1;break;
    case 'H':
     card[1][number-1]=1;break;
    case 'C':
     card[2][number-1]=1;break;
    default:
     card[3][number-1]=1;break;
	}
  }
  for(i=0;i<4;i++)
  {
   for(j=0;j<13;j++)
   {
    if(card[i][j]!=1)
	{
      if(i==0)
       System.out.println("S "+(j+1));
      else if(i==1)
       System.out.println("H "+(j+1));
      else if(i==2)
       System.out.println("C "+(j+1));
      else
       System.out.println("D "+(j+1));
	 }
	}
   }
 }
}


Measured memory_bytes: 26252
#include <bits/stdc++.h>
using namespace std;  
#define ll long long int
#define All(a) (a).begin(),(a).end()

void solve(){
  int n;
  scanf("%d",&n);
  vector<int> a(n),b(n),c(n);

  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(int i=0;i<n;i++){
    scanf("%d",&b[i]);
  }

  for(int i=0;i<n;i++){
    scanf("%d",&c[i]);
  }
  sort(All(a));
  sort(All(b));
  sort(All(c));
  ll count=0;
  for (int j = 0; j < n; j++)
  {
    auto tmp = lower_bound(All(a),b[j]);
    int l=tmp-a.begin();
    ll tmp2 = c.end()-upper_bound(All(c),b[j]);
    count+=l*tmp2;
      
    
  }
  printf("%lld\n",count);
}
int main(){
  /*
  int q;
  scanf("%d",&q);
  while(--q)solve();
  */
  solve();

  return 0;
}

Measured memory_bytes: 4596
#define ll long long int
#include <iostream>
using namespace std;

int main(void)
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);

    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
    	if((i%3!=0)&&(i%5!=0))
    		ans+=i;

    }
    cout<<ans<<"\n";


    

}

Measured memory_bytes: 3636
N = int(input())
A = [0] + [int(i) for i in input().split()] + [0]

cost = 0
pos = 0
for p in range(0, len(A)):
    cost += abs(pos - A[p])
    pos = A[p]

for i in range(1, len(A)-1):
    n_cost = 0
    if A[i-1] <= A[i] and A[i] <= A[i + 1]:
        n_cost = cost
    elif A[i] <= A[i - 1] and A[i] <= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i] >= A[i - 1] and A[i] >= A[i + 1]:
        n_cost = cost - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1])
    elif A[i-1] >= A[i] and A[i] >= A[i + 1]:
        n_cost = cost

    print(n_cost)


Measured memory_bytes: 13800
import java.util.Scanner;

public class Main {

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

        if(A==B){
            System.out.println(A+B);
        }else{
            System.out.println(Math.max(A,B)+Math.max(A,B)-1);
        }


    }
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll n;
VL v;
VL odd(ll(1e5 + 1)), even(ll(1e5 + 1));

int main() {
    cin >> n;
    REP(i, n) {
        if(i % 2)
            odd[IN()]++;
        else
            even[IN()]++;
    }
    ll oidx = max_element(All(odd)) - odd.begin();
    ll eidx = max_element(All(even)) - even.begin();
    sort(All(odd), greater<ll>());
    sort(All(even), greater<ll>());
    if(oidx != eidx)
        cout << n - odd[0] - even[0] << "\n";
    else
        cout << n - max(odd[0] + even[1], odd[1] + even[0]) << "\n";
}


Measured memory_bytes: 1792
import math
import itertools
from statistics import mean
n = int(input())
p = [list(map(int,input().split())) for i in range(n)]
ans = []
for v in itertools.permutations(p):
  length = 0
  for i in range(n-1):
    length += math.sqrt((v[i+1][0] - v[i][0])**2 + (v[i+1][1] - v[i][1])**2)
  ans.append(length)

print(mean(ans))

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

int main()
{
    int n, m, p, d;

    while( cin >> n >> m >> p )
    {
        if( n + m + p == 0 )
            break;
    
        int sum = 0, win = 0, cnt = 0;
        for( int i = 0; i < n; i++ )
        {
            cnt++;
            cin >> d;

            if( m == cnt )
                win = d;

            sum += d;
        
        }
        if( win == 0 )
            cout << win << endl;
        else
            cout << sum * ( 100 - p ) / win << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
#include<map>
#include<queue>
#include<string>
#include<iostream>

#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

map<string,int> f;

enum {Atom,Number,LParen,RParen};

struct Token{ int id,n; };

queue<Token> qu;

int molecule(void);

int unitmolecule(void){
	Token tk=qu.front();	qu.pop();
	if(tk.id==Atom){
		int a=tk.n;
		if(!qu.empty() && qu.front().id==Number){
			a*=qu.front().n;	qu.pop();
		}
		return a;
	}
	else{
		int a=molecule();
		qu.pop();
		a*=qu.front().n;	qu.pop();
		return a;
	}
}

int molecule(void){
	int a=unitmolecule();
	if(!qu.empty() && (qu.front().id==Atom || qu.front().id==LParen))	return a+molecule();
	return a;
}

int parse(string s){
	int len=s.length();

	qu=queue<Token>();
	rep(i,len){
		Token tk;

		if(isupper(s[i])){
			int num;
			string atom;
			atom+=s[i];
			if(i+1<len && islower(s[i+1]))	atom+=s[++i];
			if(f.count(atom))	num=f[atom];
			else	return -1;
			tk.id=Atom;
			tk.n=num;
		}
		else if(isdigit(s[i])){
			int num=s[i]-'0';
			if(i+1<len && isdigit(s[i+1]))	num=10*num+(s[++i]-'0');
			tk.id=Number;
			tk.n=num;
		}
		else{
			if(s[i]=='(')	tk.id=LParen;
			else			tk.id=RParen;
		}

		qu.push(tk);
	}

	return molecule();
}

int main(){
	while(1){
		string atom;	cin>>atom;
		if(atom=="END_OF_FIRST_PART")	break;
		int w;	cin>>w;
		f[atom]=w;
	}

	for(string mole;cin>>mole,mole!="0";){
		int w=parse(mole);
		if(~w)	cout<<w<<endl;
		else	cout<<"UNKNOWN"<<endl;
	}

	return 0;
}

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


int main(){
  int n,a[10];
  vector<int> ans;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(int i=1;i<=a[0]/i+1;i++){
    if(a[0]%i==0){
      bool f1=1,f2=1;
      for(int j=1;j<n;j++){
        if(a[j]%i) f1=0;
        if(a[j]%(a[0]/i)) f2=0;
      }
      if(f1) ans.push_back(i);
      if(f2&& i!=a[0]/i) ans.push_back(a[0]/i);
    }
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<(int)ans.size();i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int a, b;
	cin >> a >> b;
	int t = a + b;
	if(t >= 24)
		t -= 24;
	cout << t << endl;	
    return 0;
}


Measured memory_bytes: 3588
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b;
	cin >> a >> b;
	if(abs(a-(a+b)/2)==abs(b-(a+b)/2)) cout << (a+b)/2;
	else cout << "IMPOSSIBLE";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
    int x,y,z;
    cin >> x  >> y >> z;
    cout << z << " " << x << " " << y << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        if(N<B) System.out.println((A*N)/B-A*(N/B));
        else System.out.println((A*(B-1))/B-A*((B-1)/B));
    }
}

Measured memory_bytes: 35816
#include<iostream>
#include<cmath>

using namespace std;
int main()
{
    int n;
    cin >> n;
    int a,b,c,d;
    int aa[n];
    for(int i=0;i<n;i++){
        aa[i]=0;
    }
    for(int i=0;i<n*(n-1)/2;i++){
        cin >> a >> b >> c >> d;
        if(c>d){
            aa[a-1]+=3;
        }else if(c==d){
            aa[a-1]+=1;
            aa[b-1]+=1;
        }else{
            aa[b-1]+=3;
        }
    }
    int j=1;
    int x[n];
    for(int i=0;i<n;i++){
        x[i]=1;
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(aa[i]<aa[j]){
                x[i]++;
            }else if(aa[i]>aa[j]){
                x[j]++;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << x[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
import sys
input = sys.stdin.readline
import collections


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

    if D[0] != 0 or c[0] > 1:
        print(0)
        exit()

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()



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

int main(){

    char c;
    cin>>c;
    switch(c){
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            cout<<"vowel"<<endl;
            break;
        default:
            cout<<"consonant"<<endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,i,c;
int a[105];
int main(){
	int mi=1000000001;
	int ma=-1;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		ma=max(ma,a[i]);
		mi=min(mi,a[i]);
	}
	int ans=ma-mi;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int x;
   cin>>x;
   if(x==25)
    cout<<"Christmas";
   else if(x==24)
    cout<<"Christmas Eve";
   else if(x==23)
    cout<<"Christmas Eve Eve";
     else if(x==22)
    cout<<"Christmas Eve Eve Eve";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int in[128], out[128], ini = 0, outi = 0, com, i;
	
	while (scanf("%d", &com) != EOF){
		if (com == 0){
			out[outi] = in[ini - 1];
			outi++;
			ini--;
		}
		else {
			in[ini] = com;
			ini++;
		}
	}
	
	for (i = 0; i < outi; i++){
		printf("%d\n", out[i]);
	}
	return (0);
}

Measured memory_bytes: 600
n = gets.to_i
cards = []
n.times do |n|
  cards[n] = gets.split
  cards[n][1] = cards[n][1].to_i
end

def partation(arr, p, r)
  std = arr[r][1]
  i = p - 1
  for j in (p...r)
    if arr[j][1] <= std
      i += 1
      arr[j], arr[i] = arr[i], arr[j]
    end
  end
  arr[i + 1], arr[r] = arr[r], arr[i + 1]
  return i + 1
end

def quick_sort(arr, p, r)
  if p < r
    q = partation(arr, p, r)
    quick_sort(arr, p, q - 1)
    quick_sort(arr, q + 1, r)
  end
  return arr
end

$inf = 1.0 / 0.0
def merge_sort(arr)
  left = arr[0..(arr.length / 2 - 1)]
  right = arr[(arr.length / 2)..(arr.length - 1)]
  left = merge_sort(left) unless left.length <= 1
  right = merge_sort(right) unless right.length <= 1
  left.push(["z", $inf])
  right.push(["z", $inf])
  res = []
  l, r = 0, 0
  while !(l == left.length || r == right.length)
    if left[l][1] <= right[r][1]
      res.push(left[l])
      l += 1
    else
      res.push(right[r])
      r += 1
    end
  end
  res.pop
  return res
end


def is_Stable(c1, c2, n)
  for i in 0..n-2
    if c2[i][1] == c2[i+1][1] && c2[i] != c1[i]
      return false
    end
  end
  return true
end

cards_dup = Marshal.load(Marshal.dump(cards))
arr1 = quick_sort(cards_dup, 0, n - 1)
arr2 = merge_sort(cards)
is_Stable(arr1, arr2, n) ? puts("Stable") : puts("Not stable")
arr1.map do |a|
  puts a.join(' ')
end



Measured memory_bytes: 48348
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;




string rotate(string s);

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

  for (int i=0;i<n;i++) {
    if (s==t) {
      cout << "Yes" << endl;
      return 0;
    }
    // 回転の関数rotate
    s = rotate(s);
  }
  cout << "No" << endl;
  return 0;
}

// ex) s = abcde → bcde + a
string rotate(string s) {
  return s.substr(1) + s[0];
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

A,B = inpl()
print(max(A-2*B,0))


Measured memory_bytes: 4592
//JOI2015 1 Selecting Subjects
//20181209
//F_Naru
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int A,B,C,D,E,F;
  cin >> A >> B >> C  >> D >> E >> F;
  cout << (A+B+C+D - min(min(A,B), min(C,D)) ) + max(E,F) << endl;
}


Measured memory_bytes: 3124
#include<stdio.h>
int main()
{
    int num;
    char string[100];
    scanf("%d %s",&num,string);
    if(num>=3200)
    {
        printf("%s",string);
    }
    else if(num<3200)
    {
        printf("red\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(s==u) a--;
    if(t==u) b--;
    cout<<a<<" "<<b<<endl;

}


Measured memory_bytes: 256