akhauriyash/Code-Regression huggingface dataset:
x=int(input())
sosu=[False]*(10**5+4)
for i in range(2,10**5+4):
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            break
    else:
        sosu[i]=True
for i in range(x,10**5+4):
    if sosu[i]:
        print(i)
        break

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[2][n];
    for(int i = 0; i < n; i++)
        cin>>a[0][i];
    for(int i = 0; i < n; i++)
        cin>>a[1][i];
    int ans = INT_MIN;
    for(int i = 0; i < n; i++)
    {
        int d = a[0][0];
        for(int j = 1; j <= i; j++)
            d += a[0][j];
        for(int k = i; k < n; k++)
            d += a[1][k];
        ans = max(ans, d);

    }
    cout<<ans<<endl;
}


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

int main() {
  int l;
  cin >> l;
  double length = (double)l / 3;
  double ans = pow(length, 3);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from decimal import Decimal

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(float, input().split())


a, b = input().split()
a = Decimal(a)
b = Decimal(b)

print(int(a * b))


Measured memory_bytes: 10056
from itertools import permutations

def f(n, m, uu, vv):
    a = [[0] *n for _ in range(n)]
    for u, v in zip(uu, vv):
        a[u][v] = 1
        a[v][u] = 1
    res = 0
    for p in permutations(range(n)):
        if p[0] != 0:
            break
        ok = True
        for i in range(n - 1):
            if a[p[i]][p[i+1]] == 0:
                ok = False
                break
        if ok:
            res += 1
    return res

n , m = map(int, input().split())
a = []
b = []
for k in range(m):
    _a, _b = map(int, input().split())
    _a -= 1
    _b -= 1
    a.append(_a)
    b.append(_b)
print(f(n, m, a, b))


Measured memory_bytes: 3064
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

typedef pair<int, int> P;

int N, M;

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

    cin >> N >> M;

    vector<P> p(M);
    REP(i, M) {
        int a, b;
        cin >> a >> b;

        p[i] = {b, a};
    }
    sort(p.begin(), p.end());

    int ans = 0;
    int cur = 0;
    REP(i, M) {
        int a = p[i].second;
        int b = p[i].first;
        if (cur < a) {
            ans++;
            cur = b - 1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<long long> rain(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        rain[i] = a[i - 1] - rain[i - 1];
    }

    for (int i = 0, r = rain[0] + rain[n]; i < n; i++) {
        cout << (i == 0 ? "" : " ") << r;
        r = 2 * (a[i] - r / 2);
    }
    cout << endl;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

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

    ll N, M;
    std::cin >> N >> M;

    ll sum = 0;
    priority_queue<ll> pq;
    REP(i, N) {
        ll a;
        std::cin >> a;
        pq.push(a);
        sum += a;
    }

    while(M != 0) {
        auto top = pq.top();
        pq.pop();
        sum -= top - (top / 2);
        M--;
        pq.push(top / 2);
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 1400
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int d = 1;
    int ans  = 0;
    while(d <= n){
        d *= k;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
require 'set'
h, w = gets.split.map(&:to_i)
ch, cw = gets.split.map(&:to_i)
ch += 1
cw += 1
dh, dw = gets.split.map(&:to_i)
dh += 1
dw += 1
s = Array.new(h+4)
h.times do |i|
  s[i+2] = ('##' + gets.chop + '##').chars
end
s[0] = ['#'] * (w+4)
s[1] = ['#'] * (w+4)
s[h+2] = ['#'] * (w+4)
s[h+3] = ['#'] * (w+4)

q = [[ch, cw]]
seek = [[ch, cw]]
current_cost = 0
checked = Array.new(h+4) { Array.new(w+4) }
checked[ch][cw] = true
loop do
  # 同コスト内のノード幅優先探索
  break if q.empty?
  until q.empty?
    nh, nw = q.shift

    if [nh, nw] == [dh, dw]
      puts current_cost
      exit 0
    end

    if s[nh-1][nw] == '.' && !checked[nh-1][nw]
      seek.push [nh-1, nw]
      checked[nh-1][nw] = true
      q.push [nh-1, nw]
    end
    if s[nh+1][nw] == '.' && !checked[nh+1][nw]
      seek.push [nh+1, nw]
      checked[nh+1][nw] = true
      q.push [nh+1, nw]
    end
    if s[nh][nw-1] == '.' && !checked[nh][nw-1]
      seek.push [nh, nw-1]
      checked[nh][nw-1] = true
      q.push [nh, nw-1]
    end
    if s[nh][nw+1] == '.' && !checked[nh][nw+1]
      seek.push [nh, nw+1]
      checked[nh][nw+1] = true
      q.push [nh, nw+1]
    end
  end
  tmp_seek = []

  # 次のコストのノードの発見とキューイング
  seek.each do |eh, ew|
    (eh-2..eh+2).each do |th|
      (ew-2..ew+2).each do |tw|
        next if s[th][tw] != '.' || checked[th][tw]

        if [th, tw] == [dh, dw]
          puts current_cost + 1
          exit 0
        end

        tmp_seek.push [th, tw]
        checked[th][tw] = true
        q.push [th, tw]
      end
    end
  end
  seek = tmp_seek
  current_cost += 1
end
puts -1


Measured memory_bytes: 97928
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int str_asc_cmp(const void* a,const void* b){
    char *x=(char*)a,*y=(char*)b;
    return strcmp(x,y);
}
int main(){
    int n,l;scanf("%d %d",&n,&l);
    char s[200][200];
    for(int i=0;i<n;i++)scanf("%s",s[i]);

    qsort(s,n,sizeof(s[0]),str_asc_cmp);
    
    for(int i=0;i<n;i++)printf("%s",s[i]);
    printf("\n");
}

Measured memory_bytes: 252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(auto &x:v)
		cin>>x;
	const int M=1000000007;
	ll res=0;
	int o=0;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j){
			if(v[i]>v[j])
				++o;
			if(i<j && v[i]>v[j])
				++res;
		}
	res=res*k%M;
	res=(res+(ll)k*(k-1)/2%M*o)%M;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if a==b:
    print("YES")
else:
    if w>=v:
        print("NO")
    else:
        if  abs(a-b)/(v-w)<=t:
            print("YES")
        else:
            print("NO")

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

int main(){
  int m, n, nn;
  while(std::cin >> m >> n >> nn, m){
    vector<int> p(m);
    for (int i = 0; i < m; i++) {
      std::cin >> p[i];
    }
    sort(p.begin(), p.end());
    int maxi = 0, ans = 1e9;
    for (int i = n; i <= nn; i++) {
      if(maxi <= p[m - i] - p[m - i - 1]){
        ans = i;
        maxi = p[m - i] - p[m - i - 1];
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	vector<vector<int>> H(5,vector<int>(4)),V(4,vector<int>(5));
	REP(i,9){
		string S=in<string>();
		if(!(i%2)){
			REP(j,4) H[i/2][j] = S[j]-'0';
		}
		else{
			REP(j,5) V[i/2][j] = S[j]-'0';
		}
	}
	
	enum{R=0,D,L,U};
	int X=0,Y=0,dir=R;
	auto check = [&](){return (!X && !Y);};
	string S;
	while(true){
		if(dir==R){
			if(Y>0 && V[Y-1][X]){
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else if(X<4 && H[Y][X]){
				X++;
				S.push_back('R');
			}
			else if(Y<4 && V[Y][X]){
				dir = D;
				Y++;
				S.push_back('D');
			}
			else{
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
		}
		else if(dir==D){
			if(X<4 && H[Y][X]){
				dir = R;
				X++;
				S.push_back('R');
			}
			else if(Y<4 && V[Y][X]){
				Y++;
				S.push_back('D');
			}
			else if(X>0 && H[Y][X-1]){
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else{
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
		}
		else if(dir==L){
			if(Y<4 && V[Y][X]){
				dir = D;
				Y++;
				S.push_back('D');
			}
			else if(X>0 && H[Y][X-1]){
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else if(Y>0 && V[Y-1][X]){
				dir = U;
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else{
				dir = R;
				X++;
				S.push_back('R');
			}
		}
		else{
			if(X>0 && H[Y][X-1]){
				dir = L;
				X--;
				S.push_back('L');
				if(check()) break;
			}
			else if(Y>0 && V[Y-1][X]){
				Y--;
				S.push_back('U');
				if(check()) break;
			}
			else if(X<4 && H[Y][X]){
				dir = R;
				X++;
				S.push_back('R');
			}
			else{
				dir = D;
				Y++;
				S.push_back('D');
			}
		}
	}
	
	out(S);
	return 0;
}


Measured memory_bytes: 3000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0053
{
	class Program
	{
		static void Main(string[] args)
		{
			var	prime	= new long[ 10000 ];
			int	cnt		= 0;
			for( long i = 2; ; i++ ) {
				if( is_prime( i ) ) {
					prime[ cnt ]	= i;
					cnt++;
					if( cnt >= 10000 ) {
						break;
					}
				}
			}
		
			while( true ) {
				var	n	= int.Parse( Console.ReadLine() );
				if( n == 0 ) {
					break;
				}
				long	sum	= 0; 
				for( int i = 0; i < n; i++ ) {
					sum	+= prime[ i ];
				}
				Console.WriteLine( sum );
			}
		
		
		}

        // 素数判定
		static bool is_prime( long n )
		{
			if( n <= 1 ) {
				return( false );
			} else if( n <= 3 ) {
				return( true );
			} else if( (n % 2) == 0 ) {
				return( false );
			} else {
				for( int i = 3; i <= (int)Math.Sqrt( n ); i += 2 ) {
					if( (n % i) == 0 ) {
						return( false );
					}
				}
			}
			return( true );
		} 
	}
}

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

using namespace std;

long gcd(long a,long b) {
  
  while (a%b) {
    long r=a%b;
    a = b;
    b = r;
  }
  return b;
}


int main(){
 long n,m; 
  cin >> n >> m;
  
  vector<long> x(n);
  for(int i=0;i<n;i++){
  cin >> x[i];
  }
  
  long res=abs(x[0]-m);
  
 for(int i=1;i<n;i++){
  res=gcd(abs(x[i]-m),res);
  }
   
  
  cout << res << endl;
   
}


Measured memory_bytes: 1024
using System;

namespace abc164B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int D = int.Parse(str[3]);
            int E = A / D;
            int F = C / B;
            if (A % D != 0)
                E += 1;
            if (C % B != 0)
                F += 1;
            if (E < F)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 27300
N, M = map(int, input().split())
l = [ [ list(map(int, input().split())), i ] for i in range(M) ]
l.sort(key=lambda x: (x[0][0],x[0][1]))

idx = 1
idx_p = l[0][0]
ans = []
for x in l:
    if x[0][0] == idx_p:
        idx += 1
    else:
        idx = 1
        idx_p = x[0][0]
    ans.append([ x[1], '%06d%06d' % (idx_p, idx)])

ans.sort(key=lambda x: x[0])
for i in ans:
    print(i[1])

Measured memory_bytes: 54368
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ma[400008],fa[400008];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",ma+i);
    int len=1,mi=ma[0];
    for(int i=1;i<n;i++){
        if(mi>ma[i])
            mi=ma[i],len++;
    }
    printf("%d\n",len);
}


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

int main() {
  int mn = 200;
  int sum = 0;
  for(int i = 0; i < 5; ++i){
    int k;
    cin >> k;
    sum += ((k + 9) / 10) * 10;
    if(k % 10 == 0) mn = min(mn, 10);
    else mn = min(mn, k % 10);
  }
  
  cout << sum + mn - 10<< endl;
}

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

const int INF = 1001001001;

vector< vector<int> > to(2505);
vector< vector<int> > ot(2505);
vector<bool> toOK(2505,false);
vector<bool> otOK(2505,false);
vector<bool> ok(2505,false);

void bfs( int v ) {
  if (toOK[v]) return;
  toOK[v] = true;
  for( auto a: to[v] ) {
    bfs( a );
  }
}
void bfs2( int v ) {
  if (otOK[v]) return;
  otOK[v] = true;
  for( auto a: ot[v] ) {
    bfs2( a );
  }
}

int main() {
  int N,M,P;
  cin >> N >> M >> P;
  vector< tuple<int,int,int> > G;

  for( int i=0; i<M; ++i) {
    int a,b,c;
    cin >> a >> b >> c;
    --a; --b;
    c -= P;
    c = -c;
    G.emplace_back(a,b,c);
    to[a].push_back(b);
    ot[b].push_back(a);
  }
  bfs(0);
  bfs2(N-1);

  for (int i=0;i<N;++i) {
    if ( toOK[i] && otOK[i] ) {
      ok[i] = true;
//      cout << i << " : OK" << endl;
    }
  }

  vector<int> dist(N,INF);
  dist[0] = 0;
  
  bool upd = true;
  int step = 0;

  while (upd ) {
    upd = false;
    for (int i=0;i<M;++i) {
      int a,b,c;
      tie(a,b,c) = G[i];
      if ( !ok[a] ) continue;
      if ( !ok[b] ) continue;
      if ( dist[b] > dist[a] + c ) {
        dist[b] = dist[a] + c ;
        upd = true;
//        cout << step << " | " << a << " -> " << b << " : " << -dist[b] << endl;
      }
    }
    step++;
    if ( step > N ) {
      cout << "-1" << endl;
      return 0;
    }
//    cout << step << " | N: " << -dist[N-1] << endl;
  }
  
  
  cout << max(-dist[N-1],0) << endl;

}


Measured memory_bytes: 640
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int v=s.nextInt();
		BitSet m=new BitSet();
		m.set(v);
		for(int i=2;true;++i) {
			v=v%2==0?v/2:3*v+1;
			if(m.get(v)) {
				System.out.println(i);
				return;
			}
			m.set(v);
		}
	}
}

Measured memory_bytes: 23124
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Search(A []int, x int) int {
  N := len(A)
  if x < A[0] { return 0 }
  if A[N - 1] <= x { return N }
  lex, gtx := 0, N - 1
  for 1 < gtx - lex {
    med := (gtx + lex) / 2
    if x < A[med] {
      gtx = med
    } else {
      lex = med
    }
  }
  return lex + 1
}

func Count(A []int, x int) int {
  N := len(A)
  cnt := 0
  for i, a := range A {
    if a == 0 {
      if 0 <= x { cnt += N - i - 1 }
    } else if 0 < a {
      k := x / a
      if x < 0 && x % a != 0 { k-- }
      cnt += MaxInt(Search(A, k) - i - 1, 0)
    } else {
      k := x / a
      if 0 < x || x % a == 0 { k-- }
      cnt += MaxInt(N - MaxInt(Search(A, k), i + 1), 0)
    }
  }
  return cnt
}

func Solve() {
  var N, K int
  NextInt(&N, &K)
  var A []int
  NextIntVec(&A)
  sort.Ints(A)
  M := MaxInt(A[0] * A[0], A[N - 1] * A[N - 1])
  m := MinInt(A[0] * A[0], A[0] * A[N - 1], A[N - 1] * A[N - 1]) - 1
  for 1 < M - m {
    med := (M + m) / 2
    if Count(A, med) < K {
      m = med
    } else {
      M = med
    }
  }
  Write(M)
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	double ans = 0.0;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		ans += (1.0 / A);
	}

	ans = 1.0 / ans;

	cout << fixed << setprecision(14) << ans << endl;
	return 0;
}



Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef pair<int, int> pii;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int N, M;
		cin >> N >> M;
		if(N == 0 && M == 0){ break; }
		map< int, vector<int> > logdata;
		map< pii, int> login_time;
		int r, q;
		cin >> r;
		while(r--){
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if(logdata.find(m) == logdata.end()){
				logdata.insert(make_pair(m, vector<int>(1000)));
			}
			vector<int> &entry = logdata[m];
			if(s == 0){
				for(int i = t - 540; i < entry.size(); ++i){ --entry[i]; }
			}else{
				for(int i = t - 540; i < entry.size(); ++i){ ++entry[i]; }
			}
		}
		cin >> q;
		while(q--){
			int ts, te, m, answer = 0;
			cin >> ts >> te >> m;
			if(logdata.find(m) == logdata.end()){
				cout << 0 << endl;
			}else{
				vector<int> &entry = logdata[m];
				for(int i = ts - 540; i < te - 540; ++i){
					answer += (entry[i] ? 1 : 0);
				}
				cout << answer << endl;
			}
		}
	}
	return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int x;
    cin >> x;
    Int res = (x / 500) * 1000;
    x %= 500;
    dump(res + x / 5 * 5);
    return 0;
}

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

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

using namespace std;

typedef array<int, 2> timecard;

int analyze(int ts, int te, vector<timecard> &history) {
  int sum = 0;

  for (auto x : history) {
    if (ts < x[0]) {
      if (te <= x[0]) {
        break;
      } else {
        ts = x[0];
      }
    }
    // x[0] <= ts
    if (x[1] <= ts) {
      continue;
    }

    // x[0] <= ts < x[1], x[0] < te
    if (te <= x[1]) {
      sum += te - ts;
      break;
    } else {
      sum += x[1] - ts;
    }
  }

  return sum;
}

int main() {
  constexpr int LOGIN = 1;
  constexpr int LOGOUT = 0;
  int N, M, r, q, t, n, m, s, ts, te;

  while (cin >> N >> M && N != 0) {
    vector<vector<timecard>> user_histories(M + 1);
    vector<vector<int>> buffer(M + 1);
    cin >> r;
    rep(_, r) {
      cin >> t >> n >> m >> s;
      if (s == LOGIN) {
        buffer[m].push_back(t);
      } else {
        auto _ts = buffer[m].back();
        buffer[m].pop_back();
        if (buffer[m].size() == 0) {
          user_histories[m].push_back(timecard{_ts, t});
        }
      }
    }

    cin >> q;
    rep(_, q) {
      cin >> ts >> te >> m;
      cout << analyze(ts, te, user_histories[m]) << endl;
    }
  }
}


Measured memory_bytes: 3396
using System.Collections.Generic;
using System.Linq;
using System;

public class Cake
{
    public int w { get; set; }
    public int d { get; set; }
    public int s { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var cakes = new List<Cake>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            var d = int.Parse(line[2]);
            if (n == 0 && w == 0 && d == 0) break;
            cakes.Add(new Cake { w = w, d = d, s = w * d });
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var p = int.Parse(line2[0]);
                var s = int.Parse(line2[1]);
                cutCake(cakes, p, s);
            }
            var retlist = cakes.OrderBy(x => x.s).ToArray();
            for (int j = 0; j < retlist.Length; j++)
                if (j == retlist.Length - 1) Console.WriteLine(retlist[j].s);
                else Console.Write("{0} ", retlist[j].s);
        }
    }
    public static void cutCake(List<Cake> c, int p, int s)
    {
        var nw = c[p - 1].w;
        var nd = c[p - 1].d;
        while (true)
        {
            if (s < nw)
            {
                c.RemoveAt(p - 1);
                if (s < nw - s)
                {
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                }
                else
                {
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                }
                return;
            }
            else if (s - nw < nd)
            {
                c.RemoveAt(p - 1);
                if (s - nw < nd - s + nw)
                {
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                }
                else
                {
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                }
                return;
            }
            else s -= (nd + nw);
        }
    }
}

Measured memory_bytes: 10220
use std::io;


fn get_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    line
}

fn main() {
    let line = get_line();
    let v:Vec<_> = line.trim().split(' ').collect();
    let a:i32 = v[0].parse().unwrap();
    let b:i32 = v[1].parse().unwrap();
    println!("{} {}", a * b, a * 2 + b * 2);
}



Measured memory_bytes: 5036
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;

  while(cin >> n,n){
    vector<P> v;
    int OutW = 0,w,f,e;
    for(int i = 0 ; i < n ; i++){
      cin >> w >> f >> e;
      v.push_back(P(f,w));
      v.push_back(P(e,-w));
    }
    sort(v.begin(),v.end());
    int flg = 0;
    for(int i = 0 ; i < v.size() ; i++){
      OutW += v[i].second;
      if(OutW > 150) flg = 1; 
    }
    if(flg) cout << "NG" << endl;
    else cout << "OK" << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

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

	int ans = 0;
	for (int A = 1; A <= N; ++A) {
		for (int B = 1; A * B <= N; ++B) {
			int C = N - A * B;
			if (C > 0) {
				++ans;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3616
n = gets.to_i
array = gets.split.map(&:to_i)

check = true

array.each_index {|i|
  if array[i] > i+1
    check = false
  end
}

if check == false
  puts -1
  exit
end

ans = []
while array.size != 0
  array.each_with_index.reverse_each do |num, i|
    # puts "#{num} // #{i}"
    if num == i+1
      ans.push(num)
      array.delete_at(i)
      break
    end
  end
end

puts ans.reverse


Measured memory_bytes: 1788
from sys import exit
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
a = [int(input()) for _ in range(5)]
k = int(input())
for e0 in a:
    for e1 in a:
        if abs(e0 - e1) > k:
            print(":(")
            exit()
print("Yay!")
# S = str(input())
# L = len(S)
# T = str(input())
# exit()


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    
    int h[N];
    for (int i = 0; i < N; i++)
        cin >> h[i];

    bool array[N];
    for (int i = 0; i < N; i++)
        array[i] = true;
    for (int i = 1; i <= M; i++)
    {
        int ai, bi;
        cin >> ai >> bi;
        
        if (h[ai - 1] > h[bi - 1])
            array[bi - 1] = false;
        else if (h[ai - 1] < h[bi - 1])
            array[ai - 1] = false;
        else {
            array[ai - 1] = false;
            array[bi - 1] = false;
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (array[i] == true)
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <string.h>
typedef long long LL;
using namespace std;

int main()
{
	int n,t,sum4,sum2;
	while(cin>>n)
	{
		t=n;
		sum4=0;
		sum2=0;
		while(t--)
		{
			LL x;
			cin>>x;
			if(x%4==0)
			sum4++;
			else if(x%2==0)
			sum2++;
		}
		if(sum2>1)
		{
			if(sum4>=(n-sum2+1)/2)
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}
		else
		{
			if(sum4>=n/2)
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace fightx
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] NK = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            int[] PN = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            Array.Sort(PN);
            int ans = 0;
            for (int a = 0; a < NK[1]; a++)
                ans += PN[a];
            Console.WriteLine(ans);





        }
    }
}


Measured memory_bytes: 19716
s = str(input())
n = len(s)
lists = []
tmp = []
Sum = 0
s_lists = []
for i in range(2 ** (n-1)):
    lists = []
    tmp = []
    cnt = 0
    s_lists = []
    int_list = []
    for k in range(n):
        s_lists.append(s[k])
    for j in range(n-1):
        if ((i >> j) & 1):
            lists.append(1)
        else:
            lists.append(0)
    for m in range(len(lists)):
        if lists[m] == 1:
            s_lists.insert(m + cnt + 1, "+")
            cnt += 1
    ss = "".join(s_lists)
    ss_list = ss.split("+")
    for h in ss_list:
        tmp = int(h)
        int_list.append(tmp)
    Sum += sum(int_list)
print(Sum)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            sum += a - 1;
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 26072
N, M = map(int, input().split())
pair = [[0, 0]]*N
cost = 0
num = 0
for i in range(N):
    a, b = map(int, input().split())
    pair[i] = [a, b]

pair.sort(key=lambda x:x[0])
#print(pair)
for i in range(N):
    cost += pair[i][0] * pair[i][1]
    num += pair[i][1]
    if num >= M:
        cost -= pair[i][0] * (num - M)
        break

print(cost)


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

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  for(auto& i : h) cin >> i;
  int ans = 1;
  for(int i = 1; i < n; ++i)
  {
    int res = 0;
    for(int k = 0; k < i; ++k)
    {
      if(h[i] < h[k])
      {
        res = -1;
        break;
      }
    }
    if(res != -1) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (n, m) = (nm[0], nm[1]);
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var d = Math.Max(-1, n - seqA.Sum());
        
        Console.WriteLine(d);
    }
}


Measured memory_bytes: 29268
'use strict'

const main = (input) => {
    input = input.split(' ').map(v => parseInt(v))
    const X = input[0]
    const Y = input[1]
    const Z = input[2]
    const n = Y + Z
    const w = X - Z
    console.log(Math.floor(w / n))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
using namespace std;
long long const mod = 1e9+7;
int const m = 16;
vector< vector<long long> > dp;
int n, x[3];
bool g(int b, int c){
    int res = c;
    int cnt = 1;
    int stt = 2;
    if(res > x[stt])return true;
    if(res == x[stt]){
        res = 0;
        if(stt-- == 0)return false;
    }
    for(int i=0;i<m;i++){
        if(((b>>i)&1)==1){
            res += cnt;
            if(res > x[stt])return true;
            if(res == x[stt]){
                res = 0;
                if(stt-- == 0)return false;
            }
            cnt = 1;
        }else{
            cnt++;
        }
    }
    return true;
}
long long f(int a, int b){
    if(a == n)return 1;
    if(dp[a][b] != -1)return dp[a][b];
    long long res = 0;
    for(int i = 1; i <= 10; i++){
        if(g(b, i)){
            res += f(a+1, (b<<i)%(1<<m) + (1<<(i-1)));
        }
    }
    return dp[a][b] = res%mod;
}
int main(void){
    long long al = 1;
    cin >> n >> x[0] >> x[1] >> x[2];
    dp.assign(n, vector<long long>());
    for(int i=0;i<n;i++){
        dp[i].assign((1<<m), -1);
        al *= 10;
        al %= mod;
    }

    cout << (al - f(0, 0) + mod) % mod << endl;
}


Measured memory_bytes: 20864
#include <iostream>
#include <set>

using namespace std;
typedef long long ll;

int main() {
    set<int> se;
    for (int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        se.insert(x);
    }

    cout << (se.size() == 2 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int l=0,i,j;
  double m[100],temp,max,min;
  while(scanf("%lf",&m[l])!=EOF){
    l++;
  }

//ツバツブツδ仰ソツーツト
for(i=l-1;i>0;i--){
  for(j=0;j<i;j++){
    if(m[j]<m[j+1]){
      temp=m[j];
      m[j]=m[j+1];
      m[j+1]=temp;
    }
  }
 }
 max=m[0];

//ツバツブツδ仰ソツーツト
for(i=l-1;i>0;i--){
  for(j=0;j<i;j++){
    if(m[j]>m[j+1]){
      temp=m[j];
      m[j]=m[j+1];
      m[j+1]=temp;
    }
  }
 }
 min=m[0];
 printf("%.1f\n",max-min);
 return 0;
}

Measured memory_bytes: 0
class Card:
    def __init__(self, mark, numebr):
        super().__init__()
        self.mark = mark
        self.number = number

    def __lt__(self, other):
        return int(self.number) < int(other.number)


def partition(A, p, r):
    x = A[r].number
    i = p-1
    for j in range(p, r):
        if int(A[j].number) <= int(x):
            i = i + 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    return i + 1


def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)


if __name__ == "__main__":
    n = int(input())
    Cards = []
    Cards2 = []
    for _ in range(n):
        mark, number = input().split()
        Cards.append(Card(mark, int(number)))
        Cards2.append(Card(mark, int(number)))

    quickSort(Cards, 0, n-1)
    Cards2 = sorted(Cards2)

    stable = True
    for i in range(n):
        if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):
            stable = False

    if stable:
        print('Stable')
    else:
        print('Not stable')

    for card in Cards:
        print('{} {}'.format(card.mark, card.number))



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

const int INF = 1000000000;
int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < 5; i++)cout << s[i];
    cout << " ";
    for(int i = 6; i < 13; i++)cout << s[i];
    cout << " ";
    for(int i = 14; i < 19; i++)cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int a,b,c;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==5&&c==7)puts("YES");
    else if(a==5&&b==7&&c==5)puts("YES");
    else if(a==7&&b==5&&c==5)puts("YES");
    else puts("NO");
}

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

int main()
{

    int n, l;
    cin >> n >> l;

    vector< string >vec;
    string s;

    for(int i = 0; i < n; i++){
        cin >> s;
        vec.push_back(s);
    }
    sort(vec.begin(), vec.end());

    for(int i = 0; i < n; i++){
        cout << vec[i];
    }

    return 0;
}


Measured memory_bytes: 3640
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

char s[200001];
char t[200001];
int main(void){
	int n=nextstr(s);
	nextstr(t);
	int ans=0;
	for(int i=0; i<n; i++){
		ans+=(s[i]!=t[i]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1996
#include <cstdio>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=505;
int H,W,h,w,i,j,bsc;
int main()
{
//	freopen("matrix.in","r",stdin);
//	freopen("matrix.out","w",stdout);
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if (H%h==0 && W%w==0) printf("No\n");
	else {
		bsc=2000;
		printf("Yes\n");
		rep(i,1,H)
		{
			rep(j,1,W)
				if (i%h==0 && j%w==0) printf("%d ",-bsc*(h*w-1)-1);
				else printf("%d ",bsc);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,m,r;
     cin>>n>>m>>r;
     int cnt=0;
     for(int i=n;i<=m;i++)
     {
         if(i%r==0)
            cnt++;
     }
     cout<<cnt<<endl;

}


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

int abs(int n){
  if(n<0) return -n;
  else return n;
}
int main(){
  int ans=999;
  string S;
  cin >> S;
  for(int i=0;i<S.size()-2;i++){
    int a,b,c,d;
    b = S.at(i)-48;
    c = S.at(i+1)-48;
    d = S.at(i+2)-48;
    a=b*100+c*10+d;
    ans = min(abs(753-a),ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
  a,b = map(int,input().split())
  S.append([a,b])
ans = "Yes"
S.sort(key=lambda x:x[1])
a = 0
for i in range(N):
  a += S[i][0]
  if a>S[i][1]:
    ans = "No"
    break
print(ans)

Measured memory_bytes: 38052
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: i32 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av: Vec<i32> = vec![s];
    loop {
        let n = av[av.len() - 1];
        let a = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
        av.push(a);
        if av.iter().filter(|i| **i == a).count() >= 2 {
            break;
        }
    }
    println!("{}", av.len());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x=1,m=0;
  cin >> n ;
  vector<long int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  m=p[0];
  for (int i = 1; i < n; i++) {
    if(p[i] < m){
      m=p[i];
      x++;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <typeinfo>
#include <type_traits>

using namespace std;

template <typename T>	constexpr T	rep_start(const T &end)			{ return 0; }
template <typename T>	constexpr T	rep_start(const T &start, const T &end)	{ return start; }
template <typename T>	constexpr T	rep_end(const T &end)				{ return end; }
template <typename T>	constexpr T	rep_end(const T &start, const T &end)		{ return end; }

#define rep(index, ...) for (auto index = rep_start(__VA_ARGS__); index < rep_end(__VA_ARGS__); ++index)
#define irep(index, ...) for (auto index = rep_end(__VA_ARGS__) - 1; index >= rep_start(__VA_ARGS__); --index)

using llong = long long;
using ullong = unsigned long long;

int main ()
{
	unordered_map<int, bool> visited;

	int s;
	cin >> s;
	int a = s;
	int i = 1;
	while (!visited[a])
	{
		visited[a] = true;
		a = (a % 2 == 0) ? (a / 2) : (3 * a + 1);
		++i;
	}

	cout << i << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  bool ok = true;
  if(s[0] != '1' || s[n - 1] != '0') ok = false;
  rep(i, n / 2) if(s[i] != s[n - 2 - i]) ok = false;
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }
  rep2(i, n / 2 + 1, n) s[i] = '0';
  reverse(all(s));
  vector<vl> g(n);
  ll u = 0, v = 0;
  rep2(i, 1, n) {
    v++;
    g[u].push_back(v);
    if(s[i] == '1') u = v;
  }
  set<P> st;
  rep(i, n) for(auto v : g[i])
      st.insert({min(i + 1, v + 1), max(i + 1, v + 1)});
  for(auto p : st) cout << p.first << ' ' << p.second << '\n';
  return 0;
}

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

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

template <int MD>
struct ModInt {
    typedef ModInt M;
    int v;
    ModInt(int _v = 0) : v(_v) {}

    M& operator += (const M &r) {
        if ((v += r.v - MD) < 0) v += MD;
        return *this;
    }
    M& operator -= (const M &r) {
        if ((v -= r.v) < 0) v += MD;
        return *this;
    }
    M& operator *= (const M &r) {
        v = ll(v) * r.v % MD;
        return *this;
    }

    M operator + (const M &r) const { return M(*this) += r; }
    M operator - (const M &r) const { return M(*this) -= r; }
    M operator * (const M &r) const { return M(*this) *= r; }

    M pow(int n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;

const int MN = 234567;
int h, w, n;
Mint fac[MN], ifac[MN], dp[MN];
P p[MN];

void first() {
    fac[0] = 1;
    for (int i = 1; i < MN; i++) {
        fac[i] = fac[i - 1] * Mint(i);
    }
    ifac[MN - 1] = fac[MN - 1].inv();
    for (int i = MN - 2; i >= 0; i--) {
        ifac[i] = ifac[i + 1] * Mint(i + 1);
    }
}

Mint binom(int n, int r) {
    return fac[n] * ifac[r] * ifac[n - r];
}

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

    first();
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    p[n++] = make_pair(h, w);
    sort(p, p + n);

    for (int i = 0; i < n; i++) {
        int x = p[i].first;
        int y = p[i].second;
        dp[i] += binom(x + y - 2, x - 1);
        for (int j = i + 1; j < n; j++) {
            int x2 = p[j].first;
            int y2 = p[j].second;
            if (x <= x2 && y <= y2) {
                dp[j] -= dp[i] * binom(x2 + y2 - x - y, x2 - x);
            }
        }
    }
    cout << dp[n - 1].v << endl;
    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>

using namespace std;

typedef pair<int, int> P;

int N, K;

int main() {
	cin >> N >> K;
	
	cout << N - K + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    string s,t;
    int ans=0;
    cin>>s>>t;
    REP(i,s.length()) if(s[i]-t[i]!=0) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3924
N,X = `dd`.split.map(&:to_i)
$ss = [1]
N.times{ $ss << $ss[-1]*2+3 }
$ps = [1]
N.times{ $ps << $ps[-1]*2+1 }

def dig(n,x)
  ans = case
  when n == 0; 1
  when x == 1; 0
  when x <= 1+$ss[n-1]; dig(n-1,x-1)
  when x == 1+$ss[n-1]+1; $ps[n-1]+1
  when x < $ss[n]; $ps[n-1]+1+dig(n-1,x-1-$ss[n-1]-1)
  when x == $ss[n]; $ps[n]
  end
  #p [n,x,$ss[n],$ps[n],ans]
  ans
end

p dig(N,X)

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

//vector <long long> v;

//stack <long long> s[1000000], wym;

//queue <long long> s;

long long int  x[1000000], y, z;
char s1[1000000], s2[1000000];

int main()
{
    long long int a, b, c, d, k, l, i, j, q, t, p, n, m=131072, w, r;

    t=1;
    //scanf("%lld", &t);
    for(q=0; q<t; q++)
    {
        scanf("%lld", &n);

        w=1000;
        a=0;
        b=1000;

        for(i=0; i<n; i++)
        {
            scanf("%lld", &x[i]);
        }
        for(i=0; i<n; i++)
        {
            a+=b/x[i];
            b-=b/x[i]*x[i];
            if(x[i]>x[i+1])
            {
                b+=a*x[i];
                a=0;
            }
            w=max(w, b);
        }
        printf("%lld\n", w);
    }
    return(0);
}


Measured memory_bytes: 3824
def resolve():
	n, q = map(int, input().split())
	s = input()
	seq = [0]*(n+1)
	for i in range(1, n):
		seq[i+1] = seq[i] + s[i-1:i+1].count('AC')
	for _ in range(q):
		l, r = map(int, input().split())
		print(seq[r] - seq[l])
resolve()

Measured memory_bytes: 51968
from itertools import product


def dfs(num_s, n, ansl):
    num = int(num_s)
    if num > n:
        return

    if '7' in num_s and '5' in num_s and '3' in num_s:
        ansl.append(int(num_s))
    dfs(num_s+'7', n, ansl)
    dfs(num_s+'5', n, ansl)
    dfs(num_s+'3', n, ansl)



def main():
    n = int(input())
    ansl = []
    dfs('7',n,ansl)
    dfs('5',n,ansl)
    dfs('3',n,ansl)

    print(len(ansl))


if __name__ == "__main__":
    main()

Measured memory_bytes: 9984
lengthOfStrings = gets.to_i - 1
firstStrings  = gets.to_s
secondStrings = gets.to_s
thirdStrings  = gets.to_s

timesOfExchange = 0

for index in 0..lengthOfStrings do
    letterOfEachStrings = []
    letterOfEachStrings << firstStrings[index]
    letterOfEachStrings << secondStrings[index]
    letterOfEachStrings << thirdStrings[index]


    letterOfEachStrings =  letterOfEachStrings.uniq

    if letterOfEachStrings.size == 3 then
        timesOfExchange = timesOfExchange + 2
    elsif letterOfEachStrings.size == 2 then
        timesOfExchange = timesOfExchange + 1
    elsif letterOfEachStrings.size == 1 then
        timesOfExchange = timesOfExchange
    end
end

puts timesOfExchange

Measured memory_bytes: 1788