akhauriyash/Code-Regression huggingface dataset:
import itertools

lst = list(map(int, input().split()))
k = int(input())

ans = 'No'
for tup in itertools.combinations_with_replacement([0, 1, 2], k):
    temp = lst[:]
    for i in tup:
        temp[i] *= 2
    if temp[0] < temp[1] and temp[1] < temp[2]:
        ans = 'Yes'
print(ans)

Measured memory_bytes: 62012
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    String reverseS = new StringBuilder(s).reverse().toString();
    int total = 0;
    int x = 1;
    int modCount[] = new int[2019];
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
      modCount[total]++;
      int a = Integer.parseInt(reverseS.substring(i, i + 1));
      total += a * x;
      total %= 2019;
      ans += modCount[total];
      x *= 10;
      x %= 2019;
    }
    pw.println(ans);
  }
}


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

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int top_diam = 100000001;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] < top_diam)
        {
            top_diam = a[i];
            count++;
        }
    }
    cout << count << endl;
}


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

int main(){
  int n, m;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cin >> m;
  int b[m];
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  int t = min(n, m);
  for(int i = 0; i < t; i++){
    if(a[i] < b[i]){
      cout << 1 << endl;
      return 0;
    }else if(a[i] > b[i]){
      cout << 0 << endl;
      return 0;
    }
  }
  if(n < m){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n; cin>>n;

    int ans = 0;
    for(int i=0; i<n; i++){
        int x; cin>>x;
        ans += (x-1);
    }

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

Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>

constexpr int MAX_X = 4, MAX_Y = 50;

int main(){
    while(true){
        int X, Y, Z;
        int roulette[MAX_X], jump[MAX_Y]{}, get_money[MAX_Y]{};
        float dp[MAX_Y + 1][100 * MAX_Y + 1]{1};
        scanf("%d%d%d", &X, &Y, &Z);
        if(!X){
            break;
        }
        for(int i = 0; i < X; ++i){
            scanf("%d", &roulette[i]);
        }
        for(int i = 0; i < Z; ++i){
            int n, e, a;
            scanf("%d%d%d", &n, &e, &a);
            switch(e){
                case 1:
                    jump[n] = a;
                    break;
                case 2:
                    get_money[n] = a;
                    break;
                case 3:
                    get_money[n] = -a;
                    break;
            }
        }
        for(int i = 0; i < Y; ++i){
            for(int j = 0; j <= 100 * MAX_Y; ++j){
                if(dp[i][j] == 0){
                    continue;
                }
                for(int k = 0; k < X; ++k){
                    int ni, nj;
                    ni = std::min(i + roulette[k], Y);
                    nj = std::max(j + get_money[ni], 0);
                    ni = std::min(ni + jump[ni], Y);
                    dp[ni][nj] += dp[i][j] / X;
                }
            }
        }
        float ans = 0;
        for(int i = 0; i <= 100 * MAX_Y; ++i){
            ans += dp[Y][i] * i;
        }
        printf("%d\n", (int)ans);
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main()
{
    int n,x,y=1000,sum=0,t,i;
    int a[100];
    cin>>n>>x;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<y)
        {
            y=a[i];
        }
        sum=sum+a[i];
    }
    t=n+(x-sum)/y;
    cout<<t<<endl;
    return 0;
}


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

int main(void)
{
char s[101];
int n,i;

//入力
scanf("%s",s);
n=strlen(s);

//処理
for(i=0;i<n;i++){
	s[i]='x';
}

//出力
printf("%s",s);

	return 0;
}

Measured memory_bytes: 128
import sys
def main():
    input=sys.stdin.readline
    h,w=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(h)]
    b=[list(map(int,input().split())) for _ in range(h)]
    ofset = 80*164
    #mask = (1 << (ofset*2)) - 1
    dp=[[0 for i in range(w)] for j in range(h)]
    dp[0][0] |= 1 << (a[0][0] - b[0][0] + ofset)
    dp[0][0] |= 1 << (b[0][0] - a[0][0] + ofset)
    for i in range(h):
        for j in range(w):
            if i < h - 1:
                A = abs(a[i+1][j] - b[i+1][j])
                dp[i+1][j] |= (dp[i][j] << A)
                dp[i+1][j] |= (dp[i][j] >> A)
            if j < w - 1:
                A = abs(a[i][j+1] - b[i][j+1])
                dp[i][j+1] |= (dp[i][j] << A)
                dp[i][j+1] |= (dp[i][j] >> A)
    ans = 10000000000
    for i in range(ofset, 80*330):
        if (dp[h-1][w-1]>>i)&1:
            ans = i - ofset
            break
    for i in reversed(range(ofset)):
        if (dp[h-1][w-1]>>i)&1:
            ans = min(ans, ofset - i)
            break
    print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 62300
#include <iostream>

using namespace std;

int main() {
	int u = 0, n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
	    int mini = i;
	    for (int j = i; j < n; j++) {
	        if (a[j] < a[mini]) {
	            mini = j;
	        }
	    }
	    if (i < mini) {
	        int x = a[i];
            a[i] = a[mini];
            a[mini] = x;
            u++;
	    }
	}
	for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
	cout << a[n - 1] << endl << u << endl;
}




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

int main() {
	int N,T;
  	cin >> N >> T;
  
  	int minimum = 2000;
  	for(int i = 0; i < N; i++) {
    	int c,t;
    	cin >> c >> t;
      	if(t <= T) {
        	minimum = min(minimum,c);
        }
    }
  
  	if(minimum == 2000) {
    	cout << "TLE" << endl;
    }else {
  		cout << minimum << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    IO;
    long long int l, r;
    long long ans = INT_MAX;
    cin >> l >> r;
    if(r - l + 1 >= 2019)
        ans = 0;
    if(ans == 0)
        return cout << 0, 0;
    int modFromLeft = l % 2019;
    int modFromRight = r % 2019;
    if(modFromLeft > modFromRight)
        modFromRight += 2019;
    for(int i = modFromLeft; i < modFromRight; i++)
    {
        for(int j = modFromLeft + 1; j <= modFromRight; j++)
            ans = min(ans, (long long)(i * j) % 2019);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string s="CODEFESTIVAL2016";
string a;
int ans;
int main()
{
	cin>>a;
	for(int i=0;i<s.size();i++)
	if(s[i]!=a[i])
	ans++;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())
A = np.sort(np.array(input().split(),np.int64))
z = A[A == 0]
p = A[A > 0]
n = A[A < 0]

def count_func(x):
    cnt = 0
    if x >= 0:
        cnt += len(z) * N
    cnt += np.searchsorted(A, x // p, side='right').sum()
    cnt += (N - np.searchsorted(A, (-x - 1) // (-n), side='right')).sum()
    cnt -= np.count_nonzero(A * A <= x)
    assert cnt % 2 == 0
    return cnt // 2

l = -10 ** 18
r = 10 ** 18
while l + 1 < r:
    x = (l + r) // 2
    if count_func(x) >= K:
        r = x
    else:
        l = x

print(r)

Measured memory_bytes: 34648
/**
 *    created by : PawPaw       
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  

using namespace __gnu_pbds;  
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,  
        tree_order_statistics_node_update>  
        ordered_set;  

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define PHI acos(-1)
#define EPS 0.000000001
#define N 1000001
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define FbO find_by_order
#define OoK order_of_key

int solve(){
  int n, k, a;
  cin >> n;
  k = 0;
  F(i, 0, n-1){
    cin >> a;
    if(a == k+1) k++;
  }
  if(k == 0) cout << "-1\n";
  else cout << n-k << '\n';
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

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

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

const int inf = 1e9;

int main () {
    int N;
    std::cin >> N;
    int arr[N];
    for ( int i = 0; i < N; ++i ) 
        std::cin >> arr[i];
    int dp[N];
    dp[0] = 0;
    for ( int i = 1; i < N; ++i ) {
        int min_el = inf;
        for ( int pos : {1, 2}) {
            if( i-pos >= 0 ) {
                min_el = std::min(dp[i-pos] + std::abs(arr[i-pos]- arr[i]), min_el); 
            }
        }   
        dp[i] = min_el;
    }
    std::cout << dp[N-1] << std::endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string sA, sB, sC;
    cin >> sA >> sB >> sC;

    int iA = 0, iB = 0, iC = 0; // iAは次にAがiA番目(0-index)のカードを捨てることを表す
    int nA = sA.size(), nB = sB.size(), nC = sC.size(); // nAはAのカードの枚数
    int turnA = 1, turnB = 0, turnC = 0;  // turnA = 1のときAのターン
    int winA = 0, winB = 0, winC = 0;   // winA = 1のときAの勝ち
    while(1) {

        if(turnA) {

            if(iA == nA) {
                winA = 1;
                break;
            }

            if(sA[iA] == 'b') {
                turnA = 0;
                turnB = 1;
            }
            else if(sA[iA] == 'c') {
                turnA = 0;
                turnC = 1;
            }

            iA++;
        }
        else if(turnB) {

            if(iB == nB) {
                winB = 1;
                break;
            }

            if(sB[iB] == 'a') {
                turnB = 0;
                turnA = 1;
            }
            else if(sB[iB] == 'c') {
                turnB = 0;
                turnC = 1;
            }
            
            iB++;
        }
        else if(turnC) {

            if(iC == nC) {
                winC = 1;
                break;
            }

            if(sC[iC] == 'a') {
                turnC = 0;
                turnA = 1;
            }
            else if(sC[iC] == 'b') {
                turnC = 0;
                turnB = 1;
            }
            
            iC++;
        }
    }

    if(winA) {
        cout << 'A';
    }
    else if(winB) {
        cout << 'B';
    }
    else if(winC) {
        cout << 'C';
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int judge(string a,string b, int n){
    int flag=1;
for(int i=0;i<n;i++){
        if(a[i]!=b[i]){
            flag=0;
            break;
        }

}
return flag;

}
string rotation(string a,int n){
char temp;
temp=a[n-1];
for(int i=n;i>0;i--){
    a[i]=a[i-1];
}
a[0]=temp;
return a;

}

int main()
{

    int count=0;
    int flag=0;
    string a,b;
    int n1,n2;
    cin>>a>>b;
    n1=a.size();
    n2=b.size();
    if(judge(a,b,n1)){
        cout<<"Yes";
    }else{
        string temp=a;
    for(int i=0;i<n1;i++){
        temp=rotation(temp,n1);
        if(judge(temp,b,n1)){
            flag=1;
            break;
        }
    }
    if(flag==1){
            cout<<"Yes"<<endl;


    }
    else{
        cout<<"No"<<endl;


    }



    }



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c,i;
	int count = 0;
	scanf("%d%d%d", &a, &b, &c);
	for (i = a; i <= b; i++)
	{
		if (c%i == 0)
		{
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    k = ii()
    a, b = mi()
    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9228
import java.io.*
import java.util.*

fun solve(N: Long, D: Long, X: Long, A: LongArray){
    fun calc(x: Long): Int{
        return (1..D step x).toList().size
    }
    val ans = X + A.map{ calc(it) }.sum()
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val D = sc.next().toLong()
    val X = sc.next().toLong()
    val A = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        A[i] = sc.next().toLong()
    }
    solve(N, D, X, A)
}



Measured memory_bytes: 31492
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	Query,
	Range,
};

struct Info{
	Info(int arg_left,int arg_right,Type arg_type,int arg_index){
		left = arg_left,
		right = arg_right;
		type = arg_type;
		index = arg_index;
	}
	bool operator<(const struct Info &arg) const{

		if(left != arg.left){

			return left < arg.left;
		}else{

			return type < arg.type; //クエリの方が左に来るようにする
		}
	}

	Type type;
	int left,right,index;
};

int N,M,num_query;
ll BIT[505];
ll ans[100005];
vector<Info> info;

void add(int loc,ll value){

	BIT[loc] += value;

	loc += loc & -loc; //最後の1ビットを足した場所が次の★更新★場所

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

ll getSum(int loc){

	ll sum = BIT[loc];

	loc -= loc & -loc; //最後の1ビットを引いた場所が次の★加算★場所

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}

ll calc(int left,int right){ //left～rightの区間の総和を、sum(1～right)-sum(1～left-1)で求める
	return getSum(right)-getSum(left-1);
}

int main(){

	scanf("%d %d %d",&N,&M,&num_query);

	for(int i = 0; i <= N; i++){

		BIT[i] = 0;
	}

	int left,right;
	for(int i = 0; i < M; i++){

		scanf("%d %d",&left,&right);
		info.push_back(Info(left,right,Range,i));
	}

	for(int i = 0; i < num_query; i++){

		scanf("%d %d",&left,&right);
		info.push_back(Info(left,right,Query,i));
	}
	sort(info.begin(),info.end());

	for(int i = info.size()-1; i >= 0; i--){

		if(info[i].type == Range){

			add(info[i].right,1);

		}else{ //info[i].type == Query

			ans[info[i].index] = getSum(info[i].right);
		}
	}

	for(int i = 0; i < num_query; i++){

		printf("%lld\n",ans[i]);
	}

	return 0;
}


Measured memory_bytes: 11504
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}


constexpr int contest_num {26};

void calc_satisfy(const vector<vector<ll>>& S, const vector<ll>& C, const vector<int>& order, const int& D) {
  ll answer {};
  vector<int> fin_day(contest_num, -1);
  rep(i, D) {
    answer += S[i][order[i]-1];
    fin_day[order[i]-1] = i;
    rep(j, contest_num) {
      answer -= C[j]*(i-fin_day[j]);
    }
    cout << answer << '\n';
  }
  //return answer;
}

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

  int D;
  cin >> D;
  vector<ll> c(contest_num);
  rep(i, contest_num) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(contest_num));
  rep(i, D) {
    rep(j, contest_num) {
      cin >> s[i][j];
    }
  }
  vector<int> order(D);
  rep(i, D) cin >> order[i];
  calc_satisfy(s, c, order, D);
}


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

int main(void) {
	string S;
	long long K;
	cin >> S >> K;
	for (int i=0; i<S.size(); i++) {
		if (S[i]!='1') {cout << S[i] << endl; return 0;}
		else if (i==K-1) {cout << S[i] << endl; return 0;}
	}
	return 0;
}

Measured memory_bytes: 256
def frog1(a,n):
  dp=[float('inf')]*(n)
  dp[0]=0
  for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j])) 
  return dp[-1]
 
def main():
  n=int(input())
  a=list(map(int,input().split()))
  print(frog1(a,n))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 13928
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {


	int n;

	int T,P,R;

	static class Data{
		int id;
		int success=0;
		int time=0;
	}

	public void run(){
		Scanner sc=new Scanner(System.in);
		while(true){
			T=sc.nextInt();P=sc.nextInt();R=sc.nextInt();
			if(T==0 && P==0 && R==0)
				break;
			int[][] wrongCount=new int[T][P+1];

			Data[] data=new Data[T];
			for(int i=0;i<T;i++){
				data[i]=new Data();
				data[i].id=i+1;
			}
			for(int i=0;i<R;i++){
				int t=sc.nextInt();
				int p=sc.nextInt();
				int time=sc.nextInt();
				String type=sc.next();
				if("WRONG".equals(type)){
					wrongCount[t-1][p]++;
				}else{
					data[t-1].success++;
					data[t-1].time+=wrongCount[t-1][p]*1200+time;
				}
			}
			Arrays.sort(data,new Comparator<Data>() {
				@Override
				public int compare(Data o1, Data o2) {
					if(o1.success!=o2.success){
						return o2.success-o1.success;
					}
					if(o1.time!=o2.time){
						return o1.time-o2.time;
					}
					return o1.id-o2.id;
				}
			});

			for(Data d:data){
				pr(d.id+" "+d.success+" "+d.time);
			}
		}
	}
	public static void main(String[] _) {
		new Main().run();
	}

	public static void pr(Object o){
		System.out.println(o);
	}
}

Measured memory_bytes: 13000
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
result = 0
for k in range(N):
  result += B[A[k-1]-1]
  if k >= 1:
    if A[k] == A[k-1] + 1:
      result += C[A[k-1]-1]
print(result)

Measured memory_bytes: 3064
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 3 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    int n;
    cin>>n;

    vl v(n);
    iv(v);
    vl right(n+1);
    vl left(n+2);
    right[0] = 0;
    left[n+1] = 0;

    for(int i=0; i<n; ++i){
        right[i+1] = __gcd(right[i] , v[i]);
    }

    for(int i=n-1; i>=0; --i){
        left[i+1] = __gcd(left[i+2] , v[i]);
    }
    bint ans = -1;
    for(int i=1; i<=n; ++i){
        ans = max(ans , __gcd(right[i-1] , left[i+1]));
    }            
    cout<<ans<<endl;
    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("cin","r",stdin);
    freopen("cout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 2560
s = gets.chomp
def halt(a, b); puts "%d %d" % [a, b]; exit; end
halt  1,  2 if s.length == 2 and s[0] == s[1]
halt -1, -1 if s.length == 2
(0...s.length-2).each {|i|
  halt i+1, i+3 if s[i..i+2].chars.group_by{|v| v }.to_a.any?{|v| v.last.length >= 2}
}
halt -1, -1


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n , T;
  cin >> n >> T;
  int ans = 100000;
  for(int i = 0;i<n ;i++){
    int c, t;
    cin >> c >> t;
    if( t <=T){
      ans = min (ans,c);
    }
  }
  if(ans <=  1000){
    cout << ans;
  }
  else {
    cout << "TLE";
  }
}

Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head
void update(ll i, ll diff, vll& bit) {
    for(; i < sz(bit); i += i&-i)
        bit[i] += diff, bit[i] %= mod;
}

ll get(ll i, vll& bit) {
    ll sum = 0;
    for (; i > 0; i -= i&-i)
        sum += bit[i], sum %= mod;
    return sum;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vi l(k), r(k);
    for (int i = 0; i < k; i++)
        cin >> l[i] >> r[i];

    vll dp(n+1);
    dp[n] = 1;

    for (int i = n-1; i > 0; i--) {
        for (int j = 0; j < k; j++) {
            if (i + l[j] > n)
                continue;
            update(i, (get(min(i + r[j], n), dp) - get(i + l[j] - 1, dp) + mod)%mod, dp);
        }
    }
    cout << dp[1] << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> abc(3);
  int oc = 0,ec = 0;
  cin >> abc.at(0) >> abc.at(1) >> abc.at(2);
  for(int i=0;i<3;i++){
    if(abc.at(i)%2 ==0){
      ec ++;
    }else{
      oc ++;
    }
  }
  int s = 0;
  sort(abc.begin(),abc.end());
  if(ec==3){
    s = 3*abc.at(2);
  }else if(oc ==3){
    s = 3*abc.at(2);
  }else if(ec == 1 && abc.at(2)%2 ==0){
    s = 3*abc.at(2);
  }else if(ec ==1 && abc.at(2)%2 == 1){
    s = 3*(abc.at(2)+1);
  }else if(oc == 1 && abc.at(2)%2 ==1){
    s = 3*abc.at(2);
  }else if(oc == 1 && abc.at(2)%2 ==0){
    s = 3*(abc.at(2)+1);
  }
  int ans = (s-accumulate(abc.begin(),abc.end(),0))/2;
  cout << ans << endl;
}

  
  

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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vector <ll> a(n+1), b;
	vector <bool> used(n+1);
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	ll now = 1;
	k ++;
	for (ll i=1; i<=k; i++) {
		if (i == k) {
			cout << now;
			return 0;
		}
		if (used[now]) {
			k -= i-1;
			break;
		}
		used[now] = 1;
		now = a[now];
	}
	used.assign(n+1, 0);
	for (ll i=1; i<=k; i++) {
		if (i == k) {
			cout << now;
			return 0;
		}
		if (used[now]) break;
		used[now] = 1;
		b.push_back(now);
		now = a[now];
	}
	ll sz = b.size();
	k %= sz;
	if (!k) k = sz;
	k --;
	cout << b[k];
	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);
}

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll arr[3004][3004],dp[5][3004][3004];
int main ()
{
	ll t,n,m,k,i,a,b,j,c;
	cin >> n >> m >> k;
	
	for(i=0;i<n+2;i++)
	{
		for(j=0;j<m+2;j++)
		{
			arr[i][j]=0;
			for(t=0;t<5;t++)
			{
				dp[t][i][j]=0;
			}
		}
	}
	for(i=0;i<k;i++)
	{
		cin >> a >> b >> c;
		arr[a][b]=c;
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			a=max(max(dp[0][i-1][j],dp[1][i-1][j]),max(dp[2][i-1][j],dp[3][i-1][j]));
			b=max(dp[1][i][j-1],arr[i][j]);
			dp[0][i][j]=a;
			dp[1][i][j]=max(max(a+arr[i][j],b),dp[0][i][j-1]+arr[i][j]);
			dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+arr[i][j]);
			dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+arr[i][j]);
		}
	}
	i=n;
	j=m;
	a=max(max(dp[0][i][j],dp[1][i][j]),max(dp[2][i][j],dp[3][i][j]));
	cout << a << "\n";
	return 0;
}

Measured memory_bytes: 426324
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  vl num(n); vl numd(n);
  
  rep(i,n){
    cin >> num[i];
    numd[i] = num[i];
  }
  
  sort(all(num));
  
  rep(i,n){
    if(numd[i] == num[n-1]) cout << num[n-2] << endl;
    else cout << num[n-1] << endl;
  }
  
  
}

Measured memory_bytes: 6404
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
  int N,flag = 0;;
  cin >> N;
  for(int i = 0;i <=25 ;++i){
    for(int j = 0;j <= 14;++j){
      if(N == 4*i + 7*j)flag = 1;
    }
  }
  if(flag == 1)cout << "Yes "<< endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

const int N=2e5+10;
int adj[N];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;cin>>n;
    ll a[n-1];
    rep(i,0,n-1){
        cin>>a[i];
        adj[a[i]]++;
    }
    rep(i,1,n+1)cout<<adj[i]<<"\n";
}


Measured memory_bytes: 5912
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	rep(i,n) cin >> v[i];
	//cnt1は偶数,cnt2は奇数
	vector<int>cnt1(100010),cnt2(100010);
	rep(i,n) {
		if(i%2 == 0) {
			cnt1[v[i]]++;
		}
		if(i%2 == 1) {
			cnt2[v[i]]++;
		}
	}
	int mode1 = -1;//偶数の最頻値
	int tmp1 = -1;
	for(int i = 0;i<100010;i++) {
		if(tmp1<=cnt1[i]) {
			tmp1 = cnt1[i];
			mode1 = i;
		}
	}
	
	int mode2 = -1;//偶数で2番目に大きい最頻値
	int tmp2 = -1;
	for(int i = 0;i<100010;i++) {
		if(i != mode1 && tmp2<cnt1[i]) {
			tmp2 = cnt1[i];
			mode2 = i;
 		}
	}
	
	int mode3 = -1;//奇数の最頻値
	int tmp3 = -1;
	for(int i = 0;i<100010;i++) {
		if(tmp3<=cnt2[i]) {
			tmp3 = cnt2[i];
			mode3 = i;
		}
	}
	int mode4 = -1;//奇数で2番目に大きい最頻値
	int tmp4 = -1;
	for(int i = 0;i<100010;i++) {
		if(i != mode3 && tmp4<cnt2[i]) {
			tmp4 = cnt2[i];
			mode4 = i;
 		}
	}
	int ans = 0;
	//偶数番目の配列と奇数番目の配列の最頻値が互いに異なるとき
	if(mode1 != mode3) {
		rep(i,n) {
			if(i%2==0) {
				if(v[i] != mode1) ans++;
			}
			if(i%2 == 1) {
				if(v[i] != mode3) ans++;
			}
		}
		cout << ans << endl;
		return 0;
	}
	int ans2 = 0;
	int ans3 = 0;
	//偶数番目と奇数番目で最頻値が同じとき
	//２番目に大きい最頻値を使って２通り試して最小値をとる
	if(mode1 == mode3) {
		rep(i,n) {
			if(i%2==0) {
				if(v[i] != mode1) ans2++;
			}
			if(i%2 == 1) {
				if(v[i] != mode4) ans2++;
			}
		}
		rep(i,n) {
			if(i%2==0) {
				if(v[i] != mode2) ans3++;
			}
			if(i%2 == 1) {
				if(v[i] != mode3) ans3++;
			}
		}
		cout << min(ans2,ans3) << endl;
		return 0;
	}
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> Ls(N);
    for (auto& L : Ls) {
        std::cin >> L;
    }

    int64_t count = 0;
    for (int64_t i = 0; i < N-2; ++i) {
    for (int64_t j = 1; j < N-1; ++j) {
    for (int64_t k = 2; k < N-0; ++k) {
        if (!(i < j && j < k)) continue;
        int64_t Li = Ls.at(i);
        int64_t Lj = Ls.at(j);
        int64_t Lk = Ls.at(k);
        if (Li == Lj || Lj == Lk || Li == Lk) continue;
        if (Li > Lj && Li > Lk) {
            if (std::abs(Lj - Lk) < Li && Li < (Lj+Lk)) {
                count++;
            }
        } else if (Lj > Li && Lj > Lk) {
            if (std::abs(Li - Lk) < Lj && Lj < (Li+Lk)) {
                count++;
            }
        } else if (Lk > Li && Lk > Lj) {
            if (std::abs(Li - Lj) < Lk && Lk < (Li+Lj)) {
                count++;
            }
        }
    }
    }
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val N = nextInt()
    val A0 = listOfInt().toIntArray()
    val A1 = listOfInt().toIntArray()
    for (n in 1 until N) {
        A0[n] += A0[n - 1]
        A1[N - n - 1] += A1[N - n]
    }
    var ans = (0 until N).map { n -> A0[n] + A1[n] }.max()!!
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }



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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
//int dx[] = {0,1,0,-1};
//int dy[] = {-1,0,1,0};

//   cout<<std::setprecision(12)<<
int main()
{
    ll a,b;
    cin >> a >> b;
    if(a==0)return cout<<0<<endl,0;
    if(a<b)
    {
        cout << min(a,abs(a-b)) << endl;
    }
    else cout<<min(a%b,abs((a%b)-b))<<endl;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int isp[300000], cnt[300000];

int main() {
	memset(cnt, 0, sizeof(cnt));
	memset(isp, 0, sizeof(isp));
	
	for_(i,2,300000) {
		if (isp[i] == 0) {
			++cnt[i];
			for (int j = 2 * i; j < 300000; j += i) isp[j] = 1;
		}
		
		cnt[i] += cnt[i - 1];
	}
	
	int n;
	
	while (cin >> n, n) {
		cout << cnt[2 * n] - cnt[n] << endl;
	}
}

Measured memory_bytes: 3512
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->lineIn();
	
		$ans = 0;
		$h = 0;
		$t = 0;
		
		$f = true;
		for($i = 1; $i < $s; $i++){
			if($f){
				$h++;
			}else{
				$t++;
			}
			$f = (!$f);
		}

		$ans = ($h * $t) + floor($s / 2);
		
		echo $ans . "\n";

	}
}
?>

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a, b = 0;
    int ans = 100000;
    for (int i = 1; i <= n/2; i++) {
        int tmp = 0;
        a = i;
        b = n - a;
        while (a > 0) {
            tmp += a % 10;
            a /= 10;
        }
        while (b > 0) {
            tmp += b % 10;
            b /= 10;
        }
        if (tmp <= ans) {
            ans = tmp;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 2e5 + 5;
int n, a[M], lft[M], rght[M];

int32_t main()
{	
	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)	cin >> a[i];
	memset(lft, -1, sizeof(lft));
	memset(rght, -1, sizeof(rght));
	stack <int> s;
	for(int i = 1; i <= n; i++)
	{
		while(!s.empty() && a[i] < a[s.top()])
		{
			rght[s.top()] = i - 1;
			s.pop();
		}
		s.push(i);
	}
	while(!s.empty())
	{
		rght[s.top()] = n;
		s.pop();
	}
	for(int i = n; i >= 1; i--)
	{
		while(!s.empty() && a[i] < a[s.top()])
		{
			lft[s.top()] = i + 1;
			s.pop();
		}
		s.push(i);
	}
	while(!s.empty())
	{
		lft[s.top()] = 1;
		s.pop();
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans += (i - lft[i] + 1) * (rght[i] - i + 1) * a[i];
	cout << ans;
	return 0;
}

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

int main() {
	string s; cin >> s;
	int ans = 0;
	for (char c : s) {
		ans += (c - '0');
	}
	if (ans % 9) cout << "No";
	else cout << "Yes";
	cout << endl;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

LL dfs(const LL H)
{
    if (H == 1)
        return 1;
    return 2 * dfs(H/2) + 1;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    LL H;
    while (cin >> H) {
        cout << dfs(H) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s=input()
if s=='SUN':
  print(7)
elif s=='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
else:
  print(1)

Measured memory_bytes: 3060
import math
N, D = map(int,input().split())
X = []
for i in range(N):
  tmp = list(map(int, input().split()))
  X.append(tmp)

count = 0
for i in range(N-1):
  for j in range(i+1, N):
    dst = 0
    for k in range(D):
      dst += (X[i][k]-X[j][k])**2
    dst = math.sqrt(dst)
    if dst == int(dst):
      count+=1
print(count)

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

int main(){
	int s;
	cin >> s;
	int num2 = s % 100;
	int num1 = s / 100;
	if( num1 >= 1 && num1 <= 12 ){
		if( num2 >= 1 && num2 <= 12 ){
			cout << "AMBIGUOUS" << endl;
		}
		else cout << "MMYY" << endl;
	}
	else{
		if( num2 >= 1 && num2 <= 12 ){
			cout << "YYMM" <<endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
	return 0;
}


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

int main() {

	int n; cin >> n;
	vector<int> a, b;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int s; cin >> s;
		sum += s;
		if (s % 10 == 0) a.push_back(s);		
		else b.push_back(s);
		}
	sort(b.begin(), b.end());
	int cnt = b.size();
	if (sum % 10 == 0) {
		if (cnt == 0) {
			cout << 0 << endl;
		}
		else cout << sum - b[0] << endl;
	}
	else cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3620
a, b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(prime_factorize(a)).intersection(set(prime_factorize(b))))+1)

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

int main() {
  int A;
  cin>>A;
  
  int B;
  cin>>B;
  
 // int C;
  
  if(A*B%2==1){
    for(int i=1;i<4;i++){
      if(A*B*i%2==1){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  
  cout<<"No"<<endl;
}




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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

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

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s;

	cin >> s;

	ll sum = 0;

	REP(i, s.size()) {
		sum += s[i] - '0';
	}

	ll n = stoll(s);

	if (n % sum) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256