akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>){
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val mod = 1000000007L

    if(Math.abs(b - a) >= 2){
        println(0)
        return
    }
    var ans = 1L
    if(a == b){
        for(i in 1..a){
            ans = (ans * i) % mod
            ans = (ans * i) % mod
        }
        ans = (ans * 2) % mod
    }else{
        for(i in 1..a){
            ans = (ans * i) % mod
        }
        for(i in 1..b){
            ans = (ans * i) % mod
        }
    }
    println(ans % mod)
}

Measured memory_bytes: 37964
#include<stdio.h>
#include<string.h>
int main()
{
    char s[102];
    scanf("%s", s);
    int c, f;
    c = 0;
    while (s[c] != 'C' && c < strlen(s))
        c++;
    f = strlen(s) - 1;
    while (s[f] != 'F' && f >= 0)
        f--;
    if (c < f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int count=0;
  for(int i=0; i<(int)S.length(); i++){
    if(S.at(i) != T.at(i))
      count++;
  }
  cout << count << endl;
}




Measured memory_bytes: 3808
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat May 12 10:23:57 2018
//
package main

import (
	"fmt"
)

var N int
var arr []int

func main() {
	fmt.Scan(&N)

	arr = make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
		arr[i]--
	}

	var count int
	for i := range arr {
		j := arr[arr[i]]
		if i < arr[i] && j == i {
			count++
		}
	}
	fmt.Println(count)
}


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

int main() {

string N;
  cin>>N;
  
  if(N=="Sunny"){N="Cloudy";}
  else if(N=="Cloudy"){N="Rainy";}
   else if(N=="Rainy"){N="Sunny";}
	cout<<N<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x[3];
	int a,b;
	cin >> b;
	for(a=0;a<b;a++) {
		cin >> x[0] >> x[1] >> x[2];
		if(x[0]*x[0] + x[1]*x[1] == x[2]*x[2]){
			cout << "YES" << endl;
		}
		else if(x[0]*x[0] + x[2]*x[2] == x[1]*x[1]){
			cout << "YES" << endl;
		}
		else if(x[1]*x[1] + x[2]*x[2] == x[0]*x[0]){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> z(n);
    for(int i = 0; i < n; i++) {
        z[i].first = i + 1;
        cin >> z[i].second.first >> z[i].second.second;
    }

    int way = 0;
    double ans = 0.0;
    do {
        way++;
        for(int i = 0; i < n - 1; i++){
            ans += hypot(z[i+1].second.first - z[i].second.first, z[i+1].second.second - z[i].second.second);
        }
    } while (std::next_permutation(z.begin(), z.end()));

    cout << setprecision(12) << ans / way << endl;
    return 0;
}

Measured memory_bytes: 256
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	vector<vector<int>> graph;
	vector<int> signpost;
	int n,a,b;
	cin>>n;
	graph.resize(n);
	signpost.resize(n,-2);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		graph[--a].push_back(--b);
		graph[b].push_back(a);
	}
	signpost[0]=-1;
	queue<int> q;
	q.push(0);
	while(!q.empty())
	{
		for(auto i:graph[q.front()])
		{
			if(signpost[i]==-2)
			{
				signpost[i]=q.front();
				q.push(i);
			}
		}
		q.pop();
	}
	if(find(signpost.begin(),signpost.end(),-2)==signpost.end())
	{
		cout<<"Yes"<<endl;
		for(int i=1;i<signpost.size();i++)
		{
			cout<<signpost[i]+1<<'\n';
		}
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 10236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"siktim seni\n";
ll int a,i,ans;
string b;
int main(){
	cin>>a>>b;
	if(a%2==1){cout<<"No";return 0;}
	for(i=a-1;i>=(a/2);i--){
		if(b[i]!=b[i-a/2]){cout<<"No";return 0;}
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
 
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        long A = s.nextLong();
        long B = s.nextLong();
        long N = s.nextLong();
        long max = 0;
        long SSS;
        if(B-1 <= N){
            SSS = B-1;
        }else{
            SSS = N;
        }
        
        
        max = (A*SSS)/B;
        

        System.out.println(max);
	}
} 

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

int main() {
	int n;cin>>n;
	vector<int> height(n);
	for(int i=0;i<n;i++){
		cin>>height[i];
	}
	int prev1=0,prev2=abs(height[1]-height[0]);
	int cur=0;
	for(int i=2; i < n; i++){
		cur = min(abs(height[i]-height[i-2])+prev1, abs(height[i]-height[i-1])+prev2);
		prev1 = prev2;
		prev2 = cur;
	}
	cout<<prev2<<endl;
	
	return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=100010;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,X[maxn],L[maxn];
int f[maxn],q[maxn];

struct Node
{
    int l,r;
}a[maxn];

bool cmp(Node x,Node y)
{
    return x.r<y.r;
}

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    scanf("%d",&n);
    _rep(i,1,n)
    {
        scanf("%d%d",&X[i],&L[i]);
        a[i].l=X[i]-L[i]>0?X[i]-L[i]:0;
        a[i].r=X[i]+L[i];
    }    
    sort(a+1,a+n+1,cmp);    
    int ans=1,right=a[1].r;
    _rep(i,2,n)
    {
        if(a[i].l>=right)
        {
            ans++;
            right=a[i].r;
        }
    }
    cout<<ans;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 1;
    rep(i, 3){
        ans = ans * n;
        
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
using ull = unsigned long long;

int main(){
	unsigned X, Y, A, B, C;
	scanf("%u %u %u %u %u", &X, &Y, &A, &B, &C);
	ull p[A], q[B], r[C];
	for (int i = 0; i < A; ++i) scanf("%llu", p + i);
	for (int i = 0; i < B; ++i) scanf("%llu", q + i);
	for (int i = 0; i < C; ++i) scanf("%llu", r + i);
	nth_element(p, p + X - 1, p + A, greater< ull >());
	nth_element(q, q + Y - 1, q + B, greater< ull >());
	int D = min(C, X + Y);
	nth_element(r, r + D - 1, r + C, greater< ull >());
	ull s[X + Y + D];
	for (int i = 0; i < X; ++i){
		s[i] = p[i];
	}
	for (int i = 0; i < Y; ++i){
		s[X + i] = q[i];
	}
	for (int i = 0; i < D; ++i){
		s[X + Y + i] = r[i];
	}
	nth_element(s, s + X + Y - 1, s + X + Y + D, greater< ull >());
	ull answer = 0;
	for (int i = 0; i < X + Y; ++i){
		answer += s[i];
	}
	printf("%llu\n", answer);
	return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main(void) {
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  

  if(a+b==c || b+c==a || a+c==b)
  printf("Yes");
  
  else{
    printf("No");

  }
  return 0;
}

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

typedef long long ll;

vector<ll> diviser(ll A){
  
  set<ll> div;
  
  for(ll i=1;i*i<=A;i++)
    if(A%i==0){
      div.insert(i);
      div.insert(A/i);
    }
  
  vector<ll> res;
  
  for(auto v : div) res.push_back(v);

  return res;
}

ll f(ll b, ll n){
  if(n<b) return n;
  return f(b, n/b)+(n%b);
}

signed main(){
  
  ll n, s;
  cin>>n>>s;
  
  for(int b=2;b<1000000;b++){
    if(f(b,n)==s){
      cout<<b<<endl;
      return 0;
    }
  }
  
  if(n==s){
    cout<<n+1<<endl;
    return 0;
  }
  
  if(n-s<0){
    cout<<-1<<endl;
    return 0;
  }
  
  vector<ll> U=diviser(n-s);
  
  const ll INF=1e12;
  
  ll ans=INF;
  
  for(ll u : U){
    
    ll b=(n-s)/u+1;
    ll v=s-u;
    
    if(2<=b&&0<u&&u<b&&0<=v&&v<b) ans=min(ans, b);
      
  }
  
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
double x=n,y=(n+1)/2;
cout<<fixed<<setprecision(10)<<y/x;

return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> P;



unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

int main(void){
    int a,b;
    cin>>a>>b;
    string s="",t="";
    for(int i=0;i<b;i++){
        char x = a+'0';
        s.push_back(x);
    }
    for(int i=0;i<a;i++){
        char x = b+'0';
        t.push_back(x);
    }
    if(s<t)cout<<s<<endl;
    else cout<<t<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include <map>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <limits.h>
#include <string>
#include<functional>
#include <set>
#include <utility>
#include <iomanip>
#include <string>
#define INF 1<<30
#define inf 0x3f3f3f3f3f3f3f3f
#define MO 1000000007
#define MI 998244353
#define ll long long
#define woo 140737488355327
using namespace std;
map<ll,ll>v;
int main()
{
    ll x;scanf("%lld",&x);
    for(ll i=0;;i++)
    {
        v[i*i*i*i*i]=i;
        if(v[x-i*i*i*i*i]||x-i*i*i*i*i==0) {printf("%lld -%lld\n",v[x-i*i*i*i*i],i);break;}
        else if(i*i*i*i*i-x>=0&&v[i*i*i*i*i-x]) {printf("%lld %lld\n",i,v[i*i*i*i*i-x]);break;}
    }
}


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

int main() {
	int a,b,c,d;cin>>a>>b>>c>>d;
	int sub2=(a-c)*(a-c);
	if(sub2<=d*d){
		cout<<"Yes"<<endl;
		return 0;
	}
	sub2=(a-b)*(a-b);
	if(sub2>d*d){
		cout<<"No"<<endl;
		return 0;
	}
	sub2=(b-c)*(b-c);
	if(sub2>d*d){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
typedef unsigned long long u64;

u64 r, c;

u64 fromz(u64 x, u64 y)
{
  if (y == 0) {
    return x;
  }
  if (x == r) {
    return r+y;
  }
  if (y == c) {
    return r+c+(r-x);
  }
  return r+c+r+(c-y);
}

class dot
{
public:
  u64 x;
  u64 y;
  u64 id;
  dot(u64 _x, u64 _y, u64 _id) : x(_x), y(_y), id(_id) {}
};
bool operator<(const dot & l, const dot & r) {return fromz(l.x, l.y)<fromz(r.x, r.y);}
bool operator>(const dot & l, const dot & r) {return fromz(l.x, l.y)>fromz(r.x, r.y);}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> r >> c >> n;
  priority_queue< dot > q;
  bool isin[n];
  for (u64 i = 0; i < n; ++i) {
    u64 x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 == 0 || x1 == r || y1 == 0 || y1 == c) {
      if (x2 == 0 || x2 == r || y2 == 0 || y2 == c) {
        dot d1(x1, y1, i), d2(x2, y2, i);
        q.push(d1);
        q.push(d2);
      }
    }
    isin[i] = false;
  }
  stack< u64 > s;
  while (!q.empty()) {
    dot d = q.top();
    q.pop();
    if (!s.empty() && d.id == s.top()) {
      s.pop();
    } else if (isin[d.id]) {
      cout << "NO" << endl;
      return 0;
    } else {
      isin[d.id] = true;
      s.push(d.id);
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 8560
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int X;
    int kosu,sa;
    
   cin >> X; 
    kosu = X/100;
    sa=X-kosu*100;
    if(sa>kosu*5)
    cout << "0" << endl;
    else
    cout << "1" << endl;
}


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

using namespace std;
int main() {
  int n;
  cin >> n;
  int o[n], p[n], q[n];
  for (int i = 0; i < n; i++) {
    o[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> q[i];
  }

  int pIndex, qIndex;
  int index = 0;
  do {
    index++;
    bool same1 = true;
    bool same2 = true;
    for (int i = 0; i < n; i++) {
      if (o[i] != p[i]) same1 = false;
      if (o[i] != q[i]) same2 = false;
    }
    if (same1) pIndex = index;
    if (same2) qIndex = index;

  } while (next_permutation(o, o + n));

  cout << abs(pIndex - qIndex) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  int n; cin >> n;
  vll d(n);
  rep(i, n) cin >> d[i];
  int ans = 0;
  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int D = sc.nextInt();
		int T = sc.nextInt();
		int S = sc.nextInt();
		
		if(T*S >= D) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


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

int main() {
  int64_t  X;
  int64_t k=100;
  cin>>X;
  int64_t count=0;
 for (int i = 0; i <3762; i++) {
   count++;
     k*=1.01;
   if(k>=X){
     cout<<count<<endl;
     break;
   }
 }
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    ll n, p;
    cin >> n >> p;

    if (n == 1) {
        cout << p << endl;
        return 0;
    }

    map<ll, ll> m;
    ll d = 2;
    ll l = p;
    while (p > 1 && l >= d * d) {
        if (p % d == 0) {
            m[d]++;
            p /= d;
        } else {
            if (d == 2) {
                d++;
            } else {
                d += 2;
            }
        }
    }

    ll ans = 1;
    for (const auto q : m) {
        if (q.second >= n) {
            ans *= (ll)pow(q.first, q.second / n);
        }
    }

    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC148A()
{
	int A, B;
	cin >> A;
	cin >> B;
	if (A != 1 && B != 1)
	{
		cout << 1 << endl;
	}
	else if (A != 2 && B != 2)
	{
		cout << 2 << endl;
	}
	else
	{
		cout << 3 << endl;
	}
}
int main()
{
	ABC148A();
	return 0;
}


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

int main() {
    int n, m;
    cin>>n>>m;
 
    vector<vector<int>> s(m);
    for(int i=0; i<m;i++) {
       int k;
       cin>>k;
       s[i].resize(k);
      for (int j=0; j<k;j++) {
            cin>>s[i][j];
            s[i][j]-=1;
        }
    }
 
    vector<int>p(m);
    for (int i=0;i<m;i++) cin >> p[i];
 
    long long sum = 0;
    for (int x=0; x<1<<n;x++) {int num = 0;
     for(int i=0;i<m;i++) {
     int st = 0;
      for (int j=0;j<s[i].size(); j++) {
           if(x >> s[i][j]&1) 
               st++;
        }
       if (st%2==p[i]) {
                num++;
            }
        }
        if (num==m)sum++;
    }
 
    cout<<sum<<endl;
 
}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
	int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> sum(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + a[i];
    ll x = 0;
    for (int k = 50; k >= 0; k--) {
        ll y = x ^ (1LL<<k);
        int cnt = 0;
        for (int l = 0; l <= N; l++)
            for (int r = l + 1; r <= N; r++) {
                ll d = sum[r] - sum[l];
                if ((d & y) == y) cnt++;
            }
        if (cnt >= K) x = y;
    }
    cout << x << endl;
}


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

const int MAXN = 2e3 + 10;

int n, sumE, R;
int a[MAXN], min[MAXN], max[MAXN], rsz[MAXN], head[MAXN];
struct Edge { int link, to; } e[MAXN << 1];
inline void add(int u, int v) { e[++sumE] = (Edge) { v, head[u] }, head[u] = sumE; }

void dfs(int u, int fa) {
	rsz[u] = a[u], max[u] = 0, min[u] = 0;
	for (int i = head[u]; i; i = e[i].to) {
		int v = e[i].link;
		if (v == fa) continue;
		dfs(v, u), rsz[u] += rsz[v];
		if (min[u] > max[v] + rsz[v]) min[u] -= max[v] + rsz[v];
		else if (max[u] < min[v] + rsz[v]) min[u] = min[v] + rsz[v] - max[u];
		else min[u] = (max[u] + max[v] + rsz[v]) & 1;
		max[u] += max[v] + rsz[v];
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		char ch = getchar();
		while (ch != '0' && ch != '1') ch = getchar();
		a[i] = ch & 15;
	}
	for (int i = 1, u, v; i < n; ++i) scanf("%d%d", &u, &v), add(u, v), add(v, u);
	int ans = 233333333;
	for (int rt = 1; rt <= n; ++rt) {R=rt;
		dfs(rt, 0);
		if (!min[rt]) ans = std::min(ans, max[rt] >> 1);
	}
	if (ans == 233333333) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3916
# -*- coding: utf-8 -*-

import math

# 階乗しないで求める版

x = int(input())

# 素数判定用関数
def is_prime_2(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False
    # 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True

# xまでの間にある素数を列挙
sosu_list = []
for i in range(x+1):
    if is_prime_2(i):
        sosu_list.append(i)

# 素数のカウントは階乗前の値から個別に取って合算でも問題ない
sosu_cnt = {}
for i in range(1, x+1):
    for sosu in sosu_list:
        while i % sosu == 0:
            if sosu in sosu_cnt:
                sosu_cnt[sosu] += 1
            else:
                sosu_cnt[sosu] = 1
            i //= sosu

# 素数カウントを使って、約数の個数を求める
ans = 1
for key, value in sosu_cnt.items():
    sosu_cnt[key] += 1
    ans = (ans * sosu_cnt[key]) % (10 ** 9 + 7)
print(ans)

Measured memory_bytes: 3064
#
# Setting Go Stones
#
while (n=gets.to_i)!=0

  stone=[]
  count=[]

  stone<<gets.chomp
  count<<1

  2.upto(n) do |i|
    s=gets.chomp
    if i.even?
      if stone[-1]!=s
        stone[-1]=s
        count[-1]+=1
        (stone.size-2).downto(0) do |j|
          if stone[j]!=s
            stone[j]=s
            count[j]+=count[j+1]
            stone.pop
            count.pop
          else
            break
          end
        end
      else
        count[-1]+=1
      end
    else
      if stone[-1]==s
        count[-1]+=1
      else
        stone<<s
        count<<1
      end
    end
  end

  sum=0
  stone.each_with_index do |s, i|
    sum+=count[i] if s=='0'
  end
  puts sum

end

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;cin >> n;
	ll ans = 10000000000000000;
	for(ll i = 1; i * i <= n; i++){
		if(n % i == 0){
			ans = min(ans, i + n / i);
		}
	}
	cout << ans - 2 << endl;
}

Measured memory_bytes: 384
n = int(input())
a = [int(x) for x in input().split()]
a_div_2 = [1 if a[i] % 2 == 0 and a[i] % 4 != 0 else 0 for i in range(n)]
a_div_4 = [1 if a[i] % 4 == 0 else 0 for i in range(n)]
if a_div_2.count(1) // 2 + a_div_4.count(1) >= n // 2: print("Yes")
else: print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;//聞いた人の数
	int M; cin >> M;//候補となる食べ物の数
	bool food[M];
	for (int i = 0; i < M; i++) {
		food[i] = false;
	}
	int s; cin >> s;
	for (int i = 0; i < s; i++) {
		int  a; cin >> a;
		a--;
		food[a] = true;
	}
	for (int i = 0; i < N-1; i++) {
		int K; cin >> K;
		int ls[K];
		for (int j = 0; j < K; j++) {
			int b; cin >> b;
			b--;//添え字合わせ
			ls[j]=b;
		}
		for (int j = 0; j <M; j++) {
			bool flg = false;
			for (int c = 0; c < K; c++) {
				if (j == ls[c]) flg =true;
			}
			if (!flg) {
				food[j] = false;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <M; i++) {
		if (food[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = tx - sx, y = ty - sy;
	rep(i, x) cout << 'R';
	rep(i, y) cout << 'U';
	rep(i, x) cout << 'L';
	rep(i, y + 1) cout << 'D';
	rep(i, x + 1) cout << 'R';
	rep(i, y + 1) cout << 'U';
	cout << "LU";
	rep(i, x + 1) cout << 'L';
	rep(i, y + 1) cout << 'D';
	cout << "R\n";
}

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    string s,t;
    cin>>s>>t;
    ll ans =0;
    rep(i,s.length()){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    fin(ans);

}




Measured memory_bytes: 4160
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(void)
{
	char r[10];
	char g[10];
	char b[10];
	char s[20];
	cin >> r >> g >> b;
	sprintf (s,"%s%s%s",r,g,b);
	int i = atoi(s);
	if (i % 4 == 0)
	{
		cout << "YES";
	}
	else
	{
		cout<<"NO";
	}

	return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector< tuple< int64, int64, int64 > > s;
  for(int i = 0; i < N; i++) {
    int64 x, y, z;
    cin >> x >> y >> z;
    s.emplace_back(x, y, z);
  }
  int64 ret = 0;
  for(int i = 0; i < (1 << 3); i++) {
    sort(begin(s), end(s), [&](tuple< int64, int64, int64 > a, tuple< int64, int64, int64 > b) {
      int64 aa, bb, cc;
      int64 dd, ee, ff;
      tie(aa, bb, cc) = a;
      tie(dd, ee, ff) = b;
      if((i >> 0) & 1) {
        aa *= -1;
        dd *= -1;
      }
      if((i >> 1) & 1) {
        bb *= -1;
        ee *= -1;
      }
      if((i >> 2) & 1) {
        cc *= -1;
        ff *= -1;
      }
      return aa + bb + cc > dd + ee + ff;
    });

    int64 dd = 0, ee = 0, ff = 0;
    for(int j = 0; j < M; j++) {
      int64 aa, bb, cc;
      tie(aa, bb, cc) = s[j];
      if((i >> 0) & 1) {
        aa *= -1;
      }
      if((i >> 1) & 1) {
        bb *= -1;
      }
      if((i >> 2) & 1) {
        cc *= -1;
      }
      dd += aa;
      ee += bb;
      ff += cc;
    }
    ret = max(ret, dd + ee + ff);
  }
  cout << ret << endl;

}


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

int main(){
  long n;
  cin >> n;
  int odd = n%2;
  long a[n];
  rep(i,n)cin >> a[i];
  long dp[n+1][n+1];
  rep(i,n+1)dp[i][i] = 0;
  for(int len=1;len<=n;len++){
    for(int i=0;i+len<=n;i++){
      int j = len+i;
      if(len%2 == odd){
        dp[i][j] = max(dp[i][j-1]+a[j-1],dp[i+1][j]+a[i]);
      }else{
        dp[i][j] = min(dp[i][j-1]-a[j-1],dp[i+1][j]-a[i]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 49764
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c&& c <= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int x;
	int i = 1;
	
	do{
		scanf("%d", &x);
		if(x == 0){
			break;
		}else{
			printf("Case %d: %d\n", i, x);
			i++;
		}
	}while(x != 0);

	return(0);
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

pair<int, int> getPrePost(int num) {
    pair<int, int> ans;

    ans.second = num % 10;

    while (num >= 10)
        num /= 10;

    ans.first = num;

    return ans;
}

int solve()
{
    int n;

    std::cin >> n;
    unordered_map<int, unordered_map<int, int>> mp;
    int res = 0;

    for (int i = 1; i <= n; ++i) {
        auto pp = getPrePost(i);
        mp[pp.first][pp.second]++;
    }
    
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
            res += it2->second * mp[it2->first][it->first];
        }
    }

    std::cout << res << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

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

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define all(c) (c).begin(), (c).end()
#define speed ios::sync_with_stdio(0); cin.tie(0);

int const N = 1000 + 2, MOD = 1e9 + 7;
char g[N][N];
ll dp[N][N];

int main(){
    speed
    int n, m;
    cin >> n >> m;
    f(i, 0, n)f(j, 0, m)cin >> g[i][j];
    f(i, 0, n){
    	f(j, 0, m){
    		if (i == 0){
    			if (g[i][j] == '#' || dp[i][j - 1] == -1)dp[i][j] = -1;
    			else dp[i][j] = 1;
    		} else if (j == 0){
    			if (g[i][j] == '#' || dp[i - 1][j] == -1)dp[i][j] = -1;
    			else dp[i][j] = 1;
    		}
    		else if (g[i][j] == '#')dp[i][j] = -1;
    		else {
    			if (dp[i - 1][j] == -1 && dp[i][j - 1])dp[i][j] = dp[i][j - 1];
    			else if (dp[i - 1][j] && dp[i][j - 1] == -1)dp[i][j] = dp[i - 1][j];
    			else if (dp[i - 1][j] && dp[i][j - 1])dp[i][j] = (dp[i][j - 1] % MOD + dp[i - 1][j] % MOD) % MOD;
    			else dp[i][j] = -1;
    		}
    	}
    }
    cout << (dp[n - 1][m - 1] == -1 ? 0 : dp[n - 1][m - 1]) << endl;

}

Measured memory_bytes: 9088
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		char[] s = sc.next().toCharArray();
		ArrayList<Character> nox = new ArrayList<>();
		for(int i=0; i<s.length; i++) {
			if(s[i] != 'x') nox.add(s[i]);
		}
		int i = 0;
		int j = nox.size()-1;
		while(i < j) {
			if(nox.get(i) != nox.get(j)) {
				System.out.println(-1);
				return;
			}
			i++;
			j--;
		}
		i = 0;
		j = s.length-1;
		int ans = 0;
		while(i < j) {
			if(s[i] == 'x' && s[j] == 'x') {
				i++;
				j--;
			} else if(s[i] == 'x') {
				ans++;
				i++;
			} else if(s[j] == 'x') {
				ans++;
				j--;
			} else {
				i++;
				j--;
			}
		}
		System.out.println(ans);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 23636
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif


const int mxn=1e5+1;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            unordered_map<string,bool> vis;
    int n,i;
    cin>>n;
    string s;
    
    cin>>s;
    char h=s[s.size()-1];
    vis[s]=1;
    n--;
    while(n--)
    {
        cin>>s;
        if(vis[s]||s[0]!=h)
        {
        //	deb(s);
            cout<<"No";
            return 0;
        }
        vis[s]=1;
        h=s[s.size()-1];
    }
    cout<<"Yes";

    }
  return 0;
  }



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

priority_queue<long long> pq;
long long sum = 0;
int N, M;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        long long x; cin >> x;
        sum += x;
        pq.push(x);
    }
    for (int i = 0; i < M; ++i) {
        long long x = pq.top();
        pq.pop(); pq.push(x / 2); sum -= (x - x / 2);
    }
    cout << sum << '\n';
    return 0;
}

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

using namespace std;

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

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

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

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

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

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

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

using namespace std;

using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;

    cout << ((N - 1) % (K - 1) == 0 ? (N - 1) / (K - 1) : (N - 1) / (K - 1) + 1) << endl;

    return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> Z(N);
  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i] >> Z[i];
  }
  ll score = 0;
  for(int bit=0;bit<(1<<3);bit++){
    ll a=1,b=1,c=1;
    vector<ll> S(N);
    if(bit&(1<<0)){
      a = -1;
    }
    if(bit&(1<<1)){
      b = -1;
    }
    if(bit&(1<<2)){
      c = -1;
    }
    //cout << bit << " " << a << " " << b << " " << c << endl;
    for(int i=0;i<N;i++){
      S[i] = a*X[i] + b*Y[i] + c*Z[i];
    }
    sort(S.begin(),S.end());
    reverse(S.begin(),S.end());
    ll sum = 0;
    for(int i=0;i<M;i++){
      sum += S[i];
    }
    score = max(score,sum);
  }
  cout << score << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
  int n,a,flag=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    if(a%2==1){
      printf("first\n");
      return 0;
    }
  }
  printf("second\n");
  return 0;
  
}
  

Measured memory_bytes: 128
# APC001B - Two Arrays
def main():
    N, *AB = map(int, open(0).read().split())
    A, B = AB[:N], AB[N:]
    cnt = 0
    for a, b in zip(A, B):
        if a > b:
            cnt += a - b
        else:
            cnt -= (b - a) // 2
    print("Yes" if cnt <= 0 else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 5236
def resolve():
    n, a, b = map(int, input().split())
    s = input()
    ans = 0
    foreign = 0
    for c in s:
        if c == "a":
            if ans < a + b:
                ans += 1
                print("Yes")
            else:
                print("No")
        elif c == "b":
            if ans < a + b and foreign < b:
                ans += 1
                foreign += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4016
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	if (a+b>c+d) cout<<"Left";
	    else if (a+b<c+d) cout<<"Right";
	        else cout<<"Balanced";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
std::string s;
int main(){
    std::ios::sync_with_stdio(false);
    std::cin>>s;
    for(int i=0,j=s.size();i<j;++i)
        if(s[i]=='C')
            for(int k=i;k<=j;++k)
                if(s[k]=='F'){
                    std::cout<<"Yes\n";
                    return 0;
                }
    std::cout<<"No\n";
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

#define MAX_N 1000000

int
main(int argc, char **argv)
{
	int val[MAX_N + 1];
	int n, q;
	int a, v;
	int ai, vi;
	int i;

	scanf("%d %d", &n, &q);
	for (i = 1; i <= n; ++i)
		val[i] = 0;

	a = 1, v = 0;
	while (q--)
	{
		scanf("%d %d", &ai, &vi);
		val[ai] += vi;
		if (vi > 0)
		{
			if (val[ai] > v || (val[ai] == v && ai < a))
			{
				a = ai;
				v = val[ai];
			}
		}
		else
		{
			if (ai == a)
			{
				a = 1, v = 0;
				for (i = n; i >= 1; --i)
				{
					if (val[i] >= v)
					{
						a = i;
						v = val[i];
					}
				}
			}
		}

		printf("%d %d\n", a, v);
	}

	return 0;
}

Measured memory_bytes: 4504
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Array.(sort compare ab_s; fold_left (fun r (a, b) -> if r + b >= k then (Printf.printf "%d\n" a; exit 0); r + b) 0 ab_s)

Measured memory_bytes: 6784
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string buffer;

    cin >> buffer;
    const char* cbuff = buffer.c_str();

    char zero = '0';

    int sum = 0;
    for (size_t i = 0; i < buffer.size(); ++i)
    {
        int n = static_cast<int>(cbuff[i] - zero);
        sum += n;
    }

    if (sum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 3724
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] number = line.split(" ");
        int x = Integer.parseInt(number[0]);
        int y = Integer.parseInt(number[1]);
        int[] groupB = new int[4];
        groupB[0] = 4;
        groupB[1] = 6;
        groupB[2] = 9;
        groupB[3] = 11;
        boolean yorn = false;
        boolean firstif = true;
        boolean firstelse = true;
        
        if((x == 2) || (y == 2)) {
            yorn = false;
        } else {
            for(int i = 0; i < 4; i++) {
                if((groupB[i] == x) && firstif) {
                    yorn = false;
                    for(int j = i + 1; j < 4; j++) {
                        if(groupB[j] == y) {
                            yorn = yorn || true;
                        } else {
                            yorn = yorn || false;
                        }
                    }
                    firstif = false;
                } else if(firstelse && firstif) {
                    yorn = true;
                    for(int j = i + 1; j < 4; j++) {
                        if(groupB[j] == y) {
                            yorn = yorn && false;
                            firstelse = false;
                        } else {
                            yorn = yorn && true;
                        }
                    }
                }
            }
        }
        if(yorn) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int a, b, h;
    cin >> a >> b >> h;
cout << (a + b) * h / 2 << endl;
    

    return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}
void print(const std::vector<int>& v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> p(N);
    vector<int> match(N);
    rep(i, N) {
        cin >> p[i];
        if (p[i] == i + 1) match[i] = 1;
    }
    vector<int> cnt;
    int tmp = 0;
    rep(i, N - 1) {
        if (match[i]) {
            if (match[i + 1]) {
                tmp++;
            } else {
                tmp++;
                cnt.push_back(tmp);
                tmp = 0;
            }
        }
    }
    if(match[N-1]) tmp++;
    cnt.push_back(tmp);
    int ans = 0;
    for (auto& i : cnt) {
        if (i == 1) {
            ans++;
        } else if(i > 0) {
            // cout << i << endl;
            if (i & 1) ans += (i+1)/2;
            else ans += i/2;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
def shuffle (base, amount):
  s1 = base[:amount]
  s2 = base[amount:]
  return s2 + s1

while True:
  base = input()
  if base == '-':
    break
  new = ''
  s = int(input())

  for i in range(0, s):
    i = int(input())
    new = shuffle(base, i)
    base = new
  print(new)



Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
  int n;
  scanf("%d", &n);
  int cnt = 0;
  int i;
  for(i = 0; i < n; i++){
    int tmp;
    scanf("%d", &tmp);
    int P = 1;
    if(!tmp | tmp == 1)
      P = 0;
    else{
      int j;
      for(j = 2; j <= sqrt(tmp); j++)
	if(!(tmp % j))
	  P = 0;
    }
    if(P){
      cnt++;
//      printf("%d\n", tmp);
    }
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
  int N;cin>>N;
  vector<int> X(N),Y(N);
  double d_sum=0;
  REP(i,0,N)cin>>X[i]>>Y[i];
  vector<int> nums(N);
  iota(nums.begin(), nums.end(), 0);

  do{
      double d=0.0;
      REP(i,1,N){
        d=d+1.*sqrt(pow((X[nums[i-1]]-X[nums[i]]),2)+1.*pow((Y[nums[i-1]]-Y[nums[i]]),2));
      }
      d_sum+=d;
  } while (next_permutation(nums.begin(), nums.end()));

  print(setprecision(16)<<d_sum/(facctorialMethod(N)))
}


Measured memory_bytes: 256