akhauriyash/Code-Regression huggingface dataset:
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Integer[] flag = new Integer[64];
		for (int i = 0; i<64; i++) flag[i] = 0;  //初期化
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			ArrayList<ArrayList<Integer>> array = new ArrayList<ArrayList<Integer>>();
			for (int i=0; i<times; i++) {
				ArrayList<Integer> a = new ArrayList<Integer>();
				int obj = sc.nextInt();
				for (int j=0; j<obj; j++) a.add(sc.nextInt());
				array.add(a);
			}
			times = sc.nextInt();

			boolean b;
			for (int i=0; i<times; i++) {
				int query = sc.nextInt();
				int no = sc.nextInt();
				switch (query) {
				//test(i)
				case 0:
					System.out.println(flag[no]);
					break;

				//set(i)  ONにする
				case 1:
					for (int j=0; j<array.get(no).size(); j++) flag[array.get(no).get(j)]=1;
					break;

				//clear(i)  OFFにする
				case 2:
					for (int j=0; j<array.get(no).size(); j++) flag[array.get(no).get(j)]=0;
					break;

				//flip(i)  反転する
				case 3:
					for (int j=0; j<array.get(no).size(); j++) {
						if (flag[array.get(no).get(j)]==0) {
							flag[array.get(no).get(j)]= 1;
						} else flag[array.get(no).get(j)]= 0;
					}
					break;

				//all  全てのフラグがON？
				case 4:
					b = true;
					for (int j=0; j<array.get(no).size(); j++) {
						if (flag[array.get(no).get(j)]!=1) {
							b = false;
							break;
						}
					}
					System.out.println(b ? "1":"0");
					break;

				//any
				case 5:
					b = false;
					for (int j=0; j<array.get(no).size(); j++) {
						if (flag[array.get(no).get(j)]==1) {
							b = true;
							break;
						}
					}
					System.out.println(b ? "1":"0");
					break;

				//none  全てのフラグがOFF？
				case 6:
					b = true;
					for (int j=0; j<array.get(no).size(); j++) {
						if (flag[array.get(no).get(j)]!=0){
							b = false;
							break;
						}
					}
					System.out.println(b ? "1":"0");
					break;

				//count
				case 7:
					int count = 0;
					for (int j=0; j<array.get(no).size(); j++) {
						count += flag[array.get(no).get(j)];
					}
					System.out.println(count);
					break;

				//val  状態の整数値を出力する  最大：18446744073709551615
				case 8:
					BigDecimal total = new BigDecimal("0");
					for (int j =0; j<array.get(no).size(); j++) {
						if ( array.get(no).get(j) != 63) {
							String s = Long.toString((long)(flag[array.get(no).get(j)] * Math.pow(2, array.get(no).get(j))));
							BigDecimal bi = new BigDecimal(s);
							total = total.add(bi);   //二進数を10進数に変換
						} else {
							if (flag[63] == 1) {
								BigDecimal pow63 = new BigDecimal("9223372036854775808");  //2の63乗
								total = total.add(pow63);
								break;
							}
						}
					}
					System.out.println(total);
					break;
				}
			}
		}
	}
}



Measured memory_bytes: 108672
#include <stdio.h>

#define N   1000000
#define PN  78498

char  ef[ N + 1 ] = { 0 };
int   primes[ PN ];

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int pn = 0;
  int i, j;

  for ( i = 2; i <= N; ++i )
  {
    if ( ef[ i ] )  continue ;

    primes[ pn++ ] = i;

    for ( j = i * 2; j <= N; j += i )
    {
      ef[ j ] = 1;
    }
  }

  for ( ; ; )
  {
    int res = 0;
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < pn && n - primes[ i ] >= n / 2; ++i )
    {
      res += !ef[ n - primes[ i ] ];
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
s = input()
sum = 0
for i in range(len(s)):
    if s[i]=='x':
        sum = sum
    else:
        sum = sum +1
if len(s) < 15:
    sum = sum + 15 - len(s)
if sum >=8:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
N = input()
d = len(N)
num = int(N)
e = d//2
if d%2 == 0:
    if e == 1:
        ans = 9
    elif e == 2:
        ans = 9 + 999-99
    else:
        ans = 9 + 999-99 + 99999-9999
else:
    if e == 0:
        ans = num
    elif e == 1:
        ans = 9 + num-99
    else:
        ans = 9 + 999-99 + num-9999

print(ans)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
import numpy as np

N,A,B,C,D = map(int,input().split())

MOD = 10 ** 9 + 7

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for n in range(1,N+1):
    fact[n] = fact[n-1] * n % MOD
fact_inv[N] = pow(fact[N], MOD-2, MOD)
for n in range(N,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD
fact = np.array(fact, dtype=np.int64)
fact_inv = np.array(fact_inv, dtype=np.int64)

comb = np.zeros((N+1,N+1), dtype=np.int64)
comb[:,0] = 1
for n in range(1,N+1):
    comb[n,1:] = (comb[n-1,1:] + comb[n-1,:-1]) % MOD

dp = np.zeros(N+1, dtype=np.int64)
dp[0] = 1
for x in range(A,B+1):
    # 使うなら、C～D人で使う
    prev = dp
    dp = prev.copy()
    for n in range(C,D+1):
        y = n * x
        if y > N:
            break
        # x人組をn組とる
        # dp[i] += dp[i-y] * comb((N-i+y),y) * (y! / (x!)^n / n!)
        coef = fact[y] * pow(int(fact_inv[x]), n, MOD) % MOD * fact_inv[n] % MOD
        #print(x,n,coef)
        dp[y:] += prev[:-y] * comb[N:y-1:-1,y] % MOD * coef
        dp %= MOD

answer = dp[N]
print(answer)

Measured memory_bytes: 20308
#include<bits/stdc++.h>
using namespace std;
       
#define ff              first
#define ss              second                            
#define int             long long
#define rep(i,j,k)      for(int i=(j); i<(int)k; ++i)
#define rrep(i,k,j)     for(int i=(int)k-1; i>=(j); --i)
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define mii             map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed << setprecision(y) << x
#define mk(arr,n,type)  type *arr = new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define PI              3.14159265358979323846264338327950L
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
       
       
       
       
void c_p_c() {
  ios_base::sync_with_stdio(0); 
  cin.tie(0); 
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif  
}      
// int gcd (int a, int b) {
//   if (b == 0) return a;
//   else return gcd (b, a % b);
// }    
// int gcd(int a, int b, int& x, int& y) {
//   if (b == 0) {
//     x = 1;
//     y = 0;
//     return a;
//   }  
//   int x1, y1;
//   int d = gcd(b, a % b, x1, y1);
//   x = y1;
//   y = x1 - y1 * (a / b);
//   return d;
// }   
// int lcm (int a, int b)  {
//   return a / gcd(a, b) * b;
// }   
// int fact(int n){
//   if(n==0) return 1 ;
//   else return n*fact(n-1); 
// }   
double pi = 3.141592653589;
           
void solve() {
  int a, b; cin >> a >> b;
  cout << a * b;
}       
int32_t main() {
 //c_p_c();
 //w(x)    
 solve();
 return 0;
}      

Measured memory_bytes: 3584
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void) {

	string s;

	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		//cout << s[i] << "\n";
		if (s[i] == 'B') {
			s.erase(s.begin() + max(0, i - 1), s.begin() + i + 1);
			//printf("i=%d,erase\n", i);
			i = -1;
		}
	}

	cout << s << "\n";

	return 0;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    bool ok[4] = {1, 1, 1, 1};
    int a, b; cin >> a >> b; ok[a] = ok[b] = 0;
    for (int i = 1; i <= 3; i++) if (ok[i] == 1) cout << i << "\n";

    return 0;
}


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

int main() {
	char s[51], t[51];
	bool flag,restorable=false;
	scanf("%50s %50s", s, t);
	int i, j, slen = strlen(s), tlen = strlen(t);
	for (i = slen - tlen; i >= 0;i--) {
		flag = true;
		for (j = 0; j < tlen; j++) {
			flag = flag && ((s[i + j] == t[j]) || (s[i+j] == '?'));
		}
		if (flag) {
			restorable = true;
			for (j = 0; j < tlen; j++) {
				s[i + j] = t[j];
			}
			for (j = 0; j < slen; j++) {
				if (s[j] == '?') {
					s[j] = 'a';
				}
			}
		}
	}
	if (restorable) {
		printf("%s", s);
	}
	else {
		printf("UNRESTORABLE");
	}
	return 0;
}

Measured memory_bytes: 128
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, m;
int u, v;
int ans[55];

int main(){
    ios::sync_with_stdio(0);
    clean(ans,0);
    cin >> n >> m;
    forn(i,m){
        cin >> u >> v;
        ans[u]++;
        ans[v]++;
    }

    forr(i,1,n+1){
        cout << ans[i] << "\n";
    }
    return 0;
}

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

int main() {
  
  string a, b;
  cin >> a >> b;
  
  if (a == b) {
    cout << 'H' << endl;
  }
  else {
    cout << 'D' << endl;    
  }

  
return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int N;
    string s;
    string t;
    cin >> N;
    cin >> s;
    cin >> t;
    for(int i = 0; i < N; i++){
        bool can_be_ans = true;
        for(int j = i; j < N; j++){
            if(s[j] != t[j - i]){
                can_be_ans = false;
                break;
            }
        }
        if(can_be_ans){
            cout << i + N << endl;
            return 0;
        }
    }
    cout << 2 * N << endl;
    return 0;
}

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

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

int INF = 1000000007;
int MAXC = 200000;
int dp[30][200000]; // i???????????§????????????????????£???j???????????????????°??????????????????°

int main(){
  int n,m;
  int c[30];

  cin >> n >> m;
  rep(i,m){
    cin >> c[i] ;
  }
  sort(c,c+m);

  //  rep(i,m) cout << c[i] << " ";
  
  rep(j,30){
    rep(i,200000){  
      dp[j][i] = INF;
    }
  }
  rep(j,30){
    dp[j][0] = 0;
  }
  for(int i = 1;i<m+1;i++){
    for(int j = 0;j<n+1;j++){
      if(j-c[i-1] >= 0 )
	dp[i][j] = min( dp[i][j-c[i-1]]+1, dp[i-1][j] );
      //      dp[i][j+c[i-1]] = min( dp[i][j] + 1 , dp[i-1][j+c[i-1]] );
      else 	dp[i][j] =  dp[i-1][j] ;
	//}


    }
  }
  /*
  rep(i,m+1){
    rep(j,n+1){
      if(dp[i][j] == INF) cout << "  INF";
      else       printf("%5d",dp[i][j]);
    }
    cout << endl;
  }
  for(int i = 1; i < m;i++){
    rep(j,n){
      dp[i][j+c[i]] =  min( dp[i-1][j+c[i]] , dp[i][j] + 1 );
    }
  }
  */

 
  cout << dp[m][n] << endl;
  
  


  return 0;
}

Measured memory_bytes: 24612
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define MIN(x, y) ((x) <= (y) ? (x) : (y))
typedef struct QueueKey {
    char str[16];
    int num;
} QueueKey;
typedef struct QueueDat {
    QueueKey key;
    struct QueueDat *next;
} QueueDat;
typedef struct Queue {
    size_t len;
    QueueDat *head;
    QueueDat *tail;
} Queue;
#define queue_init(q) ((q) ? ((q)->len = 0, (q)->head = (q)->tail = NULL) : 0)
#define queue_len(q) ((q) ? (q)->len : 0)
void queue_push(Queue *q, QueueKey x) {
    QueueDat *new_dat = malloc(sizeof(QueueDat));
    *new_dat = (QueueDat){x, NULL};
    if(q->len) {
        q->tail->next = new_dat;
        q->tail = new_dat;
    }else{
        q->head = q->tail = new_dat;
    }
    q->len++;
}
QueueKey queue_pop(Queue *q) {
    assert(q->len);
    QueueDat *old_head = q->head;
    q->head = old_head->next;
    QueueKey key = old_head->key;
    free(old_head);
    q->len--;
    return key;
}

int main(int argc, char **argv) {
    int n, q;
    scanf("%d%d", &n, &q);
    Queue Q;
    queue_init(&Q);
    QueueKey key;
    for(int i = 0; i < n; ++i) {
        scanf("%s%d", key.str, &key.num);
        queue_push(&Q, key);
    }
    int cnt = 0;
    while(queue_len(&Q)){
        key = queue_pop(&Q);
        cnt += MIN(key.num, q);
        if(key.num > q){
            key.num -= q;
            queue_push(&Q, key);
        } else {
            printf("%s %d\n", key.str, cnt);
        }
    }
    return 0;
}



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

int main() {
int N;
  string C;
  cin >>N;
  int j = N-1;
  for (int i = 0; i < N; ){
  cin  >> C;
    if ( C =="Y"){
     cout << "Four" << endl; 
      break;
      }else if (C !="Y"){
      i++;
      }
    if (i==j)  {
      cout << "Three" << endl;
      }
    }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int k,t,i,v[110],st,dr;
int main()
{
    cin>>k>>t;
    for(i=1;i<=t;i++)
        cin>>v[i];
    sort(v+1,v+t+1);
    st=1;
    dr=t;
    while(st<dr)
    {
        if(v[st]<v[dr])
        {
            v[dr]-=v[st];
            v[st]=0;
            st++;
        }
        else if(v[st]==v[dr])
        {
            v[dr]=v[st]=0;
            st++;
            dr--;
        }
        else
        {
            v[st]-=v[dr];
            dr--;
        }
    }
    if(st==dr)
        cout<<max(0,v[st]-1);
    else cout<<0;
    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 100005

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);
}
#define N 100005
int n, k;
int a[N][3];
int dp[N][3];
int dpf(int i, int j)
{
	if(i == n)
		return 0;
	if(dp[i][j] >= 0)
		return dp[i][j];
	for (int h = 0; h < 3; ++h)
	{
		if(h != j)
		dp[i][j] = max(dp[i][j], a[i][h] + dpf(i + 1, h));
	}
	return dp[i][j];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		for (int j = 0; j < 3; ++j)
		{
			dp[i][j] = -1;
		}
	}
	int ans = max({a[0][0] + dpf(1, 0), a[0][1] + dpf(1, 1), a[0][2] + dpf(1, 2)});
	cout << ans << "\n";	
	return 0;
}

Measured memory_bytes: 12160
'use strict';(function(input){
  
  input=input.trim().split('').map(x=>x-0).reverse();
  
  const N=input.length;
  const M=input.reduce((a,c)=>a+((c===c)?0:1), 0);
  
  const mod = 1e9+7;
  
  const factor=[];
  
  (function(){
    var r=1;
    do{
      factor.push(r);
      r*=10;
      r%=13;
    }while(r!==1);
  })();
  
  const T=factor.length;
  
  const dp=new Array(M+1).fill(0).map(z=>new Array(13).fill(0));
  dp[0][0]=1;
  
  var cur=0,
      m=0;
  
  for(let i=0;i<N;i++){
    let f=factor[i%T],
        n=input[i];
    if(n===n){
      cur=(cur+f*n)%13;
    }else{
      for(let j=0;j<13;j++){
        for(let k=0;k<10;k++){
          let l=(j+f*k)%13;
          dp[m+1][l]=(dp[m+1][l]+dp[m][j])%mod;
        }
      }
      m++;
    }
  }
  const ans=dp[M][(13+5-cur)%13];
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 54272
import std.algorithm,
       std.string,
       std.array,
       std.range,
       std.stdio,
       std.conv;

R delegate(Args) Z(R, Args...)(R delegate(R delegate(Args), Args) f){
  return (Args args) => f(Z(f), args);
}

ulong delegate(ulong, ulong) gcd;

static this() {
  gcd = Z((ulong delegate(ulong, ulong) gcd, ulong a, ulong b) =>
          b ? gcd(b, a%b) : a < 0 ? a * -1 : a);
}

void main() {
  ulong[2] inputs = readln.chomp.split.to!(ulong[2]);
  ulong N = inputs[0],
        X = inputs[1];

  writeln(3 * (N - gcd(N, X)));
}



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

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  for(int i = 0; i < N; i++) {
    if(i != N - 1) {
      cout << S.at(i) << T.at(i);
    }
    else cout << S.at(i) << T.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 1100
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

char a[MAX][MAX];
ll dp[MAX][MAX];
ll f(ll i,ll j,ll h,ll w){
	if(i>h) return 0;
	if(j>w) return 0;
	if(a[i][j]=='#') return 0;
	if(i==h && j==w) return 1;
	if(dp[i][j]!=-1) return dp[i][j];

	ll first = f(i+1,j,h,w);
	ll second = f(i,j+1,h,w);
	dp[i][j]= (first+second)%Mod;
	return dp[i][j];
}

int main(){
	ios_base::sync_with_stdio(false);
	memset(dp,-1,sizeof(dp));
	ll h,w;cin>>h>>w;
	For(i,0,h){
		string s;cin>>s;
		For(j,0,w) a[i][j]=s[j];
	}
	cout<<f(0,0,h-1,w-1)<<endl;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 n;
  cin >> n;
  vector<i64> d(n);
  rep(i,0,n) cin >> d[i];

  i64 sum = 0;
  rep(i,0,n) rep(j, i + 1, n) {
    sum += d[i] * d[j];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
public static void main (String[]args) {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
      int N = Integer.parseInt(br.readLine());
      int sum = 0;
      String  lines = br.readLine();    

      String[] strs = lines.trim().split("\\s+");
      int [] a = new int [N];
      for (int i = 0; i < strs.length; i++) {
      a[i] = Integer.parseInt(strs[i]);
      sum = Arrays.stream(a).max().getAsInt() - Arrays.stream(a).min().getAsInt();
      }
  
      
 
System.out.println(sum);



    }catch (Exception e) {
       }
       }
   }

Measured memory_bytes: 24276
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    ll x, y;
    cin >> x >> y;
    if (x % y == 0)
        print(-1);
    else
        print(x);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=400005;

int w[N],n;

struct data {
	int l,r,w1,w2;
	bool operator <(data b) const {
		return (w[w1]==w[b.w1])?(w[w2]>w[b.w2]):(w[w1]>w[b.w1]);
	}
} ;

struct RMQ {
	int rec[18][N],lg[N];

	void pre() {
		rep(i,2,N-1) lg[i]=lg[i>>1]+1;
		rep(j,1,lg[n]) {
			rep(i,1,n-(1<<j)+1) {
				if (w[rec[j-1][i]]>w[rec[j-1][i+(1<<j-1)]]) {
					rec[j][i]=rec[j-1][i+(1<<j-1)];
				} else rec[j][i]=rec[j-1][i];
			}
		}
	}

	int ask(int l,int r) {
		int t=lg[r-l+1];
		if (w[rec[t][l]]<w[rec[t][r-(1<<t)+1]]) return rec[t][l];
		else return rec[t][r-(1<<t)+1];
	}
} T[2];

std:: priority_queue <data> heap;

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

int main(void) {
	n=read(),w[0]=INF;
	rep(i,1,n) {
		w[i]=read();
		T[i&1].rec[0][i]=i;
		T[!(i&1)].rec[0][i]=0;
	}
	T[0].pre(),T[1].pre();
	int p1=T[1].ask(1,n-1);
	int p2=T[0].ask(p1+1,n);
	heap.push((data) {1,n,p1,p2});
	for (int i=1;i*2<=n;++i) {
		data top=heap.top(); heap.pop();
		int l=top.l,r=top.r,w1=top.w1,w2=top.w2,wjp;
		printf("%d %d ", w[top.w1],w[top.w2]);
		if (w1>l+1) {
			wjp=l&1;
			p1=T[wjp].ask(l,w1-2);
			p2=T[!wjp].ask(p1+1,w1-1);
			heap.push((data) {l,w1-1,p1,p2});
		}
		if (w2+1<r) {
			wjp=(w2+1)&1;
			p1=T[wjp].ask(w2+1,r-1);
			p2=T[!wjp].ask(p1+1,r);
			heap.push((data) {w2+1,r,p1,p2});
		}
		if (w1+1<w2) {
			wjp=(w1+1)&1;
			p1=T[wjp].ask(w1+1,w2-2);
			p2=T[!wjp].ask(p1+1,w2-1);
			heap.push((data) {w1+1,w2-1,p1,p2});
		}
	} puts("");
	return 0;
}

Measured memory_bytes: 61684
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;

		for (int i = 1; i <= num; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 35832
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
  int nbr_vertices, nbr_edges;

  cin >> nbr_vertices;
  cin >> nbr_edges;

  vector<vector<pair<bool, int> > > matrix(nbr_vertices, vector<pair<bool, int> >(nbr_vertices, make_pair(true, 0)));
  int src, dest, dist;

  // Fill the matrix for vector[i][i] to 0
  for (int i = 0; i < nbr_vertices; i++) {
    matrix[i][i] = make_pair(false, 0);
  }

  // Fill the matrix with distances get from input
  for (int i = 0; i < nbr_edges; i++) {
    cin >> src;
    cin >> dest;
    cin >> dist;
    matrix[src][dest] = make_pair(false, dist);
  }

  for (int k = 0; k < nbr_vertices; k++) {
    for (int i = 0; i < nbr_vertices; i++) {
      for (int j = 0; j < nbr_vertices; j++) {
        if (!matrix[i][k].first && !matrix[k][j].first) {
          if (matrix[i][j].first) {
            matrix[i][j].first = false;
            matrix[i][j].second = matrix[i][k].second + matrix[k][j].second;
          } else if (matrix[i][j].second > matrix[i][k].second + matrix[k][j].second) {
            matrix[i][j].second = matrix[i][k].second + matrix[k][j].second;
          }
        }
      }
    }
  }

  //check negative cycles
  for (int i = 0; i < nbr_vertices; i++) {
    if (matrix[i][i].second < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }

  for (int i = 0; i < nbr_vertices; i++) {
    for (int j = 0; j < nbr_vertices; j++) {
      if (matrix[i][j].first)
        cout << "INF";
      else
        cout << matrix[i][j].second;
      if (j + 1 != nbr_vertices)
        cout << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 3172
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var a = IO.RSLong;

            if (a.Contains(0))
            {
                WriteLine(0);
                return;
            }

            long ans = 1;
            for (int i = 0; i < n; i++)
            {
                try
                {
                    checked
                    {
                        ans *= a[i];
                        if (ans > 1000000000000000000)
                        {
                            WriteLine(-1);
                            return;
                        }
                    }
                }
                catch (OverflowException ex)
                {
                    WriteLine(-1);
                    return;
                }
            }
            WriteLine(ans);
        }

        public class IO
        {
            #region Input
            public static int RInt => int.Parse(ReadLine());
            public static long RLong => long.Parse(ReadLine());
            public static double RDouble => double.Parse(ReadLine());

            public static string[] RSString => ReadLine().Split();
            public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
            public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
            public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }
    }
}

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

int n, kw, w[105], v[105];
long long int dp[105][100005];
// long long int ans = 0;

long long int fn(int i, int rem) {
    if (i == n) return 0;
    if (~dp[i][rem]) return dp[i][rem];
    dp[i][rem] = fn(i + 1, rem);
    if (rem >= w[i]) 
        dp[i][rem] = max(dp[i][rem], fn(i + 1, rem - w[i]) + v[i]);
    return dp[i][rem];
}

int main() {
    scanf("%d%d", &n, &kw);
    for (int i = 0; i < n; ++i)  {
        scanf("%d%d", &w[i], &v[i]);
    }
    memset(dp, -1, sizeof dp);
    cout << fn(0, kw) << endl;
    return 0;
}

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

int N;
int A[1024][1024];
int pos[1024];
char ok[1024];

int targetNum[2];
int targets[2][1024];
int phase;

int main(void) {
	int i, j;
	int progress = 0;
	int count = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N - 1; j++) {
			if (scanf("%d", &A[i][j]) != 1) return 1;
		}
		A[i][N - 1] = 0;
	}

	for (i = 0; i < N; i++) {
		pos[i] = 0;
		targets[0][i] = i;
	}
	targetNum[0] = N;
	phase = 0;

	do {
		progress = 0;
		memset(ok, 0, sizeof(ok));
		targetNum[1 - phase] = 0;
		for (i = 0; i < targetNum[phase]; i++) {
			int idx = targets[phase][i];
#if 0
			printf("count = %d idx = %d\n", count, idx);
#endif
			if (!ok[idx] && A[idx][pos[idx]] > 0) {
				int target = A[idx][pos[idx]] - 1;
				if (A[target][pos[target]] == idx + 1) {
					/* match accepted */
					progress = 1;
					ok[idx] = 1;
					ok[target] = 1;
					targets[1 - phase][targetNum[1 - phase]++] = idx;
					targets[1 - phase][targetNum[1 - phase]++] = target;
#if 0
					printf("count = %d match = %d vs %d\n", count, idx, target);
#endif
				}
			}
		}
		for (i = 0; i < targetNum[1 - phase]; i++) {
			pos[targets[1 - phase][i]]++;
		}
		phase = 1 - phase;
		if (progress) count++;
	} while (progress);

	for (i = 0; i < N; i++) {
		if (A[i][pos[i]] != 0) {
			/* match not accepted */
			puts("-1");
			return 0;
		}
	}

	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
//#include <vector>
//#include <iomanip>

using namespace std;

int main()
{
	int N, L;
	cin >> N >> L;

	if (L >= 1)
	{
		int sum = 0;
		for (int i = 1; i < N; i++)
		{
			sum += L + i;
		}
		cout << sum << endl;
	}
	else  //L < 1
	{
		if (L + N - 1 >= 0)
		{
			int sum = 0;
			for (int i = 0; i < N; i++)
			{
				sum += L + i;
			}
			cout << sum << endl;
		}
		else
		{
			int sum = 0;
			for (int i = 0; i < N - 1; i++)
			{
				sum += L + i;
			}
			cout << sum << endl;
		}
	}

	return 0;
}


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

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;

int main()
{
  ll n;cin>>n;
  ll a[n + 10], b[n + 10];
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll count = 0;
  rep(i, n)
  {
    if(b[i]<=a[i]+a[i+1]){
      count+=b[i];
      if(b[i]>a[i])a[i + 1] = a[i] + a[i + 1] - b[i];
    }
    else {
      count+=a[i]+a[i+1];
      a[i + 1] = 0;
    }
  }
  out(count);

  return 0;
}


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

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

	double j;

	if (N % 2 == 0)
		j = 0.5;
	else 
		j = double((N + 1) / 2) / N;
	

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ans = 10000;
    for (int i = 0; i < n; i++) {
        int cur = 0;
        for (int j = 0; j < n; j++) {
            cur += w[j] * (j <= i ? 1 : -1);
        }
        if (cur < 0) {
            cur = -cur;
        }
        if (cur < ans) {
            ans = cur;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 200005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
LL s[N];
int main(){
	int i, j, n, m, x, y;
	LL s1, s2, s3, s4, ans = 1e18, a, b;
	n = read();
	for(i = 1; i <= n; i++) s[i] = s[i - 1] + read();
	x = 1, y = 3;
	for(i = 2; i <= n - 2; i++){
		while(x + 1 < i && abs(s[i] - s[x] - s[x]) > abs(s[i] - s[x + 1] - s[x + 1])) x++;
		while(y + 1 < n && abs(s[n] - s[y] - (s[y] - s[i])) > abs(s[n] - s[y + 1] - (s[y + 1] - s[i]))) y++;
		s1 = s[x], s2 = s[i] - s[x];
		s3 = s[y] - s[i], s4 = s[n] - s[y];
		a = max(s1, s2); a = max(a, max(s3, s4));
		b = min(s1, s2); b = min(b, min(s3, s4));
		ans = min(ans, a - b);
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 1792
from math import sqrt
from collections import defaultdict

n = int(input())

d = defaultdict(int)
for i in range(2, int(sqrt(n)) + 10):
    while n % i == 0:
        d[i] += 1
        n //= i

if n != 1:
    d[n] += 1

ans = 0
for v in d.values():
    mn = 1
    while v >= mn:
        v -= mn
        ans += 1
        mn += 1

print(ans)


Measured memory_bytes: 9480
#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main()
{
  int c[26],D=IN(),i=0,j=0,s[365][26]={{0}},t,last[26]={0},sum=0;
  while(i<26){c[i++]=IN();}i=0;
  while(i<D){while(j<26){s[i][j++]=IN();}i++,j=0;}i=0;
  while(i<D)
  {
    j=0;t=IN()-1;sum+=s[i][t];last[t]=++i;
    while(j<26){sum-=c[j]*(i-last[j++]);}
    printf("%d\n",sum);
  }
}

Measured memory_bytes: 1636
N = int(input())
lis = list(map(int,input().split()))
count = 0
search = 1
result = -1
rest = 0
for i in lis:
    if i == search:
        search += 1
        rest +=1
    else:
        count +=1

if rest == search-1 and rest != 0:
    result = count

print(result)

Measured memory_bytes: 26012
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
  int a,b,ans=0;
  cin>>a>>b;
  rep(i,2)
  {
    int buf=max(a,b);
    if(buf==a)a--;
    else b--;
    ans+=buf;
  }
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

struct Camel {
   int K, L, R;
   friend ostream& operator<<(ostream& os, const Camel& c) {
      return os << "Camel " << c.K << ' ' << c.L << ' ' << c.R;
   }
};


namespace Greedy3 {

bool trace;

llong solve(int N, vector<Camel> camels) {
   llong base = 0;

   vector<Camel> camels_left, camels_right;
   for (Camel c : camels) {
      if (c.L > c.R) {
         camels_left.push_back(c);
      }
      else if (c.L < c.R)
         camels_right.push_back(c);
      base += min(c.L, c.R);
   }

   if (trace) {
      DEBUG(base);
      DEBUG(camels_left);
      DEBUG(camels_right);
   }

   sort(camels_left.begin(), camels_left.end(),
        [&] (Camel a, Camel b) {
           if (a.K != b.K)
              return a.K < b.K;
           return a.L-a.R > b.L-b.R;
        });

   sort(camels_right.begin(), camels_right.end(),
        [&] (Camel a, Camel b) {
           if (a.K != b.K)
              return a.K > b.K;
           return a.R-a.L > b.R-b.L;
        });

   llong res = base;

   {
      if (trace) cerr << "Left" << endl;
      priority_queue< int, VI, greater<int> > pq_left;
      for (Camel c : camels_left) {
         if (trace) cerr << c << endl;
         if (c.K > SZ(pq_left)) {
            pq_left.push(c.L-c.R);
         }
         else {
            pq_left.push(c.L-c.R);
            pq_left.pop();
         }
      }

      while (!pq_left.empty()) {
         if (trace) cerr << "+ " << pq_left.top() << endl;
         res += pq_left.top();
         pq_left.pop();
      }
   }


   {
   // cerr << "Right" << endl;
      priority_queue< int, VI, greater<int> > pq_right;

      for (Camel c : camels_right) {
         if (trace) cerr << c << endl;
         if (N-c.K > SZ(pq_right)) {
            pq_right.push(c.R-c.L);
         }
         else {
            pq_right.push(c.R-c.L);
            pq_right.pop();
         }
      }

      while (!pq_right.empty()) {
         if (trace) cerr << "+ " << pq_right.top() << endl;
         res += pq_right.top();
         pq_right.pop();
      }
   }

   return res;
}
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int TC;
   cin >> TC;
   FOR(tc, 1, TC) {
      int N;
      cin >> N;
      vector<Camel> camels;
      REP(i, N) {
         int K, L, R;
         cin >> K >> L >> R;
         camels.push_back({K, L, R});
      }
      llong res = Greedy3::solve(N, camels);
      cout << res << '\n';
   }

   return 0;
}


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

using namespace std;
//int moreGcd
vector<int > l;
int N = 0;
int MIN = 10000000;
int A = 0;
int B = 0;
int C = 0;
//int MAX = 0;

void calc(vector<int > cost){

    //各竹
    vector<int > each(3,0);
    //竹は行き渡りましたか？フラグ
    vector<bool > flag(3,0);
    //合成魔法をぶっ放した回数
    vector<int > marge(3,-1);
    
    for(int i = 0; i < N; i++){
        if(cost[i] < 3){
            each[cost[i]] += l[i];
            marge[cost[i]]++;
            flag[cost[i]] = 1;
        }
    }

    //みんな竹は持ったな？
    int t_MIN = 0;
    if(flag[0] && flag[1] && flag[2]){
        t_MIN += marge[0] * 10 + marge[1] * 10 + marge[2] * 10;
        t_MIN += abs(each[0] - A) + abs(each[1] - B) + abs(each[2] - C);
        
        if(t_MIN < MIN){
            MIN = t_MIN;
        }
    }
}

//全パターン探査
void dfs(int n, vector<int > cost){

    if(n == N){
        calc(cost);
    }else{
        
        for(int i = 0; i < 4; i++){
            cost[n] = i;
            dfs(n + 1, cost);
        }
    }

}

int main(){
    
    cin >> N;

    cin >> A >> B >> C;

    int b = 0;
    for(int i = 0; i < N; i++){
        cin >> b;
        l.push_back(b);
    }

    vector<int > cost(N, 0);
    
    dfs(0, cost);

    cout << MIN << endl;
}

Measured memory_bytes: 256
//a
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;

int main(){
	
	int n;
	int s[1000];
	
	while(cin>>n, n){
		
		for(int i=0; i<n; ++i){
			cin>>s[i];
		}
		
		sort(s, s+n);
		
		int sum=0;
		
		for(int i=1; i<n-1; ++i){
			sum+=s[i];
		}
		
		sum /=n-2;
		
		cout << sum << endl;
	}
	
	return 0;	
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<pair<int,int>> Task(N);
	for(int i=0; i<N; i++)
	{
		int a,b;
		cin>>a>>b;
		Task[i] = make_pair(b,a);
	}

	//締め切りが短い順に並び替え
	sort(Task.begin(),Task.end());

	bool flag = false;
	int A = 0;
	int B = 0;
	for(int i=0; i<N; i++)
	{
		A += Task[i].second;
		B = Task[i].first;

		if(A>B)
		{
			flag = true;
		}
	}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=400005,INF=1<<30;
vector<int> G[MAX][2];
int color[MAX][2];

void DFS(int u,int p,int k){
    for(int to:G[u][k]){
        if(to==p) continue;
        if(color[to][k]) continue;
        
        color[to][k]=3-color[u][k];
        DFS(to,u,k);
    }
}

vector<pair<int,int>> ans[3][3];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    
    int A,B;cin>>A>>B;
    vector<int> sq(500000,-1);
    for(int i=0;i<=700;i++){
        sq[i*i]=i;
    }
    
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            for(int to=0;to<2*N;to++){
                int ra=A-(i-to)*(i-to),rb=B-(i-to)*(i-to);
                
                if(ra>=0){
                    if(sq[ra]!=-1){
                        if(j-sq[ra]>=0){
                            G[i*(2*N)+j][0].push_back(to*(2*N)+j-sq[ra]);
                        }
                        if(j+sq[ra]<2*N){
                            G[i*(2*N)+j][0].push_back(to*(2*N)+j+sq[ra]);
                        }
                    }
                }
                
                if(rb>=0){
                    if(sq[rb]!=-1){
                        if(j-sq[rb]>=0){
                            G[i*(2*N)+j][1].push_back(to*(2*N)+j-sq[rb]);
                        }
                        if(j+sq[rb]<2*N){
                            G[i*(2*N)+j][1].push_back(to*(2*N)+j+sq[rb]);
                        }
                    }
                }
            }
        }
    }
    
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            for(int k=0;k<2;k++){
                if(color[i*(2*N)+j][k]==0){
                    color[i*(2*N)+j][k]=1;
                    DFS(i*(2*N)+j,-1,k);
                }
            }
        }
    }
    
    for(int i=0;i<2*N;i++){
        for(int j=0;j<2*N;j++){
            ans[color[i*(2*N)+j][0]][color[i*(2*N)+j][1]].push_back({i,j});
        }
    }
    
    for(int i=1;i<3;i++){
        for(int j=1;j<3;j++){
            if(ans[i][j].size()>=N*N){
                for(int k=0;k<N*N;k++){
                    cout<<ans[i][j][k].first<<" "<<ans[i][j][k].second<<endl;
                }
                return 0;
            }
        }
    }
    
}






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

int main()
{
	int a,b,c;
	int x=0;
	int n;
	cin >> n;
	for(int i=0 ;i<n ;i++){
		cin >> a >> b >> c;
		if(a<b && c<b){
			x=a;
			a=b;
			b=x;
		}
		else if(a<c && b<c){
			x=a;
			a=c;
			c=x;
		}

		if((b*b)+(c*c) == (a*a))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-

N = int(input())
xu = []
for i in range(N):
    xu.append([i for i in input().split()])

sum_otoshidama = 0.0
for i in range(N):
    x = float(xu[i][0])
    u = xu[i][1]

    if u == 'JPY':
        sum_otoshidama += x
    else:
        sum_otoshidama += x * 380000.0

print(sum_otoshidama)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;

int main(){

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

    ll sum_left = 0;
    ll sum_right = accumulate(all(v), 0ll);
    ll ans = sum_right;
    for(int i = 0; i < n; i++){
        sum_left += v[i];
        sum_right -= v[i];
        ans = min(ans, abs(sum_right - sum_left));
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
h, w, m = gets.split.map(&:to_i)
row = Array.new(h, 0)
col = Array.new(w, 0)
bomb = []
m.times do
  i, j = gets.split.map(&:to_i)
  row[i-1] += 1
  col[j-1] += 1
  bomb << [i-1, j-1]
end
row_bomb_max = row.max
col_bomb_max = col.max
ans = row_bomb_max + col_bomb_max
row_num = row.count(row_bomb_max)
col_num = col.count(col_bomb_max)
cnt = row_num * col_num
bomb.each do |i, j|
  cnt -= 1 if row[i]==row_bomb_max && col[j]==col_bomb_max
end
puts cnt == 0 ? ans - 1 : ans

Measured memory_bytes: 39692
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	auto res = new int[][](10, 500);
	auto f = new bool[](10);
	void solve(int sum, int n) {
		if (n == 10) return;
		foreach (i; 0..10) {
			if (f[i]) continue;
			f[i] = 1;
			res[n][sum + i*(n+1)]++;
 			solve(sum + i*(n+1), n+1);
 			f[i] = 0;
		}
	}
	solve(0, 0);
	foreach (line; stdin.byLine) {
		auto x = line.chomp.split.map!(to!int);
		if (x[1] >= 500) writeln(0);
		else res[x[0]-1][x[1]].writeln;
	}
}

Measured memory_bytes: 1068
import numpy as np
def input_one_number():
    return int(input())
 
def input_multiple_number():
    return map(int, input().split())
 
def input_multiple_number_as_list():
    return list(map(int, input().split()))

a,b,h,m=input_multiple_number()

rad=np.deg2rad(min(abs(h*30-m*5.5),360-(abs(h*30-m*5.5))))

ans=np.sqrt(pow(a,2)+pow(b,2)-2*a*b*np.cos(rad))
print(ans)

Measured memory_bytes: 27204