akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 5e5 + 10;

void solve(){
     int n;cin >> n;
     vector<int>a(n);
     int maxi = 0;
     int sum = 0;
     for(int i = 0;i<n;i++){
        cin >> a[i];
        sum += a[i];
        maxi = max(maxi,a[i]);
     }
     cout << sum - maxi/2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3640
class Bar
  def initialize p, q, r, b
    @p = p
    @q = q
    @r = r
    @b = b
    @ref_count = 0
    @left = nil
    @right = nil
  end

  def w
    l = @left.w * @p
    r = @right.w * @q
    lcm = (l * r) / euclid(l, r)
    lcm / @p + lcm / @q
  end

  attr_accessor :left, :right, :ref_count
  attr_reader :p, :q, :r, :b
end

class Weight
  def initialize
    @w = 1
  end
  attr_reader :w
end

def main
  loop do
    n = gets.chomp.to_i
    break if n == 0
    bars = Array.new(n+1, nil)
    (1..n).each do |i|
      p,q,r,b = gets.chomp.split.map(&:to_i)
      bars[i] = Bar.new(p, q, r, b)
    end

    weight = Weight.new
    (1..n).each do |i|
      if bars[i].r == 0
        bars[i].left = weight
      else
        bars[i].left = bars[bars[i].r]
        bars[i].left.ref_count += 1
      end

      if bars[i].b == 0
        bars[i].right = weight
      else
        bars[i].right = bars[bars[i].b]
        bars[i].right.ref_count += 1
      end
    end

    root = nil
    (1..n).each do |i|
      if bars[i].ref_count == 0
        root = bars[i]
        break
      end
    end

    puts root.w
  end
end

def euclid a, b
  m = (a > b ? a : b)
  n = (a <= b ? a : b)
  loop do
    r = m % n
    m = n
    n = r
    break if n == 0
  end
  m
end

main

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

const int MAX = 1010;
const long long INF = 1LL << 60;

long long dp[MAX][MAX] = {INF};
string s1, s2;

int main() {
  cin >> s1 >> s2;

  int s1_len = (int)s1.length();
  int s2_len = (int)s2.length();

  for (int i = 0; i <= s1_len; ++i) dp[i][0] = i;
  for (int j = 0; j <= s2_len; ++j) dp[0][j] = j;

  for (int i = 0; i < s1_len; ++i) {
    for (int j = 0; j < s2_len; ++j) {
      long long ins_del = min((dp[i + 1][j] + 1), (dp[i][j + 1] + 1));

      long long rep = 0;
      if (s1[i] == s2[j]) {
        rep = dp[i][j];
      } else {
        rep = dp[i][j] + 1;
      }

      dp[i + 1][j + 1] = min(ins_del, rep);
    }
  }

  cout << dp[s1_len][s2_len] << endl;
  return 0;
}



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

const int N = 5e5 + 10;
char str[N];

int main() {
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  // cout << n << endl;
  vector<int> a(n + 10);
  for (int i = 1; i <= n; i++) {
    if (str[i] == '<') a[i] = a[i - 1] + 1;
  }
  for (int i = n; i >= 1; i--) {
    if (str[i] == '>') a[i - 1] = max(a[i - 1], a[i] + 1);
  }
  long long sum = 0;
  for (int i = 0; i <= n; i++) {
    sum += a[i];
    // cout << a[i] << ' ';
  }
  // cout << endl;
  cout << sum << endl;
  return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	ll n;cin >> n;
	vector<ll> v(n);
	
	REP(i,n)cin >> v[i];
	
	ll ans = 0;
	
	REP(i,n){
		ll tmp = v[i] - 10*n;
		ll pla = max(0LL,tmp / (n + 1));
		ans += pla * (n+1);
		v[i] -= pla * (n + 1);
	}
	DBG(SHOW1d(v,n);)
	while(1){
		sort(ALL(v),greater<ll>());
		if(v[0] < n)break;
		v[0] -= n+1;
		REP(i,n)v[i]++;
		ans++;
	}
	
	cout << ans << endl;
		
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
  int n; cin >> n;
  string s1, s2; cin >> s1 >> s2;
  int pos = 0;
  mint ans = 1;
  bool flag; // if true vertical, false horizontal
  while(pos < n){
    if(pos == 0){
      if(s1[pos] == s2[pos]){
        ans *= 3;
        pos++;
        flag = true;
      }else{
        ans *= 6;
        pos += 2;
        flag = false;
      }
    }else{
      if(s1[pos] == s2[pos]){
        pos++;
        if(flag){
          ans *= 2;
        }else{
          flag = true;
        }
      }else{
        pos += 2;
        if(flag){
          ans *= 2;
          flag = false;
        }else{
          ans *= 3;
        }
      }
    }
  }
  cout << ans << endl;
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define endl '\n'
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<'\n';
#define mxn 100005
using namespace std;

int main()
{
    FLASH
    int n;
    cin >> n;
    n = n % 10;
    if(n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon";
    else if(n == 3)
        cout << "bon";
    else
        cout << "hon";
    return 0;
}


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

long long int law=998244353;

long long int pow(long long int b,long long int p){
    long long int ret=1;
    for(long long int i=0;i<p;i++){
        ret=(ret*b)%law;
    }
    return ret;
}

int main(){
    long long int N;
    long long int Cd[100000]={0,};
    cin>>N;
    long long int maxd=0;
    for(int i=0;i<N;i++){
        long long int d;
        cin>>d;
        if(i==0&&d!=0){
            cout<<0<<endl;
            exit(0);
        }
        if(i!=0){

            if(d==0){
                cout<<0<<endl;
                exit(0);

            }


            Cd[d-1]++;

            if(d>maxd){
                maxd=d;
            }
        }

    }

    long long int total=1;
    
    for(int i=0;i<maxd;i++){
        total=(total*pow(Cd[i],Cd[i+1]))%law;
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int base = 0;
		int n = sc.nextInt();
		int[] b = new int[n];
		for (int i = 0; i < n; ++i) {
			b[i] = sc.nextInt();
			if (b[i] == 0)
				++base;
		}
		int Q = sc.nextInt();
		int[][] q = new int[Q][2];
		for (int i = 0; i < Q; ++i) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		Arrays.sort(q, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});
		RMQ rmq = new RMQ(n + 1);
		rmq.set(0, 0);
		int p = 0;
		for (int i = 0; i < Q; ++i) {
			while (q[i][0] - p > 1) {
				int c = b[p] == 1 ? 1 : -1;
				rmq.set(p + 1, Math.min(c + rmq.query(p), rmq.query(p + 1)));
				++p;
			}
			rmq.set(q[i][1], rmq.query(p, q[i][1] + 1));
		}
		while (n - p > 0) {
			int c = b[p] == 1 ? 1 : -1;
			rmq.set(p + 1, Math.min(c + rmq.query(p), rmq.query(p + 1)));
			++p;
		}
		System.out.println(base + rmq.query(n));
	}

	class RMQ {
		int n;
		int[] v;

		public RMQ(int n_) {
			n = 1;
			while (n < n_)
				n *= 2;
			v = new int[2 * n];
			Arrays.fill(v, Integer.MAX_VALUE / 3);
		}

		void add(int k, int val) {
			k += n;
			v[k] += val;
			while (k > 1) {
				k = k / 2;
				v[k] = Math.min(v[2 * k], v[2 * k + 1]);
			}
		}

		void set(int k, int val) {
			k += n;
			v[k] = val;
			while (k > 1) {
				k = k / 2;
				v[k] = Math.min(v[2 * k], v[2 * k + 1]);
			}
		}

		int query(int a) {
			return v[a + n];
		}

		int query(int a, int b) {
			a += n;
			b += n;
			int ret = Integer.MAX_VALUE / 3;
			while (a < b) {
				if (a % 2 == 1) {
					ret = Math.min(ret, v[a++]);
				}
				if (b % 2 == 1) {
					ret = Math.min(ret, v[--b]);
				}
				a /= 2;
				b /= 2;
			}
			return ret;
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 164132
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int ans = s.size();
    rep(i, 0, s.size() - 1){
        if(s[i] != s[i + 1]){
            chmin(ans, max(i + 1, (int)s.size() - 1 - i));
        }
    }
    cout << ans << endl;
}

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

typedef enum { left, right } bool;


int trace(int N, int Q, char *s, char *s_t, bool *b_d, int origin, int static_origin, int dest, int l, int r)
{
    static int i;
    static int index;
    
    
    if(l > r)
    {
        return static_origin;
    }
    else
    {
        index = origin;
        
        
        for(i=0; i<Q && index >= 0 && index < N; i++)
        {
            if(s_t[i] == s[index])
            {
                if(b_d[i] == left)
                {
                    index--;
                }
                else
                {
                    index++;
                }
            }
        }
        
        if(index == dest)
        {
            static_origin = origin;
        }
        
        if((dest == N && index < N) || (dest == -1 && index < 0))
        {
            return trace(N, Q, s, s_t, b_d, origin+(r-origin+1)/2, static_origin, dest, origin+1, r);
        }
        else
        {
            return trace(N, Q, s, s_t, b_d, l+(origin-l)/2, static_origin, dest, l, origin-1);
        }
    }
}

int main(void)
{
    int N, Q;
    char *s, *s_t;
    bool *b_d;
    int i;
    char t, d, c;
    int sum;
    
    
    scanf("%d%c%d", &N, &c, &Q);
    
    s = (char*)malloc(sizeof(char)*(N+1));
    
    s_t = (char*)malloc(sizeof(char)*Q);
    b_d = (bool*)malloc(sizeof(bool)*Q);
    
    
    sum = N;
    
    
    scanf("%s\n", s);
    
    
    for(i=0; i<Q; i++)
    {
        scanf("%c%c%c%c", &t, &c, &d, &c);
        
        
        s_t[i] = t;
        
        if(d == 'L')
        {
            b_d[i] = left;
        }
        else
        {
            b_d[i] = right;
        }
    }
    
    
    sum -= N-trace(N, Q, s, s_t, b_d, N/2, N, N, 0, N-1);
    sum -= trace(N, Q, s, s_t, b_d, N/2, -1, -1, 0, N-1)+1;
    
    printf("%d\n", sum);
    
    
    free(s);
    free(s_t);
    free(b_d);
    
    
    //system("pause");
    
    
    return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];


  h[n-1]++;
  for(ll i = n-2; 0 <= i; i--){
    if(h[i] < h[i+1]) h[i]++;
  }

  
  rep(i, n-1){
    if(h[i] <= h[i+1]) continue;
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
#include <cmath>
using namespace std;

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


int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}


int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    if( 1 >= N || N%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    
    string T = S.substr(0,N/2);
    if( S == T+T ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
m=sum(A)
ans=0
for i in range(1,int(m**0.5)+1):
  if m % i != 0:
    continue 
  for j in [i,m//i]:
    stg = []
    for a in A:
      stg.append(a%j)
    stg.sort()
    sm,idx=0,0
    flag=False
    while sm+stg[idx]<=K:
      sm+=stg[idx]
      idx+=1
      if idx>=N:
        flag=True
        break
    if flag or sum([j-x for x in stg[idx:]]) <= K:
      ans=max(ans,j)
  
print(ans)
  
  

Measured memory_bytes: 74412
#include <cstdio>
#include <algorithm>
#include <cstring>

int main()
{
	char s[100];
	scanf("%s", s);
	int n = strlen(s);

	bool a = true;
	for (int i = 0; i < n; ++i)
	{
		a &= s[i] == s[n - 1 - i];
	}
	bool b = true;
	bool c = true;
	for (int i = 0; i < (n - 1) / 2; ++i)
	{
		b &= s[i] == s[(n - 1) / 2 - 1 - i];
		c &= s[i + (n + 3) / 2 - 1] == s[n - 1 - i];
	}
	puts(a && b && c ? "Yes" : "No");
	return 0;
}


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

int main(){
    int n; cin>>n;
    vector<string>d(n);
    map<string,int>mp;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        sort(x.begin(),x.end());
        mp[x]++;
        }
    long long ans=0;
    for(auto& p : mp){
        int s=p.second;
        ans+=(long long)s*(s-1)/2;
        }
        cout<<ans<<endl;
    }



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

int main() {
	int n, x;
	
	while(1) {
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		
		int ans = 0;
		
		for(int i = 1; i <= n; ++i) {
			for(int j = i + 1; j <= n; ++j) {
				for(int k = j + 1; k <= n; ++k) {
					if(i + j + k == x) {
						ans++;
					}
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main()	{
  long long x;
  cin >> x;
  long long t = 0;
  long long sum = 0;
  for (long long i = 0; i < 100000000; i++)	{
    sum += i;
    if (sum >= x)	{
      t = i;
      break;
    }
  }
  cout << t << endl;
  return 0;
}


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

int main()
{
  char S[1002];
  cin >> S;
  
  char ans;
  
  for(int i = 0; i < 1000; i++)
  {
    if(S[i+1] == '\0')
    {
      if(S[i] == 's')
      {
         S[i+1] = 'e';
         S[i+2] = 's';  
         S[i+3] = '\0';
         break;
      }
      else
      {
        S[i+1] = 's';
        S[i+2] = '\0';
        break;
      }
    }
  }
  
  printf("%s", S);
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int N;
string s;
int a,b,c;
int main(){
  cin >> a >> b >> c;
  int M=1000000;
  M=min(M,a+b);
  M=min(M,a+c);
  M=min(M,b+c);
  cout << M << endl;
  return 0;
}


Measured memory_bytes: 256
def solve():
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    d = 0
    count = 1
    for i in range(1, n+1):
        d = d + l[i-1]
        if d > x:
            print(count)
            exit()
        count += 1
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
use proconio::input;
use maplit::hashmap;

#[proconio::fastout]
fn main() {
    input! {
        N: usize,
        M: i128
    }
    const MOD: usize = 1000_000_000 + 7;

    let mut prime_divisors = hashmap!();
    let mut div = 2;
    let mut m = M;
    while div * div <= m {
        let count = prime_divisors.entry(div).or_insert(0);
        while m % div == 0 {
            *count += 1;
            m /= div;
        }
        div += 1;
    }
    if m != 1 {
        *(prime_divisors.entry(m).or_insert(0)) += 1;
    }

    let num_of_divisors: usize = prime_divisors.values().sum();
    let x = N - 1 + num_of_divisors;
    let mut inverse = vec![0, 1];
    let mut inverted_factorials = vec![1, 1];
    let mut factorials = vec![1, 1];
    for f in 2..=x {
        factorials.push(factorials.last().unwrap() * f % MOD);
        inverse.push(MOD - inverse[MOD % f] * (MOD / f) % MOD);
        inverted_factorials.push(inverted_factorials.last().unwrap() * inverse[f] % MOD);
    }

    let inverted_factorials: Vec<i128> = inverted_factorials.iter().map(|&x| x as i128).collect();
    let factorials: Vec<i128> = factorials.iter().map(|&x| x as i128).collect();
    let result = {
        let mut result = 1i128;
        for &x in prime_divisors.values() {
            result *= factorials[N - 1 + x];
            result %= MOD as i128;
            result *= inverted_factorials[N - 1];
            result %= MOD as i128;
            result *= inverted_factorials[x];
            result %= MOD as i128;
        }
        result
    };

    println!("{}", result)
}


Measured memory_bytes: 7548
import math
a,b,h,m=map(int,input().split())
ha=h * 30 + (30 * (m / 60))
ma=360 * (m / 60)
angle=max(ha,ma)-min(ha,ma)
if angle>=180:
  angle = 360-angle
if angle==90:
  print(math.sqrt(a*a+b*b))
elif angle==0 or angle==180:
  if angle==0:
    print(abs(a-b))
  else:
    print(a+b)
else:
  angle=angle/180*math.pi
  #print(ha,ma,angle,math.cos(angle))
  ans=math.sqrt(a*a+b*b-2*a*b*math.cos(angle))
  print(ans)


Measured memory_bytes: 9468
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
b=lmp()
sa=sum(a)
sb=sum(b)
l=[]
if sb>sa:
    print(-1)
    exit()
for i in range(n):
    l.append(-b[i]+a[i])
l=sorted(l,reverse=True)

r=[0]
s=0
ans=0
m=0
for i in range(n):
    if l[i]>0:
        s+=l[i]
        r.append(s)
    elif l[i]<0:
        ans+=1
        m+=l[i]
for i in range(len(r)):
    if m+r[i]>=0:
        print(ans+i)
        exit()

Measured memory_bytes: 21940
#include <vector>
#include <functional>

template<class T, class F>
struct dual_segment_tree {
	using value_type = T;
	using size_type = std::size_t;
private : 
	size_type n;
	const F op;
	const value_type identity;
	std::vector<value_type> node;

	void propagate (size_type i) noexcept {
		if (node[i] == identity) return;
		node[i << 1 | 0] = op(node[i << 1 | 0], node[i]);
		node[i << 1 | 1] = op(node[i << 1 | 1], node[i]);
		node[i] = identity;
	}

	void topdown_update (size_type i) noexcept {
		if (i == 0) return;
		const size_type ctz = __builtin_ctz(i);
		for (size_type h = 31 - __builtin_clz(i); h != ctz; h--) {
			propagate(i >> h);
		}
	}

public : 
	explicit constexpr dual_segment_tree (const value_type &identity, const F &op) noexcept : identity(identity), op(op) { }

	void assign (size_type _size) noexcept {
		n = _size;
		node.assign(n << 1, identity);
	}

	void assign (size_type _size, const value_type &value) noexcept {
		assign(_size);
		for (size_type i = n; i < (n << 1); i++) {
			node[i] = value;
		}
	}

	template<class InputIterator>
	void assign (InputIterator first, InputIterator last) noexcept {
		assign(last - first);
		for (size_type i = n; first != last; i++, first++) {
			node[i] = (*first);
		}
	}

	void update (size_type first, size_type last, const value_type &value) noexcept {
		topdown_update(first + n); topdown_update(last + n);
		for (first += n, last += n; first != last; first >>= 1, last >>= 1) {
			if (first & 1) { node[first] = op(node[first], value); first++; }
			if (last & 1) { last--; node[last] = op(node[last], value); }
		}
	}

	value_type fold (size_type i) noexcept {
		value_type value = node[(i += n)];
		for (i >>= 1; i > 0; i >>= 1) {
			value = op(value, node[i]);
		}
		return value;
	}

	value_type operator[] (size_type i) noexcept {
		return fold(i);
	}

	value_type at (size_type i) noexcept {
		return fold(i);
	}

};

template<class T, class F>
dual_segment_tree<T, F> make_segtree(const T &identity, const F &op) {
	return dual_segment_tree<T, F>(identity, op);
}

template<class InputIterator, class T, class F>
dual_segment_tree<T, F> make_dualsegtree (InputIterator first, InputIterator last, const T &identity, const F &op) {
	dual_segment_tree<T, F> segtree(identity, op);
	segtree.assign(first, last);
	return segtree;
}


#include <iostream>
#include <vector>
#include <cstddef>

using std::size_t;

constexpr int INF = (1 << 30);

int main() {
	int n, q;
	std::cin >> n >> q;
	
	auto min = [](const int &lhs, const int &rhs) { return (lhs < rhs ? lhs : rhs); };
	auto seg1 = make_segtree(INF, min);
	auto seg2 = make_segtree(INF, min);
	seg1.assign(size_t(n - 2), n - 2);
	seg2.assign(size_t(n - 2), n - 2);

	long long ans = 1LL * (n - 2) * (n - 2);
	while (q--) {
		int type;
		size_t i;
		std::cin >> type >> i;
		i -= 2;
		if (type == 1) {
			int value = seg1[i];
			seg2.update(0, value, i);
			ans -= value;
		} else {
			int value = seg2[i];
			seg1.update(0, value, i);
			ans -= value;
		}
	}
	
	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 6408
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

i, j = 0, 0
count = sum(a)

for i in range(N):
    if a[i] >= b[i]:
        a[i] -= b[i]
        b[i] = 0
    else:
        b[i] -= a[i]
        a[i] = 0
        if a[i+1] > b[i]:
            a[i+1] -= b[i]
            b[i] = 0
        else:
            b[i] -= a[i+1]
            a[i+1] = 0
print(count-sum(a))        


Measured memory_bytes: 18476
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出,オーバーフローする入力を投げるとよい
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
 
    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll k;
    ll w,x;
    cin>>b>>c;
    rep(i,b){
        rep(j,c){
            cin>>str;
            if(!str.compare("snuke")){
            a=i+1;
            d=j+1;
            }
        }
    }
    
    char ch='A'-1+d;
    cout<<ch<<a<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int N;
		cin >> N;
		if(N == 0){ break; }
		vector<string> query(N);
		vector<int> hit(N), blow(N);
		for(int i = 0; i < N; ++i){
			cin >> query[i] >> hit[i] >> blow[i];
		}
		vector<string> solutions;
		string s = "0000";
		for(int i = 0; i < 10000; ++i){
			s[0] = i / 1000 + '0';
			s[1] = (i / 100) % 10 + '0';
			s[2] = (i / 10) % 10 + '0';
			s[3] = i % 10 + '0';
			bool valid = true;
			for(int j = 0; j < 4; ++j){
				for(int k = j + 1; k < 4; ++k){
					if(s[j] == s[k]){ valid = false; break; }
				}
			}
			if(!valid){ continue; }
			bool accept = true;
			for(int j = 0; j < N; ++j){
				int h = 0, b = 0;
				for(int k = 0; k < 4; ++k){
					for(int l = 0; l < 4; ++l){
						if(s[k] != query[j][l]){ continue; }
						if(k == l){
							++h;
						}else{
							++b;
						}
					}
				}
				if(h != hit[j] || b != blow[j]){
					accept = false;
					break;
				}
			}
			if(accept){ solutions.push_back(s); }
		}
		if(solutions.size() == 1){
			cout << solutions[0] << endl;
			continue;
		}
		string critical = "????";
		for(int i = 0; i < 10000; ++i){
			s[0] = i / 1000 + '0';
			s[1] = (i / 100) % 10 + '0';
			s[2] = (i / 10) % 10 + '0';
			s[3] = i % 10 + '0';
			bool valid = true;
			for(int j = 0; j < 4; ++j){
				for(int k = j + 1; k < 4; ++k){
					if(s[j] == s[k]){ valid = false; break; }
				}
			}
			if(!valid){ continue; }
			bool accept = true;
			int table[4][4] = { { 0 } };
			for(int j = 0; j < solutions.size(); ++j){
				int h = 0, b = 0;
				for(int k = 0; k < 4; ++k){
					for(int l = 0; l < 4; ++l){
						if(s[k] != solutions[j][l]){ continue; }
						if(k == l){
							++h;
						}else{
							++b;
						}
					}
				}
				if(table[h][b]){
					accept = false;
					break;
				}
				table[h][b] = 1;
			}
			if(accept){
				critical = s;
				break;
			}
		}
		cout << critical << endl;
	}
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin >> tmp;
    mp[tmp]++;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i)
  {
    int tmp;
    cin >> tmp;
    mp[tmp]--;
  }
  for (auto &e : mp)
  {
    if (e.second < 0)
    {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");

  return 0;
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
#define LL long long 
#define maxn 100010
#define pb push_back
using namespace std;
vector<int> G[maxn];
LL d[maxn],a[maxn],b[maxn],n,m, p, q;
bool vis[maxn];
void dfs(int x,int fa){
	int now;
	d[x] = (d[fa] + 1) % 2;
	vis[x] = true;
	for(int i = 0; i < G[x].size(); i ++){
		now = G[x][i];
		if(!vis[now]){
			dfs(now,x);
		}
	}
}
int main(){
	cin >> n >> m;
	if(n <= 3){
		cout << 0;
		return 0;
	}
	for(int i = 1; i <= m; i ++){
		cin >> a[i] >> b[i];
		G[a[i]].pb(b[i]);
		G[b[i]].pb(a[i]);
	}
	dfs(1,0);
	bool flag = true;
	for(int i = 1; i <= n; i ++){
		//cout << d[i] << endl;
		if(d[i] == 0) p ++;
		else q ++;
	}
	for(int i = 1; i <= m; i ++){
		if(d[a[i]] == d[b[i]]){
			flag = false;
			break;
		}
	}
	if(!flag){
		cout << (LL)n * (n - 1) / 2 - m;
	}
	else{
		cout << (LL)p * q - m;
	}
	return 0;
}

Measured memory_bytes: 8960
#include<stdio.h>
int main(){
  int i,j,k,b,m1=100,m2=100;
  double a,mt1=100,mt2=100;
  for(k=0;k<3;k++){
    int id,n[5]={100,100,100,100,100};
    double t,r[5]={100,100,100,100,100};
    for(i=0;i<8;i++){
      scanf("%d %lf",&id,&t);
      for(j=3;j>=0;j--){
	if(t<r[j]){
	  r[j+1]=r[j];
	  r[j]=t;
	  n[j+1]=n[j];
	  n[j]=id;
	}
      }
    }
    if(mt2>r[2]){
      mt2=r[2];
      m2=n[2];
      if(mt1>mt2){
	a=mt1;
	mt1=mt2;
	mt2=a;
	b=m1;
	m1=m2;
	m2=b;
	if(mt2>r[3]){
	  mt2=r[3];
	  m2=n[3];
	}	
      }
    }
    printf("%d %.2f\n",n[0],r[0]);
    printf("%d %.2f\n",n[1],r[1]);
  }
  printf("%d %.2f\n",m1,mt1);
  printf("%d %.2f\n",m2,mt2);
  return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(a-c) <= d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b)<=d && abs(b-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
n=int(input())
l=[str(input()) for i in range(n)]
m=int(input())
r=[str(input()) for i in range(m)]
l.sort();r.sort()
#print(l,r)
ans=0
for i in range(n):
    a=l[i]
    b=l.count(l[i])-r.count(l[i])
    if ans<=b:
        ans=b
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  cin >> N;
  if(N<=5){
    cout << N << endl;
    return 0;
  }
  int dp[N+1];
  REP(i, N+1) dp[i] = i;
  dp[1]=1;
  dp[6]=1;
  if(N>=9)dp[9]=1;
  int six, nine;
  for(int i = 2; i<=N; ++i){
    six = 6;
    nine = 9;
    while(i>=six){
      dp[i] = min(dp[i], dp[i-six]+1);
      six *= 6;
    }
    while(i>=nine){
      dp[i] = min(dp[i], dp[i-nine]+1);
      nine *= 9;
    }
  }
  cout << dp[N] << endl;

  return 0;
}


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

int main() {
	int A, B, ans = 0;
	cin >> A >> B;
	for (int i = A; i <= B; i++) {
		int a[5], tmp = i;
		for (int j = 4; j >= 0; j--) {
			a[j] = (tmp % 10);
			tmp /= 10;
		}
		if (a[0] == a[4] && a[1] == a[3]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

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

    auto dp = initVec2<int>(n, n, INF);
    rep(i, n){
        dp[i][i] = 0;
    }
    for(int l = 1; l < n; l++){
        rep(i, n){
            int j = i + l;
            if(j >= n){
                continue;
            }
            for(int k = i; k <= j; k++){
                dp[i][j] = min(dp[i][j], dp[i][k-1] + dp[k][j] + r[i] * r[k] * c[j]);
            }
        }
    }
    cout << dp[0][n-1] << endl;

    return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int a,p;
    cin >> a >> p;
    
    cout << (3*a+p)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
# ソートした状態で文字を読み込んで、アナグラムの文字と出てくる回数を取得する
# あるアナグラム文字がn回出てくるならば、ペアの選び方はnC2で、n*(n-1)/2
# 全てのアナグラム文字に関して足し合わせ
import collections

n = int(input())
# ソートして文字読み込み
s_sorted = [''.join(sorted(input())) for i in range(n)]

# アナグラム文字列と出現回数を取得
anagram_list = collections.Counter(s_sorted)

count = 0

# 出現回数のリストからペアの選び方を計算して、足し合わせ
for i in anagram_list.values():
    count += i*(i-1)//2

print(count)

Measured memory_bytes: 19760
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

L = len(bin(K))-2

ans = 0
for a, b in AB:
    if (K | a) == K:
        ans += b

for n in reversed(range(L)):
    if (1 << n) & K:
        score = 0
        mask = (((1<<L)-(1<<n)) & K) - 1
        for a, b in AB:
            if (mask | a) == mask:
                score += b
        ans = max(ans, score)
print(ans)


Measured memory_bytes: 29428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

using namespace std;
using namespace __gnu_pbds;

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

const int N = 2e5 + 667;
int a[N];
//bool visited[100001];
//vi v[100001];
//vi ans[100001];
//int d[10001];
//queue<int> q;
//int c = 0;

//void dfs(int x){
    //if(visited[x]){
        //c++;
      //  return;
    //}
   // visited[x] = true;
   // for(auto u : v[x]){
    //    dfs(u);
  //  }
//
//}

//void bfs(int x){
   // visited[x] = true;
    //d[x] = 0;
  //  q.push(x);
//    while(!q.empty()){
    //    int s = q.front(); q.pop();
  //      for(auto u : v[s]){
//            //if(visited[u]) continue;
          //  visited[s] = true;
        //    d[u] = d[s] + 1;
      //      q.push(u);
    //    }
  //  }
//}

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

    ll h, ans = 0, cnt = 1;
    cin >> h;
    while(h > 0){
        ans += cnt;
        h /= 2;
        cnt *= 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		long n = nl();
		long k = nl();

		if (n >= k) {
			out(min(n % k, k - n % k));
		} else {
			out(min(k - n, n));
		}

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {
		int N = s.nextInt();
		int K = s.nextInt();
		int num = 1;

		for (int i = 0; i < N; i++) {
			if (num * 2 < num + K) {
				num = num * 2;
			} else {
				num = num + K;
			}
		}

		System.out.println(num);
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
    int num = 0;
    int temp = 0;
    while (s) {
        temp = s % 10;
        num += temp;
        s = s / 10;
    }
    return num;
}

int countDivisorNum(int n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            count++;
        }
    }
    return count;
}


int main() {
    int n;
    cin >> n;
    int temp = 0;

    temp = n % 10;

    if(temp==3){
        cout << "bon" << endl;
    }else if(temp==0||temp==1||temp==6||temp==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }


    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    long long int n,m,i,sum=0;
     scanf("%lld %lld",&n,&m);
     long long a[m];
     for(i=0;i<m;i++)
     {
         scanf("%lld",&a[i]);
         sum+=a[i];
     }
     if(sum>n)
     {
         printf("-1");

     }
     else
     {
         printf("%lld",n-sum);
     }
}



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

struct UnionFind{
  vector<int> d;
  UnionFind(int n=0) : d(n,-1) {}
  int find(int x){
    if( d.at(x) < 0 )  return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x,int y){
    x = find(x); y = find(y);
    if( x == y ) return false;
    if( -d.at(x) < -d.at(y) ) swap(x,y);
    d.at(x) += d.at(y);
    d.at(y) = x;
    return true;
  }
  bool same(int x,int y){ return find(x) == find(y); }
  int size(int x){ return -d.at( find(x) ); }
};

int main(){
  vector<int> deg(100005);
  vector<int> to[100005];
  int n,m,k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    deg.at(a)++;
    deg.at(b)++;
    uf.unite(a,b);
  }
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n){
    int ans = uf.size(i) - 1 - deg.at(i);
    for(int u : to[i] ){
      if(uf.same(i,u) ) ans--;
    }
    printf("%d%c",ans, i==n-1?'\n' : ' ');
  }
}


Measured memory_bytes: 6784
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#h,i = 497,284
h,i=map(int, raw_input().split())


while i != 0:
    siki= h % i
    h = i
    i = siki

print (h)

Measured memory_bytes: 4580
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <climits>

typedef long long ll;
using namespace std;

ll MOD = 1e9+7;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main(){
  std::vector<std::vector<int>> vec(3,std::vector<int>(3));
  rep(i,3) {
    rep(j,3) {
      cin >> vec.at(i).at(j);
    }
  }
  int n;
  cin >> n;
  std::vector<int> b(n);
  rep(i,n) {
    cin >> b.at(i);
  }
  rep(i,3) {
    rep(j,3) {
      rep(k,n) {
        if(vec.at(i).at(j) == b.at(k)) {
          vec.at(i).at(j) = 0;
        }
      }
    }
  }
  rep(i,3) {
    if ((vec.at(i).at(0) == 0 && vec.at(i).at(1) == 0 && vec.at(i).at(2) == 0) ||
    (vec.at(0).at(i) == 0 && vec.at(1).at(i) == 0 && vec.at(2).at(i) == 0)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if ((vec.at(0).at(0) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(2) == 0) ||
  (vec.at(0).at(2) == 0 && vec.at(1).at(1) == 0 && vec.at(2).at(0) == 0)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int siritori(string x,string y)
{
	return x.at(x.size()-1) == y.at(0);
}

int main()
{
	string a,b,c;
	cin >> a >> b >> c;

	if (siritori(a, b) == 1 && siritori(b, c) == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int num[100007],chance=0,n,m,v,p;
bool cmp(int a,int b)
{
	return a>b;
}
signed main() 
{
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	int ans=p;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&num[i]);
	}
	sort(num+1,num+1+n,cmp);
	for(int i=1;i<=n-p;i++)
	{
		if(num[p]>num[p+i]+m)
		{
			cout<<ans<<endl;
			return 0;
		}
		int t=v+i-n;
		if(t<=0)
		{
			ans++;
		}
		else 
		if( (t*m-chance-1)/i +num[p]+1<=num[p+i]+m)
		{
			ans++;
		}
		chance+=num[p]-num[p+i];
//		cout<<ans<<' ';
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4544
def test():

	output = [[0 for i in range(10)] for j in range(12)]

	n = int(input())

	for num in range(n):
		
		inputs = list(map(int,input().split()))

		b = inputs[0] - 1
		f = inputs[1] - 1
		r = inputs[2] - 1
		v = inputs[3]

		output[b*3 + f][r] += v


	for i in range(12):
		for j in range(10):
			print(f" {output[i][j]}",end = '')
		print()
		if i % 3 == 2 and i != 11:
			for j in range(20):
				print("#",end = '')
			print()


if __name__ == "__main__":
	test()


Measured memory_bytes: 5644
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int a, b;
    cin >> a >> b;
    int sum = 1, a_counter = 0;
    while(sum < b){
        a_counter++;
        sum += a - 1;
    }
    cout << a_counter << endl;
}


Measured memory_bytes: 256
n=int(input())
b=[int(j) for j in input().split()]
ans=[]
while b:
    tmp=10**18
    for i in range(len(b))[::-1]:
        if b[i]==i+1:
            tmp=i
            break
    if tmp==10**18:
        print(-1)
        exit()
    else:
        ans.append(b[tmp])
        del b[tmp]

for i in range(n)[::-1]:
    print(ans[i])

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

int main() {
	int A,B,C;
	cin>>A>>B>>C;
	if(A==B&&A==C&&B==C){
		cout<<"No"<<endl;
		return 0;
	}
	if(A==B){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(A==C){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(B==C){
		cout<<"Yes"<<endl;
		return 0;
	}
  	cout<<"No"<<endl;
}
	

Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n,m;
	cin>>n>>m;
	cout<<(n*(n-1)+m*(m-1))/2;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = []
for i in range(3):
    L.append([int(x) for x in input().split()])
    
ans = 0
A_b = -2
for i in range(N):
    A = L[0][i]
    if A_b + 1 == A:
        ans += L[2][A-2]
    ans += L[1][A-1]
    A_b = A
    
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n,t;
    cin>>n>>t;
	pii a[n];
	rep(i,0,n){
		cin>>a[i].se>>a[i].fi;
	}
	sort(a,a+n);
	int mini=inf;
	rep(i,0,n){
		if(a[i].fi>t)break;
		mini=min(a[i].se,mini);
	}
	if(mini==inf)cout<<"TLE"<<endl;
	else cout<<mini<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

using namespace std;

int main(){
  int n,p=0,w=0,g=0,y=0;
  string s;
  cin >> n;
  for (int i=0;i<n;i++){
    cin >> s;
    if (s=="P") p=1;
    else if (s=="W") w=1;
    else if (s=="G") g=1;
    else if (s=="Y") y=1;
  }
  if (p+w+g+y==3) cout << "Three" << endl;
  else cout << "Four" << endl;
}


Measured memory_bytes: 256