akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>

using namespace std;

int main(){
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  
  int res = 0;
  for(int i=0;i<=A;i++){
    for(int k=0;k<=B;k++){
      int l = X-500*i-100*k;
      if (l%50 == 0 && 0<=l && l/50<=C){
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <stack>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define MP make_pair

using namespace std;

typedef pair<int, int> P;

int l[55], t[55], r[55], b[55];

int x[200], y[200];

const int H = 500, W = 500;
int field[H][W];
int used[H][W];

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

int main(){
	int n;
	while(cin >> n, n){
		rep(i, n){
			cin >> l[i] >> t[i] >> r[i] >> b[i];
			x[i*2] = l[i], x[i*2+1] = r[i];
			y[i*2] = t[i], y[i*2+1] = b[i];
		}
		sort(x, x+n*2);
		sort(y, y+n*2);

		map<int, int> mx, my;
		rep(i, n*2){
			mx[x[i]] = 2*i+1;
			my[y[i]] = 2*i+1;
		}

		memset(field, 0, sizeof(field));
		memset(used, 0, sizeof(used));

		rep(i, n){
			int L = mx[l[i]], R = mx[r[i]];
			int T = my[t[i]], B = my[b[i]];
			for(int i = L; i <= R; i++){
				field[T][i] = 1;
				field[B][i] = 1;
			}
			for(int i = B; i <= T; i++){
				field[i][L] = 1;
				field[i][R] = 1;
			}
		}

		int ans = 0;
		rep(i, H){
			rep(j, W){
				if(!field[i][j] && !used[i][j]){
					ans++;
					queue<P> q;
					q.push(MP(j, i));
					while(!q.empty()){
						int px = q.front().first;
						int py = q.front().second;
						q.pop();

						rep(i, 4){
							int nx = px+dx[i], ny = py+dy[i];
							if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
							if(field[ny][nx] || used[ny][nx]) continue;
							used[ny][nx] = 1;
							q.push(MP(nx, ny));
						}
					}
				}
			}
		} // end rep
		cout << ans << endl;

		//rep(i, 30){
		//	rep(j, 30){
		//		cout << (field[i][j]?'#':'.');
		//	}cout << endl;
		//}cout << endl;
	}


	return 0;
}

Measured memory_bytes: 3196
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int array[] = new int[n];
        int max = 0;
        int sum = 0;
        for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
            if(max < array[i]){
                max = array[i];
            }
            sum += array[i];
        }
        if((sum-max) > max) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23124
//1102
#include "bits/stdc++.h"
using namespace std;

void solve() {
    vector<bool> prime(100001, true);
    for (int i = 2; i * i <= 100000; i++) {
        if (!prime.at(i)) continue;
        for (int j = 2 * i; j <= 100000; j += i) {
            prime.at(j) = false;
        }
    }
    vector<int> sum(100001);
    for (int i = 3; i < 100000; i++) {
        sum.at(i) = sum.at(i - 1);
        if (prime.at(i) && prime.at((i + 1) / 2)) sum.at(i)++;
    }
    int Q, l, r;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> l >> r;
        cout << sum.at(r) - sum.at(l - 1) << endl;
    }
    return;
}

int main() {
    solve();
}

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

using namespace std;


void solve() {
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    if (s[k-1] < 'a') {
        s[k-1] += 'a'-'A';
    }
    cout << s;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <memory>
using namespace std;

typedef struct Node {
    int key;
    Node *parent, *left, *right;
} Node;

Node *root, *NIL;

void insert(int k) {
    Node *x = root;
    Node *y = NIL;
    Node *z;
    
    z = new Node;

    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z -> parent = y;
    if (y == NIL) root = z;
    else {
        if ( z->key < y->key ) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u) {
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ) {
        cin >> com;
        if ( com == "insert" ) {
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print" ) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26756
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<map>
#include<queue>
#include<iostream>
#include<cmath>
#define int long long 
using namespace std;
inline int gi(){char tmp=getchar();int flag=1;while(tmp<'0'||tmp>'9'){if(tmp=='-'){flag=-1;tmp=getchar();break;}tmp=getchar();}int ans=0;while(tmp<='9' and tmp>='0') {ans=ans*10+tmp-'0';tmp=getchar();}return ans*flag;}
inline void write(int x){static int stk[100], top = 0;if (x == 0) { putchar('0'); putchar(' ');return; }if (x < 0) { x = -x; putchar('-'); }while (x) { stk[++top] = x % 10; x /= 10; }while (top) { putchar(stk[top--] + '0'); }putchar(' ');}
#define line() putchar('\n');
#define Mem(Arr,V) memset(Arr,V,sizeof Arr);
#define Mcpy(Arr,qwq) memcpy(Arr,qwq,sizeof qwq);
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max4(max3(a,b,c),d);
#define in(a) a=gi()
#define in2(a,b) in(a),in(b)
#define in3(a,b,c) in2(a,b),in(c)
#define in4(a,b,c,d) in3(a,b,c),in(d)
#define write2(a,b) write(a),write(b)
#define write3(a,b,c) write2(a,b),write(c)
#define write4(a,b,c,d) write3(a,b,c),write(d)
#define smin(a,b) a=min(a,b)
#define smax(a,b) a=max(a,b)
priority_queue<int>Q;
int A[1000001];
signed main()
{
	int n,m;
	in2(n,m);
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		in(A[i]);
		Q.push(A[i]);
		ans+=A[i];
	}
	while(m--)
	{
		int top=Q.top();
		Q.pop();
		ans=ans-(top-(top>>1));
		Q.push(top>>1);		
	}
	write(ans);
}

Measured memory_bytes: 1912
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var headTmp = nextLine()
	var head = strings.Split(headTmp, " ")

	// fmt.Println(head[0])
	// fmt.Println(head[1])
	n0, _ := strconv.Atoi(head[0])
	n1, _ := strconv.Atoi(head[1])

	var i int
	var m string

	if head[0] > head[1] {
		for i = 0; i < n0; i++ {
			m = m + head[1]
		}
		fmt.Println(m)

	} else {
		for i = 0; i < n1; i++ {
			m = m + head[0]
		}
		fmt.Println(m)

	}
}


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

n,m = map(int,input().split())
edge = [tuple(map(int,input().split())) for i in range(m)]
#辺を足していくので逆順で考える
edge = edge[::-1]

par = [i for i in range(n+1)]
rank = [1] * (n+1)
size = [1] * (n+1)

###Union-Find
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def same_check(x, y):
        return find(x) == find(y)

    #併合(Union)
def union(x, y):
    #根を探す
    x = find(x)
    y = find(y)

    #木の高さを比較し、低いほうから高いほうに根を張る
    if rank[x] < rank[y]:
        par[x] = y
        size[y] += size[x]
    else:
        par[y] = x
        size[x] += size[y]
        if rank[x] == rank[y]:
            rank[x] += 1

result = []
for i in range(m):
    a = find(edge[i][0])
    b = find(edge[i][1])
    if a == b:
        result.append(0)
    else:
        result.append(size[a]*size[b])
        union(a,b)

ans = 0
for i in range(m):
    ans += result[m-i-1]
    print(ans)

Measured memory_bytes: 29132
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	if(a>MOD){
		a -= MOD;
	}
}

int main(void){
	int n,i,j,k,ans=0;
	bool flag;
	string s,t="AGCT";
	cin >> s;
	n = s.l_ength();
	for(i=0; i<n; ++i){
		for(j=0; j<4; ++j){
			if(s[i]==t[j]){
				s[i] = 'o';
				break;
			}
		}
		if(s[i]!='o'){
			s[i]='x';
		}
	}
	for(i=0; i<n; ++i){
		for(j=i; j<=n; ++j){
			flag = true;
			for(k=i; k<j; ++k){
				if(s[k]=='x'){
					flag = false;
					break;
				}
			}
			if(flag){
				ans = max(ans,(j-i));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    A, B, C = map(int, input().split())
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print('0')
        exit()
    if A == B == C:
        print('-1')
        exit()

    ans = 0
    while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        ans += 1
        A, B, C = (B + C) * 0.5, (A + C) * 0.5, (A + B) * 0.5
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int r;
	cin>>r;
	ld pi = acos(-1);
	ld fd = 2.0 * pi * r;
	SETF();
	cout<<setprecision(6)<<fd<<"\n";
	UNSETF();
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	//cin>>T;
	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024
#define ARRAY_SIZE 100

int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[ARRAY_SIZE];
	int change_count = 0;

	for(int i = 0; i < n; i++){
		cin >> array[i];
	}

	int tmp = 0;
	for(int i = n-1;i > 0;i--){
		for(int j = 0; j < i;j++){
			if(array[j] > array[j+1]){
				tmp = array[j+1];
				array[j+1] = array[j];
				array[j] = tmp;
				change_count++;
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(i != n-1){
			printf("%d ",array[i]);
		}else{
			printf("%d\n",array[i]);
		}
	}
	printf("%d\n",change_count);
}



Measured memory_bytes: 3228
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
126

output:
126: 2 3 3 7
"""

import sys


def is_prime(n):
    if n == 2:
        return True
    elif n < 2 or not n % 2:
        return False

    return pow(2, n - 1, n) == 1


def prime_factorize(n):
    if is_prime(n):
        return [n]

    ans = []
    d = 2

    while pow(d, 2) <= n:
        while not n % d:
            ans.append(d)
            n //= d
        d += 1

    if n > 1:
        ans.append(n)

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(str(n1) + ':', *prime_factorize(n1))

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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=arr[i];
    }
    cout<<ans;

    return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  ll a, b;
  scanf("%lld %lld", &a, &b);

  ll v;
  if (a % 2 == 0 && b % 2 == 0) {
    ll pair_num = (b - a) / 2;
    v = b ^ ((pair_num % 2 == 0) ? 0 : 1);
  } else if (a % 2 == 1 && b % 2 == 0) {
    ll pair_num = (b - a) / 2;
    v = a ^ b ^ ((pair_num % 2 == 0) ? 0 : 1);
  } else if (a % 2 == 0 && b % 2 == 1) {
    ll pair_num = (b - a + 1) / 2;
    v = ((pair_num % 2 == 0) ? 0 : 1);
  } else if (a % 2 == 1 && b % 2 == 1) {
    ll pair_num = (b - a) / 2;
    v = a ^ ((pair_num % 2 == 0) ? 0 : 1);
  }

  cout << v << endl;

  // ll v2 = a;
  // for (ll i = a + 1; i <= b; i++) {
  //   v2 = v2 ^ i;
  // }
  // cout << v2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, M; cin >> N >> M;
  vi arr(N);
  rep(i,N) cin >> arr[i];
  rep(i,N) --arr[i];
  Graph G(N);
  rep(i,M) {
    int x, y; cin >> x >> y; --x; --y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  vb seen(N, false);
  int ans = 0;

  rep(i,N) {
    if (seen[i]) continue;

    seen[i] = true;
    queue<int> q;
    q.push(i);
    unordered_set<int> s;
    s.insert(i);
    
    while (!q.empty()) {
      int v = q.front(); q.pop();

      for (auto nv : G[v]) {
        if (seen[nv]) continue;

        seen[nv] = true;
        q.push(nv);
        s.insert(nv);
      }
    }

    for (auto p : s) {
      if (s.count(arr[p])) ++ans;
    }
  }

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


Measured memory_bytes: 10276
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        ArrayList<Long> hitPoint = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            hitPoint.add(stdIn.nextLong());
        }

        Collections.sort(hitPoint);

        long attack = 0;
        for (int i = 0; i < n - k; i++) {
            attack += hitPoint.get(i);
        }

        System.out.println(attack);
    }
}


Measured memory_bytes: 79568
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int a[1000];
int main()
{
    int n, m;
    cin >> n >> m;
    int sol = 0;
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        if (a[i] * 4 * m >= sum)
            sol++;
    }
    if (sol >= m)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      s: String,
      t: String,
   }
   let s = s.as_bytes();
   let t = t.as_bytes();
   let n = s.len();
   let m = t.len();
   let mut dp = vec![vec![0; m + 1]; n + 1];
   for i in 0..n {
      for j in 0..m {
         dp[i + 1][j + 1] = if s[i] == t[j] {
            dp[i][j] + 1
         } else {
            std::cmp::max(dp[i + 1][j], dp[i][j + 1])
         };
      }
   }
   let mut ans: Vec<char> = Vec::new();
   let mut i = n;
   let mut j = m;
   while dp[i][j] != 0 {
      if dp[i][j] == dp[i][j - 1] {
         j -= 1;
      } else if dp[i][j] == dp[i - 1][j] {
         i -= 1;
      } else {
         i -= 1;
         j -= 1;
         ans.push(s[i] as char);
      }
   }
   ans.reverse();
   println!("{}", ans.iter().map(|&c| c).collect::<String>());
}


Measured memory_bytes: 41212
#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long n;
map<long long,long long>mp;
long long dfs(long long p)
{
	if(mp[p])
	{
		return mp[p];
	}
	else
	{
		mp[p]=(dfs(p/2)+dfs((p-1)/2)+dfs((p-2)/2))%md;
		return mp[p];
	}
}
int main()
{
	cin>>n;
	mp[0]=1;
	mp[1]=2;
	cout<<dfs(n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
int main(){
    string temp;
    int a,b;
    stack<string> ops;
    while(cin>>temp){
        if("-" == temp || "+" == temp || "*"==temp || "/"==temp){
            a = stoi(ops.top());
            ops.pop();
            b = stoi(ops.top());
            ops.pop();
            if("-" == temp)
                ops.push(to_string(b-a));
            else if("+" == temp)
                ops.push(to_string(b+a));
            else if("*"==temp)
                ops.push(to_string(b*a));
            else if("/"==temp)
                ops.push(to_string(b/a));
        }
        else
            ops.push(temp);
    }
    cout<<ops.top()<<endl;
}


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

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

using ll = long long;
using ull = unsigned long long;

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

  int ans = 0;
  rep (i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ++ans;
    }
  }

  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    string st;
    cin>>st;
    int c[26]={};
    for(int i=0;i<st.length();i++){
        c[st[i]-'a']++;
    }
    int ans=1;
    for(int i=0;i<26;i++){
        for(int j=i+1;j<26;j++){
            ans+=c[i]*c[j];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
//debug() << imie(x) imie(y);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
int h,w;
cin>>h>>w;
string s;
for(int i=0;i<h;i++)
{
	cin>>s;

	cout<<"\n"<<s<<"\n"<<s;
}

return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
A = sorted(LI())
ans = 0
cnt = Counter(A)
m = max(A) + 1
B = [0] * (10 ** 6 + 1)
for a in A:
    if B[a] == 0 and cnt[a] == 1:
        ans += 1
    for i in range(a * 2, m, a):
        B[i] = 1


print(ans)





Measured memory_bytes: 135636
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
d = map(int, raw_input().split())
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += d[i] * d[j]
print ans

Measured memory_bytes: 4396
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	o = list(map(int,input().split()))
	m = max(o)
	o.remove(m)
	diff = 2*m - sum(o)
	if(diff%2==0):
		print(diff//2)
	else:
		m+=1
		o[0]+=1
		print((2*m-sum(o))//2 + 1)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 63724
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int sum(int c){
  int sum=0;
  int keta=(int)log10(c);
  
  for(int ii=keta;ii>=0;ii--){
    sum+=c/pow(10,ii);
    c-=pow(10,ii)*(int)(c/pow(10,ii));
  }
  return sum;
}


int main(){
  int n,a,b,x,ans=0;
  cin>>n>>a>>b;

  REP(i,n+1){
     if(a<=sum(i) && sum(i)<=b) ans+=i;
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    int K,S;
    cin>>K>>S;
    int counter=0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            if(S-i-j<=K && S-i-j>=0){
                counter++;
            }
        }
    }
    cout<<counter<<endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

#define MAX 100100
int n,k;
int res = 0;
vector<int> d[MAX];
int dfs(int v){
  int pom = 0;
  for(int el:d[v]){
    maxi(pom, dfs(el));
  }
  if(pom == k-1){
    res ++;
    return 0;
  }
  return pom + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k;
  R(i,n){
    int pom;
    cin >> pom;
    if(i == 0){
      if(pom != 1)res ++;
    }else{
      d[pom-1].PB(i);
    }
  }
  for(int el:d[0])for(int el2:d[el])dfs(el2);
  cout << res << "\n";
}


Measured memory_bytes: 8832
n=int(input())
w=list(map(int, input().split()))
count=0
for i in range(n):
    if sum(w[:i])>=sum(w[i:]):
        a=sum(w[:i])-sum(w[i:])
        b=sum(w[i-1:])-sum(w[:i-1])
        print(min(a,b))
        break

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
  int H,W;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0)break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + j)%2 != 0) {
          cout << ".";
        }
        else cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


vector<string> sall;

void dfs(string s, int n, char c_max){
    if (n == -1) return;

    for (char c = 'a'; c <= c_max; c++){
        dfs(s+c, n-1, c_max);
    }
    char n_c = c_max+1;
    dfs(s+n_c, n-1, n_c);

    if (n==0) sall.push_back(s);
    return;
}

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

    string s = "a";
    dfs(s, n-1, 'a');

    rep(i, sall.size()){
        cout << sall[i] << endl;
    }

}



Measured memory_bytes: 7796
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
ll nCr(ll n, ll r){
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
  ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
  return ret;
}

int main(void){
  ll n,h;cin>>n;
  ll ans = 0, memo = -1, count = 0;
  rep(i,n){
    cin>>h;
    if(memo < h){
      chmax(ans, count);
      memo = h;
      count = 0;
    }else{
      count++;
      memo = h;
    }
  }
  chmax(ans, count);
  cout<<ans<<endl;
  return 0;
}


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


public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner	stdin   = new Scanner(System.in);
		int		arrIn[] = new int[10];

		for(int nLoop = 0; nLoop < arrIn.length; nLoop++) {
			arrIn[nLoop] = stdin.nextInt();
		}

		Arrays.sort(arrIn);

		for(int nLoop = 0; nLoop < 3; nLoop++) {
			System.out.println(arrIn[arrIn.length - nLoop - 1]);
		}
	}
}

Measured memory_bytes: 17352
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]

heapq.heapify(A)
for m in range(M):
    most_expensive = -heapq.heappop(A)
    heapq.heappush(A, -(most_expensive // 2))

print(-sum(A))


Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    if (s[0] != 'A') { cout << "WA"; return 0; }
    int c = 0;
    for (int i = 2; i <= s.size() - 2; i++) if (s[i] == 'C') c++;
    if (c != 1) { cout << "WA"; return 0; }
    for (int i = 0; i < s.size() ; i++)
        if ('A' <= s[i] && s[i] <= 'Z' && s[i] != 'A' && s[i] != 'C')
            { cout << "WA"; return 0; }
    cout << "AC";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

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

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel";
    }else {
        cout << "consonant";
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(0)
c = [0] * (n+1)

temp=0

for i in range(n+1):
	c[i] = min(a[i],temp )
	a[i] -= c[i]
	c[i] += min(a[i], b[i])
	temp = b[i] - min(a[i],b[i])

print(sum(c))



Measured memory_bytes: 19116
import fractions

n,m=list(map(int,input().split()))
s=input()
t=input()
l=n*m//fractions.gcd(n,m)

m,n=(m//fractions.gcd(m,n),n//fractions.gcd(m,n))
p=m*n//fractions.gcd(m,n)

pos=0
while pos<l:
    if s[pos//m]!=t[pos//n]:
        print(-1)
        exit(0)

    pos+=p

print(l)

Measured memory_bytes: 77612
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
 
using namespace std;
typedef long long ll;
 
const ll MOD = 1000000007;
int dp[10001][2][100];
int D;
 
int main() {
	string str;
	cin >> str >> D;
	dp[0][0][0] = 1;
	for (int i = 0; i <= str.size(); i++) {
		for (int j = 0; j < 2; j++) {
			int lim = j ? 9 : str[i] - '0';
			for (int k = 0; k < D; k++) {
				for (int d = 0; d <= lim; d++) {
					dp[i + 1][j || (lim > d)][(k + d) % D] += dp[i][j][k];
					dp[i + 1][j || (lim > d)][(k + d) % D] %= MOD;
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < 2; i++) {
		ans += dp[str.size()][i][0];
		//cout << ans << endl;
	}
	cout << (ans - 1 + MOD) % MOD << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
using namespace std;

int64_t normal_15(int64_t digits) {
  return digits * 8 + 32;
}

int64_t digit(int64_t n) {
  if (n < 10) return 1;
  return digit(n/10) + 1;
}

string fizzbuzz(int64_t n) {
  if ((n % 15) == 0) return "FizzBuzz";
  if ((n % 5) == 0) return "Buzz";
  if ((n % 3) == 0) return "Fizz";
  return to_string(n);
}

int64_t fizzbuzz_len(int64_t n) {
  return fizzbuzz(n).size();
}

int64_t pow10(int64_t n) {
  if (n == 0) return 1;
  return 10 * pow10(n-1);
}

int64_t len_ndigits(const int64_t n) {
  if (n == 1) return 21;
  int64_t count = pow10(n) - pow10(n-1);
  int64_t loop_count = count / 15;
  int64_t sum = normal_15(n) * loop_count;
  for (int64_t i = pow10(n-1) + loop_count * 15; i < pow10(n); ++i) {
    sum += fizzbuzz_len(i);
  }
  return sum;
}

int64_t len_under_n(int64_t n) {
  int64_t d = digit(n);
  int64_t sum = 0;
  for (int64_t i = 1; i < d; ++i)
    sum += len_ndigits(i);
  int64_t rem_count = n - pow10(d-1);
  sum += normal_15(d) * (rem_count / 15);
  for (int64_t i = pow10(d-1) + (rem_count / 15) * 15; i < n; ++i) {
    sum += fizzbuzz_len(i);
  }
  return sum;
}

int main() {
  int64_t s;
  cin>>s;
  int64_t b = 0;
  int64_t t = 1ll<<57;
  while (t-b > 1) {
    int64_t m = (t + b) / 2;
    int64_t r = len_under_n(m);
    if (r >= s) {
      t = m;
    } else {
      b = m;
    }
  }
  string str;
  for (int64_t i = 0; i < 20; ++i) {
    str += fizzbuzz(b+i);
  }
  cout << str.substr(s-len_under_n(b)-1, 20) << endl;
  return 0;
}

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

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b && b==c) cout << "No" << endl;
    else if(a!=b && b!=c && c!=a) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

#define ll long long
const int mod = 1e9 + 7;

void solve() {
	int x;
	cin >> x;
	if (x >= 400 && x <= 599) {
		cout << 8;
		return;
	}
	if (x >= 600 && x <= 799) {
		cout << 7;
		return;
	}
	if (x >= 800 && x <= 999) {
		cout << 6;
		return;
	}
	if (x >= 1000 && x <= 1199) {
		cout << 5;
		return;
	}
	if (x >= 1200 && x <= 1399) {
		cout << 4;
		return;
	}
	if (x >= 1400 && x <= 1599) {
		cout << 3;
		return;
	}
	if (x >= 1600 && x <= 1799) {
		cout << 2;
		return;
	}
	if (x >= 1800 && x <= 1999) {
		cout << 1;
		return;
	}
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	// int c = 1;
	while (t--) {
		// cout << "Case #" << c << ": ";
		solve();
		// c++;
	}
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
int main()
{
    char s[200];
    scanf("%s",s);
    int len=0;
    for(int i=0;s[i]!=0;i++){
    len++;
    }
    int cnt=0;
    for(int i=0,j=len-1;i<=j;i++,j--)
    {
        if(s[i]!=s[j]){
        cnt++;}}
    printf("%d",cnt);
    return 0;
}


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

using namespace std;
const int MAX = 200000;
long long Value[MAX]{0};
long long a[MAX]{0};
int main()
{
    long long n{0};
    while(scanf("%lld", &n)!= EOF && n){
        memset(a,0,sizeof(a));
        long long x{0}, y{0};
        for (int i=0; i < n; i++){
            scanf("%lld", &a[i]);
            y+=a[i];
        }
        y-=a[0];
        x=a[0];
        Value[0] = abs(x-y);
        for (int k=1; k <n-1; k++){
            x+=a[k];
            y-=a[k];
            Value[k] =(long long) abs(x-y);
        }
        sort(Value,Value+n-1);
        printf("%lld\n",Value[0]>0? Value[0]:Value[0]*-1);
    }
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
	int i,u,a0,a1=0,a2=0,kioku[28];
	for(i=0; i<28; i++)
	{
		scanf("%d",&kioku[i]);
	}
	for(u=1; u<=30; u++)
	{
		a0=0;
		for(i=0; i<28; i++)
		{
			if(kioku[i]==u)
				a0=1;
		}
		if(a0==0)
		{
			if(a1==0)
			{
				a1=u;
			}
			else
			{
				a2=u;
			}
		}
	}

	if(a1<a2)
	{
		printf("%d\n%d\n",a1,a2);
	}
	else
	{
		printf("%d\n%d\n",a2,a1);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100005;

int n;
struct edge{
	int x,nxt;
}e[N*2];
int h[N],tot;
int d[N];

void inse(int x,int y){e[++tot].x=y;e[tot].nxt=h[x];h[x]=tot;}

int dis[N],lst[N];
bool vis[N];
int key[N];

void getdis(int x){
	vis[x]=1;
	for(int p=h[x];p;p=e[p].nxt)
	if (!vis[e[p].x]){
		dis[e[p].x]=dis[x]+1;
		lst[e[p].x]=x;
		getdis(e[p].x);
	}
}

int ans1[N],ans2[N];

int main(){
	//freopen("data.in","r",stdin);
	n=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y),inse(y,x);
		d[x]++,d[y]++;
	}
	getdis(1);
	int val=0,w=1;
	fo(i,2,n)
	if (val<dis[i])w=i,val=dis[i];
	fo(i,1,n)lst[i]=dis[i]=0,vis[i]=0;
	getdis(w);
	val=0;
	int t=w;
	fo(i,1,n)
	if (val<dis[i])t=i,val=dis[i];
	int x=w,y=t;
	int k=0;
	for(int now=y;now;now=lst[now])key[++k]=now;
	fo(i,2,k-1)d[key[i]]-=2;
	d[x]--,d[y]--;
	int pre=1;
	ans1[1]=1;ans1[n]=n;
	fo(i,2,k-1){
		fo(x,pre+2,pre+d[key[i]]+1)ans1[x-1]=x;
		ans1[pre+d[key[i]]+1]=pre+1;
		pre=pre+d[key[i]]+1;
	}
	if (pre!=n-1)return printf("-1\n"),0;
	ans2[1]=1;ans2[n]=n;
	pre=1;
	fd(i,k-1,2){
		fo(x,pre+2,pre+d[key[i]]+1)ans2[x-1]=x;
		ans2[pre+d[key[i]]+1]=pre+1;
		pre=pre+d[key[i]]+1;
	}
	bool pd=1;
	fo(i,1,n)
	if (ans1[i]!=ans2[i]){
		pd=(ans1[i]<ans2[i]);
		break;
	}
	if (pd)fo(i,1,n)printf("%d ",ans1[i]);
	else fo(i,1,n)printf("%d ",ans2[i]);
	return 0;
}

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

int main() {
     int a,b;
     cin>>a>>b;
    string str = to_string(a);
    string str2= to_string(b);
    for(int i=1;i<a;i++) {
         str2+=to_string(b);
    }
    for(int i=1;i<b;i++) {
        str+=to_string(a);
    }if(a>b){
        cout<<str2;
    }else{
        cout<<str;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
def print_ans(H, N, ar):
    """Test Case
    >>> print_ans(10, 3, [4, 5, 6])
    Yes
    >>> print_ans(20, 3, [4, 5, 6])
    No
    >>> print_ans(210, 5, [31, 41, 59, 26, 53])
    Yes
    >>> print_ans(211, 5, [31, 41, 59, 26, 53])
    No
    """
    if H <= sum(ar):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    H, N = map(int, input().rstrip().split())
    ar = list(map(int,input().rstrip().split()))
    print_ans(H, N, ar)




Measured memory_bytes: 14012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				int m=sc.nextInt();
				if(n==0 && m==0) break;
				int[] a=new int[n+1];
				int sum=0;
				int max=0;
				for(int i=0; i<n; i++) {
					a[i]=sc.nextInt();
				}
				for(int i=0; i<n; i++) {
					for(int j=i+1; j<n; j++) {
						sum=a[i]+a[j];
						if(sum<=m) {
							max=Math.max(sum, max);
						}
					}
				}
				if(max==0) {
					System.out.println("NONE");
				}
				else {
					System.out.println(max);
				}
			}
		}
	}
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:
const ll inf=1LL<<60;
ll a[4010];

ll num[2010];

int main(void){
	ll n,x;
	cin >> n >> x;
	rep(i,n) cin >> a[i];
	rep(i,n) a[i+n]=a[i];

	ll ans=inf;
	rep(i,n) num[i]=inf;

	rep(i,n){
		ll sum=0LL;
		rep(j,n){
			chmin(num[j],a[n+j-i]);
			sum+=num[j];
		}
		chmin(ans,sum+x*i);
	}

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int p, q;
		double sum, r;
		int[] s;
		double[] t;
		
		double max = -1;
		int n = sc.nextInt();
		for(int i=0;i<=n;i++){
			p = sc.nextInt();
			q = sc.nextInt();
			sum = 0;
			r = 0;
			s = new int[q];
			t = new double[q];
			for(int j=0;j<q;j++){
				s[j] = sc.nextInt();
				t[j] = sc.nextDouble();
				r += t[j];
			}
			for(int j=0;j<q;j++) sum += (s[j]*t[j])/r;

			if(i==n){
				if(max-sum>0.0000001) System.out.println("YES");
				else System.out.println("NO");
			}else{
				max = Math.max(max, sum);
			}
		}
	}	
}

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

using namespace std;

int main(){
	int N,M,K;
	cin >> N >> M >> K;
	bool f = false;
	for(int i = 0;i <= N;i++){
		
		for(int j = 0;j <= M;j++){
			int v = i*M;///黒の数
			v -= j*i;
			v += j*(N-i);
			if(v == K)f = true;
		}
	}
	cout << (f?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
#define LL long long
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
int flag[10];
string str;
bool result = false;
void check(){
    string s;
    if(flag[0])s+="A";
    s+="K";
    s+="I";
    s+="H";
    if(flag[1])s+="A";
    s+="B";
    if(flag[2])s+="A";
    s+="R";
    if(flag[3])s+="A";
    if(str==s)result = true;
    return;
}
void calu(int i){
    if(4==i){
        check();
        return;
    }
    flag[i]=0;calu(i+1);
    flag[i]=1;calu(i+1);
}
int main(){
   cin >> str;
   calu(0);
   COUT(result?"YES":"NO");
   return 0;
}


Measured memory_bytes: 256