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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const int MAXN = 2000;
int n;
ll x[MAXN];
ll y[MAXN];
ll dx[] = {0, 0, 1, -1};
ll dy[] = {1, -1, 0, 0};
char ch[] = {'U', 'D', 'R', 'L'};
const ll INF = 1e18;


int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i];
	int fl = 0;
	if ((x[0] + y[0]) % 2 == 0) {
		fl = 1;
		for (int i = 0; i < n; ++i)
			--x[i];
	}
	for (int i = 0; i < n; ++i) {
		if ((x[i] + y[i]) % 2 == 0) {
			cout << -1 << "\n";
			return 0;
		}
	}
	vector<ll> vv;
	for (int i = 0; i <= 31; ++i)
		vv.push_back(1ll << i);
	if (fl)
		vv.push_back(1);
	reverse(vv.begin(), vv.end());
	cout << vv.size() << "\n";
	for (ll x: vv)
		cout << x << " ";
	cout << "\n";
	for (int i = 0; i < n; ++i) {
		string s;
		if (fl)
			s += "R";
		for (int j = 31; j >= 0; --j) {
			int bst = -1;
			ll now = INF;
			for (int k = 0; k < 4; ++k) {
				ll cur = abs(x[i] - dx[k] * (1ll << j)) + abs(y[i] - dy[k] * (1ll << j));
				if (cur < now)
					now = cur, bst = k;
			}
			x[i] -= dx[bst] * (1ll << j);
			y[i] -= dy[bst] * (1ll << j);
			s += ch[bst];
		}
		cout << s << "\n";
	}
	return 0;
}


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

int main()
{
	int i, j, n[5];
	string s, letter[2] = {" ", "*"};
	stringstream ss;
	bool f = false;
	while (cin>>s) {
		if (f) cout<<endl;
		f = true;
		ss.str("");
		ss<<setw(5)<<setfill('0')<<right<<s;
		for (i = 0; i < 5; i++) n[i] = ss.str()[i]-'0';
		s = "";
		for (j = 0; j < 2; j++) {
			for (i = 0; i < 5; i++) {
				if (n[i]>=5) s += letter[j];
				else s += letter[(j+1)&1];
			}
			s += "\n";
		}
		for (i = 0; i < 5; i++) s += "=";
		s += "\n";
		for (j = 0; j < 5; j++) {
			for (i = 0; i < 5; i++) {
				if (n[i]%5==j) s += letter[0];
				else s += letter[1];
			}
			s += "\n";
		}
		cout<<s;
	}
	return 0;
}

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


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


  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum=0;
  rep(i,n) sum+=a[i];
  ll csum=0;
  ll ans=LLONG_MAX;
  rep(i,n-1){
    csum += a[i];
    //    cout << csum << endl;
    ans = min(ans, abs(sum-csum*2));
    //    cout << ans << endl;
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i+=1)
using namespace std;
 
int main() {
int N,D;
cin>>N>>D;
int A=D*2+1;
if(N%A==0)
cout<<N/A<<endl;
else if(N<A)
cout<<"1"<<endl;
else {
cout<<N/A+1<<endl;
}
}

Measured memory_bytes: 256
import numpy as np
N, *L = map(int, open(0).read().split())
A = np.array(L[:N])
B = np.array(L[N:2*N])
C = np.array(L[2*N:])
A.sort()
B.sort()
C.sort()
binf = np.zeros(N)
j = 0
binf = np.searchsorted(A,B)
bs = np.cumsum(binf)
bs = np.concatenate([[0],bs])
cinf = np.searchsorted(B,C)
ans = np.sum(bs[cinf])
print(ans)

Measured memory_bytes: 47280
#include<stdio.h>

int main(void){
  int A, B;
  scanf("%d %d", &A, &B);
  if(A == B) {
    printf("%d\n", 2*A);
    return 0;
  }
  if(A>B){
    printf("%d\n", 2*A-1);
  }
  else{
    printf("%d\n", 2*B-1);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <cmath>

int main()
{
    int N, A, B, C;
    scanf(" %d %d %d %d", &N, &A, &B, &C);
    int l[N];
    for(int i=0; i<N; i++) scanf(" %d", &l[i]);

    int max_loop = pow(4, N), min = 1000 * N;
    int group[N], count[4];
    for(int i=0; i<max_loop; i++){
        int i_cpy = i;
        for(int j=0; j<N; j++){
            group[j] = i_cpy % 4;
            i_cpy /= 4;
            //std::cout << group[j] << " ";
        }
        //std::cout << std::endl;
        for(int j=0; j<4; j++) count[j] = 0;
        int merge = 0;
        for(int j=0; j<N; j++){
            if(group[j] != 0 && count[group[j]] != 0) merge++;
            count[group[j]] += l[j];
        }
        if(count[1]==0 || count[2]==0 || count[3]==0) continue;
        int mp = abs(count[1] - A) + abs(count[2] - B) + abs(count[3] - C) + merge*10;
        if(mp < min) min = mp;
    }
    std::cout << min << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin >> S;
    string T; cin>>T;
    bool can=false;
    for(int i=0;i<26;i++){
        char a='a'+i;
        string tmp=S;
        tmp+=a;
        if(tmp==T){
            can=true;
        }
    }
    if(can){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef int64_t ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<vector<int>> ab(n, vector<int>());

  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }

  vector<int> dist_f(n, -1);
  vector<int> dist_s(n, -1);

  dist_f[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : ab[v]) {
      if (dist_f[nv] != -1) continue;
      dist_f[nv] = dist_f[v] + 1;
      que.push(nv);
    }
  }

  dist_s[n-1] = 0;
  que.push(n-1);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : ab[v]) {
      if (dist_s[nv] != -1) continue;
      dist_s[nv] = dist_s[v] + 1;
      que.push(nv);
    }
  }

  int f = 0;
  int s = 0;
  rep(i, n) {
    if (dist_f[i] <= dist_s[i]) f++;
    else s++;
  }

  if (f > s) puts("Fennec");
  else puts("Snuke");

  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,p;
  cin>>n>>p;
  string s;
  cin>>s;
  if(p==2){
    ll ans=0;
    rep(i,0,n){
      if((s[i]-'0')%2==0){
        ans+=i+1;
      }
    }
    cout<<ans<<endl;
  }
  else if(p==5){
    ll ans=0;
    rep(i,0,n){
      if((s[i]-'0')%5==0){
        ans+=i+1;
      }
    }
    cout<<ans<<endl;
  }
  else{
    int a[n+1];
    a[0]=0;
    int cur=1;
    rep(i,0,n){
      a[i+1]=(a[i]+cur*(s[n-1-i]-'0'))%p;
      cur=cur*10%p;
    }
    ll b[p];
    rep(i,0,p){
      b[i]=0;
    }
    rep(i,0,n+1){
      b[a[i]]++;
    }
    ll ans=0;
    rep(i,0,p){
      ans+=b[i]*(b[i]-1)/2;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N; cin>>N;
  vector<vector<int> > mat (N,vector<int>(N,0));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cin>>mat[i][j];
    }
  }
  vector<int> DP ((1<<N)+1,0);
  DP[0] = 1;
  for (int s = 0; s < 1<<N; s++)
  {
    int i = __builtin_popcount(s);
    for (int j = 0; j < N; j++)
    {
      if(s>>j & 1 && mat[i-1][j] == 1)
      {
        DP[s] += DP[s^(1<<j)];
        //集合の遷移先では冪集合の要素を示すフラグが立ち、かつ相性のフラグが立っている
        //その場合遷移先に含まれていない集合の数え上げ個数を足す。
        DP[s]%=MOD;
      }
    }
    
  }
  cout<<DP[(1<<N)-1]<<endl;
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 16768
import itertools

# どっかのサイトから
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
    
A, B = map(int, input().split())
    
com_div = sorted(list(set(make_divisors(A)) & set(make_divisors(B))))

# ふるいにかける
limit = max(com_div)**0.5 + 1

primes = []

for i in itertools.count(1):
    if i >= len(com_div):
        break
    sosuu = com_div[i]
    if sosuu > limit:
        break
    com_div = [j for j in com_div if (j % sosuu != 0 or j == sosuu)]

print(len(com_div))
    

Measured memory_bytes: 40432
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, j, n, m;
	int lock = 0, f;
	char id[512][16];
	char card[512][16];
	char mes[][16] = {"Opened by", "Closed by", "Unknown"};
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s", &id[i]);
	}
	
	scanf("%d", &m);
	for (i = 0; i < m; i++){
		scanf("%s", &card[i]);
	}
	
	for (i = 0; i < m; i++){
		f = 0;
		
		for (j = 0; j < n; j++){
			if (strcmp(card[i], id[j]) == 0){
				printf("%s %s\n", mes[lock], card[i]);
				f = 1;
				lock = !lock;
				break;
			}
		}
		
		if (f == 0){
			printf("%s %s\n", mes[2], card[i]);
		}
	}
	
	return (0);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b, x;
	cin >> a >> b >> x;
	if(a>x) puts("NO");
	else if(a+b<x) puts("NO");
	else puts("YES");
	return;
}

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


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (x, y) = input_tuple();
    println!("{}", x + y / 2);
}


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


int SymbolToPriority(char symbol){
    int priority = 0;
    switch(symbol){
        case 'S':
            priority = 0;
            break;
        case 'H':
            priority = 1;
            break;
        case 'C':
            priority = 2;
            break;
        case 'D':
            priority = 3;
            break;
    }
    return priority;
}


char PriorityToSymbol(int priority){
    char symbol = ' ';
    switch(priority){
        case 0:
            symbol = 'S';
            break;
        case 1:
            symbol = 'H';
            break;
        case 2:
            symbol = 'C';
            break;
        case 3:
            symbol = 'D';
            break;
    }
    return symbol;
}


int main(){
    //入力
    int n;
    cin >> n;
    vector<pair<char, int> > my_card(n);
    for(int i = 0; i < n; i++){
        cin >> my_card[i].first >> my_card[i].second;
    }
    
    //所持状況をboolで管理する
    //所持していたらtrue，そうでなければfalse
    bool card_status_list[4][13];
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            card_status_list[i][j] = false;
        }
    }
    
    //カードを所持していたらその場所をtrueにする
    int symbol_position, value_position;
    for(int i = 0; i < n; i++){
        symbol_position = SymbolToPriority(my_card[i].first);
        value_position = my_card[i].second-1; //カードの数字は1から始まるが，配列は0から始まるので-1して合わせる
        card_status_list[symbol_position][value_position] = true;
    }
    
    //出力
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(!card_status_list[i][j]) cout << PriorityToSymbol(i) << ' ' << j+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3044
import numpy as np
n=int(input())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
x=np.argsort(b)
g=0
f=0
for i in range(n):
    g+=a[x[i]]
    if b[x[i]]<g:
        f+=1
if f>0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 29680
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var h = hw[0];
        var w = hw[1];

        char[][] a = new char[h][];
        for (int i = 0; i < h; i++)
        {
            a[i] = Console.ReadLine().ToCharArray();
        }

        bool[] delete1 = new bool[h];
        for (int i = 0; i < h; i++)
        {
            delete1[i] = false;
        }

        bool[] delete2 = new bool[w];
        for (int i = 0; i < w; i++)
        {
            delete2[i] = false;
        }

        for (int i = 0; i < h; i++)
        {
            var flag = true;
            for (int k = 0; k < w; k++)
            {
                if (a[i][k] == '#') flag = false;
            }
            if (flag) delete1[i] = true;
        }

        for (int i = 0; i < w; i++)
        {
            var flag = true;
            for (int k = 0; k < h; k++)
            {
                if (a[k][i] == '#') flag = false;
            }
            if (flag) delete2[i] = true;
        }

        var ans = new List<List<char>>();
        for (int i = 0; i < h; i++)
        {
            ans.Add(new List<char>());
        }

        for (int i = 0; i < h; i++)
        {
            if (!delete1[i])
            {
                for (int k = 0; k < w; k++)
                {
                    if (!delete2[k])
                    {
                        ans[i].Add(a[i][k]);
                    }
                }
            }
        }

        // 出力
        for (int i = 0; i < ans.Count; i++)
        {
            if (ans[i].Count == 0) continue;
            for (int k = 0; k < ans[i].Count; k++)
            {
                Console.Write(ans[i][k]);
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define INF 1000000000
using namespace std;
int main(){
  vector<int> a(5);
  for(int i=0;i<5;i++)cin >> a[i];
  vector<int> P  = {0,1,2,3,4};
  int ans=INF;
  do{
    int sum=0;
    for(int i=0;i<5;i++){
      while(sum%10!=0)sum++;
      sum+=a[P[i]];
    }
    ans=min(ans,sum);
  }while(next_permutation(P.begin(),P.end()));
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<set>
#include<string>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
typedef unsigned long long int ll;

int main()
{

    	int n,k;
    	cin>>n>>k;
    	int ans=0;
    	int freq[n]={0};

        while(k--){
            int a;
        	cin>>a;
        	int arr[a];
        	for(int i=0;i<a;i++){
        		cin>>arr[i];
        		freq[arr[i]-1]++;
        	}
        }

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

        cout<<ans<<endl;

     
	return 0;
    }
 



Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int N = 200005;
const int M = 1000 * 1000 * 1000 + 7;
using namespace std;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
ll arr[200002];
int main(){
	
	int n;cin >> n;
	ll sum = 0;
	for(int i = 0 ; i < n ; i++){cin >> arr[i];sum += arr[i];}
	ll temp = 0, ans = 1e18;
	for(int i = 0 ; i < n - 1; i++){
		temp += arr[i];
		ans = min(ans , abs ( (sum - temp) - temp));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; long long k; cin >> s >> k;
  REP(i, k) {
    if (s[i] != '1') {
      cout << s[i] << "\n";
      return 0;
    }
  }
  cout << 1 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
   int x, y, a, b, r, sum;
   scanf("%d %d", &x, &y);
   sum = x + y + 2;
   a = x; b = y;
   if (x < y) { b = x; a = y; }
   r = a % b;
   while ( r != 0) {
      a = b;
      b = r;
      r = a % b;
   }
   sum -= ( b + 1);
   printf("%d\n", sum);
   return 0;
}

Measured memory_bytes: 1828
# 入力
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

# 処理
D = {}
for i in range(N):
  if s[i] in D.keys():  # 辞書Dに文字列s[i]が含まれる
    D[s[i]] += 1
  else:                 # 辞書Dに文字列s[i]が含まれない
    D[s[i]] = 1
    
for i in range(M):
  if t[i] in D.keys():  # 辞書Dに文字列t[i]が含まれる
    D[t[i]] -= 1
  
ans = 0  # 答え
for v in D.values():  # 辞書Dの値の集合を全て調べる
  ans = max(ans, v)

# 出力
print(ans)

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

int main()
{
    int x, y;
    cin >> x >> y;

    vector<int> appleNumVec;
    for (int i = 0; i < 3; ++i)
    {
        int input;
        cin >> input;

        appleNumVec.push_back(input);
    }

    vector<deque<int>> appleTasteVec(3);

    for (int i = 0; i < 3; ++i)
    {
        int appleNum = appleNumVec.at(i);

        for (int j = 0; j < appleNum; ++j)
        {
            int input;
            cin >> input;

            appleTasteVec.at(i).push_back(input);
        }
    }

    for (int i = 0; i < 3; ++i)
    {
        sort(appleTasteVec.at(i).begin(), appleTasteVec.at(i).end(), greater<int>());
    }

    vector<int> chosenAppleNum(3, 0);
    int chosenAppleNumSum = 0;

    long long tasteSum = 0;

    for (int i = 0; i < (x + y); ++i)
    {
        int maxTasteAppleIndex = 0, maxTaste = 0;

        for (int j = 0; j < 3; ++j)
        {
            bool isValid = true;

            if (appleTasteVec.at(j).size() == 0)
            {
                isValid = false;
            }

            if (j == 0 && chosenAppleNum.at(0) >= x)
            {
                isValid = false;
            }

            if (j == 1 && chosenAppleNum.at(1) >= y)
            {
                isValid = false;
            }

            if (isValid)
            {
                if (maxTaste < appleTasteVec.at(j).at(0))
                {
                    maxTasteAppleIndex = j;
                    maxTaste = appleTasteVec.at(j).at(0);
                }
            }
        }

        tasteSum += appleTasteVec.at(maxTasteAppleIndex).at(0);
        appleTasteVec.at(maxTasteAppleIndex).pop_front();
        ++chosenAppleNum.at(maxTasteAppleIndex);
    }

    cout << tasteSum << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
int mod = 1e9 + 7;

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

    string S;
    cin >> S;

    ll dp[S.size() + 1][4];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    rep(i, 0, S.size()) {
        rep(j, 0, 4) {
            if(S[i] != '?') {
                (dp[i + 1][j] += dp[i][j]) %= mod;
            } else {
                (dp[i + 1][j] += (dp[i][j] * 3) % mod) %= mod;
            }
        }
        if(S[i] == 'A' or S[i] == '?') (dp[i + 1][1] += dp[i][0]) %= mod;
        if(S[i] == 'B' or S[i] == '?') (dp[i + 1][2] += dp[i][1]) %= mod;
        if(S[i] == 'C' or S[i] == '?') (dp[i + 1][3] += dp[i][2]) %= mod;
    }

    cout << dp[S.size()][3] << endl;

}


Measured memory_bytes: 3664
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;

int calc(int x){
    if(x % 2) return 0;

    int cnt = 0;
    while(x % 2 == 0){
        cnt++;
        x /= 2;
    }
    return cnt;
}

int solve(){
    cin >> n;
    int cnt = 0;
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        cnt += calc(x);
    }
    return cnt;
}

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

    cout << solve() << "\n";   
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n1,n2,i,d,line[1000],mv[1000];
    for(;d=0,scanf("%d %d",&n1,&n2),n2;){
        for(i=0;i<n1;i++)
            scanf("%d",&line[i]);
        for(i=0;i<n2;i++)
            scanf("%d",&mv[i]);
        for(i=0;i<n2;i++){
            d+=mv[i];
            if(d >= n1-1)
                break;
            d+=line[d];
            if(d >= n1-1)
                break;
        }
        printf("%d\n",i+1);
    }
    return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define mi(N) int N; cin >> N;
#define ms(s) string s; cin >> s;
#define md(d) double d; cin >> d;
#define mv(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 998244353

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

signed main() {
	mi(n);
	mv(v, n);
	mv(c, n);
	int ans = 0;
	rep(n)ans += max(0, v[i] - c[i]);
	say((ans));
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        while(true){
            int hight = sc.nextInt();
            int width = sc.nextInt();
            if(hight==0 && width==0){
                break;
            }
            for(int i=0;i<hight;i++){
                String draw = "";
                for(int j=0;j<width;j++){
                    draw += "#";
                }
                System.out.println(draw);
            }
            System.out.println("");
        }
        sc.close();
    }
}


Measured memory_bytes: 55516
#include<iostream>

int main(){
    
    size_t n, k, cnt = 0;

    std::cin >> n >> k;

    for(size_t i = 0; i < n; i++){
        size_t h;
        std::cin >> h;
        if(h >= k) cnt++;
    }

    std::cout << cnt << std::endl;
    
    return 0;
}


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

using namespace std;

int g1[120],g2[120];
int i,n,s;

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int N = 2010;
const int MOD = 1e9 + 7;
int f[N][N], ans;
int main()
{
    cin >> n >> k;
    f[0][n + 1] = 1;
    for (int i = 1; i < k; ++ i)
        for (int j = n + 1, s = 0; j > 1; s = (s + f[i - 1][j --]) % MOD)
            f[i][j] = (1ll * f[i - 1][j] * max(min(1, n - j - i + 2), 0) + s) % MOD;
    for (int i = 2; i <= n + 1; ++ i) ans = (ans + f[k - 1][i]) % MOD;
    for (int i = 1; i < n - k; ++ i) ans = (ans + ans) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 16000
n, m, x, y = map(int, input().split())
xn = list(map(int, input().split()))
ym = list(map(int, input().split()))

xn.append(x)
ym.append(y)

xn.sort()
ym.sort()

if xn[-1] >= ym[0]:
    print("War")
else:
    print("No War") 

Measured memory_bytes: 3064
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> {
                    return sc.nextInt();
                })
                .collect(Collectors.toList());
        int avg = (int) Math.round(list.stream().mapToInt(m -> m).average().getAsDouble());
        System.out.println(sum(list, avg));
    }
    private static int sum(List<Integer> list, int num) {
        return list.stream().mapToInt(m -> (int) Math.pow(m - num, 2)).sum();
    }
}


Measured memory_bytes: 29012
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <functional>
#include <limits>
#include <vector>
#include <list>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <complex>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL modn = 1e9+7;
const int maxn = 1e5+9;
int arr[maxn];

int main()
{
    // ios::sync_with_stdio(false); cin.tie(0);
    int n, z, w;
    while(scanf("%d %d %d", &n, &z, &w)!=EOF) {
        for(int i=0; i<n; i++)
            scanf("%d", arr+i);
        if(n>1) printf("%d\n", max(abs(arr[n-1]-w), abs(arr[n-1]-arr[n-2])));
        else printf("%d\n", abs(arr[n-1]-w));
    }
    return 0;
}


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

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


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

	int n;
	cin>>n;
	for(int i=1;i<10;i++)
	{
		if(n%i==0)
		{
			int temp=n/i;
			if(temp<10) return cout<<"Yes",0;
		}
	}
	
	cout<<"No";
			
	cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}


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

int sum(int N, char X[]) {
	long j, k, tmp=0, ans = 0;
	for (j = 0; j < N; j++) {
		ans += X[j] * X[j];
	}

	for (j = 1; j <= 100; j++) {
		tmp = 0;
		for (k = 0; k < N; k++) {
			tmp += (X[k] - j)*(X[k] - j);
		}
		if (tmp < ans) {
			ans = tmp;
		}
	}
	return ans;
}

int main() {
	long N, i, ans;
	char X[100];
	scanf("%ld", &N);
	for (i = 0; i < N; i++) {
		scanf("%hhd", &X[i]);
	}

	ans = sum(N, X);
	printf("%ld", ans);

	return 0;
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=map(parseBigInt,split(readline()))
    l=a[1]
    for i in a
        l=lcm(l,i)
    end
    ans=0
    for i in a
        ans+=l÷i
    end
    println(ans%(10^9+7))
end
main()

Measured memory_bytes: 154764
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=(n)-1;i>j-1;i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,d,m=0,ans=1;
    vector<lli> vec;
    map<lli,lli> mp;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>d;
        vec.push_back(d);
        m=max(m,d);
        mp[d]++;
    }
    if(mp[0]!=1||vec[0]!=0){
        cout<<0<<endl;
    }
    else{
        rep(i,0,m+1){
            if(mp[i]!=0){
                if(i>1){
//                    cout<<"きてる？"<<endl;
                    rep(j,0,mp[i]){
                        ans*=mp[i-1];
                        ans%=M;
                    }
                }
            }
            else{
                cout<<0<<endl;
                exit(0);
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 10316
N = int(input())
a = list(map(int, input().split()))

x, y, z = 0, 0, 0
for v in a:
    if v % 4 == 0:
        x += 1
    elif v % 2 == 0:
        y += 1
    else:
        z += 1

if x < z:
    if (z - x == 1) & (y == 0):
        print('Yes')
    else:
        print('No')
else:
    print('Yes')



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

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

    cout << a*b;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
  
    string s,t ;
    cin>>s>>t ;

   if(s==t.substr(0,s.size()) && (s.size()+1)==t.size())
    cout << "Yes" << endl ;
   else 
    cout << "No" << endl ;
    
   
  return 0 ;
}

Measured memory_bytes: 3632
import sys
from collections import deque
from itertools import *

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X,Y = LI()

for i in range(X+1):
    for q in range(X-i+1):
        if i*2 + q*4 == Y and i+q == X:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 67672
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
K = int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
             a = gcd(i,j,k)
             ans += a
print(ans)

Measured memory_bytes: 74884
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        sc.close();

        int times = (int)(T + 0.5) / A;
        System.out.println(times * B);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k;
  cin>>k;
  ll m=7;
  int ans=1;
  bool ok=true;
  while(m%k!=0){
    if(ans>k){
      ok=false;
      break;
    }
    m=10*m+7;
    m%=k;
    ++ans;
  }
  cout<<(ok ? ans : -1)<<'\n';
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
using ll = long long;
using namespace std;
int gcd(int x,int y){
    if(y==0){
        return x;
    }else{
        return gcd(y,x%y);
    }
}
int lcm(int x,int y){
    return x/gcd(x,y)*y;
}
int main(){
    int a,b;
    cin >> a >> b;
    int c=a-b+1;
    if(c<0){
        cout<<0<<endl;
    }else{
        cout<<c<<endl;
    }
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n;
         cin>>n;
         string s;
         cin>>s;
         ll c1=0;
         ll c2=0;
         ll c3=0;
         vector<ll>v1,v2;
         for(int i=0;i<s.size();i++)
         {
            if(s[i]=='B')
            {
                  c1++;
                  v1.pb(i);
            }
            else if(s[i]=='R')
            {
                  c2++;
                  v2.pb(i);
            }
            else
            {
                 c3++;
            }
         }
         ll ans = c1*c2*c3*1LL;
         ll can = 0;
         for(auto it : v1)
         {
            for(auto it1 : v2)
            {
               if(it>it1)
               {
                    ll p1 = it-it1;
                    if(p1%2==0 && s[it1+p1/2]=='G')
                        can++;
                    if(it+p1<s.size() && s[it+p1]=='G')
                        can++;
                    if(it1-p1>=0 && s[it1-p1]=='G')
                        can++;
               }
               else
               {
                   ll p1 = it1-it;
                   if(p1%2==0 && s[it+p1/2]=='G')
                        can++;
                    if(it1+p1<s.size() && s[it1+p1]=='G')
                        can++;
                    if(it-p1>=0 && s[it-p1]=='G')
                        can++;
               }
            }
         }
         // cout<<can<<endl;
         ans-=can;
         cout<<ans<<endl;

      }
      






}



























Measured memory_bytes: 3672
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string S;
	cin >> S;
	bool a, b, c;
	a = b = c = false;
	rep(i, S.size()) {
		if (S[i] == 'a')a = true;
		else if (S[i] == 'b')b = true;
		else c = true;
	}
	if (a && b && c)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
l, r = map(int, input().split())
d = (r -l)%2019
if r -l >=2018:
    print(0)
    exit(0)
ans = 2018
for i in range(l, l+d):
    for j in range(i+1, l+d+1):
        if (i*j)%2019 < ans:
            ans =(i*j)%2019
print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;


vector<int> ans_vec;

void isrunrun_naka(vi &v, int &K, int keta, int dketa, int p)
{
    if (keta == dketa)
    {
        if (--K == 0)
        {
            ans_vec = v;
        }
        return;
    }

    if (p > 0)
    {
        v[dketa] = p - 1;
        isrunrun_naka(v, K, keta, dketa + 1, p - 1);
    }
    {
        v[dketa] = p;
        isrunrun_naka(v, K, keta, dketa + 1, p);
    }
    if (p < 9)
    {
        v[dketa] = p + 1;
        isrunrun_naka(v, K, keta, dketa + 1, p + 1);
    }
}

ll runrun(int &K, int keta)
{
    vi v(keta);
    ans_vec.resize(0);
    for (int i = 1; i <= 9; ++i)
    {
        v[0] = i;
        isrunrun_naka(v, K, keta, 1, i);
    }

    if (ans_vec.size() == 0)
    {
        return -1;
    }

    ll ans = 0ll;
    for (size_t i = 0; i < ans_vec.size(); i++)
    {
        ans  = ans * 10 + ans_vec[i];
    }
    return ans;
}

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

    ll ans = -1ll;
    int keta = 1;
    while(ans < 0)
    {
        ans = runrun(K, keta);
        ++keta;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  if(A%2==B%2){cout<<"Alice"<<endl;}
  else{cout<<"Borys"<<endl;}
  return 0;}

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

int main() {
  int n, rank;
  char suit;
  char pattern[] = { 'S','H','C','D' };
  int cards[4][13] = { {0} };
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> suit >> rank;
    if (suit == 'S') cards[0][rank - 1] = 1;
    else if (suit == 'H') cards[1][rank - 1] = 1;
    else if (suit == 'C') cards[2][rank - 1] = 1;
    else cards[3][rank - 1] = 1;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 13; j++) {
      if (cards[i][j] == 0) {
        cout << pattern[i] << " " << j + 1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3112
import java.lang.Math

fun main(args: Array<String>) {
    val mod = 1000000007L
    val (N, K) = readInputLine().split(" ").map { it.toInt() }
    val AArr = readInputLine().split(" ").map { it.toLong() }.sorted().toLongArray()

    val factorial = LongArray(N + 1)
    val inverse = LongArray(N + 1)
    val factorialInverse = LongArray(N + 1)
    factorial[0] = 1L
    factorial[1] = 1L
    inverse[0] = 1L
    inverse[1] = 1L
    factorialInverse[0] = 1L
    factorialInverse[1] = 1L
    for (i in 2..N) {
        factorial[i] = (factorial[i - 1] * i.toLong() % mod)
        inverse[i] = (mod - inverse[mod.toInt() % i] * (mod / i.toLong()) % mod)
        factorialInverse[i] = (factorialInverse[i - 1] * inverse[i] % mod)
    }

    var ans = 0L

    for (i in N downTo 1) {
        if (i < K) {
            break
        }
        ans += AArr[i - 1] * factorial[i - 1] % mod * (factorialInverse[K - 1] * factorialInverse[i - K] % mod) % mod
        ans %= mod
    }

    for (i in 1..N) {
        if (N - i + 1 < K) {
            break
        }
        ans -= AArr[i - 1] * factorial[N - i] % mod * (factorialInverse[K - 1] * factorialInverse[N - i - K + 1] % mod) % mod
        ans += mod
        ans %= mod
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 74892
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = tuple(map(int, input().split()))

    ans = 0
    for i in range(n):
        ai = a[i]
        bi = b[i]
        if ai >= bi:
            ans += bi
        else:
            bi -= ai
            ans += ai

            aj = a[i+1]
            if aj >= bi:
                a[i+1] -= bi
                ans += bi
            else:
                a[i+1] = 0
                ans += aj
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18524
using System;
using System.Linq;

namespace CSwitches
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力 N/M の取得
            var inputNM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputNM[0];
            var m = inputNM[1];

            // 各電球の繋がってるスイッチ取得
            var lamps = new int[m][];
            for (var i = 0; i < m; i++)
            {
                var switches = Console.ReadLine().Split().Skip(1).Select(int.Parse).ToArray();
                lamps[i] = switches;
            }

            // 各電球の点灯条件を取得
            var conds = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 全部OFF ~ 全部ON の全てのパターンをビット演算でチェックして数える
            var count = 0;
            var patterns = Math.Pow(2, n);
            for (var pattern = 0; pattern < patterns; pattern++)
            {
                var isSatisfied = true;
                for (var i = 0; i < m; i++)
                {
                    var switches = lamps[i];
                    var switchCount = switches.Count(s => (1 << (s - 1) & pattern) > 0);
                    isSatisfied &= switchCount % 2 == conds[i];
                    if (!isSatisfied) break;
                }

                if (isSatisfied) count++;
            }

            // 解答の出力
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13524
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline ll gcd(ll a, ll b) {
	while (b) {
		ll c = a;
		a = b; b = c % b;
	}
	return a;
}
inline ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
bool isprime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
ll mypow(ll a, ll b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	ll memo = mypow(a, b >> 1);
	return memo * memo;
}
ll modpow(ll a, ll b, ll m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	ll memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
int n;
signed main() {
	cin >> n;
	int ans = 1;
	for (int i = 2; i * i <= n; i++) {
		int m = n;
		while (m % i == 0)m /= i;
		if (m != n && m % i == 1) {
			ans++;
		}
	}
	for (int i = 1; i * i <= (n - 1); i++) {
		int m = n - 1;
		if (m % i == 0) {
			if (i != 1)ans++;
			if (i * i != m)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long n;
  long a[5];
  int b;
  long c;
  scanf("%ld",&n);
  for(b=0;b<5;b++) scanf("%ld",&a[b]);
  c=a[0];
  for(b=1;b<5;b++) if(a[b]<c) c=a[b];
  long d;
  if(n%c==0) d=n/c;
  else d=(n/c)+1;
  printf("%ld",d+4);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  char str[64];
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}





Measured memory_bytes: 11876