akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

"""
6
40 1 30 2 7 20
"""

N = getN()
A = getList()
A.sort()
imos = copy.deepcopy(A)
for i in range(N - 1):
    imos[i + 1] += imos[i]

# 自分より小さい怪物を全て飲み込んだときに一つ上の怪物を飲み込めるか
streak = [0] * N
streak[-1] = 1
for i in range(N - 1):
    if imos[i] * 2 >= A[i + 1]:
        streak[i] = 1

ans = 0
for i in range(N - 1, -1, -1):
    if streak[i] == 1:
        ans += 1
    else:
        break
print(ans)

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

using namespace std;

#define N 60

int n,ans,a[N],b[N];
map<int,map<int,int> > mp;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d%d",a+i,b+i);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) if (i!=j) ans=max(ans,++mp[a[i]-a[j]][b[i]-b[j]]);
	printf("%d\n",n-ans);
	
	return 0;
}
			

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


int main(){
  int x, y;

  while(true){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    else if(x <= y) cout << x << " " << y << endl;
    else if(x > y) cout << y << " " << x << endl;
    }
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.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+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >>n;
  vector<int> A(n);
  rep(i,n) cin >>A[i];
  sort(A);
  rep(i,n-1){
    if(A[i] == A[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

#define _overload3(_1, _2, _3, name, ...) name
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define REP(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)

typedef long long int ll;
typedef unsigned long long int ull;

const int MOD=(int)1e9+7;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll g=gcd(a,b);return a/g*b;}
ll digitsum(ll a){ll x=0;while(a>0){x+=a%10;a/=10;}return x;}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,ans=0;
    cin>>n>>m;
    vector<int> a(m,0);
    rep(i,n){
        int k;
        cin>>k;
        rep(j,k){
            int t;
            cin>>t;
            t--;
            a[t]++;
        }
    }
    rep(i,m){
        if(a[i]==n)ans++;
    }
    cout<<ans<<endl;
}

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

int main(int argc, char const* argv[])
{
  char assignments[][5] = {
    {  0 ,  0 ,  0 ,  0 ,  0  },
    { '.', ',', '!', '?', ' ' },
    { 'a', 'b', 'c',  0 ,  0  },
    { 'd', 'e', 'f',  0 ,  0  },
    { 'g', 'h', 'i',  0 ,  0  },
    { 'j', 'k', 'l',  0 ,  0  },
    { 'm', 'n', 'o',  0 ,  0  },
    { 'p', 'q', 'r', 's',  0  },
    { 't', 'u', 'v',  0 ,  0  },
    { 'w', 'x', 'y', 'z',  0  }
  };
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
      int key = (*it) - '0';
      if (key == 0) {
        continue;
      }
      int x = 0;
      for (; *it != '0'; ++it) {
        ++x;
      }
      --x;
      int a;
      if (key == 1)
        a = 5;
      else if (key == 7 || key == 9)
        a = 4;
      else
        a = 3;
      std::cout << assignments[key][x % a];
    }
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,size,ans;
int  t[100000];
int dp[100000][2];
bool flg;

void init(){
  dp[0][0]=1;
  dp[0][1]=2;
  size=0;
  flg=false;
  ans=0;
}

int main(){

  while(cin>>n>>m&&n&&m){
    init();
    for(int i=0;i<m;i++){
      cin>>t[size];
      if(t[size]==0)flg=true;
      else size++;
    }
    sort(t,t+m);
    for(int i=1;i<size;i++){
      if(t[i]-1==t[i-1]){
	dp[i][0]=dp[i-1][0]+1;
	dp[i][1]=dp[i-1][1]+1;
      }else if(t[i]-2==t[i-1]){
	dp[i][1]=dp[i-1][0]+2;
	dp[i][0]=1;
      }else{
	dp[i][0]=1;
	dp[i][1]=2;
      }
      ans=max(ans,dp[i][0]);
      if(flg)ans=max(ans,dp[i][1]);
    }
    if(ans>n)ans--;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 2124
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int R = I.nextInt();
		int C = I.nextInt();
		int K = I.nextInt();
		int Bl = 0;
		int ans = 0;
		char[][] grid = new char[R][C];
		for (int r = 0; r < R; r++) {
			grid[r] = I.next().toCharArray();
			for (int i = 0; i < C; i++) if (grid[r][i]=='#') Bl++;
		}
		for (int rnum = 0; rnum < (2<<R); rnum++) {
			for (int cnum = 0; cnum < (2<<C); cnum++) {
				boolean[] vis = new boolean[R];
				int cur = 0;
				for (int row = 0; row < R; row++) {
					if ((rnum>>row)%2==1) {
						vis[row]=true;
						for (int c = 0; c < C; c++) {
							if (grid[row][c]=='#') cur++;
						}
					} 
				}
				for (int col = 0; col < C; col++) {
					if ((cnum>>col)%2==1) {
						for (int r = 0; r < R; r++) {
							if (grid[r][col]=='#'&&!vis[r]) {
								cur++;
							}
						}
					} 
				}
				if (cur==Bl-K) ans++;
			}	
		}
		O.pln(ans/4);
	}
	public static ArrayList<String> recur(int N){
		ArrayList<String> ret = new ArrayList<String>();
		if (N==1) {
			for (int i = 0; i <= N; i++) {
				ret.add(Integer.toString(i)+" ");
			}
			return ret;
		}
		ArrayList<String> prev = recur(N-1);
		for (int i = 0; i < prev.size(); i++) {
			String S = prev.get(i);
			String[] cur = prev.get(i).split(" ");
			int cmp = Integer.parseInt(cur[cur.length-1]);
			for (int j = cmp; j <= N; j++) {
				ret.add(S+Integer.toString(j)+" ");
			}
		}
		return ret;
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

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

using ll = long long;

const ll M = 1e9 + 7;

ll mul(ll a, ll b) {
    return a * b % M;
}

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= M) res -= M;
    return res;
}

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n & 1) return mul(x, mod_pow(mul(x, x), n / 2));
    return mod_pow(mul(x, x), n / 2);
}

ll inverse(ll a) {
    return mod_pow(a, M - 2);
}

ll fac[1000010];

void compute_fac() {
    fac[0] = 1;
    for (int i = 1; i < 1000010; i++) {
        fac[i] = mul(fac[i - 1], i);
    }
}

int combo(int n, int k) {
    return mul(fac[n], inverse(mul(fac[k], fac[n - k])));
}

int main(int argc, char *argv[])
{
    compute_fac();
    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) return cout << 0 << endl, 0;
    int n = (2 * X - Y) / 3;
    int m = X - 2 * n;
    if (n < 0 || m < 0) return cout << 0 << endl, 0;
    cout << combo(n + m, n) << endl;
    return 0;
}


Measured memory_bytes: 8064
fun main(args: Array<String>) {
    val s = Integer.parseInt(readInputLine())
    
    // 前半部
    val a = s / 100
    // 後半部
    val b = s % 100

    val isMonthA = isMonth(a)
    val isMonthB = isMonth(b)

    if (isMonthA) {
        if (isMonthB) {
            println("AMBIGUOUS")
        } else {
            println("MMYY")
        }
    } else {
        if (isMonthB) {
            println("YYMM")
        } else {
            println("NA")
        }
    }
}

fun isMonth(a: Int): Boolean {
    return 1 <= a && a <= 12
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 29752
import bisect
A,B,Q = map(int,input().split())
INF = float('inf')
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b-1],s[b]]:
        for T in [t[d-1],t[d]]:
            d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Measured memory_bytes: 12804
-module('Main').
-export([main/1]).

solve() ->
    [N] = input("~d"),
    Sum = lists:sum([A || A <- lists:seq(1, N), A rem 3 =/= 0, A rem 5 =/= 0]),
    io:format("~B~n", [Sum]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.


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

int main() {
    int N,i;
    string S;
    cin >> N;

    for(i=0 ; i<N ; i++){
        cin >> S;
        if (S == "Y"){
            cout << "Four" << endl;
            break;
        }
    }

    if(i == N && S != "Y")
    cout << "Three" <<endl;
}


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

using namespace std;

int main()
{
	double x1, y1, x2, y2, d;

	cin >> x1 >> y1 >> x2 >> y2;

	d = sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

	cout << fixed << d << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = n; i < 1000; i++) {
    if (i % 111 == 0) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll  L,R,res,t,MOD=2019;
	cin>>L>>R;
	res=(L%MOD)*(R%MOD);
	ll ml=L%MOD,mr=R%MOD;

	if(R-L>=2019)cout<<0<<endl;
	else
	{
		for(ll i=L;i<R;i++)
			for(ll j=i+1;j<=R;j++)
				res=min(res,(i*j)%2019);
		cout<<res<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

typedef long long ll;
using namespace std;
int n;
ll a[10010]; 
int main() {
	cin >> n;
	rep(i,n) {
		cin >> a[i];
	}
	sort(a, a+n);
	ll s = 0;
	rep(i,n) {
		s += a[i];
	}
	cout << a[0] << " " << a[n-1] << " " << s << endl;
	return 0;
}

Measured memory_bytes: 1260
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().execute(System.in, System.out);
	}

	int[] links;
	int[] nexts;
	List<Integer>[] roads;

	@SuppressWarnings("unchecked")
	public void execute(InputStream in, PrintStream out) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		links = new int[n];
		nexts = new int[n + 1];
		roads = new List[n + 1];

		int a, b;
		for (int i = 0; i < m; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			
			addRoad(a, b);
			addRoad(b, a);
		}
		sc.close();
		
		nexts[1] = 1;
		linkRooms();

		for (int i = 1; i <= n; i++) {
			if (nexts[i] == 0) {
				out.println("No");
				return;
			}
		}
		
		out.println("Yes");
		for (int i = 2; i <= n; i++) {
			out.println(nexts[i]);
		}
	}

	private void linkRooms() {
		int len = links.length;

		int idx = 0;
		int cnt = 0;
		links[cnt++] = 1;

		while (idx < len) {
			int i = links[idx++];
			List<Integer> r = roads[i];
			if (r != null) {
				for (int k : r) {
					if (nexts[k] == 0) {
						nexts[k] = i;
						links[cnt++] = k;
					}
				}
			}
		}
	}

	private void addRoad(int x, int y) {
		List<Integer> r = roads[x];
		if (r == null) {
			r = new ArrayList<Integer>();
			roads[x] = r;
		}
		r.add(y);
	}

}


Measured memory_bytes: 81360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>

using namespace std;

char rot(char c, size_t n) {
    constexpr size_t w = 'Z' - 'A' + 1;
    return 'A' + (c + n - 'A') % w;
}

int main() {
    size_t n;
    string s;
    cin >> n;
    cin >> s;
    for (auto c : s) {
        cout << rot(c, n);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
int n;
int main(){
	cin>>n;
	cout<<n*800-(n/15)*200<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

long long n,cnt[200005]['z'+5],t=1;

string s;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> s;
    n=s.length();
    for(int i=n-1;i>=0;i--){
        for(int j='a';j<='z';j++){
            cnt[i][j]+=cnt[i+1][j];
        }
        cnt[i][s[i]]++;
    }
    for(int i=0;i<n;i++){
        //cout << cnt[i][s[i]] << '\n';
        t+=(n-i-cnt[i][s[i]]);
    }
    cout << t;
}


Measured memory_bytes: 199060
N,Y=map(int,input().split())
count = 0
for i in range(0,N+1):
  for j in range(0,N-i+1):
    sum=i*10000+j*5000+(N-i-j)*1000
    if sum == Y:
      count +=1
      a=i
      b=j
      c=N-i-j
    else:
      next
if count == 0:
  a=b=c=-1
  print("{} {} {}".format(a,b,c))
else:
  print("{} {} {}".format(a,b,c))

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

#define ll long long
#define mod 1000000007

int main() {
    ll n,W;
    cin>>n>>W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++)cin>>w[i]>>v[i];
    ll dp[n+1][W+1];

    for(ll i=0;i<=n;i++)
    for(ll j=0;j<=W;j++){

        if(i==0 || j==0)dp[i][j]=0;
        else if(w[i-1]<=j)
            dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
        else
            dp[i][j]=dp[i-1][j];
    }

    cout<<dp[n][W];
    return 0 ;
}


Measured memory_bytes: 79104
#include <stdio.h>
int main(void){
    char a;
    
    while(1){
    scanf("%c",&a);
    if(a=='\n') {
        printf("\n");
        break;
    }
    if('A'<=a&&a<='Z') printf("%c",a+32);
    else if('a'<=a&&a<='z') printf("%c",a-32);
    else printf("%c",a);
    }
    
    return 0;
}


Measured memory_bytes: 2104
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	string a,b;
	cin >> a >> b;
	for(int i=0;i<n;i++)
	{
		cout << a[i] << b[i];
	}
}

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

int main () {
    
    int a, b, c;
    cin >> a >> b >> c;
    
    int ans = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3108
n = int(input())
s = input()
ans = 0
for i in range(1, n-1):
	s1 = set(list(s[:i]))
	s2 = set(list(s[i:]))
	c = len(list(s1 & s2))
	if c > ans:
		ans = c
print(ans)
	
		

Measured memory_bytes: 3060
s = input()
t = input()

sl = len(s)
tl = len(t)
cnt = 0
ans = []
while(cnt + tl <= sl):
  tmp = 0
  for i in range(tl):
    if((s[cnt+i] == t[i]) or s[cnt+i] == '?'):
      tmp += 1
  if(tmp == tl):
    
    ans = list(s)
    ans[cnt:cnt+tl] = t
    
  cnt+=1
if(len(ans) == 0):
  print("UNRESTORABLE")
  exit()
  
for i in range(sl):
  if(ans[i] == '?'):
    ans[i] = 'a'
print("".join(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(m),b(m);
  for(Int i=0;i<m;i++) cin>>a[i]>>b[i];
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<m;i++){
    a[i]--;b[i]--;
    v.emplace_back(a[i],b[i]);
  }
  sort(v.begin(),v.end());
  Int ans=0,nxt=n+1;
  for(Int i=0;i<m;i++){
    Int a,b;
    tie(a,b)=v[i];
    if(nxt<=a){
      ans++;
      nxt=n+1;
    }
    chmin(nxt,b);
  }
  if(nxt!=n+1) ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3956
k,s = map(int,input().split())
count = 0
for x in range(k+1):
	if s - x > 2*k:
		continue
	else:
		for y in range(k+1):
			if s - x - y > k:
				continue
			elif s - x - y < 0:
				continue
			else:
				count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	// 入力
	ll N;
	cin >> N;

	ll ans = N * (N - 1) / 2;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3

n = int(input())
matrix = []
while n > 0:
    values = [int(x) for x in input().split()]
    matrix.append(values)
    n -= 1

official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]

Min = 0
Max = 9
for b, f, r, v in matrix:
    num = official_house[b - 1][f - 1][r - 1]
    if Min >= num or Max >= num:
        official_house[b - 1][f - 1][r - 1] += v

for i in range(4):
    for j in range(3):
        print('',' '.join(str(x) for x in official_house[i][j]))
    if 3 > i:
        print('#' * 20)

Measured memory_bytes: 7744
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }
//string al="abcdefghijklmnopqrstuvwxyz";
//vector< vector<int> > v (size1, vector<int>(size2) );



int main(){ 
    cin.tie(0);
    ios::sync_with_stdio(false);
    string al="abcdefghijklmnopqrstuvwxyz";
    string A;cin>>A;
    ll N;N=A.size();
    vector< vector<ll> > cnt (26, vector<ll>(N));
    FOR(i,0,26){
        ll c=0;
        FOR(j,0,N){
            if(A[j]==al[i])c++;
            cnt[i][j]=c;
        }
    }
    ll ans=0;
    FOR(i,0,N){
        ans+=N-cnt[(ll)A[i]-97][N-1]+cnt[(ll)A[i]-97][i]-i-1;
        //cout<<ans<<endl;
    }
    ans++;
    cout<<ans<<endl;
    
}
//666 Palindrome

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int T; cin >> T;
	while (T--) {
		int H, W; cin >> H >> W;
		vector<string> s(H);
		for (int i = 0; i < H; i++)
			cin >> s[i];
		set<char> st;
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				if (s[i][j] != '.')
					st.insert(s[i][j]);
		vector<char> v(st.begin(), st.end());
		for (;;) {
			int k, l, r, u, d;
			for (k = 0; k < v.size(); k++) {
				char c = v[k];
				l = W; r = 0; u = H; d = 0;
				for (int i = 0; i < H; i++)
					for (int j = 0; j < W; j++)
						if (s[i][j] == c) {
							l = min(l, j); r = max(r, j + 1);
							u = min(u, i); d = max(d, i + 1);
						}
				if (l == W) continue;
				bool rect = true;
				for (int i = u; i < d; i++)
					for (int j = l; j < r; j++)
						if (s[i][j] != c && s[i][j] != '?')
							rect = false;
				if (rect) break;
			}
			if (k == v.size()) break;
			for (int i = u; i < d; i++)
				for (int j = l; j < r; j++)
					s[i][j] = '?';
		}
		bool safe = true;
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				if (s[i][j] != '.' && s[i][j] != '?')
					safe = false;
		cout << (safe ? "SAFE" : "SUSPICIOUS") << endl;
	}
}

Measured memory_bytes: 1220
n = int(input())
l = len(str(n))
a = [int(i) for i in list(str(n))]
'''
b = sum(a)
c = [9 for _ in range(l)]
c[0] = a[0] - 1
d = sum(c)
print(max(b, d))
'''
#桁dpで解く
dp = [[0 for _ in range(l)] for _ in range(2)] #dp[0: 未満, 1: 未満でない][最大の桁和]
dp[0][0] = a[0] - 1
dp[1][0] = a[0]
for i in range(1, l):
    dp[0][i] = max(dp[0][i-1] + 9, dp[1][i-1] + a[i] - 1)
    dp[1][i] = dp[1][i-1] + a[i]
print(max(dp[0][l-1], dp[1][l-1]))


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstring>
#include<functional>

using namespace std;

#define MOD 1000000007

long long exp(long long base, long long pw)
{
	long long temp;

	if (!base)
	{
		return 0;
	}

	temp = pw;

	vector<long long> bits;

	while (temp)
	{
		bits.push_back(temp % 2);

		temp /= 2;
	}

	long long rvalue = 1;

	temp = base;

	for (int i = 0; i < bits.size(); i++)
	{

		if (bits[i])
		{
			rvalue = rvalue*temp%MOD;
		}

		temp=temp*temp%MOD;
	}

	return rvalue;
}

int main()
{
	//freopen("input.txt", "r", stdin);

	long long val[100001];

	long long n, k;

	scanf("%lld %lld", &k, &n);

	long long sol = 0;

	for (long long i = n; i >= 1; i--)
	{
		val[i] = exp(n / i, k);

		for (long long j = i * 2; j <= n; j += i)
		{
			val[i] = (val[i] + MOD - val[j]) % MOD;
		}

		sol = (sol+(i*val[i] % MOD)) % MOD;
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 4000
s = list(str(input()))

flag = True
for i in range(len(s)):
    if (i+1) % 2 == 0:
        if s[i] in ['L','U','D']:
           pass
        else:
            flag = False
    else:
        if s[i] in ['R','U','D']:
            pass
        else:
            flag = False

if s[0] in ['R','U','D']:
    pass
else:
    flag = False
            
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i) {
	return i/2;
}

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i+1;
}

int main() {
	int H,i,A[MAX+1];
	
	cin>>H;
	for(int i=1;i<=H;i++) cin>>A[i];
	
	for(i=1;i<=H;i++){
		cout<<"node "<<i<<": key = "<<A[i]<<", ";
		if(parent(i)>=1) cout<<"parent key = "<<A[parent(i)]<<", ";
		if(left(i)<=H) cout<<"left key = "<<A[left(i)]<<", ";
		if(right(i)<=H) cout<<"right key = "<<A[right(i)]<<", ";
		cout<<endl;
	} 
	
	return 0;
}

Measured memory_bytes: 3108
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 1000005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		int k;
		scanf("%d",&k);
		ll ret=0,dm=0;
		int d=0,m=0;
		for(int i=0;i<n;i++)
		{
			if(str[i]=='C') ret+=dm;
			else if(str[i]=='D') d++;
			else if(str[i]=='M')
			{
				dm+=d;
				m++;
			}
			if(i>=k-1)
			{
				int p=i-k+1;
				if(str[p]=='D')
				{
					dm-=m;
					d--;
				}
				else if(str[p]=='M') m--;
			}
		}
		printf("%lld\n",ret);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector < vector <int> > vvi;
const int HUGEI = 2147483647;  // (1 << 31) - 1
const ll HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

vector <int> init(int k) {
    vector <int> res;
    for (int i = 1; i <= 2 * k - 1; i++) res.push_back(i);
    return res;
}

void move_x_to_pos(vector <int> &res, int x, int pos1) {
    int len = res.size();
    int i, tmp;
    for (i = 0; i < len; i++) {
        if (res[i] == x) break;
    }
    tmp = res[pos1 - 1];
    res[pos1 - 1] = x;
    res[i] = tmp;
}

int main(void) {
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1) {
        cout << "No" << endl;
        return 0;
    }
    if (n == 2) {
        cout << "Yes" << endl;
        cout << "1" << endl << "2" << endl << "3" << endl;
        return 0;
    }
    vector <int> res = init(2 * n - 1);
    if (x == 2) {
        move_x_to_pos(res, x + 1, n - 1);
        move_x_to_pos(res, x, n);
        move_x_to_pos(res, x - 1, n + 1);
        move_x_to_pos(res, x + 2, n + 2);
    } else {
        move_x_to_pos(res, x - 1, n - 1);
        move_x_to_pos(res, x, n);
        move_x_to_pos(res, x + 1, n + 1);
        move_x_to_pos(res, x - 2, n + 2);
    }
    cout << "Yes" << endl;
    for (int i = 0; i < 2 * n - 1; i++) cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 3184
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"
#include "random"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<string>s(N);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
	int ans = INT_MAX;
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {

			int bag = 0;
			vector<vector<char>>t(N);
			for (int k = 0; k <= i; k++) {
				t[k].resize(M, 'W');
			}
			for (int k = i + 1; k <= j; k++) {
				t[k].resize(M, 'B');
			}
			for (int k = j + 1; k < N; k++) {
				t[k].resize(M, 'R');
			}
			for (int k = 0; k < N; k++) {
				for (int l = 0; l < M; l++) {
					if (s[k][l] != t[k][l]) {
						bag++;
					}
				}
			}
			ans = min(ans, bag);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3224
#!/usr/bin/env python3
K =int(input())
N=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(N[K-1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
 
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     ff 				first
#define 	ss 				second
#define 	pb 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vvll            vector<vll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
vll pwx(10);
void cal(ll x){ pwx[0] = 1; rep(i, 1, 10)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve() {
	string s;
	cin >> s;
	if(s[s.size() - 1] == 's') s += "es";
	else s += 's';
	cout << s << nl;
}

int main(){
    boost;
    // cal(3);

    // // For getting input from input.txt file 
    // freopen("alchemy_input.txt", "r", stdin); 
  
    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout);

    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


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

int main() {
  int N;
  cin>>N;
  vector<int> hight(N);
  for(int i=0;i<N;i++){
    cin>>hight.at(i);
  }
  int most=0,count=0;
  int start=hight.at(0);
  for(int i=1;i<N;i++){
    
    if(start<hight.at(i)){
      start=hight.at(i);
      count=0;
    }
      
    else{
      start=hight.at(i);
      count++;
    }
      
    
    if(count>most){
        most=count;
    }
  }
  cout<<most<<endl;
      
}

Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.TreeSet;

public class Main {
    private static class Point {
        final int h;
        final int w;

        private Point(int inh, int inw) {
            h = inh;
            w = inw;
        }

        public boolean equals(Object obj) {
            if (obj instanceof Point) {
                Point obj2 = (Point) obj;
                return this.h == obj2.h && this.w == obj2.w;
            }
            return false;
        }
    }

    public static void main(String[] args) {
        var sc = new java.util.Scanner(System.in);
        var h = sc.nextInt();
        var w = sc.nextInt();
        var m = sc.nextInt();
        var sumH = new int[h];
        var sumW = new int[w];
        var hw = new TreeSet<Point>((o1, o2) -> {
            if (o1.h != o2.h) {
                return o1.h - o2.h;
            } else {
                return o1.w - o2.w;
            }
        });
        for (int i = 0; i < m; i++) {
            hw.add(new Point((sc.nextInt() - 1), (sc.nextInt() - 1)));
        }
        for (Point e : hw) {
            sumH[e.h]++;
            sumW[e.w]++;
        }
        var mxH = 0;
        var mxW = 0;
        for (Point e : hw) {
            mxH = Math.max(mxH, sumH[e.h]);
            mxW = Math.max(mxW, sumW[e.w]);
        }
        Deque<Integer> mxHind = new ArrayDeque<>();
        Deque<Integer> mxWind = new ArrayDeque<>();
        for (int i = 0; i < h; i++) {
            if (sumH[i] == mxH) {
                mxHind.add(i);
            }
        }
        for (int i = 0; i < w; i++) {
            if (sumW[i] == mxW) {
                mxWind.add(i);
            }
        }

        boolean notDualflg = false;
        for (int i : mxHind) {
            for (int j : mxWind) {
                if (!hw.contains(new Point(i, j))) {
                    notDualflg = true;
                    break;
                }
            }
            if (notDualflg) {
                break;
            }
        }

        System.out.println(mxH + mxW - ((notDualflg) ? 0 : 1));
    }
}


Measured memory_bytes: 88952
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let sb = s.as_bytes();
    let l = s.len();
    let mut ans = 0;
    for i in 0..l {
        let mut cur = 0;
        for j in 0..l - i {
            match sb[i + j] as char {
                'A' | 'T' | 'G' | 'C' => cur += 1,
                _ => break,
            }
        }
        ans = std::cmp::max(ans, cur);
    }
    println!("{}", ans);
}


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

using namespace std;

int N, M, A, B, ans, fac[200009], inv[200009], mod = 1e9 + 7;

int mul (int x, int y) {return 1LL * x * y % mod;}

int pow (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

void Prec (int lim)
{
    fac[0] = inv[0] = 1;
    for (int i=1; i<=lim; i++)
        fac[i] = mul (fac[i - 1], i);
    inv[lim] = pow (fac[lim], mod - 2);
    for (int i=lim - 1; i>=1; i--)
        inv[i] = mul (inv[i + 1], i + 1);
}

int comb (int N, int K)
{
    int ans = mul (fac[N], inv[N - K]);
    ans = mul (ans, inv[K]);
    return ans;
}

int cnt_ways (int dx, int dy)
{
    return comb (dx + dy, dx);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &N, &M, &A, &B), Prec (200000);
for (int j=B + 1; j<=M; j++)
{
    int curr = mul (cnt_ways (N - A - 1, j - 1), cnt_ways (A - 1, M - j));
    ans += curr;
    if (ans >= mod) ans -= mod;
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			if(m==0)break;
			int[] a = new int[m+1];
			int[] b = new int[m+1];
			for(int i=1;i<=m;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
			}
			int[][] p = new int[m+1][1001];
			p[0][0] = 1;
			for(int i=1;i<=m;i++){
				for(int k=0;k<1001;k++){
					for(int s=0;s<=b[i];s++){
						if(k-a[i]*s<0)break;
						p[i][k] += p[i-1][k-s*a[i]];
					}
				}
			}
			int g = sc.nextInt();
			while(g--!=0)System.out.println(p[m][sc.nextInt()]);
		}
	}
}

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

int main() {
	int A, B, x;
	cin >> A >> B;
	if(A >= 13){
		x = B;
	}
	else if(A >=6){
		x = B / 2;
	}
	else{
		x=0;
	}
	cout << x << endl; // prints !!!Hello World!!!
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
S = [input() for i in range(h)]
 
for i in range(h):
    l = ''
    for j in range(w):
        if S[i][j] == '#':
            l += '#'
        else:
            l += str(sum([T[max(0, j-1) : min(w, j+2)].count('#') for T in S[max(0, i-1) : min(h, i+2)]]))
    print(l)

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  deque<int>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i%2==n%2){k.push_back(a[i]);}
    else{k.push_front(a[i]);}
  }
  for(int i=0;i<n;i++){
    cout<<k[i];
    if(i<n-1){cout<<" ";}
  }cout<<endl;

  return 0;
}

Measured memory_bytes: 4840
N = gets.strip.to_i
A = gets.split.map(&:to_i)
puts A.join(' ')
for i in 1..(A.length-1)
  key = A[i]
  j = i - 1
  while j >= 0 and A[j] > key
    A[j+1] = A[j]
    j=j-1
  end
  A[j+1] = key
  puts A.join(' ')
end

Measured memory_bytes: 8868
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CDifferBy1Bit solver = new CDifferBy1Bit();
        solver.solve(1, in, out);
        out.close();
    }

    static class CDifferBy1Bit {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            if (Integer.bitCount(a ^ b) % 2 == 0) {
                out.println("NO");
                return;
            }

            int[] num = new int[1 << n];
            doit(a, b, n - 1, 0, (1 << n) - 1, num, new int[1 << n]);
            out.println("YES");
            for (int i = 0; i < 1 << n; i++) {
                out.print(num[i]);
                out.print(' ');
            }
        }

        private void doit(int a, int b, int bit, int l, int r, int[] num, int[] temp) {
            assert Integer.bitCount(a ^ b) % 2 == 1;
            if (bit == 0) {
                num[l] = a;
                num[r] = b;
                return;
            }
            if ((a & (1 << bit)) != (b & (1 << bit))) {
                doit(a, a ^ 1, bit - 1, l, (l + r) / 2, num, temp);
                doit((a ^ 1) ^ (1 << bit), b, bit - 1, (l + r) / 2 + 1, r, num, temp);
            } else {
                doit(a, b, bit - 1, l, (l + r) / 2, temp, num);
                num[l] = temp[l];
                int pos = (l + r) / 2 + 2;
                for (int i = l + 1; i <= (l + r) / 2; i++) {
                    num[pos++] = temp[i];
                }
                doit(a ^ (1 << bit), temp[l + 1] ^ (1 << bit), bit - 1, l + 1, (l + r) / 2 + 1, num, temp);
            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}



Measured memory_bytes: 35684
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
    int w=0,i;
    char s[1000],b[10];
    scanf("%s",b);
    for(i=0;i<10;i++)b[i]=tolower(b[i]);
    while(1){
        scanf("%s",s);
        if(strcmp(s,"END_OF_TEXT") == 0)break;
        for(i=0;i<1000;i++)s[i]=tolower(s[i]);
        if(strcmp(s,b) == 0)w++;
    }
    printf("%d\n",w);
    return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
using namespace std;
int main(){
   double a;
   cin >> a;
   int aa;
   int &aaa = aa;
   if(a/108*100 == (int)(a/108*100))aaa = (int)(a/108*100);
   else aaa = (int)(a/108*100)+1;
   if((int)(aa*1.08)==a)cout << aa << endl;
   else cout << ":(" << endl;
}

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

#define say(obj) (cout << (obj) << endl)
#define endline (cout << endl)
#define all(container) (container).begin(), (container).end()
#define sortall(container) (sort((container).begin(), (container).end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
T getSum(std::vector<T>& v) {
	T ret = 0;
	for (T& x : v) ret += x;
	return ret;
}

template <typename T>
istream& operator >> (istream & is, vector<T> & vec) {
	for (T& x : vec) is >> x;  return is;
}

template <typename S, typename T>
istream& operator >> (istream & is, pair<S, T> & p) {
	is >> p.first >> p.second; return is;
}

istream& operator >> (istream & is, point & p) {
	is >> p.x >> p.y;          return is;
}

template <typename T>
ostream& operator << (ostream & os, const vector<T> & vec) {
	for (const T& x : vec) os << x << " "; return os;
}

template <typename T>
ostream& operator << (ostream & os, const vector<vector<T>> & mat) {
	for (const vector<T>& m : mat)
		os << m << endl; return os;
}
template <typename S, typename T>
ostream& operator << (ostream & os, const pair<S, T> & p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template <typename T>
ostream& operator << (ostream & os, const set<T> & s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream & os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream & os, const point & p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int A, B;
	cin >> A >> B;

	if (A >= 1 && A <= 9 && B >= 1 && B <= 9)
		say(A * B);
	else
		say(-1);


	return 0;
}


Measured memory_bytes: 256