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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int n, k;
	cin>>n>>k;
	vll a(n);
	for(int i = 0; i < n; i++) cin>>a[i];
		sort(a.begin(), a.end());
	ll s = 0;
	for(int i = 0; i < k; i++) s+=a[i];
		p(s);
	return 0;
}

Measured memory_bytes: 3648
N,M = gets.split(' ').map(&:to_i)
light = M.times.map{ gets.split(' ').map(&:to_i) }
p = gets.split(' ').map(&:to_i)

try = 2**N-1
flag = 0
ans = 0
for i in 0..try
  switch = i.to_s(2)
  switch = "0" * (N-switch.length) + switch
  #puts "switch=#{switch}"
  #puts switch
  flag = 0
  for t in 0..M-1
    light_cnt = 0
    for u in 1..(light[t][0])
      if switch[(light[t][u]-1)] == "1"
        light_cnt += 1
      end
    end
    #puts "light_cnt=#{light_cnt}"
    if (light_cnt%2)==p[t]
      next
    else
      flag = 1
      break
    end
  end
  #puts "flag=#{flag}"
  ans += 1 if flag == 0
end
puts ans


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



int main() {
  long long total=0;
  int N; cin>>N;
  for(int i = 1; i <= N; ++i){
    if(i%3!=0&&i%5!=0){
      total+=i;
    }
  }
  cout<<total<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<vector>
#include<map>
#include<limits.h>
#include<ctype.h>
#include<queue>
using namespace std;
typedef long long ll;
ll ar[100003],prime[100004],s1[100003];
ll y11[100003];
vector<ll> primes;
void sieve(ll n)
{
	ll i;
	for(i=0;i<=n;i++)
	prime[i]=1;
	prime[0]=prime[1]=0;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==1)
		{
			for(ll j=i*i;j<=n;j=j+i)
			prime[j]=0;
		}
	}
	for(ll i=0;i<=n;i++)
	if(prime[i]==1)
    {
	primes.push_back(i);
    }
}
map<ll,ll> mp;

int main()
{
	sieve(100003);
	ll n,i;
	ll s,y,k;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>ar[i];
	ll j;
	for(i=1;i<=n;i++)
	{
	    s=1,y=1;
	    k=ar[i];
		for(j=0;j<primes.size();j++)
		{
		ll pp=primes[j];
		if(pp*pp*pp>k)
		break;
		ll count=0;
		while(k%pp==0)
		{
			k=k/pp;
			count++;
		}
		count=count%3;
		for(ll kk=0;kk<count;kk++)
		s=s*pp;
		ll count2=(3-count)%3;
		for(ll kk=0;kk<count2;kk++)
		y=y*pp;
	    }
	    ll p=0;
	    s=s*k;
	    ll sq=sqrt(k);
	    for(ll oo=sq-1;oo<=sq+1;oo++)
	    if(oo*oo==k)
	    p=1;
	    if(p==1)
		y=y*sq;
		else
			y=y*k*k;
        s1[i]=s;
	   y11[i]=y;
	    mp[s]++;
	    mp[y]--;
	}
	ll cc=0;
	for(i=1;i<=n;i++)
	{
		if(mp[s1[i]]>=0)
        {
		cc++;
		mp[y11[i]]=-1;
        }
	}
	cout<<cc<<endl;
	return 0;
}


Measured memory_bytes: 16000
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
dic = {}
for i in range(h):
    for j in range(w):
        if a[i][j] not in dic.keys():
            dic[a[i][j]] = 1
        else:
            dic[a[i][j]] += 1
group = {0:0, 1:0, 2:0, 3:0}
for v in dic.values():
    group[v%4] += 1
ans = 'Yes'
if group[1] + group[3] >= 2:
    ans = 'No'
else:
    if h&1 and w&1:
        if group[2] + group[3] > h//2 + w//2:
            ans = 'No'
    elif h&1 or w&1:
        if group[1] or group[3]:
            ans = 'No'
        elif group[2] > (h*w - ((h//2)*(w//2)*4))//2:
            ans = 'No'
    else:
        if group[1] or group[2] or group[3]:
            ans = 'No'
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int n;
	long long a;
	int num[250] = {};
	int ans[250] = {};

	

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;
		num[i] += a;
	}
	
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		while (num[i] % 2 == 0) {
			cnt++;
			num[i] = num[i] / 2;
		}

		ans[i] += cnt;
	}

	sort(ans, ans + n);
	
	cout << ans[0] << endl;
	

	


}

Measured memory_bytes: 256
n=int(input())
lists=[]
for x in range(n):
  a,b=input().split()
  lists.append([a,int(b),x+1])
lists.sort(key=lambda t:t[1],reverse=True)
lists.sort(key=lambda t:t[0])
for x in range(n):
  print(lists[x][2])

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <bitset>
#include <limits>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
// all_of

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#endif

int H, W;
string s[100];
int c[26];
int f[4];
int main() {
	cin >> H >> W;
	REP(i, 0, H) {
		cin >> s[i];
	}
	REP(i, 0, H) {
		REP(j, 0, W) {
			c[s[i][j] - 'a']++;
		}
	}

	REP(i, 0, 26) {
		f[c[i] % 4]++;
	}

	bool ok = false;
	if (H % 2 == 0 && W % 2 == 0) {
		if (f[0] == 26) ok = true;
	} else if (H % 2 != 0 && W % 2 != 0) {
		if (f[1] + f[3] == 1 && f[2] + f[3] <= H / 2 + W / 2) ok = true;
	} else if (H % 2 != 0 && W % 2 == 0) {
		if (f[1] + f[3] == 0 && f[2] <= W / 2) ok = true;
	} else {
		if (f[1] + f[3] == 0 && f[2] <= H / 2) ok = true;
	}
	cout << (ok ? "Yes": "No") << endl;
	return 0;
}



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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
ll pow2[32];
vector<char>s(32,'0');
vll dp,dp2;

void init(){
	pow2[0]=1LL;
	for(int i=1; i<32; i++)
		pow2[i] = pow2[i-1]*2LL;
	for(int i=0; i<32; i+=2){
		if(dp.empty())dp.eb(pow2[i]);
		else dp.eb(pow2[i]+dp.back());
	}
	for(int i=1; i<32; i+=2){
		if(dp2.empty())dp2.eb(pow2[i]);
		else dp2.eb(pow2[i]+dp2.back());
	}
}

void solve(int x){
	if(x==0)return;
	else if(x<0){
		auto ptr = lower_bound(all(dp2),x*-1)-dp2.begin();
		int next = x+pow2[ptr*2+1];
		s[ptr*2+1]='1';
		solve(next);
	}else{
		auto ptr = lower_bound(all(dp),x)-dp.begin();
		int next = x-pow2[ptr*2];
		s[ptr*2]='1';
		solve(next);
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int x; cin >> x;
	init();
	if(x==0){
		cout << 0 << endl;
		return 0;
	}
	solve(x);
	reverse(all(s));
	bool st=0;
	for(auto ch:s){
		if(ch=='1')st=1;
		if(st)cout << ch;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		// ??????????????°?????¢?????????????????????????????§????´???????array
		int[] count_array = new int[26];

		// ??°???????????¨?????¨??????????????????
		char word_a = 'a';

		while (true) {

			// ???????????\???
			String Strings = input.readLine();

			if (Strings==null) {
				break;
			}

			// 1?????????????????¢??????????????????????????°?????°????????????????????????????´?
			char[] String_array = Strings.toCharArray();

			// ??\?????????????°??????????a~z????????£?????????????????????????????°
			int count = 0;

			// ??????String_array???????´????????????????????????????????????????????????????a~z??§???????????????
			for (int String_spot = 0; String_spot < String_array.length; String_spot++) {

				// AOJ????????¨??????????????????????????????????°??????????
				if (Character.isUpperCase(String_array[String_spot])) {

					String_array[String_spot] = Character.toLowerCase(String_array[String_spot]);

				}

				// a^z?????????????????????????´¢????????¨?????????????????????????????????
				char one_word = String_array[String_spot];

				// ?????????Z????¬??????????????????????
				word_a = 'a';

				// ??\???????????????????????????????????????????????¢?????????????????????????????????????´¢????????????
				for (int word_spot = 0; word_spot <= ('z' - 'a'); word_spot++) {

					// ??\??????????????????????????????????????¢????????????????????????????????¨?????´????????¨???
					if (one_word == word_a) {

						// ????????????
						count = 1;

						// output??¨
						count_array[word_spot] += count;

					}

					// ?¬??????????
					word_a++;

				}

			}
		}

		// ?????????Z????¬??????????????????????
		word_a = 'a';

		// ??\???????????????????????????????????¢?????????????????????z
		for (int word_spot = 0; word_spot < 26; word_spot++) {

			System.out.println(word_a + " " + ":" + " " + count_array[word_spot]);

			word_a++;

		}

	}
}

Measured memory_bytes: 24116
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	char s[101];
	chin(s);
	int l=strlen(s);
	printf("%c%d%c\n",s[0],l-2,s[l-1]);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		
		int a = (n-m)*100 + m*1900;
		
		System.out.println(a<<m);
		in.close();

	}

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    map<ll,ll> mp;
    rep(i,n){
        ll a;cin >> a;mp[a]++;
    }
    ll m;cin >> m;
    bool check=true;
    rep(i,m){
        ll b;cin >> b;
        if(mp[b]<=0)check=false;
        mp[b]--;
    }
    cout << (check? "YES":"NO") <<endl;
}

Measured memory_bytes: 16084
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int X = int.Parse(Console.ReadLine());
		while(true){
			if(IsPrime(X)){
				break;
			} else {
				X++;
			}
		}
		Console.WriteLine(X);
	}
	public static bool IsPrime(int num)
	{
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false;

		double sqrtNum = Math.Sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2){
			if (num % i == 0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 11220
import java.util.*;
public class Main
{
  public static Scanner sc = new Scanner(System.in);
  public static void main(String[]args)
  {
    int n = sc.nextInt();
    int[]height = new int[n];
    for(int i=0;i<n;i++)
      height[i]=sc.nextInt();
    int max = height[0];
    long total =0;
    for(int i=1;i<n;i++)
    {
      if(height[i]==max)
        continue;
      else if(height[i]<max)
        total+=max-height[i];
      else
      {
        max = height[i];
      }
    }
    System.out.println(total);
  }
}


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

#define pb push_back
#define ll long long

using namespace std;

const ll inf = 1e12 + 10;
const int maxn =3e5 + 10;
const int MOD = 1e9 + 7;

int a[maxn];
bool dp[maxn];

int main(){
	int n , k;
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++)
		cin >> a[i];
	for(int i = 0 ; i <= k ; i++){
		for(int j = 0 ; j < n ; j++){
			if(i - a[j] >= 0 && !dp[i-a[j]])
				dp[i] = true;
		}
	}
	if(dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
int main()
{
  int x, y, i, b;
  scanf("%d %d",&x,&y);
  if(x>y){
    while(1){
      b=x%y;
      if(b==0) break;
       else {
	x=y;
	y=b;
      }
    }
  printf("%d\n",y);
  }
  else if(y>x){
    while(1){
      b=y%x;
      if(b==0) break;
     else {
	y=x;
	x=b;
      }
    }
  printf("%d\n",x);
  }
  else if(x==y){
    while(1){
 b=y%x;
      if(b==0)	break;
      else {
	y=x;
	x=b;
      }
    }
    printf("%d\n",x);
  }
  return 0;
}

Measured memory_bytes: 592
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
import sys
sys.setrecursionlimit(10**6)

s = input()
t = input()
N = len(s)
M = len(t)
ans = []

def print_lcs(dp,i,j):
    global ans
    if i == 0 or j == 0:
        return
    if s[i-1] == t[j-1]:
        print_lcs(dp,i-1,j-1)
        ans.append(s[i-1])
    else:
        if dp[i-1][j] >= dp[i][j-1]:
            print_lcs(dp,i-1,j)
        else:
            print_lcs(dp,i,j-1)


def main():
    dp = [[0]*(M+1) for _ in range(N+1)]
    
    for i in range(N):
        for j in range(M):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    
    print_lcs(dp,N,M)
    print(''.join(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 142356
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


int main() {
    using P = pair<int, int>;
    int N, Q;
    cin >> N >> Q;
    multimap<int, P, greater<int>> mps;
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        mps.emplace(pair<int, P>(x, P(s - x, t - x)));
    }
    map<int, int> mp;
    mp.insert(P(-1000000007, -1));
    for (auto itr = mps.begin(); itr != mps.end(); ++itr) {
        auto it = mp.upper_bound(itr->second.second);
        it--;
        int ev = it->second;
        mp.erase(mp.lower_bound(itr->second.first), mp.lower_bound(itr->second.second));
        mp.emplace(P(itr->second.first, itr->first));
        mp.emplace(P(itr->second.second, ev));
    }
    vector<int> D(Q);
    rep(i, Q) {
        cin >> D[i];
    }
    rep(i, Q){
        int d = D[i];
        auto it = mp.upper_bound(d);
        it--;
        cout << it->second << endl;
    }
    return 0;
}



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

const double eps=1e-9;
typedef valarray<double> vec;
typedef valarray<vec> mat;

inline int pivoting(mat &a,int k,int &c){
	int n=a.size(),m=a[0].size(),p=k,ret=0;
	for(;c<m;++c){
		double cmax=abs(a[k][c]);
		range(i,k+1,n){
			if(abs(a[i][c])>cmax){
				p=i,ret=1;
				cmax=abs(a[i][c]);
			}
		}
		if(abs(cmax)>eps) break;
	}
	if(k!=p) swap(a[k],a[p]);
	return ret;
}

int forward(mat &a){
	int n=a.size(),m=a[0].size(),ret=0,c=0;
	rep(i,n-1){
		ret+=pivoting(a,i,c);
		if(abs(a[i][c])<eps) break;
		range(j,i+1,n){
			double coef=a[j][c]/a[i][c];
			range(k,c,m) a[j][k]-=coef*a[i][k];
		}
	}
	return ret;
}

int rnk(mat &a){
	int n=a.size(),m=a[0].size(),ret=0;
	rep(i,n)rep(j,m) if(abs(a[i][j])>eps) ret=i+1;
	return ret;
}

int main(void){
	int n,m;
	cin >> n >> m;
	mat a(vec(0.0,m),n);
	rep(i,m){
		int s,t;
		cin >> s >> t;
		s--,t--;
		a[s][i]+=1.0;
		a[t][i]-=1.0;
	}
	forward(a);
	int ans=m-rnk(a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12876
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	int n, x, l, now= 0;
	cin >>n >> x;
	if (now <= x) ans ++;
	REP(i, n){
		cin >> l;
		now += l;
		if (now <= x) ans ++;
	}
    cout << ans << endl;
}

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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define m_p make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    REP(i,1,10){
        REP(j,1,10){
            if(i*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,X,M=map(int,input().split())
A=[X]
x=(A[0]**2)%M
i=0
while not x in A:
    A.append(x)
    i+=1
    x=(x**2)%M

loopid=A.index(x)
looplen=i-loopid+1
loopsum=sum(A[loopid:])
startsum=sum(A[:loopid])

ans=0
if N-1<loopid:
    ans=sum(A[:N])
else:
    loopnum=(N-1-loopid+1)//looplen if looplen else N-1-loopid
    rest=N-1-(loopid+looplen*loopnum)+1
    ans+=startsum
    ans+=loopnum*loopsum
    ans+=sum(A[loopid:loopid+rest])
print(ans)


Measured memory_bytes: 68572
#include<stdio.h>
int main(){
  int a,b;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
  if ( op == '+' ){
    printf("%d\n",a+b);
  } else if ( op == '-' ){
    printf("%d\n",a-b);
  } else if ( op == '*' ){
    printf("%d\n",a*b);
      } else if ( op == '/' ){
    printf("%d\n",a/b);
  } else if(op=='?'){
    break;
      }
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  auto calc=[&](string t){
    int o=0,tmp=0,app=0,f=1;
    for(int i=0;i<(int)t.size();i++){
      if(t[i]=='*'){
	app=1;
	tmp=o;
	continue;
      }
      if(t[i]=='(') o++;
      else o--;
      if(o<0){
	f=0;break;
      }
    }
    if(o||!app||!f) return;
    ans=max(ans,tmp);
  };
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=n;j++){
      string t=s.substr(i,j-i);
      calc(t);
      
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  int N, K;
  cin >> N >> K;
  int max = (N-1) * (N-2) /2;
  if (max < K) {
  	cout << -1 << endl;
  } else {
  	cout << N-1 + (max-K) << endl;
  	for (int i=1; i<N; i++) {
  		cout << 1 << " " << i+1 << endl;
  	}
  	int more = 0;
  	for (int i=2; i<N; i++) {
  		for (int j=i+1; j<=N; j++) {
  			if (more == max-K) {
  				break;
  			}
  			cout << i << " " << j << endl;
  			more++;
  		}
  		if (more == max-K) {
			break;
		}
  	}
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1E3+7;
const int INF=1e9+7;
int mp[N][N];
int arr[N];
int n,m,k;
vector<int>ve;
int cal(int x,int y,int j){//用来计算第从x到y行第j列的值。
    int sum=0;
    for(int i=x;i<=y;i++)
        sum+=mp[i][j];
    return sum;
}
int check(){
    int c=ve.size(),sum=0;
    for(int k1=1;k1<c;k1++) arr[k1]=0;
    bool flag=0;
    for(int j=1;j<=m;j++){
        for(int k1=1;k1<c;k1++){
            arr[k1]+=cal(ve[k1-1]+1,ve[k1],j);
            if(arr[k1]>k){
                sum++;
                flag=1;
                break;
            }
        }
        if(!flag) continue ;
        flag=0;
        for(int k1=1;k1<c;k1++){
            arr[k1]=cal(ve[k1-1]+1,ve[k1],j);
            if(arr[k1]>k) return INF;
        }
    }
    return sum;
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            char x;
            cin>>x;
            if(x=='1') mp[i][j]=1;
            else mp[i][j]=0;
        }
    }
    int c=(1<<(n-1))-1;
    int ans=INF;
    for(int i=0;i<=c;i++){
        ve.push_back(0);
        for(int j=0;j<n-1;j++)
            if((1<<j)&i) ve.push_back(j+1);
        ve.push_back(n);
        int x=ve.size();
        ans=min(ans,x-2+check());
        ve.clear();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    map<string,string> A;
    A["Sunny"]= "Cloudy";
    A["Cloudy"]= "Rainy";
    A["Rainy"]= "Sunny";
    string s;
    cin >> s;
    cout << A[s] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],b[n],c[n],dp[n][3];
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(int i=1; i<n; i++){
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC133A
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int N = int.Parse(word[0]);
            int A = int.Parse(word[1]);
            int B = int.Parse(word[2]);
            if (N*A<B)
            {
                Console.WriteLine(N*A);
            }
            else if (N*A>B)
            {
                Console.WriteLine(B);
            }
            else if (N*A==B)
            {
                Console.WriteLine(B);
            }
            Console.ReadKey();
        }
    }
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x ;
  cin >> x ;
  ll y = x%11 ;
  if(y==0){
    cout << x/11*2 <<endl ;
    return 0 ;
  }
  if(1<=y && y<=6){
    cout << x/11*2+1 ;
  }
  else{
    cout << x/11*2 + 2 <<endl ;
  }
  
  
  
  return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	std::string s, t;
	std::cin >> s >> t;
	for (int i = 0;i < s.size();i++) {
		std::cout << s[i];
		if (i == s.size() - 1 && s.size() > t.size()) {
			break;
		}
		std::cout << t[i];
	}
	std::cout << std::endl;
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

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

	int ret = 0;
	REP(i, 1, 9) {
		vector<int> v(i + 1);
		do {
			int num = 0;
			int ok = 0;
			rep(j, i) {
				if (v[j] == 0) num += 3 * pow(10, j);
				else if (v[j] == 1) num += 5 * pow(10, j);
				else num += 7 * pow(10, j);
				ok |= 1 << v[j];
			}

			if (num <= N && ok == 7) {
				ret++;
			}

			int pt = 0;
			while (true) {
				v[pt]++;
				if (v[pt] == 3) {
					v[pt] = 0;
					pt++;
				} else break;
			}
		} while (v.back() == 0);
	}

	cout << ret << endl;
}


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

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;

int main(){
   //freopen("in.txt", "r", stdin);
    string s;
    cin >> s;
    int a = (s[0]-'0')*10 + s[1]-'0';
    int b = (s[2]-'0')*10 + s[3]-'0';
    bool f1 = (a >= 1 && a <= 12);
    bool f2 = (b >= 1 && b <= 12);
    if(f1 && f2){
        cout << "AMBIGUOUS" << endl;
    } else if(f1){
        cout << "MMYY" << endl;
    } else if(f2) {
        cout << "YYMM" << endl;
    } else cout << "NA" << endl;
    return 0;
}


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


int main(){
    int N;
    cin>>N;
    if(N/100==7){
        cout<<"Yes"<<endl;
    }
    else if ((N%100)/10==7){
        cout<<"Yes"<<endl;
    }
    else if (N%10==7){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long int lli;
const int inf = 1e9;

int popcount(int n){
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    return (n & 0x0000ffff) + (n >>16 & 0x0000ffff);
}

lli modpow(lli a, lli p){
	lli ret = 1;
	for(int i=63; i>=0; i--){
		ret *= ret;
		if((1LL<<i & p) != 0){
			ret *= a;
		}
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n-1), b(n-1);
	for(int i=0; i<n-1; i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	int m;
	cin >> m;
	vector<int> u(m), v(m);
	for(int i=0; i<m; i++){
		cin >> u[i] >> v[i];
		u[i]--; v[i]--;
	}

	vector<vector<int>> adj(n, vector<int>(n, inf));
	for(int i=0; i<n; i++){
		adj[i][i] = 0;
	}
	for(int i=0; i<n-1; i++){
		adj[a[i]][b[i]] = adj[b[i]][a[i]] = 1;
	}

	vector<bitset<50>> bits(m);
	for(int d=0; d<n-1; d++){
		auto adj2 = adj;
		adj2[a[d]][b[d]] = adj2[b[d]][a[d]] = inf;
		for(int k=0; k<n; k++){
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					adj2[i][j] = min(adj2[i][j], adj2[i][k] +adj2[k][j]);
				}
			}
		}
		for(int i=0; i<m; i++){
			if(adj2[u[i]][v[i]] == inf){
				bits[i][d] = 1;
			}
		}
	}

	lli ans = 0;
	for(int i=0; i<(1<<m); i++){
		lli sign = (popcount(i)%2==0)? 1: -1;
		bitset<50> tmp;
		for(int j=0; j<m; j++){
			if(i>>j&1) continue;
			tmp = tmp|bits[j];
		}
		ans += sign *modpow(2, n-1-tmp.count());
	}
	cout << abs(ans) << endl; 
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <climits>
#define mk make_pair
#define pb push_back
#define scanf scanf_s
#define printf printf_s
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pos;
const ll N = 2010, MOD = 998244353;

ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}

int bb(int v1) {
	if (v1 % 2 == 0)return v1 / 2 - 1;
	else return v1 / 2;
}

ll dp[N][N],n;
pos a[N];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i+1; }
	sort(a , a + n );
	for (int i = n ; i >= 1; i--) {
		for (int j = 0; j <= n - i; j++) {
			int fi = j, li = n - (n-i-j) + 1;
			dp[i - 1][fi + 1] = max(dp[i - 1][fi + 1], dp[i][j] + a[i-1].first * abs(a[i-1].second - (fi + 1)));
			dp[i - 1][fi] = max(dp[i - 1][fi], dp[i][j] + a[i-1].first * abs(a[i-1].second - (li - 1)));
			int ab;
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n+2; i++)ans = max(ans, dp[0][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 26296
// At Coder :: Beginner Contest 178 :: C - Ubiquity 
// https://atcoder.jp/contests/abc178/tasks/abc178_c
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{1000000007};

ll pow(ll base, ll exp, ll mod) {
    ll result = 1;
    base = base % mod;

    if (base == 0) return 0;

    while (exp > 0) {
        if (exp & 1) {
            result = (result * base) % mod;
        }

        exp = exp >> 1;
        base = (base * base) % mod;
    }
    return result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;

    // If there are not two spaces for 0,9, there are no arrays possible.
    if (N < 2) {
        cout << "0\n";
    } else {
        // How many sequences have no nines?
        ll noNines{pow(9LL, N, MOD)};
        // The same number of sequences have no zeros.
        ll noZeros{noNines};
        // How many sequences have no nines *and* no zeros?
        ll noNinesZeros{pow(8LL, N, MOD)};
        // How many sequences are there?
        ll universe{pow(10LL, N, MOD)};
        // PIE: Start with the universe, remove sequences with no zeros, 
        // then remove sequences with no nines.  We have double counted
        // sequences with no nines *and* no zeros, so add them back in.
        ll soln{universe};
        soln = (soln - noNines) % MOD;
        soln = (soln - noZeros) % MOD;
        soln = (soln + noNinesZeros) % MOD;
        if (soln < 0LL) soln += MOD;
        cout << soln << "\n";
    }
    return EXIT_SUCCESS;
}


Measured memory_bytes: 3580
import sys
import math
import queue
import copy
import bisect#2分探索
from collections import deque #popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

#N = int(input())
A, B, C, D = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

while A>0 and C>0:
    C-=B
    if C<=0:
        print('Yes')
        break
    A-=D
    if A<=0:
        print('No')
        break
    #print(A,C)


Measured memory_bytes: 68764
function main(input) {
  const args = input.split('\n');
  const row1 = args[0].split(' ').map(n => parseInt(n, 10));
  const row2 = args[1].split(' ').map(n => parseInt(n, 10));
  
  const H = row1[0],
        W = row1[1],
        h = row2[0],
        w = row2[1];
  
  ans = (H * W) - (h * W) - ((H - h) * w);
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29532
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int a, b, ans = 1000000000, sub;
  for(int i = 1; i <= N / 2; i++){
    sub = 0;
    a = i;
    b = N - i;
    while(a != 0){
      sub += a % 10;
      a /= 10;
    }
    while(b != 0){
      sub += b % 10;
      b /= 10;
    }
    ans = min(ans, sub);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,a[N],s,K,ans,w[N],x[N],l,A[N],B[N];
bool ck(int y){
//	printf("%lld\n",y);
	int zh=0,fh=0,al=0,bl=0;
	for(int i=1;i<=n;++i){
		int k=a[i]%y;
		if(k<=(y>>1)){
			zh+=k;
			A[++al]=k;
		}
		else {
			fh+=y-k;
			B[++bl]=y-k;
		}
	}
	sort(A+1,A+al+1);
	sort(B+1,B+bl+1);
	if(zh>fh){
		int t=(zh-fh)/y;
		for(int i=0;i<t;++i){
			zh-=A[al-i];
		}
		if(K>=zh)return 1;
		else return 0;
	}
	else {
		int t=(fh-zh)/y;
		for(int i=0;i<t;++i){
			fh-=B[bl-i];
		}
		if(K>=fh)return 1;
		else return 0;
	}
}
void se(int z,int y){
	if(z==l+1){
		if(ck(y))ans=max(ans,y);
		return;
	}
	for(int i=0;i<=w[z];++i){
		se(z+1,y);
		y*=x[z];
	}
}
signed main(){
	scanf("%lld %lld",&n,&K);
	for(int i=1;i<=n;++i){
		scanf("%lld",&a[i]);
		s+=a[i];
	}
	for(int i=2;i*i<=s;++i){
		if(s%i==0){
			x[++l]=i;
			w[l]++;
			s/=i;
			while(s%i==0){w[l]++;s/=i;}
		}
	}
	if(s!=1){
		x[++l]=s;
		w[l]=1;
	}
	se(1,1);
	printf("%lld\n",ans);
}

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

int main()
{
    int D, G;
    cin >> D >> G;
  
  	vector<int> P(D), C(D);
    for (int i = 0; i < D; i++) {
        cin >> P[i] >> C[i];
    }

    bool flag = false;
    int goal, sum;
    int minp = 10000;

    for (int bit = 0; bit < (1 << D); bit++) {
        goal = 0;
        sum = 0;
        for (int i = 0; i < D; i++) {
            if (bit & (1 << i)) {
                sum += (P[i] * (i + 1) * 100) + C[i];
                goal += P[i];
            }
        }
        if (sum >= G) {
            minp = min(minp, goal);
        }
    }

    sum = 0;
    goal = 0;
    for (int i = D - 1; i >= 0; i--) {
        for (int j = 1; j <= P[i]; j++) {
            sum += (i + 1) * 100;
            goal++;
            if (sum >= G) {
                break;
            }
        }
        sum += C[i];
        if (sum >= G) {
            break;
        }
    }
    minp = min(minp, goal);
    cout << minp << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char fig[101];
    int num;
    
    while (scanf("%s", fig) != EOF){
        num = 0;
        for (char *pt=fig; *pt!='\0'; pt++){
            switch (*pt){
            case 'I':
                switch(*(pt+1)){
                case 'V':
                    num += 4;
                    pt++;
                    break;
                case 'X':
                    num += 9;
                    pt++;
                    break;
                default:
                    num += 1;
                    break;
                }
                break;
            case 'V':
                num += 5;
                break; 
            case 'X':
                switch(*(pt+1)){
                case 'L':
                    num += 40;
                    pt++;
                    break;
                case 'C':
                    num += 90;
                    pt++;
                    break;
                default:
                    num += 10;
                    break;
                }
                break;
            case 'L':
                num += 50;
                break;
            case 'C':
                switch(*(pt+1)){
                case 'D':
                    num += 400;
                    pt++;
                    break;
                case 'M':
                    num += 900;
                    pt++;
                    break;
                default:
                    num += 100;
                    break;
                }
                break;
            case 'D':
                num += 500;
                break;
            case 'M':
                num += 1000;
                break;
            }
        }
        printf("%d\n", num);
    }
        
    return 0;
}

Measured memory_bytes: 972
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int table[n + 1][n + 1]; rep(i, n + 1) rep(j, n + 1) table[i][j] = 0;
    rep(j, n) {
        int u, k; cin >> u >> k;
        int v;
        rep(l, k) {
            cin >> v;
            table[u][v] = 1;
        }
    }
    int mc[n + 1]; rep(i, n + 1) mc[i] = inf;
    queue<int> q;
    q.push(1);
    mc[1] = 0;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        rrep(i, 2, n + 1) {
            if (table[now][i] == 1 && mc[i] == inf) {
                mc[i] = mc[now] + 1;
                q.push(i);
            }
        }
    }
    rrep(i, 1, n + 1) {
        cout << i << " " << (mc[i] == inf ? -1 : mc[i]) << endl;
    }
}



Measured memory_bytes: 3164
from fractions import gcd

N, M = map(int,input().split())
S = list(input())
T = list(input())

gc = gcd(N, M)

ans = N*M//gc

for i in range(gc):
    if S[N//gc*i] != T[M//gc*i]:
        ans = -1
        break
                
print(ans)

Measured memory_bytes: 6584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string o, e;
  cin >> o >> e;
  
  string ans;
  
  if (o.size() == e.size()) {
    for (int i = 0; i < o.size(); i++) {
      ans += o[i];
      ans += e[i];
    }
  }
  else {
    for (int i = 0; i < e.size(); i++) {
      ans += o[i];
      ans += e[i];
    }
    ans += o[e.size()];
  }
  
  cout << ans;
}

Measured memory_bytes: 3540
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// a^k mod p
int modpow(int a, int k, int p) {
	int ans = 1;
	while (k > 0) {
		if (k % 2 == 1) {
			ans *= a;
			ans %= p;
		}
		a = (a * a) % p;
		k = k / 2;
	}
	return ans;
}

int dp[123456][15];

signed main() {

	string S;
	cin >> S;

	dp[0][0] = 1;
	int keta = 0;
	for(int i=S.length()-1; i>=0; i--){

		char ch = S[i];
		
		int pow = modpow(10, keta, 13);
		if ('0' <= ch && ch <= '9') {
			int d = ch - '0';
			for (int j = 0; j < 13; j++) {
					(dp[keta+1][(j+d*pow)%13] += dp[keta][j] ) %= mod;
			}
		}
		else {
			for (int d = 0; d <= 9; d++) {
				for (int j = 0; j < 13; j++) {
					(dp[keta+1][(j+d*pow)%13] += dp[keta][j]) %= mod;
				}
			}

		}
		keta++;
	}

	cout << dp[S.length()][5] << endl;

	return 0;
}

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

int main(){  
	int N;
	int K;
	cin >> N;
	cin >> K;
	int x[N];
	int move = 0;
	for(int i = 0; i < N; i++){
		cin >> x[i];
	} 
	for(int i = 0; i < N; i++){
		move += min(x[i], K - x[i]) * 2;
	}
	cout << move << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <complex>

using namespace std;
using LL = long long;
using Arrow = complex<LL>;

class Solution {
public:
	double engines(vector<Arrow>& arrows) {
		const int n = arrows.size();
		auto compareAngle = [](const auto& a, const auto& b) {
			return atan2(imag(a), real(a)) < atan2(imag(b), real(b));
		};
		sort(arrows.begin(), arrows.end(), compareAngle);

		Arrow window(0, 0);
		LL ans = 0;
		int R = 0;
		for (int L = 0; L < n; ++L) {
			if (R < L)
				R = L, window = Arrow(0, 0);
			while (R - L < n && norm(window + arrows[R % n]) >= norm(window))
				window += arrows[R % n], ++R;
			ans = max(ans, norm(window)), window -= arrows[L % n];
		}
		return sqrt(ans);
	}
};

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

	vector<Arrow> arrows(n);
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		arrows[i] = Arrow(x, y);
	}

	Solution sol;
	double ans = sol.engines(arrows);
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;

ll N, K, res;

void dfs(int x, int y) {
	--y;
	if (y) {
		for (int i = 2; i*x <= N; ++i) {
			dfs(i*x, y);
		}
	}
	else
		++res;
}

int main(){
	cin >> N >> K;
	for (int i = 1; i != N + 1; ++i) {
		dfs(i, K);
	}
	cout << res << endl;
	return 0;
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
  int x;
  cin >> x;
  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632