akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);

int main() {
	int n;
	cin >> n;
	ll ans = 1;
	for (int i = 2;i <= n;++i) {
		facterize(i);
	}
	for (auto p : ins) {
		ll x = p.second;
		ans *= (x + 1);
		ans = ans % 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vll vector<ll>
#define vec vector
#define pb push_back
#define pop pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define FASTio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//ll mod = 1000000007;
void solve() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b > 0 && d > 0)cout << max((a * 1LL * c), (b * 1LL * d));
	elif(b <= 0 && d <= 0)cout << (a * 1LL * c);
	elif(b <= 0 && d > 0) cout << max((a * 1LL * c), (b * 1LL * c));
	elif(b > 0 && d <= 0)cout << max((a * 1LL * c), (a * 1LL * d));
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FASTio
	// START FROM HERE :)

	solve();

}





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

ll counter(ll x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    vector<vector<ll>> X(16, vector<ll>(16, 0));
    vector<vector<ll>> Y(16, vector<ll>(16, 0));
    for(int i=1;i<N+1;i++){
        cin>>A[i];
        for(int j=1;j<=A[i];j++){
            cin>>X[i][j]>>Y[i][j]
        ;}
    ;}
    ll Max=0;
    
   for(int bit=0;bit<(1<<N);bit++){bool check=1;
    for(int i=1;i<N+1;i++){if(bit&(1<<N-i)){
     for(int j=1;j<A[i]+1;j++){
         if((bit>>(N-X[i][j])&1)^Y[i][j]){check=0;}
     ;}}
    ;}
    if(check==1){Max=max(Max,counter(bit));
    }
    }
    cout<<Max<<endl;


return 0;
}  



Measured memory_bytes: 256
n = gets.to_i
p = gets.split.map(&:to_i)
i = 0
wn = 0
while i < n
  wn += 1 if p[i] != (i + 1)
  i += 1
end

if wn == 0 || wn == 2
  puts 'YES'
else
  puts 'NO'
end

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

int main(){
  long N;
  long power1, power2;
  long real_power;
  long time_total=0;
  long time_use;
  cin >> N;
  cin >> power2;
  time_use = (N-1)/power2+1;
  time_total += time_use;
  for(int i=0; i<4; i++){
    power1 = power2;
    cin >> power2;
    power2 = min(power1, power2);
    time_total += (N-1)/power2+1 - time_use + 1;
    time_use = (N-1)/power2+1;
  }
  cout << time_total << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = input()
snp = np.array(list(map(int,s)))

cand1 = (1 == snp[0::2]).sum() + (0 == snp[1::2]).sum()
cand2 = (0 == snp[0::2]).sum() + (1 == snp[1::2]).sum()

print(min(cand1,cand2))

Measured memory_bytes: 15796
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[100001];
int b[100000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	int ans = 0;
	rep(i, n) {
		int t1 = min(a[i], b[i]);
		a[i] -= t1;
		ans += t1;
		b[i] -= t1;
		int t2 = min(a[i + 1], b[i]);
		a[i + 1] -= t2;
		ans += t2;
		b[i] -= t2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
use proconio::input;

fn main() {
    input! {
        k: i64,
        a: i64,
        b: i64,
    }

    let mut ans = false;
    for v in a..=b {
        if v % k == 0 {
            ans = true;
        }
    }

    if ans {
        println!("OK");
    } else {
        println!("NG");
    }
}


Measured memory_bytes: 2104
def solve():
    x,y = map(int, input().split())

    cand = []

    cand.append(y - x)
    cand.append(y - (-x) + 1)
    cand.append((-y) - (-x) + 2)
    cand.append((-y) - x + 1)

    print(min(*list(filter(lambda a: a >=0, cand))))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

map<int, int> mp;
int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  rep(i, Q){
    int tmp;
    cin >> tmp;
    if(mp.count(tmp)){
      mp[tmp]++;
    }else{
      mp[tmp] = 1;
    }
  }
  rep(i, N){
    if(Q - mp[i + 1] < K){
      cout << "Yes" <<endl;
    }else{
      cout << "No" <<endl;
    }
  }
}
  

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x,y) fixed<<setprecision(y)<<x
#define ll long long
#define ld long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    fast_io()
    
    int a,b;
    cin>>a>>b;

	int arr[a][b];
	memset(arr,0,sizeof(arr));

	lop(i,0,a){
		int t;
		cin>>t;
		lop(j,0,t){
			int x;
			cin>>x;

			arr[i][x-1] = 1;
		}
	}

	int ans=0;
	lop(i,0,b){
		bool flag=true;
		lop(j,0,a){
			// cout<<arr[j][i]<<" ";
			if(arr[j][i]==0){
				flag=false;
				break;
			}
		}
		// cout<<endl;
		if(flag)
			ans++;

	}

	cout<<ans;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            //ここから
            var hoge = IO.ReadLineToIntArray();

            var ans = hoge[0] - hoge[1] * 2;
            ans = ans < 0 ? 0 : ans;

            //ここまで
            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }
        static public int Conbin(int n, int m) { return Factorial(n) / (Factorial(n - m) * Factorial(m)); }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < (long)Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public string[] ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToArray(); }
        static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define f first
#define s second
#define endl '\n'
typedef long long int lli;

int main() {
	optimizar_io
	int n, a, b;
	cin >> n >> a >> b;

	if((b - a - 1) & 1) {
		cout << "Alice" << endl;
	} else cout <<  "Borys" << endl;

}

Measured memory_bytes: 256
import bisect

N = int(input())
L = list(map(int, input().split()))

Sum = 0
L.sort(reverse=False)

for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        hoge = 0
        hoge = j - bisect.bisect(L, L[i] - L[j])
        if hoge < 0:
            hoge = 0
        Sum += hoge

print(Sum)


Measured memory_bytes: 43996
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

(N, M) = reads()

if N == M == 1:
  ans = 1
elif N > 1 and M == 1:
  ans = N - 2
elif M > 1 and N == 1:
  ans = M - 2
else:
  ans = (N - 2) * (M - 2)

print(ans)


Measured memory_bytes: 3572
#include <stdio.h>
#include <vector>
#include <queue>
#include <memory.h>
#include <functional>
#include <algorithm>
#include <math.h>
using namespace std;

//FILE * in = freopen("input.txt", "r" , stdin);

const int n = 123456;
int data[123456*2 + 2];

void init(){
	int i, j;
	fill(data, data+n*2+10, -1);
	data[2] = 1;

	for(i = 3; i <= n*2; i++) {
		if (data[i] == 0) continue;
		if(i%2 == 0) {
			data[i] = 0;
			continue;
		}
		data[i] = 1;
		for(j = 2; i * j <= n*2 ; j++) {
			data[i*j] = 0;
		}
	}
}

void process(int x) {
	int cnt = 0;
	for(int i = x + 1; i <= 2*x; i++) {
		if(data[i] == 1)
			++cnt;
	}
	printf("%d\n", cnt);
}

int main() {
	int x;
	init();
	while(true) {
		scanf("%d", &x);
		if (x == 0) break;
		process(x);
	}
	return 0;
}

Measured memory_bytes: 1992
N = int(input())
if N == 3:
    print('2 5 63')
    exit()

ans = []
total = 0
for n in range(1,30001):
    if n%2 == 0 or n%3 == 0:
        ans.append(n)
        total += n
    if len(ans) == N: break

if total%6 == 1:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 2

elif total%6 == 2:
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 4

elif total%6 == 3:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3

elif total%6 == 4:
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 2

elif total%6 == 5:
    i = N - 1
    while ans[i]%3 > 0:
        i -= 1
    ans[i] += 3
    i = N - 1
    while ans[i]%2 > 0:
        i -= 1
    ans[i] += 4

print(*ans)

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

int main(){
    int W,H,x,y,r;
    cin >>W>>H>>x>>y>>r;
    if (x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H) cout <<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define LEN 100005
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) {if (x % y == 0) return y;else return LGCD(y, x % y);}
ll LLCM(ll x, ll y) {return x * y / LGCD(x, y);}

int GCD(int x, int y) {if (x % y == 0) return y;else return GCD(y, x % y);}
int LCM(int x, int y) {return x * y / GCD(x, y);}
ll dp[10000][10000];
ll combination(ll n, ll r) {
         if (n == r){dp[n][n] = 1;}
	else if (r == 0) {return dp[n][0] = 1;}
	else if (r == 1) {return dp[n][1]=n;}
	else {dp[n][r]=dp[n - 1][r - 1] % 1000000007 + dp[n - 1][r] % 1000000007;
	return dp[n][r]=combination(n - 1, r - 1) % 1000000007 + combination(n - 1, r) % 1000000007;}
}
int main() {
	int a, b;
	cin >> a>>b;
	int ans;

	if (a < 0 && b < 0)ans = a * b;
	else if (a > 1 && b > 1)ans = a * b;
	else if (a >= 0 && b <= 0)ans = a - b;
	else ans = a + b;
	


	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
  cin>>str;
  cout<<str[0]<<str.length()-2<<str[str.length()-1]<<endl;
  
    return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b;

	cin >>a >>b;
	if(a.size()>b.size())cout<<"GREATER"<<endl;
	else if(a.size()<b.size())cout<<"LESS"<<endl;
	else{
		if(a>b)cout<<"GREATER"<<endl;
		else if(a<b)cout<<"LESS"<<endl;
		else cout<<"EQUAL"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::min;

fn main() {
    let tmp: Vec<usize> = read_vec();
    let x = tmp[0];
    let y = tmp[1];
    let c = tmp[4];
    let mut p: Vec<u64> = read_vec();
    let mut q: Vec<u64> = read_vec();
    let mut r: Vec<u64> = read_vec();

    p.sort();
    p.reverse();
    q.sort();
    q.reverse();
    r.sort();
    r.reverse();

    let mut v: Vec<u64> = vec![];
    for i in 0..x {
        v.push(p[i]);
    }
    for i in 0..y {
        v.push(q[i]);
    }

    v.sort();

    for i in 0..min(c, x + y) {
        if r[i] > v[i] {
            v[i] = r[i];
        } else {
            break;
        }
    }

    let ans = v.iter().fold(0, |s, a| s + a);

    println!("{}", ans);
}


Measured memory_bytes: 13168
def main():
    N, M = map( int, input().split())
    AB = [ tuple( map( int, input().split())) for _ in range(M)]
    V = [0]*(N+1)
    for a, b in AB:
        V[a] += 1
        V[b] += 1
    for v in V:
        if v%2 == 1:
            print("NO")
            return
    print("YES")
        
if __name__ == '__main__':
    main()


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

int main(){
int N,M;
  cin>>N;
  vector<string>S(N);
  for(int i=0; i<N; i++){
   cin>>S[i]; }
  
  cin>>M;
  vector<string>T(M);
  for(int i=0; i<M; i++){
   cin>>T[i]; }
  
  vector<int>count(110);
  for(int i=0; i<N; i++){
   for(int j=0; j<N; j++){
    if(S[i]==S[j]){count[i]++;} }}

  for(int i=0; i<N; i++){
   for(int j=0; j<M; j++){
    if(S[i]==T[j]){count[i]--;} }}
  
  int ans=*max_element(count.begin(), count.end());
  cout<<ans;
}

Measured memory_bytes: 256
// original code was by Alan_cty,I modified a teeny-tiny place.This code is only for testing.
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define fo(i,a,b) for(int i=a;i<=b;i++)
    #define fd(i,a,b) for(int i=a;i>=b;i--)
    using namespace std;
     
    typedef long long ll;
     
    int read() {
        char ch;
        for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
        int x=ch-'0';
        for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
        return x;
    }
     
    const int N=3*1e5+5;
     
    int w,h,n,ta,tb,ans;
    struct P{int x,y;}p[N],sta[N],stb[N];
    bool cmp(P x,P y) {return x.x<y.x;}
     
    int tr[N<<2],tag[N<<2];
     
    void add(int v,int z) {tr[v]+=z;tag[v]+=z;}
     
    void down(int v) {
        if (tag[v]) {
            add(v<<1,tag[v]);
            add(v<<1|1,tag[v]);
            tag[v]=0;
        }
    }
     
    void modify(int v,int l,int r,int x,int y,int z) {
        if (l==x&&r==y) {add(v,z);return;}
        int mid=l+r>>1;down(v);
        if (y<=mid) modify(v<<1,l,mid,x,y,z);
        else if (x>mid) modify(v<<1|1,mid+1,r,x,y,z);
        else modify(v<<1,l,mid,x,mid,z),modify(v<<1|1,mid+1,r,mid+1,y,z);
        tr[v]=max(tr[v<<1],tr[v<<1|1]);
    }
     
    void solve() {
        sort(p+1,p+n+1,cmp);
        fo(i,1,n<<2) tr[i]=tag[i]=0;
        ta=tb=0;
        fo(i,1,n) {
            ans=max(ans,tr[1]+p[i].x);
            if (p[i].y<=h/2) {
                int la=i-1;
                while (ta&&sta[ta].y<p[i].y) {
                    modify(1,1,n,sta[ta].x,la,sta[ta].y-p[i].y);
                    la=sta[ta--].x-1;
                }
                if (la!=i-1) sta[++ta].x=la+1,sta[ta].y=p[i].y;
            } else {
                int la=i-1;
                while (tb&&stb[tb].y>p[i].y) {
                    modify(1,1,n,stb[tb].x,la,p[i].y-stb[tb].y);
                    la=stb[tb--].x-1;
                }
                if (la!=i-1) stb[++tb].x=la+1,stb[tb].y=p[i].y;
            }
            sta[++ta].x=i;sta[ta].y=0;
            stb[++tb].x=i;stb[tb].y=h;
            modify(1,1,n,i,i,h-p[i].x);
        }
    }
     
    int main() {
        //freopen("paint.in","r",stdin);
       // freopen("paint.out","w",stdout);
        w=read();h=read();n=read();
        fo(i,1,n) {
            p[i].x=read();
            p[i].y=read();
        }
        p[++n].x=0;p[n].y=0;
        p[++n].x=w;p[n].y=h;
        solve();
        fo(i,1,n) swap(p[i].x,p[i].y);
        swap(w,h);
        solve();
        printf("%d\n",ans*2);
        return 0;
    }

Measured memory_bytes: 16512
#include<stdio.h>
int main()
{
	int S, h, m, s;
	scanf("%d", &S);

	h = S / 3600;
	m = (S - 3600 * h) / 60;
	s = S % 60;

	printf("%d:%d:%d\n",h,m,s);
	return 0;
	

}

Measured memory_bytes: 1020
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools

# 標準入力を取得
N = int(input())
x, y = [], []
for n in range(N):
    x_n, y_n = list(map(int, input().split()))
    x.append(x_n)
    y.append(y_n)


def get_distance(i: int, j: int) -> float:
    return math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)


def get_path_length(distance: dict, path: list) -> float:
    path_length = 0
    for n in range(N - 1):
        path_length += distance[(path[n], path[n + 1])]

    return path_length


# 求解処理
distance = {}
for i, j in itertools.product(range(N), range(N)):
    distance[(i, j)] = get_distance(i, j)

ans = 0
for path in itertools.permutations(range(N)):
    ans += get_path_length(distance, path)
ans /= math.factorial(N)

# 結果出力
print(ans)


Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int a[n+1];
	vector<int> v[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans++;
		for(int j=0;j<v[i].size();j++){
			if(a[v[i][j]]>=a[i]){
				ans--;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9156
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int64 position[M],distance[M-1];
  rep(i,M){
    cin>>position[i];
  }
  sort(position,position+M);
  rep(i,M-1){
    distance[i]=position[i+1]-position[i];
  }
  sort(distance,distance+M-1);
  int64 ans=0;
  rep(i,M-N){
    ans+=distance[i];
  }
  if(N>=M){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void sbs()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}
void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
#define N 1000002
vector<vi> dp(102,vi(N,INT_MAX));

int32_t main()
{
    //sbs();
    // int t;cin>>t;
    // while(t--) {
        
    //     cout<<'\n';
    // }

    int n,w;cin>>n>>w;
    vi v(n+1),wt(n+1);
    
    for (int i = 1; i <= n; ++i){
        cin>>wt[i]>>v[i];
    }
    dp[0][0]=0;
    for (int i = 1; i < n+1; ++i){
        dp[i][0]=0;
    }
    for (int i = 1; i < n+1; ++i){
        for (int j = 1; j < N; ++j){
            if(v[i]<=j && dp[i-1][j-v[i]]!=INT_MAX){
                dp[i][j]=min(dp[i-1][j],wt[i]+dp[i-1][j-v[i]]);
            }else dp[i][j]=dp[i-1][j];
        }
    }
    int mx=0;
    for (int i = 1; i < N; ++i){
        if(dp[n][i]<=w){
            mx=i;
        }
    }
    cout<<mx<<endl;
    return 0;
}

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

using namespace std;

const int N = 1 << 18;
const int INF = 1e6;

int n;
int a[N + 5], b[N + 5];
int dp[N + 5][51];
int val[N + 5];

int f(int id, int mask){
	int ret = 0;
	for(int i=0; i<id; i++){
		if((1 << i) & mask) continue;
		ret++;
	}
	return ret;
}

int solve(int mask, int last, int vlast){
	if(mask == (1 << n) - 1) return 0;
	int& ret = dp[mask][vlast];
	if(ret != -1) return ret;
	ret = INF;
	for(int i=0; i<n; i++){
		if(mask & (1 << i)) continue;
		int v = abs(val[mask] - i) % 2 == 0 ? a[i] : b[i];
		if(vlast > v) continue;
		ret = min(ret, solve(mask | (1 << i), i, v) + f(i,mask));
	}
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(int i=0; i<N; i++){
		int cnt = 0;
		for(int j=0; j<18; j++) if(i & (1 << j)) cnt++;
		val[i] = cnt;
	}
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	memset(dp,-1,sizeof dp);
	int ans = INF;
	for(int i=0; i<n; i++){
		ans = min(ans, solve(1 << i, i, (i % 2 == 0) ? a[i] : b[i]) + i);
	}
	if(ans >= 1000) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 55552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using Edge = pair<int, int>;


vector<vector<Edge>> G;
vector<int> dist;
vector<bool> seen;

bool dfs(int v){
    bool ret = false;
    for(auto e : G[v]){
        int nv = e.first;
        int cost = e.second;
        if(seen[nv]){
            //矛盾
            if(dist[nv] != dist[v] + cost) return true;
        }else{
            dist[nv] = dist[v] + cost;
            seen[nv] = true;
            ret |= dfs(nv);
        }
    }
    return ret;
}

int main(){
    int n, m; cin >> n >> m;
    G.resize(n);
    dist.assign(n, 0);
    seen.assign(n, 0);
    rep(i,m) {
        int l, r, d; cin >> l >> r >> d;
        --l, --r;
        G[l].push_back(Edge(r, d));
        G[r].push_back(Edge(l, -d));
    }
    rep(i,n){
        if(!seen[i]){
            dist[i] = 0;
            seen[i] = true;
            if(dfs(i)){
                cout << "No" << endl;
                //for(auto e : dist) cout << e;
                cout << endl;
                return 0;
            }
        }  
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 12032
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

int n[5];

int main()
{
	for(int i = 0; i < 5; i++)
	{
		scanf("%d",n + i);
	}
	sort(n,n + 5);
	printf("%d %d %d %d %d\n",n[4],n[3],n[2],n[1],n[0]);
	return 0;
}

Measured memory_bytes: 1204
N = input()
heights = [0] * N
line = raw_input()
T = map(int, line.split())
line = raw_input()
A = map(int, line.split())

def cal():
    preMax = 0
    for i in xrange(N):
        if T[i] > preMax:
            heights[i] = T[i]
            preMax = T[i]
        else:
            heights[i] = -preMax

    preMax = 0
    for i in xrange(N-1, -1, -1):
        if A[i] > preMax:
            # check
            if heights[i] > 0 and heights[i] != A[i]:
                return 0
            if heights[i] < 0 and A[i] > -heights[i]:
                return 0
            heights[i] = A[i]
            preMax = A[i]
        else:
            # heights[i] should <= preMax
            if heights[i] > 0 and heights[i] > preMax:
                return 0
            if heights[i] < 0:
                heights[i] = max(heights[i], -preMax)

    total = 1
    for i in xrange(N):
        if heights[i] < 0:
            total *= -heights[i]
            total %= (10 ** 9 + 7)

    return total

print cal()

Measured memory_bytes: 16368
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String out;
        switch(n % 10){
            case 3:
                out = "bon";
                break;
            case 0:
                out = "pon";
                break;
            case 1:
                out = "pon";
                break;
            case 6:
                out = "pon";
                break;
            case 8:
                out = "pon";
                break;
            default:
                out = "hon";
                break;
        }
        System.out.println(out);
        scan.close();
    }
}

Measured memory_bytes: 26992
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, M = map(int, input().split())

if M % 2 != 0:
    print(-1)
    exit()

G = [[] for i in range(N)]
E = []
for i in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    G[a].append(b)
    G[b].append(a)
    E.append((a, b))

visited = [False] * N
T = [set() for i in range(N)]
que = [0]
while que:
    u = que.pop()
    for w in G[u]:
        if visited[w]:
            continue
        visited[w] = True
        T[u].add(w)
        T[w].add(u)
        que.append(w)


ans = []
deg = [0] * N
for a, b in E:
    if b in T[a]:
        continue
    ans.append((a, b))
    deg[a] += 1


def dfs(u, p):
    for w in T[u]:
        if w == p:
            continue
        dfs(w, u)
        if deg[w] % 2 != 0:
            ans.append((w, u))
            deg[w] += 1
        else:
            ans.append((u, w))
            deg[u] += 1


dfs(0, -1)
for a, b in ans:
    print(a + 1, b + 1)

Measured memory_bytes: 515976
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D,E,K;
    cin >> A >> B >> C >> D >> E >> K;
    string code ="Yay!";
    if(abs(A-B)>K || abs(A-C)>K || abs(A-D)>K || abs(A-E)>K || abs(B-C)>K || abs(B-D)>K || abs(B-E)>K 
    || abs(C-D)>K || abs(C-E)>K || abs(D-E)>K)
    code = ":(";
    cout << code << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int n, m, ans=0, a, x[100];
	char s[100][10], t[100][10];

	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%s", s[i]);
	}
	scanf("%d", &m);
	for(int i=0; i<m; i++){
		scanf("%s", t[i]);
	}

	for(int i=0; i<n; i++){
		x[i]=0;
		for(int j=0; j<n; j++){
			a=strcmp(s[i], s[j]);
			if(a==0){
				x[i]++;
			}
		}
		for(int j=0; j<m; j++){
			a=strcmp(s[i], t[j]);
			if(a==0){
				x[i]--;
			}
		}
	}

	for(int i=0;i<n; i++){
		if(x[i]>=ans){
			ans=x[i];
		}
	}

	printf("%d\n", ans);

	return 0;

}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main(){
    double a,b,avg;
    int res;
    
    scanf("%lf %lf",&a,&b);
    
    avg=(a+b)/2;
    
    res=ceil(avg);
    
    printf("%d\n",res);
    
    return 0;
}

Measured memory_bytes: 128
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]

  dl = 2
  while dl < len(S):
    center = (len(S) - dl) // 2
    if S[:center] == S[center:-dl]:
      print(len(S)-dl)
      return
    dl += 2


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


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


int main(){
  int N;
  cin >> N;
  int W[N], total;
  int S[N] = {};
  int tmp = 0;
  // for(int i = 0; i < N; i++) cin >> W[i];
  // sort(W, W + N);
  for(int i = 0; i < N; i++){
    cin >> W[i];
    tmp += W[i];
    S[i] = tmp;
    // cout << S[i] << " ";
    // total += W[N];
  }

  int ans = 1000000;
  for(int i = 0; i < N-1; i++){
    ans = min(abs(S[N-1] - S[i] - S[i]), ans);
  }
  // cout << S[N-1] << " " << ans << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int H, W;
	scanf("%d %d", &H, &W);
	int N;
	scanf("%d", &N);
	int color[100][100];
	SET_ZERO(color);
	int x = 0, y = 0;
	int dx = 1;
	for (int i = 0; i < N; i++) {
		int a;
		scanf("%d", &a);
		for (int j = 0; j < a; j++) {
			color[y][x] = i+1;
			x += dx;
			if (!(0 <= x && x < W)) {
				x -= dx;
				dx *= -1;
				y++;
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			printf("%d ", color[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int)n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 


 
int main(){
	//in_o();
	string s;
	cin>>s;
	int a=0,b=0;
	FOR(i,0,s.length()){
		if(i%2){
			if(s[i]=='0')a++;
			else b++;
		}else{
			if(s[i]=='1') a++;
			else b++;
		}
	}
	cout<<min(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

bool comp(const pair<int, int> &j1, const pair<int, int> &j2){
  if(j1.first != j2.first)
    return j1.first < j2.first;
  else
    return j1.second > j2.second;
}

bool comp2(const pair<int, int> &j1, const pair<int, int> &j2){
  return j1.first >= j2.first;
}

int main(){
  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> jobs(n);
  for(int i = 0; i < n; i++)
    cin >> jobs[i].first >> jobs[i].second;

  stable_sort(jobs.begin(), jobs.end(), comp);

  queue<pair<int, int>> jobs_que;
  for(int i = 0; i < n; i++){
    if(jobs[i].first > m)
      break;
    jobs_que.push(jobs[i]);
  }
  
  int ans = 0;
  priority_queue<int> cands;
  
  for(int i = 0; i < m; i++){
    while(!jobs_que.empty() && jobs_que.front().first - 1 <= i){
	cands.push(jobs_que.front().second);
	jobs_que.pop();
    }
    
    if(cands.empty())
      continue;
    ans += cands.top();
    cands.pop();
  }

  cout << ans << endl;
  
  return 0;
}

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

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

  int a;
  int min_a = INT_MAX;
  int max_a = INT_MIN;
  rep(i, N) {
    cin >> a;
    max_a = max(max_a, a);
    min_a = min(min_a, a);
  }
  cout << max_a - min_a << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
typedef long long unsigned int ll;
using namespace std;

int main(){
          int a,b,x;
          cin >> a >> b >> x;
          if(a<=x and x<=a+b)   cout << "YES" << endl;
          else cout << "NO" << endl;
          return 0;
}



Measured memory_bytes: 256
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>
#include<memory>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

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

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
ll N, M;
string S, T, X;


ll gcd(ll a, ll b) {
	if (a < b)return gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}




//サブ関数
//入力
void input()
{
	cin >> N >> M >> S >> T;
}


//計算
void calc()
{
	ll lenX = N * M / gcd(N, M);
	map<ll, char> mp;

	ll ln = lenX / N;
	ll lm = lenX / M;
	REP(i, N)mp[ln*i + 1] = S[i];
	REP(i, M) {
		auto itr = mp.find(lm*i + 1);
		if (itr != mp.end() && itr->second != T[i]) {
			cout << -1 << endl;
			return;
		}
	}
	cout << lenX << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 6144
h,w=[int(x) for x in input().split()]
a=[]
for _ in [0]*h:
    ai=list(input())
    if "#" in ai:
        a.append(ai)
tenchi=[]
for wi in zip(*a):
    if "#" in wi:
        tenchi.append(wi)
for ansi in zip(*tenchi):
    print("".join(ansi))

Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>

using namespace std;

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

int main() {
    int N, K; cin >> N >> K;
    int h[N]; rep(i, N) cin >> h[i];

    sort(h, h + N);

    int hd[N - K + 1];
    rep(i, N - K + 1) hd[i] = h[i + K - 1] - h[i];

    cout << *min_element(hd, hd + N - K + 1);

    return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


int n;
ll a[3005];
ll s[405];
ll dp[405][405]; // dp[i][j]:=[i,j)の最小値

ll rec(int i, int j){
  if(dp[i][j]!=LINF) return dp[i][j];
  if(j-i==1) return dp[i][j]=0;
  
  for(int m=i+1; m<j; m++){
    chmin(dp[i][j], rec(i,m)+rec(m,j));
  }
  dp[i][j]+=s[j]-s[i];
  return dp[i][j];
}

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
    s[i+1]=s[i]+a[i];
  }
  rep(i,n+1) rep(j,n+1) dp[i][j]=LINF;
  
  cout<<rec(0,n)<<endl;
}

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

using namespace std;
typedef long long ll;

ll n, x;

ll rec(ll a, ll b) {
  if (a == 0 || b == 0) return 0;
  return a + (a / b * 2 - 1) * b + rec(b, a % b);
}

int main(void) {
  cin >> n >> x;
  cout << x + rec(n - x, x) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ll piv = 1;
  ll bre = 0;
  rep(i,n){
    if(vec[i] == piv){
      piv++;
    }else{
      bre++;
    }
  }
  if(bre == n){
    bre = -1;
  }
  cout << bre << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll N; cin >> N;
  vector<ll> A(N), B(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i] >> B[i];
  }
  ll ans = 0;
  for(int i = N - 1; i >= 0; --i){
    A[i] += ans;
    if(A[i] % B[i] != 0)
      ans += ((A[i]/B[i]) + 1) * B[i] - A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,a,b,c,d,h,w,x,y;
string str;

signed main(){

  cin >> str;
  FOR(i,str.length()-1){
    if(str[i]=='A' && str[i+1]=='C'){
      cout <<"Yes\n";
      return 0;
    }
  }
  cout <<"No\n";
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back 
#define pob pop_back
#define mp make_pair

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    if(x>=30)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No";
    return 0;
}

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

int g[15][15];
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,s.size()) {
        s[i] = (s[i]-'A'+n)%26 + 'A';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
int main()
{
   char a[100000];
    scanf("%s",a);
    int n,i;
    n=strlen(a);
    int s=0;
    for(i=0;i<n/2;i++)
    {
    	if(a[i]!=a[n-i-1])
    	s++;
	}
	printf("%d\n",s);

   
}

Measured memory_bytes: 128
using System;

namespace _99_2
{
    class Program
    {
        static void Main(string[] args)
        {
			string[] str = Console.ReadLine().Split(' ');
			int a = int.Parse(str[0]);
			int b = int.Parse(str[1]);
			Console.WriteLine(((1 + b - a) * (b - a) / 2) - b);
		}
    }
}
 

Measured memory_bytes: 13140
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		Integer A[]=new Integer [N]; for(int i=0;i<N;i++)A[i]=sc.nextInt();
		int F[]=new int [N]; for(int i=0;i<N;i++)F[i]=sc.nextInt();
		
		Arrays.sort(A,Collections.reverseOrder());
		for(int i=0;i<N;i++)A[i]=A[i].intValue();
		Arrays.sort(F);
		long l=-1, r=(long)Math.pow(10, 12);
		while(r>l+1) {
			long c = l+(r-l)/2;
			boolean ok = func(c,N,A,F,K);
			if(ok)r=c;else l=c;
		}
		System.out.println(r);
	}
	
	static boolean func(long c, int N,Integer[] a, int F[], long K) {
		long sum=0;
		for(int i=0;i<N;i++) {
			sum += Math.max(0, a[i]-c/F[i]);
		}
		return sum<=K;
	}
}


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

int main() {
    int n;
    cin >> n;
    pair<int, int> a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i].second >> a[i].first;
    sort(a, a + n);
    int time = 0;
    for (int i = 0; i < n; i++) {
        time += a[i].second;
        if (time > a[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1920