akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

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

void solve() {
	string s; cin >> s;
	if (s.size()%2) {
		cout << "No";
		return;
	}
	for (int i = 0; i < (int)s.size()-1; i+=2) {
		if (s[i] == 'h' && s[i+1] == 'i') continue;
		cout << "No";
		return;
	}
	cout << "Yes";
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long x = sc.nextLong();
      long y = sc.nextLong();
    
      if(x*(-1) == y) 
        System.out.println(1);
      else if(x == y)
        System.out.println(0);
      else if(x < y)
        if(y > 0 && (x * 1.0 / y < 0)) 
            System.out.println(Math.abs(Math.abs(y) - Math.abs(x)) + 1);
        else
            System.out.println(Math.abs(Math.abs(y) - Math.abs(x)));
      else 
          if(x < 0 || (y * 1.0 / x > 0))
            System.out.println(Math.abs(Math.abs(x) - Math.abs(y)) + 2);
          else
            System.out.println(Math.abs(Math.abs(x) - Math.abs(y)) + 1);
  }
}

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

int main(){
    int N,K;
    int x[100000];
    cin >> N >> K;
    int len1=0;
    int len2=0;
    int m=2000000001;
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    for(int i=0;i<N-K+1;i++){
        //for(int j=0;j<K;j++){
            len1 = abs(x[i]) + x[i+K-1] - x[i];
            len2 = abs(x[i+K-1]) + x[i+K-1] - x[i];
            m = min(m, len1);
            m = min(m, len2);
        //}
    }   
    cout << m << '\n';
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>


using namespace std;


void security()
{
  string s;
  cin >> s;

  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] == s[i])
    {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


void fifty_fify()
{
  string s;
  cin >> s;

  sort(s.begin(), s.end());

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
}


void dodecagon()
{
  int r;
  cin >> r;

  cout << 3 * r * r << "\n";
}


void harmony()
{
  int a, b;
  cin >> a >> b;

  if (a % 2 == b % 2) cout << (a + b) / 2 << "\n";
  else cout << "IMPOSSIBLE\n";
}


void transfer()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << "\n";
}


void A_137()
{
  int a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << "\n";
}


void red_or_not()
{
  int a;
  cin >> a;
  string s;
  cin >> s;

  if (a >= 3200) cout << s << "\n";
  else cout << "red\n";
}


void tenki()
{
  string s, t;
  cin >> s >> t;

  int cnt = 0;
  for (int i = 0; i < 3; ++i)
  {
    if (s[i] == t[i]) ++cnt;
  }
  cout << cnt << "\n";
}


void password()
{
  int n;
  cin >> n;

  cout << pow(n, 3) << "\n";
}



void one_clue()
{
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i < x + k; ++i)
  {
    if (i == x + k - 1) cout << i << "\n";
    else cout << i << " ";
  }
}



void resistors_in_parallel()
{
  int n;
  cin >> n;
  vector<float> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  float ans = 0.0;
  for (int i = 0; i < n; ++i) ans += 1.0 / a[i];
  cout << 1.0 / ans << "\n";
}


void power_socket()
{
  int a, b;
  cin >> a >> b;

  if (b == 1) cout << 0 << "\n";

  int cnt = 1, tap = (a - 1) * cnt + 1;
  while (tap < b)
  {
    ++cnt;
    tap += a - 1;
  }
  
  cout << cnt << "\n";
}


void buffet()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n - 1; ++i) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    ans += b[a[i] - 1];
    if (i > 0 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1] - 1];
  }
  cout << ans << "\n";
}




int main()
{
  //security();
  //fifty_fify();
  //dodecagon();
  //harmony();
  //transfer();
  //A_137();
  //red_or_not();
  //tenki();
  //password();

  //resistors_in_parallel();
  //power_socket();
  //buffet();
  //resistors_in_parallel();
  one_clue();

}

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

main(){
    string line;
    while(1){
	getline( cin, line );
	if ( line == "END OF INPUT" ) break;

	int cnt = 0;
	for ( int i = 0; i < line.size(); i++ ){
	    if ( line[i] == ' ' ) {
		cout << cnt; cnt = 0;
	    } else {
		cnt++;
	    }
	}
	cout << cnt << endl;

    }
}

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


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

  int arr[n],count=0;

  for(int i = 0 ; i < n ; i++)
    cin>>arr[i];
  
  for(int i = 0 ; i <= n-3 ; i++){
    if((arr[i]<arr[i+1] && arr[i+1] < arr[i+2]) ||
        (arr[i]>arr[i+1] && arr[i+1]>arr[i+2])
      ){
        count++ ;
      }
  }

  cout<<count;
    
    
	return 0;
}

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


using namespace std ;


char CMP( int *number ,int i ,int j )
{
	return ( number[ j ] % i ) > ( number[ j + 1 ] % i ) ;
}

#define cmp CMP( number ,i ,j )


int student[ 100 + 1 ] ;

int number[ 100 + 1 ] ;

int main( void )
{
	int N ,M ;
	scanf( "%d %d" ,&N ,&M ) ;

	int i ,j ;
	for( i = 1 ; i <= N ; ++i )
	{
		scanf( "%d" ,&number[ i ] ) ;
	}

	for( i = 1 ; i <= M ; ++i )
	{
		for( j = 1 ; j < N ; ++j )
		{
			if( cmp )
			{
				swap( number[ j ] ,number[ j + 1 ] ) ;
			}
		}
	}

	for( i = 1 ; i <= N ; ++i )
	{
		printf( "%d\n" ,number[ i ] ) ;
	}


	return 0 ;
}

Measured memory_bytes: 2716
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nk = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);

        int[] arr = new int[n];
        String[] line = scanner.nextLine().split(" ", n);
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(line[i]);
        }

        Arrays.sort(arr);
        int sum = 0;
        for (int i = n - k; i < n; i++) {
            sum += arr[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e18 + 8;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 998244353;


int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int h1, m1, h2, m2, t;
    cin >> h1 >> m1 >> h2 >> m2 >> t;
    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;
    t2 -= t;
    int ans = max(0LL, t2 - t1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#define MIN(a,b) ((a)>(b)?(b):(a))
using namespace std;

int main(void){
	int n,c=0;
	int a0=0,a1=0,a2=0,a;
	int now=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%3==0)a0++;
		else if(a%3==1)a1++;
		else a2++;
	}
	if(a1==0&&a2==0){
		cout<<1<<endl;
		return 0;
	}
	if(a1>a2){
		a1--;
		c++;
		c+=a0;
		a0=0;
		now=1;
	}else{
		a2--;
		c++;
		c+=a0;
		a0=0;
		now=2;
	}
		bool f=true;
		while(f){
			f=false;
			if(now==1&&a1!=0){
				a1--;
				c++;
				f=true;
				now=2;
			}else if(now==2&&a2!=0){
				a2--;
				c++;
				f=true;
				now=1;
			}
		}
		if(c!=n)c++;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3088
n = gets.to_i
arr = []
s = 0
ans = 0
a = gets.chomp.split(" ").map!(&:to_i)
b = gets.chomp.split(" ").map!(&:to_i)
i = 0
b.each do |v|
  t = v - a[i]
  if t > 0
    s += t
    ans += 1
  else
    arr.push(-t)
  end
  i += 1
end
arr.sort!.reverse!
arr.each do |v|
  break if s<=0
  s -= v
  ans += 1
end
puts s <= 0 ? ans : -1


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

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

bool check1(int64_t y) {
    REP(i, 1, 10) {
        if (y * i % 10 == 7) {
            return true;
        }
    }
    return false;
}

int64_t check2_1(string x, int64_t y) {
    int64_t tx = stoll(x);
    return tx % y;
}

int64_t check2(int64_t y) {
    string x = "7";
    int64_t tx = check2_1(x, y), r = 1;
    map<int64_t, bool> mii;
    while (tx != 0) {
        if (mii.find(tx) != mii.end()) {
            return -1;
        } else {
            mii[tx] = true;
        }
        x = to_string(tx);
        x.push_back('7');
        r++;
        tx = check2_1(x, y);
    }
    return r;
}

void Main() {
    int64_t k; cin >> k;
    if (!check1(k)) {
        cout << -1 << endl;
        return;
    }
    int64_t c2 = check2(k);
    if (c2 == -1) {
        cout << -1 << endl;
        return;
    } else {
        cout << c2 << endl;
    }
}


Measured memory_bytes: 66168
#include <iostream>
#include <string>
using namespace std;
int main()
{
   string s;cin>>s;
   if(s=="SUN"){
    cout<<7;
   }
   if(s=="MON"){
    cout<<6;
   }
   if(s=="TUE"){
    cout<<5;
   }
   if(s=="WED"){
    cout<<4;
   }
   if(s=="THU"){
    cout<<3;
   }
   if(s=="FRI"){
    cout<<2;
   }
   if(s=="SAT"){
    cout<<1;
   }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

void solve() {
    ll n;
    int x, m;
    cin >> n >> x >> m;

    vector<int> cnt(m, 0);
    vector<int> cycle;
    int cur = x;
    ll ans = 0;

    while (n > 0) {
        cnt[cur]++;

        if (cnt[cur] == 2) cycle.push_back(cur);
        else if (cnt[cur] == 3) break;

        ans += cur;
        n--;

        cur = (1LL * cur * cur) % m;
    }
    

    if (!cycle.empty()) {
        ll cycle_sum = 0;
        for (int &el : cycle) {
            cycle_sum += el;
        }

        ll p = n / cycle.size();
        ll q = n % cycle.size();
        ans += p * cycle_sum;

        fori (i, 0, q) {
            ans += cycle[i];
        }
    }

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



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

    vector <int> din(4);
    string input;
    cin >> input;

    rep(i,4) din.at(i) = input.at(i) - '0';

    int re = 0;

    // 0~8のループ
    rep(x,8){
        int sum = 0;
        string out;
        out += (char)('0' + din.at(0));
        sum += din.at(0);
        for(int i = 0; i < 3 ; i++){

            if(x & (1<<i)){
                sum += din.at(i+1);
                out += '+';
              	out += (char)('0' + din.at(i+1));
            }else{
                sum -= din.at(i+1);
                out += '-';
                out += (char)('0' + din.at(i+1));
            }
        }

        if(sum == 7){
          	out += '=';
          	out += '7';
            cout << out << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int SZ=300005;
vector<int> graph[SZ];
queue<int> q;
int dist[SZ];
int main(void){
	ios::sync_with_stdio(false); cin.tie(NULL);
	memset(dist,-1,sizeof(dist)); 
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		graph[3*x].push_back(3*y+1);
		graph[3*x+1].push_back(3*y+2);
		graph[3*x+2].push_back(3*y);
	}
	int s,t; cin >> s >> t;
	dist[3*s]=0;
	q.push(3*s);
	while(!q.empty()){
		int f=q.front(); q.pop();
		for(int nxt:graph[f]){
			if(dist[nxt]!=-1) continue;
			q.push(nxt);
			dist[nxt]=dist[f]+1;
		}
	}
	if(dist[3*t]==-1) cout<<-1;
	else cout<<dist[3*t]/3;
	return 0;
}

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

int main() {
int a, N;
double s = 0.0;

cin >> N;
for (int i = 0; i < N; i++) {
  cin >> a;
  s += 1.0 / a;
}
cout << 1 / s << endl;
return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input().split()
for i in range(n):
    a[i]=int(a[i])

su=0
for i in range(n):
    su+=a[i]
best = abs(su-2*a[0])
curr=0
for i in range(n-1):
    curr+=a[i]
    diff=abs(su-2*curr)
    best=min(best,diff)

print (best)


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

int main() {
	int a, b, c;
	int num = 0;
	cin >> a >> b >> c;
	vector<int> data{a, b, c};
	while (!(data[0] == data[1] && data[1] == data[2] && data[2] == data[0])) {
		sort(data.begin(), data.end());
		if (data[1] != data[2]) {
			data[0] += 1;
			data[1] += 1;
			num++;
		}
		else {
			data[0] += 2;
			num++;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split(" "))

s1 = "####################################################################################################\n\
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#\n"
s2 = "....................................................................................................\n\
#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.\n"
black = '#' * 100 + '\n'
white = '.' * 100 + '\n'

cnt = (A-1) // 50
mer = (A - 1) % 50
if mer == 0:
	up = s1 * cnt + black
else:
	up = s1 * cnt + black + ('.#' * mer) + ('#' * (100 - 2*mer)) + '\n' + black

cnt = (B-1) // 50
mer = (B - 1) % 50

if mer == 0:
	down = s2 * cnt + white
else:
	down = s2 * cnt + white + ('#.' * mer) + ('.' * (100 - 2*mer)) + '\n' + white

print(str(len((up+down)) // 100) + " 100")
print(up + down)



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;


#define pb push_back
#define ff first
#define ss second
#define SIZE 200001
#define INF int(2e9 + 9)
#define BIG_INF ll(4e18 + 9)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define _sz(v) int((v).size())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout)
//#pragma GCC optimize("Ofast")

const int mod = 1e9 + 7;

ll binpow(ll a, ll b, ll mod = BIG_INF)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= mod;
        res %= mod;
    }
    res %= mod;
    return res;
}




int T = 1, n, a[SIZE];
vector<int> v;
string s;

map<string, int> cnt;
void solve()
{
    cin >> n;
    while(n--)
    {
        cin >> s;
        cnt[s]++;
    }

    cout << "AC x " << cnt["AC"] << "\n";
    cout << "WA x " << cnt["WA"] << "\n";
    cout << "TLE x " << cnt["TLE"] << "\n";
    cout << "RE x " << cnt["RE"];

}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    filein; fileout;

//    cin >> T;

    while(T--)
    {
        solve();
    }




    return 0;
}


Measured memory_bytes: 3636
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    """
        ababababa
        bababba
        のどちらかで終わる
        両端が同じなら上
        そうでないなら下のようになる
        
        つまり両端が同じなら奇数長になり
        そうでないなら偶数長になる
    """

    if (len(S)&1) == (S[0]==S[-1]):
        print("Second")
    else:
        print("First")


if __name__ == '__main__':
    main()

Measured memory_bytes: 5648
n = int(input())
d,x = map(int, input().split())
a = [int(input()) for i in range(n)]
for i in range(n):
    k = 0
    count = 0
    while k*a[i]+1 <= d:
        k += 1
        count += 1
    else:
        x += count
print(x)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int g = 1;
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            g = gcd(g, A[i]);
        }

        List<Integer> primes = createPrimes();
        Map<Integer, Integer> lcmSpec = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int a = A[i]/g;
            for (int prime : primes) {
                int count = 0;
                while (a%prime == 0) {
                    count++;
                    a /= prime;
                }
                int old = lcmSpec.getOrDefault(prime, 0);
                lcmSpec.put(prime, Math.max(old, count));
            }
            lcmSpec.put(a, 1);
        }

        long lcmMod = g;
        for (Map.Entry<Integer, Integer> entry : lcmSpec.entrySet()) {
            int p = entry.getKey();
            int c = entry.getValue();
            lcmMod *= powMod(p, c);
            lcmMod %= MOD;
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += (lcmMod*powMod(A[i], MOD-2))%MOD;
            ans %= MOD;
        }

        System.out.println(ans);
    }

    private static long powMod(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b%2 == 1) {
            return (a*powMod(a, b-1))%MOD;
        }
        long half = powMod(a, b/2);
        return (half*half)%MOD;
    }

    private static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a%b);
    }

    private static List<Integer> createPrimes() {
        List<Integer> primes = new ArrayList<>();
        for (int a = 2; a <= 1_000; a++) {
            boolean isPrime = true;
            for (int i = 2; i*i <= a; i++) {
                if (a%i == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                primes.add(a);
            }
        }
        return primes;
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> ds(n);
  for (int i=0; i<n; i++) cin >> ds[i];
  set<int> values;
  for (int d:ds) values.insert(d);
  cout << values.size() << endl;
}

Measured memory_bytes: 256
import sys

def get_maximum_profit():
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = min(v0, v1)
    max_profit = v1-v0

    for i in range(element_number-2):
        v = int(input())
        max_profit = max(max_profit, v-min_v)
        min_v = min(min_v, v)

    print(max_profit)

if __name__ == '__main__':
    get_maximum_profit()

Measured memory_bytes: 7700
import collections


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

F = [-1 for _ in range(N)]

que = collections.deque([0])
while que:
    target = que.popleft()
    for g in G[target]:
        if F[g] == -1:
            F[g] = target
            que.append(g)

res = [F[i] + 1 for i in range(N)]
res[0] = "Yes"
print("\n".join(map(str, res)))


Measured memory_bytes: 106392
#include <iostream>
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() 
{
    int i,n;
    cin>>n;
    long long h[n],dp[n];
    for(i=0;i<n;i++)
	{
	 cin>>h[i];
	}
	
	dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
	for(i=2;i<n;i++)
	{
	  dp[i]=min( (dp[i-1]+abs(h[i]-h[i-1])), (dp[i-2]+abs(h[i]-h[i-2]))  );     
	}
	cout<<dp[n-1];
	return 0;
    
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> d(K);
  vector<vector<int>> A(K, vector<int>(101));
  for(int i = 0; i < K; i++){
    cin >> d.at(i);
    for(int j = 0; j < d.at(i); j++){
      cin >> A.at(i).at(j);
    }
  }
 
  vector<bool> have_sw(N,false);
  
  for(int i = 0; i < K; i++){
    for(int j = 0; j < d.at(i); j++){
      have_sw.at(A.at(i).at(j)-1) = true;
    }
  }
   
  int count=0;
  
  for(int i = 0; i < N; i++){
    if(have_sw.at(i) == false){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3648
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      int c=sc.nextInt();
      System.out.println(Math.min(a+b,Math.min(a+c,b+c)));
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[SIZE];
int main(){
    RS(s+1);
    int n=LEN(s+1);
    REPP(c,'a','z'+1){
        int now=0;
        int mi=MOD,id;
        REPP(i,1,n+1){
            if(s[i]==c){
                if(now<mi){
                    mi=now;
                    id=i;
                }
                now++;
                if(mi<now&&id!=i){
                    printf("%d %d\n",id,i);
                    return 0;
                }
            }
            else now--;
        }
    }
    return 0*puts("-1 -1");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i< (n);++i)
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u) --a;
  else --b;
  cout << a << " " << b << endl;

}




Measured memory_bytes: 256
ali1, ali2, bob1, bob2 = map(int, input().split())

if ali1 <= bob1 <= ali2: 
    if ali1 <= bob2 <= ali2:
        print(bob2 -bob1)
    else:
        print(ali2 - bob1)
elif bob1 <= ali1 <=bob2:
    if bob1 <= ali2 <= bob2:
        print(ali2 - ali1)
    else:
        print(bob2 - ali1)
else:
    print(0)

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

using namespace std;

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

typedef long long ll;

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

 ll n,p;
  cin >> n >> p;
  
  map<ll,ll> mp;
  
  while(p%2==0){
   mp[2]++;
   p/=2; 
  }
  
  for(ll i=3;i*i<=p;i+=2){
   while(p%i==0){
   mp[i]++;
     p/=i;
   }
  }
  if(p!=1) mp[p]++;
  ll res=1;
  
  for(auto p:mp){
    while(p.second>=n){
     res*=p.first;
     p.second-=n;
    }
  }
  cout << res << endl;
  
 
}

Measured memory_bytes: 256
class SegmentTree():

    def __init__(self,init_val,n,func): #init_valは長さnの配列 O(2*n)
        self.ide_ele=0
        self.num=pow(2,n-1).bit_length() #n以上の最小の2のべき乗
        self.seg=[self.ide_ele]*2*self.num #セグメントツリー本体
        self.f=func

        for i in range(n):
            self.seg[i+self.num-1]=init_val[i] 
        
        for i in range(self.num-2,-1,-1):
            self.seg[i]=(self.seg[2*i+1])|(self.seg[2*i+2])        
        
      
    def update(self,k,x): #k番目の要素をxに変更する O(logN)
        k+=self.num-1
        self.seg[k]=x
        while k:
            k=(k-1)//2
            self.seg[k]=self.f(self.seg[2*k+1],self.seg[2*k+2])
    
    def query(self,p,q): #[p,q)のクエリに答える O(logN)
        if q<=p:
            return self.ide_ele

        p+=self.num-1
        q+=self.num-2
        res=self.ide_ele

        while q-p>1:

            if (p&1)==0:
                res=self.f(res,self.seg[p])

            if (q&1)==1:
                res=self.f(res,self.seg[q])
                q-=1
            p//=2
            q=(q-1)//2
        
        if p==q:
            res=self.f(res,self.seg[p])
        else:
            res=self.f(self.f(res,self.seg[p]),self.seg[q])
        
        return bin(res).count('1')

def main():
    n=int(input())
    s=input()

    dic={i:j for i,j in zip('abcdefghijklmnopqrstuvwxyz',[2**i for i in range(26)])}
    l=[0]*n

    for i in range(n):
        l[i]=dic[s[i]]
    
    def f(x,y):
        return x|y

    st=SegmentTree(l,n,f)
    
    q=int(input())
    for _ in range(q):
        a=list(map(str,input().split()))
        a[0]=int(a[0])

        if a[0]==1:
            a[1]=int(a[1])
            st.update(a[1]-1,dic[a[2]])
        
        else:
            a[1]=int(a[1])-1
            a[2]=int(a[2])
            print(st.query(a[1],a[2]))
            
if __name__=='__main__':
    main()



Measured memory_bytes: 31384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Main {
	int N,M;
	int[] X;
	TreeMap<Integer,HashMap<Integer,Integer>> s;

	public void solve() {
		N = nextInt();
		M = nextInt();

		X = new int[N];
		s = new TreeMap<Integer,HashMap<Integer,Integer>>();

		for(int i = 0;i < N;i++){
			X[i] = nextInt();
			int mod = X[i] % M;

			if(!s.containsKey(mod)){
				s.put(mod,new HashMap<Integer,Integer>());

			}
			s.get(mod).put(X[i], s.get(mod).containsKey(X[i]) ? s.get(mod).get(X[i]) + 1 : 1);
		}

		int ans = 0;

		for(int mod = 0;mod <= M / 2;mod++){
			int dom = (M - mod) % M;

			if(s.containsKey(mod) && s.containsKey(dom)){
				int S = 0;
				int T = 0;

				for(int key : s.get(mod).keySet()){
					S += s.get(mod).get(key);
				}

				for(int key : s.get(dom).keySet()){
					T += s.get(dom).get(key);
				}

				if(mod == dom){
					ans += S / 2;
				}else if(S < T){
					T -= S;
					for(int key : s.get(dom).keySet()){
						int cnt = s.get(dom).get(key);

						int min = Math.min(cnt, T);
						T -= min / 2 * 2;
						ans += min / 2;
					}
					ans += S;
				}else{
					S -= T;
					for(int key : s.get(mod).keySet()){
						int cnt = s.get(mod).get(key);

						int min = Math.min(cnt, S);
						S -= min / 2 * 2;
						ans += min / 2;
					}
					ans += T;
				}
			}else if(s.containsKey(mod)){
				for(int key : s.get(mod).keySet()){
					int cnt = s.get(mod).get(key);
					ans += cnt / 2;
				}
			}else if(s.containsKey(dom)){
				for(int key : s.get(dom).keySet()){
					int cnt = s.get(dom).get(key);
					ans += cnt / 2;
				}
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 61296
#include <cstdio>
#include <vector>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int N_MAX = 2000;

int N, K;
int K1, K2;
vector<int> G[N_MAX];

int sa;
int sb;

void dfs(int p, int v, int d) {
  if (d <= K1) sa++;
  if (d == K2) sb++;
  if (d < K2) {
    REP(i, G[v].size()) {
      int u = G[v][i];
      if (u != p) {
        dfs(v, u, d + 1);
      }
    }
  }
}

void solve() {
  K1 = K / 2;
  K2 = K - K1;
  int sx = 0;
  REP(v, N) {
    sa = 1;
    int sbx = 0;
    REP(i, G[v].size()) {
      sb = 0;
      dfs(v, G[v][i], 1);
      if (K1 < K2) sbx = max(sbx, sb);
    }
    sx = max(sx, sa + sbx);
  }
  printf("%d\n", N - sx);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N - 1) {
    int A, B;
    scanf("%d%d", &A, &B);
    G[A - 1].push_back(B - 1);
    G[B - 1].push_back(A - 1);
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

typedef priority_queue<pii, vector<pii>, greater<pii>> eat_;
typedef priority_queue<pii> not_eat_;

signed main()
{
    int N, K;
    cin >> N >> K;
    vpii sushi;
    sushi.resize(N);
    int t, d;
    REP(i, N)
    {
        cin >> t >> d;
        sushi[i] = make_pair(d, t);
    }

    //食べる候補を保持するqueue
    eat_ eat;
    not_eat_ not_eat;
    //食べる個数
    map<int, int> used_list;

    //おいしさ降順に並び替える
    sort(sushi.begin(), sushi.end(), greater<pii>());

    int var;
    int deli = 0;
    int ans = 0;
    // 美味しいものから貪欲に選ぶ。
    REP(i, N)
    {
        if (i < K)
        {
            deli = deli + sushi[i].first;
            if (++used_list[sushi[i].second] > 1) //2個以上あるやつは交換候補へ
                eat.push(sushi[i]);
        }
        else
        {
            if (used_list.find(sushi[i].second) == used_list.end()) //食べるリストにない種類を一個だけ交換候補へ。キーの存在で判断できる。
            {
                used_list[sushi[i].second] = 0;
                not_eat.push(sushi[i]);
            }
        }
    }

    //スコア計算
    var = 0;
    REP(i, 100001)
    {
        if (used_list[i] != 0)
            var++;
    }
    chmax(ans, deli + var * var);

    //種類が増えるように、食べるものリストのまずいやつと食べないものリストの美味しいやつを交換していく。
    while (true)
    {
        if (eat.empty() or not_eat.empty())
            break;
        deli -= eat.top().first;
        eat.pop();
        deli += not_eat.top().first;
        not_eat.pop();

        var++;
        chmax(ans, deli + var * var);
    }

    cout << ans << endl;
    //system("pause");
}

Measured memory_bytes: 8948
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

struct Info {
  LL price;
  LL store;
  bool operator<(const auto &right) const {
    return price < right.price;
  }
};


int main() {
  LL N, M; std::cin >> N >> M;
  std::vector<Info> info(N);
  for (int i = 0; i < N; ++i) std::cin >> info[i].price >> info[i].store;

  std::sort(info.begin(), info.end());

  LL price = 0;
  LL remain = M;
  for (int i = 0; i < N; ++i) {
    if (remain <= info[i].store) {
      price += info[i].price * remain;
      break;
    } else {
      price += info[i].price * info[i].store;
      remain -= info[i].store;
    }
  }

  std::cout << price << std::endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <thread>

template<typename T, int BUFSIZE>
class Stack {

// Ctor
public:
    Stack():
        pos(0)
    {
    };

// Methods
    public:

    void Push(T elem) {
        buf[pos++] = elem;
    }

    T Pop() {
        if (IsEnpty()) {
            std::cout << "Empty" << std::endl;
        }
        return buf[--pos];
    }

    bool IsEnpty() {
        if (pos < 0) {
            return true;
        }
        return false;
    }

    void Show() {
        for (int i = 0; i < pos - 1; i++) {
            std::cout << buf[i] << " ";
        }
        std::cout << buf[pos-1] << std::endl;
    }
    private:

//Attribute
public:
    T buf[BUFSIZE];
    int pos;

};


class Porland: public Stack<int, 100> {
// Ctor
public:
    Porland(): Stack() {
    }

// Methods

    void Calc(char* w) {
        if (*w == '*') {
            int rhs = Pop();
            int lhs = Pop();
            Push(lhs * rhs);
        }
        else if (*w == '/') {
            int rhs = Pop();
            int lhs = Pop();
            Push(lhs / rhs);
        }
        else if (*w == '+') {
            int rhs = Pop();
            int lhs = Pop();
            Push(lhs + rhs);
        }
        else if (*w == '-') {
            int rhs = Pop();
            int lhs = Pop();
            Push(lhs - rhs);
        }
        else{
            Push(std::atoi(w));
        }
    }

// Attribute

};

int main(int argc, char const* argv[])
{
    char c[100];
    int pos = 0;
    Porland st;

    std::string str;
    std::stringstream ss;
    std::getline(std::cin, str);
    ss << str;
    char w[100];
    while(ss.getline(w, 100,  ' ')) {
        st.Calc(w);
    }
    st.Show();
    return 0;
}

Measured memory_bytes: 3200
A, B, C, K = map(int, input().split(" "))

ans = 0
if K - A >= 0:
    ans += A
    K -= A
elif K < A:
    ans += K
    K = 0

if K - B >= 0:
    K -= B
elif K < B:
    K = 0

if K > 0:
    ans -= K

print(ans)

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



const int MAX_C = 100;
long long Com[MAX_C][MAX_C];
void COMinit() {
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i) Com[0][i] = 0;
    for (int i = 1; i < MAX_C; ++i) {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j) {
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]);
        }
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return Com[n][k];
}



int main(){
    ll n,a,b; cin>>n>>a>>b;
    vector<ll> w(n), v(n);
    rep(i,n) cin>>w[i];
    
    sort(w.begin(), w.end(), greater<ll>());
    v[0] = w[0]; // w: もと、 v: 累積和
    rep(i,n-1) v[i+1]+=v[i]+w[i+1];
    double res=(double)v[a-1]/a;
    cout<<fixed<<setprecision(20)<<res<<endl;

    ll cnt=1, left=0; //cnt: w[a-1] ... w[a+cnt-2]まで同じ数, left: w[a-2]から左へleft個同じ数
    for(ll i = a; i < n; i++){
        if(w[i]==w[i-1]) cnt++;
        else break;
    }
    for(ll i=a-2; i>=0; i--){
        if(w[i]==w[i+1]) left++;
        else break;
    }
    ll com=0;
    COMinit();
    if(w[a-1]!=w[0]){
        com = COM(cnt+left, left+1);
    }else{
        for(ll i = left+1; i<=min(left+b-a+1ll, cnt+left); i++){
            com+=COM(cnt+left, i);
        }
    }
    cout<<com<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<complex>
#include<algorithm>
#include<vector>
using namespace std;

typedef complex<double> P;

#define EPS (1e-10)

#define EQ(a,b) (abs((a)-(b)) < EPS)

#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )


double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

bool inTriangle(P v1,P v2,P v3,P v){
	if(cross(v2-v1,v-v1)<-EPS&&cross(v3-v2,v-v2)<-EPS&&cross(v1-v3,v-v3)<-EPS)return true;
	else if(cross(v2-v1,v-v1)>EPS&&cross(v3-v2,v-v2)>EPS&&cross(v1-v3,v-v3)>EPS)return true;
	return false;
}

P data[4];
bool input(){
	char c;
	
	for(int i=0;i<4;i++){
		if(!(cin>>data[i].real()))return false;
		cin>>c;
		cin>>data[i].imag();
		if(i<3)cin>>c;
	}
	return true;
}
int main(){
	while(input()){
		
		for(int i=0;i<4;i++){
			vector<P>v;
			for(int j=0;j<4;j++){
				if(j!=i)v.push_back(data[j]);
			}
			if(inTriangle(v[0],v[1],v[2],data[i])){
				cout<<"NO"<<endl;
				goto fail;
			}
		}
		cout<<"YES"<<endl;
		fail:;
	}
	
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int n = N.size();
	Int dp[110][5][2] = { 0 };
	dp[0][0][1] = 1;
	for (int i = 0; i < n; ++i) {
		int x = N[i] - '0';
		for (int j = 0; j < 10; ++j) {
			for (int k = 0; k <= K; ++k) {
				if (j == 0) {
					dp[i+1][k][0] += dp[i][k][0];
					if (j < x) {
						dp[i+1][k][0] += dp[i][k][1];
					}
					if (j == x) {
						dp[i+1][k][1] += dp[i][k][1];
					}
				} else {
					dp[i+1][k+1][0] += dp[i][k][0];
					if (j < x) {
						dp[i+1][k+1][0] += dp[i][k][1];
					}
					if (j == x) {
						dp[i+1][k+1][1] += dp[i][k][1];
					}
				}
			}
		}
	}
	Int ans = dp[n][K][0] + dp[n][K][1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N,M = map(int, raw_input().split())

A=[]
for i in range(N):
	A.append(map(str, raw_input().split()))


score=0
for i in range(M):
	point_tmp=0
	for j in range(N):
		if str(i+1) in A[j][1:]:
			point_tmp+=1
	if point_tmp==N:
		score+=1

print score

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

typedef long long LL;

const int N = 100010;

LL a[N], b[N];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n+1; i++)
        scanf("%lld", &a[i]);
    for(int i=0; i<n; i++)
        scanf("%lld", &b[i]);
    LL ans = 0;
    // a[n-1] += a[n];
    for(int i=0; i<n; i++)
    {
        if(a[i] >= b[i])
        {
            ans += b[i];
            b[i] = 0;
            continue;
        }
        else if(a[i] + a[i+1] >= b[i])
        {
            ans += b[i];
            b[i] -= a[i];
            a[i+1] -= b[i];
        }
        else if(a[i] + a[i+1] < b[i])
        {
            ans += a[i] + a[i+1];
            b[i] -= a[i];
            b[i] -= a[i+1];
            a[i] = a[i+1] = 0;
        }
    }
    printf("%lld\n", ans);
    

    


    return 0;
}

Measured memory_bytes: 1792
n=int(input())
l=sorted([int(input())for i in range(n)],reverse=1)
if n%2:
    print(max(2*sum(l[:n//2-1])+l[n//2-1]+l[n//2]-2*sum(l[n//2+1:]),2*sum(l[:n//2])-sum(l[n//2:n//2+2])-2*sum(l[n//2+2:])))
else:
    o=-1
    print(2*sum(l[:n//2-1])+l[n//2+o]-l[n//2+1+o]-2*sum(l[o+n//2+2:]))

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

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

long long ans;

void solve(long long a, long long b)
{
	if (a % b == 0) return ans += (a << 1) - b, void();
	ans += a / b * b * 2;
	solve(b, a % b);
}

int main()
{
	long long n, x;
	scanf("%lld%lld", &n, &x);
	ans = n;
	if (x < n - x) x = n - x;
	solve(x, n - x);
	printf("%lld\n", ans);
	
	return 0;
}



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

using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i];
  }

  int total = 0;
  int before = -9999;
  for (int i = 0; i < n; i++) {
    int eat = a[i];
    total += b[eat - 1];
    if (before + 1 == eat) total += c[before - 1];
    before = eat;
  }

  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 110

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}


int dpf(int i, int t, int k)
{

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	char ch;
	cin >> ch;
	char ans;
	if(ch == 'A')
		ans = 'T';
	else if(ch=='T')
		ans = 'A';
	else if(ch == 'C')
		ans = 'G';
	else
		ans = 'C';
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc155/tasks/abc155_c
//C++のmapはordered mapと言われ、キーがソートされた形で管理される
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
 
int N;
string S[200000];
map<string,int> m;
 
vector<string> ans;
 
void solve(){
	int max_counter = 0;
	for(int i=0;i<N;i++){
		m[S[i]]++;//mapにないやつは勝手に0で初期化されていると思っていい
		max_counter = max(m[S[i]],max_counter);
	}
	for(auto a : m){
		if(a.second==max_counter){
			ans.push_back(a.first);
		}
	}
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> S[i];
 
	solve();

	for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 28404
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N = 2e6+200;
template <class Ruby> inline void read(Ruby &x)
{
	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
int a[N], b[N], n, val[N];
int main()
{
	read(n);
	for(R int i=1; i<=n; i++)read(a[i]);
	for(R int i=1; i<=n; i++)read(b[i]);
	for(R int i=1; i<=n; i++)val[i]=i;
	int ans1=0, ans2=0;
	for(R int i=1;  ; i++)
	{
		int flag=0;
		for(R int j=1; j<=n; j++)
		{
			if(val[j]!=a[j]){flag=1;break;
			}
		}
		if(!flag)ans1=i;
		flag=0;
		for(R int j=1; j<=n; j++)
		{
			if(val[j]!=b[j]){flag=1;break;
			}
		}
		if(!flag)ans2=i;
		next_permutation(val+1, val+1+n);
		if(ans1  && ans2)break;
	}
	cout<<abs(ans1-ans2);
	return 0;
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a>b){
		printf("a > b\n");	
	}else if(a<b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
char s[10];
int main()
{
    cin>>s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    for(int i=43;i<=45;i+=2)
        for(int j=43;j<=45;j+=2)
            for(int k=43;k<=45;k+=2)
            {
                int ans=a;
                if(i==43) ans+=b;
                else ans-=b;
                if(j==43) ans+=c;
                else ans-=c;
                if(k==43) ans+=d;
                else ans-=d;
                if(ans==7)
                {
                    cout<<a<<char(i)<<b<<char(j)<<c<<char(k)<<d<<"=7"<<endl;//只要输出一种
                    return 0;
                }
            }
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

#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__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll inf=1e18;

int n;
ll k;
pll tab[nax];

ll mini[nax];

int main()
{
	scanf("%d%lld", &n, &k);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld%lld", &tab[i].first, &tab[i].second);
	}
	for (int i=1; i<nax; i++)
		mini[i]=inf;
	ll s=0;
	for (int i=1; i<=n; i++)
	{
		for (int j=s; j>=0; j--)
		{
			mini[j+tab[i].second]=min(mini[j+tab[i].second], mini[j]+tab[i].first);
		}
		s+=tab[i].second;
	}
	ll wyn=s;
	while(mini[wyn]>k)
		wyn--;
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 8448