akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
K = []
for i in range(H):
    A = list(map(int, input().split()))
    K.append(A)

Ans = []
i = 0
while(True):
    for j in range(W-1):

        if K[i][j]%2 == 1:
            K[i][j] -= 1
            K[i][j+1] += 1
            Ans.append((i+1, j+1, i+1, j+2))
    i += 1
    if i >= H:
        break
    if K[i-1][W-1] % 2 == 1:
        K[i-1][W-1] -= 1
        K[i][W-1] +=1
        Ans.append((i, W, i+1, W))
    for j in range(W-1, 0, -1):
        if K[i][j]%2 == 1:
            K[i][j] -= 1
            K[i][j-1] += 1
            Ans.append((i+1, j+1, i+1, j))
    i += 1
    if i >= H:
        break
    if K[i-1][0] % 2 == 1:
        K[i-1][0] -= 1
        K[i][0] += 1
        Ans.append((i, 1, i+1, 1))

print(len(Ans))
for i in Ans:
    print(*i)

Measured memory_bytes: 92276
#include<bits/stdc++.h>
using namespace std;
int p,k;
int ans=0;
int main()
{
	int n;
	string a,b,c;
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i]&&a[i]!=c[i])
		ans++;
		if(a[i]==c[i]&&a[i]!=b[i])
		ans++;
		if(b[i]==c[i]&&b[i]!=a[i])
		ans++;	
		if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i])
		ans=ans+2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

#define MAX 20000

using namespace std;

int r[MAX];

int main() {
  int n, s, x;
  int maxn;

  while(cin >> n >> s, n && s) {
    int cnt = 0;
    for(int i = 0 ; i < n ; i++) {
      cin >> r[i];
      //r[i] = x;
    }
    sort(r, r+n);
   
    for(int i = 0 ; i < n-1 ; i++){
      for(int j = i+1;j < n;j++){
    if(r[i]+r[j] > s){
      if(j == i+1){
        for(int k = n-j;k > 0;k--){
          cnt += k;
        }
        i += n;//I¹³¹é½ßÌ
        j += n;
        break;
      }
      cnt += (n - j);
      break;
      break;
    }
      }
    }
   
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 900
#include<cstdio>
using namespace std;
int n,m,a,sum=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d",&a);
		sum+=a;
	}
	if(sum>n) printf("-1\n");
	else printf("%d\n",n-sum);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int MOD = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
      int n,k;
      cin>>n>>k;
      int ct = 0;
      while(n>=k)
      {
          ct++;
          n/=k;
      }
      cout<<ct+1;
    }
   return 0;
}


Measured memory_bytes: 256
N, W, H = [int(n) for n in input().split()]


xmap = [0 for _ in range(W+1)]
ymap = [0 for _ in range(H+1)]
for i in range(N):
    x, y, w = [int(n) for n in input().split()]
    l = max(x-w, 0)
    r = min(x+w, W)
    a = max(y-w, 0)
    b = min(y+w, H)
    xmap[l] += 1
    xmap[r] -= 1
    ymap[a] += 1
    ymap[b] -= 1
# print(xmap, ymap)
covered = 0
xcovered = True
for i in range(W):
    covered += xmap[i]
    if covered <= 0:
        xcovered = False
covered = 0
for i in range(H):
    covered += ymap[i]
    if covered <= 0 and not xcovered:
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 7292
#include "stdio.h"
#include "math.h"
#include "algorithm"
#include "queue"
#include "vector"

typedef std::pair<double,int> pdi;

//point n -> start
//		n+1 -> end
double dist[1005][1005];
double minDist[1005];
bool isV[1005];
int xs,ys,xt,yt;
int n;
int xi[1005],yi[1005],ri[1005];
std::priority_queue<pdi , std::vector<pdi>, std::greater<pdi> > qu;

double squa(double x){
	return x*x;
}


int main(){
	scanf("%d%d%d%d",&xs,&ys,&xt,&yt);
	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%d%d%d",&xi[i],&yi[i],&ri[i]);
	}

	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			dist[i][j] = dist[j][i] = std::max(0.0,sqrt( squa(xi[i]-xi[j]) + squa(yi[i]-yi[j]) )-ri[i]-ri[j]);
		}
	}

	for(int i = 0; i < n; i++){
		dist[i][n] = dist[n][i] = std::max(0.0,sqrt( squa(xi[i]-xs) + squa(yi[i]-ys) )-ri[i]);
	}
	for(int i = 0; i < n; i++){
		dist[i][n+1] = dist[n+1][i] = std::max(0.0,sqrt( squa(xi[i]-xt) + squa(yi[i]-yt) )-ri[i]);
	}

	dist[n][n+1] = dist[n+1][n] = sqrt( squa(xs-xt) + squa(ys-yt) );

	for(int i = 0; i < n+2; i++){
		minDist[i] = -1.0;
	}

	/*for(int i = 0; i < n+2; i++){
		for(int j = 0; j < n+2; j++){
			printf("%5.3f ",dist[i][j]);
		}
		printf("\n");
	}*/

	//run dijkstar
	qu.push({0.0,n});
	minDist[n] = 0.0;
	while(!qu.empty()){
		pdi no = qu.top();
		qu.pop();
		if(no.second==n+1){
			break;
		}else if(!isV[no.second]){
			//printf("%d %.10f\n",no.second,no.first);
			isV[no.second] = true;
			for(int i = 0; i < n+2; i++){
				if(!isV[i] && (minDist[i]==-1.0||no.first + dist[no.second][i]<minDist[i]) ){
					minDist[i] = no.first + dist[no.second][i];
					qu.push({minDist[i],i});
				}
			}
		}
	}
	printf("%.10f\n",minDist[n+1]);
}

Measured memory_bytes: 12400
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int n,m;cin>>n>>m;
  vector<int> ac(n+1,0);
  vector<int> wa(n+1,0);
  vector<int> p(m);
  vector<string> s(m);
  rep(i,m)cin>>p[i]>>s[i];
  int ac_num=0;
  int wa_num=0;
  rep(i,m){
    if(s[i]=="AC"){
      if(ac[p[i]]==0)ac_num++;
      ac[p[i]]++;
    }
    else{
      if(ac[p[i]]==0)wa[p[i]]++;
    }
  }
  rep1(i,n){
    if(ac[i]>=1){
      wa_num+=wa[i];
    }
  }
  cout<<ac_num<<" "<<wa_num<<endl;
  return 0;
}


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

using namespace std;

int main() {

  string S; string T; string U;
  cin>>S>>T>>U;
  transform(S.begin(), S.end(),S.begin() ,::toupper);
   transform(T.begin(), T.end(),T.begin() ,::toupper);
   transform(U.begin(), U.end(),U.begin() ,::toupper);
  cout<<S.at(0)<<T.at(0)<<U.at(0)<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(2 * n);
  for (int i = 0; i < 2 * n; ++i) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < 2 * n; i += 2) {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int r;
  cin>>r;
  cout<<r*M_PI*2<<endl;

  return 0;
}




Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int s,w; cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val s = sc.nextLine()
    var max = 0
    for (i in 1 until n) {
        val s1 = s.substring(0, i)
        val s2 = s.substring(i)
        val m = s1.toCharArray().intersect(s2.toCharArray().asIterable()).count()
        max = Math.max(max, m)
    }
    println(max)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

using namespace std;
typedef long long int ll;

ll INF = 114514191919119;

//数学的に解こうとするとハマった
//制約を見ると全探査でも良さそう
int main(){

    ll H, W;
    cin >> H >> W;
    //3の倍数ならそりゃうまくいく
    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = INF;
    //とりあえず縦に割る
    for(ll i = 1; i <= H - 1; i++){
        //縦縦
        ll t1 = ((H - i) / 2) * W;
        ll t2 = ((H - i) / 2 + (H - i) % 2)  *  W;
        ll tmx = max(W * i, max(t1, t2));
        ll tmn = min(W * i, min(t1, t2));
        ans = min(ans, tmx - tmn);
        
        //縦横
        ll w1 = (H - i) * (W / 2);
        ll w2 = (H - i) * (W / 2 + W % 2);
        ll wmx = max(W * i, max(w1, w2));
        ll wmn = min(W * i, min(w1, w2));
        //cout << wmx - wmn << endl;
        ans = min(ans, wmx - wmn);

    }

    for(ll i = 1; i <= W - 1; i++){
        //縦縦
        ll t1 = ((W - i) / 2) * H;
        ll t2 = ((W - i) / 2 + (W - i) % 2)  *  H;
        ll tmx = max(H * i, max(t1, t2));
        ll tmn = min(H * i, min(t1, t2));
        ans = min(ans, tmx - tmn);
        //cout << tmx - tmn << endl;
        
        //縦横
        ll w1 = (W - i) * (H / 2);
        ll w2 = (W - i) * (H / 2 + H % 2);
        ll wmx = max(H * i, max(w1, w2));
        ll wmn = min(H * i, min(w1, w2));
        //cout << wmx - wmn << endl;
        ans = min(ans, wmx - wmn);

    }

    cout << ans << endl;

}

Measured memory_bytes: 256
l, r = map(int, input().split())
mod = 2019
l_n = l//mod
r_n = r//mod
ans = float("inf")
if l_n == r_n:
    for i in range(l, r):
        for j in range(i+1, r+1):
            if ans >= i*j % mod:
                ans = i*j % mod
    print(ans % mod)
elif l_n < r_n:
    print(0)


Measured memory_bytes: 40684
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    vector<int> v(4);
    int a;
    bool flag = true;
    for (int i = 0; i < 4; i++) {
        cin >> a;
        if (a == 1) {
            v[0]++;
        }else if(a == 9){
            v[1]++;
        }else if(a == 7){
            v[2]++;
        }else if(a == 4){
            v[3]++;
        }else{
            flag = false;
        }
    }
    for (int i = 0; i < 4; i++) {
        if (v[i] != 1) {
            flag = false;
        }
    }
    if (flag) {
        cout << "YES" << endl;
    }else{
        cout << "NO"<< endl;
    }
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
a = []
ans = []
no = [True] * h
for i in range(h):
    a.append(input())
    ans.append([0] * w)

color = 1
last_i = 0
for i in range(h):
    last_j = 0
    found = False
    for j in range(w):
        if a[i][j] == '#':
            for k in range(last_i, i+1):
                for l in range(last_j, j+1):
                    ans[k][l] = color
            last_j = j+1
            color += 1
            found = True
    if found:
        last_i = i+1

for i in range(h):
    for j in range(w-1):
        if ans[i][j+1] == 0:
            ans[i][j+1] = ans[i][j]
for i in range(h-1):
    for j in range(w):
        if ans[i+1][j] == 0:
            ans[i+1][j] = ans[i][j]

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=' ')
    print('')


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

int main() {
	// your code goes here
	char a,b,c,d;
	cin>>a>>b>>c>>d;
	int n,m;
	n = 10*(a-'0')+(b-'0');
	m = 10*(c-'0')+(d-'0');
	
	if( (n>0 && n<13 ) && (m>0 && m<13) ) cout<<"AMBIGUOUS";
	else if(n>0 && n<13 ) cout<<"MMYY";
	else if(m>0 && m<13) cout<<"YYMM";
	else cout<<"NA";
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        if(n[0] == n[1])
            WriteLine(n[2]);
        else if(n[0] == n[2])
            WriteLine(n[1]);
        else
            WriteLine(n[0]);
    }
}


Measured memory_bytes: 19020
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort(reverse=True)

    if L[0]<sum(L)-L[0]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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>a(n+2);
    for(int i = 1;i<=n;i++) cin >> a[i];
    int s = 0;
    for(int i = 0;i<=n+1;i++) {
        s += abs(a[i]-a[i+1]);
    }
    for(int i = 1;i<=n;i++) {
        int tmp = abs(a[i-1]-a[i+1]) - abs(a[i-1] - a[i]) -abs(a[i]-a[i+1]);
        int ans = s + tmp;
        cout << ans << endl;
    }

}

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

#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 1e9 + 7;
const ll LINF = 1e18 + 14;

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;

    int sum = 0;
    for (int i = 1; i < n; i++) {
        sum += (n - 1) / i; 
    }
    cout << sum;
    return 0;
} 


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(int, n);
    VEC(int, a, n);
    sort(ALL(a));
    int ans = 0, num = a[0], cnt = 1;
    FOR(i, 1, n){
        if(a[i - 1] == a[i]){
            cnt++;        
        }else{
            ans += cnt < num ? cnt : cnt - num;
            cnt = 1;
            num = a[i];
        }
    }
    ans += cnt < num ? cnt : cnt - num;
    OUTL(ans);
RET;}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int n;
    cin >> n;
    int v[3] = {};
    rep(i, n){
        int a;
        cin >> a;
        if(a % 4 == 0){
            v[0]++;
        }
        else if(a % 2 == 0){
            v[1]++;
        }
        else{
            v[2]++;
        }
    } 
    
    if((v[0]==0 && v[2]==0) || (v[0]>=v[2]) || (v[0]==v[2]-1 && v[1]==0)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;



int main() {
	int n;
	scanf("%d", &n);
	long long ans = 0;
	int by = 1;
	while(n--) {
		int a;
		scanf("%d", &a);
		if(a <= by) maxi(by, a + 1);
		else {
			ans += (a - 1) / by;
			maxi(by, 2);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
        int r = sc.nextInt();
        long remain = (long)(2 * Math.pow(10,9)) * 2;
        a:for (long i = l; i < r; i++) {
            for (long j = i + 1; j <= r; j++) {
                if(i*j % 2019 < remain)
                    remain = i*j % 2019;
                if(remain == 0)
                    break a;
            }
        }
		System.out.println(remain);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Range {
public:
    int start, end;
    Range() {}
    Range(int s, int e) {
	start = s;
	end = e;
    }
};

signed main() {
    int N, Q;
    while (cin >> N >> Q) {
	if (N == 0) break;

	map<string, Range> infos;
	rep(i, N) {
	    string name;
	    int a, b;
	    cin >> name >> a >> b;

	    if (infos.find(name) == infos.end()) {
		infos[name] = Range(b - a + 1, b);
	    } else {
		infos[name].end = max(infos[name].end, b);
	    }
	}

	rep(i, Q) {
	    int a;
	    cin >> a;

	    bool output = false;
	    for (auto it = infos.begin(); it != infos.end(); it++) {
		auto &info = (*it).second;
		if (info.start <= a && info.end >= a) {
		    cout << (*it).first << ' ' << (a - info.start + 1) << endl;
		    output = true;
		    break;
		}
	    }
	    if (!output) {
		cout << "Unknown" << endl;
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 3240
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] nums = new int[n];

    for(int i=0; i<n; i++){
      nums[i] = sc.nextInt();
    }

    Arrays.sort(nums);
    int cnt = 0;

    for(int i=0; i<n-2; i++){
      for(int j=i+1; j<n-1; j++){
        for(int k=j+1; k<n; k++){
          if(nums[k]<nums[i]+nums[j]){
            cnt++;
          }
        }
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 24944
#include<bits/stdc++.h>
#define N 100005
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int n,x[N];
inline int gcd(int a,int b){while(b){int t=a;a=b,b=t%a;}return a;}
int main(){
	n=read()+1;
	for(int i=1;i<=n;++i)x[i]=read();
	sort(x+1,x+n+1);
	int g=x[2]-x[1];
	for(int i=3;i<=n;++i)g=gcd(g,x[i]-x[i-1]);
	cout<<g;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
const int N=200005;
using namespace std;
ll k,n,a[N],r[N],b[N];
ll be,p=1,l,cnt;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	while(1)
	{
		if(b[a[p]]!=0)
		{
			be=b[a[p]];
			l=cnt-be+1;
			break;
		}
		r[++cnt]=a[p];
		b[a[p]]=cnt;
		p=a[p];
	}
	if(k<=be) cout<<r[k];
	else 
	{
		int s=(k-be)%l;
		cout<<r[s+be];
	}
    return 0;
}

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

#define mx 200005
#define ll long long 



namespace MO{
    const int MAXN = 500005;
    const int MAXQ = 500005;

    int Sz;
    int A[MAXN];
    int blkId[MAXN];
    bool vis[MAXN];

    struct Query{
        int L,R,id;
        Query(){}
        Query(int x,int y,int i){L=x;R=y;id=i;}
        bool operator<(const Query other) const{
            int a = blkId[L]; int b = blkId[other.L];
            return a == b ? (a & 1 ? (R > other.R) : (R < other.R)) : a < b;
        }
    }qry[MAXQ];
    int perQ[MAXQ];

    int MaxFreq = 0;
    int CoC[MAXN];
    int Count[MAXN];
    void Check(int x){
        if(!vis[x]){
            vis[x]=1;
            if(Count[A[x]]==0) MaxFreq++;;
            Count[A[x]]++; 
            
        }
        else{
            vis[x]=0;
            Count[A[x]]--;
            if(Count[A[x]]==0) 
            MaxFreq--;
        }
    }
}
using namespace MO;

int main(){

	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
    int N,Q;
    scanf("%d %d",&N,&Q);

    //Initiate Global
    Sz=sqrt(N);
    memset(vis,0,sizeof(vis));
    memset(Count,0,sizeof(Count));
    for(int i=0;i<=N;i++) blkId[i] = i/Sz;

    for(int i=1;i<=N;i++) scanf("%d",&A[i]);
    for(int i=1;i<=Q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        qry[i] = Query(l,r,i);
    }
    sort(qry+1,qry+Q+1);

    int left = qry[1].L;
    int right = left-1;

    for(int i=1;i<=Q;i++){
        Query now = qry[i];
        while(left<now.L)  Check(left++);
        while(left>now.L)  Check(--left);
        while(right<now.R) Check(++right);
        while(right>now.R) Check(right--);
        perQ[now.id] = MaxFreq;
    }
    for(int i=1;i<=Q;i++)printf("%d\n",perQ[i] );
}

Measured memory_bytes: 17844
#include<list>
#include<cstdio>

using namespace std;

struct Data{
	int id,pos,len;
	Data(){}
	Data(int I,int P,int L):id(I),pos(P),len(L){}
};

int main(){
	for(int n;scanf("%d",&n),n;){
		list<Data> L;
		list<Data>::iterator it;
		while(n--){
			char type; scanf(" %c",&type);
			if(type=='W'){
				int id,len; scanf("%d%d",&id,&len);
				int pos=0;
				for(it=L.begin();it!=L.end();++it){
					Data &a=*it;
					if(pos<a.pos){
						int d=min(a.pos-pos,len);
						len-=d;
						L.insert(it,Data(id,pos,d));
					}
					if(len==0) break;
					pos=a.pos+a.len;
				}
				if(len>0){
					L.insert(it,Data(id,pos,len));
				}
			}
			else if(type=='D'){
				int id; scanf("%d",&id);
				for(it=L.begin();it!=L.end();){
					Data &a=*it;
					if(id==a.id) it=L.erase(it);
					else ++it;
				}
			}
			else{
				int pos; scanf("%d",&pos);
				int ans=-1;
				for(it=L.begin();it!=L.end();++it){
					Data &a=*it;
					if(a.pos<=pos && pos<a.pos+a.len){
						ans=a.id;
						break;
					}
					if(pos<a.pos) break;
				}
				printf("%d\n",ans);
			}
		}
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 904
#!/mnt/c/Users/moiki/bash/env/bin/python
N,T = list(map(int, (input()).split()))

clist = []
for i in range(N):
    tc, tt = list(map(int, input().split()))
    if T >= tt:
        clist.append(tc)
clist.sort()
try:
    print(clist[0])
except:
    print("TLE")

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int main()
{


        ll n;
        cin >> n;
        vector<P> x(n);
        for(ll i = 0; i < n; i++) {
                ll a,b;
                cin >> a >> b;
                x[i].first = b;
                x[i].second = a;
        }

        sort(all(x));

        ll tmp = 0;

        bool ok = true;

        for(ll i = 0; i < n; i++){
                tmp += x[i].second;
                if(tmp > x[i].first) ok = false;
        }

        if(ok) cout << "Yes" << endl;
        else cout << "No" << endl;


        return 0;

        






}

















Measured memory_bytes: 3328
N,M=gets.strip.split.map(&:to_i)
m=[]
m<<0
(1..N).each do |i|
  m<<0
end
(1..M).each do |i|
  a=gets.strip.split.map(&:to_i)
  m[a[0]]+=1
  m[a[1]]+=1
end
(1..N).each do |i|
  if m[i]%2==1
    puts "NO"
    exit
  end
end
puts "YES"

Measured memory_bytes: 2684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}


int main(){
    int k,a,b;
    int i=0;
    scanf("%d%d%d",&k,&a,&b);
    for(i=a;i<=b;i++){
        if((i%k)==0){
            printf("OK");
            return 0;
        }
        
    }
    printf("NG");
}
#pragma endregion
 
 


Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n;
int dp[114][5][5][5];
signed main() {
	cin >> n;
	rep(i, 4)rep(j, 4)rep(k, 4) {
		if (i == 0 && j == 2 && k == 1)continue;
		if (i == 0 && j == 1 && k == 2)continue;
		if (i == 2 && j == 0 && k == 1)continue;
		dp[3][i][j][k] = 1;
	}
	for (int i = 4; i <= n; i++) {
		rep(j, 4)rep(k, 4)rep(l, 4)rep(m, 4) {
			if (k == 0 && l == 2 && m == 1)continue;
			if (k == 0 && l == 1 && m == 2)continue;
			if (j == 0 && l == 2 && m == 1)continue;
			if (j == 0 && k == 2 && m == 1)continue;
			if (k == 2 && l == 0 && m == 1)continue;
			dp[i][k][l][m] += dp[i - 1][j][k][l];
			dp[i][k][l][m] %= moder;
		}
	}
	int ans = 0;
	rep(i, 4)rep(j, 4)rep(k, 4)ans += dp[n][i][j][k];
	cout << ans % moder << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
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;}

//head
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int a, b;
  	cin >> a >> b;

  	for(int i = 0; i < 1001; i++){
  		int v2 = i / 10;
  		int v1 = i * 2;
  		v1 /= 25;
  		if(v1 == a && v2 == b){
  			cout << i << endl;
  			return 0;
  		}
  	}
  	cout << -1 << endl;
	return 0;
}


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

int main(){
	int a[5];
	while(cin >> a[0],a[0]){
		int cnt[3] = {};
		for(int i = 1;i < 5;i++) cin >> a[i];
		for(int i = 0;i < 5;i++) cnt[a[i] - 1]++;
		if((cnt[0] && cnt[1] && cnt[2]) || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5){
			for(int i = 0;i < 5;i++) cout << 3 << endl;
			continue;
		}
		for(int i = 0;i < 5;i++){
			if(!cnt[0]){
				if(a[i] == 2) cout << 1 << endl;
				else cout << 2 << endl;
			}
			else if(!cnt[1]){
				if(a[i] == 3) cout << 1 << endl;
				else cout << 2 << endl;
			}
			else {
				if(a[i] == 1) cout << 1 << endl;
				else cout << 2 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3036
import java.util.Scanner;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int q = sc.nextInt();
    
    int[] a = new int[n];
    int[] b = new int[q];
    
    for(int i = 0; i < n; i ++ ) {
      a[i] = 0;
    }
    
    for(int j = 0; j < q; j ++ ) {
      b[j] = sc.nextInt();
    }
    
    for(int j = 0; j < q; j ++ ) {
      a[b[j]-1] ++;
    }
 
    for(int i = 0; i < n; i ++) {
      if(a[i] > q-k) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
    
  }
}


Measured memory_bytes: 80276
#include <iostream>
#include <limits>

using namespace std;


int main() {
    
    int h, w;
    
    while (cin >> h >> w)
    {
        if (h == 0 && w == 0)
            break;

        for (int y = 0; y < h; ++y)
        {
            for (int x = 0; x < w; ++x)
            {
                if (y == 0 || y == h - 1 || x == 0 || x == w - 1)
                    cout << '#';
                else
                    cout << '.';
            }
            cout << endl;
        }

        cout << endl;
    }

    return 0;
} 

Measured memory_bytes: 3072
x=[]
y=[]

for i in range(10):
    X = int(input())
    x.append(X)
    
for i in range (10):
    Y = int(input())
    y.append(Y)
    
list.sort(x, reverse=True)
    
list.sort(y,reverse=True)
    
print(x[0]+x[1]+x[2], y[0]+y[1]+y[2])


Measured memory_bytes: 5596
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  int ans0,ans1,ans2;
  ans2 = a[n-1];
  auto it = lower_bound(a,a+n,ans2/2);
  ans0 = *it;
  it--;
  ans1 = *it;
  if(ans0 < ans2 - ans1) cout << ans2 << " " << ans0 << endl;
  else cout << ans2 << " " << ans1 << endl;
  return 0;
}


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

int main(void){
  int N;
  cin >> N;
  
  vector<int> lump(N);
  for( int i=0 ; i < N ; i++ ){
    cin >> lump.at(i);
  }
  
  int num = 1;
  for( int i=0 ; i<N ; i++ ){
    num = lump.at(num-1);
    if( num == 2 ){
      cout << i+1 << endl;
      break;
    }
  }
  if( num != 2 )  cout << "-1" << endl;
}     

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int solve() {
  int N; cin >> N;
  if(N == 0) return 1;

  double ideal = 22.0;
  double mi = 1e9; int id = -1;
  for(int i=0; i<N; i++) {
    int p; double h, w; cin >> p >> h >> w;
    h /= 100.0;
    double bmi = w / (h * h);

    double sub = fabs(ideal - bmi);
    if(sub < mi) {
      mi = sub;
      id = p;
    }
  }
  cout << id << endl;
  return 0;
}

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



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

#define ll long long
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

struct Edge{
   int from, to, cost;
};

const ll INF = (ll)4e18;
int N, M;
vector<vector<Edge>>  G;
bool ok = true;

void dfs(vector<ll> &dist, int pos) {
   for (auto e : G[pos]) {
      if (dist[e.to] == INF) { // ノードの値が定まってない
         dist[e.to] = dist[pos] + e.cost;
         dfs(dist, e.to);
      }
   }
}

int main() {
   cin >> N >> M;
   G = vector<vector<Edge>>(N);
   rep (i, 0, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--, r--;
      G[l].push_back(Edge{l, r, d});
      G[r].push_back(Edge{r, l, -d});
   }

   vector<ll> dist(N, INF);
   rep (i, 0, N) {
      if (dist[i] == INF) { // 始点
         dist[i] = 0;
         dfs(dist, i);
      }
   }

   rep (i, 0, N) {
      for (auto e : G[i]) {
         if (dist[e.to] - dist[e.from] != e.cost) {
            puts("No");
            return 0;
         }
      }
   }
   puts("Yes");

   return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	int k,t;
	cin >> k >> t;
	vector<int> cake(t);
	rep(i,t) cin>>cake[i];
	int nax = -INF;
	int nax_i;
	rep(i,t) {
		if(nax<cake[i]){
			nax = cake[i];
			nax_i = i;
		}
	}
	cake[nax_i]--;
	int before=nax_i;
	int cnt=1;
	for(int i=1;i<k;i++){
		//最大インデックスを探す
		nax = -INF;
		rep(j,t) {
			if(before==j)
				continue;
			if(nax<cake[j]){
				nax = cake[j];
				nax_i = j;
			}
		}
		if(nax<=0)
			break;
		cake[nax_i]--;
		before = nax_i;
		cnt++;
	}
	ll ans=0;
	rep(i,t)
		ans+=cake[i];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int k;
    cin>>k;
    vector<ll>a;
    for(int i=1; i<=9; ++i){
        a.push_back(i);
    }
    while(1){
        if(k<=a.size()){
            cout<<a[k-1]<<endl;
            return 0;
        }
        k-=a.size();
        vector<ll>old;
        swap(old,a);
        for(auto x:old){
            for(int i=-1; i<=1; ++i){
                int d=x%10+i;
                if(d<0||d>9)continue;
                ll x2=x*10+d;
                a.push_back(x2);
            }
        }
    }
}

Measured memory_bytes: 1712
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	var n = f.readLine().toLong()

	val triangle = LongArray(46)
	triangle[0] = 0L
	for(i in 1..45){
		triangle[i] = triangle[i-1]+i.toLong()
	}



	var answer = 0L
	var i = 2L
	while(i*i <= n){
		var count = 0L
		while(n%i == 0L){
			n/=i
			count++
		}
		if(count == 0L){
			i++
			continue
		}
		var l = 1
		var r = 40
		var ans = -1
		while(l <= r){
			var mid = l + (r-l)/2
			//println("$i $mid")
			if(triangle[mid] <= count){
				ans = mid
				l = mid+1
			} else {
				r = mid-1
			}

		}
		//println("$i $ans")
		i++
		answer += ans.toLong()
	}

	if(n != 1L) answer++
	println(answer)
}


Measured memory_bytes: 34240
n = int(input())
e = []
for _ in range(n):
    a, b = map(int, input().split())
    e.append((b, a))
e.sort()

cur = 0
can = True
for b, a in e:
    cur += a
    if cur > b:
        can = False
        break

print('Yes' if can else 'No')


Measured memory_bytes: 29456
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int> > town_pos(n);
  for(int i=0; i<n; i++) cin >> town_pos[i].first >> town_pos[i].second;

  vector<int> permutation_num;
  for( int i=0; i<n; i++) permutation_num.push_back(i);

  long double sum = 0;
  do{
    for(int i=1; i<n; i++){
      int dx = town_pos[permutation_num[i-1]].first - town_pos[permutation_num[i]].first;
      int dy = town_pos[permutation_num[i-1]].second - town_pos[permutation_num[i]].second;
      sum += sqrt( pow(dx, 2) + pow( dy, 2) );
    }
  }while(next_permutation(permutation_num.begin(), permutation_num.end()));

  for(int i=0; i<n; i++){
    sum /= (i+1);
  }
  printf("%.10Lf\n", sum );

  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	string S;cin>>S;
	int pile=0;
	int cur=0;
	int ans=0;
	while(cur<S.size()){
		if(S[cur]=='A'){
			int nex=cur;
			while(nex<S.size()&&S[nex]=='A')nex++;
			pile+=nex-cur;
			cur=nex;
			continue;
		}
		if(cur+1<S.size()&&S.substr(cur,2)=="BC"){
			ans+=pile;
			cur+=2;
			continue;
		}
		pile=0;
		cur++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] l = { { 1, 2, 3, 4 }, { 2, -1, 4, -3 }, { 3, -4, -1, 2 }, { 4, 3, -2, -1 } };
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int[] a = new int[8];
            while (n-- > 0) {
                int[] r = new int[5];
                for (int i = 0; i < 8; i++) {
                    a[i] = sc.nextInt();
                }
                for (int i = 0; i < 4; i++) {
                    for (int j = 4; j < 8; j++) {
                        r[Math.abs(l[i][j - 4])] += a[i] * a[j] *(l[i][j - 4] >= 0 ? 1 : -1) ;
                    }
                }
                for (int i = 1; i < 5; i++) {
                    System.out.print(r[i] + (i == 4 ? "\n" : " "));
                }
            }
        }
    }
}


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

int main() {
  int N, a, b, c;
  cin >> N;
  a = N/100;
  b = (N-a*100)/10;
  c = (N-a*100-b*10);
  if (a==7 || b==7 || c==7 )
    cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

using namespace std;
const int INF = (int)1e9;

int main(){
	int n, m, r,ans = INF;
	cin >> n >> m >> r;
	vector<int> rr(r);
	for(int i = 0; i < r; i++){
		cin >> rr[i];
	}
	sort(begin(rr), end(rr));
	vector<vector<int>> c(n + 1, vector<int>(n + 1, INF));
	for(int i = 0; i < m; i++){
		int a, b, x;
		cin >> a >> b >> x;
		c[a][b] = x;
		c[b][a] = x;
	}
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	do{
		int t = 0;
		for(int i = 1; i < r; i++){
			t += c[rr[i - 1]][rr[i]];
		}
		ans = min(ans, t);
	} while(next_permutation(begin(rr), end(rr)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n,k;
    cin >> n >> k;

    vector<int> flag(n,0);
    for (int i=0;i<=k-1;i++)
    {
        int d;
        cin >> d;
        for (int j=0;j<=d-1;j++)
        {
            int a;
            cin >> a;
            flag[a-1]=1;
        }
    }

    int ans=0;
    for (int i=0;i<=n-1;i++)
    {
        if (flag[i]==0)
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
const int N=1e4+5,M=1e9+7;
const ull base=13331;
const double Pi=acos(-1.0);
const ll C=299792458;
int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int ans1=0;
	int ans2=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0&&s[i]=='0'){
			ans1++;
		}
		if(i%2==1&&s[i]=='1'){
			ans1++;
		}
	}
	for(int i=0;i<s.size();i++){
		if(i%2==1&&s[i]=='0'){
			ans2++;
		}
		if(i%2==0&&s[i]=='1'){
			ans2++;
		}
	}
	cout<<min(ans1,ans2)<<endl;;
}

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

inline char toUpper(char a) { return 'A' + a - 'a'; }

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << toUpper(s1[0]) << toUpper(s2[0]) << toUpper(s3[0]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn], d[maxn];
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", &a[i]);
	}
	d[1] = 1;
	for(int i=2; i<=n; i++){
		if(a[i]<=a[i-1])
			d[i] = d[i-1]+1;
		else
			d[i] = 1;
	}
	int ans = 1;
	for(int i=1; i<=n; i++)
		ans = max(ans, d[i]);
	cout << ans-1;
	return 0;
} 

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int n,i,j,k,v,x,cnt=0,m=0;
  int A[1000000];
  int G[1000000];
  scanf("%d",&n);
     
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    }
     
  G[0]=1;
  for(i=1;G[i-1]<=n;i++){
    m++;
    G[i]=G[i-1]*3+1;
    if(m>100)break;
  }
  for(i=0;i<m/2;i++){
    x=G[i];
    G[i]=G[m-i-1];
    G[m-i-1]=x;
  }
     
     
  for(i=0;i<m;i++){
    for(j=G[i];j<n;j++){
      v=A[j];
      k=j-G[i];
      while(k>=0&&A[k]>v){
    A[k+G[i]]=A[k];
        k=k-G[i];
    cnt++;
      }
      A[k+G[i]]=v;
    }
  }
     
  printf("\n%d\n",m);
  for(i=0;i<m;i++){
    printf("%d ",G[i]);
  }
  printf("\n%d\n",cnt);
  for(i=0;i<n;i++){
    printf("%d\n",A[i]);
    }
  return 0;
}

Measured memory_bytes: 6480
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b , a%b) : a; }
int main()
{
  int n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  vector<ll> left(n+1, 0);
  vector<ll> right(n+1, 0);
  
  rep(i, n) left[i+1] = gcd(left[i], vec[i]);
  repr(i, n-1) right[i] = gcd(right[i+1], vec[i]);
  ll ans = 0;
  rep(i, n) {
    ans = max(ans, gcd(left[i], right[i+1]));
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 5560
# AOJ 0030 Sum of Integers
# Python3 2018.6.18 bal4u

def rec(n, s, vmin):
	if vmin == 10 or vmin > s: return 0
	if n == 1: return (1 if s < 10 else 0)
	sum = 0;
	for i in range(vmin, 10): sum += rec(n-1, s-i, i+1)
	return sum

while True:
	n, s = list(map(int, input().split()))
	if n < 1: break
	print(rec(n, s, 0))


Measured memory_bytes: 5596