akhauriyash/Code-Regression huggingface dataset:
<?php
$n = trim(fgets(STDIN));
$A = 0;
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%d%d", $a, $b);
  if($A<$a){
    $A = $a;
    $max = $a + $b;
  }
}
echo $max;

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

const long MAXX=100100;
bool a[MAXX];

int main() {
	long x;
	cin>>x;
	a[100]=1;a[101]=1;
	a[102]=1;a[103]=1;
	a[104]=1;a[105]=1;
	for(long i=106;i<=x;++i)
		a[i]=a[i-100]|a[i-101]
			|a[i-102]|a[i-103]
			|a[i-104]|a[i-105];
	cout<<a[x]<<endl;
	return 0;
}

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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int main(){
    string s;
    int n;
    cin>>s;
    cin>>n;
    
    int c=0;
    rep(i,n){
        string a;
        cin>>a;
        a+=a;
        if( a.find(s,0)!=-1 )c++;
    }
    cout<<c<<endl;
    return 0;
    
}

Measured memory_bytes: 1212
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define esp 1e-10
int main(){
    int req;
    long double a, b;
    long double cur, ans=0;
    cin>>a>>b;
    for (int i=1; i<=a; i++){
        int tar=i;
        long double cnt=0;
        while (tar<b){
            tar*=2;
            cnt++;
        }
        double temp=1.0/a;
        for (int j=1; j<=cnt; j++) temp*=0.5;
        ans+=temp;
    }
    cout<<fixed;
    cout<<setprecision(10)<<ans-esp<<endl;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
if l+(R-L) >= 2019:
    print(0)
    exit()
else:
    if r < l:
        l, r = r, l
    minv = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            minv = min(minv, i*j%2019)
print(minv)


Measured memory_bytes: 40812
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N;
    cin >> N;
    if(N >= 30 ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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





int main(){
    cout << fixed << setprecision(10);

    double w,h,x,y;


    cin >> w >> h >> x >> y;

    int c=0;

    if(x*2==w&&y*2==h){
        c=1;
    }

    double ans =(double)(w*h)/2;

    cout << ans <<" "<< c << endl;
    




    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<double> arr(n);
    priority_queue <double ,vector <double>,greater<double> > pq;
    for(int i=0; i <n;i++)  {
      cin >> arr[i];
      pq.push(arr[i]);
    }
    while(pq.size()!=1)  {
        double x=pq.top();
        pq.pop();
        double y=pq.top();
        pq.pop();
        pq.push((x+y)/2.0);
    }
    cout<<fixed<<setprecision(10);
    cout<< pq.top() <<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[1000];
int e[1000];
int f[1000];
int g[1000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		int c;
		scanf("%d",&c);
		for(int i=0;i<c;i++){
			scanf("%d%d%d%d",d+i,e+i,f+i,g+i);
		}
		int p;
		scanf("%d",&p);
		for(int i=0;i<p;i++){
			int q,r,s;
			scanf("%d%d%d",&q,&r,&s);
			int last=0;
			int ret=0;
			int now=0;
			for(int j=0;j<c;j++){
				if(f[j]==s){
					if(g[j]){
						if(now==0)last=d[j];
						now++;
					}else{
						now--;
						if(now==0){
							if(q<=d[j]&&d[j]<=r)ret+=d[j]-max(q,last);
							if(d[j]>r&&last<=r)ret+=r-max(q,last);
						}
					}
				}
			}
			printf("%d\n",ret);
		}
	}
}

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

int main() 
{
    int N,k;
    cin>>N>>k;
    int h[N];  //INPUT ARRAY
    int ans[N];  //OUTPUT ARRAY
    for(int i=0;i<N;i++)
    {
     cin>>h[i];
     ans[i]=INT_MAX;
    }
    ans[0]=0;
    for(int i=0;i<N;i++)
    {
         for(int j=i+1;j<N&&j-i<=k;j++)
           ans[j]=min(ans[j],ans[i]+abs(h[i]-h[j]));
    }
	cout<<ans[N-1];
	
	return 0;
}


Measured memory_bytes: 1024
R=range
while True:
    n,x=map(int,input().split())
    if n==x==0:
        break
    r=0
    for a in R(1,x//3):
        for b in R(a+1,x//2):
            c=x-a-b
            if b<c<=n:
                r+=1
    print(r)

Measured memory_bytes: 7688
#include <iostream>
#include <vector>
using namespace std;
int main(void){
	string S;
	cin >> S;
	int answer = 0;
	for(int i = 1; i < 4; i++){
		if(S.at(i) == S.at(i-1)){
			answer = 1;
		}
	}
	if(answer){
		cout << "Bad" << endl;
	}else{
		cout << "Good" << endl;
	}
	return 0;
}


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

int N, K, Q;
vector<int> A;
int R = 2000000000;

int main() {
  cin >> N >> K >> Q;
  for(int i = 0; i < N; ++i) {
    int a; cin >> a; A.push_back(a);
  }
  for(int i = 0; i < N; ++i) {
    int m = A[i];
    vector<int> v;
    priority_queue<int, vector<int>, greater<int>> q;
    for(int j = 0; j <= N; ++j) {
      if(j < N && A[j] >= m) v.push_back(A[j]);
      else {
        sort(v.begin(), v.end());
        for(int k = 0; k < (int)v.size() - (K - 1); ++k) {
          q.push(v[k]);
        }
        v.clear();
      }
    }
    if((int)q.size() >= Q) {
      int M;
      for(int k = 0; k < Q; ++k) {
        M = q.top(); q.pop();
      }
      R = min(R, M - m);
    }
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

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

	set<long long> s;
	auto diff = B - A;
	for (auto i = 0; i < K && i <= diff; ++i)
	{
		s.insert(A + i);
		s.insert(B - i);
	}

	for (auto n : s)
	{
		cout << n << endl;
	}

	return 0;
}


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

int S[100000], n;

int binarysearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right)/2;
        
        if(S[mid] == key){
        return 1;
        }
        if(key < S[mid]){
            right = mid;
        }
        else if(key > S[mid]){
            left = mid+1;
        }
    }
    
    return 0;
}

int main(){
    int q, k;
    int count = 0;
    
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &S[i]);
    }
    
    scanf("%d", &q);
    for(int j=0; j<q; j++){
        scanf("%d", &k);
        if(binarysearch(k)) count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j,c=0,p,h[1000010],m=1,max=0,k;
    string s;
    cin >> s >> k;
    for(i=0;i<k;i++)
    {
        if(s[i]!='1')
        {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
    
    return 0;

}


Measured memory_bytes: 3600
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var N = lines[0];
  if(N==3 || N==5 || N==7){
    console.log("YES");
  }else{
    console.log("NO");
  }
});

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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
  long long odds = 0;
  long long evens = 0;

  for(long long i = 0; i < N; i++){
    if(A[i]%2 == 0) {
      evens++;
    }
    else {
      odds++;
    }
  }

  cout << ((odds % 2 == 0) ? YES : NO) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
    solve(N, std::move(A));
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n, k, l[55];
	cin >> n >> k;
	REP(i, n)cin >> l[i];
	sort(l,l+n, std::greater<int>());
	int sum = 0;
	REP(i, k) {
		sum += l[i];
	}
	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main() {
    char c;
    scanf("%c", &c);

    if ((c >= 'a' && c <= 'z')){
    	
    	printf("a\n");
    	
	}else if(c >= 'A' && c <= 'Z'){
		
		printf("A\n");
	}
    
    return 0;
}

Measured memory_bytes: 1956
n = int(raw_input())
   
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
   
def BFS(s):
  for e in range(n):
    if v[s][e] == 1:
      if d[e] > d[s] + 1:
        d[e] = d[s]+1
        BFS(e)
   
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(G[1]):
    v[G[0]-1][G[2+j]-1] = 1
   
d[0] = 0
for s in range(n):
  BFS(s)
for s in range(n):
  if d[s] == 99999:
    d[s] = -1
for s in range(n):
  print'{0} {1}'.format(s+1, d[s])

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    if(s.back() != 's') s += 's';
    else s += "es";
    cout << s << endl;

    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	int n;
	cin >> n;

	VI l(n);
	REP(i, n)cin >> l[i];

	sort(ALL(l));

	ll ans = 0;

	REP(i, n) {
		FOR(j, i + 1, n) {
			ll k = l[i] + l[j] - 1;
			int m = upper_bound(ALL(l), k) - l.begin();
			ans += max(0, m - j - 1);
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
S=input()
judge=0
for i in range(len(S)):
    if i%2==0:
        if S[i]=="L":
            judge=1
    else:
        if S[i]=="R":
            judge=1
if judge==0:
    print("Yes")
else:
    print("No")

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

#define             sf           scanf
#define             pf           printf
#define             mx           100005
#define             READ         freopen("in.txt", "r", stdin);

using namespace std;

typedef           long long int        ll;

ll n, cap, weight[mx], cost[mx], dp[105][mx];

ll func(ll i, ll w)
{
	ll p1, p2;

	if(i==n) return 0;
	if(dp[i][w] != -1) return dp[i][w];

	if(w+weight[i]<=cap) p1 = cost[i] + func(i+1, w+weight[i]);
	else p1 = 0;

	p2 = func(i+1, w);

	dp[i][w] = max(p1, p2);

	return dp[i][w];
}

int main()
{
	// READ

	memset(dp, -1, sizeof(dp));

	sf("%lld %lld", &n, &cap);

	for(int i = 0; i < n; i++) sf("%lld %lld", weight+i, cost+i);

	ll ans = func(0, 0);

	pf("%lld\n", ans);


	return 0;
}

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

  int main()
  {
	string s;
    cin >> s;
    if((s.find("A") != string::npos) && s.find("B") != string::npos) {
      cout << "Yes" << endl;
    }
    else
      cout << "No" << endl;
    return 0;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0;
    cin>>N;

    string num=to_string(N);

    if(num[0]==num[1]&&num[1]==num[2]){

    }else{
        while(num[0]!=num[1]||num[1]!=num[2]){
            N++;
            num=to_string(N);
        }
    }

            cout<<N<<endl;

            

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


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

using namespace std;
int w,h,n;
int x_0,x_1,y_0,y_1;

int main(){
  cin >> w >> h >> n;
  x_1 = w;
  y_1 = h;
  REP(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1) x_0 = max(x_0,x);
    if(a==2) x_1 = min(x_1,x);
    if(a==3) y_0 = max(y_0,y);
    if(a==4) y_1 = min(y_1,y);
  }
  cout << max(0,x_1-x_0)*max(0,y_1-y_0) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
mochi = [i() for _ in range(N)]
mochi.sort(reverse=True)
ans = 1
for i in range(N-1):
    if mochi[i] > mochi[i+1]:
        ans += 1
print(ans)

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

int main(){
	int n,m;
	int card[52];
	string mark[52];

	cin >> n;
	m = 52 - n;

	for (int i = 0; i < n; i++){
		cin >> mark[i] >> card[i];
	}

	int count = 0;
	
	for (int j = 0; j < 4; j++){
		for (int io = 1; io <= 13; io++){
			if (j == 0){
				for (int y = 0; y < n; y++){
					if (mark[y] == "S"){
						if (io == card[y]){
							count = 1;
						}
					}
				}
				if (count == 0){
					cout << "S" << " " << io << endl;
				}
				count = 0;
			}
			if (j == 1){
				for (int y = 0; y < n; y++){
					if (mark[y] == "H"){
						if (io == card[y]){
							count = 1;
						}
					}
				}
				if (count == 0){
					cout << "H" << " " << io << endl;
				}
				count = 0;
			}
			
				if (j == 2){
					for (int y = 0; y < n; y++){
						if (mark[y] == "C"){
							if (io == card[y]){
								count = 1;
							}
						}
					}
					if (count == 0){
						cout << "C" << " " << io << endl;

					}
					count = 0;
				}
					if (j == 3){
						for (int y = 0; y < n; y++){
							if (mark[y] == "D"){
								if (io == card[y]){
									count = 1;
								}
							}
						}
						if (count == 0){
							cout << "D" << " " << io << endl;
						}
						count = 0;

					}

				}
			}


			
			int tt;
			cin >> tt;
		}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,a;

int main(void){
	scanf("%d%d",&h,&a);
	int cnt=(h+a-1)/a;
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define LL long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
bool c[100010];
bool a[100010];
int n;
void out()
{
	for (int i=0;i<n;i++) printf(a[i] ? "W" : "S");
	exit(0);
}
void dfs(int x)
{
	/*cout <<x<<" ##############\n";
	for (int i=0;i<n;i++) cout <<a[i];
	cout <<"\n";*/
	if (x==n)
	{
		if (a[x-1]==a[1] && a[0]^c[0]==1) return;
		if (a[x-1]!=a[1] && a[0]^c[0]==0) return;
		if (a[x-2]==a[0] && a[x-1]^c[x-1]==1) return;
		if (a[x-2]!=a[0] && a[x-1]^c[x-1]==0) return;
		out();
		return;
	}
	if (x<2)
	{
		a[x]=1;
		dfs(x+1);
		a[x]=0;
		dfs(x+1);
	}
	else
	{
		if (a[x-1]^c[x-1]==0) a[x]=a[x-2];
		else a[x]=a[x-2]^1;
		dfs(x+1);
	}
}
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		char ch;
		cin >>ch;
		c[i]=(ch=='o' ? 0 : 1);
	}
	//fill(a,a+n,-1);
	dfs(0);
	cout <<"-1";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define forn(i,n,m) for(int (i)=(n);i<=(int)(m);(i)++)
#define pb push_back
#define mp make_pair
#define re return
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF=1e9;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue <int> qi;
ll n,ans=1,k=1;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	while(n!=1){
		k*=2;
		n/=2;
		ans+=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 100000000
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];

int prime(){
  
  int i, j, u, v, mincost=0, sum=0; 
  int color[N], d[N], pi[N];

  for(u=0; u<n; u++){
    d[u] = INF;
    pi[u] = -1;
    color[u] = WHITE;
  }
  d[0] = 0;

  while(1){
    mincost = INF;
    u = -1;
    for(i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(u == -1) break;

    color[u] = BLACK;

    for(v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] != INF){
	if(M[u][v] < d[v]){
	pi[v] = u;
	d[v] = M[u][v];
	color[v] = GRAY;
	}
      }
    }
  }

  for(i=0; i<n; i++){
      if(pi[i] != -1){
	sum += M[i][pi[i]];
      }
  }

  return sum;
}

int main(){

  int i, j, m;
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d", &m);
      if(m == -1){
	M[i][j] = INF;
      } else {
	M[i][j] = m;
      }
    }
  }

  printf("%d\n", prime());
  
  return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int a;
	while(scanf("%d",&a)&&a!=0)
	{
		int sum=0;
		int min=1000;
		int max=0;
		for(int i=0;i<a;i++)
		{
			int tmp;
			scanf("%d",&tmp);
			sum+=tmp;
			if(min>tmp) min = tmp;
			if(max<tmp) max = tmp;
		}	
		printf("%d\n",(sum-min-max)/(a-2));
	}
	return 0;
}

Measured memory_bytes: 1188
fun main(args: Array<String>) {
    abc114c()
}

fun abc114c() {
    val n = readLine()!!.toLong()

    val answer = dfs(0L, n)

    println(answer)
}

fun dfs(s: Long, n: Long): Long {
    if (s > n) return 0L

    val is753num = s.toString()
        .let { it.contains("7") && it.contains("5") && it.contains("3") }

    return dfs(s * 10 + 7, n) + dfs(s * 10 + 5, n) + dfs(s * 10 + 3, n) + if (is753num) 1 else 0
}


Measured memory_bytes: 34744
#include <iostream>
#include <vector>
#include <iterator>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    int mi = N+1, res = 0;
    for (int i = 0; i < N; ++i) {
        int p; cin >> p;
        mi = min(mi, p);
        if (mi== p) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M, L;
	cin >> N >> M >> L;
	int C[301][301];
	rep1(i, N) rep1(j, N) C[i][j] = 1e9 + 1;
	rep1(i, N) C[i][i] = 0;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		C[a][b] = c;
		C[b][a] = c;
	}

	rep1(k, N) rep1(i, N) rep1(j, N) {
		chmin(C[i][j], C[i][k] + C[k][j]);
	}

	rep1(i, N) rep1(j, N) {
		C[i][j] = (C[i][j] <= L) ? 1 : 1e9;
	}

	rep1(k, N) rep1(i, N) rep1(j, N) {
		chmin(C[i][j], C[i][k] + C[k][j]);
	}

	int Q;
	cin >> Q;
	rep(i, Q) {
		int s, t;
		cin >> s >> t;
		if (C[s][t] < 1e9) co(C[s][t] - 1);
		else co(-1);
	}

	Would you please return 0;
}

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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	while (cin >> n) {
		int last;
		cin >> last;
		int cur = 0;
		int ans = 0;
		for (int i = 1; i < n; ++i) {
			int next;
			cin >> next;
			if(next > last) cur = 0;
			else cur++;
			ans = max(ans, cur);
			last = next;
		}
		cout << ans << '\n';
	}
}



Measured memory_bytes: 256
s = input()


def length(s, i, j):
    for c in s[i:j + 1]:
        if c not in 'ACGT':
            return 0
    return len(s[i:j + 1])


def find(s):
    candidate = 0
    for i in range(len(s)):
        for j in range(len(s)):
            candidate = max(candidate, length(s, i, j))

    return candidate


print(find(s))


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

#define ll long long

#define pii std::pair<int,int>
#define mp std::make_pair
#define fi first
#define se second

#define SZ(x) (int)(x).size()
#define pb push_back

template<class T>inline void chkmax(T &x, const T &y) {if(x < y) x = y;}
template<class T>inline void chkmin(T &x, const T &y) {if(x > y) x = y;}

template<class T>
inline void read(T &x) {
    char c;int f = 1;x = 0;
    while(((c=getchar()) < '0' || c > '9') && c != '-');
    if(c == '-') f = -1;else x = c-'0';
    while((c=getchar()) >= '0' && c <= '9') x = x*10+c-'0';
    x *= f;
}
static int outn;
static char out[(int)2e7];
template<class T>
inline void write(T x) {
    if(x < 0) out[outn++] = '-', x = -x;
    if(x) {
        static int tmpn;
        static char tmp[20];
        tmpn = 0;
        while(x) tmp[tmpn++] = x%10+'0', x /= 10;
        while(tmpn) out[outn++] = tmp[--tmpn];
    }
    else out[outn++] = '0';
}

const int N = 500;

int n;
char a[N + 9][N + 9];

int main() {
	read(n);
	for(int i = 0; i < n; ++i)
		scanf("%s", a[i]);
	bool blk = false;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			if(a[i][j] == '#')
				blk = true;
	if(!blk) puts("-1");
	else {
		int c = 0;
		for(int j = 0; j < n; ++j)
			for(int i = 0; i < n; ++i)
				if(a[i][j] == '.') {
					c++;
					break;
				}
		int ans = 1e9;
		for(int i = 0; i < n; ++i) {
			int w = 0;
			for(int j = 0; j < n; ++j)
				w += a[i][j] == '.';
			bool b = false;
			for(int j = 0; j < n; ++j)
				if(a[j][i] == '#') {
					b = true;
					break;
				}
			int cur = w + (!b);
			chkmin(ans, cur);
		}
		ans += c;
		std::cout << ans << std::endl;
	}
	
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
using namespace std;
struct Node
{
	int c0,c1;
	int id;
	bool operator<(const Node a)const
	{
		return 1ll*c0*a.c1<1ll*a.c0*c1||(1ll*c0*a.c1==1ll*a.c0*c1&&id<a.id)||(1ll*c0*a.c1==1ll*a.c0*c1&&id==a.id&&c0*200000ll+c1<a.c0*200000ll+a.c1);
	}
	bool operator==(const Node a)const
	{
		return c0==a.c0&&c1==a.c1&&id==a.id;
	}
};
int n,p[200005],pa[200005],c0[200005],c1[200005];
priority_queue<Node>q,del;
int find(int x)
{
	return x==pa[x]?x:pa[x]=find(pa[x]);
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x==0)c0[i]=1;
		else c1[i]=1;
		Node now;
		now.id=i;
		now.c0=c0[i],now.c1=c1[i];
		if(i!=1)q.push(now);
	}
	ll ans=0;
	for(int i=1;i<=n;i++)pa[i]=i;
	for(int i=1;i<n;i++)
	{
		while(!q.empty()&&!del.empty()&&q.top()==del.top())
		{
			q.pop();
			del.pop();
		}
		Node a=q.top();
		q.pop();
		int u=a.id;
		int v=find(p[u]);
		ans+=1ll*c1[v]*c0[u];
		pa[u]=v;
		a.id=v;
		a.c0=c0[v],a.c1=c1[v];
		if(v!=1)del.push(a);
		c1[v]+=c1[u],c0[v]+=c0[u];
		a.c0=c0[v],a.c1=c1[v];
		if(v!=1)q.push(a);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11504
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e1 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int l1, r1, l2, r2;
	cin >> l1 >> r1 >> l2 >> r2;
	cout << max(0, min(r2, r1) - max(l1, l2)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,res,cnt[11][11];
int firstdigit(int x){
    int f=x;
    while(x){
        f = x;
        x/=10;
    }
    return f;
}
int lastdigit(int x){
    return x%10;
}
int main (){
    cin >> n;
    for(int i=1;i<=n;i++){
        int a = i;
        cnt[firstdigit(a)][lastdigit(a)]++;
    }
    for(int i=1;i<=n;i++){
          int a = i;
        res+=cnt[lastdigit(a)][firstdigit(a)];
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[20][20], c[20], n, m, x;
int getbit(int num, int pos) { return (num >> pos) & 1; }
int getsum(int row) {
  int s[20] = {0}, money = 0;
  for (int i = 0; i < n; i++) {
    if (getbit(row, i) == 0) {
      money += c[i];
      for (int j = 0; j < m; j++) {
        s[j] += a[i][j];
      }
    }
  }
  for (int j = 0; j < m; j++) {
    if (s[j] < x) {
      money = -1;
      break;
    }
  }
  return money;
}
int main() {
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int minm = INT_MAX;
  for (int i = 0; i < (1 << n); i++) {
    if (getsum(i) != -1) {
      minm = min(minm, getsum(i));
    }
  }
  if (minm == INT_MAX) minm = -1;
  cout << minm << endl;
  return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env python3
import sys


def solve(T: str):
    a = ""
    # prev = ""
    for i in range(len(T)):
        t = T[i]
        if t == "?":
            t="D"
        a+=t
        # prev = t
    print(a)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = next(tokens)  # type: str
    solve(T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9608
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 123;
const ld EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

ll n, k, s;

void solve(){
	cin >> n >> k >> s;

	for(int i = 1; i <= k; ++i){
		cout << s << ' ';
	}

	for(int i = k + 1; i <= n; ++i){
		cout << INF - (s == INF) << ' ';
	}

}

int main(){

	faster();
 
	int T = 1;
	// cin >> T;
	
	while(T--){
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 1280
# 再帰関数
# 入力文字列の最大の正整数を返す
# def func( in_str: str, prev: str ):
#     if len(in_str) == 0:
#         return 0
#     for i in range(len(in_str)):
#         s = in_str[0:i+1]
#         if s == prev:
#             continue
#         else:
#             new_str = in_str[i+1:]
#             ret = func(new_str, s)
#             if ret == -1:
#                 continue
#             return 1 + ret
#
#     return -1

#再帰じゃない
def func( in_str: str ):
    prev =""
    num_in_str = len(in_str)
    new_str = in_str
    stack_str =[]
    stack_start = []
    stack_i = []
    stack_K = []
    K = 0
    old_i = 0
    is_separate = False
    while(True):
        num = len(new_str)
        if num == 0:
            break
        for i in range(old_i, num):
            s = new_str[0:i+1]
            if s == prev:
                is_separate = False
                continue
            else:
                # 分岐前に状態保存
                #stack_str.append(new_str)
                stack_start.append(num_in_str - len(new_str))
                stack_i.append(i+1)
                stack_K.append(K)

                new_str = new_str[i+1:]

                prev = s
                K += 1
                is_separate = True
                break
        # 失敗したらスタックからもとに戻す
        if is_separate == False:
            #new_str = stack_str.pop()
            start = stack_start.pop()
            new_str = in_str[start:]
            old_i = stack_i.pop()
            K = stack_K.pop()
        else:
            old_i = 0

    return K

s = input()
#s="aabbaa"
#s="aaaccacabaldkfjadhjdhafidhkajhdkfjahdskjhfakhdkfaababc"*1000
#num = func( s, "")
num = func( s )

print(num)

Measured memory_bytes: 20352
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	
	cout<< string(s.length(),'x') << endl;
	return 0;
}


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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
	fast_io;
	
	string s;
	cin>>s;
	if(s[1]=='B')   cout<<"ARC";
	else    cout<<"ABC";
	return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sTmp = "";
            for (int i = 1; i < sS.Length ; i++)
            {
                sTmp = sS.Substring(0, sS.Length - i);
                if (chkDup(sTmp)) { break; }
            }

            //出力
            Console.WriteLine("{0}", sTmp.Length.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
        // 重複確認
        private static Boolean chkDup(string sTmp)
        {
            Boolean bDup = false;
            if (sTmp.Length > 0 && sTmp.Length % 2 == 0)               // 文字列長が偶数のみ可
            {
                int iHaf = sTmp.Length / 2;
                string sTm1 = sTmp.Substring(0, iHaf);
                string sTm2 = sTmp.Substring(iHaf, iHaf);
                if (sTm1 == sTm2) { bDup = true; }
            }
            return bDup;
        }

}


Measured memory_bytes: 13268
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <iostream>
using namespace std;

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

    printf("%d\n", N/3);
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,k,q = list(map(int,input().split()))
kaitocnt = [0] * (n+1)
for _ in range(q):
    kaitocnt[int(input())]+=1

for i in range(1,n+1):
    if(k-q+kaitocnt[i] > 0):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4680
#include<stdio.h>
#include<string.h>
int n;
int ans;
int d[6];
char ord[5];
int m;

int main(){
	while(true){
		scanf("%d",&n);
		if(n==0)break;
		ans=1;
		d[0]=6;d[1]=1;d[2]=4;d[3]=3;d[4]=5;d[5]=2;
		for(int i=0;i<n;i++){
			scanf("%s",&ord);
			if(strcmp(ord,"North")==0)m=0;
			if(strcmp(ord,"South")==0)m=1;
			if(strcmp(ord,"East")==0)m=2;
			if(strcmp(ord,"West")==0)m=3;
			if(strcmp(ord,"Right")==0)m=4;
			if(strcmp(ord,"Left")==0)m=5;
			switch(m){
			case 0:
				d[0]=d[4];
				d[4]=d[1];
				break;
			case 1:
				d[4]=d[0];
				d[0]=d[5];
				break;
			case 2:
				d[2]=d[0];
				d[0]=d[3];
				break;
			case 3:
				d[0]=d[2];
				d[2]=d[1];
				break;
			case 4:
				d[4]=d[2];
				d[2]=d[5];
				break;
			case 5:
				d[2]=d[4];
				d[4]=d[3];
				break;
			}
			d[1]=7-d[0];
			d[3]=7-d[2];
			d[5]=7-d[4];
			ans+=d[1];
		}
		printf("%d\n",ans);
	}
}

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

const int NMAX = 1e4 + 5;
int n, sol[NMAX];

int main() {
    cin >> n;
    for(int i = 1; i <= 100; i++) {
        for(int j = 1; j <= 100; j++) {
            for(int k = 1; k <= 100; k++) {
                int val = i * i + j * j + k * k + i * j + i * k + k * j;
                if(val <= 10000) {
                    sol[val]++;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << sol[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, ans = 1e6; cin >> n;
  vector<char> s(n+10);
  vector<int> v(n+1, 0), t(n+1, 0);
  rep(i, n){
    cin >> s[i];
    if(s[i] == 'W'){
      v[i+1] = v[i]+1;
      t[i+1] = t[i];
    }
    else{
      v[i+1] = v[i];
      t[i+1] = t[i]+1;
    }
  }
  for(int i = 1; i <= n; i++){
    ans = min(ans, v[i-1]+(t[n]-t[i]));
  }
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;

    int misiyou = 1;
    int count = 0;
    while(B>misiyou){
        misiyou += A-1;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N = int(input())

L = list(map(int,input().split()))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            
            edges = [L[i],L[j],L[k]]
            edges = sorted(edges)
            
            if edges[2] >= edges[1] + edges[0]:
                continue
            ans += 1
print(ans)

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

static class NagataKanaIsAGenius {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]a=Console.ReadLine().Select(c=>c-'0').ToArray();
        int[,]cum=new int[10,n+1];
        for(int i=0;i<10;i++){
            for(int j=0;j<n;j++){
                cum[i,j+1]=cum[i,j];
                if(a[j]==i)cum[i,j+1]++;
            }
        }
        bool[,,]ckd=new bool[10,10,10];
        for(int i=0;i<n;i++){
            for(int j=0;j<10;j++){
                if(cum[j,i]==0)continue;
                for(int k=0;k<10;k++){
                    if(cum[k,i+1]==cum[k,n])continue;
                    ckd[j,a[i],k]=true;
                }
            }
        }
        int ans=0;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    if(ckd[i,j,k])ans++;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int x;
	cin >> x;
	int cnt = 0;
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b ;j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if (i * 500 + j * 100 + k * 50 == x)
				{
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
	//system("pause");
}

Measured memory_bytes: 256
n=int(input())
a=sorted(set([int(x) for x in input().split()]))

while len(a)!=1:
    if a[0]==0:
        a=a[1:]
    for i in range(1,len(a)):
        a[i]%=a[0]
    a=sorted(set(a))

print(a[0])


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='9')
        s[i]='1';
        else if(s[i]=='1')
        s[i]='9';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
/* 
   AOJ 2242
   Era Name

 */

#include<stdio.h>

#define ERA_NAME_MAX 17
#define DATA_BASE_MAX 1000

struct data
{
  char era_name[ERA_NAME_MAX];
  int era_based_year, western_year;
};

struct data data_base[DATA_BASE_MAX];


int is_in_era(struct data era_data, int year)
{
  return (era_data.western_year >= year && year >= era_data.western_year - era_data.era_based_year + 1);
}

int main(void)
{
  int i, j, data_num, query_num, query, unknown_flag = 1;

  while(1)
    {
      scanf("%d %d", &data_num, &query_num);
      if(data_num == 0 && query_num == 0)
	{
	  break;
	}

      for(i = 0; i < data_num; i++)
	{
	  scanf("%s %d %d", data_base[i].era_name, &data_base[i].era_based_year, &data_base[i].western_year);
	}
      
      for(i = 0; i < query_num; i++)
	{
	  scanf("%d", &query);
	  
	  unknown_flag = 0;
	  for(j = 0; j < data_num; j++)
	    {
	      if(is_in_era(data_base[j], query))
		{
		  printf("%s %d\n", data_base[j].era_name, query - data_base[j].western_year + data_base[j].era_based_year);
		  unknown_flag = 1;
		}
	    }

	  if(unknown_flag == 0)
	    {
	      printf("Unknown\n");
	    }
	}
    }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2001,MAXsum=2000001,INF=1<<30;

int main(){
    
    int N,M,Q;cin>>N>>M>>Q;
    vector<vector<char>> S(N,vector<char>(M));
    vector<vector<int>> A(N+1,vector<int>(M+1,0)),B(N+1,vector<int>(M+1,0)),C(N+1,vector<int>(M+1,0));
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin>>S[i][j];
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(S[i][j]=='1') A[i+1][j+1]=A[i+1][j]+1;
            else A[i+1][j+1]=A[i+1][j];
        }
    }
    
    for(int j=0;j<M;j++){
        for(int i=0;i<N;i++){
            A[i+1][j+1]+=A[i][j+1];
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<M-1;j++){
            if(S[i][j]=='1'&&S[i][j+1]=='1') B[i+1][j+1]=B[i+1][j]+1;
            else B[i+1][j+1]=B[i+1][j];
        }
    }
    
    for(int j=0;j<M;j++){
        for(int i=0;i<N;i++){
            B[i+1][j+1]+=B[i][j+1];
        }
    }
    
    for(int j=0;j<M;j++){
        for(int i=0;i<N-1;i++){
            if(S[i][j]=='1'&&S[i+1][j]=='1') C[i+1][j+1]=C[i][j+1]+1;
            else C[i+1][j+1]=C[i][j+1];
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            C[i+1][j+1]+=C[i+1][j];
        }
    }
    
    for(int i=0;i<Q;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        a--;b--;
        int sum=(A[a][b]+A[c][d]-A[a][d]-A[c][b]);
        int x=(B[a][b]+B[c][d-1]-B[a][d-1]-B[c][b]);
        int y=(C[a][b]+C[c-1][d]-C[a][d]-C[c-1][b]);
        cout<<sum-x-y<<endl;
    }
    
    /*for(int i=0;i<N+1;i++){
        for(int j=0;j<M+1;j++){
            cout<<C[i][j]<<" ";
        }
        cout<<endl;
    }*/
}



Measured memory_bytes: 53888
#include <bits/stdc++.h>
using namespace std;
int main(){
string n;
cin>>n;
set<char>s;
bool A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,Z=0;
for(int i=0;i<n.size();i++){
    s.insert(n[i]);
    if(n[i]=='a')A=1;
    else if(n[i]=='b')B=1;
    else if(n[i]=='c')C=1;
    else if(n[i]=='d')D=1;
    else if(n[i]=='e')E=1;
    else if(n[i]=='f')F=1;
    else if(n[i]=='g')G=1;
    else if(n[i]=='h')H=1;
    else if(n[i]=='i')I=1;
    else if(n[i]=='j')J=1;
    else if(n[i]=='k')K=1;
    else if(n[i]=='l')L=1;
    else if(n[i]=='m')M=1;
    else if(n[i]=='n')N=1;
    else if(n[i]=='o')O=1;
    else if(n[i]=='p')P=1;
    else if(n[i]=='q')Q=1;
    else if(n[i]=='r')R=1;
    else if(n[i]=='s')S=1;
    else if(n[i]=='t')T=1;
    else if(n[i]=='u')U=1;
    else if(n[i]=='v')V=1;
    else if(n[i]=='w')W=1;
    else if(n[i]=='x')X=1;
    else if(n[i]=='y')Y=1;
    else if(n[i]=='z')Z=1;
}
auto it=s.begin();
int i;
for(i=0;i<s.size();i++){
if(*it!=static_cast<char>('a'+i)){
        cout<<static_cast<char>('a'+i);
        return 0;
    }
    it++;
}
if(A+B+C+D+E+F+G+H+I+J+K+L+M+N+O+P+Q+R+S+T+U+V+W+X+Y+Z==26){
    cout<<"None";
}
else cout<<static_cast<char>('a'+i);
return 0;
}


Measured memory_bytes: 512
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 998244353;
int n, m, a[3002];
ll dp[3002][3002];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i], dp[i][i]=a[i];
    for(int d=1; d<=n-1; d++){
        for(int i=1; i+d<=n; i++) dp[i][i+d]=max(1LL*a[i]-dp[i+1][i+d], 1LL*a[i+d]-dp[i][i+d-1]);
    }
    cout<<dp[1][n];
}


Measured memory_bytes: 70144
#include <stdio.h>

int main()
{
  int t,h=0,m=0;
  scanf("%d",&t);
  while(t>=60)
  {
    if(t>=3600)
    {
      t=t-3600;
      h++;
    }
    else
    {
      t=t-60;
      m++;
    }
  }
  printf("%d:%d:%d\n",h,m,t);
  return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < LL, LL > pa;

inline LL read()
{
	LL sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 20005;

int n, ans;
LL a[MAXN], table[20];
vector < pa > f, g;

inline vector < pa > merge(vector < pa > a, vector < pa > b)
{
	vector < pa > ret;
	for( auto x : b ) a.pb( x );
	sort( a.begin(), a.end() );
	LL l = 0, r = 0;
	for( auto t : a )
		if( r < t.xx )
		{
			if( l && r ) ret.pb( mp( l, r ) );
			l = t.xx, r = t.yy;
		}
		else r = max( r, t.yy );
	ret.pb( mp( l, r ) );
	return ret;
}

inline bool cal(int x, int y)
{
	f.clear(); g.clear();
	f.pb( mp( table[ x ] * y, table[ x ] * ( y + 1 ) ) );
	for( int i = 1 ; i <= n ; i++ )
	{
		LL c = a[ i ] % table[ x + 1 ];
		g.clear();
		for( auto t : f )
		{
			if( t.xx <= c && c < t.yy ) return true;
			LL l = ( t.xx - c + table[ x + 1 ] ) % table[ x + 1 ], r = ( t.yy - c + table[ x + 1 ] ) % table[ x + 1 ];
			if( !r ) r = table[ x + 1 ];
			g.pb( mp( l, r ) );
		}
		f = merge( f, g );
	}
	return false;
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) a[ i ] = read();
	table[ 0 ] = 1;
	for( int i = 1 ; i <= 18 ; i++ ) table[ i ] = table[ i - 1 ] * 10;
	for( int i = 0 ; i < 18 ; i++ )
		for( int j = 9 ; j ; j-- )
			if( cal( i, j ) )
			{
				ans += j;
				break;
			}
	return printf( "%d\n", ans ), 0;
}


Measured memory_bytes: 512
from itertools import permutations

def solve(N, P, Q):
    vals = [i for i in range(1, N + 1)]
    perms = list(permutations(vals))
    print(abs(perms.index(P) - perms.index(Q)))

if __name__ == "__main__":
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    solve(N, P, Q)


Measured memory_bytes: 44656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int n,A,P;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
       scanf("%d",&A);
       P|=(A%2==1);
    }
    printf("%s",P?"first":"second");
}

Measured memory_bytes: 256