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

using namespace std;

const int mod = 1e9 + 7;
const int maxb = 2e5;
long long mem[maxb + 2];

long long power(long long a, long long b){
    long long  res = 1;

    while(b){
        if(b & 1){
            res = res * a % mod;
        }
        a = (long long)(a * a) % mod;
        b >>= 1;
    }

    return res;
}

long long nCr(long long n, long long k){
    if(n - k > k)
        k = n - k;

    long long res = 1;

    for(int i = k + 1; i <= n; i++){
        res = (res * i) % mod;
    }
    for(int i = 2; i <= n - k; i++){
        res = (res * mem[i]) % mod;
    }
    return res;
}


int main(){
    int n, a, b;

    cin >> n >> a >> b;

    mem[1] = 1;
    for(int i = 2; i <= b; i++){
        mem[i] = power(i, mod - 2) % mod;
    }

    long long ans = ((long long)power(2, n) - 1 - nCr(n, a) - nCr(n, b) + 2 * mod) % mod;


    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
long double const pi = std::acos(-1.0L);


int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i,n) cin >> w[i];
  bool ok = true;
  rep(i,n-1){
    if(w[i][w[i].size()-1] != w[i+1][0]){
     ok = false;
    }
  }
  rep(i,n){
    rep(j,i){
      if(w[i]==w[j]) {
        ok = false;
      }
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);



int main() {
  int s,w; cin >> s >> w;
  if (s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  
  return 0;

}

Measured memory_bytes: 3636
N, H =list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
B.sort(reverse = True)

from itertools import accumulate

B_cumsum = [0] + list(accumulate(B)) #N+1

swing = max(A)

answer = H

for i in range(N+1):
  # i本の刀を投げる
  if H <= B_cumsum[i]:
    answer = min(answer, i)
    continue
  else:
    answer = min(answer, i + (H-B_cumsum[i]+swing-1)//swing)

print(answer)

Measured memory_bytes: 34632
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];

ll gcd(ll x, ll y)
{
	if (x % y == 0) return y;
	else return gcd(y, x % y);
}
// 1or素数だと１を返す
ll prime(ll x)
{
	for (ll i = 2; i * i <= x; i++)
	{
		if (x % i == 0) return 0;
	}
	return 1;
}
int main()
{
	ll a, b;
	cin >> a >> b;
	ll ans = 1;

	ll c = gcd(a, b);

	for (ll i = 2; i*i <= c; i++)
	{
		if (c % i == 0 )
		{
			ans++;
			while (c % i == 0)
			{
				c /= i;
			}
		}
	}
	if (1 < c) ans++;
	cout << ans << "\n";

	return 0;
}

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

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

cout << n*n*n << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
  string n;
  cin >> n;
  bool flag = false;
  for(int i = 0;i < n.size();i++){
    if(n[i] == '7') flag = true;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a;
  cin>>a;
 int  x=26;
  string s;
  int count=0;
  int i=0;
  while(a>0)
  {
  s[i]='a'+(a-1)%x;
   
   // cout<<a%x<<endl;
      a=(a-1)/x;
    i++;
    
  }
  
  
  for(int j=i-1;j>=0;j--)
  {
    cout<<s[j];
  }
  
    
}


Measured memory_bytes: 3632
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int count=0;
		for(int i=a;i<=b;i++){
			if(c%i==0) count++;
		}
		System.out.println(count);
		
	}

}

Measured memory_bytes: 26296
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    
    if (n==m) {
      System.out.println("Yes");
      return;
    }
    System.out.println("No");
    
  }
}

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

char S[1123];

int main(void) {
	scanf("%s",&S);

	for (int i = 0; i < strlen(S); ++i) {
		if (S[i] == 'A') { printf("X"); }
		else if (S[i] == 'B') { printf("Y"); }
		else if (S[i] == 'C') { printf("Z"); }
		else if (S[i] == 'D') { printf("A"); }
		else if (S[i] == 'E') { printf("B"); }
		else if (S[i] == 'F') { printf("C"); }
		else{ printf("%c", S[i] - 3); }
	}
	printf("\n");
	return 0;
}

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

using namespace std;

#define LL long int

const int MAX = 1e6;
const int MOD = 1e9+7;



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

    int ans = 0;

    for(int i = 1; i <= n; ++i){
        ans += (n - 1) / i;
    }

    cout << ans << endl;




    return 0;
}
/*
1, 1,2,3
2, 1
3, 1

*/

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
int n,m,a,b,x,i,pot[100];
typedef struct path{
	int a;
	int b;
	int x;
	struct path* next;
}Path;
Path *first,*look,*prev;
Path* newpath(int a,int b,int x,Path* next){
	Path* p=(Path*)malloc(sizeof(Path));
	p->a=a;
	p->b=b;
	p->x=x;
	p->next=next;
	return p;
}
void connect(int from,int to){
	int i;
	for(i=0;i<m;i++){
		if(pot[i]==from){pot[i]=to;if(to==0)n--;}
	}
}
int main(void){
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		for(i=0;i<n;i++)pot[i]=i+1;
		scanf("%d",&m);
		first=NULL;
		for(i=0;i<m;i++){
			scanf("%d,%d,%d",&a,&b,&x);
			if(first==NULL)first=newpath(a,b,x,NULL);
			else if(first->x > x)first=newpath(a,b,x,first);
			else{
				prev=first;look=first->next;
				while(look!=NULL){
					if(look->x > x){prev->next=newpath(a,b,x,look);break;}
					else{prev=look;look=look->next;}
				}
				if(look==NULL)prev->next=newpath(a,b,x,look);
			}
		}
		look=first;x=0;m=n;
		while(look!=NULL){
			a=pot[look->a];b=pot[look->b];
			if(a!=b){
				if(x==0){pot[look->a]=0;pot[look->b]=0;n-=2;}
				else{if(a<b)connect(b,a); else connect(a,b);}
				x+=look->x/100-1;
			}
			look=look->next;
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 748
import queue

q = queue.Queue()
for i in range(1,10):
    q.put(i)

k = int(input())
cou = 0
while True:
    cou += 1
    t = q.get()
    if cou == k:
        print(t)
        exit()
    if t % 10 == 0:
        q.put(t*10)
        q.put(t*10 + 1)
    elif t % 10 == 9:
        q.put(t*10 + 8)
        q.put(t*10 + 9)
    else:
        s = t % 10
        q.put(t*10 + s -1)
        q.put(t*10 + s)
        q.put(t*10 + s + 1)

Measured memory_bytes: 12576
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
vector<int>E[100000];
int d[100000], pr[100000];
void rec(int v, int p) {
	d[v] = p;
	for (int u : E[v])rec(u, p + 1);
}
int main() {
	int n; scanf("%d", &n);memset(pr, -1, sizeof(pr));
	rep(i, n) {
		int id, k; scanf("%d%d", &id, &k);
		rep(j, k) {
			int c; scanf("%d", &c);
			E[id].push_back(c);
			pr[c] = id;
		}
	}
	rep(i, n) {
		if (!~pr[i]) {
			rec(i, 0); break;
		}
	}
	rep(i, n) {
		printf("node %d: parent = %d, depth = %d, ", i, pr[i], d[i]);
		if (!~pr[i])printf("root, [");
		else if (E[i].empty())printf("leaf, [");
		else printf("internal node, [");
		rep(j, E[i].size()) {
			if (j)printf(", ");
			printf("%d", E[i][j]);
		}
		printf("]\n");
	}
}


Measured memory_bytes: 7088
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;


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

    unordered_set<char> x(s.begin(), s.end());
    cout << (x.size() == 1 ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var Rcount = 0;
            var Bcount = 0;
            foreach (var c in s)
            {
                switch (c)
                {
                    case 'R':
                        Rcount++;
                        break;
                    case 'B':
                        Bcount++;
                        break;
                }
            }

            var output = Rcount > Bcount ? "Yes" : "No";
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    vector<int> A(N+1);
    for(int i=0;i<N;i++) cin>>A[i+1];
    
    for(int t=0;t<min(K,100);t++){
        vector<int> B(N+2);
        for(int i=1;i<=N;i++){
            int l=max(0,i-A[i]),r=min(N,i+A[i]);
            B[l]++;
            B[r+1]--;
        }
        for(int i=1;i<N+2;i++) B[i]+=B[i-1];
        
        for(int i=1;i<=N;i++) A[i]=B[i];
    }
    
    for(int i=0;i<N;i++) cout<<A[i+1]<<" ";
    cout<<endl;
}



Measured memory_bytes: 4784
A = []
A += list(map(int, input().split(' ')))
A += list(map(int, input().split(' ')))
A += list(map(int, input().split(' ')))

N = int(input())

B = []
for _ in range(N):
    b = int(input())
    try:
        idx = A.index(b)
        B.append(idx)
    except ValueError:
        pass

bingo_indices = [
    [0, 1, 2], [3, 4, 5], [6, 7, 8],
    [0, 3, 6], [1, 4, 7], [2, 5, 8],
    [0, 4, 8], [2, 4, 6]
]

is_bingo = 'No'
for indices in bingo_indices:
    if (indices[0] in B) and (indices[1] in B) and (indices[2] in B):
        is_bingo = 'Yes'
        break

print(is_bingo)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int INF = 1001001001;
 
vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];
 
void dfs(int v) {
  if (reachableFrom1[v]) return;
  reachableFrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}
 
int main() {
  int n, m, p;
  cin >> n >> m >> p;
  vector<tuple<int,int,int>> edges;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    c -= p;
    c = -c;
    edges.emplace_back(a,b,c);
    to[a].push_back(b);
    rto[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i] = reachableFrom1[i]&reachableToN[i];
  { // bellman-ford
    vector<int> d(n,INF);
    d[0] = 0;
    bool upd = true;
    int step = 0;
    while (upd) {
      upd = false;
      rep(i,m) {
        int a, b, c;
        tie(a,b,c) = edges[i];
        if (!ok[a]) continue;
        if (!ok[b]) continue;
        int newD = d[a]+c;
        if (newD < d[b]) {
          upd = true;
          d[b] = newD;
        }
      }
      step++;
      if (step > n) {
        puts("-1");
        return 0;
      }
    }
    int ans = -d[n-1];
    ans = max(ans, 0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 768
m, k = map(int, input().split())
if k == 0:
	ans = []
	for i in range(2**m):
		ans += [i, i]
	print(*ans)
else:
	if m == 1:
		print(-1)
	elif k >= 2**m:
		print(-1)
	else:
		ans = []
		ans += [i for i in range(2**m) if i != k]
		ans += [k]
		ans += [i for i in range(2**m-1, -1, -1) if i != k]
		ans += [k]
		print(*ans)

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

typedef long long ll;
typedef pair<int, int> pii;

int N, M;
pii P[402];
vector<pii> adj[402];
int vis[402];
ll ans;

bool dfs(int u, int fe) {
    if(vis[u]) return false;
    vis[u] = 1;

    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        int e = adj[u][i].second;
        if(e >= fe) continue;
        if(vis[v]) return false;
        if(!dfs(v, e)) return false;
    }
    return true;
}

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < M; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;

        adj[u].push_back({v, i});
        adj[v].push_back({u, i});
    }
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            memset(vis, 0, sizeof(vis));
            if(!dfs(i, 1e9)) continue;
            if(!dfs(j, 1e9)) continue;
            ans++;
        }
    }
    printf("%lld", ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N){
    cin >> a.at(i);
  }
  int cur = 1;
  int ans = -1;
  rep(i, N){
    cur = a.at(cur-1);
    if(cur==2){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
while true do
    h,w = gets.split.map(&:to_i)
    break if h ==0 && w ==0
    h.times do |i|
        str = ''
        w.times do |j|
            if i == 0 || i == h-1 then
                str += '#'
            elsif j == 0 || j == w-1 then
                str += '#'
            else
                str += '.'
            end
        end
        puts str
    end
    puts
end


Measured memory_bytes: 7252
/* 
 * Project: AtCoder Beginners Contest 166 
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/02
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
using namespace std;

int n;
int k;
int d[100];
int a[100][100];

void solve() {
    int bin[n];
    for (int i=0;i<n;i++) {
        bin[i] = 0;
    }
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < d[i]; j++) {
            bin[a[i][j]-1]++;
        }
    }

    int cnt = 0;

    for (int i = 0; i < n; i++) {
        if (bin[i] == 0)
            cnt++;
        // printf("%d\n", bin[i]);
    }
    printf("%d\n", cnt);
}

int main() {

    scanf("%d", &n);
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
        scanf("%d", &d[i]);
        for (int j = 0; j < d[i]; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    solve();

}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool flg = false;
    for (int i = 1; i < b; i++) {
        if (a*i % b == c) {
            flg = true;
            break;
        }
    }
    if (flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int cnt=0;
VI adj[N];
int vis[N];
void dfs(int u, int p=-1){
    cnt++;
    vis[u]=1;
    for(auto v: adj[u]) if (v!=p and !vis[v]) dfs(v, u);
}
int main(){
    int n, m;
    sc(n);sc(m);
    fr(i, 1, m){
        int u, v;sc(u);sc(v);
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans = 0;
    fr(i, 1, n){
        if (!vis[i]){
            dfs(i);
            ans = max(ans, cnt);
            cnt= 0;
        }
    }
    pr(ans);n_l;
    return 0;
}



Measured memory_bytes: 43568
import java.util.*;
public class Main {

	static class event{
		int t, v, x;
		event(int t, int v, int x){
			this.t = t;
			this.v = v;
			this.x = x;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		event[] e = new event[N*2];
		for(int i = 0; i < N; i++) {
			int S = sc.nextInt();
			int T = sc.nextInt();
			int X = sc.nextInt();
			e[i] = new event(S - X, 1, X);
			e[N*2-1-i] = new event(T - X, -1, X);
		}
		Arrays.sort(e, (x, y) -> x.t != y.t ? x.t - y.t : x.v - y.v);
		TreeSet<Integer> b = new TreeSet<>();
		int i = 0;
		StringBuilder ans = new StringBuilder();
		for(int q = 0; q < Q; q++) {
			int D = sc.nextInt();
			while(true) {
				if(i >= N*2 || e[i].t > D)
					break;
				if(e[i].v == 1)
					b.add(e[i].x);
				else
					b.remove(e[i].x);
				i++;
			}
			ans.append(b.size() == 0 ? -1 + "\n" : b.first() + "\n");
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 218072
//Let's join Kaede Takagaki Fun Club !!
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(false);
	
	string s; g(s);
	if(s[2]==s[3]&&s[4]==s[5]) o("Yes"); else o("No");
}

Measured memory_bytes: 256
#include <cstdio>
#include <string.h>
using namespace std;

char w[16], t[1024];

bool lower(char* a) {
	int p = 0;
	while (a[p] != '\0') {
		if (a[p] >= 'A' &&a[p] <= 'Z') {
			a[p] -= ('A' - 'a');
		}
		p++;
	}
	return true;
}

int main(){
	int c = 0;
	scanf("%s", w);
	lower(w);
	while (scanf("%s", t), strcmp(t, "END_OF_TEXT") != 0) {
		lower(t);
		if (strcmp(w, t) == 0) {
			c++;
		}
	}
	printf("%d\n", c);
	
	return 0;
}


Measured memory_bytes: 2680
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
using namespace std;
const int maxn = 1000000 + 10;
int n;
ll a[maxn]; 
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n);
    int x, y;
    bool fg1 = false, fg2 = false;
    for(int i = n-1; i > 0; i--)
    {
        if(a[i] == a[i-1])
        {
            x = i;
            fg1 = true;
            break;
        }
    }
    if(fg1)
    {
        for(int i = n-1; i > 0; i--)
        {
            if(a[i] == a[i-1] && i != x && i != (x-1))
            {
                y = i;
                fg2 = true;
                break;
            }
        }
    }
    if(fg1 && fg2)
    {
        ll ans = a[x] * a[y];
        printf("%lld\n", ans);
    }
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,temp,k;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&k,&temp);
        if(k==0){
            s.insert(temp);
            printf("%ld\n",s.size());
        }
        else if(k==1){
            if(s.find(temp)==s.end())printf("0\n");
            else printf("1\n");
        }
        else{
            s.erase(temp);   
        }
    }
}


Measured memory_bytes: 12192
import math
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split()))
    m = sum(s) / n
    a = math.sqrt(sum([float(s[i]-m)**2 for i in range(n)]) / n)

    print("{0:.8f}".format(a))



Measured memory_bytes: 5708
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	int sum = accumulate(v.begin(), v.end(), 0) / n;
	int ans1 = 0, ans2 = 0;
	for (int i : v)ans1 += (sum - i) * (sum - i);
	for (int i : v)ans2 += (sum + 1 - i) * (sum + 1 - i);
	cout << min(ans1, ans2) << endl;


}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
    int r,c,RC[102][102]={0},i,j;
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&RC[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            RC[i][c]+=RC[i][j];
        }
    }
    for(i=0;i<c+1;i++){
        for(j=0;j<r;j++){
            RC[r][i]+=RC[j][i];
        }
    }
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            printf("%d",RC[i][j]);
            if(j!=c)printf(" ");
        }
        printf("\n");
    }



    return 0;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

int main() 
{
    FAST;
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll s=(h1*60)+m1,e=(h2*60)+m2,dif=e-s;
    dif+=(24*60);
    dif%=(24*60);
    cout<<max(0ll,dif-k);
    subt;
    return 0;
}

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

int main() {
    /*変数定義，入力*/
    ll A,B,K;
    cin >> A;
    cin >> B;
    cin >> K;
    
    //int A, B;cin >> A >> B;
    //vector<int> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    
    /*出力*/
    if(K <= A) cout << A - K << " " << B << endl;
    else if(K > A && K <= A + B) cout << 0 << " " << B - (K-A) << endl;
    else cout << 0 << " " << 0 << endl;

    /*終了*/
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  ll N, prod = 1;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  REP(i, N) {
    if (A[i] <= 1000000000000000000 / prod) {
      prod *= A[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << prod << endl;
  return 0;
}

Measured memory_bytes: 4056
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    int N,M;
    cin>>N>>M;
    vector<int>a(M);
    vector<int>b(M);
    vector<int>city(N);
    for(int i=0;i<M;i++){
        cin>>a.at(i)>>b.at(i);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(a.at(j)==i+1){
                city.at(i)++;
            }
            if(b.at(j)==i+1){
                city.at(i)++;
            }
        }
    }
    for(int i=0;i<N;i++){
        cout<<city.at(i)<<endl;
    }
    
    
    
        return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> lab(
		H,
		vector<char>(W, '#')
	);

	char cur;
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			cin >> cur;
			lab[y][x] = cur;
		}
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if (lab[y][x] == '.') {
				int num = 0;
				//  斜め左上
				if (y >= 1 && x >= 1) {
					if (lab[y - 1][x - 1] == '#') {
						num++;
					}
				}
				//  上
				if (y >= 1) {
					if (lab[y - 1][x] == '#') {
						num++;
					}
				}
				//  斜め右上
				if (y >= 1 && x + 1 <= W - 1) {
					if (lab[y - 1][x + 1] == '#') {
						num++;
					}
				}
				//  左
				if (x >= 1) {
					if (lab[y][x - 1] == '#') {
						num++;
					}
				}
				//  右
				if (x + 1 <= W - 1) {
					if (lab[y][x + 1] == '#') {
						num++;
					}
				}
				//  斜め左下
				if (y + 1 <= H - 1 && x - 1 >= 0) {
					if (lab[y + 1][x - 1] == '#') {
						num++;
					}
				}
				//  下
				if (y + 1 <= H - 1) {
					if (lab[y + 1][x] == '#') {
						num++;
					}
				}
				//  斜め右下
				if (y + 1 <= H - 1 && x + 1 <= W - 1) {
					if (lab[y + 1][x + 1] == '#') {
						num++;
					}
				}
				lab[y][x] = num + '0'; 
			}
		}
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			cout << lab[y][x];
		}
		cout << endl;
	}
	return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

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

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string s; cin >> s;
    if (s.length() == 3) reverse(all(s));
    cout << s << endl;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys

# import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, K, *x = map(int, read().split())
X = np.array(x)
R = X[K / 2 < X]
L = X[K / 2 >= X]

ans = sum(L * 2) + sum(2 * (K - R))
print(ans)



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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			var xy = new XY[n];
			for (int i = 0; i < n; i++) {
				long x = cin.Long();
				long y = cin.Long();
				xy[i] = new XY(x, y);
			}

			var sorted = xy.Select(x => new { Pos = x, Angle = x.Angle() }).OrderBy(x => x.Angle).ToArray();
			var angles = new double[2 * n];
			for (int i = 0; i < n; i++) {
				angles[i] = sorted[i].Angle;
				angles[i + n] = sorted[i].Angle + 360;
			}

			int si = 0;
			double start = angles[0];
			XY pt = new XY(0, 0);
			long ans = 0;
			for (int i = 0; i < n * 2; i++) {
				if (angles[i] - angles[si] >= 180) {
					while (angles[i] - angles[si] >= 180) {
						pt.X -= sorted[si % n].Pos.X;
						pt.Y -= sorted[si % n].Pos.Y;
						++si;
						long tempDist = pt.Distance();
						ans = Math.Max(ans, tempDist);
					}

					pt.X += sorted[i % n].Pos.X;
					pt.Y += sorted[i % n].Pos.Y;
				} else {
					pt.X += sorted[i % n].Pos.X;
					pt.Y += sorted[i % n].Pos.Y;
				}

				long dist = pt.Distance();
				ans = Math.Max(ans, dist);
			}

			Console.WriteLine(Math.Sqrt(ans));
		}

		public class XY
		{
			public long X;
			public long Y;

			public XY(long x, long y)
			{
				X = x;
				Y = y;
			}

			public double Angle()
			{
				return 360 * Math.Atan2(Y, X) / (2 * Math.PI) + 360;
			}

			public long Distance()
			{
				return X * X + Y * Y;
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13524
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[302][SIZE];

int main(){
  int n, x, s[300];

  scanf("%d%d", &n, &x);

  for(int i=0;i<n;i++){
    scanf("%d", s+i);
  }

  sort(s, s+n, greater<int>());

  dp[0][x] = 1;

  for(int i=0;i<n;i++){
    for(int j=0;j<=x;j++){
      if(!dp[i][j]) continue;

      dp[i+1][j%s[i]] = (dp[i+1][j%s[i]] + dp[i][j]) % mod;
      int t = n - 1 - i;
      debug(t);
      dp[i+1][j] = (dp[i+1][j] + dp[i][j] * t % mod) % mod;
    }
  }

  ll ans = 0;

  for(int i=0;i<=x;i++){
    ans += dp[n][i] * i;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int n,m,x;
  cin >> n >> m;
  int a[m],b[m],d[m];
  rep(i,m) d[i]=0;
  rep(i,m){
    cin >> a[i] >> b[i];
    rep(j,b[i]){
      cin >> x;
      d[i] += (1 << (x-1));
    }
  }
  int dp[m][1<<n];
  rep(i,m) rep(j,1<<n) dp[i][j] = 1e9;
  dp[0][0]=0;dp[0][d[0]]=a[0];
  for(int i=1;i<m;i++){
    rep(j,1<<n) dp[i][j] = dp[i-1][j];
    rep(j,1<<n){
      dp[i][j|d[i]] = min(dp[i][j|d[i]],dp[i-1][j]+a[i]);
    }
  }
  int ans = dp[m-1][(1<<n)-1];
  cout << (ans < 1e9 ? ans : -1) << endl;
}

Measured memory_bytes: 16256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) break;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  }
}

Measured memory_bytes: 19480
/*🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪*/
/*🔪*/ import java.util. /*🔪*/
/*🔪*/  Scanner; public  /*🔪*/
/*🔪*/class Main { public/*🔪*/
/*🔪*/ static void main  /*🔪*/
/*🔪*/ (String[] args) { /*🔪*/
/*🔪*/System.out.println /*🔪*/
/*🔪*/   (new Scanner(   /*🔪*/
/*🔪*/  System.in).next()/*🔪*/
/*🔪*/   .compareTo      /*🔪*/
/*🔪*/("2019/04/30")<=0 ?/*🔪*/
/*🔪*/"Heisei" :"TBD");}}/*🔪*/
/*🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪*/

Measured memory_bytes: 23764
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]



X = int(input())
ans = 0

while True:
  if(X-500<0):
    break
  else:
    ans += 1000
    X -= 500

while True:
  if(X-5<0):
    break
  else:
    ans += 5
    X -= 5


print(ans)


Measured memory_bytes: 40552
// https://yamakasa.net/atcoder-agc-039-a/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string S;
    ll K;
    cin >> S >> K;
    ll n = S.length();
    if(n == 1) {
        cout << K / 2 << "\n";
        return 0;
    }
    ll l = 0;
    ll r = 0;
    for(int i = 0; i < n; i++) {
        if(S[0] == S[i]) {
            l++;
        } else {
            break;
        }
    }
    if(l == n) {
        cout << n * K / 2 << "\n";
        return 0;
    }
    for(int i = n - 1; i >= 0; i--) {
        if(S[n - 1] == S[i]) {
            r++;
        } else {
            break;
        }
    }
    if(l + r == n) {
        // S[0] != S[n - 1]
        ll ans = l / 2 * K + r / 2 * K;
        cout << ans << "\n";
        return 0;
    }
    ll ans = 0;
    ll c = 1;
    for(int i = l; i < n - r; i++) {
        if(S[i] == S[i + 1]) {
            c++;
        } else {
            ans += c / 2 * K;
            c = 1;
        }
    }
    ans += c / 2 * (K - 1);

    if(S[0] == S[n - 1]) {
        ans += l / 2 + (l + r) / 2 * (K - 1) + r / 2;
    } else {
        ans += l / 2 * K + r / 2 * K;
    }
    // cout << l << " " << r << "\n";
    cout << ans << "\n";
    return 0;
}

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

struct card_t {
	char s;
	int n;
	int idx;
};
typedef struct card_t Card;

int patition(Card a[MAX_N], int p, int r) {
	int x, i, j, t, s;
	char c;

	x = a[r].n;
	i = p - 1;
	for (j = p; j < r; j++) {
		if (a[j].n <= x) {
			i += 1;
			c = a[i].s;
			t = a[i].n;
			s = a[i].idx;
			a[i].s = a[j].s;
			a[i].n = a[j].n;
			a[i].idx = a[j].idx;
			a[j].s = c;
			a[j].n = t;
			a[j].idx = s;
		}
	}
	c = a[i+1].s;
	t = a[i+1].n;
	s = a[i+1].idx;
	a[i+1].s = a[r].s;
	a[i+1].n = a[r].n;
	a[i+1].idx = a[r].idx;
	a[r].s = c;
	a[r].n = t;
	a[r].idx = s;
	return i + 1;
}

void quick_sort(Card a[MAX_N], int p, int r) {
	int q;

	if (p < r) {
		q = patition(a, p, r);
		quick_sort(a, p, q-1);
		quick_sort(a, q+1, r);
	}
}

int main(void) {
	Card in[MAX_N];
	int n, i;
	const char *stable;

	scanf("%d ", &n);
	for (i = 0; i < n; i++) {
		scanf("%c %d ", &in[i].s, &in[i].n);
		in[i].idx = i;
	}
	quick_sort(in, 0, n-1);

	stable = "Stable";
	for (i = 0; i < n-1; i++) {
		if (in[i].n == in[i+1].n && in[i].idx > in[i+1].idx) {
			stable = "Not stable";
			break;
		}
	}
	puts(stable);

	for (i = 0; i < n; i++) {
		printf("%c %d\n", in[i].s, in[i].n);
	}
	return 0;
}

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

int luca_from_i(int N, int64_t Lm2, int64_t Lm1, int i){
  int64_t resolt = Lm1 + Lm2;
  int64_t temp = Lm1;
  Lm1 = resolt;
  Lm2 = temp;

  if(i==N){
    cout << resolt<< endl;
    return 0;
  }

  return luca_from_i(N, Lm2, Lm1, i+1);
}

int luca(int N){
  if(N==0){
    cout << 2 << endl;
    return 2;
  }
  if(N==1){
    cout << 1 << endl;
    return 1;
  }

  return luca_from_i(N, 2ll, 1ll, 2);
}


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

  luca(N);
}

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

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>a(m);
    for(int i=0;i<m;i++){
        cin >> a.at(i);
    }
    int ans =0;
    int ansa =0;
    for(int i=x;i>0;i--){
        for(int j=0;j<m;j++){
            if(a.at(j)==i){
                ans++;
            }
        }
    }//0made
    for(int i=x;i<n;i++){
        for(int j=0;j<m;j++){
            if(a.at(j)==i){
                ansa++;
            }
        }
    }
    int anss = min (ans,ansa);
    cout << anss << endl;
    
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,l,num;
  scanf("%d%d",&n,&l);
  num=(2*l+n-1)*n/2;
  if(l>=0)
    printf("%d\n",num-l);
  else if(l+n-1>=0)
    printf("%d\n",num);
  else
    printf("%d\n",num-(l+n-1));
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
int y,m,d;
char s[10];
while(scanf("%s%d%d%d",s,&y,&m,&d)==4){
    if(s=="#"){
        break;
    }
    else
    {
        if(y<=30){
            printf("%s %d %d %d\n","HEISEI",y,m,d);
        }
        else if(y==31 && m>=5){
            printf("%c %d %d %d\n",'?',y-30,m,d);
        }
        else if(y>31){
            printf("%c %d %d %d\n",'?',y-30,m,d);
        }
        else{
             printf("%s %d %d %d\n","HEISEI",y,m,d);
        }
    }
}
    return 0;
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
      
      
int main(){
  int n,a,b;
  cin >> n >>a >> b;
  int ac=0,bc=0; // acは国内の学生の通過者、bcは国外の通過者
  int bcr=0; // bcrは国外の順位
  for(int i=0;i<n;i++){
    char q;
    cin >> q;
    if(q=='a'){
      if(ac+bc<a+b){
        cout << "Yes" << endl;
        ac++;
      }else{cout << "No" << endl;}}
    if(q=='b'){
      if(ac+bc<a+b && bcr<b){
        cout << "Yes" <<endl;
        bc++;
      }else{cout << "No" << endl;}
    bcr++;}
    if(q=='c'){cout << "No" << endl;}
  }
}

Measured memory_bytes: 640
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


n = int(input())
s = str(input())

csum = [[0 for j in range(2)] for i in range(n+1)]
# csum[i][0] := iコ目までの黒の数
# csum[i][1] := iコ目までの白の数

for i in range(1,n+1):
  csum[i][0] = csum[i-1][0]
  if s[i-1] == "#":
    csum[i][0] += 1

for i in range(n-1,-1,-1):
  csum[i][1] = csum[i+1][1]
  if s[i] == ".":
    csum[i][1] += 1  

ans = n*2
for i,j in csum:
  ans = min(ans,i+j)

print(ans)

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

#define STRMAX 1000

void SolvePuzzle(const char* T, const char* P){
	int tlen = STRMAX;
	int plen = STRMAX;
	for (int i = 0; i < STRMAX; i++){
		if (tlen == STRMAX && T[i] == '\0') tlen = i;
		if (plen == STRMAX && P[i] == '\0') plen = i;
		if (tlen != STRMAX && plen != STRMAX) break;
	}
	if (tlen < plen) return;
	for (int i = 0; i < tlen - plen + 1; i++){
		bool b = true;
		for (int j = 0; j < plen; j++){
			if (T[i + j] != P[j]){
				b = false;
				break;
			}
		}
		if (b){
			std::cout << i << std::endl;
		}
			
	}
}

int main(){
	char T[STRMAX + 2];
	char P[STRMAX + 2];
	std::cin >> T >> P;
	SolvePuzzle(T, P);

	return 0;
}


Measured memory_bytes: 3136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var S []string
var h, w int
var bombs []Bomb

type Bomb struct {
	i, j int
}

func main() {
	sc.Split(bufio.ScanWords)
	h, w = nextInt(), nextInt()
	S = make([]string, h)
	ans := make([][]int, h)

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			ans[i] = append(ans[i], 0)
		}
	}

	for i := 0; i < h; i++ {
		S[i] = nextStr()
		for j := 0; j < w; j++ {

			if string(S[i][j]) == "#" {
				tmp := Bomb{i, j}
				bombs = append(bombs, tmp)
				ans[i][j] = -2
			}

		}
	}

	for _, bomb := range bombs {
		i := bomb.i
		j := bomb.j
		for a := maxInt(i-1, 0); a <= minInt(i+1, h-1); a++ {
			for b := maxInt(j-1, 0); b <= minInt(j+1, w-1); b++ {
				// fmt.Println(i, j, a, b)
				if i == a && j == b {
					continue
				}
				if ans[a][b] == -2 {
					continue
				}
				ans[a][b]++

			}
		}
	}

	// fmt.Println(ans, bombs)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range ans {
		for i := 0; i < w; i++ {
			if v[i] == -2 {
				buf.Write([]byte(fmt.Sprintf("#")))
			} else {
				buf.Write([]byte(fmt.Sprintf("%d", v[i])))
			}
			if i == w-1 {
				buf.Write([]byte(fmt.Sprintf("\n")))
			}
		}
	}
	buf.Flush()

}


Measured memory_bytes: 896
using System;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b;
            string[] s=Console.ReadLine().Split(' ');
            a=int.Parse(s[0]);
            b = int.Parse(s[1]);
            if (a + b == 15) Console.WriteLine("+");
            else if (a * b == 15) Console.WriteLine("*");
            else Console.WriteLine("x");
        }

    }
}


Measured memory_bytes: 27420
# 最初に入れておくとinputが早くなる
from operator import itemgetter
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))

sate = [0]
flag = True

for i in range(n):
    sate.append(sate[i] + l[i][0])
    if (sate[i + 1] > l[i][1]):
        flag = False
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 58344