akhauriyash/Code-Regression huggingface dataset:
MAX_V = 999999999999999999999
while 1:
    n,m = list(map(int,input().split()))
    if n == 0:break
    costs = {x:[] for x in range(1,n+1)}
    passed = [[0 for x in range(2)] for y in range(n+1)]
    result = [MAX_V,MAX_V]
    for i in range(m):
        a,b,c = list(map(int,input().split()))
        costs[a].append((b,c))
        costs[b].append((a,c))

    spam = [(0,1,2)] #(cost,num,free tickets count)
    while len(spam) > 0:
        mc = min(spam)
        spam.remove(mc)

        tic_i = 0 if mc[2] == 2 else 1

        if mc[2] != 1 and passed[mc[1]][tic_i] != 0:
            continue

        if mc[2] != 1:
            passed[mc[1]][tic_i] = 1
            if n == mc[1]:
                result[tic_i] = mc[0]

        if max(result) < MAX_V:break

        #移動できる場所の登録
        for cv in costs[mc[1]]:
            #チケット不使用
            if mc[2] != 1:
                spam.append((mc[0] + cv[1],cv[0],mc[2]))
            #チケット使用
            if mc[2] > 0:
                spam.append((mc[0],cv[0],mc[2]-1))

    print(min(result))

Measured memory_bytes: 6780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

int number[10]={-1,2,5,5,4,5,6,3,7,6};
int dp[10100];//i本のマッチ棒で作ることのできる最大の数の桁

int main()
{
	int n,m;
	int a[9];
	int ans=0;
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>a[i];
	sort(a,a+m);
	reverse(a,a+m);
	fill(dp,dp+10100,-100);
	//初期値は1ケタの整数
	dp[0]=0;
	//ここからdp
	for(int i=0;i<10001;i++)
	{
		if(dp[i]!=-100)
		{
			for(int j=0;j<m;j++)
			{
				dp[i+number[a[j]]]=max(dp[i+number[a[j]]],dp[i]+1);
			}
		}
	}
	//ここまでdp
	cerr<<dp[n]<<endl;
	//ここからO(n)で下っていく
	//dp[n-number[k]]=dp[n]-1　が成立するならkは使われている
	int used[10];
	fill(used,used+10,0);
	int index=n;
	while(index!=0)
	{
		for(int i=0;i<m;i++)
		{
			if(index-number[a[i]]>=0 && dp[index-number[a[i]]]==dp[index]-1)
			{
				index-=number[a[i]];
				used[a[i]]++;
				break;
			}
		}
	}

	for(int i=9;i>-1;i--)
	{
		for(int j=0;j<used[i];j++)
			cout<<i;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    long a =1;
    for(int i=1; i<=n; i++) {  
    	a = a * i % (1000000000+7);
    }   	
    	System.out.println(a);
    }
}

Measured memory_bytes: 35568
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			int K = scan.nextInt();
			int []A = new int[N];
			int onenum = 0;
			 long goukei = 0;
			
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				if(A[i]==1)onenum = i;
			}
			
			int migi = N-1-onenum;
			int hidari = onenum-0;
			
			/*
				if(migi%(K-1)!=0)goukei+=(migi/(K-1)+1);
				else goukei+=migi/(K-1);
				*/
				//System.out.println(goukei);
			
			
			
				if((N-1)%(K-1)!=0)goukei+=((N-1)/(K-1)+1);
				else goukei+=(N-1)/(K-1);
				//System.out.println(goukei);
			
			
			System.out.println(goukei);
	
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 49400
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define ll long long
#define lld double
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<"\n"
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 998244353;


void solve(int t)
{
    int n,m;
    cin>>n>>m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    d1(ans);
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    for(int t=1;t<=T;t++)
        solve(t);
}

Measured memory_bytes: 256
s = input()
n = s.__len__()
hn = ((n - 1) / 2).__int__()
qn = (hn / 2).__int__()
ans = 'Yes'
for i in range(hn):
    if s[i] != s[n-1-i]:
        ans = 'No'
for i in range(qn):
    if s[i] != s[hn-1-i]:
        ans = 'No'
print(ans)

Measured memory_bytes: 3064
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	ll L, R;
	cin >> L >> R;
	ll ans = INF;
	fori(i, L, min(L + 2019, R + 1)) {
		fori(j, i + 1, min(L + 2019, R + 1)) {
			if ((i * j) % 2019 < ans) {
				ans = (i * j) % 2019;
			}
		}
	}
	cout << ans << endl;
}

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

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

    int t = 0, x = 1;
    while (t < n){
        if (a[t] == x)
            x++;
        t++;
    }
    if (x != 1)
        cout << n - x + 1 <<"\n";
    else cout << "-1\n";

    return 0;
}

Measured memory_bytes: 1024
from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
print(input()[0::2])


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

int main(){
	string S;
	cin>>S;
	int count=0;
	rep(i,S.size()){
		if(S.at(i)=='o'){
			count++;
		}
	}
	if(count+(15-S.size())>=8){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
abc = gets.split.map(&:to_i)

ans = 1
case abc.count{|e| e.even?}
when 1
    abc.map!{|e| e.odd? ? e + 1 : e}
when 2
    abc.map!{|e| e.even? ? e + 1 : e}
else 
    ans = 0
end

m = abc.max
abc.each{|e| ans += (m - e) / 2}
puts ans

Measured memory_bytes: 3836
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
import itertools
list_all = itertools.permutations (range(1, N+1))

for i, L in enumerate(list_all):
    if L == tuple(P):
        a = i + 1
    if L == tuple(Q):
        b = i + 1
print(abs(a-b))

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;
const int D=365;

int main(){
    int d;
    cin>>d;
    vector<long int> c(26);
    rep(i,26) cin>>c[i];
    vector<vector<long int> > s(D,vector<long int>(26));
    rep(i,D){
        rep(j,26) cin>>s[i][j];
    }
   /* 
    vector<int> last(26,-1);
    vector<long int> ans(D+1);
    for(int i=0;i<D;i++){
        ans[i+1]=ans[i]+s[i][t[i]];
        rep(j,26){
            if (t[i]==j) last[j]=i; 
            ans[i+1]-=c[j]*(i-last[j]);
        }
    }
    for (int i=1;i<D+1;i++)  cout<<ans[i]<<endl;
    */
    rep(i,D){
        cout<<(i+10)%26+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int H, W;
    cin >> H >> W;
    int Ch, Cw, Dh, Dw;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    vector<vector<char>> Sij(H, vector<char>(W));
    vector<vector<bool>> visited(H, vector<bool>(W, false));
    REP(i,H){
        REP(j,W){
            cin >> Sij[i][j];
        }
    }

    typedef tuple<int, int, int> pos;
    deque<pos> routes;
    routes.push_front(pos(Ch, Cw, 0));

    int dh_l[4] = {1, -1 , 0, 0};
    int dw_l[4] = {0, 0, 1, -1};

    priority_queue<int> que;

    while(!routes.empty()){
        pos target = routes.front(); routes.pop_front();
        int _h = get<0>(target);
        int _w = get<1>(target);
        int count = get<2>(target);

        if(visited[_h-1][_w-1] == true){continue;}
        visited[_h-1][_w-1] = true;
        
        if(_h == Dh && _w == Dw){
            que.push(count);
            continue;
        }

        for(int k=0; k<4; k++){
            int dh = dh_l[k];
            int dw = dw_l[k];
            if(_h+dh <= H && _h+dh >0 && _w+dw>0 && _w+dw <= W){
                if(Sij[_h+dh-1][_w+dw-1] == '.' && visited[_h+dh-1][_w+dw-1] == false){
                    // cout << "pre; h: " << _h << ", w: " << _w << ", count" << count << ", dh: " << dh << ", dw" << dw << endl;
                    routes.push_front(pos(_h+dh, _w+dw, count));
                }
            }
        }

        for(int dh2: {-2, -1, 0, 1, 2}){
            for(int dw2: {-2, -1, 0, 1, 2}){
                if(dh2 == 0 && dw2 == 0){continue;}
                if(_h+dh2 <= H && _h+dh2 >0 && _w+dw2>0 && _w+dw2 <= W){
                    if(Sij[_h+dh2-1][_w+dw2-1] == '.' && visited[_h+dh2-1][_w+dw2-1] == false){
                        routes.push_back(pos(_h+dh2, _w+dw2, (count+1)));
                    }
                }
            }
        }

    }

    if(que.size()==0){
        cout << -1 << endl;
    }else{
        cout << que.top() << endl;
    }
    return 0;

   
}

Measured memory_bytes: 5356
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	string S; cin >> S;
	cout << S.substr(0, 4) << " " << S.substr(4, 8) << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

using namespace std;

int main() {
	int n, sum = 0;
	cin >> n;
	int v[n];
	for(int i = 0; i < n; i++) cin >> v[i];
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) sum += v[i] * v[j];
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	while (cin >> n, n){
		int sum = 0;
		int mi = 1000000000;
		int ma = 0;
		REP(i, n){
			int a;
			cin >> a;
			sum += a;
			mi = min(mi, a);
			ma = max(ma, a);
		}
		cout <<(sum-ma-mi)/(n-2) <<endl;
	}
}

Measured memory_bytes: 3008
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n;
string s[155];
bool up=false;

void init(){
  rep(i,105)s[i]="aaa";
}

int main(){
  while(cin>>n){
    if(n==0)break;
    init();
    up=false;
    int cnt=0;
    rep(i,n)cin>>s[i];
    for(int i=0;i<n;i+=2){
      if(!up&&((s[i]=="lu"&&s[i+1]=="ru")||(s[i]=="ru"&&s[i+1]=="lu"))){
	up=true;
	cnt++;
      }else if(up&&((s[i]=="ld"&&s[i+1]=="rd")||(s[i]=="rd"&&s[i+1]=="ld"))){
	up=false;
	cnt++;
      }
      
    }
    cout<<cnt<<endl;
  }
    
  return 0;
}

Measured memory_bytes: 3184
import std.algorithm, std.conv, std.range, std.stdio, std.string;

const days = [0,31,28,31,30,31,30,31,31,30,31,30,31];

void main()
{
  auto rd = readln.split.to!(int[]), x = rd[0], y = rd[1];
  writeln(days[x] == days[y] ? "Yes" : "No");
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

cnt = [0 for i in range(8)]
count = 0

for i in range(N):
    if 1<= a[i] <= 399:
        cnt[0] = 1
    elif 400<=a[i]<=799:
        cnt[1] = 1
    elif 800<=a[i]<=1199:
        cnt[2] = 1
    elif 1200<=a[i]<=1599:
        cnt[3] = 1
    elif 1600<=a[i]<=1999:
        cnt[4] = 1
    elif 2000<=a[i]<=2399:
        cnt[5] = 1
    elif 2400<=a[i]<=2799:
        cnt[6] = 1
    elif 2800<=a[i]<=3199:
        cnt[7] = 1
    else:
        count += 1

ans_min = sum(cnt)
ans_max = ans_min + count
if ans_min == 0:
    ans_min =1

print("{} {}".format(ans_min, ans_max))

Measured memory_bytes: 3064
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
x,y=map(int,input().split())
if x*4>=y and y>=2*x and (x*4-y)%2==0:
    print("Yes")
else:
    print("No")


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();
        int x = sc.NextInt();
        int y = sc.NextInt();

        int answer = n <= k ? n * x : k * x + (n - k) * y;

        Console.WriteLine(answer);
    }

    // 最大公約数
    private static int Gcd(int a, int b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            int r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    private static int Lcm(int a, int b)
    {
        return a / Gcd(a, b) * b;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    int cnt = 0, sum = 0;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    int ct = (sum + (4 * M) - 1) / (4 * M);
    rep(i, N) {
        if (A[i] >= ct) cnt++;
    }

    cout << (cnt >= M ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string S, T;
    cin >> S >> T;

    vector<string> ans(0);

    REP(i, S.size() - T.size() + 1){
        bool ok = true;

        REP(j, T.size()){
            if(S[i + j] != '?' && S[i + j] != T[j]){
                ok = false;
                break;
            }
        }

        if(!ok) continue;

        string a = S;
        REP(j, a.size()){
            if(a[j] == '?') a[j] = 'a';
        }
        REP(j, T.size()){
             a[i + j] = T[j];
        }
        ans.push_back(a);
    }

    SORT(ans);
    if(ans.size() == 0){
        cout << "UNRESTORABLE";
    }else{
        cout << ans[0];
    }
    
    return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
using namespace std;
#define rep(p,q) for(int i = p;i < q; i++)

int main(void) {
	string str;
	bool c = false , f = false;
	cin >> str;
	rep(0, str.size()) {
		if (str[i] == 'C' && !c) {
			c = true;
		}
		else if (str[i] == 'F' && c ) {
			f = true;
		}
	}
	if (c && f) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  int x=2*N/K;
  int y=(x+1)/2,z=x/2;
  if (K%2==0){
    cout << (long long)y*y*y+(long long)z*z*z << endl;
  }
  else {
    cout << (long long)z*z*z << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int n,m,r;
int field[100][100];
int d[100][100];
bool seen[100][100];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int dfs(int x,int y){
    seen[x][y] = true;
    r++;
    rep(i,4){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(nx<0 || nx>=m || ny<0 || ny>=n)continue;
        if(seen[nx][ny])continue;
        if(field[nx][ny] == 0)continue;
        if(d[nx][ny] != INF)continue;
        dfs(nx,ny);
    }
    return r;
}

int main(){
    int k;cin>>k;
    int res = 0;
    rep(i,k){
        for(int j=i+1;j<k;j++){
            if(i%2==0 && j%2==1)res++;
            if(i%2==1 && j%2==0)res++;
        }
    }
    cout<<res;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

N = int(input())
vertex = set()
conn = [[] for _ in range(2*10**5 + 1)]
check = [False]*(2*10**5 + 1)
for i in range(N):
    x, y = [int(x) for x in input().split()]
    vertex.add(x)
    vertex.add(y + 10**5)
    conn[x].append(y + 10**5)
    conn[y + 10**5].append(x)

count = [0] * 2
def dfs(z):
    if check[z] == True:
        return
    check[z] = True
    if z <= 10**5:
        count[0] += 1
    else:
        count[1] += 1
    for w in conn[z]:
        dfs(w)

ans = 0
for z in vertex:
    if check[z] == False:
        count = [0]*2
        dfs(z)
        X, Y = count[0], count[1]
        ans += X * Y
ans -= N

print(ans)

Measured memory_bytes: 91948
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define min(a, b) (a > b ? b : a)

int func(int a, int b, int c) {
    if (b == 0 && c == 0)
        return 0;
    else if (a & 1)
        return func(a >> 1, b >> 1, c >> 1);
    else if (b & 1)
        return func(c >> 1, b >> 1, a >> 1) + 1 + func(0, 0, (a | b | c) >> 1);
    else
        return func(a >> 1, b >> 1, c >> 1) + 1 + func(0, (a | b | c) >> 1, 0) +
               func(0, a | b | c, 0);
}

int main() {
    int n, m, tray[3];
    while (std::cin >> n >> m && n && m) {
        rep(i, 3) {
            tray[i] = 0;
            int k, num;
            std::cin >> k;
            rep(j, k) {
                std::cin >> num;
                tray[i] |= 1 << (num - 1);
            }
        }

        int res = min(func(tray[0], tray[1], tray[2]),
                      func(tray[2], tray[1], tray[0]));
        std::cout << (res <= m ? res : -1) << std::endl;
    }
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
double pi = acos(-1);
int hr = 12*60;
int mr = 60;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	m += h*60;
	int f = m%mr;
	int g= m%hr;
	double mx = (double)b*sin((double)f*pi*2.0/(mr));
	double my = (double)b*cos((double)f*pi*2.0/(mr));
	double hx = (double)a*sin((double)g*pi*2.0/(hr));
	double hy = (double)a*cos((double)g*pi*2.0/(hr));
	cout<<fixed<<setprecision(15)<<sqrt(((mx-hx)*(mx-hx)) + ((my-hy)*(my-hy)));
}


Measured memory_bytes: 4100
#include <stdio.h>
int main(void)
{
	char a[5];
	scanf("%s",a);
	if (a[0] == '1')
	{
		a[0] = '9';
	}
	else
	{
		a[0] = '1';
	}
	if (a[1] == '1')
	{
		a[1] = '9';
	}
	else
	{
		a[1] = '1';
	}
	if (a[2] == '1')
	{
		a[2] = '9';
	}
	else
	{
		a[2] = '1';
	}
	printf("%s",a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
}


Measured memory_bytes: 3600
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int x = scan.nextInt();
    int [][] a = new int[n][m+1];
    for (int i=0;i<n;i++){
      a[i][0] = scan.nextInt();
      for (int j=1;j<m+1;j++){
        a[i][j] = scan.nextInt();
      }
    }
    long g = (long) Math.pow(2,n);
    boolean check = false;
    ArrayList<Integer> kk = new ArrayList<Integer>();
    for (int i=0;i<g;i++){
      int ss [] = new int[m];
      int price = 0;
      int [] k = find(n,i);
      for (int mm=0;mm<n;mm++){
        if (k[mm] == 0){
          continue;
        }
        else{
          price += a[mm][0];
          for (int jj=1;jj<m+1;jj++){
            ss[jj-1] += a[mm][jj];
          }
        }
      }
      if (check(ss,x) == true){
        kk.add(price);
      }
    }

    if (kk.size() == 0){
      System.out.println(-1);
    }
    else{
      int min = kk.get(0);
      for (int v = 0;v<kk.size();v++){
        if (min>kk.get(v)){
          min = kk.get(v);
        }
      }
      System.out.println(min);
    }


  }

  public static boolean check(int[] a,int b){
    for (int i=0;i<a.length;i++){
      if(a[i] < b){
        return false;
      }
    }
    return true;
  }

  public static int[] find(int a,long b){
    int[] g = new int[a];
    int j = a-1;
    while (b>0){
      if (b%2 == 0){
        g[j] = 0;
      }
      else{
        g[j] = 1;
        b -= 1;
      }
      j -= 1;
      b = (long) b/2;
    }
    return g;
  }

}


Measured memory_bytes: 38280
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int a[3];

int input() {
	if (scanf("%d %d %d", a, a+1, a+2) < 0) return 0;
	return 1;
}

void init() {
}

long solve() {
	sort(a, a+3);
	int d = a[2]*2-a[0]-a[1];
	if (d%2==0) return d/2;
	else return (d+3)/2;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 128
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int>P;
main(){
  int n,m;
  int max=0;
  int turara[100004]={0};
  P p;
  priority_queue<P ,vector<P> ,greater<P> > q;
  cin>>n>>m;
  for(int i=2;i<=n+1;i++){
    cin>>turara[i];
  }
  for(int i=2;i<=n+1;i++){
    if(turara[i-1]<turara[i]&&turara[i+1]<turara[i]){
      p.first=m-turara[i];
      if(p.first>max){
	max=p.first;
      }
      p.second=i;
      q.push(p);
    }
  }
  while(!q.empty()){
    turara[q.top().second]=0;
    if(turara[q.top().second-2]<turara[q.top().second-1]){
      p.first=q.top().first+m-turara[q.top().second-1];
      if(p.first>max){
	max=p.first;
      }
      p.second=q.top().second-1;
      q.push(p);
    }
    if(turara[q.top().second+2]<turara[q.top().second+1]){
      p.first=q.top().first+m-turara[q.top().second+1];
      if(p.first>max){
	max=p.first;
      }
      p.second=q.top().second+1;
      q.push(p);
    }
    q.pop();
  }
  cout<<max<<endl;
}

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

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

    int x,n; cin >> x >> n;
    int p[n]; rep(i,n) cin >> p[i];
    int dif = 200,ans = 0;
    for(int i = 0; i <= 101; ++i){
        bool flag = false;
        rep(j,n){
            if(i == p[j]){
                flag = true;
                break;
            }
        }
        if(flag) continue;
        if(dif > abs(x-i)){
            dif = abs(x-i);
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648
n=int(input())
Y=[]*n
for i in range(n):
    Y.append([-1]*n)
for i in range(n):
    for j in range(int(input())):
        x,y=map(int,input().split())
        Y[i][x-1]=y       

ans=0
for c in range(2**n):
    b=bin(c)[2:]
    B=[0]*n
    for i in range(len(b)):
        B[-i-1]=int(b[-i-1])
    a=0
    for i in range(n):
        if B[i]==1:
            for j in range(n):
                if B[j]+Y[i][j]==1:
                    a=1
                    break
        if a>0:
            break
    if a==0:
        ans=max(ans,sum(B))
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
  int i,j,k;
  int d;	//365
  int c[26];
  int score[9490];
  int t[365] = {0};
  int day1[26] = {0};
  double x = 0.36787944117;
  int tmp1=-999999,tmp2=-999999;
  int tmpi = 0;
  
  scanf("%d",&d);
  for(i=0;i<26;i++){
      scanf("%d ",&c[i]);
  }
  for(i=0;i<d*26;i++){
      scanf("%d ",&score[i]);
  }
  //st
  
  for(i=0;i<26;i++){
    if(c[i]>tmp1){
     tmp1 = c[i];
    }
    tmpi = i;
  }
  tmp1 = -999999;/*
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      if(score[i*26+j]-c[j]*(1+day1[j])>tmp1){
       	t[i] = j;
      }
    }
  }
  */
  //en
  int sp[26]={0};
  int pp=-999999;
  int pp2 = 0;
  for(i=0;i<d;i++){
    
    
    
    pp2=0;
    for(k=0;k<26;k++){  
    if(sp[k]==0&&score[k]+c[k]*(1+day1[k])>pp){	
      pp=score[k];
      pp2 = k;
    }}
    pp=-999999;
    sp[pp2]=1;
    printf("%d\n",pp2+1);
    //printf("%d\n",(tmpi+i)%26+1);
    if(i%26==25){
    	for(k=0;k<26;k++){
         sp[k]=0; 
        }
    }  
    
    
    for(k=0;k<26;k++){
      day1[k] += 1;
    }
    day1[pp2]=0;
  }
 return 0; 
}






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

int main(void){
    int N;
    cin>>N;
    vector<int> t(N);
    vector<double> v(N);
    int T=0;
    rep(i,N) {
        cin>>t[i];
        T += t[i]*2;
    }
    rep(i,N) cin>>v[i];
    vector<double> s(T+1);
    rep(x,T){
        if(x<=T/2) s[x] = x/2.0;
        else s[x] = (T-x)/2.0;
    }
    int l=0,r=0;
    rep(i,N){
        r += 2*t[i];
        rep(x,T){
            if(x<=l) s[x] = min(s[x],v[i]+(l-x)/2.0);
            else if(x<=r) s[x] = min(s[x],v[i]);
            else s[x] = min(s[x],v[i]+(x-r)/2.0);
        }
        l = r;
    }

    double sum = 0;
    rep(x,T){
        sum += 0.25*(s[x]+s[x+1]);
    }
    printf("%.6f\n",sum);

    return 0;
}


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

#define ll long long

int t;
int n;


void solve() {
	cin>>n;
	cout<<(n%1000?(1000-n%1000):0)<<'\n';
}

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

	//cin >> t;
	//while(t--) 
		solve();
	//return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
	public static BitSet isntprimenum = new BitSet(1000000);
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		setPrimeNum();
		while (stdin.hasNext()) {
			int a = stdin.nextInt();
			int d = stdin.nextInt();
			int n = stdin.nextInt();
			if (a == 0 && d == 0 && n == 0) break;
			for (int i = 0; i < n; i++){
				while (isntprimenum.get(a)) {
					a += d;
				}
				a += d;
			}
			System.out.println(a - d);
 		}
		System.exit(0);
	}
	public static void setPrimeNum() {
		isntprimenum.set(0, true);
		isntprimenum.set(1, true);
		for (int i = 2; i < 1000; i++) {
			if (isntprimenum.get(i)) continue;
			int j = i * 2;
			while (j < 1000000) {
				isntprimenum.set(j, true);
				j += i;
			}
		}
	}
}

Measured memory_bytes: 21116
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0&&c>0)
	{
		c-=b;
		if(c<=0)
		{
			cout<<"Yes\n";
			break;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No\n";
			break;
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'){
		printf("%c\n",b);
		}
	else {
		if(b=='H')puts("D");
		else puts("H");
		}
	return 0;
	}

Measured memory_bytes: 256
using AtCoderBeginnerContest145.Questions;
using AtCoderBeginnerContest145.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest145.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var s = inputStream.ReadLine();

            if (n % 2 != 0)
            {
                yield return "No";
                yield break;
            }

            yield return s.Substring(0, n / 2) == s.Substring(n / 2) ? "Yes" : "No";
        }
    }
}


namespace AtCoderBeginnerContest145
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest145.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest145.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 11092
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    
    int size = s.size();
    char c = s[size - 1];
    
    if(c == '2' || c == '4' || c == '5' || c == '7' || c == '9'){
        cout << "hon";
    }else if(c == '0' || c == '1' || c == '6' || c == '8'){
        cout << "pon";
    }else{
        cout << "bon";
    }
    
    cout << endl;
}


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

using namespace std;

double const PI = acos(-1);

int r;

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

	cin >> r;

	cout << setprecision(10) << 2 * PI * r << endl;
}


Measured memory_bytes: 3788
import { isRegExp } from "util";

class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  let [a,b,c,d,e]=o.nn(5)
  o.o(((c-a)*60+d-b)-e)
}
m();

Measured memory_bytes: 29668
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
LR = []
for i in range(M):
	LR.append(rl())
cnts = [0]*(N+1)
for l, r in LR:
	cnts[l-1] += 1
	cnts[r] -= 1
ans = 0
s = 0
for i in range(N):
	s += cnts[i]
	if s == M:
		ans += 1
print(ans)


Measured memory_bytes: 92924
#include<cstdio>
#include<algorithm>
int h[100000];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&h[i]);
    std::sort(h,h+n);
    for(int i=0;i+k-1<n;i++)h[i]=h[i+k-1]-h[i];
    std::sort(h,h+(n+1-k));
    printf("%d",h[0]);
    return 0;
}

Measured memory_bytes: 512
while 1:
    data = input()
    if data == "#":
        break

    _, y, m, d = data.split()
    y = int(y)
    m = int(m)
    d = int(d)

    if y == 31:
        if m <= 4:
            gen = "HEISEI"
        else:
            gen = "?"
            y -= 30
    elif y < 31:
        gen = "HEISEI"
    else:
        gen = "?"
        y -= 30

    print(gen, y, m, d)



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

using ll = long long;
using namespace std;
constexpr ll inf = 2e18;
constexpr ll mod = 1e9+7;

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

    int N;
    cin>>N;
    ll tsum = 1, asum = 1;
    for (int n = 0; n < N; n++) {
        int T, A;
        cin>>T>>A;

        // Tにあわせる場合
        ll rt = ((tsum - 1) / T + 1) * T;
        ll ra = rt / T * A;
        if (ra < asum) ra = inf;

        // Aにあわせる場合
        ll la = ((asum - 1) / A + 1) * A;
        ll lt = la / A * T;
        if (lt < tsum) lt = inf;

        if (rt + ra < lt + la) {
            tsum = rt;
            asum = ra;
        } else {
            tsum = lt;
            asum = la;
        }
    }
    cout<<tsum+asum<<endl;

    return 0;
}

Measured memory_bytes: 256
// AOJ 2088: Spirograph
// 2017.11.21 bal4u@uu

#include <stdio.h>
#include <math.h>

#define PI 3.1415926535897932384626433832795
#define DIV_NUM 7500
int P, Q, R;
double a, b, c;

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

double f(double x) 
{
	return sqrt(a*(b-c*cos(P*x/Q)));
}

int main()
{
	int i, g;
	double h, h2, ans, x, xmin, xmax;

	while (scanf("%d%d%d", &P, &Q, &R) && P > 0) {
		if (R == 0) { printf("%.10lf\n", 2*PI*(P-Q)); continue; }
		g = gcd(P-Q, Q), xmin = 0, xmax = 2*PI*Q/g;

		b = Q*Q;
		a = (P-Q)*(P-Q), a /= b;	// a = (p-q)^2 / q^2
		b += R*R;					// b = q^2 + r^2
		c = 2*Q*R;					// c = 2 * q * r

		h = (xmax - xmin) / (2.0*DIV_NUM), h2 = 2*h;
		x = xmin;
		ans = f(x);
		for (i = 1; i < DIV_NUM; i++) {
			ans += 4*f(x+h) + 2*f(x+h2);
			x += h2;
		}
		ans += 4*f(x+h) + f(x+h2);
		ans *= h/3; 
		printf("%.10lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2032
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K, sum = 0;
	int ans = 1;
	cin >> N >> K;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}
	VI cand;
	for (int i = 1; i*i <= sum; i++) {
		if (sum%i == 0) {
			cand.push_back(i);
			cand.push_back(sum / i);
		}
		//cout << "K" << endl;
	}
	//cout << ans << endl;
	
	REP(j, cand.size()) {
		int x = cand[j];
		int need;
		VI r(N);
		
		REP(i, N)r[i] = A[i] % x;
		SORT(r);
		//cout << ans << endl;
		int B = 0;
		REP(i, N) B += x - r[i];
		int A = 0;
		need = 1e18;
		REP(i, N) {
			
			A += r[i];
			B -= x - r[i];
			need = min(need, max(A, B));
		}
		if (need <= K)ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    a = []
    f = [-1, 1]
    for _ in range(n):
        x, y, z = map(int, input().split())
        a.append((x,y,z))
    ans = 0
    for i in f:
        for k in f:
            for p in f:
                a.sort(key=lambda t: t[0] * i +t[1] * k +t[2] * p)
                sx = 0
                sy = 0
                sz = 0
                for j in range(m):
                    sx += a[j][0]
                    sy += a[j][1]
                    sz += a[j][2]
                s = abs(sx) + abs(sy) + abs(sz)
                ans = max(ans, s)
    return ans


print(main())

Measured memory_bytes: 3268
n = int(input())
h = list(map(int, input().split()))
   
h_max = h[0]
for i in range(1, n):
  if h[i-1] > h_max:
    h_max = h[i-1]
  if h[i] < h_max -1:
    print("No")
    exit(0)
print("Yes")

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

#define ft first
#define sd second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> tri;

const int MAXN = 100 * 1000 + 123;



map<int, int> d[MAXN];
map<int, vector<int>> g[MAXN];
int n, m;

inline void inp();
inline void bfs();
inline bool upd(int&, const int);

int main() {/*only 1 tof left??*/
	inp();
	bfs();
	printf("-1");
	return 0;
}
inline void inp() {
	scanf("%d%d", &n, &m);
	int p, q, c;
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &p, &q, &c);
		g[--p][c].push_back(--q), g[q][c].push_back(p);
	}
}
inline bool upd(int &x, const int y) { return ((x == 0 || y < x)? x = y, true: false); }
inline void bfs() {/*giving up????_________________last chances___________-____________________-______________--________________________________..________________*/
	deque<tri> deq;
	d[0][0] = 0;
	deq.push_back({{0, 0}, 0});
	while (!deq.empty()) {
		tri v = deq.front();
		deq.pop_front();
		if (v.sd != d[v.ft.ft][abs(v.ft.sd)])
			continue;
		if (v.ft.ft == n - 1) {
			printf("%d", v.sd);
			exit(0);
		}
		if (v.ft.sd) {
			if (upd(d[v.ft.ft][0], v.sd))
				deq.push_front({{v.ft.ft, 0}, v.sd});
			for (auto &u : g[v.ft.ft][v.ft.sd]) {
				auto &tif = d[u][v.ft.sd];
				if (upd(tif, v.sd))
						deq.push_front({{u, v.ft.sd}, tif});
			}
		}
		else {
			for (auto &i : g[v.ft.ft])
				if (upd(d[v.ft.ft][i.ft], v.sd + 1))
					deq.push_back({{v.ft.ft, i.ft}, v.sd + 1});
		}
	}
}

Measured memory_bytes: 72448
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long double D;
typedef complex<D> P;
const D EPS = 1e-9;

D dot(P a, P b){ return a.real()*b.real() + a.imag()*b.imag(); }
D cross(P a, P b){ return a.real()*b.imag() - a.imag()*b.real(); }

int on_segment(P a, P b, P c){
  b -= a; c -= a;
  if( abs(cross(b,c)) > EPS) return 0;
  if( dot(b,c) < EPS ) return -1;
  return 1;
}

int main(){
  D d;
  while(cin >> d, abs(d)>EPS){
    D px, py, vx, vy;
    cin >> px >> py >> vx >> vy;
    P cur = P(px, py), nxt = P(px+vx, py+vy);

    int flag = on_segment(cur, nxt, P(0,0));
    if(flag == 0){
      cout << "impossible" << endl;
    }else{
      D ans = 0;
      if(flag == 1)ans = abs(cur);
      else ans = 2.0 - abs(cur);
      if(ans > d-EPS)cout << "impossible" << endl;
      else cout << fixed << setprecision(10) << ans << endl;
    }
  }
}

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

int a, b, c, k;
int ans;

int main() {
	scanf("%d%d%d%d", &a, &b, &c, &k);
	if (k <= a)
		cout << k << endl;
	else if (k > a && k <= a + b)
		cout << a << endl;
	else
		cout << 2 * a + b - k << endl;
	return 0;
}

Measured memory_bytes: 3640