akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
ll par[214514];
ll rankk[214514];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i;
		rankk[i]=0;
	}
}
ll find(ll x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}
void unite(ll x, ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(rankk[x]<rankk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rankk[x]==rankk[y])rankk[x]++;
	}
}
signed main(){
	int n,k,l;
	cin>>n>>k>>l;
	vector< pair<int,int> > p,q,gr,sgr;
	map<pair<int,int>,int> mope;
	vector<int> cp,cq;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		p.pb(mp(x-1,y-1));
	}
	for(int i=0;i<l;i++){
		int x,y;
		cin>>x>>y;
		q.pb(mp(x-1,y-1));
	}
	init(n);
	for(int i=0;i<p.size();i++){
		unite(p[i].first,p[i].second);
	}
	for(int i=0;i<n;i++){
		cp.pb(find(i));
	}
	init(n);
	for(int i=0;i<q.size();i++){
		unite(q[i].first,q[i].second);
	}
	for(int i=0;i<n;i++){
		cq.pb(find(i));
	}
	for(int i=0;i<n;i++){
		gr.pb(mp(cp[i],cq[i]));
		mope[ mp(cp[i],cq[i]) ]++;
	}
	for(int i=0;i<n;i++){
		cout<<mope[gr[i]]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 24940
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,n = inm()
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)

t = [BIG]*(h+1)
t[0] = 0
for i in range(n):
    for j in range(h):
        if t[j]>=0:
            k = min(h,j+a[i])
            t[k] = min(t[k], t[j]+b[i])
print(t[h])


Measured memory_bytes: 41832
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;
int a,b,c;
vector<int> d;

int dfs(int n,int cnt,int A,int B,int C){
    if(n == cnt){
        if(min({A,B,C}) == 0){
            return max_int;
        }
        else return abs(A-a) + abs(B-b) + abs(C-c)-30;
    }
    int w = dfs(n,cnt+1,A,B,C);
    int x = dfs(n,cnt+1,A+d[cnt],B,C)+10;
    int y = dfs(n,cnt+1,A,B+d[cnt],C)+10;
    int z = dfs(n,cnt+1,A,B,C+d[cnt])+10;
    return min({w,x,y,z});
}

signed main(){
    cin >> n >> a >> b >> c;
    d.resize(n);
    input(d,n);
    print(dfs(n,0,0,0,0));

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


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

 int main() {

 int N,A;
cin>>N>>A;

int L=A; int R=A+N-1;

 int eat;
 if(R<=0)eat=R;
 else if(L>=0)eat=L;
 else eat=0;

int answer=(R+L)*(R-L+1)/2-eat;
cout<<answer<<endl;

return 0;

}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool flag = true;
  if (n & 1) flag = false;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[i + n / 2]) flag = false;
  }
  cout << (flag ? "Yes\n" : "No\n");
  return 0;
}

Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   int k;cin>>k;
   string s;cin>>s;
   if(sz(s)<=k)cout<<s<<"\n";
   else
   {
       int i=0;
       while(i<k)cout<<s[i],i++;
       cout<<"...\n";
   }
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3644
#include <iostream>
#include <bitset>
#include <algorithm>

using namespace std;

const int max_n = 5000;
int a[max_n];
bitset<max_n + 1> s[2 * max_n + 1];
bool t[2 * max_n + 1];
int n;
int k;
int result = 0;

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= 2 * k; i++) {
        s[i].reset();
    }
    fill(t, t + 2 * k + 1, false);
    
    t[0] = true;
    for (int i = 0; i < n; i++) {
        int x = min(k, a[i]);

        for (int j = k - 1; j >= 0; j--) {
            if (t[j]) {
                t[j + x] = true;
                s[j + x] |= s[j];
                s[j + x][x] = true;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        int x = a[i];
        
        if (x < k) {
            bool found = false;
            for (int j = k; j < k + x && !found; j++) {
                found |= s[j][x];
            }
            
            if (!found) {
                result++;
            }
        }
    }
    
    cout << result << "\n";
    
    return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
int h, w, n;
int a[20000],b[20000],grid[105][105];
string l = " \n";

int main(){
	scanf("%d %d", &h, &w);
	scanf("%d", &n);
//	int idx = 0;
	for (int i = 1 ; i <= n ; i++)
		scanf("%d", &a[i]);
	int idx = 0;
	for (int i = 1 ; i <= n ; i++) {
		for (int j = 0 ; j < a[i] ; j++) {
			b[idx++] = i;	
		}
	}
	idx = 0;
	for(int i = 0 ; i < h ; i++){
		if (i % 2 == 0) {
			for(int j = 0 ; j < w ; j++){
				grid[i][j] = b[idx++];
			}
		} else {
			for(int j = w - 1 ; j >= 0 ; j--){
				grid[i][j] = b[idx++];
			}
		}
	}
	for (int i = 0 ; i < h ; i++) {
		for (int j = 0 ; j < w ; j++) {
			printf("%d%c" , grid[i][j] , l[j == w - 1]);
		}
	}
}

Measured memory_bytes: 384
n,a,b=map(int,input().split())
s=input()
participant=[str(c) for c in s]
gokakua=0
gokakub=0
for i in participant:
    if i=='a':
        if gokakua+gokakub<a+b:
            print("Yes")
            gokakua+=1
        else:
            print("No")
    if i=='b':
        if gokakua+gokakub<a+b and gokakub<b:
            print("Yes")
            gokakub+=1
        else:
            print("No")
    if i=='c':
        print("No")

Measured memory_bytes: 9848
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]++;
  }
  bool flag=1;
  if(n%2==0){
    for(auto c:mp){
      if(c.first%2==0||c.second!=2) flag=0;
    }
  }
  else{
    for(auto c:mp){
      if(c.first==0){
        if(c.second!=1) flag=0;
      }
      else if(c.first%2==1||c.second!=2) flag=0;
    }
  }
  if(flag){
    ll ans=1;
    for(auto c:mp){
      ans*=c.second;
      ans%=mod;
    }
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
  //cout << flag << endl;
}

Measured memory_bytes: 3584
from collections import defaultdict as ddic, deque, Counter
from itertools import permutations, combinations, product
import bisect, heapq

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

def solve(A, B):
    if A >= 13: return B
    if 6 <= A <= 12: return B / 2
    return 0

print solve(*rrm()) 


Measured memory_bytes: 28396
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

const int MAX = 303030;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll power(ll x,ll n) {
	if (n == 0)return 1;
	else if(n % 2 == 1){
		return (x*power(x,n-1)) % MOD;
	}else{
		ll half = power(x, n / 2);
		return (half * half)%MOD;
	}
}

ll N, A, B, C;
ll ans = 0;
int main(){
	cin >> N >> A >> B >> C;
	combinit();
	ll X = (A*inv[A + B]) % MOD;
	ll Y = (B*inv[A + B]) % MOD;
	
	for (ll i = N; i <= 2 * N - 1; i++) {
		ll temp = 1;
		temp *= i;
		temp %= MOD;
		temp *= comb(i - 1, N - 1);
		temp %= MOD;
		temp *= (power(X, N)*power(Y, i - N) + power(Y, N)*power(X, i-N)) % MOD;
		temp %= MOD;
		ans += temp;
		ans %= MOD;
	}

	if (C > 0) {
		ans *= (100*inv[A+B]) % MOD;
		ans %= MOD;
	}
	cout << ans%MOD << endl;
	
	return 0;
}


Measured memory_bytes: 7296
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    while (true) {
        String s = sc.nextLine();

        if ("0".equals(s)) break;

        int ans = 0;
        for (char c : s.toCharArray()) {
            ans += Integer.valueOf(c) - 48;
        }
        pw.println(ans);
    }
    
    pw.flush();
  }
}


Measured memory_bytes: 26204
n=int(input())
if(n%4==0):
    print('Yes')
elif(n%7==0):
    print('Yes')
else:
    k=n
    flag=0
    while(n>0):
        n=n-4
        if(n%7==0):
            flag=1
            break
    while(k>0):
        k=k-7
        if(n%4==0):
            flag=1
            break
    if(flag==1):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
# coding=utf-8

Q = int(input())

S = set()

for i in range(Q):
    qtype, number = map(int, input().split())
    if qtype == 0:
        S.add(number)
        print(len(S))
    elif qtype == 1:
        if number in S:
            print(1)
        else:
            print(0)
    elif qtype == 2:
        try:
            S.remove(number)
        except KeyError:
            pass



Measured memory_bytes: 23364
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> v(N); 
    for(int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    } 
    sort(v.begin(), v.end());
    double av = ( double(v.at(0)) + double(v.at(1)) ) / 2.0;
    for(int i = 2; i < N; i++)
    {
        av = ( av + double(v.at(i))) / 2.0;
    } 
    cout << av << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) (c).begin(), (c).end()

const int INF=1e9;
const int MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    string s;
    while(cin>>s, s!="0") {
        int ans=0;
        rep(i,s.size()) ans+=s[i]-'0';
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

long long ntemples, nshrines, nquestions;
std::vector<long long> shrines;
std::vector<long long> temples;
std::vector<long long> questions;

long long smaller_eq_point(long long target, const std::vector<long long>& v)
{
  long long ok = 0;
  long long ng = (long long)v.size();
  while (1 < abs(ok - ng)) {
    long long mid = (ok + ng) / 2;
    if (v.at(mid) <= target) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return v.at(ok);
}

long long larger_eq_point(long long target, const std::vector<long long>& v)
{
  long long ok = (long long)v.size()-1;
  long long ng = -1;
  while (1 < abs(ok - ng)) {
    long long mid = (ok + ng) / 2;
    if (target <= v.at(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return v.at(ok);
}

long long solve(long long start)
{
  long long left_shrine = smaller_eq_point(start, shrines);
  long long left_temple = smaller_eq_point(start, temples);
  long long right_shrine = larger_eq_point(start, shrines);
  long long right_temple = larger_eq_point(start, temples);
  long long result = LLONG_MAX;

  /*
  std::cout << '\n';
  std::cout << left_shrine << '\n';
  std::cout << left_temple << '\n';
  std::cout << right_shrine << '\n';
  std::cout << right_temple << '\n';
  */

  if (left_shrine <= start && left_temple <= start) {
    result = std::min(result, std::max(start-left_shrine, start-left_temple));
  }
  if (left_shrine <= start && start <= right_temple) {
    result = std::min(result,
        std::min((start-left_shrine)*2+(right_temple-start),
                 (start-left_shrine)  +(right_temple-start)*2));
  }
  if (start <= right_shrine && left_temple <= start) {
    result = std::min(result,
        std::min((right_shrine-start)*2+(start-left_temple),
                 (right_shrine-start)  +(start-left_temple)*2));
  }
  if (start <= right_shrine && start <= right_temple) {
    result = std::min(result, std::max(right_shrine-start, right_temple-start));
  }
  return result;
}

int main()
{
  std::cin >> nshrines >> ntemples >> nquestions;
  for (long long i = 0; i < nshrines; i++) {
    long long tmp;
    std::cin >> tmp;
    shrines.push_back(tmp);
  }
  for (long long i = 0; i < ntemples; i++) {
    long long tmp;
    std::cin >> tmp;
    temples.push_back(tmp);
  }
  for (long long i = 0; i < nquestions; i++) {
    long long tmp;
    std::cin >> tmp;
    questions.push_back(tmp);
  }
  std::sort(shrines.begin(), shrines.end());
  std::sort(temples.begin(), temples.end());
  for (long long i = 0; i < nquestions; i++) {
    std::cout << solve(questions.at(i)) << '\n';
  }
  return 0;
}


Measured memory_bytes: 3828
#include<stdio.h>
int main()
{
    int n,t,i,j,a[100],temp,s=0;
    scanf("%d %d",&n,&t);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(a[j+1]>a[j])
            {
                temp=a[j+1];
                a[j+1]=a[j];
                a[j]=temp;
            }
        }
    }
    for(i=0;i<t;i++)
    {
        s=s+a[i];
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

  int wrong_cnt = 0;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    if (val != i + 1) {
      wrong_cnt++;
    }
  }
  if (wrong_cnt == 0 || wrong_cnt == 2) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}


Measured memory_bytes: 256
/**
 * @jakestrj
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "bits/stdc++.h"
using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define mem(a, b) memset(a, (b), sizeof(a))
#define mem2(a, b) memset(a, (b), sizeof(a[0][0])*len(a)*len(a[0]))
#define sz(x) ((int)(x).size())
#define len(x) (int)(sizeof(x)/sizeof(x[0]))
#define endl "\n"
#define INF 1e18
#define EPS 1e-9
#define PI 2*acos(0)
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
typedef tuple<int, int, int> trio;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef map<int,int> mpii;
typedef set<int> si;

template<class T, int SZ> struct Seg { // SZ should be power of 2
	T seg[2*SZ], ID = 0;

	Seg() { memset(seg,0,sizeof seg); }
	T comb(T a, T b) { return max(a,b); } //change operation to FIT
	// easily change this to min or max
	// comb(ID,b) must equal b

	void build() { peri(i, SZ-1, 0) seg[i] = comb(seg[2*i],seg[2*i+1]); }

	void upd(T p, T value) {  // set value at position p
		for (seg[p += SZ] = value; p > 1; p >>= 1)
			seg[p>>1] = comb(seg[(p|1)^1],seg[p|1]);
		// make sure non-commutative operations work
	}

	T query(T l, T r) {  // sum on interval [l, r]
		T res1 = ID, res2 = ID; r++;
		for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
			if (l&1) res1 = comb(res1,seg[l++]);
			if (r&1) res2 = comb(seg[--r],res2);
		}
		return comb(res1,res2);
	}
};

const int MN = 1e5+10;

int n;
ll C;
vll x,v;

ll ret(){
	vll inDir(n+2);
	Seg<ll, MN> rmq;
	repi(i, 1, n+1){
		inDir[i] = inDir[i-1] + (v[i]-(x[i]-x[i-1]));
	}
	ll tmp=0;
	rmq.upd(n+1, 0);
	peri(i, n, 0){
		tmp += v[i] - (x[i+1]-x[i]);
		rmq.upd(i, tmp);
	}
	ll res=0;
	repi(i, 0, n){
		ll tmp = rmq.query(i+1, n+1) - x[i];
//		cout << tmp << endl;
		res = max(res, (inDir[i] + max(0ll, tmp)));
 	}
 	return res;
}

struct B {
	void solve(std::istream& cin, std::ostream& cout) {
		cin >> n >> C;
		x.clear(); v.clear();
		x.resize(n+2); v.resize(n+2);
		x[0]=0; v[0]=0; //start
		x[n+1] = C; v[n+1]=0; //return to start
		repi(i, 1, n){
		    cin >> x[i] >> v[i];
		}
		//CW:
		ll max_cw = ret();
		//CCW: x[i] = C-x[i]
		reverse(all(v)); reverse(all(x));
		rep(i, 0, sz(x)){
			x[i] = C-x[i];
		}
		ll max_ccw = ret();
		cout << max(max_cw, max_ccw) << endl;
	}
};


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> s[i][j];
    }
  }

  int k = 0;
  vector<vector<int>> a(H, vector<int>(W, 0));
  rep(i, H) {
    bool ok = false;
    rep(j, W) {
      if (s[i][j] == '#') {
        k++;
        ok = true;
      }
      if (ok)
        a[i][j] = k;
    }
  }

  rep(i, H) {
    repr(j, W - 2, 0) {
      if (a[i][j] == 0)
        a[i][j] = a[i][j + 1];
    }
  }

  repp(i, 1, H - 1) {
    rep(j, W) {
      if (a[i][j] == 0)
        a[i][j] = a[i - 1][j];
    }
  }

  repr(i, H - 2, 0) {
    rep(j, W) {
      if (a[i][j] == 0)
        a[i][j] = a[i + 1][j];
    }
  }

  cout << a << "\n";
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void){

	int width,height,wcount;

	while(1){
		scanf("%d",&height);
		scanf("%d",&width);
		
		if(height==0&&width==0){
			break;
		}
		
		for(wcount=width;wcount>0;wcount--){
				printf("#");
		}
		printf("\n");
		
		while(height-2>0){
			printf("#");
			for(wcount=width;wcount-2>0;wcount--){
				printf(".");
			}
			printf("#");
			printf("\n");
			height--;
		}
		
		for(wcount=width;wcount>0;wcount--){
				printf("#");
		}
		printf("\n\n");
	}
		
	return 0;
}

Measured memory_bytes: 2608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            Integer l[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                l[i] = Integer.valueOf(in.next());
            }
            int ans = 0;

            Arrays.sort(l, Comparator.reverseOrder());

            for (int i = 0; i < k; i++) {
                ans += l[i];
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23252
#include <vector>
#include <iostream>
#include <map>
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> A(N+1);
  for(int i = 1; i <= N; ++i)
    cin >> A[i], A[i] +=  K-1+A[i-1], A[i] %= K;
  
  map<int,int> C;
  long long ans = 0;
  ++C[0];
  for(int i = 1; i <= N; ++i){
    A[i] %= K;
    if(i >= K) --C[A[i-K]];
    // cerr << i << " " << C[A[i]] << endl;
    ans += C[A[i]];
    ++C[A[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
int map[220][220];
int r[220];
int N,M,R;

void floyd()
{
	for(int k=1;k<=N;k++)
    {
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<=N;j++)
            {
               map[i][j]=min(map[i][k]+map[k][j],map[i][j]);
            }
        }
    }
}

int main()
{
	while(~scanf("%d%d%d",&N,&M,&R))
	{
		for(int i=0;i<R;++i)
			scanf("%d",&r[i]);
		//memset(map,INF,sizeof(map));
		for(int i=0;i<=N;++i)
		{
			for(int j=0;j<=N;++j)
				if(i == j)
					map[i][j] = 0;
				else
					map[i][j] = INF;
		}
 
		for(int i=0;i<M;++i)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			if(map[x][y]>z || map[y][x]>z)
			{
				map[x][y]=map[y][x]=z;
			}
		}
		floyd();
		sort(r,r+R);
		int ans = INF;
		do
		{
			int sum = 0;
			for(int i=0;i<R-1;++i)
			{
				sum+=map[r[i]][r[i+1]];
			}
			ans=min(ans,sum);
		}while(next_permutation(r,r+R));
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

const int N=105;

int n,m,a[N];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	int ans=0;
	for (int i=1;i<=n&&a[i]<=m;i++)
	{
		m-=a[i];
		ans++;
	}
	if (m&&ans==n) ans--;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;

int N, A[20],B[20];

int bit_count(int K, int M) {

	int ret = 0;
	for(int i=1;i<=M;i++) { if (K % 2 == 1) { ret++; } K /= 2; }
	return ret;
}


int dp[1 << 20][55];

int INF = 9999;

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = 1; i <= N; i++) {
		cin >> B[i];
	}


	
	dp[0][0] = 0;

	for (int k = 1; k < (1 << N); k++) {
		for (int m = 0; m <= 50; m++) {
			dp[k][m] = INF;
		}
	}

	for (int k = 0; k < (1 << N); k++) {
		for (int m = 0; m <= 50; m++) {
			if (dp[k][m] == INF) { continue; }

			int num = bit_count(k, N);

			for (int j = 1; j <= N; j++) {
				if (k >> (j - 1) & 1) { continue; }
				int val;
				if (abs(num + 1 - j) % 2 == 0) { val = A[j]; }
				else { val = B[j]; }
				int tentou = j - 1 - bit_count(k, j - 1);
				//cout << "tentou= " << tentou << endl;
				int next = k | (1 << (j - 1));
				if (m <= val) {
					dp[next][val] = min(dp[next][val], dp[k][m] + tentou);
				}
			}
		}
	}

	int ans = INF;

	for (int m = 0; m <= 50; m++) {
		ans = min(ans, dp[(1<<N)-1][m]);
	}

	if (ans == INF) { cout << -1 << endl; }
	else { cout << ans << endl; }

	

	/*for (int k = 0; k < (1 << N); k++) {
		cout << bitset<3>(k) << "  " << "dp.first= " << dp[k].first << "  dp.second= " << dp[k].second << endl;

	}*/

	return 0;
}

Measured memory_bytes: 57600
a,b=map(int,input().split()) 
c=10000 
d=5000 
e=1000 
ans=False 
for i in range(a+1): 
	for j in range(a+1): 
		if i*c+j*d+(a-i-j)*e==b and a-i-j>=0: 
			ans=True 
			break 
	if(ans):break 
if(ans):print(i,j,a-i-j) 
else:print(-1,-1,-1) 


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main() {
  int n, t; cin >> n >> t;
  int minc = INF;
  for (int i = 0; i < n; i++) {
    int c, time; cin >> c >> time;
    if (t >= time && minc > c) minc = c;
  }
  cout << (minc != INF ? to_string(minc) : "TLE") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    long int N,A,B,S;
    scanf("%ld %ld %ld",&N,&A,&B);
    if (N>(A+B)) {
        S=(N/(A+B))*A;
        if (N%(A+B)>A) {
            S+=A;
        }
        else{
            S+=(N%(A+B));
        }
    }
    else{
        if (N>A) {
            S=A;
        }
        else{
            S=N;
        }
    }
    
    printf("%ld\n",S);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    int a,now=1;
    rep(i,n) {
        cin >> a;
        if (a==now) ++now;
    }
    if (now==1) cout << -1 << endl;
    else cout << n-now+1 << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

ll dp[100001][13];

int main() {
  string S;
  cin >> S;

  dp[0][0] = 1;
  rep(i, S.size()) rep(j, 13) if (dp[i][j] != 0) rep(k, 10) {
    if (S[i] != '?' && (S[i] - '0') != k) continue;
    int v = (j * 10 + k) % 13;
    dp[i + 1][v] += dp[i][j];
    dp[i + 1][v] %= MOD;
  }

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


Measured memory_bytes: 10624
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	long double x[20];
	string u[20];
	scan(N);
	int bai=380000;
	long double ans=0;
	rep(i,N){
		scan(x[i]);scan(u[i]);
		if(u[i][0]=='B') ans+=x[i]*bai;
		else ans+=x[i];
	}
	prin(ans);

	return 0;
}


Measured memory_bytes: 256
import heapq as h
import math
import numpy as np
import copy
import itertools

 
# n,m = map(int,input().split())
n = int(input())
# l = list(map(lambda x:-int(x),input().split()))
ll = []
for _ in range(n):
    ll.append(list(map(int, input().split())))
dis = []
sum = 0
for v in itertools.permutations(ll, n):
    for i in range(n-1):
        sum += math.sqrt((v[i][0] - v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2)

    

    # dis.append(math.sqrt((v[0][0] - v[1][0])**2 + (v[0][1]-v[1][1])**2))
print(sum/math.factorial(n))

# sum = 0
# for i,v in enumerate(itertools.permutations(dis, n-1)):
#     sum += v[0] + v[1]
# print(sum/len(dis))
# print(dis)




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

using namespace std;

int main() {
  int n, a;
  cin >> n;
  bool all_even = true;
  for (int i = 0; i < n; i++) {
    cin >> a;
    all_even &= (a & 1) == 0;
  }
  if (all_even) {
    cout << "second\n";
  }
  else {
    cout << "first\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
  int N,M,X;
  cin>>N>>M>>X;
  vector<int>A(M);
  rep(i,M){
      cin>>A[i];
  }
  sort(A.begin(),A.end());
  int cnt=0;
  int cn=0;
  rep(i,M){
      if(A[i]<X){
          cnt++;
      }
      else{
          cn++;
      }
  }
  cout<<min(cnt,cn)<<endl;
}



Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

string s;

string colortable[] = { "black", "blue", "lime", "aqua",
"red", "fuchsia", "yellow", "white" };
double numtable[8][3]={
{ 0, 0, 0 },
{ 0, 0, 255 },
{ 0, 255, 0 },
{ 0, 255, 255 },
{ 255, 0, 0 },
{ 255, 0, 255 },
{ 255, 255, 0 },
{ 255, 255, 255 }
};

double changenum(string s){
	double res = 0;
	REP(i, 2){
		double num;
		if (s[i] >= '0'&&s[i] <= '9') num = s[i] - '0';
		else if (s[i] == 'a')num = 10;
		else if (s[i] == 'b')num = 11;
		else if (s[i] == 'c')num = 12;
		else if (s[i] == 'd')num = 13;
		else if (s[i] == 'e')num = 14;
		else if (s[i] == 'f')num = 15;
		
		if (i == 0)res += num * 16;
		else res += num;
	}
	return res;
}

void solve(){

}

int main(){
	while (cin >> s&&s != "0"){
		int ans;
		double dk = INF, rk = changenum(s.substr(1, 2)),
			gk = changenum(s.substr(3, 2)), bk = changenum(s.substr(5, 2));
		REP(i, 8){
			double num = sqrt(pow(numtable[i][0] - rk, 2)
				+ pow(numtable[i][1] - gk, 2)
				+ pow(numtable[i][2] - bk, 2));
			if (num - dk < EPS){
				dk = num;
				ans = i;
			}
		}
		cout << colortable[ans] << endl;
	}
}

Measured memory_bytes: 1188
a,b,c=map(int,input().split())
if (a**2)+(b**2)==(c**2):
    s=a*b/2
elif (a**2)+(c**2)==(b**2):
    s=a*c/2
elif (b**2)+(c**2)==(a**2):
    s=b*c/2
print(int(s))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double x, h;
  while(cin >> x >> h) {
    if(x == 0 && h == 0) break;
    printf("%.10f\n", x*x + 2*x*sqrt(h*h + x*x/4.0));
  }
  return 0;
}

Measured memory_bytes: 1236
answers = []

def get_answer(n, m, gems_coordinate, operation_set, answers)
  visited_coordinate = []
  now = [10,10]
  operation_set.each do |ope|
    if ope[0] == "N"
      ope[1].times do
        now[1] += 1
        visited_coordinate << Marshal.load(Marshal.dump(now))
      end
    end
    if ope[0] == "E"
      ope[1].times do
        now[0] += 1
        visited_coordinate << Marshal.load(Marshal.dump(now))
      end
    end
    if ope[0] == "S"
      ope[1].times do
        now[1] += -1
        visited_coordinate << Marshal.load(Marshal.dump(now))
      end
    end
    if ope[0] == "W"
      ope[1].times do
        now[0] += -1
        visited_coordinate << Marshal.load(Marshal.dump(now))
      end
    end
  end
  gems_coordinate.each do |g|
    flag = false
    visited_coordinate.each do |v|
      flag = true if v[0] == g[0] && v[1] == g[1]
    end
    return answers << "No" if flag == false
  end
  return  answers << "Yes"
end


while true
  n = gets.to_i
  gems_coordinate = []
  operation_set = []
  break if n == 0
  n.times do
    array = gets.chomp.split(" ").map(&:to_i)
    x = array[0].to_i
    y = array[1].to_i
    gems_coordinate << [x, y]
  end
  m = gets.to_i
  m.times do
    array = gets.chomp.split(" ")
    x = array[0].to_s
    y = array[1].to_i
    operation_set << [x, y]
  end
  answers = get_answer(n, m, gems_coordinate, operation_set, answers)
end

answers.each do |ans|
  puts ans
end

Measured memory_bytes: 9616
#include <stdio.h>

int is_median(int a, int n1, int n2)
{
  return (n1 <= a && a <= n2) || (n2 <= a && a <= n1);
}

int main(int argc, char** argv)
{
  int n;
  scanf("%d", &n);
  
  int* p = malloc(sizeof(int)*n);
  int i;
  for (i = 0; i < n; i++)
  {
    scanf("%d", p+i);
  }
  
  int result = 0;
  for (i = 1; i < n-1; i++)
  {
    if (is_median(p[i], p[i-1], p[i+1]))
    {
      result++;
    }
  }
  
  printf("%d", result);
  return 0;
}

Measured memory_bytes: 128
from itertools import accumulate as acc
import sys

if __name__ == "__main__":
    s = sys.stdin.readlines()
    N, M, Q = map(int, s[0].split())
    LR = [[0]*N for _ in [0]*N]
    for l, r in (map(int, e.split()) for e in s[1:M + 1]):
        LR[l - 1][r - 1] += 1

    S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in LR))]
    print('\n'.join(map(str, (S[q - 1][N - p] for p, q in (map(int, e.split()) for e in s[M + 1:])))))


Measured memory_bytes: 38468
#!/usr/bin/python3
# -*- coding: utf-8 -*-

s = input()
revs = s[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']


def scan(n):
    for w in words:
        if revs[n:].startswith(w):
            return len(w)
    print('NO')
    exit()


n = 0
while revs[n:] != '':
    n += scan(n)

print('YES')


Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    reverse(all(S));
    vector<int> A(N+1);
    int b = 1;
    rep(i,N) {
        int k = S[i] - '0';
        A[i+1] = k*b;
        A[i+1] += A[i];
        A[i+1] %= 2019;
        b *= 10;
        b %= 2019;
    }

    map<int, ll> dic;
    rep(i,N+1) dic[A[i]]++;
    ll ans = 0;
    for (auto i : dic) {
        ans += i.second*(i.second-1)/2;
    }

    cout << ans << ln;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int d, g;
    cin >> d >> g;
    g /= 100;
    vector<int> p(d), c(d);
    REP(i, d){
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    
    int ans = INF;
    for(int mask = 0; mask < (1 << d); mask++){
        int sum = 0, cur = 0;
        REP(j, d) if(mask & (1 << j)){
            sum += (j+1) * p[j] + c[j];
            cur += p[j];
        }

        for(int j = d-1; j >= 0; j--) if(!(mask & (1 << j))){
            if(sum >= g) break;
            REP(k, p[j]){
                if(sum >= g) break;
                sum += j+1;
                cur++;
            }
        }
        if(sum >= g){
            ans = min(ans, cur);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, num;
    cin >> n;
    vector<vector<ll>> sum(2, vector<ll> (n+2));
    sum[0][0] = 0, sum[1][0] = 0, sum[0][1] = 0, sum[1][1] = 0;
    for(int i = 2; i <= n+1; i++) {
        cin >> num;
        sum[i%2][i] = sum[i%2][i-1] + 2*num;
        sum[(i%2 + 1)%2][i] = sum[(i%2 + 1)%2][i-1];
    }
    for(int i = 2; i <= n+1; i++) {
        cout << (sum[i%2][n+1]-sum[(i%2+1)%2][n+1])/2 - sum[i%2][i-2] + sum[(i%2+1)%2][i-1] << " ";
    }
    cout << endl;
    return 0; 
}

Measured memory_bytes: 2928
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            Console.WriteLine(doCollatz(n));
        }
    }
    public static long doCollatz(int n)
    {
        var count =0;
        while (n != 1)
        {
            if (n % 2 == 0) n /= 2;
            else n = 3 * n + 1;
            count++;
        }
        return count;
    }
}

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

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	std::vector<int> a(n);
	for (int i{}; i < n; i++) scanf("%d", &a[i]);
	std::vector<bool> win(k + 1);
	for (int i{}; i < k; i++)
	{
		if (win[i]) continue;
		for (int j{}; j < n; j++)
			if (i + a[j] <= k)
				win[i + a[j]] = true;
	}
	if (win[k])
		printf("First\n");
	else
		printf("Second\n");

	return 0;
}

Measured memory_bytes: 256
from math import floor
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    A,B,N = map(int, readline().split())

    if N < B:
        print(floor(A * N / B) - A * floor(N / B))
    else:
        print(floor(A * (B-1) / B) - A * floor((B-1) / B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  string a,b; cin >> a >> b;
  double v = sqrt(stoi(a+b));
  COUT(v == floor(v) ? "Yes" : "No");
  return 0;
}

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

int main(){

  int N;
  long long D;
  long long x, y;
  int count = 0;
  cin >>N >> D;
  D = D * D;
  
  for(int i = 0; i < N; i++){
  	cin >> x >> y;
    if(x*x + y*y <= D){
      count+=1;
      //cout << x << " " << y << endl;
  }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3608
from collections import deque
s = deque(input())
n = int(input())
q = []
for i in range(n):
  query = list(input().split())
  q.append(query)
  
a = 1
for i in range(n):
  if int(q[i][0]) == 1:
    a *= -1
  else:
    if int(q[i][1]) == 1:
      if a > 0:
        s.appendleft(q[i][2])
      else:
        s.append(q[i][2])
    else:
      if a > 0:
        s.append(q[i][2])
      else:
        s.appendleft(q[i][2])
s = list(s)
s = "".join(s)
if a > 0:
  print(s)
else:
  s = s[::-1]
  print(s)

Measured memory_bytes: 34932
import math as m

n = int(input())
k = int(input())

def f(n,k):
    l = len(str(n))
    if l < k:
        ans = 0
    elif k == 0:
        ans = 1
    elif l == k:
        t = 10 ** (k-1)
        ans = (n//t-1) * f(t-1, k-1) + f(n%t,k-1)
    else:
        ans =  m.factorial(l-1) // m.factorial(k) // m.factorial(l-1-k) * (9 ** k)
        t = n % (10**(l-1))
        ans += f(t,k-1) + f(10**(l-1)-1,k-1)* (n// (10**(l-1))-1)
    return ans

ans = f(n,k)

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main ()
{

long int k,a,i,b;
//cin>>k;
cin>>k>>a>>b;
for( long int i=a;i<=b;i++)
{
    if(i%k==0)
    {
        cout<<"OK"<<endl;
        break;
    }
  if( i==b)
    cout<<"NG"<<endl;
}
    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cerr << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll A[1<<20];
ll B[1<<20];

int main() {

    //freopen("lazy_loading.txt","r",stdin);
    //freopen("output_file_name.txt","w",stdout);
    int n;cin>>n;
    rep(i, n) cin>>A[i]>>B[i];

    ll add = 0;
    for(int i = n-1;i >= 0;i--) {
        A[i] += add;

        if(A[i]%B[i] == 0) continue;

        add += ((A[i]/B[i]) + 1)*B[i] - A[i];
        //debug(add);
    }

    cout<<add<<endl;

    return 0;
}


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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int cnt=0;
	for(int i=0;i<10000;i++){
		if(A%2==1||B%2==1||C%2==1){
			cout << cnt;
			return 0;
		}
		int tmpA=A;
		int tmpB=B;
		int tmpC=C;
		tmpA=B/2+C/2;
		tmpB=A/2+C/2;
		tmpC=A/2+B/2;
		A=tmpA;
		B=tmpB;
		C=tmpC;
		cnt++;
	}
	cout << -1;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int k; cin >> k;

    ll sum = 0;

    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int l = 1; l <= k; ++l) {
                sum += __gcd(i, __gcd(j, l));
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200 + 2;
ll p[70];
bool chk(ll x) {
    for(int i = 61; i >= 0; i--)
    {
        if(!(x >> (ll)i))
            continue;
        if(!p[i]) {
            p[i] = x;
            return 1;
        }
        x ^= p[i];
    }
    return 0;
}
void Get_LB(ll x) {
    for(int i = 61; i >= 0; i--)
    {
        if(!(x >> (ll)i))
            continue;
        if(!p[i])
        {
            p[i] = x;
            break;
        }
        x ^= p[i];
    }
}

int T;
int n; ll a[N]; char s[N];

int main() {
	scanf("%d", &T);
	while (T --) {
		scanf("%d", &n);
		for (int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
		scanf("%s", s + 1);
		memset(p, 0, sizeof(p));
		bool ok = 1;
		for (int i = n; i >= 1; i --) {
			if (s[i] == '1') {
				if (chk(a[i])) ok = 0;
			} else {
				Get_LB(a[i]);
			}
		}
		printf("%s\n", ok ? "0" : "1");
	}
}

Measured memory_bytes: 3652