akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

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

const double EPS = 1e-10;
const int INF = 1001001001;

struct Edge{
	Edge(int s, int d, int c) : src(s), dst(d), cost(c){}
	int src, dst, cost;
};

vector<Edge> G[20];
int cost[20];
int f(int now, int pre, int dist)
{
	cost[now] = dist;
	int sum = 0;
	rep(i, G[now].size()){
		Edge next = G[now][i];
		if(next.dst != pre && G[next.dst].size() > 1)
			sum += f(next.dst, now, dist+next.cost) + next.cost;
	}
	return sum;
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		fill(cost, cost+n, 0);
		rep(i, n)
			G[i].clear();
		rep(i, n-1){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			--a;
			--b;
			G[a].push_back(Edge(a, b, c));
			G[b].push_back(Edge(b, a, c));
		}
		int sum = f(0, -1, 0);
		printf("%d\n", sum*2-*max_element(cost, cost+n));
	}
	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <deque>

struct Enemy
{
    int pos{};
    int hp{};
};

struct Attack
{
    int pos{};
    int count{};  
};

int main()
{
    int n{}, d{}, a{};
    std::cin >> n >> d >> a;
    std::vector<Enemy> enemy(n);
    for (int i = 0; i < n; i++) {
        std::cin >> enemy[i].pos >> enemy[i].hp;
    }
    std::sort(enemy.begin(), enemy.end(), [](const auto& e1, const auto& e2) {
        return e1.pos < e2.pos;
    });
    long long result = 0;
    std::deque<Attack> attacks;
    int tmpCount = 0;
    for (auto itr = enemy.begin(); itr != enemy.end(); ++itr) {
        while (tmpCount > 0 && attacks.front().pos < itr->pos - d) {
            result += attacks.front().count;
            tmpCount -= attacks.front().count;
            attacks.pop_front();
        }
        int count = itr->hp / a;
        if (itr->hp % a > 0) count++;
        if (count > tmpCount) {
            attacks.emplace_back(Attack{ itr->pos + d, count - tmpCount });
            tmpCount = count;
        }
    }
    result = std::accumulate(
        attacks.begin(),
        attacks.end(),
        result,
        [](long long acc, const Attack& x) {
            return acc + x.count;
        });
    
    std::cout << result << std::endl;

    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, c = 0, d = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i += 2) {
    c++;
  }
  for (int i = 2; i <= n; i += 2) {
    d++;
  }
  c = max(c, d);
  puts(c >= k ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	string s;cin>>s;
	int ans=0;
	rep(i,s.size())if(s[i]=='o')ans++;
	if(15-s.size()+ans>=8)cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

int main()
{
    ll n, m;
    cin >> n >> m;

    priority_queue<ll> pq;

    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        pq.push(x);
    }

    for (int i = 0; i < m; ++i) {
        ll t = pq.top();
        pq.pop();
        if (t == 0)
            break;
        pq.push(t / 2);
    }

    ll sum = 0;
    while (!pq.empty()) {
        sum += pq.top();
        pq.pop();
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1400
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = map(int, input().split())
abcd = [0] * q
for i in range(q):
    abcd[i] = list(map(int, input().split()))

def dfs(seq):
    if len(seq) == n:
        yield seq
        return
    if len(seq) == 0:
        _max = 1
    else:
        _max = seq[-1]
    for i in range(_max, m+1):
        new_seq = seq.copy()
        new_seq.append(i)
        yield from dfs(new_seq)

ans = 0
for s in dfs([]):
    tmp_ans = 0
    for a, b, c, d in abcd:
        if (s[b-1] - s[a-1]) == c:
            tmp_ans += d
    ans = max(ans, tmp_ans)
print(ans)


Measured memory_bytes: 9128
A=[]
for _ in range(3):
    x=list(int(i) for i in input().split())
    A.append(x)
M=[[0 for i in range(3)]for j in range(3)]
n=int(input())

for _ in range(n):
    p=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==p:
                M[i][j]=1
                break
bool=False
for i in range(3):
    if bool is False:
        sum=0
        for j in range(3):
            sum+=M[i][j]
        if sum==3:
            bool=True
for i in range(3):
    if bool is False:
        sum=0
        for j in range(3):
            sum+=M[j][i]
        if sum==3:
            bool=True
if (M[0][0]+M[1][1]+M[2][2])==3:
    bool=True
if (M[0][2]+M[1][1]+M[2][0])==3:
    bool =True
if bool:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
n = int(input())
x = list(map(int,input().split()))
#x = sorted(list(map(int,input().split())),reverse=True)
#nmax = max(x)
#ans = 2*nmax-sum(x)
lst = []

  
nmi = min(x)
nma = max(x)
del x[x.index(nmi)]
del x[x.index(nma)]

mainus = [i for i in x if i < 0]
plus = [i for i in x if i >= 0]
for i in mainus:
  lst.append(str(nma)+" "+str(i))
  nma -= i
for i in plus:
  lst.append(str(nmi)+" "+str(i))
  nmi -= i
lst.append(str(nma)+" "+str(nmi))
print(nma-nmi)
for i in lst:
  print(i)
"""
while max(x) > -1 and len(x) > 1:
  mi = min(x)
  ma = max(x)
  lst.append(str(mi)+" "+str(ma))
  del x[x.index(mi)]
  del x[x.index(ma)]
  x.append(mi - ma)

for i in range(len(x)):
  lst.append(str(nma)+" "+str(i))
  nma += i
print(nmi - nma)
for i in range(len(lst)):
  print(lst[i])
print(nmi,nma)
"""

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

int main(){
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if (u==s){
		a--;
	} else {
		b--;
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
vi adj[200005];
ll mark[200005]={0},y;
void dfs(ll x)
{
    mark[x]=1;
    y++;
    fr(i,0,adj[x].size())
    {
        if(mark[adj[x][i]]==0)
        {
            dfs(adj[x][i]);
        }
    }
}
int main()
{
    fast;
   ll p=1;
   //std::cin >> t;
   while(p--)
   {
       ll n;
       std::cin >> n;
       ll presum[n]={0},a[n];
       fr(i,0,n)
       std::cin >> a[i];
       rf(i,n-1,0)
       {
           if(i==n-1)
           presum[i]=a[i];
           else
           presum[i]=(presum[i+1]+a[i])%mod;
       }
       ll sum=0;
       fr(i,0,n-1)
       {
           sum=(sum+(presum[i+1]*a[i])%mod)%mod;
       }
       cout<<sum<<"\n";
   }
}


Measured memory_bytes: 11420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int now = 1;
	int cnt = 0;
	vector<int> num;
	rep(i,n){
		if(now==s[i]-'0') cnt++;
		else{
			num.push_back(cnt);
			cnt = 1;
			now = 1 - now;
		}
	}
	num.push_back(cnt);
	if(num.size()%2==0) num.push_back(0);

	int left = 0;
	int right = 0;
	int tmp = 0;
	int add = 2*k+1;
	int ans = 0;

	for(int i = 0; i < num.size(); i+=2){
		int nextleft = i;
		int nextright = min(i+add, (int)num.size());

		while(left < nextleft){
			tmp -= num[left];
			left++;
		}

		while(right < nextright){
			tmp += num[right];
			right++;
		}

		chmax(ans, tmp);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}
int n,m;

int check(int i,int j)
{
	if(i<1||j<1||i>n||j>m) return 0;
	return 1;
}

int main(){
   
   cin>>n>>m;
   int vis[n+1][m+1];
   memset(vis,0,sizeof(vis));
   char c[n+1][m+1];
   queue< pair<int,int > > q;
   for(int i=1;i<=n;i++)
   {
   	 for(int j=1;j<=m;j++)
   	 {
   	 	cin>>c[i][j];
   	 	if(c[i][j]=='#'){
   	 		vis[i][j]=1;
   	 		q.push({i,j});
   	 	}
   	 }

   }
   

   while(!q.empty()){
   	  pair<int,int> k= q.front();
   	  int i=k.first;
   	  int j=k.second;
   	  q.pop();
      if(check(i+1,j)){
      	   if(!vis[i+1][j]){
      	   	   q.push({i+1,j});
      	   	   vis[i+1][j]=1+vis[i][j];
      	   }
      }
      if(check(i,j+1)){
      	   if(!vis[i][j+1]){
      	   	   q.push({i,j+1});
      	   	   vis[i][j+1]=1+vis[i][j];
      	   }
      }
      if(check(i-1,j)){
      	   if(!vis[i-1][j]){
      	   	   q.push({i-1,j});
      	   	   vis[i-1][j]=1+vis[i][j];
      	   }
      }
      if(check(i,j-1)){
      	   if(!vis[i][j-1]){
      	   	   q.push({i,j-1});
      	   	   vis[i][j-1]=1+vis[i][j];
      	   }
      }

   }
   
   int ans=0;
   for(int i=1;i<=n;i++)
   {
   	  for(int j=1;j<=m;j++)
   	  {
   	  	ans=max(ans,vis[i][j]);
   	  }
   } 

   cout<<ans-1<<endl;



}

Measured memory_bytes: 13328
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}

int main()
{
	int r;
	cin >> r;
	cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static long[] a;
        static long N;
        static long K;
        
        static void Main(string[] args)
        {
          //入力を受け取る
          //long N = int.Parse(Console.ReadLine());
          long[] AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
          long A = AB[0];
          long B = AB[1];
          long mld = Gcd(A, B);;
          


          var count = 1;
          if(mld%2 == 0){
            while(mld%2 == 0){
              mld = mld/2;
            }
            count++;
          }
          
          for(long i= 3;i*i < mld ;i+=2){
            if(mld%i == 0){
              while(mld%i == 0){
                mld = mld/i;
              }
              count++;
            }
          }
          
          if(mld!=1){
            count++;
          }
          
          //結果を出力
          Console.WriteLine(count);
        }
  
          // ユークリッドの互除法 
        static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }
 }

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int card[3][3];

int solve(){
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> card[i][j];
    }
  }
  int n;  cin >> n;
  for(int i=0; i<n; i++){
    int b;  cin >> b;
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if(card[j][k] == b){
          card[j][k]-=b;
          continue;
        }
      }
    }
  }

  for(int i=0; i<3; i++){
    int sum = 0;
    for(int j=0; j<3; j++){
      sum += card[i][j];
    }
    if(sum==0){
      cout << "Yes" << endl;
      return 0;
    }
  }

  for(int i=0; i<3; i++){
    int sum = 0;
    for(int j=0; j<3; j++){
      sum += card[j][i];
    }
    if(sum==0){
      cout << "Yes" << endl;
      return 0;
    }
  }

  int sum_l = 0, sum_r = 0;
  for(int i=0; i<3; i++){
    sum_l += card[i][i];
    sum_r += card[i][2-i];
  }
  if(sum_l==0 || sum_r==0)  cout << "Yes" << endl;
  else  cout << "No" << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

typedef struct{
    ll i;
    ll j;
    ll depth;
}data;


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

    ll H,W;
    cin >> H >> W;
    char A[H+2][W+2];
    for(int i = 0; i < H+2;i++){
        for(int j = 0; j < W;j++){
            A[i][j] = '#';
        }
    }

    queue<data> q;

    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            cin >> A[i+1][j+1];
            if(A[i+1][j+1]  == '#'){
                data tmp = {i+1,j+1,0};
                q.push(tmp);
            }
        }
    }
    ll ans = 0;
    while(!q.empty()){
        data dt = q.front();
        q.pop();
        ans = max(ans,dt.depth);
        if(A[dt.i-1][dt.j] == '.'){
            A[dt.i-1][dt.j] = '#';
            data tmp = {dt.i-1,dt.j,dt.depth+1};
            q.push(tmp);
        }
        if(A[dt.i][dt.j-1] == '.'){
            A[dt.i][dt.j-1] = '#';
            data tmp = {dt.i,dt.j-1,dt.depth+1};
            q.push(tmp);
        } 
        if(A[dt.i+1][dt.j] == '.'){
            A[dt.i+1][dt.j] = '#';
            data tmp = {dt.i+1,dt.j,dt.depth+1};
            q.push(tmp);
        } 
        if(A[dt.i][dt.j+1] == '.'){
            A[dt.i][dt.j+1] = '#';
            data tmp = {dt.i,dt.j+1,dt.depth+1};
            q.push(tmp);
        } 
    }

    cout << ans << endl;


    

    return 0;
}

Measured memory_bytes: 25396
#include<iostream>
using namespace std;
int main (void)
{
  int n,i;
  string s,t;
  cin>>s;
  int ans=0;
  n=s.size();
  for(i=0;i<n/2;i++){if(s[i]!=s[n-i-1]){ans++;}}
  cout<<ans;

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main() {
  string day;
  cin >> day;
  
  if(day=="SUN")
    cout << 7;
  else if(day=="MON")
    cout<< 6;
  else if(day=="TUE")
    cout<<5;
  else if(day=="WED")
    cout<<4;
  else if(day=="THU")
    cout<< 3;
  else if(day=="FRI")
    cout<< 2;
  else cout<<1;

  return 0;
}


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

typedef long long ll;
typedef long double ld;

#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ALL(v)      v.begin(), v.end()
#define PB          push_back
#define MP          make_pair
#define UB          upper_bound
#define LB          lower_bound
#define PI          2*acos(0.0)
#define MOD         1000000007
#define GCD(a, b)   __gcd(a, b)
#define LCM(a, b)   ((a)*(b)) / GCD(a, b)
#define INPUT       freopen("input.txt", "r", stdin);
#define OUTPUT      freopen("output.txt", "w", stdout);
#define PRINT(a)    for(auto i : a) cout << i << " "; cout << endl;
#define PRINTS(s)   for(auto i=s.begin(); i!=s.end(); i++) cout << *i << " "; cout << endl;
#define PRINTM(m)   for(auto i=m.begin(); i!=m.end(); i++) cout << i->first << " " << i->second << endl;

int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
string lowerCase = "abcdefghijklmnopqrstuvwxyz";
string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/// Graph moves
const int fxKing[] = {+1,+1,+0,-1,-1,-1,+0,+1}; /// King's move
const int fyKing[] = {+0,+1,+1,+1,+0,-1,-1,-1}; /// King's move
const int fxKnight[] = {+2,+1,-1,-2,-2,-1,+1,+2}; /// Knight's move
const int fyKnight[] = {+1,+2,+2,+1,-1,-2,-2,-1}; /// Knight's move

ll q, t, a, b, c, d, m, n, k;
ll cnt, Mn, Mx, sum, sum1, sum2, ck;
ll arr1[1000], arr2[1000];

map <ll, ll> mp1, mp2;
set <ll> st1, st2;
vector <ll> vec1, vec2;
string str1, str2, str3;
int arr[26];

int main()
{
    FIO;
    t = 1;
    while(t--)
    {
        cin >> n >> str1 ;
        for(int i=0; i<n; i++)
        {
            arr[str1[i]-'a']++;
        }
        for(int i=0; i<26; i++)
        {
            if(arr[i]&1){
                return cout << "No" << endl, 0;
            }
        }
        cout << "Yes" << endl;
    }

    return 0;
}


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

using ll = long long;

using P = pair<ll, int>;    // (大きさ, 色)

int main() {
    const int MAX_N = 200000;

    int N;
    cin >> N;

    static P creatures[MAX_N];
    for (int i = 0; i < N; i++) {
        cin >> creatures[i].first;
        creatures[i].second = i;
    }
    sort(creatures, creatures + N);

    static ll cumsum[MAX_N];
    for (int i = 0; i < N; i++) {
        cumsum[i] = creatures[i].first;
        if (i > 0) cumsum[i] += cumsum[i - 1];
    }

    int ans = 1;
    bool flag = true;
    for (int i = N - 2; i >= 0; i--) {
        if (flag && cumsum[i] * 2 >= creatures[i + 1].first) ans++;
        else flag = false;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <cstring>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <queue>
#include <set>

using namespace std;

vector<pair<int, int> > g[1000];
vector<int> d[1000];

int s[8];
int t[8];

int n, m, k, p;
map<int, int> ids;
int poss[32];
const int inf = 1 << 30;

int memo[32][1 << 6][1 << 6];

int solve(int pos, int have, int done){
  if(done == (1 << k) - 1) return 0;
  if(memo[pos][have][done] != -1) return memo[pos][have][done];

  const int p = poss[pos];
  int ret = inf;

  REP(i,k) if((have & (1 << i)) == 0 && (done & (1 << i)) == 0){
    const int next = s[i];
    const int cost = d[p][next];
    if(cost == -1) continue;
    ret = min(ret, cost + solve(ids[next], have | (1 << i), done));
  }

  REP(i,k) if((have & (1 << i)) != 0 && (done & (1 << i)) == 0){
    const int next = t[i];
    const int cost = d[p][next];
    if(cost == -1) continue;
    ret = min(ret, cost + solve(ids[next], have ^ (1 << i), done | (1 << i)));
  }

  return memo[pos][have][done] = ret;
}

vector<int> dijkstra(int start){
  vector<int> ret(n, -1);
  typedef pair<int, int> data;
  priority_queue<data, vector<data>, greater<data> > pq;
  pq.push(make_pair(0, start));
  while(pq.size()){
    const data dt = pq.top(); pq.pop();
    const int cost = dt.first;
    const int pos = dt.second;

    if(ret[pos] != -1) continue;
    ret[pos] = cost;

    REP(i,g[pos].size()){
      const int next = g[pos][i].first;
      if(ret[next] == -1){
	pq.push(make_pair(cost + g[pos][i].second, next));
      }
    }
  }

  return ret;
}


int main(){
  n = getInt();
  m = getInt();
  k = getInt();
  p = getInt() - 1;

  REP(i,m){
    const int x = getInt() - 1;
    const int y = getInt() - 1;
    const int w = getInt();

    g[x].push_back(make_pair(y, w));
    g[y].push_back(make_pair(x, w));
  }

  REP(i,k){
    s[i] = getInt() - 1;
    t[i] = getInt() - 1;
  }

  int id = 0;
  REP(i,k){ poss[id] = s[i]; ids[s[i]] = id++; }
  REP(i,k){ poss[id] = t[i]; ids[t[i]] = id++; }

  d[p] = dijkstra(p);
  REP(i,k){
    d[s[i]] = dijkstra(s[i]);
    d[t[i]] = dijkstra(t[i]);
  }

  /*
  REP(i,n){
    printf("%d:", i);
    if(d[i].size() != 0)
      REP(j,n) printf(" %d", d[i][j]);
    puts("");
  }
  */

  memset(memo, -1, sizeof(memo));

  int ans = inf;
  REP(i,k) if(d[p][s[i]] != -1){
    ans = min(ans, d[p][s[i]] + solve(i, 1 << i, 0));
  }

  if(ans == inf){
    puts("Cannot deliver");
  }else{
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1736
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


import itertools

diff = 0
n2i = {n: i for i, n in enumerate(itertools.permutations(range(1, N + 1)))}
print(abs(n2i[P] - n2i[Q]))




Measured memory_bytes: 10472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main() { 
    ll X;
    cin >> X;
    if(X>=30)cout <<"Yes" <<endl;
    else cout <<"No" << endl;
    return 0;
}

Measured memory_bytes: 3596
N = list(input())
A = []
B = []
for i in range(len(N)):
    if int(i) % 2 == 0:
        B.append(N[i])
    else:
        A.append(N[i])
C = A.count('0') + B.count('1')
D = B.count('0') + A.count('1')
print(min(C,D))

Measured memory_bytes: 4744
#include <cstdio>
#include <algorithm>
#include <cstring>
#define inf 0x7fffffff
using namespace std;

int n, t[10005], v[10005], sumt;
double ans, limt[40005];
int main() {
	for(int i = 0; i < 40005; i++) limt[i] = inf;
	ans = 0.0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	scanf("%d", &t[i]), sumt += t[i];
	sumt *= 2;
	for(int i = 1; i <= n; i++)
	scanf("%d", &v[i]);
	double vs = 0.0;
	int ts = 0;
	for(int i = 1; i <= n; i++) {
		for(int k = ts; k <= ts + 2 * t[i]; k++)
		limt[k] = min(limt[k], 1.0 * v[i]);
		double p = 0.5;
		for(int k = ts - 1; k >= 0; k--, p += 0.5)
		limt[k] = min(limt[k], 1.0 * v[i] + p);
		ts += 2 * t[i];
	}
	double p = 0;
	for(int i = sumt; i >= 0; i--, p += 0.5)
	limt[i] = min(limt[i], p);
	for(int i = 1; i <= sumt; i++) {
		double vn = min(vs + 0.5, limt[i]);
		ans += (vs + vn) * 0.25;
		vs = vn;
	}
	printf("%lf\n", ans);
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        if (s.length() == 2) {
            if (s.charAt(0) == s.charAt(1)) {
                System.out.println("1 2");
            } else {
                System.out.println("-1 -1");
            }
            return;
        }

        for (int i = 2; i < s.length(); i++) {
            if (s.charAt(i) == s.charAt(i - 2)) {
                System.out.println((i - 1) + " " + (i + 1));
                return;
            }
            if (s.charAt(i) == s.charAt(i - 1)) {
                System.out.println(i + " " + (i + 1));
                return;
            }
        }

        System.out.println("-1 -1");
    }
}


Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

const int NN = 55;
int n,k;
int x[NN],y[NN];

int32_t main() {
    cin >> n >> k;
    rep (i,n) cin >> x[i] >> y[i];

    int mi = 5e18;
    rep (i1,n) rep (i2,n) rep (j1,n) rep (j2,n) {
        if (x[i1] < x[i2] && y[j1] < y[j2]) {
            int c = 0;
            rep (ii,n) if (x[i1] <= x[ii] && x[ii] <= x[i2] &&
                           y[j1] <= y[ii] && y[ii] <= y[j2]) c++;
            if (c >= k) chmin(mi,(x[i2]-x[i1])*(y[j2]-y[j1]));
        } 
    }
    cout << mi << endl;    
}


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


int main()
{
  ll n;
  cin >> n;
  
  ll ans = 0;
  for(int i = 1; i <= n; i++)
  {
    ll d = n / i;
    ans += i * d * (d+1) / 2;
  }
  cout << ans << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  vi d(N);
  rep(i,N) cin >> d[i];
  sort(d.begin(),d.end());
  
  cout << d[N/2]-d[N/2-1] << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t
 
using namespace std;
 
typedef pair<int, int> pii;
const int N = 5003;
const int M = 202;
const int inf = int(1e18);
 
int n, m, l, r, iTicket, a[N], b[M][N], f[N][N];
set<int> s;
set<int>::iterator p;
vector<int> cur;
 
void Update(int x) {
    iTicket = x;
    sort(cur.begin(), cur.end(), [](const int& i, const int& j) {
            return b[iTicket][i] > b[iTicket][j];
         });
    s.clear(); s.insert(0); s.insert(n + 1);
    for(int i: cur) {
        p = s.upper_bound(i);
        r = (*p); l = *(p = prev(p)) + 1;
        f[l][i] += b[iTicket][i];
        f[l][r] -= b[iTicket][i];
        f[i + 1][i] -= b[iTicket][i];
        f[i + 1][r] += b[iTicket][i];
        s.insert(i);
    }
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 2; i <= n; ++i) cin >> a[i], a[i] += a[i - 1];
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j)
            cin >> b[j][i];
    }
    cur.clear(); cur.resize(n); iota(cur.begin(), cur.end(), 1);
    for(int i = 1; i <= m; ++i) Update(i);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j)
            f[i][j] += f[i][j - 1];
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j)
            f[i][j] += f[i - 1][j];
    } int res = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = i; j <= n; ++j) {
            res = max(res, f[i][j] - a[j] + a[i]);
        }
    }
    cout << res;
}

Measured memory_bytes: 203904
def compress(used_x)
	x_map = {}
	used_x.to_a.sort.each_with_index{|x, i| x_map[x] = i}
	x_map
end

class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

require 'set'

n, m = gets.split.map &:to_i
used_x = Set.new
used_y = Set.new

treasure = (1..n).map{
	x, y = gets.split.map &:to_i
	used_x << x
	used_y << y
	[x, y]
}

x_map = compress(used_x)
y_map = compress(used_y)
a = (0..x_map.size-1).map { [0] * y_map.size }
treasure.each{|x, y|
	a[x_map[x]][y_map[y]] += 1
}

a.accum_2d!

used_x = used_x.to_a.sort
used_y = used_y.to_a.sort

queries = (1..m).map {
	gets.split.map &:to_i
}

queries.each{|x1, y1, x2, y2|
	i1 = used_x.bsearch_first_index{|x| x1 <= x}
	if !i1
		puts 0
		next
	end
	j1 = used_y.bsearch_first_index{|y| y1 <= y}
	if !j1
		puts 0
		next
	end
	i2 = used_x.bsearch_last_index(i1, used_x.size-1){|x| x <= x2}
	if !i2
		puts 0
		next
	end
	j2 = used_y.bsearch_last_index(j1, used_y.size-1){|y| y <= y2}
	if !j2
		puts 0
		next
	end

	p a[i2+1][j2+1] - a[i2+1][j1] - a[i1][j2+1] + a[i1][j1]
}

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

int x, y;
vector<char>c;
void saiki(int a, int b) {
	if (a == x&&b == y) {
		for (char k : c)cout << k;
		cout << endl;
	}
	if ((a >= 5 && b <= 3) ||(a<=3&&b>=5)|| (a == 4 && b==6) || (a == 6 && b == 4)||(a==5&&b==5))return;
	c.push_back('A');
	saiki(a + 1, b);
	c.pop_back();
	c.push_back('B');
	saiki(a,b+1);
	c.pop_back();
}
int main() {
	cin >> x >> y;
	saiki(0, 0);
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 1010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, x[MAXN], y[MAXN], f[50], p[50];

int mod2(int x) {
    x %= 2;
    if (x < 0) x += 2;
    return x;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> x[i] >> y[i];
    FOR(i,2,n)
        if (mod2(x[i] + y[i]) != mod2(x[1] + y[1])) {
            cout << -1;
            return 0;
        }
    bool add = false;
    if (mod2(x[1] + y[1]) == 0) {
        add = true;
        FOR(i,1,n) x[i]++;
    }
    int bits = 31;
    cout << bits + add << "\n";
    FOR(i,0,bits-1) cout << (1<<i) << ' ';
    if (add) cout << 1;
    cout << "\n";

    ll sum = (1LL << 31) - 1;

    FOR(i,1,n) {
        ll u = x[i] + y[i], v = x[i] - y[i];
        string res = "";
        ll g = (u + sum) / 2;
        ll h = (v + sum) / 2;
        FORE(i,bits-1,0) {
            if (g & (1LL << i)) f[i] = 1;
            else f[i] = 0;
            if (h & (1LL << i)) p[i] = 1;
            else p[i] = 0;
        }
        FOR(i,0,bits-1) {
            if (f[i] && p[i]) res += "R";
            else if (f[i] && !p[i]) res += "U";
            else if (!f[i] && p[i]) res += "D";
            else res += "L";
        }
        if (add) res = res + "L";
        // u = 0, v = 0;
        // FOR(i,0,SZ(res)-1)
        //     if (res[i] == 'R') u += (1LL << i);
        //     else if (res[i] == 'L') u -= (1LL << i);
        //     else if (res[i] == 'U') v += (1LL << i);
        //     else v -= (1LL << i);
        // cout << u << ' ' << v << endl;
        cout << res << "\n";
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false); cin.tie(NULL)

double maxvolume(double s) 
{ 
    double length = s / 3; 
  
    s -= length; 
    double breadth = s / 2; 
   
    double height = s - breadth; 
  
    return length * breadth * height; 
} 
  
int main() 
{ 
    double s ;
    cin >> s; 
    cout << setprecision(10) << maxvolume(s) ;
    return 0; 
} 
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 1005

int N,a,b,c;
vector<P> G[MAX];
int t[MAX];

int solve(int pos,int prev,int pcost){
  if(t[pos]>0)return pcost;
  int res=0;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i].first;
    int ccost=G[pos][i].second;
    if(to==prev)continue;
    res+=solve(to,pos,ccost);
  }
  return min(res,pcost);
}

int main(){
  cin>>N;
  for(int i=1;i<N;i++)cin>>t[i];
  for(int i=0;i+1<N;i++){
    cin>>a>>b>>c;
    G[a].push_back(P(b,c));
    G[b].push_back(P(a,c));
  }
  cout<<solve(0,-1,1e9)<<endl;
  return 0;
}

Measured memory_bytes: 1256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    internal static void Main(string[] args)
    {
        var A = int.Parse(ReadLine());
        var B = int.Parse(ReadLine());
        var C = int.Parse(ReadLine());
        var D = int.Parse(ReadLine());

        WriteLine(Math.Min(A, B) + Math.Min(C, D));
    } 
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n,k,q;
  cin>>n>>k>>q;
  vector<int>a(q),d(n,k);
  rep(i,q) {
    cin>>a[i];
    a[i]--;
  }
  rep(i,n){
    d[i]-=q;
  }
  rep(i,q)
    d[a[i]]++;
  rep(i,n){
    if(d[i]>0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}

Measured memory_bytes: 1408
n = int(input())

res = 0
for i in range(1, n+1):
    if i % 3 == 0 and i % 5 == 0:
        res += 0
    elif i % 3 == 0:
        res += 0
    elif i % 5 == 0:
        res += 0
    else:
        res += i

print(res)


Measured memory_bytes: 9072
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
using LL = long long;
int main()
{
    LL n, in[5];
    while (~scanf("%lld", &n)) {
        REP(i,0,4) scanf("%lld", &in[i]);

        LL ans = 0;
        REP(i,0,4) {
            LL d = n / in[i];
            if (n%in[i]) d++;
            d += i;

            //printf("d=%lld ans=%lld\n",d,ans);
            ans = max(ans+1, d);
        }
        printf("%lld\n", ans);
    }
    
    return 0;
}



Measured memory_bytes: 256
N = int(input())


def make_divisors(n):  # 任意の整数の約数をリストで返す関数
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


List = make_divisors(N)

if len(List) % 2 == 1:
    print(List[len(List) // 2] * 2 - 2)
else:
    print(List[len(List) // 2 - 1] + (List[len(List) // 2] - 2))


Measured memory_bytes: 38640
#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}

inline static int sp(char* str, unsigned short i){
    if(i>99){
        str[2] = i%10+48; i/=10;
        str[1] = i%10+48;
        str[0] = i/10+48;
        return 3;
    }else if(i>9){
        str[1] = i%10+48;
        str[0] = i/10+48;
        return 2;
    }else{
        str[0] = i+48;
        return 1;
    }
}

char a[2*500*500];
char buffer[8*1024*1024];

int main(void){
    const int h=gl(), w=gl();
    int p = 0;
    int pos=0;
    char *aa = a-2; 
    fread(a, 1, 2*w*h, stdin);
    {
        char haveCoin = 0;
        short old_y, old_x;
        for(int i=1; i<=h; i++){
            if(i%2==1){
                for(int j=1; j<=w; j++){
                    if(haveCoin){
                        pos++;
                        p += sp(buffer+p, old_y)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, old_x)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, i)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, j)+1; buffer[p-1] = '\n';
                    }
                    haveCoin ^= aa[2*j]&1;
                    old_y = i;
                    old_x = j;
                }
            }else{
                for(int j=w; j>0; j--){
                    if(haveCoin){
                        pos++;
                        p += sp(buffer+p, old_y)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, old_x)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, i)+1; buffer[p-1] = ' '; 
                        p += sp(buffer+p, j)+1; buffer[p-1] = '\n';
                    }
                    haveCoin ^= aa[2*j]&1;
                    old_y = i;
                    old_x = j;
                }
            }
            aa+=2*w;
        }
    }
    pl(pos); putchar_unlocked('\n');
    fwrite(buffer, 1, p, stdout);
    return 0;
}


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

long long k,n;
int arr[3003000];

int main(){
	cin>>k>>n;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
	}
	bool check=false;
	for(int i=1;i<=n;i++){
		k-=arr[i];
		if(k<=0)check=true;
	}
	if(check)cout<<"Yes";
	else cout<<"No";
} 

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int x1,x2,y1,y2,x,xx,y,yy;

  cin >> x1 >> y1 >> x2 >> y2;
  x = x2 - (y2 - y1);
  y = y2 + (x2 - x1);
  xx = x - (x2 - x1);
  yy = y - (y2 - y1);
  cout << x << ' ' << y << ' ' << xx << ' ' << yy << endl;
}


Measured memory_bytes: 256
#C-Energy Drink Collector
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost += lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
        break
print(cost)

Measured memory_bytes: 22384
N = int(input())
B = 0
for i in range(N):
  A = 0
  n = int((i+1)**(1/2))
  for j in range(n):
     if (i+1) % (j+1) == 0:
        A += 1
  if A == 4 and (i+1) % 2 == 1:
    B += 1
print(B)
    


Measured memory_bytes: 38640
#include <iostream>
using namespace std;
int main() {
  long long num;
  cin >> num;
  int i = 0;
  double ans = 100;
  do {
    ans *= 1.01;
    ans = (long long)ans;
    i++;
  } while (ans < num);
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

const int M_MAX = pow(10, 3);
vector<vector<int>> dp(M_MAX+10, vector<int>(pow(2, 12), -1));

int a[M_MAX]={}, b[M_MAX]={}; vector<vector<int>> c(M_MAX+10, vector<int>());

int dfs(int m, int s) {
  if (dp[m][s]!= -1) return dp[m][s];
  if (m==0) {
    if (s==0) return dp[m][s] = 0;
    else return dp[m][s] = INF;
  }

  int result = dfs(m-1, s), tmp_s = s;
  rep(dig, c[m-1].size()) if (tmp_s&(1<<c[m-1][dig])) tmp_s -= pow(2,c[m-1][dig]);
  result = min(result, dfs(m-1, tmp_s)+a[m-1]);
  return dp[m][s] = result;
}

int main() {
  int N, M; cin >> N >> M;
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) { int tmp; cin >> tmp; tmp--; c[i].push_back(tmp); }
  }
  // for (auto x: c) { for (auto y: x) cout << y << " "; cout << endl; }
  int d = dfs(M, pow(2,N)-1);
  int result = d == INF ? -1 : d;
  cout << result << endl;
  return 0;
}

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

signed main() {
	int N;
	cin >> N;
	vector<int>X(N);
	int mn = INF;
	int mx = -INF;
	rep(i, N) {
		cin >> X[i];
		mx = max(mx, X[i]);
		mn = min(mn, X[i]);
	}
	int sum;
	int ans = INF;
	for (int i = mn; i <= mx; i++) {
		sum = 0;
		for (int j = 0; j < N; j++) {
			sum += pow(X[j] - i, 2);
		}
		ans = min(ans, sum);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int a[15][15],sum[15];
using namespace std;
int main()
{
	int n,m,x,ans=1e9;
	cin>>n>>m>>x;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for (int i=1;i<(1<<n);i++)
	{
		memset(sum,0,sizeof(sum));
		for (int j=0;j<n;j++)
		{
			if ((i>>j)&1)
			{
				for (int k=0;k<=m;k++)
				{
					sum[k]+=a[j][k];
				}
			}
		}
		int flag=1;
		for (int p=1;p<=m;p++)
		{
			if (sum[p]<x)  
			{
				flag=0;
				break;
			}
		}
		if (flag)   ans=min(sum[0],ans);
	}
	if (ans==1e9)   cout<<-1;
	else   cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
s = STDIN.gets.chomp

if !s.include?('B')
  puts 0
  exit 0
end

if !s.include?('W')
  puts 0
  exit 0
end

last_index = s.size - 1
sorted = last_index - s.rindex('W')

black_indices = []
s.chars.each_with_index do |char, i|
  if char == 'B'
    black_indices << i
  end
end

if sorted == black_indices.size
  puts 0
  exit 0
end

# p black_indices

black_indices = black_indices[0..(black_indices.size - sorted - 1)]

# p last_index
# p sorted
# p black_indices
# p last_index - sorted - 1
# p black_indices[0..(last_index - sorted - 1)]

sum = 0
black_indices.each do |i|
  sum += last_index - sorted - i
  sorted += 1
end

p sum


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

int main()
{
  string S;
  bool o = false;
  cin >> S;
  
  for (int i = 0; i < S.size(); ++i)
  {
    o = !o;
    char c = S[i];
    if ((c == 'L' && o) || (c == 'R' && !o))
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,M;
    Scd(N);
    vi d(N);
    Rep(i,N) Scd(d[i]);
    Scd(M);
    vi t(M);
    Rep(i,M) Scd(t[i]);

    sort( d.begin(), d.end() );
    sort( t.begin(), t.end() );

    int j = 0;
    bool ans = false;
    Rep(i,N){
        if( d[i] == t[j] ) j++;
        if( j == M ) {
            ans = true;
            break;
        }
    }

    printf ("%s\n", ans ? "YES" : "NO" );

    return 0;
}





Measured memory_bytes: 1792