akhauriyash/Code-Regression huggingface dataset:
// Aizu Vol-10 1004: Pair of Primes
// 2017.8.16 bal4u@uu

#include <stdio.h>

#define MAX  10000
#define SQRT 100     // sqrt(MAX)
char prime[MAX + 5], *p, *q, *pmax;

int main()
{
	int k, ans;

	for (pmax = prime + MAX, k = 3, p = prime + 3; k <= SQRT; k += 2, p += 2)
		if (!*p) for (q = p + k; q <= pmax; q += k) *q = 1;
	prime[1] = 1, prime[2] = 0; // for (p = prime + 4; p <= pmax; p += 2) *p = 1;

	while (scanf("%d", &k) == 1) {
		if (!(k & 1)) puts(prime[k - 1] ? "0" : "2");
		else if (k == 3) puts("1");
		else {
			char *s;
			for (ans = 0, s = p = prime + 3, q = prime + k - 2; q >= s; p += 2, q -= 2)
				if (!*p && !*q) ans++;
			printf("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int l,a,b,c,d;
  scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
  int x = (a+c-1)/c;
  x = max(x,(b+d-1)/d);
  printf("%d\n",l-x);
  return 0;
}

Measured memory_bytes: 2728
import java.util.Scanner;
import java.util.Arrays;

fun main (args : Array<String>) {
  val isPrime = BooleanArray(100_003 + 1) {true};
    isPrime[0] = false;
    isPrime[1] = false;
    
    for (i in 2 .. isPrime.size - 1) {
      if (isPrime[i]) {
        for (j in (i + i) .. isPrime.size - 1 step i) {
          isPrime[j] = false
        }
      }
    }

  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val X = input.nextInt()
    
    for (i in X..(isPrime.size - 1)) {
      if (isPrime[i]) {
        println(i)
        break
      }
    }
  }  
}

Measured memory_bytes: 38484
x = int(input())
if x % 11 == 0:
    print(x // 11 * 2)
else:
    cnt = x // 11 * 2
    x -= x // 11 * 11
    while x > 0:
        if cnt % 2 == 0:
            x -= 6
        else:
            x -= 5
        cnt += 1
    print(cnt)

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x = ni()
if x == 1:
    print(0)
else:
    print(1)


Measured memory_bytes: 10896
N, K = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
C = list(map(int, input().split()))
 
ans = -(10 ** 18)
 
for si in range(N):
    x = si
    loop = []
    total = 0
    while 1:
        x = P[x]
        loop.append(C[x])
        total += C[x]
        if x == si:
            break
    T = len(loop)  # 周期の大きさ
    tmp = 0
    for i in range(T):
        tmp += loop[i]
        if K < i + 1:
            break
        now = tmp
        if total > 0:  # loopの和が正ならloopを回した方がお得
            loop_times = (K - (i + 1)) // T  # 何周できるか
            now += total * loop_times
        ans = max(ans, now)
 
print(ans)

Measured memory_bytes: 80572
import math
x = int(input().split()[0])
def get_sieve_of_eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

data = get_sieve_of_eratosthenes(2*x+10)
for i in data:
  if i >= x:
    print(i)
    break

  


Measured memory_bytes: 17524
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  for(int i=0;i<a;i++){
    if(!isdigit(s[i])){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  if(s[a]!='-'){
    cout<<"No"<<endl;
    exit(0);
  }
  for(int i=a+1;i<b+a+1;i++){
    if(!isdigit(s[i])){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int C, N, asum, bsum, ans;

int main()
{
	in >> C >> N;
	std::vector<std::vector<int>>p(N, std::vector<int>(N));
	std::vector<std::vector<int>>A(N, std::vector<int>(N / 2));
	std::vector<std::vector<int>>B(N / 2, std::vector<int>(N));
	rep(i, N)
	{
		std::string temp;
		in >> temp;
		rep(j, N) p[i][j] = temp[j] - '0';
	}
	rep(i, N) rep(j, N) A[i][std::min(j, N - j - 1)] ^= p[i][j];
	rep(i, N) rep(j, N) B[std::min(i, N - i - 1)][j] ^= p[i][j];
	rep(i, N) rep(j, N / 2) asum += A[i][j];
	rep(i, N / 2) rep(j, N) bsum += B[i][j];
	if (asum == 0 && bsum == 0) ++ans;
	rep(loop, C - 1)
	{
		int num, x, y;
		in >> num;
		rep(i, num)
		{
			in >> x >> y;
			--x; --y;
			A[x][std::min(y, N - y - 1)] ^= 1;
			B[std::min(x, N - x - 1)][y] ^= 1;
			if (A[x][std::min(y, N - y - 1)] == 0) --asum;
			else ++asum;
			if (B[std::min(x, N - x - 1)][y] == 0) --bsum;
			else ++bsum;
		}
		if (asum == 0 && bsum == 0) ++ans;
	}
	out << ans << std::endl;
	return 0;
}



Measured memory_bytes: 10792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int m = in.nextInt();
    if (n >= m){
      System.out.println(0);
    } else {
      int[] array = new int[m];
      for (int i = 0; i < m; i++) {
        array[i] = in.nextInt();
      }

      Arrays.sort(array);
      int[] steps = new int[m - 1];
      for(int i = 0; i < m - 1; i++) {
        steps[i] = array[i + 1] - array[i];
      }

      Arrays.sort(steps);
      int[] result = new int[m - n];
      System.arraycopy(steps, 0, result, 0, m - n );

      int sum = 0;
      for(int i = 0; i < result.length; i++) {
        sum += result[i];
      }

      System.out.println(sum);
    }
  }
}

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

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

	long long ans = 0;
	for (int A = 1; A < N; ++A) {
		if (N % A == 0) {
			ans += N / A - 1;
		}
		else {
			ans += N / A;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
A, B, K = map(int, input().split())
k = 0
while True:
    if k == K:
        break
    if A % 2 == 1:
        A -= 1
    B += A // 2
    A -= A // 2
    k += 1
    if k == K:
        break
    if B % 2 == 1:
        B -= 1
    A += B // 2
    B -= B // 2
    k += 1
print(A, B)

Measured memory_bytes: 9128
s = gets.chomp + ?T
x, y = gets.split.map(&:to_i)

dp = Array.new(2) {{}}
i = s.index(?T)
dp[0][i] = 1
dp[1][0] = 1

s.slice!(0..i)
a = 0
m = 1

s.each_char do |c|
    if c == ?F
        a += 1
    else
        if a > 0
            h = {}
            dp[m].each_key {|k| h[k+a] = h[k-a] = 1}
            dp[m] = h
        end
        a = 0
        m ^= 1
    end
end

puts dp[0][x] && dp[1][y] ? "Yes" : "No"

Measured memory_bytes: 91284
console.log((args=>{
  const [A,B,C,D] = args.trim().split(' ').map(BigInt);
  const gcd = (a,b) => {while(a)[a,b]=[b%a,a]; return b;};
  const A2B = B - A + 1n;
  const divC = B/C - (A-1n)/C;
  const divD = B/D - (A-1n)/D;
  const CD = C*D/gcd(C,D);
  const divCD = B/CD - (A-1n)/CD;

  return `${A2B - divC - divD + divCD}`
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 29608
#include <stdio.h>
 
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BRACK 2
 
void visit(int);
 
int array[MAX][MAX], road_color[MAX] ,arr1[MAX], arr2[MAX];
int n, vst=0;
 
int main(){
  int num1, num2, num3, i, j;
 
  scanf("%d", &n);
 
  for( i=0; i<n; i++){
    for( j=0; j<n; j++){
      array[i][j] = 0;
    }
  }
 
  for( i=0; i<n; i++){
    scanf("%d %d", &num1, &num2);
    num1--;
 
    for( j=0; j<num2; j++){
      scanf("%d", &num3);
      num3--;
 
      array[num1][num3] = 1;
    }
  }
 
  for( i=0; i<n; i++){
    road_color[i] = WHITE;
  }
 
  for( i=0; i<n; i++){
    if( road_color[i] == WHITE )visit(i);
  }
 
  for( i=0; i<n; i++){
    printf("%d %d %d\n", i+1, arr1[i], arr2[i]);
  }
 
  return 0;
}
 
void visit(int u ){
  int i;
 
  road_color[u] = GRAY;
 
  arr1[u] = ++vst;
 
  for( i=0; i<n; i++){
    if( array[u][i] == 0 )continue;
 
    if( road_color[i] == WHITE )visit(i);
   
  }
    road_color[i] = BRACK;
 
    arr2[u] = ++vst;
}

Measured memory_bytes: 636
import Control.Monad
import Data.Functor
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector as V
import Data.List (minimumBy)

type Node   = Int
type Weight = Int
type AdjM   = V.Vector (VU.Vector Weight)
type MST    = [(Node, Weight)]


main :: IO ()
main = do
    n    <- readLn
    adjM <- V.replicateM n $
            VU.fromList .
            map ((\w -> if w == -1 then 2001 else w) . read) .
            words <$> getLine :: IO AdjM
    print $ total n adjM

total :: Int -> AdjM -> Weight
total n adjM = sum . map snd $ prim [(0, 0)]
  where
    prim :: MST -> MST
    prim mst
        | n == length mst = mst
        | otherwise       = prim (next:mst)
      where
        next :: (Node, Weight)
        next = minimumBy (\a b -> compare (snd a) (snd b)) unvisits

        unvisits :: [(Node, Weight)]
        unvisits = [ (node, (adjM V.! vnodes) VU.! node)
                   | node <- [0..(n-1)]
                   , node `notElem` (map fst mst)
                   , vnodes <- (map fst mst)
                   ]


Measured memory_bytes: 8388
#include<iostream>
using namespace std;
int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	int a[1000005] = {};
	int b[1000005] = {};
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i];
	}
	int check[1000005] = {};
	for (int i = 0; i < n; i++) {
		if (s[i] == 'C' && s[i - 1] == 'A') {
			check[i] += 1;
		}
	}
	int sum2[1000005];
	sum2[0] = 0;
	for (int i = 1; i < n; i++) {
		sum2[i] = check[i] + sum2[i - 1];
	}
	for (int i = 0; i < q; i++) {
		cout << sum2[b[i] - 1] - sum2[a[i] - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 15232
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)

#define ordered_set tree<ll,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) (ll)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0

typedef double db;
typedef long long ll;

const ll ary=1e5+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll m,k;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>m>>k;
	if(!k){
		for(int i=0;i<(1<<m);i++){
			cout<<i<<" "<<i<<" ";
		}
		return 0;
	}
	ll x=0;
	for(int i=0;i<(1<<m);i++){
		if(i==k){
			continue;
		}
		x=(x^i);
	}
	if(x!=k||k>=(1<<m)){
		cout<<-1;
		return 0;
	}
	vector<ll> q;
	for(int i=0;i<(1<<m);i++){
		if(i!=k){
			cout<<i<<" ";
			q.putb(i);
		}
	}
	cout<<k<<" ";
	for(int i=len(q)-1;i>=0;i--){
		cout<<q[i]<<" ";
	}
	cout<<k;
}

Measured memory_bytes: 3060
n, a, b = map(int, input().split())
s = a + b
ans = 0

if a == 0:
    print(ans)
    exit()
elif b == 0:
    print(n)
    exit()

if n <= s and n <= a:
    ans = n
elif n <= s:
    ans = a
else:
    d = n % s
    if d == 0:
        ans += n // s * a
    elif d >= a:
        ans += (n // s * a) + a
    else:
        ans += (n // s * a) + d

print(ans)

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

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

    if (n % 2 == 0)
    {
        int m2 = m / 2;
        int m1 = m - m2;
        for (int i = 1; i <= m1; i++)
        {
            cout << i << " " << m1 * 2 + 1 - i << endl;
        }

        int d = m1 * 2;
        for (int i = 1; i <= m2; i++)
        {
            cout << d + i << " " << d + m2 * 2 + 2 - i << endl;
        }
    }
    else
    {
        for (int i = 1; i <= m; i++)
        {
            cout << i << " " << m * 2 + 1 - i << endl;
        }
    }
}

Measured memory_bytes: 3600
#include <iostream>

//int a[10005];

int main()
{
  int n, m;
  std::cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++)
  {
    int cur;
    std::cin >> cur;
    sum += cur;
  }
  int diff = n - sum;
  if (diff < 0)
  {
    std::cout << "-1" << std::endl;
  }
  else
  {
    std::cout << diff << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3636
def k(ary, b)
  sum = 0
  ary.each_with_index do |a, i|
    # a - i - 1 = b
    sum += (a - (b + i + 1)).abs
  end
  sum.to_i
end

n=STDIN.gets.to_i
a = STDIN.gets.split(' ').map(&:to_i)
b = []

a.each_with_index do |a, i|
  b.push(a - i - 1)
end
b.sort!

b = b[b.length/2]

puts k(a, b)

Measured memory_bytes: 19896
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

int N,C;
int s[100003],t[100003],c[100003];

int main(){
	cin>>N>>C;
	rep(i,N) cin>>s[i]>>t[i]>>c[i];
	int T[100003][C+3];
  rep(i,C) Rep(j,100003) T[j][i]=0;
	rep (i,C){
		rep(j,N){
			if(c[j]==i){
				T[s[j]][i]++;
				T[t[j]+1][i]--;
			}
		}
	}
	int onair[100003][C+3];
	rep(i,C) onair[0][i]=0;
	rep(i,C){
		rep(j,100000){
			onair[j][i]=T[j][i]+onair[j-1][i];
		}
	}
	int ans[100003];
	Rep(i,100004) ans[i]=0;
	rep(i,C){
		rep(j,100000){
			if(onair[j][i]>=1)
			ans[j]++;
		}
	}
	sort(ans,ans+100001);
	reverse(ans,ans+100001);
	cout<<ans[0]<<endl;
	
	  return 0;
  }


Measured memory_bytes: 27648
import math

def main():
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    print(math.ceil(n/min(a,b,c,d,e))+4)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    int v,j;
    for(int i =1;i <= n-1;i++){
        for(int k = 0;k < n;k++){
                if(k != n-1){
                    printf("%d ",a[k]);
                } else {
                    printf("%d\n",a[k]);
                }
        }
        v = a[i];
        j = i-1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        
    }
    for(int k = 0;k < n;k++){
                if(k != n-1){
                    printf("%d ",a[k]);
                } else {
                    printf("%d\n",a[k]);
                }
            }
}



Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    int flag=0;
    int n;
    cin>>a>>n;
    while(n--)
    {
        int x;
        cin>>x;
        switch(x)
        {
        case 1:
            flag=!flag;
            break;
        case 2:
            int y;
            char b;
            cin>>y>>b;
            if((y==1&&!flag)||(y==2&&flag))
            {
                a.insert(a.begin(),b);
            }
            else a.insert(a.end(),b);
        }
    }
    if(flag)reverse(a.begin(),a.end());
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 900
#include<stdio.h>
#define N 44

int main(void){
  int n, i;
  int fib[N];

  scanf("%d",&n);

  for(i=0;i<=n;i++){

    if(i==0 || i==1) fib[i] = 1;

    else if(i>=2) fib[i] = fib[i-1] + fib[i-2];

  }

  printf("%d\n",fib[n]);

  return 0;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int min = Integer.MAX_VALUE;
		int max = -1;
		for(int i = 0; i < n; i++){
			int a = in.nextInt();
			if(a > max) max = a;
			if(a < min) min = a;
		}
		System.out.println(max-min);
		in.close();
	}

}

Measured memory_bytes: 21204
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=1<<29;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

int main(){
    int n,T;
    cin>>n>>T;
    LL t[200100];
    for(int i=0;i<n;++i){
        cin>>t[i];
    }
    LL ans=T;
    for(int i=0;i<n-1;++i){
        ans+=min((LL)T,t[i+1]-t[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N,K;
int main(){
	cin>>N>>K;

int ans=1;
	ans*=K;
	for(int i=1;i<N;i++){
		ans*=(K-1);
	}

	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int H, W, i, j;
   while(scanf("%d %d", &H, &W)){
   if(H == 0 && W == 0)break;
for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
        if(i == 0 || i == H-1 || j == 0 || j == W-1){
            printf("#");
        } else {
            printf(".");
        }
    }
    printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2088
#include<iostream>
#include<cassert>
#include<algorithm>
#include<vector>
using namespace std;

bool solve(vector<int> v){
  int maxp = 0;
  for ( int i = 0; i < v.size(); i++ ){
    if ( i*10 <= maxp ){
      maxp = max(maxp, v[i] + i*10);
    }
  }
  return 10*(v.size()-1) <= maxp;
}

main(){
  int N; cin >> N;
  vector<int> v, u;
  for ( int i = 0; i < N; i++ ){
    int x; cin >> x; v.push_back(x);
  }
  u = v;
  reverse(u.begin(), u.end());

  cout << (solve(v)&&solve(u)?"yes":"no") << endl;

  return 0;
}




Measured memory_bytes: 7584
c=[list(map(int, input().split())) for i in range(3)]
if (c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]) and \
   (c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61960
(defun colorfulTransceivers (a b c d)
  (cond
    ((<= (abs (- a c)) d) (format t "Yes~%"))
    ((and (<= (abs (- a b)) d) (<= (abs (- b c)) d))
     (format t "Yes~%"))
    (t
     (format t "No~%"))))    

(defun split-string (str)
  (let ((string-position (position #\Space str)))
    (cond
      ((null string-position) (list str))
    (t (cons (subseq str 0 string-position) (split-string (subseq str (1+ string-position))))))))


(apply #'colorfulTransceivers (mapcar #'parse-integer (split-string (read-line))))

Measured memory_bytes: 15208
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

typedef long long ll;

using namespace std;

int main()
{
    int n; cin >> n;
    ll res = 1;
    for (ll i = 2; i <= n; i++){
        res = res * i % (1000000007); 
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  LL h;
  cin >> h;
  LL count = 0;
  while(h>0){
    h /= 2;
    count++;
  }
  LL res = pow(2,count);
  cout << res-1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long MOD  = 1e9+7;
 
 
signed main(){
    fast;
    int n;
    cin >> n;
    vector <string> a(n);
    for(int i=0 ; i<n ; i++){
        string x; cin >> x;
        sort(all(x));
        a[i] = x;
    }
     sort(all(a));
    // for(auto x : a)
    //     cout << x << endl;
    int ans = 0;
    int c = 1;
    for(int i=0 ; i<n-1; i++){
        if(a[i]==a[i+1])
            c++;
        else {
            ans += (c*(c-1))/2;
            c= 1;
        }
    }
    ans += (c*(c-1))/2;
    cout << ans << endl;
}

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

int main() {
	int n,m;
	cin >> n >> m;
	if(n<m){
		for(int i=0;i<m;i++){
			cout << n;
		}
		cout << endl;
	}else{
		for(int i=0;i<n;i++){
			cout << m;
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))
 
l=[x[i] for i in range(n)]
 
l.sort()
 
small=l[n//2-1]
large=l[n//2]
 
for i in range(n):
    if x[i]>=large:
        print(small)
    else:
        print(large)

Measured memory_bytes: 25228
N,H = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for _ in range(N)]
a = sorted(a,reverse=True,key= lambda x : x[1])
ma = max(a,key = lambda x:x[0])[0]
cnt = 0
su = 0
for i in range(N):
  if a[i][1]>=ma:
    if su<H:
      cnt+=1
      su += a[i][1]
    else:
      print(cnt)
      exit()
H -= su
if H<=0:
  print(cnt)
  exit()
cnt+= (H+ma-1)//ma
print(cnt)

Measured memory_bytes: 23512
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;
 
void solve()
{
	int n,x,t;
	cin>>n>>x>>t;
	int ans=0;
	while(n>x)
	{
		ans+=t;
		n-=x;
	}
	if(n!=0)
		ans+=t;
	cout<<ans;
}
 
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int mi=1000,ans=0;
int main(){
	string s,t;
	cin>>s>>t;
	int l2=t.length(),l1=s.length();
	for(int i=0;i<l1-l2+1;i++){
		ans=0;
		for(int j=0;j<l2;j++){
			if(s[j+i]!=t[j])ans++;
		}
		mi=min(mi,ans);
	}
	cout<<mi<<endl;
} 

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

using namespace std;

int main ()
{
  string S,T;
  cin>>S>>T;
  int n=S.size();
  for(int i=0;i<n;i++)
  {
    if(S[i]!=T[i])
    {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3588
INF = 1 << 29
COINS = [500,100,50,10,5,1]
while gets
  l = $_.split.map(&:to_i)
  p = l.shift
  break if p == 0
  ret = INF
  for change in 0..499
    ps = cs = 0
    pay = p + change
    for k in 0..5
      m = [pay/(c=COINS[k]), l[5-k]].min
      ps += m
      pay -= m*c
      m = change / c
      cs += m
      change -= m*c
    end
    ret = ps + cs if ret > (ps + cs)
  end
  p ret
end

Measured memory_bytes: 8716
import sys
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def solve():
    N, P = map(int, input().split())
    S = input()
    if 10%P == 0:
        ans = 0
        for i in range(N):
            if int(S[N-i-1]) % P == 0:
                ans += N - i
        
        return ans
    
    ten = 1
    cur = 0
    val = [0] * P
    val[cur] += 1
    for i in range(N):
        cur = (cur + int(S[N-i-1])*ten) % P
        ten *= 10
        ten %= P
        val[cur] += 1
    ans = 0
    for p in range(P):
        ans += val[p] * (val[p] - 1) // 2
    
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3880
// AOJ 2643: AI
// 2018.1.28 bal4u

#include <stdio.h>

char map[53][53];
char s[1002];
char tr['Z'];
char rot[2][4] = {{3,0,1,2},{1,2,3,0}};
char mov[2][4] = {{-1,0,1,0},{0,1,0,-1}};	// N,E,S,W
char mk[53][53][4][1002];
int ans, r, c, d;		// d: dir
int gr, gc;				// goal

char *prg(char *p);

char *act(char *p)
{
	int nr, nc;

	ans++;
	if (*p == '<' || *p == '>') d = rot[*p=='>'][d];
	else {
		if (*p == '^') nr = r+mov[0][d], nc = c+mov[1][d];
		else           nr = r-mov[0][d], nc = c-mov[1][d];
		if (!map[nr][nc]) r = nr, c = nc;
	}
	return p+1;
}

char *con(int *res, char *p)
{
	int f;

	f = 1; if (*p == '~') p++, f = 0;
	*res = !f;

	if (*p == 'T') *res = f;
	else if (*p == 'C') {
		if (map[r+mov[0][d]][c+mov[1][d]]) *res = f;
	} else if (d == tr[*p]) *res = f;
	return p+1;
}

char *skip(char *p, char a, char b)
{
	int f = 1;
	while (*p > ' ') {
		if (*p == b) f++;
		else if (*p == a) { if (--f == 0) break; }
		p++;
	}
	return p;
}

char *do_if(char *p)
{
	int f;

	p = con(&f, p);
	if (f) { if ((p = prg(p)) == NULL) return NULL; }
	else p = skip(p, ']', '[');
	if (*p != ']') return NULL;
	return p+1;
}

char *do_while(char *p)
{
	int f;
	char *q;

	for (q = p; ; p = q) {
		p = con(&f, p);
		if (f) { if ((p = prg(p)) == NULL) return NULL; }
		else { p = skip(p, '}', '{'); break; }
	}
	if (*p != '}') return NULL;
	return p+1;
}

char *prg(char *p)
{
	while (1) {
		if (r == gr && c == gc) return NULL;
		if (mk[r][c][d][p-s]) { ans = -1; return NULL; }
		mk[r][c][d][p-s] = 1;

		if (*p <= ' ') { ans = -1; return NULL; }
		if (*p == ']' || *p == '}') break;
		if      (*p == '[') { if ((p = do_if   (p+1)) == NULL) return NULL; }
		else if (*p == '{') { if ((p = do_while(p+1)) == NULL) return NULL; }
		else p = act(p);
	}
	return p;
}

int main()
{
	int H, W, sr, sc;
	char *p;

	tr['N'] = 0, tr['E'] = 1, tr['S'] = 2, tr['W'] = 3;

	fgets(s, 10, stdin), sscanf(s, "%d%d", &H, &W);
	for (r = 0; r < H; r++) {
		fgets(p=map[r], 1002, stdin);
		for (c = 0; c < W; c++, p++) {
			if      (*p == 's') sr = r, sc = c;
			else if (*p == 'g') gr = r, gc = c;
			*p = (*p == '#');
		}
	}
	fgets(s, 1002, stdin);

	r = sr, c = sc, d = 0;
	ans = 0;
	prg(s);
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 10948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
struct seg{
    ll s,dl;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    vector<seg>A(n);
    REP(i,n){
        cin >> A[i].s >> A[i].dl;
    }
    sort(A.begin(), A.end(), [](const seg &a, const seg &b){ return a.dl<b.dl;});
    vector<ll> DP(n+1,0);
    FOR(i,1,n+1){
        DP[i]= A[i-1].s+DP[i-1];
    }
    int f= 1;
    REP(i,n){
        if(DP[i+1]>A[i].dl) f= 0;
    }
    cout << ((f)?"Yes":"No") << endl;
}

Measured memory_bytes: 4992
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    dp = [0] * 100
    dp[0] = 2
    dp[1] = 1
    for i in range(2, 100):
        dp[i] = dp[i - 1] + dp[i - 2]
    print(dp[N])


if __name__ == '__main__':
    main()


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        map<int,int> m, m2;
        for(int j = 0; j < i; ++j)
            ++m[s[j]];
        for(int j = i; j < n; ++j)
            ++m2[s[j]];
        int sum = 0;
        for(auto& x : m)
            sum += min({1, x.second, m2[x.first]});
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/// Swift5 -> Swift2.2
extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
       self.init(count: count, repeatedValue: repeating)
    }
}
/// end

let N = Int(readLine()!)!
let h = [0] + readLine()!.split(separator: " ").map { Int($0)! }
var dp = Array(repeating: 0, count: N + 1)

for i in 1 ... N {
    switch i {
    case 1:
        continue
    case 2:
        dp[i] = abs(h[i] - h[i - 1])
    default:
        // Avoid "expression was too complex to be solved in reasonable time"
        let step1 = dp[i - 1] + abs(h[i] - h[i - 1])
        let step2 = dp[i - 2] + abs(h[i] - h[i - 2])
        dp[i] = min(step1, step2)
    }
}

print(dp.last!)


Measured memory_bytes: 7148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int A,B,C;
    cin >> A >> B >> C;
    
    int K;
    cin >> K;
    rep(i,K){
        if(A >= B) B*=2;
        else if(B >= C) C*=2;
        else break;
    }
    
    if(A < B && B < C) cyes;
    else cno;
    
    
    

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define endl              "\n"
#define pb              push_back
#define fir               first
#define sec               second
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define ll              long long
#define ld              long double
#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define isPowerOfTwo(s) (!(s & (s-1)))
typedef vector<int> vi;
typedef deque<int> de;
void origi() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
int n , arr[2000];
int bs(int i, int r) {
    int str = r, end = n - 1 , ans=r;
    while (str <= end) {
        int mid = (str + end ) / 2;
        if (arr[r] + arr[i] > arr[mid])
            ans = mid, str = mid + 1;
        else end = mid - 1;
    }
    return ans - r;
}
void tiranga() {
    int res = 0;
    cin >> n;
    lp(i, n) cin >> arr[i];
    sort(arr, arr + n);
    lp(i, n) {
        loop(r, i + 1, n - 1) res+=bs(i,r);
    }
    cout << res;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#else
#endif 
    origi();
    tiranga();
   
}


Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
diff = []

for i in range(len(a)):
    if (i == len(a) - 1):
        distance = a[0] + (k - a[-1])

    else:
        tar2 = a[i + 1]
        tar1 = a[i]
        distance = tar2 - tar1

    diff.append(distance)

# スタート位置を見つける
index = diff.index(max(diff))
ans = sum(diff) - max(diff)

print(ans)
# print(index)
# > 2なので、15~5は避ける。
# if (index == len(diff)):


Measured memory_bytes: 32284
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int N, cnt, res;

int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
	{
		int t;
		scanf("%d", &t);
		if (t == i) cnt++;
		else
		{
			res += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	res += (cnt + 1) / 2;

	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
def A():
    temp = [int(i) for i in input().split()]
    print(max(0, temp[0]-2*temp[1]))

def B():
    N = int(input())
    T = [int(i) for i in input().split()]
    s = 0
    for i in range(N):
        for j in range(i):
            s += T[i]*T[j]
    print(s)

def C():
    N = int(input())
    S = input()
    if N == 1:
        print(1)
    else:
        ans = 1
        cur_c = S[0]
        for c in S:
            if c != cur_c:
                ans += 1
                cur_c = c
        
        print(ans)

from bisect import bisect_left, bisect_right
from itertools import combinations 

def D():
    N = int(input())
    L = sorted([int(i) for i in input().split()])
    count = 0
    for i in range(N):
        s = 0
        e = i-1
        while s<e:
            if L[i] < L[s]+L[e]:
                count += e-s
                e -= 1
            else:
                s += 1

    # dp_sum = [[0 for i in range(N)] for j in range(N)]
    # count = 0
    # for i in range(N):
    #     for j in range(i):
    #         print(L, L[i]+L[j])
    #         print(bisect_left(L, L[i]+L[j])-2, count)
    #         check_idx = bisect_left(L, L[i]+L[j])
    # count = 0
    # for i in range(N):
    #     for j in range(i):
    #         for k in range(j):
    #             if L[k] < L[i]+L[j] and L[j] < L[i]+L[k] and L[i] < L[j]+L[k]:
    #                 count += 1

    print(count)

D()

Measured memory_bytes: 3188
def resolve():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))

    ans = [1]*n
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if h[a] > h[b]:
            if ans[a] == 1:
                ans[a] = 1
            ans[b] = 0
        elif h[a] == h[b]:
            ans[a] = 0
            ans[b] = 0
        else:
            if ans[b] == 1:
                ans[b] = 1
            ans[a] = 0
    print(sum(ans))

resolve()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll mod = 1000000007;
int main(){
  int n; cin >> n;
  vector <ll> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]++;
  }
  vector <ll> num(n+1);
  num[0] = 3;
  ll ans = 1;
  rep(i, n){
    ans *= (num[a[i]-1]-num[a[i]]);
    ans %= mod;
    num[a[i]]++;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
    int a[2];
    while (cin>>a[0]>>a[1]) {
        if (a[0]==0&&a[1]==0) {
            return 0;
        } else {
            sort(a,a+2);
            cout<<a[0]<<" "<<a[1]<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	
	int X;
	cin>>X;
	if(X==5||X==7||X==3){
		ce("YES")
	}else{
		ce("NO")
	}
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
ll ma=0,v,c; int n,u,b,w;
vector<ll> a[4],s[4];
 
int main(){
	cin >> n >> u >> c >> b;
	a[0].push_back(b);
	REP(i,1,n){
		cin >> w >> v;
		a[w-c].push_back(v);
	}
	REP(i,0,4) sort(a[i].begin(),a[i].end(),greater<ll>());
	REP(i,0,4) s[i].push_back(0);
	REP(i,0,4) REP(j,1,a[i].size()+1) s[i].push_back(s[i][j-1]+a[i][j-1]);
	REP(i,0,a[0].size()+1) REP(j,0,a[1].size()+1) REP(k,0,a[2].size()+1) REP(l,0,a[3].size()+1)
		if((c*i)+(c+1)*j+(c+2)*k+(c+3)*l<=u) ma=max(ma, s[0][i]+s[1][j]+s[2][k]+s[3][l]);
	
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i, n, s, t;
  
  scanf("%d %d", &s, &t);
  
  if(s < t){
    i=s;
    s=t;
    t=i;
  }
  n= s%t;
  while(n!=0){
    s = t;
    t = n;
    n = s % t;
  }
  printf("%d\n", t);
  return 0;
}



Measured memory_bytes: 2140
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int x;
    cin >> x;
    int a = 0;
    int b = 0;
    while(x >= 500){
        x -= 500;
        a += 1;
    }
    while(x >= 5){
        x -= 5;
        b += 1;
    }
    cout << 1000 * a + 5 * b << endl;
}

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

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

const int INF = 10000000;
const int MAX_V = 1000;
int graph[2][MAX_V][MAX_V];
int n, m;

bool visited[MAX_V];
int cost[MAX_V];

void init_graph() {
    REP(h, 2) {
        REP(i, m) {
            REP(j, m) {
                if (i == j) graph[h][i][j] = 0;
                else        graph[h][i][j] = INF;
            }
        }
    }
}

void make() {
    REP(i, n) {
        int u, v, c, t;
        scanf("%d %d %d %d", &u, &v, &c, &t);
        u--; v--;
        graph[0][u][v] = c; graph[0][v][u] = c;
        graph[1][u][v] = t; graph[1][v][u] = t;
    }
}

void init_dijkstra() {
    REP(i, MAX_V) visited[i] = false;
    REP(i, MAX_V) cost[i] = INF;
}

void dijkstra(int start, int g[MAX_V][MAX_V]) {
    init_dijkstra();

    cost[start] = 0;

    while (true) {
        int mi = INF;
        int nxt = -1;
        visited[start] = true;
        REP(i, m) {
            if (visited[i]) continue;
            if (i != start) {
                int d = cost[start] + g[start][i];
                if (d < cost[i]) {
                    cost[i] = d;
                }
            }
            if (mi > cost[i]) {
                mi = cost[i];
                nxt = i;
            }
        }
        start = nxt;
        if (nxt == -1) break;
    }
}

void solve() {
    while (true) {
        scanf("%d %d", &n, &m);

        if (n == 0 && m == 0) break;

        init_graph();

        make();

        int k;
        scanf("%d", &k);

        REP(i, k) {
            int p, q, r;
            scanf("%d %d %d", &p, &q, &r);
            p--; q--;
            dijkstra(p, graph[r]);
            printf("%d\n", cost[q]);
        }
    }
}

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

Measured memory_bytes: 5516
while True:
    v = int(input())
    if v == 0:
        break
    
    c = 0
    f = 0
    for i in range(1,13):
        m, n = [int(x) for x in input().split()]
        c += m - n
        if f == 0 and c >= v:
            f = i
    
    if f > 0:
        print(f)
    else:
        print("NA")



Measured memory_bytes: 5620
#include <cstdio>
#include <utility>
#include <queue>
#include <iostream>
using namespace std;

int main(){
  int W, H, gx, gy, sx, sy, n = 0;
  cin >> W >> H;
  string M[H];
  vector< pair<int,int> > springs;
  for(int i = 0; i < H; ++i){
    cin >> M[i];
    for(int j = 0; j < W; ++j){
      if(M[i][j] == 'g'){
	gx = i;
	gy = j;
	M[i][j] = '.';
      }else if(M[i][j] == 's'){
	sx = i;
	sy = j;
	M[i][j] = '.';
	++n;
      }else if(M[i][j] == '.') ++n;
      else if(M[i][j] == '*'){
	springs.push_back(make_pair(i,j));
      }
    }
  }
  double INF = (1e10), l = 0.0, r = INF, exp_[H][W], exp[H][W];

  int d[] = {1,0,-1,0};
  queue< pair<int,int> > que;
  que.push(make_pair(gx,gy));
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      exp_[i][j] = INF;
      exp[i][j] = INF;
    }
  }

  exp_[gx][gy] = 0.0;
  while(!que.empty()){
    int x = que.front().first, y = que.front().second;
    que.pop();
    for(int k = 0; k < 4; ++k){
      int x_ = x + d[k], y_ = y + d[(k+1)%4];
      if(x_ >= H || x_ < 0 || y_ >= W || y_ < 0) continue;
      char c = M[x_][y_];
      if(c == '.' && exp_[x_][y_] > exp_[x][y]+1){
	exp_[x_][y_] = exp_[x][y]+1;
	que.push(make_pair(x_,y_));
      }
    }
  }
  vector< vector<double> > dist_from_spring(H, vector<double>(W, INF));
  for(int i = 0; i < springs.size(); ++i){
    queue< pair<int,int> > que2;
    que2.push(make_pair(springs[i].first, springs[i].second));
    dist_from_spring[springs[i].first][springs[i].second] = 0;
    while(!que2.empty()){
      int x = que2.front().first, y = que2.front().second;
      que2.pop();
      for(int k = 0; k < 4; ++k){
	int x_ = x + d[k], y_ = y + d[(k+1)%4];
	if(x_ >= H || x_ < 0 || y_ >= W || y_ < 0) continue;
	char c = M[x_][y_];
	if(c == '.' && (dist_from_spring[x_][y_] > dist_from_spring[x][y]+1)){
	  que2.push(make_pair(x_,y_));
	  dist_from_spring[x_][y_] = dist_from_spring[x][y]+1;
	}
      }
    }
  }
 
  for(int t = 0; t < 100; ++t){
    double mean = (l+r)/2.0;
    long double s = 0.0;
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	if(M[i][j] == '.'){
	  exp[i][j] = min(exp_[i][j], dist_from_spring[i][j]+mean);
	  s += exp[i][j];
	}
      }
    }

    if(s/n < mean){
      r = mean;
    }else{
      l = mean;
    }
  }
  printf("%.12f\n",exp[sx][sy]);
  return 0;
}

Measured memory_bytes: 8964