akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <complex>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

const double EPS=1e-10;
#define equals(a, b) (fabs((a)-(b))<EPS)
#define X real()
#define Y imag()
typedef complex<double> Point;
typedef complex<double> Vector;


struct Segment {
    Point p1, p2;
};

double dot(Vector a, Vector b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Vector a,Vector b) {
    return a.X*b.Y - a.Y*b.X;
}

enum CCW {
    COUNTER_CLOCKWISE=1,
    CLOCKWISE=-1,
    ONLINE_BACK=2,
    ONLINE_FRONT=-2,
    ON_SEGMENT=0,
};

int ccw(Point p0, Point p1, Point p2) {
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return CCW::COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS) return CCW::CLOCKWISE;
    if(dot(a,b)<-EPS) return CCW::ONLINE_BACK;
    if(norm(a)<norm(b)) return CCW::ONLINE_FRONT;

    return CCW::ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4) {
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2) {
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2) {
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}


Point a,b;
Point s[102],t[102];
int o[102],l[102];
vector<pair<double,int>> intersections;
int solve(int p) {
    int ret=0;
    rep(i,intersections.size()) {
        int t=intersections[i].sc;
        if(o[t]) {
            if(l[t]!=p) {
                ret++;
                p=l[t];
            }
        }
        else {
            if(l[t]==p) {
                ret++;
                p=l[t]^1;
            }
        }
    }

    return ret;
}

void solve() {
    intersections.clear();
    int n;
    cin>>n;
    rep(i,n) {
        int x1,y1;
        int x2,y2;
        cin>>x1>>y1>>x2>>y2>>o[i]>>l[i];
        s[i]=Point(x1,y1);
        t[i]=Point(x2,y2);
    }
    rep(i,n) {
        if(intersect(Segment{a,b},Segment{s[i],t[i]})) {
            Point p = getCrossPoint(Segment{a,b},Segment{s[i],t[i]});
            double d=abs(p-a);
            intersections.pb(mp(d,i));
        }
    }
    sort(all(intersections));
    cout<<min(solve(0),solve(1))<<endl;
}

int main() {
    int n;
    cin>>n;
    rep(i,n) {

        int x,y;
        cin>>x>>y;
        a.real(x);
        a.imag(y);
        cin>>x>>y;
        b.real(x);
        b.imag(y);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1220
n=int(input())
a=[]
b=[]

for i in range(n):
      aa=int(input())
      a.append(aa)
      d=[]
      for j in range(aa):
            x,y=map(int,input().split())
            d.append((x,y))
      b.append(d)
cc=0
for i in range(2**n):
      L=[0]*n
      for j in range(n):
            if ((i>>j)&1):
                  L[j]=1
      if 1 in L:
            flag=True
            for k in range(n):
                  if L[k]==1:
                        for m in range(a[k]):
                              if L[b[k][m][0]-1]!=b[k][m][1]:
                                    flag=False
                                    break
            if flag:
                  cc=max(sum(L),cc)
print(cc)

Measured memory_bytes: 3064
t = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]

x, y = list(map(int, input().rstrip().split()))

result = 'No'
for ti in t:
    if x in ti and y in ti:
        result = 'Yes'
        break;

print(result)



Measured memory_bytes: 2940
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		Deque<String> dq = new ArrayDeque<>(Arrays.asList(s.split("")));
		int n = Integer.valueOf(sc.nextLine());
		boolean isReverse = false;
		for (int i = 0; i < n; i++) {
			if ("1".equals(sc.next())) {
				// que反転
				isReverse = !isReverse;
			} else {
				// 向きを示す物が必要
				if ("1".equals(sc.next()) == isReverse) {
					// 後ろ
					dq.addLast(sc.next());
				} else {
					// 前
					dq.addFirst(sc.next());
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		int size = dq.size();
		for (int i = 0; i < size; i++) {
			if (isReverse) {
				sb.append(dq.pollLast());
			} else {
				sb.append(dq.pollFirst());
			}
		}

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 109588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main()
{
    long long N;
    cin >> N;
    vector<long long> p(N * 3);
    for(int i = 0; i < N * 3; i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    long long a = p.size();
    long long ans = 0;
    for(int i = N; i < a; i+=2){
        ans += p[i];
    }
    cout << ans << endl;
}


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

int main() {
    int a, b;
    while (cin >> a >> b, a) {
        int cnt = 0;
        if (a < b) swap(a, b);
        while (b) {
            cnt++;
            swap(a = a % b, b);
        }
        cout << a << " " << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
ab = [readInts() for i in range(n)]
ab.sort(key=lambda x:x[1])
now = 0
for i in ab:
  now+=i[0]
  if now<=i[1]:
    pass
  else:
    print("No")
    exit()

print("Yes")

Measured memory_bytes: 47184
import java.io.*;
public class Main{
  public static void main(String[] args){
    int E869120=1;
    int square1001=1;
    String buf1,buf2,buf3;
    try{
      BufferedReader br
          = new BufferedReader(new InputStreamReader(System.in));

      buf1 = br.readLine();
      buf2 = buf1.substring(0,buf1.indexOf(" "));
      buf3 = buf1.substring(buf1.indexOf(" ")+1);
      E869120 = Integer.parseInt(buf2);
      square1001 = Integer.parseInt(buf3);

  } catch(Exception e) {
      System.out.print("Error:" + e);
  }
  if(E869120<=15&square1001<=15&E869120+square1001<=16&E869120>=1&square1001>=1){
   if(E869120<=8&square1001<=8)
   {
     System.out.println("Yay!");}
     else{System.out.println(":(");}

   }
 


  }
}

Measured memory_bytes: 21204
def calc_dist(n, start, edges)
    updated = [start]
    dist = Array.new(n)
    prev = Array.new(n)
    dist[start] = 0
    prev[start] = -1
    while updated.length > 0
        u = updated.pop
        edges[u].each do |v, _|
            next if dist[v]
            dist[v] = dist[u] + 1
            prev[v] = u
            updated.push(v)
        end
    end
    return dist, prev
end

def diameter(n, edges)
    dist1, _ = calc_dist(n, 1, edges)
    far1 = n.times.max_by{|i|dist1[i]}
    dist2, prev2 = calc_dist(n, far1, edges)
    far2 = n.times.max_by{|i|dist2[i]}
    diam = dist2[far2]
    centers = []
    back = far2
    while back != -1
        centers.push(back) if dist2[back] == diam/2 || dist2[back] == (diam+1)/2
        back = prev2[back]
    end
    return diam, centers
end

def calc_dist2deg(n, start, edges, degrees, except=nil)
    updated = [start]
    dist = Array.new(n)
    dist2deg = Array.new(n, 0)
    dist[start] = 0
    dist[except] = -1 if except
    dist2deg[0] = degrees[start]
    while updated.length > 0
        u = updated.pop
        edges[u].each do |v, _|
            next if dist[v]
            dist[v] = dist[u] + 1
            dist2deg[dist[v]] = degrees[v] if dist2deg[dist[v]] < degrees[v]
            updated.push(v)
        end
    end
    return dist2deg
end

N = gets.to_i

edges = Array.new(N){Hash.new}
degrees = Array.new(N, 0)
(N-1).times do |i|
    a, b = gets.split.map(&:to_i)
    edges[a-1][b-1] = true
    edges[b-1][a-1] = true
    degrees[a-1] += 1
    degrees[b-1] += 1
end

diam, centers = diameter(N, edges)
colors = diam/2 + 1

ans = Float::INFINITY
if diam % 2 == 0
    cp = centers[0]
    d2d = calc_dist2deg(N, cp, edges, degrees)
    ans = d2d[0]
    (1...N).each do |i|
        ans *= d2d[i] - 1 if d2d[i] - 1 > 1
    end
    ce_cand = edges[cp].keys.map{|k|[cp, k]}
else
    ce_cand = [centers]
end

ce_cand.each do |c1, c2|
    d2d_1 = calc_dist2deg(N, c1, edges, degrees, c2)
    d2d_2 = calc_dist2deg(N, c2, edges, degrees, c1)
    result = 2
    N.times do |i|
        max = [d2d_1[i], d2d_2[i]].max - 1
        result *= max if max > 1
    end
    ans = result if ans > result
end

puts [colors, ans].join(' ')

Measured memory_bytes: 1916
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	static long solve(int N, long X) {
		long count = 0;
		while (N >= 0) {
			if (N == 0) {
				count += X > 0 ? 1 : 0;
				break;
			}
			if (X == 0) break;
			X--; // ban
			if (X <= H[N-1]) {
				N--;
				continue;
				// return solve(N-1, X);
			}
			X -= H[N-1];
			if (X == 0) break;

			count += 1 + P[N-1];
			X--;
			if (X == 0) break;
			N--;
		}
		return count;
	}

	static long[] P;
	static long[] H;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long X = sc.nextLong();

		H = new long[N+1];
		P = new long[N+1];
		H[0] = 1;
		P[0] = 1;
		for (int i = 0; i < N; i++) {
			H[i+1] = H[i] * 2 + 3;
			P[i+1] = P[i] * 2 + 1;
		}
		long ans = solve(N, X);
		System.out.println(ans);

		// System.out.println("BBPPPBPBPPPBB");
		// for (int i = 1; i <= 13; i++) {
		// 	System.out.println(solve(2, i));
		// }
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int N;
	int sum = 0;
	cin >> N;
	for (int i = 0; i<N; i++){
		string x;
		cin >> x;
		if (x == "Y") {
			sum++;
		}
		else {
			continue;
		}
	
	}
	if (sum == 0) {
		cout << "Three" << endl;
	}
	else
		cout << "Four" << endl;
}
	

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

using namespace std;

#define MAX_V 100000
#define INF (1<<29)
typedef long long ll;

void bfs(int s,int *d,ll *cnt,vector<int> G[MAX_V]){
  queue<int> Q; Q.push(s);
  memset(cnt,0,sizeof(cnt));
  fill(d,d+MAX_V,INF);
  d[s] = 0;
  cnt[d[s]]++;
  while(!Q.empty()){
    int v = Q.front(); Q.pop();
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      int to = G[v][i];
      if(d[v] + 1 < d[to]){
        d[to] = d[v] + 1;
        cnt[d[to]]++;
        Q.push(to);
      }
    }
  }
}

int main(){
  int V,E,S,T,x,y;
  int ds[MAX_V],dt[MAX_V];
  ll cs[MAX_V],ct[MAX_V];
  vector<int> G[MAX_V];
  cin >> V >> E >> S >> T;
  S--; T--;
  for(int i = 0 ; i < E ; i++){
    cin >> x >> y; x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  
  bfs(S,ds,cs,G); 
  bfs(T,dt,ct,G);
  
  ll ans = 0LL;
  int min_dist = ds[T];
  for(int i = 0 ; i < V ; i++){
    int j = min_dist-2-i;
    ans += (j >= 0 ? cs[i]*ct[j] : 0);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9968
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>

using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
#define MODE 0
#define DEB(X) if(MODE)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(MODE)cout<<X<<" ";
#define ARDEB(i,X) if(MODE)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) if(MODE){(f)? cout<<"true ":cout<<"false ";}
#define FORDEB(n,X) if(MODE)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(MODE)cout<<endl;
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000;
 
int main(){
	string s;
	int a[5];
	bool f[5];
	cin>>s;
	for(int i=0;i<4;i++){
		a[i]=int(s[i]-'0');
	}
	BitFOR(3){
		int dim=a[0];
		DEB(Bit)END
		DEB(BIT(Bit,4))END
		REP(i,3){
			DEB(BIT(1<<i,4))END
			if(Bit&(1<<i)){
				dim+=a[i+1];
				f[i]=true;
			}
			else{
				dim-=a[i+1];
				f[i]=false;
			}
		}
		if(dim==7)break;
	}
	cout<<a[0];
	REP(i,3){
		cout<<((f[i])? "+":"-")<<a[i+1];
	}
	cout<<"=7"<<endl;
	return 0;
}

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

#define NIL NULL

struct node{
  struct node *l;
  struct node *r;
  struct node *p;
  int key;
};

typedef struct node * Node;

Node root;

void Preorder(Node t){
  printf(" %d",t->key);
  if(t!=NIL){
    if(t->l!=NIL)Preorder(t->l);
    if(t->r!=NIL)Preorder(t->r);
  }
}

void Inorder(Node t){
  
  if(t!=NIL){
    if(t->l!=NIL){
      Inorder(t->l);
      }
    printf(" %d",t->key);
    
    if(t->r!=NIL){
      Inorder(t->r);
      }
  }
}

void insert(int k){
  Node y=NIL;
  Node x=root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key=k;
  z->l=NIL;
  z->r=NIL;
  
  while(x!=NIL){
    y=x;

    if(z->key<x->key) x=x->l;
    else x=x->r;
  }
  z->p=y;
  
  if(y==NIL) root=z;
  else if(z->key<y->key) y->l=z;
  else y->r=z;
}

Node Search(Node t,int k){
  if(t==NIL || k==t->key) return t;
  if(k<t->key) return Search(t->l,k);
  else return Search(t->r,k);
}

Node Minimum(Node t){
  while(t->l!=NIL){
    t=t->l;
  }
  return t;
}

Node Successor(Node t){
  if(t->r!=NIL)return Minimum(t->r);
  Node y=t->p;
  while(y!=NIL && t==y->r){
    t=y;
    y=y->p;
  }
  return y;
}

void Delete(Node z){
  Node y;
  Node x;

  if(z->l==NIL || z->r==NIL) y=z;
  else y=Successor(z);

  if(y->l!=NIL) x=y->l;
  else x=y->r;

  if(x!=NIL) x->p=y->p;

  if(y->p==NIL)root=x;
  else if(y==y->p->l) y->p->l=x;
  else  y->p->r=x;

  if(y!=z)z->key=y->key;
}


main(){
  int n, i, x;
  char str[20];
  
  scanf("%d",&n);

  for ( i = 0; i < n; i++ ){
    scanf("%s",str);

    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    } 
    else if(str[0]=='p'){
      Inorder(root);
      printf("\n");
      
      Preorder(root);
      printf("\n");
    }
    else if(str[0]=='f'){
      scanf("%d",&x);
      Node s=Search(root,x);
      if (s!= NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if(str[0]=='d'){
      scanf("%d",&x);
      Delete(Search(root, x));
    }
  }
  return 0;
}

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

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

  }

  for(int i=0;i<n;i++){
   cout << cnt[i] << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;

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

	

}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n, m;
pair<ll, ll> arr[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> arr[i].ff >> arr[i].ss;
  sort(arr + 1, arr + 1 + n);
  int rem = m;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (rem <= arr[i].ss) {
      ans += (arr[i].ff * rem);
      break;
    }
    else {
      rem -= arr[i].ss;
      ans += (arr[i].ff * arr[i].ss);
    }
  }
  cout << ans << endl;
}





Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,k,i,dif=999999999;
    cin >> n >> k;
    vector<int> h(n);
    for(i=0;i<n;i++) cin >> h.at(i);
    sort(h.begin(),h.end());
    for(i=0;i<n-k+1;i++) dif = min(dif,h.at(i+k-1)-h.at(i));
    cout << dif << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
    mll R;
    ll S = 0;
    REP(i, N) {R[A[i]]++; S += A[i];}
    REP(i, Q){
        if(R.count(B[i])){
            ll x = R[B[i]];
            R.erase(B[i]);
            if(R.count(C[i])){
                R[C[i]]+= x;
            }
            else{
                R[C[i]] = x;
            }
            S += x*(C[i]-B[i]);
            
        }
        cout<<S<<endl;

    }
    
    
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 9108
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 

using namespace std;

int main() {
	int i, j, k, l, a, b, c, d;
	string str;

	cin >> str;

	a = (int)str[0] - 48;
	b = (int)str[1] - 48;
	c = (int)str[2] - 48;
	d = (int)str[3] - 48;
	
	//cout << a << endl;
	int num = 0;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			num = 0;
			for (k = 0; k < 2; k++) {
				if (i == 0) {
					num = (a + b);
				}
				else {
					num = (a - b);
				}

				if (j == 0) {
					num = num + c;
				}
				else {
					num = num - c;
				}

				if (k == 0) {
					num = num + d;
				}
				else {
					num = num - d;
				}

				if (num == 7) {
					char one, two, three;
					cout << a;
					if (i == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << b;
					if (j == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << c;
					if (k == 0) {
						cout << "+";
					}
					else {
						cout << "-";
					}
					cout << d;
					cout << "=7" << endl;


					return 0;
				}

			}
		}
	}




	//cout << num << endl;




	return 0;
}


Measured memory_bytes: 256
import heapq

n = int(input())
a = list(map(int,input().split()))


h1 = []
sum1 = [0]
for i in range(n):
    sum1[0] += a[i] 
    heapq.heappush(h1,a[i])

for i in range(n,2*n):
    sum = sum1[i-n]
    aa = heapq.heappop(h1)
    if (aa < a[i]):
        heapq.heappush(h1,a[i])
        sum += (a[i] - aa)
    else:
        heapq.heappush(h1,aa)
    sum1.append(sum)

h2 = []
sum2 = [0]
for i in range(n):
    sum2[0] -= a[3*n-i-1] 
    heapq.heappush(h2,-1 * a[3*n-i-1])

for i in range(n,2*n):
    sum = sum2[i-n]
    aa = heapq.heappop(h2)
    if (aa < -1 * a[3*n - i-1]):
        heapq.heappush(h2,-1 * a[3*n - i-1])
        sum += (-1 * a[3*n - i-1] - aa)
    else:
        heapq.heappush(h2,aa)
    sum2.append(sum)


ans = - 10 ** 15
for i in range(n+1):
    ans = max(ans,sum1[i]+sum2[n-i])

print(ans)

Measured memory_bytes: 37212
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int main() {
    int X;
    cin >> X;
    int ans = 0;
    while (X >= 500) {
        X -= 500;
        ans += 1000;
    }
    while (X >= 5) {
        X -= 5;
        ans += 5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k=MI()
    print("YES" if (n+1)//2>=k else "NO")

main()

Measured memory_bytes: 8940
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)
x.sort()
y.sort()

if x[-1] >= y[0]:
    print("War")
else:
    print("No War")

Measured memory_bytes: 62032
n = int(input())
l = list(map(int,input().split()))
ans = 0
sum_n = [0]*n
sum_n[0] = l[0]
sumall = sum(l)
for i in range(1,n):
    sum_n[i] = sum_n[i-1] + l[i]
for i in range(n):
    ans += ((l[i]*(sumall-sum_n[i]))%1000000007)
print(ans%1000000007)

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

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define int long long
#define vi vector<ll>
#define pb push_back
#define mp make_pair
#define sp(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
#define all(v) v.begin(),v.end()
void kehsihba() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin>>n;
	set<string>m;
	string s;
	while(n--){
		cin>>s;
		m.insert(s);
	}
	cout<<m.size();

}


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

struct kitaeri {
	int bango;
	int ninzu;
};

int kugyu(const void* a, const void* m) {
	int aa = ((const struct kitaeri*)a)->ninzu;
	int mm = ((const struct kitaeri*)m)->ninzu;
	if (aa < mm) return -1;
	return aa > mm;
}

int N;
struct kitaeri tomatu[200000];

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &tomatu[i].ninzu) != 1) return 1;
		tomatu[i].bango = i + 1;
	}
	qsort(tomatu, N, sizeof(*tomatu), kugyu);
	printf("%d", tomatu[0].bango);
	for (i = 1; i < N; i++) {
		printf(" %d", tomatu[i].bango);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  int before = 0;
  int incr = 0; // 1: increasing, 2: decreasing
  int cnt = 1;
  rep(i, n) {
    int a; cin >> a;
    if (i==0) {
      before = a;
      continue;
    }
    if (before == a) {
      continue;
    }
    if (a > before) {
      if (incr < 0) {
        cnt++;
        incr = 0;
      } else {
        incr = 1;
      }
    } else {
      if (incr > 0) {
        cnt++;
        incr = 0;
      } else {
        incr = -1;
      }
    }
    before = a;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define cinn(a) for(auto &_k:(a)) cin >> _k
#define coutt(a) for(auto &_k:(a)) cout << _k << ' '
inline int cint() { int temp; cin>>temp; return temp; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    int s[n];
    for (int i=0; i<n; i++){
        int temp; cin >> temp;
        s[temp-1]=i+1;
    }
    for (auto &k:s) cout << k << ' ';
}

Measured memory_bytes: 1280
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int inf = 1012345678;
const int max_size = 262144;
int N, Q, l, r, a[200009], s[200009], dp[200009], seg[524296]; vector<int> g[200009];
void release(int pos, int val) {
	pos += max_size;
	seg[pos] = max(seg[pos], val);
	while (pos > 1) {
		pos >>= 1;
		seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
	}
}
int query(int a, int b, int k = 1, int l = 0, int r = max_size) {
	if (a <= l && r <= b) return seg[k];
	if (r <= a || b <= l) return -inf;
	int lc = query(a, b, k * 2, l, (l + r) >> 1);
	int rc = query(a, b, k * 2 + 1, (l + r) >> 1, r);
	return max(lc, rc);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i], s[i + 1] = s[i] + a[i];
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> l >> r; l--;
		g[l].push_back(r);
	}
	fill(seg, seg + max_size * 2, -inf);
	release(0, 0);
	for (int i = 0; i < N; i++) {
		sort(g[i].begin(), g[i].end(), greater<int>());
		for (int j : g[i]) release(j, query(i, j));
		release(i + 1, query(i, i + 1) + s[i] - s[i + 1] - a[i] + 1);
	}
	cout << N - query(N, N + 1) - s[N] << endl;
	return 0;
}

Measured memory_bytes: 13312
#include<iostream>
#include<string>
#include<queue>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
int main()
{
	string s,t,u;
	int a,b;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u)
	{
		cout<<a-1<<" "<<b;
	}
	else
	{
		cout<<a<<" "<<b-1;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int k, x;
   cin >> k >> x;
   for (int i = 0; i < 2*k-1; i++)
      cout << (x - k + 1 + i) << " ";
   cout << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int w, n;
    cin >> w >> n;
    vector<int> a(n), b(n), c(w);
    rep(i, 0, n){
        char s;
        cin >> a[i] >> s >> b[i];
        a[i]--; b[i]--;
    }  
    rep(i, 0, w) c[i] = i;
    rep(i, 0, n){
        swap(c[a[i]], c[b[i]]);
    }
    rep(i, 0, w){
        cout << c[i] + 1 << endl;
    }
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

using namespace std;

int main(){
    ll N, K;   cin >> N >> K;
    ll tmp, ans;
    int j = 0;
    vector<ll> v(N);
    rep(i,N)    cin >> v[i];
    ll x, x1, x2;
    x1 = 0;
    x2 = 10000000005;
    while(x2 - x1 > 1){
        x = (x1 + x2) / 2;
        tmp = 0;
        for(int i=0; i<N; i++){
            if(v[i] % x == 0)   tmp--;
            tmp += v[i] / x;
        }
        if(tmp <= K){
            ans = x;
            x2 = x;
        }else{
            x1 = x;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4752
#include <stdio.h>

int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i < 10; ++i)
	{
		if (n <= 100*i+10*i+i)
		{
			printf("%d\n", 100*i+10*i+i);
			return 0;
		}
	}
}

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

double dist(ll int x,ll int y)
{
    return sqrt(x*x+y*y);
}
void solve()
{
  int n,d;
  cin >> n >> d;
  vector<pair<int,int>>arr(n);
  for (int c=0;c<n;c++)
    cin >> arr[c].first >> arr[c].second;
    int ans=0;
    for (int c=0;c<n;c++)
        if (dist(arr[c].first,arr[c].second)<=d*1.00)
            ans++;
    cout << ans << endl;

}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=0;tt<t;tt++)
        {
            solve();
        }    
        return 0;
}

Measured memory_bytes: 4780
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
eval'N,A,B,C='+`dd`.split*?,
a=o[A*=t=o[A+B,-2+M=10**9+7],N]
b=o[B*=t,N]
f=f=1,*(1..2*N).map{|i|f=f*i%M}
N.times{|i|$.=($.+(N+i)*f[N+i-1]*o[f[N-1]*f[i],M-2]*(a+b))%M
a=a*B%M
b=b*A%M}
p$.*100*t%M

Measured memory_bytes: 5128
fun main(args: Array<String>) {
  val (n, a, b)= readLine()!!.split(" ").map(String::toInt)

  if (a + b > n + 1) {
    println(-1)
    return
  }

  if (a.toLong() * b.toLong() < n.toLong()) {
    println(-1)
    return
  }

  val ys = IntArray(a)
  ys[0] = b
  for (k in 0 until (n - b)) {
    ys[k % (a - 1) + 1]++
  }

  val xs = mutableListOf<Int>()
  var base = 0
  for (y in ys) {
    for (x in base + y downTo base + 1) {
      xs.add(x)
    }
    base += y
  }
  println(xs.joinToString(" "))
}


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

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

ll n,m,x,y,k,d,i,j,index,flag=0,mini,count=0,result,odd,even,sum=0,temp;
cin>>n>>m>>x>>y;

//string str;
//cin>>str;
//ll a[200005];
//ll b[200005];
//vector<ll> ans;
//set<ll> s;

/*for(i=0;i<n;i++)
{
    cin>>a[i];
}
*/
//sort(a,a+n);


odd=max(n*x,m*y);
even=max(m*x,n*y);
cout<<max(odd,even);



    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
void init(){
}
void solve(){
    ll n, st = 100;
    cin >> n;
    int ans = 0;
    while (st < n){
        st = st * 1.01;
        ++ans;
    }
    cout << ans << endl;
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
Xs = input()
X = int(Xs)
if X < 100:
  print("0")
  exit()
X_ = int(Xs[-3:])
_X = int(Xs[0:-3])
if X_ == 0 or X_ == 1 or X_ == 2 or X_ == 3 or X_ == 4 or X_ == 5:
  print("1")
  exit()
count = 0
count += X_ // 5
X_ = X_ %  5
count += X_ //4
X_=X_%4
count += X_ //3
X_=X_%3
count += X_ //2
X_=X_%2
count += X_ //1
X_=X_%1
if _X - count >= 0:
  print("1")
else:
  print("0")
if em: sys.stdin = open('/dev/tty')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
void input();
int max(int32_t a, int b){
   return max((int)a, b);
}

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n;
   cin >> n;
   vector<int> a(n);
   vector<bool> ans(n, false);
   for(int i = 0; i < n; i ++)
      cin >> a[i];
   int am = 0;
   for(int i = n-1; i >= 0; i --){
      int cnt = 0;
      for(int j = i + i + 1; j < n; j += (i + 1)){
         if(ans[j])
            cnt ++;
      }
      if(cnt % 2 == a[i]){
         continue;
      }else{
         ans[i] = true;
         am ++;
      }
   }
   cout << am << endl;
   for(int i = 0; i < n; i ++){
      if(ans[i])
         cout << i + 1 << " ";
   }
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        scanf("%lld", &d[i]);
    }

    Vl m(q), x(q), n(q);
    for (int i = 0; i < q; i++) {
        scanf("%lld %lld %lld", &n[i], &x[i], &m[i]);
    }

    Vl dm(k);
    for (int i = 0; i < q; i++) {
        ll out = 0;
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m[i];
        }
        for (int j = 0; j < k; j++) {
            if (dm[j] == 0) {
                if (j <= (n[i] - 1) % k - 1)
                    out += (n[i] - 1) / k + 1;
                else
                    out += (n[i] - 1) / k;
            }
        }
        ll a_last = x[i] % m[i];
        for (int j = 0; j < k; j++) {
            if (j <= (n[i] - 1) % k - 1)
                a_last += dm[j] * ((n[i] - 1) / k + 1);
            else
                a_last += dm[j] * ((n[i] - 1) / k);
        }
        out += a_last / m[i];
        printf("%lld\n", n[i] - 1 - out);
    }

    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max =0;
    int ans =1;
    int[] list = new int[N+1];
    for (int i=1; i<=N; i++) {
      int a = i;
        while (a % 2 == 0) {
          list[i]++;
          a /= 2;
        }
        if(list[i]>max) {
          max = list[i];
          ans =i;
        }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    print(max(i + bisect(cum_B, K - a) for i, a in enumerate(cum_A) if a <= K))


if __name__ == "__main__":
    main()


Measured memory_bytes: 55172
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define cmin(x,y) (x)=(y)<(x)?(y):(x)
#define cmax(x,y) (x)=(y)>(x)?(y):(x)
using namespace std;
const ld pi=acos(-1);
const ld eps=1e-8;
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll get_inv(ll x){
	return ksm(x,mod-2);
}
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
#define N 60
int n,a[N],b[N],f[N][N][N],g[N][N]; ll ans;
void gg(){ puts("-1"); exit(0); }
//#define local
int main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	n=read();
	rep (i,1,n) a[i]=read();
	rep (i,1,n) b[i]=read();
	rep (i,0,50) f[0][i][i]=1;
	rep (i,1,50) rep (j,0,50) rep (k,0,50) f[i][j][k]=f[i-1][j][k]|f[i-1][j%i][k];
	bool fl=1;
	rep (i,1,n) if (!f[50][a[i]][b[i]]) fl=0;
	if (!fl) gg();
	rep (i,1,n) g[i][a[i]]=1;
	per (k,50,1){
		fl=1;
		rep (i,1,n){
			bool qwq=0;
			rep (j,0,50) qwq|=g[i][j]&&f[k-1][j][b[i]];
			if (!qwq){ fl=0; break; }
		}
		if (!fl){
			ans+=1ll<<k;
			rep (i,1,n) rep (j,0,50) g[i][j%k]|=g[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}
// sample data:
/*
3
19 10 14
0 3 4

160

====
3
19 15 14
0 0 0

2

=====
2
8 13
5 13

-1
=====
4
2 0 1 8
2 0 1 8

0

=====
1
50
13

137438953472

*/

// rest:
/*

*/

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int N;
int A[100];

int main(){
    int min, max;
    min = 0;
    max = 0;
    cin >> N;
    for (int i = 0; i < N ; i++){
        cin >> A[i];
    }
    min = A[0];
    max = A[1];
    for (int i = 0; i < N ; i++){
        if (A[i] < min){
            min = A[i];
        }
        if (A[i] > max){
            max = A[i];
        }
    }
    int ret = max - min;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int num[101];
int big = 0;
int input;
int main(){
	for(int i=0; i <= 101; i++) num[i]=0;
	while(scanf("%d", &input) != EOF) num[input]++;
	for(int i=0; i <= 100; i++) big = max(big, num[i]);
	for(int i=0; i <= 100; i++) if(num[i] == big) cout << i << endl;
}

Measured memory_bytes: 1208
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    a, b, n = LI()
    print(min(b - 1, n) * a // b)
    return


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


Measured memory_bytes: 76768
N = int(input())

current = 0, 0, 0
for _ in range(N):
	t, x, y = map(int, input().split())
	t_diff = t - current[0]
	d_diff = abs(x-current[1]) + abs(y-current[2])
	if t_diff < d_diff:
		print('No')
		break
	elif (d_diff - t_diff)%2 != 0:
		print('No')
		break
	current = t, x, y
else:
	print('Yes')
		

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int N = ReadInt();
            Console.WriteLine((N - 2) * 180);
        }
    }
}


Measured memory_bytes: 11092
N = 8
FREE = -1
NOT_FREE = 1

row = [FREE for _ in range(N)]
col = [FREE for _ in range(N)]
dpos = [FREE for _ in range(2*N-1)]
dneg = [FREE for _ in range(2*N-1)]

X = [[False for _ in range(N)] for _ in range(N)]

def printBoard():
    i,j = 0, 0
    for i in range(N):
        for j in range(N):
            if X[i][j]:
                if row[i] != j: return
    
    for i in range(N):
        for j in range(N):
            print("Q" if row[i]==j else ".", end='')
        print()
            

def recursive(i):
    j = 0

    if i==N:
        printBoard()
    
    else:
        for j in range(N):
            if NOT_FREE == col[j] or \
               NOT_FREE == dpos[i+j] or \
               NOT_FREE == dneg[i-j+N-1]:
               continue
            row[i] = j; col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE
            recursive(i+1)
            row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE

k = int(input())
for _ in range(k):
    r,c = map(int,input().split())
    X[r][c] = True

recursive(0)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const int INF = 1e9;
const int MOD = 1000000007;
vector<ll> prime;
vector<P> ans1,ans2;

vector<P> getPrimes(ll x){
        vector<P> res;
        for(ll i = 2; i * i <= x;i++){
                if(x%i ==0){
                        res.push_back(P{i,0});
                        while(x%i ==0) x /= i,res.back().second++;
                }
        }
        if( x > 1) res.push_back(P{x,1});
        return res;
}

void dfs(int i,int n,ll now){
        if(i == n) prime.push_back(now);
        else{
                ll one = 1;
                rep(j,ans1[i].second+1){
                        dfs(i+1,n,now*one);
                        one *= ans1[i].first;
                }
        }
}

int main(){
        ll n;
        cin >> n;
        ans1 = getPrimes(n);
        ans2 = getPrimes(n-1);
        ll ans = 0;
        ll now = 1;
        for(auto p:ans2){
                now *= p.second + 1;
        }
        now --;
        ans += now;
        dfs(0,ans1.size(),1);
        sort(prime.begin(),prime.end());
        prime.erase(unique(prime.begin(),prime.end()),prime.end());
        for(ll p: prime){
                if(p==1) continue;
                if(n%p ==0){
                    ll q = n/p;
                    while(q%p == 0) q /= p;
                    if((q-1)%p ==0) ans++;
                }
        }
        cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import math
N,K = map(int, input().split())
A_list = list(map(int, input().split()))
lb = 0
ub = 10**9

for i in range(100):
    middle = (lb + ub)/2
    sumi = -N
    for a in A_list:
        sumi += math.ceil(a/middle)

    if sumi <= K:
        ub = middle
    else:
        lb = middle
print(math.ceil(middle))

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

const int MAX = 50;
const string RESET = "...................................................."; // 点の数は52個 50+左右の2個ね
const int DMAX = 8;
const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const char BOMB = '#';
int main() {
	int H, W;
	cin >> H >> W;
	string S[MAX + 2];
	S[0] = RESET;
	S[H + 1] = RESET;
	for (int i = 1;i < H + 1;i ++) {
		cin >> S[i]; // こういう二次元マップは高さ-横の順のループになるから気を付けてね
		S[i] = "." + S[i] + "."; // 範囲外参照阻止用
	}
	for (int i = 1;i < H + 1;i ++) {
		for (int j = 1;j < W + 1;j ++) { // この時点でマップの各マス
			if (S[i][j] == BOMB) continue; // 爆弾マスは調べる必要ないから
			S[i][j] = '0'; // まだ地雷をチェックしてないので0個
			for (int k = 0;k < DMAX;k ++) { // 周囲8マスをチェック
				if (S[i + dy[k]][j + dx[k]] == BOMB) { // もし周囲に爆弾があったら
					S[i][j] ++; // 爆弾数を1追加
				}
			}
		}
	}
	
	for (int i = 1;i < H + 1;i ++) {
		cout << S[i].substr(1, W); // 範囲外参照の阻止で入れた点はちゃんと除外しようね
		if (i < H) cout << endl; // 改行を忘れずに
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、周囲を空きマスで埋めておくことで、周囲8マスを参照したときにうっかり範囲外参照をしちゃうのを阻止するよ
これは本当に一般的なテクニックだから、覚えておくようにね

次に、周囲8マスの参照だけど、今回のdx及びdyみたいな形式を使うと参照が楽になるよ
これは、私の場合右から時計回りに参照するときのxとyの差分座標を入れてるよ
オーダーはO(HW)
*/

Measured memory_bytes: 256