akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, raw_input().split())
ab = []
for _ in range(M):
  _ab = map(int, raw_input().split())
  ab.append(_ab)
  
sorted_a = sorted(ab, key=lambda x:x[0])
sorted_b = sorted(ab, key=lambda x:x[1])

from_1 = set([b for a, b in sorted_a if a == 1])
to_N = set([a for a, b in sorted_b if b == N])

if len(from_1 & to_N) > 0:
  print 'POSSIBLE'
else:
  print 'IMPOSSIBLE'

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

using namespace std;

bool fp[5005][5005], fr[5005][5005];
int sr[5005][5005];
int n, k, a[5005], an;

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 1; i <= n; ++i) scanf("%d",&a[i]), a[i] = min(a[i], k);
	fp[0][0] = 1;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j <= k; ++j){
			fp[i + 1][j] |= fp[i][j];
			fp[i + 1][min(j + a[i + 1], k)] |= fp[i][j];
		}
	}
	fr[n + 1][0] = 1;
	for(int i = n + 1; i > 1; --i){
		for(int j = k; j >= 0; --j){
			fr[i - 1][j] |= fr[i][j];
			fr[i - 1][min(j + a[i - 1], k)] |= fr[i][j];
		}
	}
	for(int i = 1; i <= n + 1; ++i){
		sr[i][0] = 1;
		for(int j = 1; j <= k; ++j)
			sr[i][j] = sr[i][j - 1] + fr[i][j];
	}
	an = n;
	for(int i = 1; i <= n; ++i){
		bool ok = 0;
		for(int j = 0; j < k; ++j){
			int l = k - a[i] - j, r = k - 1 - j;
			l = max(l, 0);
			ok |= (fp[i - 1][j] & (sr[i + 1][r] - (l ? sr[i + 1][l - 1] : 0) > 0));
		}
		an -= ok;
	}
	printf("%d", an);
	return 0;
}

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

a.sort(reverse=True)

cnt = 1
ans = a[0]

if n == 2:
    print(ans)
    exit()

for i in range(1, n):
    cnt += 1
    ans += a[i]
    if cnt == n - 1:
        break
    else:
        cnt += 1
        ans += a[i]
    if cnt == n - 1:
        break

print(ans)


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


int main(){
    int n;
    cin >> n;
    vector<int> rx(n),ry(n),bx(n),by(n);
    for(int i = 0; i < n; i++){
        cin >> rx.at(i) >> ry.at(i);
    }
    
    for(int i = 0; i < n; i++){
        cin >> bx.at(i) >> by.at(i);
    }
    
    vector<bool> paired(n,false);
    int answer = 0;
    
    for(int i = 0; i < n; i++){
        
        int b_x = 200,b_y,b;
        
        for(int j = 0; j < n; j++){
            if(bx.at(j) < b_x){
                b_x = bx.at(j);
                b_y = by.at(j);
                b = j;
            }
        }
        
        int r_y = -1;
        int r = 200;
        for(int j = 0; j < n; j++){
            if(rx.at(j) < b_x && ry.at(j) < b_y && !paired.at(j)){
                if(ry.at(j) > r_y){
                    r_y = ry.at(j);
                    r = j;
                }
            }
        }
        
        if(r != 200){
            paired.at(r) = true;
            answer++;
        }
        

        bx.at(b) = 200;
        
    }
    
    cout << answer << endl;
    
}

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      int cnt = i*M + j*N - 2*i*j;
      if (cnt == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
function main(input) {
  input = input.trim()
  const args = input.split("\n")

  args[0] = args[0].split(" ")
  const x = Number(args[0][0])
  const n = Number(args[0][1])

  if (n === 0) return console.log(x)

  const pArray = args[1].split(" ").map(v => Number(v))

  const candidates = []
  for (let i = x; i <= 101; i++) {
    if (!pArray.includes(i)) {
      candidates.push({ value: i, abs: Math.abs(x - i) })
      break
    }
  }
  for (let i = x; i >= 0; i--) {
    if (!pArray.includes(i)) {
      candidates.push({ value: i, abs: Math.abs(x - i) })
      break
    }
  }

  const result = candidates.reduce((acc, cur) => {
    return acc.abs < cur.abs ? acc.value : cur.value
  })

  console.log(result)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29576
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;
using ll=long long;
#define rep(i,n) for(int 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()
 
int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int difx = x2 - x1;
    int dify = y2 - y1;

    int addx = -1*dify;
    int addy = difx;
    
    cout << x2 + addx << " " << y2 + addy << " " << x1 + addx << " " << y1 + addy << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p%i == 0) return false;
	}
	return true;
}
 
int n;
 
int main() {
	cin >> n;
	for (int i = 3; i <= 55555; i += 5) {
		if (isprime(i) == true) {
			if (i != 3) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}



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

int main()
{
	string s,s2;
	cin >> s;
	rep(i,s.size())
	{
		s[i] = tolower(s[i]);
	}

	int count = 0;
	while(cin >> s2)
	{
		if(s2 == "END_OF_TEXT") break;
		
		rep(i,s2.size())
		{
			s2[i] = tolower(s2[i]);
		}
		if(s2 == s) count++;
		
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define all(x) (x).begin(), (x).end()

int main(){
    int n,m;
    cin>>n>>m;
    int arr[m];
    for(int i=0; i<m; i++)
        cin>>arr[i];
    int sum=0;
    for(auto& i: arr)
        sum+=i;
    if(sum>n)cout<<"-1"<<endl;
    else cout<<(n-sum)<<endl;
    return 0;
}



Measured memory_bytes: 3656
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i=1;
		while(sc.hasNextLine()){
			String str = sc.nextLine();
			if(!(str.equals("0"))){
				System.out.println("Case "+i+": "+str);
				i=i+1;
			}
		}
	}
}

Measured memory_bytes: 59120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int i = 1;

		while (true) {
			int x = Integer.parseInt(br.readLine());
			if (x == 0) {
				break;
			}
			System.out.println("Case" + " " + (i++) + ":" + " " + x);
		}
	}
}

Measured memory_bytes: 31852
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int minCost = 1001;
        for(int i=0; i<n; i++){
            int cost = sc.nextInt();
            int time = sc.nextInt();
            if(t >= time){
                if(minCost > cost) minCost = cost;
            }
        }
        if(minCost == 1001) System.out.println("TLE");
        else System.out.println(minCost);
    }
}

Measured memory_bytes: 23124
// 標準入力
using System;
public class Program{
    public static void Main(){
        var a=0 ;
        var b=0;
        var c=0;
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        if(a*b==2){
            c=3;
        }else if(a*b==3){
            c=2;
        }else if(a*b==6){
            c=1;
        }
        Console.WriteLine(c);
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
#define mod 1000000007
using namespace std;

const int NMAX = 100010;
int fact[2 * NMAX], invfact[2 * NMAX];

int put(int a, int p)
{
    int ans = 1;
    while (p) {
        if (p & 1)
            ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        p /= 2;
    }
    return ans;
}

void precalc()
{
    fact[0] = 1;
    for (int i = 1; i < 2 * NMAX; i++)
        fact[i] = 1LL * fact[i - 1] * i % mod;
    invfact[2 * NMAX - 1] = put(fact[2 * NMAX - 1], mod - 2);
    for (int i = 2 * NMAX - 1; i > 0; i--)
        invfact[i - 1] = 1LL * invfact[i] * i % mod;
}

int comb(int a, int b)
{
    a += b;
    if (b > a || b < 0)
        return 0;
    return 1LL * fact[a] * invfact[b] % mod * invfact[a - b] % mod;
}

pair <int, int> points[NMAX];
int H, W;
int n;
int dp[NMAX];

int main()
{
    precalc();
    scanf("%d%d%d", &H, &W, &n);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &points[i].first, &points[i].second);
    points[0] = make_pair(H, W);

    sort(points, points + n + 1);

    for (int i = 0; i <= n; i++) {
        dp[i] = comb(points[i].first - 1, points[i].second - 1);
        for (int j = 0; j < i; j++)
            dp[i] = (dp[i] - 1LL * dp[j] * comb(points[i].first - points[j].first, points[i].second - points[j].second)) % mod;
    }

    dp[n] = (dp[n] + mod) % mod;

    printf("%d\n", dp[n]);

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int a[100005], b[100005];

int main()
{
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = w * h / 2;
    printf("%.6f",ans);
    cout << " ";
    if (w / 2 == x and h / 2 == y)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
bingoDict = {}
bingoList = []
pos = 0
mark = 0 

#Creates a list containing three lists for each row of numbers
for i in range(3):
  bingoList.append(list(map(int, input().split())))

#Iterates through list inside of list, adding them to a dictionary 
for row in range(len(bingoList)):
  for item in range(len(bingoList[row])):
    pos += 1
    tempList = [] 
    tempList.append(bingoList[row][item])
    tempList.append(0)
    bingoDict[pos] = tempList

#Number of numbers called 
N = int(input())

#If the number is mentioned, add one to value (could be more than 1)
for i in range(N):
  numCalled = int(input())
  for key in bingoDict:
    if numCalled == bingoDict[key][0]:
      bingoDict[key][1] += 1

#print('\n BingoDict: %s' % bingoDict)
  
for key in bingoDict:
  if (key == 1 or key == 4 or key == 7) and key + 2 <= 9:
    if bingoDict[key][1] and bingoDict[key + 1][1] and bingoDict[key + 2][1] >= 1:
      mark = 1
  if key + 6 <= 9:
    if bingoDict[key][1] and bingoDict[key + 3][1] and bingoDict[key + 6][1] >= 1:
      mark = 1
  if key == 1:
    if bingoDict[key][1] and bingoDict[key + 4][1] and bingoDict[key + 8][1] >= 1:
      mark = 1
  if key == 3:
    if bingoDict[key][1] and bingoDict[key + 2][1] and bingoDict[key + 4][1] >= 1:
      mark = 1

if mark == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
N, K = map(int, input().split())
X = list(map(int, input().split()))

if X[0] >= 0:
    print(X[K - 1])
    exit()

if X[-1] <= 0:
    print(-X[N - K])
    exit()

ans = float('inf')
for i in range(K, N + 1):
    l = i - K
    r = i - 1
    if X[l] <= 0 <= X[r]:
        abs_l = -X[l]
        abs_r = X[r]
        dist = 0
        if abs_l > abs_r:
            dist = 2 * abs_r + abs_l
        else:
            dist = 2 * abs_l + abs_r
        ans = min(ans, dist)
print(ans)


Measured memory_bytes: 14224
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;

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

	int a = s % 100;
	int b = (s - a) / 100;

	bool ai = a <= 12 && a >= 1;
	bool bi = b <= 12 && b >= 1;

	string ans = "NA";

	if (ai && bi) {
		ans = "AMBIGUOUS";
	}
	else if (ai && !bi) {
		ans = "YYMM";
	}
	else if (!ai && bi) {
		ans = "MMYY";
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<ll>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> s(n), t(m);
    rep(i, n)cin >> s[i];
    rep(i, m)cin >> t[i];
    bool ok = false;

    rep(i, n - m + 1){  //始点の位置(y)
        rep(j, n - m + 1){  //始点の位置(x)
            bool f = true;
            rep(y, m){
                rep(x, m){
                    int ny = i + y, nx = j + x;
                    if(s[ny][nx] != t[y][x])f = false;
                }
            }
            if(f)ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;vl al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}
mt19937 rnd; void set_rnd(){random_device r;rnd=mt19937(r());}
vl fact, rfact; void set_fact(int n, ll m){fact.pb(1);rfact.pb(1);FOR(i,1,n+1)fact.pb(fact[i-1]*i%m),rfact.pb(modpow(fact[i],m,m-2));}
const int iinf = 1e9+6;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 2e5+1;
void init(){
  set_rnd();
//  set_fact(N);
}
int h, w, n, r;
map<int, si> m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cin >> h >> w >> n;
  FOR(i, 0, n){
    int x, y;
    cin >> x >> y;
    m[x-1].insert(y-1);
  }
  r = 0;
  FOR(i, 1, h){
    if(!m[i].empty() && *m[i].begin() <= r){
      cout << i << endl;
      return 0;
    }
    if(m[i].find(r+1) == m[i].end()) r++;
  }
  cout << h << endl;
  return 0;
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<f64> A(N);
    for (i32 i = 0; i < N; i++) cin >> A[i];
    f64 sum = 0;
    for (i32 i = 0; i < N; i++) sum += 1.0 / A[i];
    cout << 1.0 / sum << endl;
}


Measured memory_bytes: 3792
import sys

def main():
    input = sys.stdin.readline
    x = int(input())

    n = x // 11
    if x % 11 == 0:
        return 2 * n
    elif x % 11 <= 6:
        return 2 * n + 1
    else:
        return 2 * (n + 1)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2940
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	int n;
	cin >> n;
	v64 arr(n,0);
	for(int i = 0;i < n;i++)
		cin >> arr[i];
	ll prev = 1e18,jump = 0,ans = 0;
	int idx = 0;
	while(idx < n){
		if(arr[idx] <= prev){
			jump++;
			ans = max(ans,jump);
			prev = arr[idx++];
			continue;
		}
		else{
			jump = 0;
			prev = 1e18;
			idx--;
		}
		idx++;
	}
	cout << (ans - 1) << ln;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};


int main(){
    ll n, m;    cin >> n >> m;
    vector<ll> a(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int factor2 = -1;
    for(int i = 0; i < n; i++){
        int tmpFactor2 = 0;
        while(a[i] % 2 == 0){
            a[i] /= 2;
            tmpFactor2++;
        }
        if(factor2 == -1){
            factor2 = tmpFactor2;
        }
        else if(factor2 != tmpFactor2){
            cout << 0 << endl;
            return 0;
        }
    }

    ll x = 1;
    while(factor2 > 0){
        x *= 2;
        factor2--;
    }
    for(int i = 0; i < n; i++){
        if(x > m){
            cout << 0 << endl;
            return 0;
        }
        x = lcm(x, a[i]);
    }

    if(x > m){
        cout << 0 << endl;
    }
    else{
        if((m / x + 1) / 2 == 0){
            cout << m << " " << x << endl;
        }
        cout << (m / x + 1) / 2 << endl;
    }



    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

#define MAX 1000000000
#define MIN -10000000000

#define ll long long

using namespace std;
int main() {

        ll n,k,i,j,temp,last,maxx;
        do {
            cin >> n >> k;
            if(k==0&&n==0)break;
            vector<ll> a(n);
            vector<ll> s(n + 1);
            for (i = 0; i < n; i++) {
                cin >> a[i];
            }
            //cin >> temp >> temp;
            s[0] = 0;
            for (i = 0; i < n; i++) {
                s[i + 1] = s[i] + a[i];
            }
            maxx = a[k - 1] + a[0];
            for (i = 0; i < n - k + 1; i++) {
                //   cout << s[i+k]-s[i] << endl;
                maxx = max(s[i + k] - s[i], maxx);
            }
            cout << maxx << endl;
        }while(k!=0&&n!=0);

//cout << "aaa" << endl;

    return 0;
}


Measured memory_bytes: 4384
// 2015/06/30 Tazoe

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

class FC{
public:
	int p[31];	// p[0]は使わない
	int n;		// 操作回数

	bool is_over()		// 終了判定
	{
		return p[1]==p[2] && p[2]==p[3] && p[3]==p[4] && p[4]==p[5]	// p[1]?p[9]
		    && p[5]==p[6] && p[6]==p[7] && p[7]==p[8] && p[8]==p[9]
		    && p[10]==p[11] && p[11]==p[12]				// p[10]?p[12]
		    && p[13]==p[14] && p[14]==p[15]				// p[13]?p[15]
		    && p[16]==p[17] && p[17]==p[18]				// p[16]?p[18]
		    && p[19]==p[20] && p[20]==p[21];				// p[19]?p[21]
	}

	void rot1()		// 回転1
	{
		swap(p[ 7], p[22]);  swap(p[ 8], p[23]);  swap(p[ 9], p[24]);
		swap(p[13], p[18]);  swap(p[10], p[12]);
	}

	void rot2()		// 回転2
	{
		swap(p[ 1], p[28]);  swap(p[ 2], p[29]);  swap(p[ 3], p[30]);
		swap(p[15], p[16]);  swap(p[19], p[21]);
	}

	void rot3()		// 回転3
	{
		swap(p[ 1], p[24]);  swap(p[ 4], p[27]);  swap(p[ 7], p[30]);
		swap(p[10], p[21]);  swap(p[16], p[18]);
	}

	void rot4()		// 回転4
	{
		swap(p[ 3], p[22]);  swap(p[ 6], p[25]);  swap(p[ 9], p[28]);
		swap(p[12], p[19]);  swap(p[13], p[15]);
	}
};

int main()
{
	int N;
	cin >> N;

	for(int i=0; i<N; i++){
		FC now;
		for(int j=1; j<=30; j++){
			cin >> now.p[j];
		}
		now.n = 0;

		queue<FC> que;			// キュー
		que.push(now);

		while(!que.empty()){		// キューが空になるまで
			now = que.front();
			que.pop();

			if(now.is_over()){
				cout << now.n << endl;
				break;
			}

			FC nex1 = now;  nex1.rot1();  nex1.n++;  que.push(nex1);
			FC nex2 = now;  nex2.rot2();  nex2.n++;  que.push(nex2);
			FC nex3 = now;  nex3.rot3();  nex3.n++;  que.push(nex3);
			FC nex4 = now;  nex4.rot4();  nex4.n++;  que.push(nex4);
		}
	}

	return 0;
}

Measured memory_bytes: 12168
a, b, c, x, y = gets.split.map(&:to_i)

c_set = c * 2

no_half = a * x + b * y
x_only_half = c_set * x + b * ([y - x, 0].max)
y_only_half= a * ([x - y, 0].max) + c_set * y

puts [no_half, x_only_half, y_only_half].min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n,h;
  cin >> h >> n;
  vector<int> a(n),b(n);
  vector<vector<ll>> dp(n+1,vector<ll>(h+1,INF));
  dp[0][0]=0;
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  rep(i,n){
    for(int j=0; j<=h; j++){
      //dp[i+1][j]=min(dp[i][j],dp[i+1][j-a[i]]+b[i]);

      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i+1][min(j+a[i], h)], dp[i+1][j] + b[i]);

    }
  }

  cout << dp[n][h] << endl;

  return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> ans(N,0);
  vector<vector<int>> V(N+1, vector<int>(3));
  for(int i=1; i<N+1; i++){
    int c, s, f;
    cin >> c >> s >> f;
    V[i][0]=c;
    V[i][1]=s;
    V[i][2]=f;    
  }
  for(int i=1; i<N; i++){
    for(int j=0; j<i; j++){
      int a=ans[j], c=V[i][0], s=V[i][1], f=V[i][2];        
      if(a<=s) a=s;
      else if(a%f!=0) a+=(f-a%f);
      a+=c;
      ans[j]=a;
//      cout<<"i:"<<i<<" j:"<<j<<" a:"<<a<<" c:"<<c<<" s:"<<s<<" f:"<<f<<endl;
    }
  }
  for(int i=0; i<N; i++){
    cout << ans[i] << endl;
  }
}


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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int fact_of_two(int i) {
    int j;
    for (j = 0; j < 100; j++) {
        if (i % int(pow(2, j)) != 0) {
            break;
        }
    }
    assert (j >= 1);
    return j - 1;
}

int main(void) {
    int n;
    vector <int> an;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        an.push_back(a);
    }
    int mi = 999999;
    for (int i = 0; i < n; i++) {
        mi = min(mi, fact_of_two(an[i]));
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

Z=[]
W=[]

for _ in range(N):
    x,y=map(int,input().split())
    Z.append(x+y)
    W.append(x-y)
    
print(max(max(Z)-min(Z),max(W)-min(W)))

Measured memory_bytes: 24972
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val C = IntArray(N) { 0 }
    var count = 1
    C[0] = readLine()!!.toInt()

    var min = C[0]

    a@ for (i in 1 until N) {
        val A = readLine()!!.toInt()
        if (min >= A) {
            C[count] = A
            count++
            min = A
            continue@a
        }
        for (j in 0 until count) {
            if (C[j] < A) {
                C[j] = A
                continue@a
            }
        }
        C[count] = A
        count++
    }

    println(count)
}

Measured memory_bytes: 39380
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;

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

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

int main(){
int n,k;cin>>n>>k;
vector<int> su(n+1,0);

rep(i,k){
  int d;cin>>d;
  rep(j,d){
    int a;
    cin>>a;
    su[a]++;
  }
}
int cnt=0;
for (int i = 1; i <=n; i++)
{
  if(su[i]==0)cnt++;
}
cout<<cnt<<endl;
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  int cnt_a=0, cnt_b=0, cnt_ab=0;
  int ans=0;
  rep(i,n){
    string s;
    cin>>s;
    bool a=0, b=0;
    if(s[0]=='B') b=1;
    if(s[s.size()-1]=='A') a=1;
    if(a&b) cnt_ab++;
    else if(a) cnt_a++;
    else if(b) cnt_b++;
    rep(si,s.size()-1){
      if(s[si]=='A'&&s[si+1]=='B') ans++;
    }
  }
  if(cnt_a==0 && cnt_b==0) ans+=min(max(0,cnt_ab-1),n-1);
  else ans+=min(min(cnt_a,cnt_b)+cnt_ab,n-1);
  cout<<ans<<endl;
}


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

typedef long long LL;

int a, b, c, d, k, n;
void solve() {
	std::cin >> a >> b >> c >> d, n = a + b, k = n / (std::min(a, b) + 1);
	int l = 0, r = n, ans = 0;
	while (l <= r) {
		int mid = l + r >> 1, B = b - mid / (k + 1), A = n - mid - B;
		if (B <= (LL) A * k) ans = l = mid + 1; else r = mid - 1;
	}
	for (int i = c; i <= std::min(d, ans); ++i)
		std::cout << "AB"[!(i % (k + 1))];
	for (int i = std::max(c, ans + 1); i <= d; ++i)
		std::cout << "BA"[!((n - i + 1) % (k + 1))];
	std::cout << '\n';
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	int tc; std::cin >> tc;
	while (tc--) solve();
	return 0;
}

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

int main()
{
	int N;
	ll L;
	cin >> L >> N;
	vector<ll> X(N * 2);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		X[N + i] = L + X[i];
	}
	vector<ll> sumX(N * 2 + 1);
	for (int i = 0; i < N * 2; i++) {
		sumX[i + 1] = sumX[i] + X[i];
	}
	ll res = 0;
	{
		ll val = 0;
		for (int i = N; i < N * 2; i++) {
			int cnt = N - (i - N + 1), l = (cnt + 1) / 2, r = cnt - l;
			ll dist = (L * l - (sumX[N] - sumX[N - l])) * 2;
			dist += ((sumX[i + r + 1] - sumX[i]) - L * (r + 1)) * 2;
			if (cnt & 1) dist -= L - X[N - l];
			else dist -= X[i + r] - L;
			val = max(val, dist);
		}
		res = max(res, val);
	}
	{
		ll val = 0;
		for (int i = N - 1; i >= 0; i--) {
			int cnt = i, r = (cnt + 1) / 2, l = cnt - r;
			ll dist = ((sumX[N + r] - sumX[N]) - L * r) * 2;
			dist += (L * (l + 1) - (sumX[i + 1] - sumX[i - l])) * 2;
			if (cnt & 1) dist -= X[N + r - 1] - L;
			else dist -= L - X[i - l];
			val = max(val, dist);
		}
		res = max(res, val);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    string ins;
    cin>>n;
    for(int ix=0;ix<n;ix++){
        int out=0,po=0;
        vector<bool> runner(3,false);
        for(;;){
            cin>>ins;
            if(ins=="HIT"){
                if(runner[2]){
                    po++;
                    runner[2]=false;
                }
                if(runner[1]){
                    runner[2]=true;
                    runner[1]=false;
                }
                if(runner[0]) runner[1]=true;
                runner[0]=true;
            }else if(ins=="OUT"){
                out++;
                if(out==3)break;
            }else if(ins=="HOMERUN"){
                po++;
                for(int i=0;i<3;i++){
                    if(runner[i])po++;
                    runner[i]=false;
                }
            }
        }
        cout<<po<<endl;
    }
}

Measured memory_bytes: 0
import math
a,b,x=map(int,input().split())


vmax=b*a*a/2
pi=math.pi
if x<vmax:
    h=2*x/(b*a)
    print(90.0-math.atan(h/b)*180/pi)
else:
    xt=a*a*b-x
    bt=xt/(a*a)
    ht=2*bt
    print(math.atan(ht/a)*180/pi)
    


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int A[300][300];
int l[300];
bool alive[300];
int ctr[300];

bool f(int X) {
  rep(i, M) alive[i] = true;
  rep(i, N) {
    l[i] = 0;
  }
  int rem = M;
  while (true) {
    rep(i, M) ctr[i] = 0;
    rep(x, N) {
      ctr[A[x][l[x]]]++;
    }
    int mx = -1, mi = -1;
    rep(i, M) {
      if (!alive[i]) continue;
      if (ctr[i] > mx) {
        mx = ctr[i];
        mi = i;
      }
    }
    assert(mi != -1);
    if (mx > X) {
      // miは解散
      alive[mi] = false;
      rem--;
      if (rem == 0) return false;
      rep(x, N) {
        while (l[x] < M && !alive[A[x][l[x]]]) l[x]++;
        assert(l[x] <= M);
      }
    }
    else break;
  }
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) {
    rep(j, M) {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int lo = 0, hi = N+1;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (f(mid)) hi = mid;
    else lo = mid;
  }
  cout << hi << "\n";
  return 0;
}


Measured memory_bytes: 640
import sys


def main():
    raw = input().split(' ')
    n = int(raw[0])
    a = int(raw[1])
    b = int(raw[2])

    def get_max():
        return min(a, b)

    def get_min():
        return max(a + b - n, 0)

    print("{} {}".format(get_max(), get_min()))


if __name__ == "__main__":
    argv = sys.argv[1:]
    main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc084.contest.atcoder.jp/tasks/abc084_d>
問題文============================================================
 「N も (N+1)÷2 も素数」を満たす奇数 N を 2017に似た数 とします。
 
 Q 個のクエリが与えられます。
 
 クエリ i(1≦i≦Q) では奇数 li,ri が与えられるので、
 li≦x≦ri かつ 2017に似た数 となる奇数 x の個数を求めてください。
=================================================================

解説=============================================================

 1..N までに2017素数であるものの個数を累積和で確保しておき
 一つのキューに対して O(1) でもとまる
 
================================================================
*/
const ll MAX_PRIME = 100000;
vector<int> primes(MAX_PRIME + 1);
vector<int> is_prime(MAX_PRIME + 1,true);
vector<int> prime2017(MAX_PRIME + 1,0);
vector<int> cusum(MAX_PRIME + 1,0);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

void init(){
    init_primes();
    for(int i = 1; i <= MAX_PRIME; i++){
        if(is_prime[i] && is_prime[(i+1)/2]){
            prime2017[i] = true;
        }
    }
    for(int i = 0; i < MAX_PRIME;i++){
        cusum[i+1] = cusum[i] + prime2017[i+1];
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    init();
    ll Q; cin >> Q;
    while(Q--){
        ll l,r; cin >> l >> r;
        cout << cusum[r] - cusum[l-1] << endl;
    }
	return 0;
}


Measured memory_bytes: 2296
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << b + b - a;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int N,M;
ll res;
priority_queue<int> pq;
multimap<int, int> mm;

ll dp(int n){
    if(M < n) return res;

    auto p = mm.equal_range(n);
    for(auto itr = p.first; itr != p.second; ++itr) pq.push(itr->second);
    if(!pq.empty()){
        res += pq.top(); pq.pop();
    }
    return dp(n+1);
}


int main()
{
    cin >> N >> M;
    for(int i = 0 ; i < N; ++i){
        int a,b;
        cin >> a >> b;
        mm.emplace(a, b);
    }
    cout << dp(1) << endl;
    return 0;
}



Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,K;
  cin>>N>>K;
  int ans=K;
  rep(i,1,N) ans*=(K-1);
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC166
{
    /// <summary>
    /// 
    /// </summary>
    static class B
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var k = NextInt();

            var snk = new int[n + 1];
            snk[0] = 1;
            for (int i = 0; i < k; i++)
            {
                var d = NextInt();
                for (int j = 0; j < d; j++)
                {
                    var a = NextInt();
                    snk[a] = 1;
                }
            }
            Console.WriteLine(snk.Count(s => s == 0));
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27976
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())

    if N % 2 == 0:
        res = N // 2
    else:
        res = N // 2 + 1

    print(res)



main()


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int getsumdigits(int i);
int main()
{
    int n;
    cin >> n;
    int min = 10000;
    for(int i=1;i<=n/2;i++)
    {
        int a=i;
        int b=n-a;
        int tmp = getsumdigits(a);
        tmp += getsumdigits(b);
        if(tmp < min)
        {
            min = tmp;
        }
    }
    cout << min << endl;
}
int getsumdigits(int n)
{
    int res = 0;
    while(n > 0) 
    {
        res += n%10;
        n /= 10;
    }
    return res;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using std::__gcd;

const int MAXN=1e5+5;
int n,k,gcd;
int a[MAXN];
bool flag;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		if(a[i]==k){
			printf("POSSIBLE");
			return 0;
		}
		if(a[i]>k) flag=true;
	}
	if(!flag){
		printf("IMPOSSIBLE");
		return 0;
	}
	gcd=a[1];
	for(int i=2;i<=n;++i)
		gcd=__gcd(gcd,a[i]);
	if(k%gcd==0) printf("POSSIBLE");
	else printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>  
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <cmath>
#include <cstdio>
#include<unordered_set>
#include <cstring>
#include <iomanip>
#include <list>
typedef long long ll;
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define MAX 1000000 
using namespace std;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n; cin >> n;
  map<string, int> m;
  int maxk = 0;
  for (int i = 0; i < n; i ++) {
    string s; cin >> s;
    m[s] ++;
    if (m[s] > maxk) maxk = m[s];
  }
  vector<string> v;
  for (auto x : m) {
    if (x.second == maxk) {
      v.pb(x.first);
    }
  }
  sort(v.begin(), v.end());
  for (auto val : v) {
    cout << val << endl;
  }
  

}    
                

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

int main()
{
	int n;
	cin >> n;
	vector<int64_t> l(87);
	l.at(0) = 2LL;
	l.at(1) = 1LL;

	for (int i = 2; i <= n; i++)
	{
		l.at(i) = l.at(i - 1) + l.at(i - 2);
	}

	cout << l.at(n) << endl;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vi getInput(){
    vi ret;
    
    rep(i,9){
        int a,b;
        cin>>a;
        ret.pb(a);
        
        if(a<10){
            cin>>b;
            ret.pb(b);
        }
    }
    
    int a,b,c;
    cin>>a;
    cin>>b;
    ret.pb(a);
    ret.pb(b);

    if(a+b>=10){
        cin>>c;
        ret.pb(c);
    }

    
    return ret;
}



int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        vector<pii> data;
        rep(i,n){
            int gNum;
            cin>>gNum;
            
            vi in=getInput();
            int len=in.size();

            int sum=0;
            int c=0;
            rep(i,9){
                if(in[c]==10){
                    sum+=10+in[c+1]+in[c+2];
                    c++;
                }
                else if(in[c]+in[c+1]==10){
                    sum+=10+in[c+2];
                    c+=2;
                }
                else{
                    sum+=in[c]+in[c+1];
                    c+=2;
                }

            }
            while(c<len){
                sum+=in[c];
                c++;
            }
            data.pb(pii(sum,gNum));
        }
        
        rep(i,data.size()-1){
            for(int j=i+1;j<data.size();j++){
                if( data[i].first<data[j].first || (data[i].first==data[j].first && data[i].second>data[j].second) ){
                    swap(data[i],data[j]);
                }
            }
        }
        rep(i,data.size()){
            cout<<data[i].second<<" "<<data[i].first<<endl;
        }
        
    }
    return 0;
}



//3
//1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
//1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
//1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

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

int N,A,B;

void yes(){
  cout << "Yes"<< endl;
}
void no(){
  cout << "No" << endl;
}

int main(){
  cin >>N >> A >> B;
  int k = 0, s = 0, o = 0;
  
  for(int i=0;i<N;i++){
    char c; cin >> c;    
    if( c == 'a' ){
      if( k + s < A + B ) {
        yes();
        k++;
      }
      else no();

    } else if( c == 'b' ) {
      if(  k + s < A + B && s < B ) {
        yes();
        s++;
      }      
      else no();

    } else {
      o++;
      no();
    }
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n;   cin >> n;
    vector<ll> v(n, 0);
    rep(k, n){
        ll x=k+1;
        for(int i=1; i*i<=x; i++){
            if(x%i==0){
                v[k] += 1;
                if(x/i!=i) v[k] += 1;
            }
        }
    }
    ll res=0;
    rep(i, n){
        if(i%2) continue;
        res += v[i]==8;
    }
    cout << res << endl;
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<limits.h>

#define NK 100000

int main( int argc, char *argv[] ) 
{
	int n, k, w[NK], P = INT_MAX;

	scanf( "%d%d", &n, &k );

	int i, sum = 0, miniLoadings = 0;
	for ( i=0; i<n; i++ ) {
		scanf( "%d", &w[i] );
		sum += w[i];
		if( miniLoadings < w[i] ) {
			miniLoadings = w[i];
		}
	}
	
	int j, start;
	int truck, truckCnt, loadings;
	
	if( 1 == k ) {
        P = sum;    
    } else if( n == k ) {
    	P = miniLoadings;
    } else {
    	miniLoadings = sum/k;
		start = loadings = 0;
		for( i=0; i<n; i++ ) {
			loadings += w[i];
			if( P <= loadings ) { 
				loadings -= w[ start++ ];
				loadings -= w[ i-- ];
				continue;
			}
			if( miniLoadings <= loadings ) {
				truck = 0;
				truckCnt = k;
				for( j=0; truckCnt!=0 &&  j<n; j++ ) {
					truck += w[j];
					if( loadings < truck ) {
						truckCnt--;
						j--;
						truck = 0;
					}
				}
				if( truckCnt && loadings < P ) {
					P = loadings;
					loadings -= w[ start++ ];
					loadings -= w[ i-- ];
				} else {
					miniLoadings = loadings;
				}
			}
		}
	}

	printf( "%d\n", P );
	
    return 0;
}

Measured memory_bytes: 988