akhauriyash/Code-Regression huggingface dataset:
import sys
import collections

n = -1
while True:
    if n != -1:
        print '#'
    n = int(sys.stdin.readline())
    if n == 0:
        break
    
    result = []
    for i in xrange(n):
        read = raw_input().split()
        L = read[0]
        P, A, B, C, D, E, F, S, M = map(int, read[1:])
        time = A + B + C + (D + E) * M
        profit = F * M * S - P
        result.append((float(profit) / time, L))
    result.sort(key = lambda x: (-x[0], x[1]))
    for r in result:
        print r[1]

Measured memory_bytes: 4616
#include <stdio.h>

#define MAX_N 100

int bubbleSort(int A[], int N);

int main() {
  int N;
  int A[MAX_N];
  int cnt;
  int i;

  scanf("%d", &N);
  
  for(i = 0; i < N; ++i)
    scanf("%d", A+i);

  cnt = bubbleSort(A, N);
  
  for(i = 0; i < N; ++i)
    printf("%d%c", A[i], " \n"[i==N-1]);
  
  printf("%d\n", cnt);

  return 0;
}

int bubbleSort(int A[], int N) {
  int cnt = 0;
  int tmp;
  int flag = 1;
  int j;

  while(flag) {
    flag = 0;
    for(j = N-1; j > 0; --j) {
      if(A[j] < A[j-1]) {
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        cnt++;
      }
    }
  }
  return cnt;
}



Measured memory_bytes: 2040
N , M = map(int,input().split())
MOD = 10 ** 9 + 7
if abs(N - M) > 1:
    print("0")
    exit()
large = max(N , M)
small = min(N , M)
N_fuct = 1
M_fuct = 1
for i in range(2,large + 1):
    N_fuct *= i
    N_fuct %= MOD
for i in range (2,small + 1):
    M_fuct *= i
    M_fuct %= MOD
ans = N_fuct * M_fuct
if large == small:
    ans *= 2
    print(ans % MOD)
else:
    print(ans % MOD)

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

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

def main():
    mod=10**9+7
    T=LI()
    A=LI()
    B=LI()
    
    
    d1=(A[0]-B[0])*T[0]
    d2=(A[1]-B[1])*T[1]
    
    if d1>=0:
        #最初は必ず正の方向へいかないように調整
        d1*=-1
        d2*=-1
        
    
    if d1+d2==0:
        print("infinity")
    elif d1==0:#d1=0のパターンを排除した
        print(0)
    elif d1+d2<=0:
        print(0)
    else:
        cnt=(-1*d1)//(d1+d2)
        ans=cnt*2+1
        if cnt*(d1+d2)==-1*d1:
            ans-=1
        print(ans)
        
        
        
    

main()


Measured memory_bytes: 38384
n = int(input())
A = list(map(int, input().split()))
s = 0

def count(A, n):
    for i in range(n):
        if (A[i] % 2 == 1) or (A[i] == 0):
            return False
        A[i] = A[i] // 2
    return True

while True:
    if count(A, n):
        s += 1
    else:
        break
    
print(s)


Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int x = X;
    int y = Y;
    int z = 0;
    int ans = A * x + B * y;
    while (x > 0 || y > 0) {
        z += 2;
        x = max(x - 1, 0);
        y = max(y - 1, 0);
        ans = min(ans, A * x + B * y + C * z);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
typedef std::pair<int,int> P;
    ll N;
    ll A[100010],B[100010],C[100010];
    ll ans;
    int ok=0,ng=100001,mid;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N)cin>>A[i];
    REP(i,N)cin>>B[i];
    REP(i,N)cin>>C[i];
    sort(A,A+N);sort(B,B+N);sort(C,C+N);
    REP(i,N){
        bool x=false,y=false;
        if(!(A[0]<B[i]))x=true;
        if(!(B[i]<C[N-1]))y=true;
        DEB(B[i])TF(x)TF(y)END
        ll res=1;
        if(x||y){
            ans+=0;
            continue;
        }
        ok=0,ng=N;
        while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            DEB(mid)END
            if(A[mid]<B[i])ok=mid;
            else ng=mid;
        }
        res*=ok+1;DEB(ok)DEB(ng)
        ok=N-1,ng=-1;DEB(res)END
        while(abs(ok-ng)>1){
            mid=(ok+ng)/2;
            DEB(mid)END
            if(B[i]<C[mid])ok=mid;
            else ng=mid;
        }
        res*=N-(ok);
        ans+=res;
        DEB(ok)DEB(ng)END
        DEB(ans)DEB(res)END
    }
    cout<<ans<<endl;

    return 0;
}
/*6
2 3 6 14 53 159
58 9 79 323 84 6
2 50 79 288 383 2643
5*4
3*5*/


Measured memory_bytes: 2560
int main(){
    
    int card[4][13]={};
    int n, num, i, j;
    char m;
    
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf(" %c %d", &m, &num);
        if(m=='S') card[0][num-1]=1;
        else if(m=='H') card[1][num-1]=1;
        else if(m=='C') card[2][num-1]=1;
        else if(m=='D') card[3][num-1]=1;
    }
    
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(i==0&&card[i][j]==0){
             printf("S %d\n", j+1);
            }else if(i==1&&card[i][j]==0){
                printf("H %d\n", j+1);
            }
            else if(i==2&&card[i][j]==0){
             printf("C %d\n", j+1);
            }
            else if(i==3&&card[i][j]==0){
             printf("D %d\n", j+1);
            }
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 2104
a = input()
b = input().split()
c = [0, 0, 0, 0, 0, 0, 0, 0]
d = 0
e = 0
for i in b:
    j = 0
    while j < len(c):
        if j == 0 and c[j] == 0 and (1 <= int(i) < 400):
            c[j] += 1
            d += 1
        elif c[j] == 0 and (400 * j <= int(i) < 400 * (j+1)):
            c[j] += 1
            d += 1
        j += 1
    if int(i) >= 3200:
        e += 1
min, max = d, d+e
if d == 0:
    min = 1
print(min, max)

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

signed main()
{
	int w,h,x,y;
	cin >> w >> h >> x >> y;
	int t = h*w;
		cout << fixed << setprecision(20) << double(0.5*t) << " ";
		cout << (2*x == w && 2*y == h?'1':'0');
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}

int main(){
	Speed_UP
  ll x;
  cin>>x;
  if(x==0)
    cout<<"1";
  else
    cout<<"0";



}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string a,b;
    std::cin >> a >> b;
    if(a.size()>b.size()){
        std::cout << "GREATER" << "\n";
        return 0;
    }

    if(a.size()==b.size()){
        for(int i=0; i<a.size(); i++){
            if(a[i]>b[i]){
                std::cout << "GREATER" << "\n";
                return 0;
            }
            if(a[i]<b[i]){
                std::cout << "LESS" << "\n";
                return 0;
            }
        }
        std::cout << "EQUAL" << "\n";
        return 0;
    }

    if(a.size()<b.size()){
        std::cout << "LESS" << "\n";
        return 0;
    }
}

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

int main() {
    string s; cin >> s;
    int N = s.length();

    vector<int> mi(N+1), bit(N+1);
    for(int i=N-1; i>=0; i--) {
        bit[i] = bit[i+1] | (1 << (s[i] - 'a'));
        while(bit[i] >> mi[i] & 1) mi[i]++;
        if(mi[i] == 26) mi[i] = 0,  bit[i] = 0;
    }
    string ans = "";
    for(int i=0; i<N; i++) {
        char c = 'a' + mi[i];
        ans += c;
        while(i < N && s[i] != c) i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(n) for (int i = 0; i < (n); ++i)
#define X (1000000000+7)
int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(n)
    {
        cin >> a[i];
    }
    ll cnt_corner = 0, cnt_sq = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(a[i]>a[j]){
                cnt_sq++;
                if(i<j){
                    cnt_corner++;
                }
            }
            //cout << ((i < j) ? "*" : "+");
            //cout << ((a[i] > a[j]) ? "●" : "×") << " ";
        }
        //cout << endl;
    }
    //cout<<cnt_sq<<" "<<cnt_corner;
    ll cnt=0;
    //corner
    cnt += cnt_corner*k%X;
    //sq
    cnt += cnt_sq*(k*(k-1)/2%X)%X;
    cnt %= X;
    cout<<cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int a, b;
int counto;
int aa[100009];
char bb[5];
int main() {
	int n = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> aa[i];
	}
	sort(aa, aa + n);
	cout << aa[n / 2] - aa[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
from bisect import bisect_left

n = int(input())

l_list = [int(x) for x in input().split()]
l_list.sort()

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l_list, l_list[j] + l_list[i]) - (j + 1)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


int main(int argc, char const *argv[]) {
  ll n, m, INF = 100000000000000000;std::cin >> n >> m;
  vvl d = VV(m, 3, 0, ll);
  re(i, m){
    scanf("%lld %lld", &d[i][0], &d[i][1]);
    ll tmp = 0;
    re(j, d[i][1]){
      ll c;scanf("%lld", &c);
      tmp += 1<<(c-1);
    }
    d[i][2] = tmp;
  }
  vvl dp = VV(m+1, 1<<n, INF, ll);
  dp[0][0] = 0;

  for(int i=0;i<m;i++){
    for(int j=0;j<(1<<n);j++){
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      dp[i+1][j|d[i][2]] = min(dp[i+1][j|d[i][2]], dp[i][j]+d[i][0]);
    }
  }
  std::cout << (dp[m][(1<<n)-1]==INF?-1:dp[m][(1<<n)-1]) << '\n';
  return 0;
}


Measured memory_bytes: 32384
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1e5+10;
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int mn = INT_MAX;
    for(int i = 0; i < s.size() - 2; ++i)
    {
        int x = (s[i] - '0')*100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        mn = min(mn , abs(x-753));
    }
    cout<<mn;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
nc=(b//c)-((a-1)//c)
nd=(b//d)-((a-1)//d)

import math
p=math.gcd(c,d)
q=(c*d)//p

ncd=(b//q)-((a-1)//q)
r=nc+nd-ncd
ans=(b-a+1)-r
print(ans)

Measured memory_bytes: 9204
import java.util.Scanner;

class Aizu{
	int t;
	int h;
	
	Aizu(int t,int h){
		this.t=t;
		this.h=h;
	}
}

public class Main {

	public static void main(String[] args) {
		new Main().run();
		//new AOJ2418().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);

		while(sc.hasNext()){
			int N=sc.nextInt();
			int T=sc.nextInt();
			int H=sc.nextInt();
			int L=sc.nextInt();
			int zankin=0;

			Aizu a[]=new Aizu[N];

			for(int i=0;i<N;i++){
				a[i]=new Aizu(sc.nextInt(), sc.nextInt());
			}

			for(int i=0;;i++){
				boolean flag=false;
				//0
				if(a[i%N].t+a[i%N].h==0){
					//i is winner
					System.out.println((i%N)+1);
					break;
				}
				//1
				if(a[i%N].t!=0){
					a[i%N].t--;
					T++;
					if(L<T){
						//i is winner
						System.out.println((i%N)+1);
						break;
					}
					zankin+=10;
				}
				else{
					a[i%N].h--;
					H++;
					zankin+=100;
				}
				//2
				if(90<=zankin){
					//3
					int otsuri=zankin-90;
					zankin=0;
					while(true){
						if(otsuri<=T*10){
							//10円で払える
							T-=otsuri/10;
							a[i%N].t+=otsuri/10;
							break;
						}
						else if(H!=0 && 100<=otsuri){
							H--;
							otsuri-=100;
							a[i%N].h++;
						}
						else{
							//destroy!i is winner
							flag=true;
							break;
						}
					}
				}
				if(flag){
					System.out.println((i%N)+1);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 20232
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define xx return
using namespace std;
int main(){
    int n;
    double d;
    cin>>n>>d;
    int ans=0;
    for (int i=0; i<n; i++){
        double q,r;
        cin>>q>>r;
        if (sqrt(q*q+r*r)<=d) ans++;
    }
    cout<<ans;
}

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

for i in range(len(a)):
  if a[i] == 1:
    a[i] = 300000
  elif a[i] == 2:
    a[i] = 200000
  elif a[i] == 3:
    a[i] = 100000
  else:
    a[i] = 0

    
if a[0] == 300000 and a[1] == 300000:
  p = 1000000
else:
  p = a[0] + a[1]
      
print(p)

Measured memory_bytes: 3064
#include<set>
using namespace std;
#include<iostream>
int	main(){

/*	int N, C, c[100], n;
	cin >> N;
	C = 0;
	n = 0;

	for (int i = 0; i <N; i++ ){
		cin >> c[i];
		C+= c[i];
	}

	for (int i = 0; i <N; i++ ){
		if (c[i] <= 0.1*C){
			n+= 30;
		}
	}
	cout << n << endl;
}
	/*
	while(true){
	
	int A,B,C,D,E,F,G,H,I,J,answer;
		
	cin >> A;
	if(A == 0) return 0;
	cin >> B >> C >> D >> E >> F >> G >> H >> I >> J;
	answer = A - B - C - D-E-F-G-H-I-J;
	cout << answer << endl;

	}
	*/
	/*
	int A,B,C,D,E,F;

	cin >> A, B, C, D;
	if(A < B, C, D){ 
		cout << B + C + D << endl;
	}
	
	else if(B < A, C, D){
		cout << A + C + D << endl;
	}

	else if(C < A && C < B && C < D){
		cout << A + B + D << endl;
	}

	else if(D < A && D < B && D < C){
		cout << A + B + C << endl;
	}

	if(E < F){
		cout << F << endl;
	}

	else{
		cout << E << endl;
	}
	
	return 0;
}*/
	/*
	int N, M;
	cin >> N >> M;
	cout << N + M << endl << N - M << endl << N * M << endl << N / M << endl;
}*/

/*int N, M; 
	cin >> N >> M;
	cout << N % M << endl;
}*/

/*	int N;
	cin >> N;
	cout << -(N % 2)+1 ;
}*/

	/*int A, B, C, D, E ;
	cin >> A >> B >> C >> D >> E;
	cout << (A + B + C + D + E) / 5 ;
}*/

	/*int A, B, C, D ;
	cin >> A >> B >> C >> D;
	cout << (A + B + C + D) / 60 << endl << (A + B + C + D) % 60 << endl;
	*/

/*	int A,B;
	cin >> A >> B;
	cout << ( A + B ) / 2 << endl;*/

/*	int m, f, b;
	cin >> m >> f >> b;

	if ( m + f >= b && m <= b ){
		cout << b - m << endl;
	}
	
	if ( m + f > b && m > b ){
		cout << 0 << endl;
	}


	if ( m + f < b ){
		cout << "NA" << endl;
	}*/

/*	int X , x ;
	cin >> X ;

	x = X % 7 ;

	if ( x == 2 ){
		cout << "sat" << endl;
	}

	if ( x == 3 ){
		cout << "sun" << endl;
	}

	if ( x == 4 ){
		cout << "mon" << endl;
	}

	if ( x == 5 ){
		cout << "tue" << endl;
	}

	if ( x == 6 ){
		cout << "wed" << endl;
	}

	if ( x == 0 ){
		cout << "thu" << endl;
	}

	if ( x == 1 ){
		cout << "fri" << endl;
	}*/

	/*int a , b , N ;
	cin >> a >> b >> N ;

	int s[100] , f[100];
	for ( int i=0 ; i<N ; i++ ){
		cin >> s[i] >> f[i];
	
		if (( s[i] <= a && a < f[i]) || s[i] < b && b <= f[i] || s[i] >= a && f[i] <= b ){
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}*/

	/*int N, A, B, C;
	vector <int> a;
	vector <int> dp;

	int pizza (int C){
		if (C == N) return 0;
		if (dp[C]! = -1) return dp[C];
		dp[C] = max (pizza(C+1); pizza(C+1)+a[C]);
		return dp[C];
	}

		int main(){
			cin >> N;
			for(int i = 0; i<N; i++){
				int tmp;
				cin >> tmp;
				a.push_back(tmp);
				dp.push_back(-1);
			}
			cout << pizza(0) << endl;

			return 0;
	}
		cout << C[i]/(A+B);*/
	
/*	int main(){
		int N, A, B, C, a, dp, i;

		dp[i+1] = max(dp[i], dp[i]+a[]), C[0] = 0;
	}*/

/*	long long N;
	cin >> N;
	cout << 264 + 52 * N << endl;
}*/

	/*int H, W;
	cin >> H >> W;
	if (H * 4 == W * 3){
		cout << "YOKO" << endl;
	}

	else{
		cout << "TATE" << endl;
	}


	}*/

	int i, m, s, e, I, M, S, E;
	cin >> i >> m >> s >> e >> I >> M >> S >> E;

	if(i + m + s + e >= I + M + S + E){
		cout << i + m + s + e << endl;
	}

	else{
		cout << I + M + S + E << endl;
	}
}


Measured memory_bytes: 3028
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[N-1] = B[N-2]
for i in range(N-2, 0, -1):
    A[i] = min(B[i], B[i-1])

A[0] = B[0]
print(sum(A))

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

vector<vector<P>> G;
int n;
vector<int> ans;

void dfs(int i, int c, int p) {
  ans[i] = c;
  for (auto& e : G[i]) {
    if (e.first == p) {
      continue;
    }
    if (e.second) {
      dfs(e.first, (c ^ 1), i);
    } else {
      dfs(e.first, c, i);
    }
  }
}

int main() {
  cin >> n;
  G.resize(n);
  ans.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    G[u].push_back(P(v, w % 2));
    G[v].push_back(P(u, w % 2));
  }
  dfs(0, 0, -1);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}


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

using namespace std;

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

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

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

int N;
void input(){
    // fast_io();
    cin >> N;
}
vector<char> seat;


void query(int idx){
    string q;
    cout << idx << endl;
    cin >> q;
    seat[idx] = q[0];
}

int solve(){
    seat.resize(N);
    
    int le = 0, ri = N-1;
    query(le);
    query(ri);
    int n=0;
    while(n<20){
        int mid = (le+ri)/2;
        query(mid);
        if(seat[mid]=='V') break;
        if(seat[le]==seat[mid] && ((mid-le+1)%2)==0 ) ri=mid;
        else if(seat[le]!=seat[mid] && ((mid-le+1)%2) ) ri=mid;
        else le=mid;
        n++;
    }
    return 0;
}   

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

Measured memory_bytes: 3824
import math

n, m, c = map(int, input().split())
b_list = list(map(int, input().split()))

passed = 0
for i in range(n):
    a_list = list(map(int, input().split()))
    total = 0
    for j in range(len(a_list)):
        total += a_list[j] * b_list[j]
    if (total + c > 0):
        passed += 1

print(passed)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        scanner.close();

        int n = 0;
        if(K != 1){
            n = N - K;
        }

        System.out.println(n);
    }
}


Measured memory_bytes: 23252
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);
	int[] a = new int[3];

	while(sc.hasNext()){
	    int n = sc.nextInt();
	    for(int cs = 0; cs < n; cs++){
		for(int i = 0; i < 3; i++){
		    a[i] = sc.nextInt();
		    a[i] *= a[i];
		}
		Arrays.sort(a);
		String s = "NO";
		if(a[0]+a[1] == a[2]) s = "YES";
		System.out.println(s); 
	    }
	}
    }
    public static void main(String[] args){
	new Main();
    }
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int n;
    cin >> n;
    vi a(n);
    int soma = 0;
    fo(i, n) {
        cin >> a[i];
        soma += a[i];
    }

    sort(all(a));

    if ( soma % 10 == 0 ) {
        int at = 0;
        while ( at < n and (soma - a[at]) % 10 == 0 ) {
            at++;
        }
        if ( at == n ) {
            cout << 0 << endl;
            return 0;
        }
        soma -= a[at];
    }

    cout << soma << endl;

    return 0;
}

Measured memory_bytes: 3592
import sys
from collections import defaultdict,deque
input = sys.stdin.readline
N,M= map(int,input().split())
XYZ= [list(map(int,input().split())) for i in range(M)]
g = defaultdict(list)

for x,y,z in XYZ:
    g[x].append(y)
    g[y].append(x)

visited = [False] * (N+1)

connect = 0
for i in range(1,N+1):
    if visited[i]:
        continue
    connect += 1
    dq = deque([i])
    while dq:
        v = dq.pop()
        visited[v] = True
        for nv in g[v]:
            if visited[nv]:
                continue
            dq.append(nv)

print(connect)
        







Measured memory_bytes: 82012
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
N = int(input())
#S = str(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

id = 0
minN = sys.maxsize
for i in range(N):
  ave = abs(A - (T-(H[i] * 0.006)))
  if minN > ave :
    minN = ave
    id = i
print (id+1)







Measured memory_bytes: 3572
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, W = sc.nextInt()
    val w, v = new Array[Int](N)
    for (i <- 0 until N) {
      val _w, _v = sc.nextInt()
      w(i) = _w
      v(i) = _v
    }

    val dp = Array.fill(N+1, W+1)(0L)
    for {
      i <- 0 until N
      j <- 0 to W
    } {
      if (j + w(i) <= W)
        dp(i+1)(j+w(i)) = dp(i+1)(j+w(i)) max (dp(i)(j) + v(i))
      dp(i+1)(j) = dp(i+1)(j) max dp(i)(j)
    }

    println(dp(N)(W))
  }

}


Measured memory_bytes: 145640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 2e5 + 5;
int n;
int a[maxn], b[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  return true;
}

priority_queue<pair<int, int>> pq;

void solve() {
  while (!pq.empty()) {
    pq.pop();
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > b[i]) {
      printf("-1\n");
      return;
    }
    if (a[i] < b[i]) {
      pq.push(make_pair(b[i], i));
    }
  }
  long long res = 0;
  while (!pq.empty()) {
    int i = pq.top().second;
    pq.pop();
    int x = 0;
    for (int dir = -1; dir <= 1; dir += 2) {
      int j = (i + dir + n) % n;
      x += b[j];
    }
    int need = b[i] - a[i];
    if (!(need % x)) {
      int k = need / x;
      res += k;
      b[i] = a[i];
      continue;
    }
    if (x > b[i]) {
      printf("-1\n");
      return;
    }
    res += b[i] / x;
    b[i] %= x;
    if (b[i] < a[i]) {
      printf("-1\n");
      return;
    }
    pq.push(make_pair(b[i], i));
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 4852
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 7 * 17 * (1 << 23) + 1;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, t, p = -1, c = 0, ans = 0;
	cin >> n;
	while(n--) {
		cin >> t;
		if(p!=t) {
			ans += c/2;
			c=0;
		}
		c++;
		p=t;
	}
	ans += c/2;
	cout << ans;
}


Measured memory_bytes: 256
from bisect import bisect_left
from itertools import product
I = lambda n: [int(input()) for _ in range(n)]
def f(S, x):
    p = bisect_left(S, x)
    return [S[p-1], S[p]]
g = lambda x, s, t: abs(x-s)+abs(s-t)
INF = 10**11
a, b, q = map(int, input().split())
S, T, X = [-INF]+I(a)+[INF], [-INF]+I(b)+[INF], I(q)
for x in X:
    min_ = INF
    for s, t in product(f(S, x), f(T, x)):
        min_ = min(min_, g(x, s, t), g(x, t, s))
    print(min_)

Measured memory_bytes: 18000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int [] ans = new int[num+1];
		for(int i = 1 ; i < num ;i++) {
			int a = sc.nextInt();
			ans[a]++;
		}
		for(int i = 1 ; i <= num ;i++) {
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 69672
# coding: utf-8
# input
n = int(input())
eat = list(map(int, input().split()))
data = list(map(int, input().split()))
plus = list(map(int, input().split()))

# processing
ans = 0
for i in range(len(eat)):
    ans += data[eat[i] - 1]
    if i <= n - 2:
        if eat[i + 1] == eat[i] + 1:
            ans += plus[eat[i] - 1]

# output
print(ans)


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

using namespace std;

int n;

string a, b;

int main()
{
    cin >> n;
    cin >> a >> b;
    int ans = n * 2;
    for(int i = 0; i < n; i++)
    {
        bool ok = true;
        for(int j = 0; j <= i; j++)
            if(a[a.size() - i - 1 + j] != b[j])
            {
                ok = false;
                break;
            }
        if(ok == true)
            ans = n * 2 - (i + 1);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    ll N;
    cin >> N;

    // process
    ll ans = 0;
    if (N % 2 == 0) {
//        ll digits = 0;
//        for (ll i = 18; i >= 0; i--) {
//            if (N >= pow(10, i)) {
//                digits = i;
//                break;
//            }
//        }
//        ll digit = 0;
//        for (ll i = digits; i >= 1; i--) {
//            ll tmp = N;
//            tmp /= pow(10, i);
//            tmp %= 10;
//            digit = digit * 10 + tmp;
//            ans += digit;
//        }
        for (ll i = 10; i <= N; i *= 5) {
            ans += N / i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,i,j,k,b[201][201],s[201][201],z[201];
int main(void)
{
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			scanf("%d",&b[i][j]);
			s[i][j]=0;
			z[i]=0;
		
		}
	}
	for(j=1;j<=3;j++){
		for(i=1;i<=n;i++){
			for(k=1;k<=n;k++){
				if(i!=k){
					if(b[i][j]==b[k][j]){
						s[i][j]=1;

					}
				}
			}
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			if(s[i][j]==0){
				z[i]+=b[i][j];
			}
		
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",z[i]);
	}
	//printf("a=%d\n",s[4][1]);
	return 0;
}

Measured memory_bytes: 1340
#include<stdio.h>

int main(void){
  int i,flag=0;
  char str[101],tx;
  scanf("%s",str);
  
  i=0;
  while(!(str[i] == '\0')){
    tx = str[i++];
    if(i%2==0 && !(tx=='L'||tx=='U'||tx=='D')){
      flag = 1;
      break;
   }
    else if(i%2==1 && !(tx=='R'||tx=='U'||tx=='D')){
      flag = 1;
      break;
    }
  }
  
  if(flag == 1)
    printf("No");
  else
    printf("Yes");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int d,n,ans;
    cin>>d>>n;
    if(n==100)n=101;
    if(d==0)ans=n;
    else if(d==1)ans=n*100;
    else if(d==2)ans=n*10000;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const N = lines[0]-0;
    const C = lines[1].split("");
    
    let st = 0, en = N-1;
    
    let ans = 0;
    while(st<en && st<=N && en>=0){
        if(C[st]=="W" && C[en]=="R"){
           [C[st], C[en]] = [C[en], C[st]];
           ans++;
        }else if(C[st]=="R"){
            st++;
        }else if(C[en]=="W"){
            en--;
        }else{
            st++;en--;
        }
    }
    console.log(ans);
});


Measured memory_bytes: 35980
def main():
    inf = 1<<29
    n,m = map(int,input().split())
    coins = list(map(int,input().split()))
    dp = [inf]*(n+1)
    dp[0] = 0
    for i in range(1,n+1):
        for j in range(m):
            if i-coins[j]<0:continue
            dp[i] = min(dp[i],dp[i-coins[j]]+1)
    print (dp[n])


if __name__ == '__main__':
    main()




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

A = [[0]*w for i in range(h)]

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                A[i][j] = 1
    elif a == 2:
        for i in range(h):
            for j in range(x,w):
                A[i][j] = 1
    elif a == 3:
        for i in range(y):
            for j in range(w):
                A[i][j] = 1                
    else:            
        for i in range(y,h):
            for j in range(w):
                A[i][j] = 1                

ans = 0
for i in range(h):
    for j in range(w):
        if A[i][j] == 0:
            ans += 1

print(ans)

Measured memory_bytes: 9208
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,cnt,ans=INF,x,i;
  cin >> n;
  for(i=1; i*i<=n; i++) {
    if(n%i==0) {
      cnt=to_string(n/i).size();
      ans=min(ans,cnt);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
  long long int n,a,b,den,q,r;
  scanf("%lld%lld%lld", &n,&a,&b);

  if (a==0){
    printf("0\n");
    return 0;
  }
  den=a+b;
  q=n/den;
  r=n%den;
  if(r<=a)
      printf("%lld\n", (a*q)+r);
  if (r>a)
      printf("%lld\n", (a*q)+a);

  return 0;
}


Measured memory_bytes: 128
N = int(input())
S = list(input())

alphabet = ['A', 'B', 'C', 'D', 'E', 'F',
            'G', 'H', 'I', 'J', 'K', 'L',
            'M', 'N', 'O', 'P', 'Q', 'R',
            'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
answer = []
for s in S:
    number = alphabet.index(s)
    while number + N >= 26:
        number = number - 26 
    answer.append(alphabet[number+N])
print(''.join(answer))


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

long long int N, W, w, v, w0, o, s, dpt[114][1919], a;

int main(){
    scanf("%lld%lld%lld%lld", &N, &W, &w0, &v);
    s = W % w0 + 300;
    fill(dpt[0], dpt[114], -1);
    //long long int dpt[114][s];
    dpt[0][0] = 0;
    dpt[1][0] = v;
    o = (W - 600) / w0;
    for(int i = 1; i < N; ++i){
        scanf("%lld%lld", &w, &v);
        for(int j = i; j >= 0; --j){
            for(int k = 0; k < 777; ++k){
                if(k + w - w0 < 880 && dpt[j][k] >= 0){
                    dpt[j + 1][k + w - w0] = max(dpt[j][k] + v, dpt[j + 1][k + w - w0]);
                }
            }
        }
    }
    s = min(s, 777LL);
    for(int j = 0; j <= N; ++j){
        for(int k = 0; k < s; ++k){
            //cout <<dpt[j][k] << " ";
            if(j * w0 + k <= W){
                a = max(a, dpt[j][k]);
            }
        }
        //cout << "\r\n";
    }
    cout << a << endl;
    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

vector<vector<int>> AllPairsShortestPath(const vector<vector<int>>& d_matrix) {
  int n = d_matrix.size();
  vector<vector<int>> r_matrix(d_matrix);
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (r_matrix[i][k] + r_matrix[k][j] < r_matrix[i][j]) {
          r_matrix[i][j] = r_matrix[i][k] + r_matrix[k][j];
        }
      }
    }
  }
  return r_matrix;
}

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

  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> d_matrix = Make2DVector(n, n, l + 1);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    int c;
    cin >> v1 >> v2 >> c;
    v1--;
    v2--;
    d_matrix[v1][v2] = d_matrix[v2][v1] = c;
  }
  auto r_matrix = AllPairsShortestPath(d_matrix);
  auto d2_matrix = Make2DVector(n, n, n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) d2_matrix[i][j] = 0;
      else if (r_matrix[i][j] <= l) {
        d2_matrix[i][j] = 1;
      }
    }
  }
  auto r2_matrix = AllPairsShortestPath(d2_matrix);

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    if (r2_matrix[s][t] == n) {
      cout << -1 << endl;
    } else {
      cout << r2_matrix[s][t] - 1 << endl;
    }
  }
}

Measured memory_bytes: 2048
#include <iostream>

using namespace std;

typedef long long ll;

int n;
int dp[120][(1 << 12)];

const long long MOD = 1e9 + 7;

int mask(int a, int b, int c)
{
    return (1 << (8 + a)) + (1 << (4 + b)) + (1 << c);
}

signed main()
{
    cin >> n;
    for (int c1 = 0; c1 < 4; c1++)
    {
        for (int c2 = 0; c2 < 4; c2++)
        {
            for (int c3 = 0; c3 < 4; c3++)
            {
                if (c1 == 1 && c2 == 2 && c3 == 3) continue;
                if (c1 == 1 && c2 == 3 && c3 == 2) continue;
                if (c1 == 2 && c2 == 1 && c3 == 3) continue;
                dp[3][mask(c1, c2, c3)] = 1;
            }
        }
    }
    // 1243 1423 1223
    for (int i = 4; i <= n; i++)
    {
        for (int c1 = 0; c1 < 4; c1++)
        {
            for (int c2 = 0; c2 < 4; c2++)
            {
                for (int c3 = 0; c3 < 4; c3++)
                {
                    for (int c4 = 0; c4 < 4; c4++)
                    {
                        if (c2 == 1 && c3 == 2 && c4 == 3) continue;
                        if (c2 == 1 && c3 == 3 && c4 == 2) continue;
                        if (c2 == 2 && c3 == 1 && c4 == 3) continue;
                        if (c1 == 1 && c2 == 2 && c3 == 0 && c4 == 3) continue;
                        if (c1 == 1 && c2 == 0 && c3 == 2 && c4 == 3) continue;
                        if (c1 == 1 && c2 == 2 && c3 == 2 && c4 == 3) continue;
                        dp[i][mask(c2, c3, c4)] = (dp[i - 1][mask(c1, c2, c3)] + dp[i][mask(c2, c3, c4)]) % MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int c1 = 0; c1 < 4; c1++)
    {
        for (int c2 = 0; c2 < 4; c2++)
        {
            for (int c3 = 0; c3 < 4; c3++)
            {
                ans = (ans + dp[n][mask(c1, c2, c3)]) % MOD;
            }
        }
    }
    cout << ans;
}


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

#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e5+5;
#define mod 1000000007

int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    int a=0,b=0;
    for(int i=1;i<=2*n;i++)
    {
        if(i%2==0) cout<<t[b++];
        else cout<<s[a++];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int y,m,d;
    char s1,s2;
    cin >> y >> s1 >> m >> s2 >> d ;
    if(m<=4){
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
int main(){
    int k, n; cin >> k >> n;
    vector<int> at(n);
    for(int &l : at) cin >> l;
    
    int clw = at[n-1] - at[0];    
    // int uclw = at[n-2] + k - at[n-1];
    int uclw = 1e9;
    for(int i = n - 2; i >= 0; i--){
        uclw = min(uclw, at[i] + k - at[i + 1]);
    }
    // cout << clw << ":" << uclw << "\n";
    cout << min(clw, uclw);

}


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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll x,y,z,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<pii> v;
    rep(i,0,a-1){
        cin>>z;
        v.pb({z,1});
    }
    rep(i,0,b-1){
        cin>>z;
        v.pb({z,2});
    }
    rep(i,0,c-1){
        cin>>z;
        v.pb({z,0});
    }
    sort(all(v));
    ll rem=0,curra=0,currb=0;
    ll ans=0,temp=0;
    rrep(i,sz(v)-1,0){
        if(curra<x && v[i].S==1){
            curra++;
            ans+=v[i].F;
        }
        else if(currb<y && v[i].S==2){
            currb++;
            ans+=v[i].F;
        }
        else if(v[i].S==0){
            rem++;
            temp+=v[i].F;
        }
        if((rem+curra+currb)==(x+y)) break;
    }
    cout<<ans+temp<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 10476
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(),v.end()
#define fio() ios::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define fornn(i,a,n) for(ll i=a;i<=n;i++)
#define pb push_back
#define MAXN 100005LL
#define INF 1000000005LL
inline void solve(){
    ll n,k,maxi=0LL,ans=0LL;
    cin>>n>>k;
    while(n--){
        ll temp;
        cin>>temp;
        ans=__gcd(temp,ans);
        maxi=max(maxi,temp);
    }
    if(k<=maxi && k%ans==0){
        cout<<"POSSIBLE";
    }
    else
        cout<<"IMPOSSIBLE";
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("output.txt","w",stdout);
    // freopen("input.txt","r",stdin);
    // #endif
    fio();
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
if N==2 or M==2:
    print(0)
    exit()
if N==1 and M==1:
    print(1)
    exit()
if N==1 or M==1:
    print(max(N,M)-2)
    exit()
print((N-2)*(M-2))


Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>
// #include <atcoder/all>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
// using namespace atcoder;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;
// using mint = modint1000000007;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ")
#define print1(v) cout << fixed << setprecision(10) << v << "\n"
#define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n"
#define print3(v1, v2, v3) cout << fixed << setprecision(10) << v1 << " " << v2 << " " << v3 << "\n"
#define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); }
#define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); }

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 1e5+5;
int n, m;
vii s(maxn);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

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

    cin >> n;

    int k = (1+sqrt(1+8*n))/2;
    if (k*(k-1) != 2*n) {
        print1("No");
        return 0;
    } else {
        print1("Yes");
        print1(k);
    }

    int num = 1;
    REP(i, k-1) {
        FOR(j, i+1, k) {
            s[i].push_back(num);
            s[j].push_back(num);
            num++;
        }
    }

    REP(i, k) {
        cout << k-1 << " ";
        printvi(s[i], k-1);
    }
}

Measured memory_bytes: 7460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<P> a(n);
	rep(i, n) cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end());
	
	ll ans = 0;
	int i = 0;
	while(0 < m){
		if(0 < a[i].second){
			m--;
			a[i].second--;
			ans += a[i].first;
		}
		else{
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
S = input()

f = int(S[:2])
b = int(S[2:])

if 1 <= f <= 12 and 1 <= b <= 12:
    print('AMBIGUOUS')
elif 1 <= b <= 12:
    print('YYMM')
elif 1 <= f <= 12:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940
func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!};
}
let a = readInts();
let N = a[0];
let D = a[1];
var range = -1, ans = 0;
while(range < N - 1) {
    range += (2 * D + 1);
    ans += 1;
}
print(ans);

Measured memory_bytes: 8160
#include <cstdio>

int main(void) 
{
    int i, j;
    for(i = 1; i <= 9; i++) {
        for(j = 1; j <= 9; j++) {
            printf("%dx%d=%d\n", i, j, i*j);
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  vector<P> xy(n);

  REP(i, n) {
    int x, y;
    cin >> x >> y;
    xy[i] = P(x, y);
  }

  sort(xy.begin(), xy.end());
  int ans = 0;
  map<P, int> mp;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      int f = xy[i].first - xy[j].first;
      int s = xy[i].second - xy[j].second;
      mp[P(f, s)]++;
    }
  }
  for(auto &[k, v] : mp) ans = max(ans, v);

  cout << (n - ans) << endl;
}


Measured memory_bytes: 3628