akhauriyash/Code-Regression huggingface dataset:
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$A = $key->A[0];
$B = $key->A[1];
$C = $key->A[2];
if (($A[strlen($A)-1]==$B[0]) && ($B[strlen($B)-1]==$C[0])) {
  printf("YES\n");
}
else  {
  printf("NO\n");
}


Measured memory_bytes: 3576
#include <stdio.h>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STR(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) {if((a)<(b))(a)=(b);}
#define MINS(a,b) {if((a)>(b))(a)=(b);}

int main(){
	unsigned long long N;
	scanf("%llu", &N);
	for(unsigned long long h = 1; h <= 3500; h++) for(unsigned long long n = 1; n <= 3500; n++){
		if(4*h*n > N*n + N*h && N*h*n % (4*h*n - N*n - N*h) == 0){
			printf("%llu %llu %llu\n", h, n, N*h*n/(4*h*n - N*n - N*h));
			return 0;
		}
	}
	printf("NOT FOUND\n");
}

Measured memory_bytes: 128
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+1):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  div_cdd=[0]*n
  for i in range(n):
    div_cdd[i]=a[i]%cdd
  div_cdd=sorted(div_cdd)
  pstv,ngtv=0,-sum(div_cdd)
  # calc need
  if pstv==-ngtv:
    ans=max(ans,cdd)
    continue
  for i in range(n):
    pstv+=cdd-div_cdd[-1-i]
    ngtv+=div_cdd[-1-i]
    if pstv==-ngtv: break
  ans=max(ans,cdd) if pstv<=k else ans
    
print(ans)

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

using ll = long long; 
using P = pair<int,int>;

int main() {

  int k, x;
  cin >>  k >> x;

  if (500*k >= x){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, Z, W;
	cin >> N >> Z >> W;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];

	reverse(a.begin(), a.end());
	vector<ll> sen(N-1), go(N-1);
	REP(i, N-1){
		ll tmp = abs(a[i+1]-a[0]);
		REP(j, i){
			tmp = max(go[j], tmp);
		}
		sen[i] = tmp;

		tmp = abs(a[i+1]-a[0]);
		REP(j, i){
			tmp = min(sen[j], tmp);
		}
		go[i] = tmp;
	}
	ll res = abs(W-a[0]);
	REP(i, N-1) res = max(res, go[i]);
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<long long>>dp;
int f(vector<vector<int>>&A,int i,long long &mask)
{
    //cout<<"ASDf";
    if(i==A.size())
        return 1;
    if(dp[i][mask]!=-1)
        return dp[i][mask];
    long long ans=0;
    for(int j=0;j<A[i].size();j++)
    {
        if(A[i][j]&&!((1<<j)&mask))
        {
            long long temp=mask;
            mask=mask|(1<<j);
            ans=(ans+f(A,i+1,mask))%1000000007;
            mask=temp;
        }
    }
    return dp[i][mask]=ans;
}
int main()
{
    int n;
    cin>>n;
    vector<vector<int>>A(n,vector<int>(n));
    dp.resize(n,vector<long long>(1<<(n+1),-1));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>A[i][j];
    long long mask=1<<(n);
    cout<<f(A,0,mask);
}

Measured memory_bytes: 721280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
const ll INF =1LL << 62;

ll dp[31];
int main(){
	for(int i=0;i<31;i++){
		dp[i]=0;
	}
	dp[0]=1;
	for(int i=1;i<31;i++){
		dp[i]+=dp[i-1];
		if(i>1)dp[i]+=dp[i-2];
		if(i>2)dp[i]+=dp[i-3];
	}
	while(1){
		int n;cin >>n;
		if(n==0)break;
		cout << (dp[n]+3649)/3650<< endl;
	}
}



Measured memory_bytes: 3068
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

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

    void run() {

        long x = sc.nextLong();

//        System.out.println((long)Math.pow(1000, 5));
//        System.out.print((long)Math.pow(1001, 5));


        for (int a=-1000; a<=1000; a++) {
            for (int b=-1000; b<=1000; b++) {
                long calc = (long)Math.pow(a, 5) - (long)Math.pow(b, 5);
                if (calc == x) {
                    System.out.print(a + " ");
                    System.out.print(b);
                    return;
                }
            }
        }

    }
}


Measured memory_bytes: 38640
//AtCoder ABC045 A - 台形 / Trapezoids
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    int a,b,h;
    cin>>a>>b>>h;
    int ans=(a+b)*h/2;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n,x1,y1,z1,w1,x2,y2,z2,w2;
    while (cin>>n, n) {
        for (int i=0; i<n; ++i) {
            cin>>x1>>y1>>z1>>w1>>x2>>y2>>z2>>w2;
            cout << (x1 * x2) - (y1 * y2) - (z1 * z2) - (w1 * w2) << " "
                 << (x1 * y2) + (x2 * y1) + (z1 * w2) - (w1 * z2) << " "
                 << (x1 * z2) + (z1 * x2) + (w1 * y2) - (y1 * w2) << " "
                 << (x1 * w2) + (w1 * x2) + (y1 * z2) - (z1 * y2) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
 
void solve(){
	int k,t;
	cin>>k>>t;
	vector<int>a(t);
	rep(i,t)cin>>a[i];
	sort(a.begin(),a.end());
	int ans=a.back();
	rep(i,t-1)ans-=a[i];
	if(ans<1)ans=1;
	cout<<ans-1<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
const int N=200500;
int n,K,W;
int w[N];
int v[N];
int dp[101][100100];
int f(int i, int s){
	if(s>=K)return 0;
	if(i==n)return 1e9+10;
	int &r=dp[i][s];
	if(r!=-1)return r;
	r=f(i+1,s);
	r=min(r,f(i+1,s+v[i])+w[i]);
	return r;
}
int main(){FIN;
	cin>>n>>W;
	fore(i,0,n)cin>>w[i]>>v[i];
	int l=0,r=1e5+10;
	while(r-l>1){
		K=(l+r)/2;
		memset(dp,-1,sizeof dp);
		if(f(0,0)<=W)l=K;
		else r=K;
	}
	cout<<l<<"\n";
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 6000;

int n;
string str;
int a[N + 5], b[N + 5];

string solve0(int l, int r) {
    string res;
    int p = -1;
    for(int i = l; i <= r; ++i) if(a[i] > p) {
        p = b[i];
        res += "ab";
    }
    return res;
}

bool vis[N + 5];
string solve1(int l, int r) {
    string res;
    for(int i = l; i <= r; ++i) vis[a[i]] = vis[b[i]] = true;
    for(int i = l; i <= r; ++i) {
        string temp;
        for(int j = 0; j < (n << 1); ++j) if(vis[j]) temp += str[j];
        vis[a[i]] = vis[b[i]] = false;
        chkmax(res, temp);
    }
    return res;
}

int s[N + 5];
int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    std::cin >> str;

    for(int i = 0; i < (n << 1); ++i) {
        if(str[i] == 'a') a[++ a[0]] = i, ++ s[i]; else b[++ b[0]] = i, -- s[i];
        s[i + 1] = s[i];
    }

    string tmp, ans;
    vector<string> stk;

    for(int i = 1; i <= n; ++i) {
        int j = i;
        if(a[i] < b[i]) {
            while(s[b[j]] && j + 1 <= n && a[j + 1] < b[j + 1]) ++ j;
            tmp = solve0(i, j), i = j;
        } else {
            while(s[a[j]] && j + 1 <= n && a[j + 1] > b[j + 1]) ++ j;
            tmp = solve1(i, j), i = j;
        }

        stk.push_back(tmp);
    }

    std::reverse(stk.begin(), stk.end());
    for(auto t : stk) chkmax(ans, t + ans);
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 512
class SWAG():
    __slots__=('unit','f','fold_r','fold_l','data_r','data_l')
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.fold_r=[unit]
        self.fold_l=[unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        for t in data[sep:]:
            self.append(t)
        for t in data[sep-1::-1]:
            self.appendleft(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.__init__(self.unit,self.f,self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.__init__(self.unit,self.f,self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Measured memory_bytes: 25884
s = input()
a = int(s[0:2])
b = int(s[2:])

if 13 <= a or a == 0:
    if 1 <= b and b <= 12:
        print('YYMM')
    else:
        print('NA')
else:
    
    if 1<= b  and b<= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, a[N], ans;

int main()
{
      cin >> n;

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

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

      cout << ans << endl;
}


Measured memory_bytes: 640
### main

loop do
  n = gets.to_i
  break if n == 0

  bevs = []
  bods = []
  for b in gets.split.map(&:to_i)
    if (b & 1) == 0
      bevs << b
    else
      bods << b
    end
  end
  bevs.sort!
  bods.sort!
  #p bevs
  #p bods

  fact2 = 1
  b1 = bevs[0]
  while (b1 & 1) == 0
    b1 >>= 1
    fact2 <<= 1
  end
  #p fact2

  bev0 = bevs[0] / fact2
  bev1 = bevs[1] / fact2
  bod0 = bods[0]
  #p [bev0, bev1, bod0]

  b0 =  Math.sqrt(bev0 * bev1 / bod0 + 0.5).to_i * fact2

  puts b0
  puts bevs.map{|bev| bev / b0}.join(' ')
end

Measured memory_bytes: 9932
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int w, h;
int dxy[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
char tiles[21][21];
char visited[21][21];

void rec(int y, int x)
{
    visited[y][x] = 1;
    
    for (int i=0; i<4; i++)
    {
        int x1, y1;
        x1 = x + dxy[i][0];
        y1 = y + dxy[i][1];

        if (tiles[y1][x1] == '.' && visited[y1][x1] ==0 && x1 >= 0 && x1 < w && y1 >= 0 && y1 < h)
        {
            
            rec(y1, x1);
        }
    }
}

int main(void)
{
    while (scanf("%d %d", &w, &h) && w && h)
    {
        

        int  x0, y0;

        

        for (int i=0; i<h; i++)
        {
            for (int j=0; j<w; j++)
            {
                cin >> tiles[i][j];

            }
        }
        for (int i=0; i<h; i++)
        {
            for (int j=0; j<w; j++)
            {
                if (tiles[i][j] == '@')
                {
                    y0=i;
                    x0=j;
                }
            }
        }
        memset(visited, 0, sizeof(visited));
        rec(y0, x0);
        //printf("%d %d", x0, y0);
        int cnt=0;
        for (int i=0; i<h; i++)
        {
            for (int j=0; j<w; j++)
            {
                cnt += visited[i][j];
            }
        }
        printf("%d\n", cnt);

    }
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    int a[n];
    int sum=0;
    for (int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    if (x<sum) cout<<-1;
    else cout<<x-sum;
}

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

N = int(input())
statements = list(str(input()))
patterns = [['S', 'S'], ['S', 'W'], ['W', 'S'], ['W', 'W']]
null_flg = 1

for pattern in patterns:
    animals = pattern
    for index in range(1, N-1):
        rule = statements[index] + animals[index]
        if rule == 'oS':
            animals.append(animals[index - 1])
        elif rule == 'xS':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'oW':
            if animals[index - 1] == 'S':
                animals.append('W')
            else:
                animals.append('S')
        elif rule == 'xW':
            animals.append(animals[index - 1])

    last_flg = first_flg = 0
    last = statements[-1] + animals[-1]
    if last == 'oS':
        if animals[0] == animals[-2]:
            last_flg = 1
    elif last == 'xS':
        if animals[0] != animals[-2]:
            last_flg = 1
    elif last == 'oW':
        if animals[0] != animals[-2]:
            last_flg = 1
    elif last == 'xW':
        if animals[0] == animals[-2]:
            last_flg = 1

    if last_flg:
        first = statements[0] + animals[0]
        if first == 'oS':
            if animals[-1] == animals[1]:
                print(''.join(animals))
                null_flg = 0
                break
        elif first == 'xS':
            if animals[-1] != animals[1]:
                print(''.join(animals))
                null_flg = 0
                break
        elif first == 'oW':
            if animals[-1] != animals[1]:
                print(''.join(animals))
                null_flg = 0
                break
        elif first == 'xW':
            if animals[-1] == animals[1]:
                print(''.join(animals))
                null_flg = 0
                break

if null_flg:
    print('-1')

Measured memory_bytes: 7376
import sys
N,M=map(int,input().split())

A=[list(input()) for _ in range(N)]
B=[list(input()) for _ in range(M)]
offset=N-M
 
for row_offs in range(offset+1):
  for col_offs in range(offset+1):
    is_match=True
    for row in range(M):
      img_row=A[row+row_offs][col_offs:col_offs+M]
      tmp_row=B[row][:]
      if img_row != tmp_row:
        is_match=False
    if is_match:
      print("Yes")
      sys.exit()
print("No")


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


#define ll                  long long
#define scl(n)              cin>>n;
#define scc(c)	            cin>>c;
#define fr(i,n)             for (ll i=0;i<n;i++)
#define fr1(i,n)            for(ll i=1;i<=n;i++)
int main()
{
  ll i, j;
  string s, s1;
  cin>>s;
  if(s[2]==s[3] and  s[4]==s[5])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: f64,
        b: f64,
        x: f64,
    }
    println!(
        "{}",
        if 2f64 * x <= a * a * b {
            (a * b * b / 2f64 / x).atan().to_degrees()
        } else {
            (2f64 * b / a - 2f64 * x / a / a / a).atan().to_degrees()
        }
    );
}


Measured memory_bytes: 2836
class Array
def gcd2
  self.inject{|a,b| a.gcd(b)}
end
end

ary =$stdin.readlines
a =ary[0].split.map!(&:to_i)
n = a[0]
x = a[1]
cities = ary[1].chomp.split.map!(&:to_i)

    array = []
    for i in (0..n-1)
      array.push((cities[i] - x).abs)
    end
  answer = array.gcd2
=begin
  p n
  p x
  p cities
  p array
=end
puts answer


Measured memory_bytes: 9476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
template <typename T> 
using lim = numeric_limits<T>;
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b; cin >> a >> b;
    cout << a*b << "\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int d[n];
  for(int i = 0; i < n; i++){
    cin>>d[i];
  }
  sort(d,d+n);
  cout<<d[n/2]-d[n/2-1]<<endl;
  return 0;
}




Measured memory_bytes: 640
#include <stdio.h>
 
int c, p, l, lp;
long long r;
int main() {
  for(; (c = getchar()) != EOF && c > ' '; r += ++l) {
    if(c != p) { 
      if(c == '<')
        r -= l < lp ? l : lp;
      p = c, lp = l, l = 0;
    }
  }
  if(p == '>')
    r -= l < lp ? l : lp;
  printf("%lld\n", r);
  return 0;
}


Measured memory_bytes: 128
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    c = rl().rstrip()
    
    counter = Counter(c)
    red = counter['R']
    white = counter['W']
    
    red -= c[:red].count('R')
    white -= c[-white:].count('W')
    print(min(red, white))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 73984
#pragma optimization_level 3
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  998244353;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll k, n, l[N], r[N];
ll dp[N], pre[N];

void MAIN(int tc){
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        cin >> l[i] >> r[i];
    }

    pre[1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            ll L = l[j], R = r[j];
            if(i - L <= 0) continue;
            dp[i] += (pre[max(i - L, 0ll)] - pre[max(i - R - 1, 0ll)] + MOD) % MOD;
            dp[i] %= MOD;
        }
        pre[i] += (pre[i - 1] + dp[i]) % MOD;
        pre[i] %= MOD;
        //deb3(i, pre[i], dp[i]);
    }

    deb1(dp[n]);
}

int main(){
    ios:: sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed; cout<<setprecision(10);

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

Measured memory_bytes: 6744
N=int(input())
hlist=list(map(int,input().split()))
dp=[10*5]*N
dp[0]=0
dp[1]=abs(hlist[1]-hlist[0])

if N>2:
    for i in range (2,N):
        c1=abs(hlist[i]-hlist[i-2])+dp[i-2]
        c2=abs(hlist[i]-hlist[i-1])+dp[i-1]
        dp[i]=min(c1,c2)

print(dp[-1])

Measured memory_bytes: 20600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int N, M, Q;
vi a, b, c, d;

int dfs(int i, vi &A) {
    if (i == N) {
        int ans = 0;
        rep(j, Q) {
            if (A.at(b.at(j) - 1) - A.at(a.at(j) - 1) == c.at(j)) ans += d.at(j);
        }
        return ans;
    }
    int ret = 0;
    rep2(j, 1, M + 1) {
        if (i == 0) {
            A.push_back(j);
            ret = max(dfs(i + 1, A), ret);
            A.pop_back();
        } else {
            if (A.at(A.size() - 1) <= j) {
                A.push_back(j);
                ret = max(dfs(i + 1, A), ret);
                A.pop_back();
            }
        }
    }
    return ret;
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i, Q) { cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); }
    vi A;
    cout << dfs(0, A) << endl;
}


Measured memory_bytes: 3608
import Control.Monad
import Control.Applicative
import Data.List

main :: IO()
main = getLine >>= main' . read
    where
        main' 0 = return ()
        main' _ = do
            as <- map read . words <$> getLine :: IO [Int]
            print $ solve as 
            main

solve :: [Int] -> Int
solve as = head $ sort $ f $ sort as

f :: [Int] -> [Int]
f (_:[])= []
f (a:as) = ((head as) - a) : (f as)
 

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    int t=0;
    if(a<0){
        t+=abs(a)*c;
        t+=d;
        t+=b*e;
    }else{
        t+=(b-a)*e;
    }
    cout << t << endl;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, int> pi;
const int MAXN = 200005;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct edg{
	int s, e;
	lint x;
	bool operator<(const edg &ee)const{
		return x < ee.x;
	}
};

int n, a[MAXN], proc[MAXN];
int sz[MAXN], msz[MAXN];
vector<edg> ans;
vector<pi> gph[MAXN];
vector<int> cdfn;

void dfs(int x, int p){
	cdfn.push_back(x);
	sz[x] = 1;
	msz[x] = 0;
	for(auto &i : gph[x]){
		if(!proc[i.second] && i.second != p){
			dfs(i.second, x);
			sz[x] += sz[i.second];
			msz[x] = max(msz[x], sz[i.second]);
		}
	}
}

int get_center(int x){
	cdfn.clear();
	dfs(x, -1);
	pi ans(1e9, x);
	for(auto &i : cdfn){
		int w = max(msz[i], sz[x] - sz[i]);
		ans = min(ans, pi(w, i));
	}
	return ans.second;
}

vector<pi> dfn;
lint dis[MAXN];

void dfs2(int x, int p){
	dfn.push_back(pi(a[x] + dis[x], x));
	for(auto &i : gph[x]){
		if(proc[i.second] || i.second == p) continue;
		dis[i.second] = dis[x] + i.first;
		dfs2(i.second, x);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<n; i++){
		int s, e, x;
		scanf("%d %d %d",&s,&e,&x);
		gph[s].push_back(pi(x, e));
		gph[e].push_back(pi(x, s));
	}
	queue<int> que;
	que.push(1);
	while(!que.empty()){
		int x = que.front();
		que.pop();
		x = get_center(x);
		dfn.clear();
		dis[x] = 0;
		dfs2(x, -1);
		sort(dfn.begin(), dfn.end());
		for(int i=1; i<dfn.size(); i++){
			ans.push_back({dfn[0].second, dfn[i].second, 
					dfn[0].first + dfn[i].first});
		}
		proc[x] = 1;
		for(auto &i : gph[x]){
			if(!proc[i.second]){
				que.push(i.second);
			}
		}
	}
	sort(ans.begin(), ans.end());
	disj.init(n);
	lint dap = 0;
	for(auto &i : ans){
		if(disj.uni(i.s, i.e)) dap += i.x;
	}
	cout << dap << endl;
}


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

int main(){

	char* str;
	int i = 0;
	int n = 1024;

	str = (char*)calloc(n,sizeof(char));

	fgets(str,n,stdin);

	while( str[i] != '\0' ){
		if( str[i] == ',' ) str[i] = ' ';
		i++;
	}

	printf("%s",str);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
vector<int> g[100005];
ll q,n;
ll a[1500005];
int main()
{
    //IOS;
    ll x,y;
    while(cin>>x>>y)
    {
        ll sum=0;
        for(sum=0;x<=y;x=x*2,sum++);
        cout<<sum<<"\n";
    }
    return 0;
}



Measured memory_bytes: 4096
# C - One Quadrillion and One Dalmatians
n = int(input())
dic = dict()

import string
i = 1

for s in string.ascii_lowercase:
	dic[i % 26] = s
	i += 1	

name = ''
i = 1

while True:
	mod = n % 26
	name += dic[mod]
	
	if n > 26:
		if mod == 0:
			mod = 26
		
		n = (n - mod) // 26
		i += 1
	else:
		break

print(''.join(list(reversed(name))))

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

struct query {
  int a, b, c, d;
};
struct manyReq {
  int n, m;
  vector<query> q;
  int ans = 0;

  manyReq(int n, int m, vector<query> q) : n(n), m(m), q(q) {}

  int get_score(vector<int> &A) {
    int s = 0;
    for (query qi : q) {
      if (A.at(qi.b) - A.at(qi.a) == qi.c) s += qi.d;
    }
    return s;
  }

  void dfs(vector<int> A) {
    if (A.size() == (unsigned int)n + 1) {
      int now = get_score(A);
      ans = max(ans, now);
      return;
    }

    A.push_back(A.back());
    while (A.back() <= m) {
      dfs(A);
      A.back()++;
    }
  }
};


int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<query> Q(q);
  for (auto &qi : Q) {
    cin >> qi.a >> qi.b >> qi.c >> qi.d;
  }
  manyReq mr(n, m, Q);
  mr.dfs(vector<int>(1, 1));
  cout << mr.ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////
#define R(i,n) for(int i=0;i<(n);i=i+1)
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,a[100010],ans,cnt;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		if(i){
			if(a[i-1]>=a[i])cnt++;
			else cnt=0;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	
	return 0;
}


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

ll gcd(ll a,ll b){
  ll x = max(a,b);
  ll y = min(a,b);

  ll r;
  do{
    r = x % y;
    x = y;
    y = r;
  }while(r!= 0);

  return x;
}

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

  vector<int> L(N),R(N);
  L[0]=a[0];
  for(int i=1;i<N;i++){
    L[i]=gcd(L[i-1],a[i]);
  }
  R[N-1]=a[N-1];
  for(int i=N-2;i>=0;i--){
    R[i]=gcd(R[i+1],a[i]);
  }

  ll ans=0;
  rep(i,N){
    ll w=0;
    if(i==0){ w = R[1];}
    else if(i==N-1){w =L[N-2];}
    else{
      w = gcd(L[i-1],R[i+1]);
    }
    ans = max(ans,w);
  }
  cout << ans << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string S, T; cin >> S >> T;
    vec cS(26, 0), cT(26, 0);
    REP(i, S.size()){
        cS[(int)(S[i] - 'a')]++;
        cT[(int)(T[i] - 'a')]++;
    }
    SORT(cS); SORT(cT);
    string ans = "Yes";
    REP(i, 26) if(cS[i] != cT[i]) ans = "No";
    cout << ans;
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 1; i < n-1; ++i) {
        if((a[i-1] < a[i] && a[i] < a[i+1]) 
        || (a[i-1] > a[i] && a[i] > a[i+1])) {
            ans++;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N, M, K;
    cin >> N >> M >> K;

    vector<ll> A(N), B(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];


    for (int i = 1; i < N; ++i) {
        A[i] += A[i - 1];
    }

    for (int i = 1; i < M; ++i) {
        B[i] += B[i - 1];
    }

    int ans = upper_bound(all(B), K) - B.begin();
    for (int i = 0; i < N; ++i) {
        if (A[i] > K) { continue; }
        chmax(ans, i + 1);

        auto pt = upper_bound(all(B), K - A[i]);
        if (pt == B.begin()) continue;
        int tmp = (i + 1) + (pt - B.begin());
        chmax(ans, tmp);
    }

    cout << ans << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n,a,b,ans=0;
	cin>>n>>a>>b;
	int k=a+b,m,d;
	d=n/k;
	m=n%k;
	ans=a*d;
	if(m>=a){
		ans+=a;
	}
	else
		ans+=m;
	cout<<ans<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int D;
  cin >> D;
  if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
  if (D == 23) cout << "Christmas Eve Eve" << endl;
  if (D == 24) cout << "Christmas Eve " << endl;
  if (D == 25) cout << "Christmas" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
li = []
C = sorted(Counter(a).items())
for i in range(len(C)):
    if C[i][1] >= 4:
        li.append(C[i][0])
        li.append(C[i][0])
    elif C[i][1] >= 2:
        li.append(C[i][0])
if len(li) <= 1:
    print(0)
    sys.exit()
print(li[-1]*li[-2])

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

ll inf = 1000000LL * 1000000LL * 1000000LL;
ll mod = 1000000007;

int main(int argc , char** argv){
	int H , W;
	cin >> H >> W;
	vector<vector<char>> mat(H,vector<char>(W));
	vector<vector<int>> dp(H,vector<int>(W,0));
	for(int i = 0 ; i < H ; ++i){
		for(int j = 0 ; j < W ; ++j){
			cin >> mat[i][j] ;
		}
	}dp[0][0] = 1;
	for(int i = 1 ; i < H ; ++i){
		if(mat[i][0] == '#')break;
		else dp[i][0] = 1;
	}
	for(int i = 1 ; i < W ; ++i){
		if(mat[0][i] == '#')break;
		else dp[0][i] = 1;
	}
	for(int i = 1 ; i < H ; ++i){
		for(int j = 1 ; j < W ; ++j){
			if(mat[i][j] == '#')continue;
			if(mat[i-1][j] == '.')dp[i][j] = (dp[i][j] + dp[i-1][j] % mod ) % mod;
			if(mat[i][j-1] == '.')dp[i][j] = (dp[i][j] + dp[i][j-1] % mod ) % mod; 
		}
	}
	cout << dp[H-1][W-1] << endl;
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    string s;
    cin >> s;

    s.pop_back();
    s.pop_back();

    ll half = s.size()/2;

    string left = "";
    string right = "";

    rep(i, half){
        left += s[i];
        right += s[half+i];
    }    
    
    while(left != right){
        right = left.back() + right;
        left.pop_back();
        right.pop_back();
        right.pop_back();
    }

    cout << left.size()*2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
map<int,int>mp;
int main()
{
    ll a1,a2,a3,b1,b2,b3,c1,c2,c3,n,x;
    cin>>a1>>a2>>a3>>b1>>b2>>b3>>c1>>c2>>c3;
    cin>>n;
    while(n--)
    {
        cin>>x;
        mp[x]=1;
    }
    if((mp[a1]==1&&mp[a2]==1&&mp[a3]==1)||(mp[a1]==1&&mp[b1]==1&&mp[c1]==1)||(mp[a1]==1&&mp[b2]==1&&mp[c3]==1)||(mp[a2]==1&&mp[b2]==1&&mp[c2]==1)||(mp[a3]==1&&mp[b3]==1&&mp[c3]==1)||(mp[b1]==1&&mp[b2]==1&&mp[b3]==1)||(mp[c1]==1&&mp[c2]==1&&mp[c3]==1)||(mp[a3]==1&&mp[b2]==1&&mp[c1]==1))
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int i, n, a=0;
  string c;
  cin >> n;
  for (i=0;i<n;i++) {
    cin >> c;
    if (c=="Y"){
      a = 1;
      break;
    }
  }
  if(a==0) {
    cout << "Three" << endl;
  }else{
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

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

// 非再帰
int gcd(int a, int b) {
  int r1 = b;
  int r2 = a;
  while (r2) {
    int r3 = r1 % r2; // r1 = q * r2 + r3
    r1 = r2;
    r2 = r3;
  }
  return r1;
}

int main() {
  int a, b;
  std::cin >> a >> b;
  std::cout << gcd(a, b) << std::endl;
}



Measured memory_bytes: 3092
def inversePermutation(arr, size):
	arr2 = [0] * (size)
	for i in range(0, size):
		arr2[arr[i] - 1] = i + 1
	return " ".join(map(str, arr2))

size = int(input())
arr = list(map(int, input().split()))

print(inversePermutation(arr, size))



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


int main(void)
{
    int N, tmp;
    int f[10101]={0};
    cin>>N;

    int cnt=0;
    REP(i, 1, 100){
        REP(j, 1, 100){
            REP(k, 1, 100){
                tmp=i*i+j*j+k*k+i*j+j*k+k*i;
                if(tmp<=N){
                    f[tmp]++;
                }
            }
        }
    }

    REP(i, 1, N+1){
        cout<<f[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int n, t, a;

int main(){
    cin >> n;
    long long left = 1LL, right = 1LL;
    rep(i, n){
        cin >> t >> a;
        long long ma = left / t + (left % t != 0),
                  to = right / a + (right % a != 0);
        long long va = max(ma, to);
        left = va * t;
        right = va * a;
    }
    cout << left + right << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

cmap = []
for _ in range(10):
  cmap.append(list(map(int, input().split())))

amap = []
for _ in range(h):
  amap.append(list(map(int, input().split())))

for k in range(10):
  for i in range(10):
    for j in range(10):
      if cmap[i][j] > cmap[i][k] + cmap[k][j]:
        cmap[i][j] = cmap[i][k] + cmap[k][j]

ans = 0
for alist in amap:
  for a in alist:
    if a != -1:
      ans += cmap[a][1]

print(ans)


Measured memory_bytes: 3444
import scala.io.StdIn

object Main extends App {
  val s = Array(StdIn.readLine)

  val res = s
    .filter(_.charAt(0) == 'A')
    .filter(_.count(_.isUpper) == 2)
    .map(l => l.substring(2, l.length-1))
    .exists(a => a.count(_ == 'C') == 1)

  println(if (res) "AC" else "WA")
}


Measured memory_bytes: 27092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i;
	double v[50];
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> v[i];
	}
	sort(v,v+n);
	for(i=1; i<n; ++i){
		v[0] += v[i];
		v[0] /= 2.0;
	}
	printf("%.10lf\n",v[0]);
	return 0;
}


Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
S=input()
n=len(S)
D=[0]*2019
T=[0]*(n+1)
T[0]=1
for i in range(n):
  T[i+1]=(T[i]*10)%2019

cur=0
keta=0
ans=0
D[0]+=1
for s in S[::-1]:
  cur=(cur+int(s)*T[keta])%2019
  ans+=D[cur]
  D[cur]+=1
  keta+=1
print(ans)

Measured memory_bytes: 70556
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll a[100005];
ll n,m;
 
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	bool flag=false;
	if(a[n-1]-a[0]==1){
		ll kazu=0;
		for(i=0;i<n;i++){
			if(a[i]==a[0])kazu++;
		}
		if((a[0]-kazu+1)>=1 && (n-kazu)/(a[0]-kazu+1)>=2)flag=true;
	}else if(a[n-1]-a[0]==0){

		

		if(n/a[0]>=2 || n==a[0]+1)flag=true;
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 5760
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = None
dif = 10**10

for i in range(-1000, 1000):
    if i in p:
        continue
    if abs(i - x) < dif:
        dif = abs(i - x)
        ans = i

print(ans)


Measured memory_bytes: 64252