akhauriyash/Code-Regression huggingface dataset:
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n;
const int M = 1e5 ;
int a[M]; 
int dp[M];
int main ()
{
    scanf ("%d" , &n );
    for (int i =0 ; i < n ;i++)
        scanf ("%d" ,a+i); 
    dp[1] = abs(a[0] - a[1]); 
    for (int i = 2; i < n ;i++)
    {
        dp[i] = min ( abs(a[i] - a[i-1]) + dp[i-1] , abs(a[i] - a[i-2]) + dp[i-2] ); 
    }
    cout << dp[n-1] <<"\n";
}

Measured memory_bytes: 1024
use std::io::*;

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let lines = input.split('\n');

  let avg = lines.take(5)
    .map(|l| {
      let score = l.parse().unwrap();
      if score < 40 { 40 } else { score }
    })
    .sum::<u32>() / 5;

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



Measured memory_bytes: 5020
#include <iostream>
using namespace std;
int n,ans;
string s;
int main(void){
    cin>>s;
    n=s.size();
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='1')ans++;
        }
        else{
            if(s[i]=='0')ans++;
        }
    }
    cout<<min(ans,n-ans)<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int H, W, i, j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(i == 0 || i == H - 1 || j == 0 || j == W - 1){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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


int main()
{
	int n,l,ans=0,tmp=10000,t;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;++i) ans+=l+i-1;
	for(int i=1;i<=n;++i) if(tmp>abs(l+i-1)) tmp=abs(l+i-1),t=l+i-1;
	printf("%d",ans-t);
}

Measured memory_bytes: 256
N,K= map(int,input().split())
A = [0] + list(map(int,input().split()))


visited = [-1] * (N+1)

visited[1] = 0

i = 1
k = 0
while True:
    nv = A[i]
    k += 1
    if K == k:
        print(nv)
        exit()
    if not visited[nv] == -1:
        break
    visited[nv] = k
    i = nv

loop = k - visited[nv]
res = (K-visited[nv]) % loop

for i in range(res):
    nv = A[nv]

print(nv)




Measured memory_bytes: 32412
#include<iostream>
using namespace std;
long long a,b,c=1,d=0,e[100001];
inline void dfs(long long x,long long s){
	if(x==a){
		if(s%2==0){
			d++;
		}
		return ;
	}
	for(long long i=e[x]-1;i<=e[x]+1;i++){
		dfs(x+1,s*i);		
	}
	return ;
}
int main(){
	cin>>a;
	for(long long i=0;i<a;i++){
		cin>>e[i];
	}
	dfs(0,1);
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;
int dp[1000][1000];

int ninklisi(int x,int y)
{
	//printf("!");
	if(y==0 || x==y)
	{
		return 1;
	}
	else if(dp[x][y] != -1)
	{
		return dp[x][y];
	}
	dp[x][y]=ninklisi(x-1,y-1)+ninklisi(x-1,y);
	return dp[x][y];
}

int main()
{
	int n,m,cevap=0;
	scanf("%d%d",&n,&m);

	for(int i=0;i<1000;i++)
	{
		for(int j=0;j<1000;j++)
		{
			dp[i][j]=-1;
		}
	}
	if(n>=2)
	{
		cevap+=ninklisi(n,2);
	}
	if(m>=2)
	{
		cevap+=ninklisi(m,2);
	}
	printf("%d\n",cevap);
}

Measured memory_bytes: 4096
let x, y, z, k = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let a_s = Array.init x @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let bs = Array.init y @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let cs = Array.init z @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ab_s = Array.make (x * y) 0
let ans = Array.make (k * z) 0
let _ =
  for i = 0 to x - 1 do
    for j = 0 to y - 1 do
      ab_s.(i * y + j) <- a_s.(i) + bs.(j) done done;
  Array.sort (fun x y -> y - x) ab_s;
  for i = 0 to min (x * y - 1) @@ k - 1 do
    for j = 0 to z - 1 do
      ans.(i * z + j) <- ab_s.(i) + cs.(j) done done;
  Array.sort (fun x y -> y - x) ans;
  for i = 0 to k - 1 do Printf.printf "%d\n" ans.(i) done

Measured memory_bytes: 37372
/**
 * @author Video Vocabulary
 * @date 2020-07-05 18:00:53
 */
#include <bits/stdc++.h>

using namespace std;

void solve() {
    
}

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

    int n;
    cin >> n;
    int m = n%1000;
    cout << (m==0?0:1000-m) << endl;
}


Measured memory_bytes: 3644
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[int(input())-1])


Measured memory_bytes: 3060
using System;
    using System.Collections.Generic;
    using System.Linq;
    using static Atcoder;
    using System.Threading.Tasks;
    using System.ComponentModel;
     
    public class Hello
    {
     
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine().Replace(" ",""));
         Console.WriteLine((Math.Sqrt(n)-Math.Floor(Math.Sqrt(n)) == 0?"Yes":"No"));   
        }
    }
     
    public class Atcoder
    {
    static void Swap<T>(ref T a, ref T b)
    {
    var t = a;
    a = b;
    b = t;
    }
    public static int LCM(int a, int b)
    {
    int c = a * b;
    if (a < b) Swap(ref a, ref b);
    int d = a % b;
    while (d != 0)
    {
    a = b;
    b = d;
    d = a % b;
    }
    return c / b;
    }
    public static string strReverse(string s)
    {
    return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
    return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
    if (n < 2) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
     
    //double sqrtNum = Math.Sqrt(n);
    for (int i = 3; i < n; i += 2)
    {
    if (n % i == 0) return false;
    }
    return true;
    }
    public static string[] SpRead(char c)
    {
    return Console.ReadLine().Split(c);
    }
    }

Measured memory_bytes: 13140
n = int(input())
B = []
total = []
count = 0

for i in range(n):
	a,b = map(int, input().split())
	B.append(b)
	total.append(a+b)

total_new = sorted(total, reverse=True)

for i in range(0, n, 2):
	count += total_new[i]

count -= sum(B)

print(count)


Measured memory_bytes: 12224
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int s[500005];
int n;

int sol(const vector<int> &v){
  int m = v.size();
  if(m==1) return 0;
  if(m==2) return max(v[0], v[1]);

  vector<vector<int>> dp(m+1,vector<int>(4,0));
  // 未使用，k-1個残す，1個残す，全部使用
  rep(i,m-1){
    { // v[i]ぜんぶのこる
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = dp[i][0] + v[i];
      if(v[i+1] > 1) dp[i+1][2] = dp[i][0] + v[i+1]-1;
      dp[i+1][3] = dp[i][0] + v[i+1];
    }
    { // v[i]-1個
      dp[i+1][0] = max(dp[i+1][0], dp[i][1]);
      if(v[i]>1){
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] + v[i]-1);
        dp[i+1][2] = max(dp[i+1][2], dp[i][1] + v[i+1]-1);
        dp[i+1][3] = max(dp[i+1][3], dp[i][1] + v[i+1]);
      }
    }
    { // v[i] 1個
      dp[i+1][0] = max(dp[i+1][0], dp[i][2]);
      if(v[i]>1){
        dp[i+1][1] = max(dp[i+1][1], dp[i][2] + 1);
        dp[i+1][2] = max(dp[i+1][2], dp[i][2] + v[i+1]-1);
        dp[i+1][3] = max(dp[i+1][3], dp[i][2] + v[i+1]);
      }
    }
    { // v[i] 0
      dp[i+1][0] = max(dp[i+1][0], dp[i][3]);
    }
  }

  return *max_element(all(dp[m-1]));
}

int solve(int l, int r){
  if(l+1==r) return 0;

  vector<int> v;
  int i=l;
  while(i<r){
    int d=0;
    while(i+d<r && s[i+d]==1) d++;
    v.pb(d);
    i += d+1;
  }

  // dbg(l,r,vector<int>(&s[l], &s[r]));
  // dbg(v);
  // dbg(sol(v));

  return sol(v);
}

int main(){
  cin>>n;
  string str;
  cin>>str;
  str += "00";
  rep(i,n) s[i] = str[i]-'0';

  int ans = 0;
  {
    int i = 0;
    while(i<n && s[i]==0) i++;
    int pre = i;
    while(i<n){
      while( !(s[i]==0 && s[i+1]==0)) i++;
      ans += solve(pre, i);
      while(i<n && s[i]==0) i++;
      pre = i;
    }

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2820
#include<bits/stdc++.h>
 
#define mp          make_pair
#define pb          push_back
#define lb          lower_bound
#define ub          upper_bound
#define ff          first
#define ss          second
#define ii          pair<int,int>
#define mod         int(1e9+7)
#define inf         1e18
 
typedef long long int ll;
typedef long double ld;
 
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
const int N=3e5;

int dp[102][100005];
int A[100];

void solve()
{
	int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>A[i];

    for(int i=0;i<=A[0];i++)
        dp[0][i]=1;

    for(int i=1;i<n;i++)
    {
        vector<int> prefix_sum(k+1);
        prefix_sum[0]=dp[i-1][0];
        for(int j=1;j<k+1;j++){
            prefix_sum[j]=(prefix_sum[j-1]+dp[i-1][j])%mod;
        }
        for(int j=0;j<k+1;j++)
        {
            if(j>A[i])
            {
                dp[i][j]=(prefix_sum[j]+mod-prefix_sum[j-A[i]-1])%mod;
            }
              else
                dp[i][j]=prefix_sum[j];
            
        }
    }
    cout<<dp[n-1][k]<<endl;
    return ;
}
 
int main()
{
    fio
 
    int t=1;
//    cin>>t;
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 43052
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main(){
  long long X;
  scanf("%lld", &X);
  for (long long a=-1000; a<1000; a++){
    for (long long b=-1000; b<1000; b++){
      if ((long long)pow(a, 5)-(long long)pow(b, 5)==X){
        printf("%lld %lld\n", a, b);
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
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 setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#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--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int32_t main()
{
	c_p_c();
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;

	vi A(a), B(b), C(c);

	for (int i = 0; i < a; ++i)
		cin >> A[i];

	for (int i = 0; i < b; ++i)
		cin >> B[i];

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

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());

	for (int i = 0; i < x; ++i)
		C.pb(A[i]);

	for (int i = 0; i < y; ++i)
		C.pb(B[i]);

	sort(C.rbegin(), C.rend());

	int ans = 0;

	for (int i = 0; i < x + y; ++i)
		ans += C[i];

	cout << ans << '\n';
	return 0;
}

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N, ans = 0;
vll L;

void solve(){
    rep(i,N){
        if(i%2!=0)
            ans += L[i];
    }

    cout << ans << endl;
}

int main(){
    cin >> N;
    N *= 2;
    L.resize(N,0);
    rep(i,N) cin >> L[i];

    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());

    solve();
}


Measured memory_bytes: 256
import copy

def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x[1]:
            i += 1
            A[i], A[j] = A[j], A[i]
            
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)
        
n = int(input())
S = []
for _ in range(n):
    a, b = map(str, input().split())
    S.append([a, int(b)])
copyS = copy.deepcopy(S)

quicksort(S, 0, n-1)

for i in range(n-1):
    if S[i][1] == S[i+1][1]:
        if copyS.index(S[i]) > copyS.index(S[i+1]):
            print("Not stable")
            break         
else:
    print("Stable")
    
for j in S:
    print(" ".join(str(a) for a in j))


Measured memory_bytes: 39444
#include <iostream>
#include <string>
#include <sstream>

void split(int* arr, const std::string& str) {
    std::stringstream stream;
    stream << str;
    std::string buf;
    for (int i = 0; std::getline(stream, buf, ' '); ++i) {
        arr[i] = std::stoi(buf);
    }
}

void get_array(int* arr, std::istream& stream) {
    std::string buf;
    std::getline(stream, buf);
    split(arr, buf);
    return;
}

bool binary_search(int const* s, const int v, const int l, const int r) {
    const int m = (l + r) >> 1;
    if (l == m) {
        return v == s[m];
    }

    enum class Pos {
        Left,
        Right
    };
    const Pos p = v < s[m] ? Pos::Left : Pos::Right;
    return binary_search(
        s,
        v,
        p == Pos::Left ? l : m,
        p == Pos::Right ? r : m);
}

bool binary_search(int const* s, const int n, const int v) {
    return binary_search(s, v, 0, n);
}

int count(int const* s, const int n, int const* t, const int q) {
    int count = 0;
    for (int i = 0; i < q; i++) {
        if (binary_search(s, n, t[i])) {
            ++count;
        }
    }
    return count;
}

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

    int n;
    std::cin >> n;
    std::cin.ignore();

    int s[100000];
    get_array(s, std::cin);

    int q;
    std::cin >> q;
    std::cin.ignore();

    int t[50000];
    get_array(t, std::cin);

    std::cout << count(s, n, t, q) << std::endl;

    return 0;
}

Measured memory_bytes: 5100
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<functional>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
using p = pair<ll,ll>;
const ll INF = (ll)1e9;
void a(){
    int n,m;
    cin >> n >> m;
    cout << (n==m?"Yes":"No");
}

void b(){
    int a,b;
    cin >> a >> b;
    int _min = min(a,b);
    int _max = max(a,b);
    for(int i=0;i<_max;i++){
        cout << _min;   
    }
}
int main(){
    b();
    return 0;
}

Measured memory_bytes: 256
N, Y = gets.split.map &:to_i
n = Y / 1000 - N
_5k = 0
while n >= 0
  if n % 9 == 0
    _10k = n / 9
    _1k = N - _5k - _10k
    break if [_10k, _5k, _1k].any?{|x|x<0}
    puts [_10k, _5k, _1k]*" "
    exit
  end
  n -= 4
  _5k += 1
end
puts"-1 -1 -1"


Measured memory_bytes: 3836
lt = ["dream", "dreamer", "erase", "eraser"]
s = input()

lt = [w[::-1] for w in lt]
s = s[::-1]
cond = True
i = 0
while i < len(s):
    for t in lt:
        if s[i:].startswith(t):
            i += len(t)
            break
    else:
        cond = False
        break

print("YES" if cond else "NO")


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int D;
cin >> D;
vi c(26);
rep(i,26) cin >> c[i];
vvi s(D,vi(26));
rep(d,D) rep(i,26) cin >> s[d][i];

int cur = 0;
vi last(26,-1);
rep(d,D) {
    int res = -INF;
    int p = 0;
    rep(i,26) {
        int up = s[d][i];
        int old = last[i];
        last[i] = d;
        int down = 0;
        rep(j,26) {
            down += c[j] * (d-last[j]);
        }
        last[i] = old;
        if(chmax(res,up-down)) p = i;
    }
    last[p] = d;
    cout << p+1 << endl;
}

return 0;
}

Measured memory_bytes: 3732
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll i,N,T,A;
  cin>>N;
  if(N==1){
    puts("Hello World");
  }else{
    cin>>N>>T;
    cout<<N+T<<endl;
  }
  return 0;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define point pair<int,int>

int N;
point pos[60];

int unit(point d)
{
    int ret = N;
    rep(i, N)
    {
        rep(j, N)
        {
            point p1 = pos[i];
            point p2 = pos[j];
            if(p1.first + d.first == p2.first && p1.second + d.second == p2.second)ret--;
        }
    }
    return ret;
}

signed main()
{
    cin >> N;
    rep(i, N)
    {
        int x, y;
        cin >> x >> y;
        pos[i] = {x, y};
    }

    if(N == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    int ans = 100;
    rep(i, N)
    {
        rep(j, N)
        {
            if(i == j)continue;
            point d = {pos[i].first - pos[j].first, pos[i].second - pos[j].second};
            ans = min(ans, unit(d));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:https://onlinejudge.u-aizu.ac.jp/services/room.html#RitsCamp18Day3/problems/B>
問題文============================================================
 N 個の 1 次式 y=aix (1≤i≤N) が与えられます。
 
 1,2,…,N の部分列 s1,s2,…,sk (i<j ならば si<sj) を考えます。
 まず式 s1 を x=1 として評価することから始め、
 式 si を評価した結果を式 si+1 に x として入力することを考えます。すなわち以下のようになります。
 
 x0=1
 xi=a_si*x_i−1 (1≤i≤k)
 
 このとき、xk が最大となるような部分列を求めてください。
 ただし、そのような部分列が複数考えられる場合は列の長さが最小のものを求めるとします。
 また、さらにそのような部分列が複数考えられる場合は辞書順最小のものを求めるとします。
 ただし、部分列 s1,s2,…,sm が t1,t2,…,tn より辞書順で小さいとは以下のいずれかの場合を指します。
 
 ある i が存在して s1=t1,s2=t2,…,si=ti かつ si+1<ti+1
 m<n で、s1=t1,s2=t2,…,sm=tm
 
=================================================================

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

================================================================
*/

void solve(){
    int N; cin >> N;
    vector<int> a(N); for(auto& in:a) cin >> in;
    
    // get 2
    vector<int> idx2;
    // get -2
    vector<int> idxn2;
    // exist -1
    bool n1 = false;
    int idxn1 = -1;
    
    for(int i = 0; i < N;i++){
        if(a[i] == 2) idx2.push_back(i);
        if(a[i] == -2) idxn2.push_back(i);
        if(!n1 && a[i] == -1) { n1 = true; idxn1 = i; }
    }
    
    vector<int> ans;
    for(auto v:idx2) ans.push_back(v);
    for(auto v:idxn2) ans.push_back(v);
    
    if(idxn2.size()%2==0){
        sort(ans.begin(),ans.end());
    }else{
        if(n1) ans.push_back(idxn1);
        else ans.pop_back();
        sort(ans.begin(),ans.end());
    }
    cout << ans.size() << endl;
    for(auto v:ans) cout << v+1 << endl;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=505;
int n,m;
char s[maxn][maxn],a1[maxn][maxn],a2[maxn][maxn];
int main(){
	n=gi(),m=gi();
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(i,1,n)rep(j,1,m)a1[i][j]=a2[i][j]=s[i][j];
	rep(i,1,m)a1[1][i]=a2[n][i]='#';
	rep(i,1,n)a1[i][1]=a2[i][m]='#';a1[1][m]='.';a2[n][1]='.';
	rep(i,2,n-1)rep(j,2,m-1)if(i&1)a1[i][j]='#';else a2[i][j]='#';
	rep(i,1,n){rep(j,1,m)putchar(a1[i][j]);putchar('\n');}
	putchar('\n');
	rep(i,1,n){rep(j,1,m)putchar(a2[i][j]);putchar('\n');}
	return 0;
}
/*
#############
#############
##.###..##..#
####.#...#..#
######.###..#
#############
#############

.............
.###.###.###.
.###.###.###.
.###########.
.#.#.###.###.
.#.#.###.###.
.............

.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............

#####
##.#.
#.#..
##.#.
#...#

....#
#####
....#
#####
.####
*/

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define cs(ans); cout<<setprecision(6)<<fixed<<ans<<endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};	
void solve(){
	ll k,a,b;
	cin>>k>>a>>b;
	if(a%k==0 || b%k==0) cout<<"OK"<<endl;
	else{
		if(a/k==b/k) cout<<"NG"<<endl;
		else cout<<"OK"<<endl;
	}
	
	
	
		
	
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
double find(int A[],int n,int i,int j){
    double sum=0;
    int cnt=0;
    for(int k=n-1;k>=0;k--){
        if(k==i||k==j) continue;
        sum+=A[k];
        cnt++;
        if(cnt>=2) break;
    }
    return sum;
}
int main(){
    int n,A[1010];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    sort(A,A+n);
    double ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            double a=A[j]-A[i];
            double b=find(A,n,i,j);
            ans=max(ans,b/a);
        }
    }
    printf("%.20lf\n",ans);
    return 0;
}

Measured memory_bytes: 3244
a,b,c = map(int, input().split())
cnt = 0
memo = set()
while a%2 == 0 and b%2 == 0 and c % 2 == 0:
    a, b, c = (b+c)//2, (a+c)//2, (b+c)//2
    if (a, b, c) in memo:
        print(-1)
        exit()
    else:
        memo.add((a,b,c))
    cnt += 1
print(cnt)


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

#define irep(i,n)  for(int i=0;i<(n);i++)
#define irepy(i,n) for(int i=1;i<=(n);i++)
#define jrep(j,n)  for(int j=0;i<(n);j++)
#define jrepy(j,n) for(int j=1;i<=(n);j++)

int main(){
  int a,b;
  cin >> a >> b;
  int sum = a+b;
  int sub = a-b;
  int mul = a*b;
 
  cout<< max(sum,max(sub,mul)) << endl ;

  return 0;

}


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

int main() {
	int a, b, ans;
	char op;
	while (1) {
	cin >> a >> op >> b;
		switch (op) {
		case '+':
			ans = a + b; break;
		case '-':
			ans = a - b; break;
		case '*':
			ans = a * b; break;
		case '/':
			ans = a / b; break;
		case '?':
			return 0;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
 
int main(){
int a,b,c;
  
  cin>>a>>b>>c;
  int sum = a+b+c;
  
  if(sum>=22)
    cout<<"bust"<<'\n';
  
  else
    cout<<"win"<<'\n';
  
  
  return 0;
}

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

int main(){
  int n,m;cin>>n>>m;
  vector<vector<int>> data(n);
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;a--;b--;
    data[a].push_back(b);
    data[b].push_back(a);
  }
  
  queue<int> q;
  vector<int> ans(n);
  vector<bool> jd(n,false);
  
  int pl=0;int cnt=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<data[pl].size();j++){
      if(!jd[data[pl][j]]){
        ans[data[pl][j]]=pl+1;
        jd[data[pl][j]]=true;
        q.push(data[pl][j]);
      }
    }
    pl=q.front();
    q.pop();
  }
  
  for(int i=0;i<n;i++)if(!jd[i]){cout<<"No"<<endl;return 0;}
 
  cout<<"Yes"<<endl;
  for(int i=1;i<n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 10220
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

map < ll, ll > check;

int main() {
	int n;
	cin >> n;
	ll sum = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		ll t; cin >> t;
		sum += t;
		check[sum]++;
	}
	for (auto itr = check.begin(); itr != check.end(); itr++) {
		pair<ll,ll> tm = *itr;
		if (tm.first == 0)ans += tm.second;
		ans += tm.second*(tm.second - 1) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define BITSEARCH(i,n) for(int i=0;i<(1<<(n));++i)
#define BITCHK(i,j) (i) & (1<<(j))

/* BITSEARCH 使い方
 
BITSEARCH(i,n){
  vector<int> h;
  REP(j,n){
    if (BITCHK(i,j)){
      h.push_back(j+1);
    }
  }
}

*/

using namespace std;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int64_t n;
  cin >> n;
  vector<int> vec(n);
  REP(i,n){
    cin >> vec.at(i);
  }
  SORT(vec);
  REV(vec);
  int a = 0;
  int b = 0;
  REP(i,n){
    if (i%2 == 0){
      a += vec.at(i);
    }else{
      b += vec.at(i);
    }
  }
  cout << a - b  << endl;
  return 0;
}



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

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

int main() {

    int h,w;

    cin >> h >> w;

    char s[h][w];

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

    string ans = "Yes";

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '#') {
                bool flag = false;
                for (int k = 0; k < 4; k++) {
                    if(j + dx[k] >= 0 && j + dx[k] < w && i + dy[k] >= 0 && i + dy[k] < h){
                        if(s[i+dy[k]][j+dx[k]] == '#'){
                            flag = true;
                        }
                    }
                }
                if(!flag){
                    ans = "No";
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();

    vector<int> index(len);
    int r = 0;
    for (int i = 0; i < len; i++) {
        if (s.at(i) == 'L') index.at(i) = r;
        else r = i;
    }
    int l = len - 1;
    for (int i = len - 1; i >= 0; i--) {
        if (s.at(i) == 'R') index.at(i) = l;
        else l = i;
    }

    vector<int> sum(len);
    for (int i = 0; i < len; i++) {
        if (s.at(i) == 'R') {
            if ((index.at(i) - i) % 2 == 0) sum.at(index.at(i))++;
            else sum.at(index.at(i) - 1)++;
        }
        else {
            int r_index = index.at(i);

            if ((i - r_index) % 2 == 0) sum.at(r_index)++;
            else sum.at(r_index + 1)++;
        }
    }

    for (int i = 0; i < len; i++) {
        cout << sum.at(i) << " ";
    }
    cout << endl;
}   

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n = 0;
		for(int i = 1; i <=9; i++) {
			if(N % i == 0 && N / i <= 9) {
				n++;
			}
		}
		if(n != 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23508
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int n, i;
	cin >> n;
	int a[n], out[n];
	out[0] = 0;
	for(i = 0; i < n; i++)
		cin >> a[i];
	for(i = 0; i < n; i++)
		out[0] += pow((-1),i)*a[i];
	for(i = 1; i < n; i++)
	{
		out[i] = 2*a[i-1]-out[i-1];
	}
	for(i = 0; i < n-1; i++)
		cout << out[i] << " ";
	cout << out[n-1] << endl;
	return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int x,a,b,y,z;
  cin>>x>>a>>b;
  y = abs(a-x);
  z = abs(b-x);
  if(y>z){
    cout<<"B"<<endl;
  }
  else{
    cout<<"A"<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 256
//my first atcoder contest
//arigato hojaimas
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
#define MOD 1000000007
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll mp[26]={0};
   // map<char, int> m;
    for(int i=0; i<n; i++)
    {
        mp[s[i]-'a']++;
        //m[s[i]]++;
    }
//    if(m.size()==n)
//        cout<<(int)(pow(2,n)+0.00000001)-1<<endl;
//    else
//    {
        ll ans=1LL;
        for(int i=0; i<26; i++)
        {
            ans*=(mp[i]+1LL);
            ans%=MOD;


        }
//        for(int i=2; i<=mp.size(); i++)
//        {
//            for(int j=1; j<=i; j++)
//            {
//
//
//            }
//        }
        cout<<ans-1LL<<endl;

   // }
    return 0;
}


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

int h, w;
int c[10][10];

int main() {
	int i, j, k;

	cin >> h >> w;
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			for (k = 0; k < 10; k++) {
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			int a;
			cin >> a;
			if (a != -1) ans += c[a][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  string T;
  cin >> T;
  ll N = T.size();
  ll K;
  cin >> K;

  set<string> S;
  for (ll i = 0; i < N; i++)
  {
    for (ll j = i; j < N; j++)
    {
      if (j - i + 1 > K)
        continue;
      string t = T.substr(i, j - i + 1);
      S.emplace(t);
    }
  }

  auto itr = S.begin();
  for (ll i = 0; i < K - 1; i++)
  {
    itr++;
  }
  string ans = *itr;
  cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<string,int>> vec;
  for(int i=0; i<n; i++){
	string str;
    int num;
    cin >> str >> num;
    vec.push_back(make_pair(str, num));
  }
  string str;
  cin >> str;
  int sum = 0;
  bool flag = false;
  for(int i=0; i<n; i++){
    if(flag) sum += vec[i].second;
    if(vec[i].first == str) flag = true;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline().rstrip())
a,b = [int(x) for x in stdin.readline().rstrip().split()]
k = 0
while a <= b:
    if a % n == 0:
        k = 1
    a += 1
if k == 1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 61736
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------

    int n,m;

    cin >> n >> m;
    int i;
    string a[n],b[m];
    rep(i,n){
        cin >> a[i];
    }
    rep(i,m){
        cin >> b[i];
    }

    int j,k;
    rep (i,n-m+1){
        rep(j,n-m+1){
           rep(k,n){
                if (a[i+k].substr(j,m)==b[k]){
                    if(k==m-1){
                        pri("Yes") ;
                        return 0;
                    }
                } else {
                    break; 
                }
           }
        }
    }
    pri("No") ;
    return 0;
}



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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  string s;
  cin >> s;
  
  int count_right = 0;
  int count_left = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '(') count_left++;
    if(s[i] == ')'){
      if(count_left > 0) count_left--;
      else count_right++;
    }
  }
  
  for(int i = 0; i < count_right; i++) cout << '(';
  cout << s;
  for(int i = 0; i < count_left; i++) cout << ')';
  cout << endl;
  
  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	long long int n;
   	cin>>n;
   	long long int ans=0;
   	for(long long int i=1;i<=n-1;i++){
   		ans+=((n-1)/i);	
	}
	cout<<ans;
   	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],n,k;
int check(int x){
	long long ans=0,p;
	for(int i=0;i<n;i++){
		if(a[i]%x==0)ans+=a[i]/x-1;
		else ans+=a[i]/x;
	}
	if(ans<=k)return 1;
	return 0;
}
int main(){
	cin>>n>>k;
	int l=1,r=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		r=max(r,a[i]);
	}
	while(l<=r){
		int mid=(l+r)/2;
		if(!check(mid))l=mid+1;
		else r=mid-1;
	} 
	printf("%d\n",l); 
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 100 + 10;
const int maxp = (1 << 15) + 5;

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

int n, m;
int Maxp;
int G[maxn][maxn];

void addedge(int u, int v, int c) { 
    G[u][v] = G[v][u] = c;
}

int cost[maxp];
void init() {
    cost[0] = 0;
    for(int i = 1; i < Maxp; ++i) {
        int u = 0;
        for(int j = 0; j < n; ++j) if(i >> j & 1) { u = j; break; }

        cost[i] = cost[i ^ (1<<u)];
        for(int j = u+1; j < n; ++j) if((i >> j & 1) && G[u][j] > 0) cost[i] += G[u][j];
    }
}

int dp[maxp][maxn];
int calc() {

    init();
    memset(dp, ~oo, sizeof dp);

    for(int s = 1; s < Maxp; s += 2) {
        dp[s][0] = cost[s];
        for(int t = 1; t < n; ++t) 
            if(s >> t & 1) {
                int rest = s ^ 1 ^ (1 << t);
                for(int sub = rest; sub; sub = (sub-1) & rest) {
                    chkmax(dp[s][t], dp[s^sub][t] + cost[sub^(1<<t)]);
                }
                for(int j = 0; j < n; ++j) if((s >> j & 1) && j != t) {
                    chkmax(dp[s][t], dp[s^(1<<t)][j] + G[j][t]);
                }
            }
    }
    return dp[Maxp-1][n-1];
}

int sum;
int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
    
    memset(G, ~oo, sizeof G);
    scanf("%d%d", &n, &m); 
    Maxp = 1 << n;

    for(int i = 1; i <= m; ++i) {
        int u, v, c;
        scanf("%d%d%d", &u, &v, &c);
        addedge(--u, --v, c);
        sum += c;
    }
    cout << sum - calc() << endl;

    return 0;
}


Measured memory_bytes: 14464
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto ps = new double[][](N, 2);
    foreach (i; 0..N) {
        auto xy = readln.split.to!(double[]);
        ps[i][0] = xy[0];
        ps[i][1] = xy[1];
    }
    auto xs = new int[](N);
    foreach (i; 0..N) xs[i] = i;
    double sum_d = 0;
    int cnt;
    do {
        double d = 0;
        auto x = ps[xs[0]][0], y = ps[xs[0]][1];
        foreach (j; 1..N) {
            auto i = xs[j];
            d += sqrt((x - ps[i][0])^^2 + (y - ps[i][1])^^2);
            x = ps[i][0];
            y = ps[i][1];
        }
        sum_d += d;
        ++cnt;
    } while (nextPermutation(xs));
    writefln("%.010f", sum_d / cnt);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    ll S = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
    }
    sort(A.begin(), A.end());
    vector<ll> x;
    for (ll i = 1; i*i <= S; i++) {
        if (i*i == S) {
            x.push_back(i);
        }
        else {
            if (S % i == 0) {
                x.push_back(i);
                x.push_back(S/i);
            }
        }
    }
    sort(x.begin(), x.end());
    ll ans = 1;
    for (auto g: x) {
        ll k = 0;
        vector<ll> v;
        for (auto a: A) {
            if (a % g == 0) continue;
            k += (a/g+1)*g-a;
            v.push_back((a/g+1)*g-a);
        }
        if (k % g != 0) continue;
        sort(v.begin(), v.end(), [](auto x, auto y) {
            return x > y;
        });
        ll e = 0;
        for (int i = (k/g); i < v.size(); i++) {
            e += v[i];
        }
        if (e <= K) {
            ans = g;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

long long int modpos(long long int m, long long int n, long long int d) {
    long long int res;
    if(n == 0) return 1;
   
    res = modpos((m*m)%d, n / 2, d);
    if(n % 2) {
        res = (res*m)%d;
    }
    return res;
}

int main(void) {
    long long int m, n;
    long long int d = 1000000007ll;
   
    scanf("%lld %lld\n", &m, &n);
    printf("%lld\n",modpos(m, n ,d));
   
    return 0;
}

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

main()
{
	long long ans=0,lf=0;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		long long a;
		scanf("%lld",&a);
		ans+=min(lf,a);
		a-=lf;
		if(a>0)
			ans+=a/2;
		if(a%2==1)
		{
			lf=1;
		}
		else
		{
			lf=0;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256