akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

char s[9][5], t[3][3][5];
int dx[]{ -1,0,1,0 }, dy[]{ 0,1,0,-1 };
int dfs(int p) {
	int res = 0;
	rep(i, 3)rep(j, 3) {
		if (t[i][j][0])continue;
		rep(k, 4) {
			rep(l, 4) {
				int nx = i + dx[l], ny = j + dy[l];
				if (nx < 0 || 3 <= nx || ny < 0 || 3 <= ny || !t[nx][ny][0])continue;
				if (abs(s[p][(l + k) % 4] - t[nx][ny][(l + 2) % 4]) != 'a' - 'A')goto g;
			}
			if (p == 8)res++;
			else {
				rep(l, 4)t[i][j][l] = s[p][(l + k) % 4];
				res += dfs(p + 1); t[i][j][0] = 0;
			}g:;
		}
	}
	return res;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		rep(j, 9)cin >> s[j];
		printf("%d\n", dfs(0));
	}
}

Measured memory_bytes: 3092
#include <stdio.h>
int main(){

   int n, i, j, v,  r[100]; 
   
   scanf("%d", &n);
   for(i = 0; i < n; i++){
       scanf("%d", &r[i]);
   }
   
   for(i = 1; i < n; i++){
   	   for(j = 0; j < n; j++){
   	   	    printf("%d", r[j]);
   	   	    if(j < n - 1){
   	   	    	printf(" ");
   	   	    }
   	   }
   	   printf("\n");
   	   v = r[i];
   	   j = i - 1;
   	   while(j >= 0 && r[j] > v){
   	   	    r[j + 1] = r[j];
   	   	    j--;
   	   	    r[j + 1] = v;
   	   }
   }
   
   for(i = 0; i < n; i++){
   	    printf("%d", r[i]);
   	    if(i < n - 1){
   	    	printf(" ");
   	    }
   }
   printf("\n");
   return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    int dp[410][410];
    for (int i = 0; i < 410; ++i) {
        for (int j = 0; j < 410; ++j) {
            dp[i][j] = M;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = 400; j >= a; --j) {
            for (int k = 400; k >= b; --k) {
                dp[j][k] = min(dp[j][k], dp[j - a][k - b] + c);
            }
        }
    }
    int ans = M;
    for (int i = 1; i * ma < 410 && i * mb < 410; ++i) {
        ans = min(ans, dp[i * ma][i * mb]);
    }
    cout << (ans < M ? ans : -1) << "\n";
    return 0;
}


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

int panjang;
string s;
string t;

int main(){
	cin>>s;
	panjang=s.length();
	if(panjang%2==0){
		panjang-=1;
	}
	for(int i=0;i<=panjang;i+=2){
		t+=s[i];
	}
	cout<<t<<endl;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int A = sc.nextInt();
		final int B = sc.nextInt();

		int[] prob = new int[3];

		for (int i = 0; i < N; i++) {
			int pi = sc.nextInt();
			if (pi <= A) {
				prob[0]++;
			} else if (pi > A && pi <= B) {
				prob[1]++;
			} else {
				prob[2]++;
			}
		}

		System.out.println(Math.min(Math.min(prob[0], prob[1]), prob[2]));

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans=0;
    for(int i=0; i<6; ++i){
        if(s[i]=='1')ans++;
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  REP(i,26) {
    REP(j,16) {
      if(i * 4 + j * 7 == n) {cout << "Yes" << endl; return 0;}
    }
  }
  cout << "No" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize
    };
    if n == 1 {
        println!("0");
        return;
    }
    // 10^n - 2*9^n + 8^n
    let (mut a, mut b, mut c) = (10isize, 9isize, 8isize);
    for _ in 1..n {
        a = a * 10 % 1000000007;
        b = b * 9 % 1000000007;
        c = c * 8 % 1000000007;
    }
    let mut rs = (a - 2 * b + c) % 1000000007;
    if rs < 0 {
        rs += 1000000007;
    }
    println!("{}", rs);
}


Measured memory_bytes: 2172
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int p[] = new int[n];

        for(int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);

        int amount = 0;
        for(int i = 0; i< k; i++) {
            amount += p[i];
        }

        System.out.println(amount);
    }
}

Measured memory_bytes: 38864
#include <stdio.h>

int main()
{
  int ans, X;
  scanf("%d", &X);
  for (int i = 1; i < X; i++)
    if ((1 + i) * i / 2 >= X) {
      ans = i;
      break;
    }
  printf("%d", ans);
  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    rep(_, N){
        char s;
        cin >> s;
        if(s == 'Y') drop("Four");
    }
    drop("Three");
    return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    A = B = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a > b:
            A += a + b
        elif a < b:
            B += a + b
        else:
            A += a
            B += b
    print(A, B)

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
 int main() {
     int n, k;
     cin >> n >> k;
     string s;
     cin >> s;
     s[k-1] += 32;
     cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで

int main() {
  int64_t n, a, b, ans=0;
  cin >> n >> a >> b;
  int64_t x[n];
  for(int i=0; i<n; i++)
    cin >> x[i];
  for(int i=1; i<n; i++){
    int tmp = x[i]-x[i-1];
    if(tmp*a<b) ans+=tmp*a;
    else ans+=b;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 4368
#include<iostream>
#include<string>

using namespace std;

int main()
{
    string str;
    cin>>str;
    int flag=0;
    for(int i=0;i<str.size();i++)
    {
        if(i%2==0)
        {
            if(str[i]=='R'||str[i]=='U'||str[i]=='D')
                continue;
            else
            {
                flag=1;
                break;
            }
        }
        else
        {
            if(str[i]=='L'||str[i]=='U'||str[i]=='D')
                continue;
            else
            {
                flag=1;
                break;
            }
        }

    }
    if(!flag)
            cout<<"Yes";
        else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 200010;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

ll pw(ll a, ll x){
	ll ret = 1;
	a %= mod;
	while(x){
		while(!(x&1)){
			(a *= a) %= mod;
			x /= 2;
		}
		(ret *= a) %= mod;
		x--;
	}
	return ret;
}
int main(){
	ll n,a,b,c,i,j;
	cin >> n >> a >> b >> c;
	inverse();
	ll s = 0,t = 0,p = 1,q = 1;
	ll x = b*inv[100 - c]%mod,y = a*inv[100 - c]%mod;
	for(i=0;i<n;i++){
		(s += comb(n + i - 1,i)%mod*p%mod*(n + i)) %= mod;
		(p *= x) %= mod;
	}
	(s *= pw(a*inv[100-c],n)) %= mod;
	for(i=0;i<n;i++){
		(t += comb(n + i - 1,i)%mod*q%mod*(n + i)) %= mod;
		(q *= y) %= mod;
	}
	(t *= pw(b*inv[100-c],n)) %= mod;
	cout << (s + t)*100%mod*inv[100 - c]%mod << endl;
}

Measured memory_bytes: 4992
"""
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, m = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
size = [1 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if not same(a - 1, b - 1):
        unite(a - 1, b - 1)
x = [0] * n
ans = 0
for i in range(n):
    j = get_root(i)
    x[j] += 1
    ans = max(ans, x[j])
print(ans)
"""

from collections import deque

def bfs(s):
    q = deque()
    q.append(s)
    visit[s] = 1
    cnt = 1
    while q:
        p = q.popleft()
        for j in G[p]:
            if visit[j] == 0:
                q.append(j)
                visit[j] = 1
                cnt += 1
    global ans
    ans = max(ans, cnt)
    return

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
visit = [0] * (n + 1)
ans = 0
for i in range(1, n + 1):
    if visit[i] == 0:
        bfs(i)
print(ans)

Measured memory_bytes: 106852
import math

def digitsum(x, b):
    accum = 0
    while x > 0:
        accum += x % b
        x //= b
    return accum

def solve(n, s, max_ns):
    if n < s: return -1
    # 1 <= n < 2**37
    max_digits = int(math.ceil(math.log2(max_ns)))
    # sentinel.
    min_b = n + 2

    # 1桁
    if n == s:
         min_b = n + 1

    # 2桁
    # 10*11程度調べるのは重すぎる
    # それぞれの数字0<=x,y<=b-1として
    # xb + y = n, x + y = s
    # => x(b-1) = n-s
    # 2 .. (n-s)^(1/2) の範囲で約数qを持てば、b=q+1またはb=(n-s)//q+1が候補
    for q in range(1, int((n - s)**0.5) + 1):
        if (n - s) % q == 0:
            for b in [q + 1, (n - s) // q + 1]:
                if b < min_b:
                    if digitsum(n, b) == s:
                        min_b = b

    # 3桁以上
    # <=> n >= b**(3 - 1)
    # <=> b <= n**(1/2)
    b_low = 2
    b_high = min(min_b, int(n ** 0.5) + 1)
    for b in range(b_low, b_high):
        if digitsum(n, b) == s:
            min_b = b

    if min_b < n + 2:
        return min_b
    return -1

def test():
    import random
    random.seed(0)
    for i in range(100):
        b = random.randint(2, 10**11)
        n = random.randint(1, 10**11)
        s = digitsum(n, b)
        solved_b = solve(n, s, 10**11)
        if s == digitsum(n, solved_b) and solved_b <= b:
            print('OK b={}, n={}, s={}, solved_b={}'.format(b, n, s, solved_b))
        else:
            print('NG!!! b={}, n={}, s={}, solved_b={}'.format(b, n, s, solved_b))

if __name__ == '__main__':
    n = int(input())
    s = int(input())
    print(solve(n, s, 10**11))


Measured memory_bytes: 3064
# import math
import collections

n = int(input())
# nf = math.factorial(n)
sosu = []

for i in range(1, n+1):
    if (2 ** i-1) % i == 1:
        sosu.append(i)

# print(sosu)
yakusu = collections.Counter()

for i in range(1, n+1):
    for j in sosu:
        if i < j:
            break
        elif i % j == 0:
            while i % j == 0 or i < 1:
                yakusu[j] += 1
                i = i / j


# print(yakusu)

ans = 1
for i in yakusu.values():
    ans *= (i+1)
print(ans % (10**9 + 7))


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

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Swap(ref int a, ref int b) {
        var t = a;
        a = b;
        b = t;
    }

    static int Partition(int[] xs) {
        int n = xs.Length;
        int pibot = xs[n-1];

        int less = 0; // pibot ??\????????????????´?????????????
        for (int i = 0; i < n-1; i++) {
            if (xs[i] <= pibot) {
                Swap(ref xs[less], ref xs[i]);
                less++;
            }
        }

        // pibot ??????????????????
        Swap(ref xs[less], ref xs[n-1]);
        return less;
    }

    static void Main() {
        ReadInt();
        var xs = ReadInts();

        int p = Partition(xs);
        var ys = xs.Select((e, i) => i == p ? "[" + e.ToString() + "]" : e.ToString()).ToArray();
        Console.WriteLine(string.Join(" ", ys));
    }
}

Measured memory_bytes: 17328
#include <iostream>
#include <vector>

uint32_t bit_count(uint32_t bits) {
  bits = (bits & 0b0101'0101'0101'0101'0101'0101'0101'0101) +
         (bits >> 1 & 0b0101'0101'0101'0101'0101'0101'0101'0101);
  bits = (bits & 0b0011'0011'0011'0011'0011'0011'0011'0011) +
         (bits >> 2 & 0b0011'0011'0011'0011'0011'0011'0011'0011);
  bits = (bits & 0b0000'1111'0000'1111'0000'1111'0000'1111) +
         (bits >> 4 & 0b0000'1111'0000'1111'0000'1111'0000'1111);
  bits = (bits & 0b0000'0000'1111'1111'0000'0000'1111'1111) +
         (bits >> 8 & 0b0000'0000'1111'1111'0000'0000'1111'1111);
  return (bits & 0b0000'0000'0000'0000'1111'1111'1111'1111) +
         (bits >> 16 & 0b0000'0000'0000'0000'1111'1111'1111'1111);
}

int main() {
  uint32_t N = 0;
  std::cin >> N;

  std::vector<std::vector<std::pair<uint32_t, bool>>> pred(N);
  for (size_t i = 0; i < N; i++) {
    uint32_t A = 0;
    std::cin >> A;
    pred[i] = std::vector<std::pair<uint32_t, bool>>(A);
    for (size_t j = 0; j < A; j++)
      std::cin >> pred[i][j].first >> pred[i][j].second;
  }

  uint32_t mask = (1 << N) - 1;
  uint32_t max = 0;
  while (mask > 0) {
    bool flag = true;
    for (size_t i = 0; i < N; i++) {
      if (!(mask >> i & 1)) continue;
      for (auto &&p : pred[i]) {
        flag = (mask >> (p.first - 1) & 1) == p.second;
        if (!flag) break;
      }
      if (!flag) break;
    }

    if (flag) max = std::max(max, bit_count(mask));
    mask--;
  }
  std::cout << max << std::endl;

  return 0;
}

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

int main() {
    string s;
	int ans;
	vector<string> week = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	cin >> s;
  	
  	for(int i = 0; i < 7; i++){
      
      if(s == week[i]){
      	ans = 7 - i;
      }
    }
    cout << ans << endl;
  	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

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


	// 最初を負にする
	ll sum = a[0];
	ll ans = 0;
	if(sum >= 0){
		ans = (sum - (-1));
		sum = -1;
	}
	For(i,1,n){
		sum += a[i];
		// 符号が変わるなら何もしない
		if(sum * (sum-a[i]) < 0); // ok
		else {
			// sumが正なら負に、sumが負なら正にする
			// sum が 0 のとき注意が必要
			if(sum == 0){
				if(sum-a[i] < 0){
					sum = 1;
					ans ++;
				} else {
					ans ++;
					sum = -1;
				}
			}
			else if(sum > 0){
				ans += (sum - (-1));
				sum = -1;
			} else {
				ans += (1 - sum);
				sum = 1;
			}
		}
	}
	ll tmp = ans;
	sum = a[0];
	ans = 0;
	if(sum <= 0){
		ans = (1 - sum);
		sum = 1;
	}
	For(i,1,n){
		sum += a[i];
		// 符号が変わるなら何もしない
		if(sum * (sum-a[i]) < 0); // ok
		else {
			// sumが正なら負に、sumが負なら正にする
			// sum が 0 のとき注意が必要
			if(sum == 0){
				if(sum-a[i] < 0){
					sum = 1;
					ans ++;
				} else {
					ans ++;
					sum = -1;
				}
			}
			else if(sum > 0){
				ans += (sum - (-1));
				sum = -1;
			} else {
				ans += (1 - sum);
				sum = 1;
			}
		}
	}
	ans = min(tmp,ans);
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);lin(A);lin(B);
  ll a=min(A,B);ll b=max(A,B);
  
  ll d=b-a;
  
  if(d%2==0){
    cout<<d/2;
  }
  
  else{
    ll res=1000000000000000;
    res=min(a-1+(d+1)/2,N-b+(d+1)/2);
    cout<<res;
  }
  
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	string S;
	cin>>S;
	if(S[0]=='7'||S[1]=='7'||S[2]=='7')
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int a,b;
  cin >> a >> b;
  
  int result = a * b;
  
  if (result % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
    int st,ed;
    st=max(a,c);
    ed=min(b,d);
    printf("%d",max(0,ed-st));
	return 0;
}

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

ll solve(ll x1, ll y1, ll x2, ll y2) {
	ll d=1;
	rep(i, 30) d*=3; // pow(3, 30)
	if( y1>y2 ) swap(x1, x2), swap(y1, y2);
	ll ans=abs(x1-x2)+abs(y1-y2);
	while(d>1) {
		d/=3;
		ll nx1=x1/d, nx2=x2/d;
		ll ny1=y1/d, ny2=y2/d;
		if( nx1!=nx2 ) break;
		if( nx1%3==1 && abs(ny1-ny2)>1 ) {
			ll top=nx1*d-1;
			ll bot=nx1*d+d;
			ll loss=min(x1,x2)-top;
			loss=min(loss, bot-max(x1,x2));
			ans+=loss*2;
			break;
		}
	}
	return ans;
}

int main () {
	int Q;
	cin >> Q;
	while(Q--) {
		ll x1,y1,x2,y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1--; y1--; x2--; y2--;
		ll ans1 = solve(x1, y1, x2, y2);
		ll ans2 = solve(y1, x1, y2, x2);
		cout << max(ans1, ans2) << '\n';
	}
	return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int len = s.length();
    if (s[len-1]=='s'){
        s = s + "es";
    }
    else{
        s = s + 's';
    }
    cout<<s<<endl;



    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#define N 200000

int main(){
	int i, n, maxv, minv, r[N];
	
	scanf("%d", &n);
	
	for( i = 0; i < n; i++ ){
	scanf("%d", &r[i]);
    }
    
    maxv = r[1] - r[0];
    minv = r[0];
    
    for( i = 1; i < n; i++ ){
    if(maxv < r[i] - minv)
        maxv = r[i] - minv;
	if(minv > r[i])
	    minv = r[i];
    }
    
    printf("%d\n", maxv);
	    
	return 0;
}

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

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = a - b;
    if (k & 1) ans *= -1;
    if (abs(ans) > 1e18) {
        puts("Unfair");
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        for(int i = 0; i < n; i++){
        	BigInteger n1 = new BigInteger(br.readLine());
        	BigInteger n2 = new BigInteger(br.readLine());

        	String result = n1.add(n2).toString();
        	
        	if(result.length() <= 80){
        		System.out.println(result.toString());
        	}
        	else {
        		System.out.println("overflow");
        	}
        }

    }

}

Measured memory_bytes: 24344
n,k,q = map(int,input().split())
point = [k-q for i in range(n)]
for i in range(q):
    ans = int(input())
    point[ans - 1] = point[ans - 1] + 1
for i in range(n):
    if point[i] < 1:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 7908
#include<stdio.h>
int main()
{
	int a[3][3],n,b[10],i,j,k,flg[3][3]={0},flg2=0;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			scanf("%d",&a[i][j]);
		}
	}
	scanf("%d",&n);
	for(k=0;k<n;k++){
		scanf("%d",&b[k]);
	}
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			for(k=0;k<n;k++){
				if(a[i][j]==b[k]) flg[i][j]=1;
			}
		}
	}
	for(i=0;i<3;i++){
		if(flg[i][0]==flg[i][1]&&flg[i][0]==flg[i][2]&&flg[i][0]==1) flg2=1;
		if(flg[0][i]==flg[1][i]&&flg[0][i]==flg[2][i]&&flg[0][i]==1) flg2=1;
	}
	if(flg[0][0]==flg[1][1]&&flg[0][0]==flg[2][2]&&flg[0][0]==1) flg2=1;
	if(flg[0][2]==flg[1][1]&&flg[0][2]==flg[2][0]&&flg[0][2]==1) flg2=1;
	if(flg2==1) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1636
s=int(input())

list=[]
i=0
list.append(s)

while True:
    if list[i]%2==0:
        list.append(list[i]//2)
    else:
        list.append(3*list[i]+1)
    if list.count(list[i])==2:
        print(i+1)
        break
    i+=1

Measured memory_bytes: 2940
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

intt arr[55];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt n, k;
    cin >> n >> k;
    for (intt i = 1; i <= n; i++)
        cin >> arr[i];
    sort (arr + 1, arr + n + 1);
    intt res = 0;
    for (intt i = n; i >= n - k + 1; i--)
        res += arr[i];
    cout << res << endl;
    return 0;
}


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

int main(void)
{
    double x1, x2, y1, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

    double a = pow(x2 - x1, 2);
    double b = pow(y2 - y1, 2);
    double sum = sqrt(a + b);

    printf("%f\n", sum);

    return 0;
}


Measured memory_bytes: 2128
y = [int(input()) for i in range(int(input()))]
y = sorted(set(y))
c = 1
max_c = 1
for i,j in enumerate(y):
    try:
        if j < y[i+1]:
            c += 1
            if max_c < c:
                max_c = c
        else:
            c = 1
    except:
        pass
print(max_c)

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

int a[200010]={0};

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int s;
        scanf("%d",&s);
        a[s]++;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",a[i]);
    return 0;
}


Measured memory_bytes: 4496
package main
 
import "fmt"
 
func main() {
  var n int
  fmt.Scan(&n)
  i := 0
  for true {
    i+= 1
    if 1000 * i >= n {
      ans := 1000 * i - n
      fmt.Println(ans)
      break
    }
  }
}

Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
int s[100000],t[100000],ch[100000],wa[200002],sum[200002];
int main(void){
	int n,c,i,j,max;
	cin>>n>>c;
	for(i=0;i<n;i++) cin>>s[i]>>t[i]>>ch[i];
	for(i=0;i<=200002;i++) sum[i]=0;
	for(i=1;i<=c;i++){
		for(j=0;j<=200002;j++) wa[j]=0;
		for(j=0;j<n;j++){
			if(ch[j]==i){
				wa[s[j]*2-1]++; wa[t[j]*2]--;
			}
		}
		for(j=1;j<=200002;j++) wa[j]+=wa[j-1];
		for(j=0;j<=200002;j++){
			if(wa[j]>0) sum[j]++;
		}
	}
	max=0;
	for(i=0;i<=200002;i++){
		if(max<sum[i]) max=sum[i];
	}
	cout<<max<<endl;
	return 0;
}

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



 set<int> st;

int main()
{
    int a,b,c,d,e,f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    double mx=0.0;
    int p=100*a,q=0;

    for(int i=0;i*a*100<=f;i++){
        for(int j=0;j*b*100<=f;j++){
            st.insert(i*a*100+j*b*100);
        }
    }

    for(int i=0;i*c<=f;i++){
        for(int j=0;j*d<=f;j++){
            set<int>::iterator pos;
            if((i*c+j*d)*100%e==0)
                pos=lower_bound(st.begin(),st.end(),(i*c+j*d)*100/e);
            else
                pos=upper_bound(st.begin(),st.end(),(i*c+j*d)*100/e);
            if(pos!=st.end()&&(*pos)+i*c+j*d<=f){
                if(((double)i*c+j*d)/((double)(i*c+j*d)+(double)(*pos))>mx){
                    mx=((double)i*c+j*d)/((double)(i*c+j*d)+(double)(*pos));
                    p=(*pos)+i*c+j*d,q=i*c+j*d;
                }
            }
        }
    }
     printf("%d %d\n",p,q);
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
	int A,B,C;
	cin>>A>>B>>C;
	string ans="No";
	if(A+B>=C)ans="Yes";
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000;
 
int main()
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(abs(a-x)>abs(b-x)) 
		printf("B\n");
	else
		printf("A\n");
	return 0;	
} 

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

using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

int main()
{

    int n;

    cin>>n;

    string str;

     cin>>str;


     int W[n],E[n];


      for(int i=0;i<n;i++){

           if(i)
            W[i]=W[i-1]+ (str[i]=='W'),E[i]=E[i-1]+(str[i]=='E');
           else{
              W[i]=(str[i]=='W'),E[i]=(str[i]=='E');
           }

      }

  int ans=11111111;
       for(int i=0;i<n;i++){


                 if(!i)
                  ans=min(ans,E[n-1]-E[i]);
                 else
                  ans=min(ans,W[i-1]+E[n-1]-E[i]);

       }
      cout<<ans;


    return 0;
}


Measured memory_bytes: 3076
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=sorted(A)
cnt=0
m=0
for i in range(N):
  if B[i][1]>=M-cnt:
    m+=(M-cnt)*B[i][0]
    print(m)
    exit()
  else:
    cnt+=B[i][1]
    m+=B[i][0]*B[i][1]

Measured memory_bytes: 28648
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
//#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
//#include <array>
#include <valarray>
#include <stdio.h>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")
#include <algorithm>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

long long  int nCm(long long int n, long long int m) {
	if (m == 1) {
		return n;
	}
	else {
		return n*nCm(n - 1, m - 1) / m;
	}
}

long long int npm(long long int n,long long int m) {
	if (m == 1) {
		return n;
	}
	else 
		if (m == 0) {
			return 1;
		}else {
		return n*npm(n, m - 1);
	}
}

 int main() {
	 string s;
	 int K;
	 cin >> s;
	 cin >> K;
	 vector<int> str(s.size());
	 for (int i = 0; i < s.size(); ++i) {
		 str[i] = (int)s[i]-97;
	 }
	 for (int i = 0; i < s.size() - 1; ++i) {
		 if (str[i] != 0) {
			 if (26 - str[i] <= K) {  K -=( 26 - str[i]); str[i] = 0;}
		 }
	 }
	 str[s.size() - 1] = (str[s.size() - 1] + K) % 26;
	 
	 for (int i = 0; i < s.size(); ++i) {
		 s[i] = (char)str[i]+97;
	 }
	 cout << s << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
using ll = long long;
/*
    g++ -std=c++11 test.cpp -o test.out && ./test.out
*/
void solve(){
    ll n; cin >> n;
    string result = "";
    
    while(n >= 1){
        int cur_index = --n % 26;
        char cur_letter = 'a' + cur_index;
        result += cur_letter;
        n/=26;
    }

    reverse(result.begin(), result.end());
    cout << result;
}   
 
int main()
{    
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    solve();
    
    return 0;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, M = MI()
    H = LI()
    E = [[] for _ in range(N)]
    for i in range(M):
        a, b = MI1()
        E[a].append(b)
        E[b].append(a)

    used = [-1] * N
    for v in range(N):
        if used[v] == 0: continue
        h = H[v]
        for nv in E[v]:
            nh = H[nv]
            if h > nh:
                used[nv] = 0
            elif h < nh:
                used[v] = 0
                break
            else:
                used[v] = 0
                used[nv] = 0
                break
        else:
            used[v] = 1
    print(sum(used))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 30148
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    ans=0
    for i in range(n):
        x,u=input().split()
        x=float(x)
        if u=='JPY':
            ans+=x
        else:
            ans+=x*380000
    print(ans)
resolve()

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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a).size()
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define endl "\n"

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
//K-th smallest
//cout << k << "rd smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;


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

ll mod=1000000007;

ll power(ll x, ll y) 
{
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return (temp*temp)%mod;
	else
		return (((x*temp)%mod)*temp)%mod; 
}

vector<ll> a(100005),b(100005),c(100005);
ll dp[100005][3];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll i;
	for(i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	for(i=2;i<=n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
	return 0;
}

Measured memory_bytes: 4992
int dif(int a, int b){return a<b?b-a:a-b;}
int gcd(int a, int b){
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int n, X, x, ans, i;
int main(){
  scanf("%d%d", &n, &X);
  scanf("%d", &x);
  ans = dif(x,X);
  for(i=1; i<n; i++){
    scanf("%d", &x);
    ans = gcd(ans, dif(x,X));
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 128
// #define DEBUG

#include <bits/stdc++.h>
#define x first
#define y second
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define out(t, a) copy(all(a), ostream_iterator<t>(cout, " ")); cout << "\n";
#define int long long

using namespace std;

void set_program() {
	#ifdef DEBUG
		freopen ("test.in", "r", stdin);
		freopen ("test.out", "w", stdout);
		// freopen ("test.in", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pt;

const int ALF = 26;
const int LOGN = 20;
const int MOD = 998244353;
const int INF = 1e9;
const int MAXN = 1e5;

void solve() {
	int k, n;
	cin >> k >> n;
	vector <int> a(n);
	for (int& i : a) {
		cin >> i;
	}
	int res = 0;
	for (int i = 1; i < n; ++i) {
		res += a[i] - a[i - 1];
	}
	int ans = res;
	for (int i = 0; i < n - 1; ++i) {
		res += (a[i] - a[(i - 1 + n) % n] + k) % k;
		res -= a[i + 1] - a[i];
		ans = min(ans, res);
	}
	cout << ans << "\n";
}

signed main() {
	set_program();
	int t;
	#ifdef DEBUG
		// cin >> t;
		t = 2;
	#else
		// cin >> t;
		t = 1;
	#endif
	for (int num_test = 1; num_test <= t; ++num_test) {
		solve();
		cout << "\n";
	}
 	return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


std::bitset<122222> dp[88][88];


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int H, W, A[88][88], B[88][88];

  std::cin >> H >> W;
  
  for (int i = 0; i < H; i ++)
    for (int j = 0; j < W; j ++)
      std::cin >> A[i][j];

  for (int i = 0; i < H; i ++)
    for (int j = 0; j < W; j ++)
      std::cin >> B[i][j];

  for (int i = 0; i < H; i ++)
    for (int j = 0; j < W; j ++) {
      int d = std::abs(A[i][j] - B[i][j]);
      
      if (i == 0 && j == 0) {
        dp[i][j].set(d);
      }
      else {
        if (i)
          for (int k = 0; k < 122222; k ++)
            if (dp[i - 1][j][k]) {
              dp[i][j].set(std::abs(k - d));
              dp[i][j].set(std::abs(k + d));
            }

        if (j)
          for (int k = 0; k < 122222; k ++)
            if (dp[i][j - 1][k]) {
              dp[i][j].set(std::abs(k - d));
              dp[i][j].set(std::abs(k + d));
            }
      }
    }

  for (int i = 0; i < 122222; i ++)
    if (dp[H - 1][W - 1][i]) {
      std::cout << i << std::endl;

      break;
    }
  
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL k;cin >> k;
    vector<LL> a(k);
    inc(i, 0, k) cin >> a[i];
    if(a[k-1] != 2){
        cout << -1 << endl;
        return 0;
    }
    LL mmin = 2;
    LL mmax = 2;
    reverse(a.begin(), a.end());
    inc(i, 0, k){
        if(a[i] > mmax){
            cout << -1 << endl;
            return 0;
        }
        LL b = (mmin+a[i]-1)/a[i]*a[i];
        if(b > mmax){
            cout << -1 << endl;
            return 0;
        }

        // mmax
        LL ok = mmin;
        LL ng = mmax+max(a[i], mmax)*2;
        while(ng-ok>1){
            //cout << ok << " " << ng << endl;
            LL m = (ok+ng)/2;
            if(m/a[i]*a[i] <= mmax && m/a[i]*a[i] >= mmin){
                ok = m;
            }else{
                ng = m;
            }
        }
        mmax = ok;

        // mmin
        if(mmin < a[i]){
            mmin = a[i];
        }else if(mmin > a[i]){
            mmin = (mmin+a[i]-1)/a[i]*a[i];
        }

        if(mmin > mmax){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << mmin << " " << mmax << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
bool done[N];

int n, m, x;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
        a--;
    else if (u == t)
        b--;
    cout << a << ' ' << b;
    return 0;
}


Measured memory_bytes: 256