akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0;i<n;i++){
			int b=0;
			int c=0;
			boolean flag=true;
			for(int j=0;j<10;j++){
				int a=sc.nextInt();
				if(a>b){
					b=a;
				}else if(a>c){
					c=a;
				}else{
					flag=false;
				}
			}
			if(flag){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 18152
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, ans;
    cin >> a;
    ans = a + a * a + a * a * a;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
//666yuchen
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
using namespace std;
int n,a[105],gs;
bool cmp(int a,int b)
{
  return a>b;
}
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  sort(a+1,a+1+n,cmp);
  for(int i=1;i<=n;i++)if(i%2==1)gs+=a[i];else gs-=a[i];
  cout<<gs;
  return 0;
}

Measured memory_bytes: 256
<?php
$A=[];
for($i=0;$i<26;$i++) $A[$i]=0;

while(!feof(STDIN)){
	$S=trim(fgets(STDIN));
	foreach(str_split($S) as $c){
		$n=ord($c);
		if(64<$n && $n<91) ++$A[$n-65];
		elseif(96<$n && $n<123) ++$A[$n-97];
	}
}

for($i=0;$i<26;$i++) echo chr($i+97),' : ',$A[$i],PHP_EOL;

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	int d = 1;
	int ans = 0;
	rep(i, 0, 6)
	{
		if (i % 2 == 0)
		{
			if (d <= N)
			{
				if (N < 10 * d)
				{
					ans += N - d + 1;
				}
				else
				{
					ans += 9 * d;
				}
			}
		}
		d *= 10;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static int gcd(int first, int second) {
	    if(second == 0) {
	        return first;
	    }
		return gcd(second, first % second);
	}

	public static void main(String[] args) {
		// user input line here
		Scanner sc = new Scanner(System.in);
		// pull numbers
		int first = sc.nextInt();
		int second = sc.nextInt();
		// print the result of gcd() with inputted numbers
		int exp = (int) Math.pow(10, 9);
		if(first>=1 && second <= exp) {
			System.out.println(gcd(first, second));
		}
	}

}



Measured memory_bytes: 26208
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 2000 + 10;
vector<int> vec, g[MAXn];
vector<pair<int, int> > edge;
int n, k, ans = MAXn;
bool flag[MAXn];
int bfs() {
	for (int i = 0, level = 0; i < vec.size() && level < k / 2; level++)
		for (int j = vec.size(); i < j; i++)
			for (int x = 0; x < g[vec[i]].size(); x++)
				if (!flag[g[vec[i]][x]]) {
					flag[g[vec[i]][x]] = true;
					vec.push_back(g[vec[i]][x]);
				}
	return n - (int)vec.size();
}
int main() {
	cin >> n >> k;
	if (k % 2) {
		for (int i = 0; i < n - 1; i++) {
			int a , b;
			cin >> a >> b;
			a--;b--;
			g[a].push_back(b);
			g[b].push_back(a);
			edge.push_back({a , b});
		}
		
		for (int i = 0; i < edge.size(); i++) {
			fill_n(flag, MAXn, 0);
			vec.clear();
			vec.push_back(edge[i].first);
			vec.push_back(edge[i].second);
			flag[edge[i].first] = flag[edge[i].second] = true;
			ans = min(ans , bfs());
		}
	}
	else {
		for (int i = 0; i < n - 1; i++) {
			int a , b;
			cin >> a >> b;
			a--;b--;
			g[a].push_back(b);
			g[b].push_back(a);
			edge.push_back({a , b});
		}
		
		for (int i = 0; i < n; i++) {
			fill_n(flag, MAXn, 0);
			vec.clear();
			vec.push_back(i);
			flag[i] = true;
			ans = min(ans, bfs());
		}
	}
	cout << ans;
	
	
}

Measured memory_bytes: 384
from itertools import groupby, accumulate

N, K = map(int, input().split())
S = input()

L = [len(tuple(v)) for k, v in groupby(S)]

A = [0] + list(accumulate(L))
M = len(A)

if M <= 2 * K + 1:
    print(max(0, A[-1] - A[0] - 1))
    quit()

D = 2 * K + 1
ans = 0
for i in range(M - D):
    l = max(0, A[i] - A[0] - i)
    c = max(0, A[i + D] - A[i] - 1)
    r = max(0, A[-1] - A[i + D] - (M - 1 - i - D))

    ans = max(ans, l + c + r)

print(ans)


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int mx = max(A, max(B, C));
  int d = 3 * mx - (A + B + C);
  if (d % 2 == 0)
    cout << d / 2 << endl;
  else
    cout << (d + 3) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;




int main(void) {
  string s;
  cin >> s;
  
  ll cnt[2]={};
  for(ll i=0; i<s.size(); i++) {
    cnt[s[i]-'A']++;
  }
  
  if(cnt[0]==3||cnt[1]==3) {
    pt("No");
  }else {
    pt("Yes");
  }
  
  
  
  
  
}






Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N, K = MI()

print(math.ceil(math.log(N, K)) if N != 1 else 1)


Measured memory_bytes: 43504
import java.io.*;
import java.util.*;
import java.math.BigDecimal; 
 
public class Main {
 
	void submit() {
	    String missString = nextString();	    
	    char[] missChar= missString.toCharArray();

	    String seikaiString = "CODEFESTIVAL2016";
	    char[] seikaiChar = seikaiString.toCharArray();
	    
	    int kaisu = 0;

	    for(int i=0; i<seikaiString.length(); i++){
	        if(missChar[i] != seikaiChar[i]) kaisu++;
	    }
	    out.println(kaisu);
	    
	}
	
	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int k,s;
    cin >> k >> s;

    int ans = 0;    
    for (int i = 0; i <= k; i++){
        for (int j = 0; j <= k; j++){
            if(s-(i+j)>=0 && s-(i+j)<=k) ans++;
        }
    }
    pr(ans);
}


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

long long jou(long long x,int y){
  long long ans=1;
  for(int i=0;i<y;i++){
    ans*=x;
  }
  return ans;
}
  


int main() {
 long long a,b;
  cin>>a>>b;
  for(int i=0;i<1000;i++){
    if(jou(b,i)>a){
      cout<<i;
      break;
    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
using namespace std;

int main(void) {
  int N;
  string s;
  cin >> N >> s;

  int ans[100000];
  int cnt = 0;
  REP(p, 0, 2) REP(q, 0, 2) {
    ans[0] = p;
    ans[1] = q;
    REP(i, 2, N) {
      if(ans[i - 1] == 0 && s[i - 1] == 'o') ans[i] =     ans[i - 2];
      if(ans[i - 1] == 0 && s[i - 1] == 'x') ans[i] = 1 - ans[i - 2];
      if(ans[i - 1] == 1 && s[i - 1] == 'o') ans[i] = 1 - ans[i - 2];
      if(ans[i - 1] == 1 && s[i - 1] == 'x') ans[i] =     ans[i - 2];
    }
    int f1 = 0, f2 = 0;
    if(ans[N - 1] == 0 && s[N - 1] == 'o' && ans[N - 2] == ans[0]) f1 = 1;
    if(ans[N - 1] == 0 && s[N - 1] == 'x' && ans[N - 2] != ans[0]) f1 = 1;
    if(ans[N - 1] == 1 && s[N - 1] == 'o' && ans[N - 2] != ans[0]) f1 = 1;
    if(ans[N - 1] == 1 && s[N - 1] == 'x' && ans[N - 2] == ans[0]) f1 = 1;
    if(ans[0] == 0 && s[0] == 'o' && ans[N - 1] == ans[1]) f2 = 1;
    if(ans[0] == 0 && s[0] == 'x' && ans[N - 1] != ans[1]) f2 = 1;
    if(ans[0] == 1 && s[0] == 'o' && ans[N - 1] != ans[1]) f2 = 1;
    if(ans[0] == 1 && s[0] == 'x' && ans[N - 1] == ans[1]) f2 = 1;
    if(f1 && f2) {
      REP(i, 0, N) cout << (ans[i] == 0 ? 'S' : 'W');
      cout << endl;
      return 0;
    }
    cnt++;
    if(cnt == 4) cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	ll N;
	cin >> N;
	ll res = 0;
	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		res += (a - 1);
	}

	cout << res << endl;
	return 0;
}


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

int G[110][110];

int main() {
    int n;
    cin >> n;
    int u, k, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j > 1) cout << " ";
            cout << G[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
string STRINF = "-";
void chmax(string &a, string b) {
    if(a == STRINF) {
        a = b;
    } else if(a.size() < b.size()) {
        a = b;
    } else if((a.size() == b.size()) && a < b)
        a = b;
    {}
}
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.second > b.second;
    }
}
int B[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[11000];

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> ve(M);
    rep(i, 0, M) { cin >> ve[i]; }
    rep(i, 0, 11000) { dp[i] = STRINF; }
    dp[0] = "";
    rep(i, 0, N + 1) {
        if(dp[i] == STRINF) {
            continue;
        }
        rep(r, 0, M) {
            int a = ve[r];
            chmax(dp[i + B[a]], dp[i] + (char)('0' + a));
        }
    }
    cout << dp[N] << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll A, B;
	cin >> A >> B;
	cout << abs(A-B) << endl;
	return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

int main() {
  ll n;
  cin >> n;
  vector< pair<ll, ll> > vc;
  for (ll i=0;i<n;i++){
    ll x, y;
    cin >> x >> y;
    vc.push_back(pair<ll, ll>(y, x));
  }
  sort(vc.begin(), vc.end());
  
  ll time = 0;
  for (ll i=0;i<n;i++){
    ll tmp_a = vc[i].second;
    ll tmp_b = vc[i].first;
    time += tmp_a;
    //cout << tmp_a << " " << tmp_b << " " << time << endl;
    if (time > tmp_b){
      cout << "No" << endl;
      exit(0);
    }
  }
  cout << "Yes" << endl; 
}

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

int main(){
    int b;
    cin >> b;
    vector<int> a(4, 0);
    for(int i = 0; i < 4; i++)
    {
        a[i] = b%10;
        b /= 10;
    }
    reverse(a.begin(), a.end());
    for(int bit = 0; bit < (1<<3); bit++)
    {
        int num=a[0];
        for(int i = 0; i < 3; i++)
        {
            if(bit&(1<<i)){
                num+=a[i+1];
            }
            else{
                num -= a[i+1];
            }
        }
        if(num==7){
            cout <<a[0];
            for(int i = 0; i < 3; i++)
            {
                if(bit&(1<<i)){
                    cout << '+' << a[i+1];
                }
                else{
                    cout << '-' << a[i+1];
                }
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int a[3],b[3];
	bool f[4][2];
	int i;
	for (i = 0; i < 4; i++) {
		f[i][0] = 0;
		f[i][1] = 0;
	}
	for (i = 0; i < 3; i++) {
		cin >> a[i] >> b[i];
		if (!f[a[i] - 1][0])
			f[a[i] - 1][0] = 1;
		else if (!f[a[i] - 1][1])
			f[a[i] - 1][1] = 1;
		else {
			cout << "NO" << endl;
			return 0;
		}

		if (!f[b[i] - 1][0])
			f[b[i] - 1][0] = 1;
		else if (!f[b[i] - 1][1])
			f[b[i] - 1][1] = 1;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

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

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

int h, w;
int cost[1010][1010];

vector<string> mp;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

void solve()
{
  int sy, sx;
  int gy, gx;

  cin >> h >> w;
  cin >> sy >> sx;
  cin >> gy >> gx;

  mp.resize(h);
  sx--; sy--;
  gx--; gy--;
  for(int i = 0; i < h; ++i)
  {
    cin >> mp[i];
  }

  deque<P> que;
  que.push_front(P(sy, sx));
  cost[sy][sx] = 1;

  while(!que.empty())
  {
    int ty = que.front().first;
    int tx = que.front().second;    
    que.pop_front();
    int dist = cost[ty][tx];
    // cout << "--\n" << ty  << " " << tx << " " << dist << ":\n";

    // 徒歩
    for(int i = 0; i < 4; ++i)
    {
      int ny = ty + dy[i];
      int nx = tx + dx[i];
      if (ny < 0 || h <= ny) continue;
      if (nx < 0 || w <= nx) continue;
      if (mp[ny][nx] == '#') continue;
      if (0 < cost[ny][nx] && cost[ny][nx] <= dist) continue;
      cost[ny][nx] = dist;
      que.push_front(P(ny, nx));
      // cout << ny << " " << nx << " " << cost[ny][nx] << endl;
    }

    // 魔法
    for(int y = -2; y <= 2; ++y) for(int x = -2; x <= 2; ++x)
    {
      int ny = ty + y;
      int nx = tx + x;
      if (ny < 0 || h <= ny) continue;
      if (nx < 0 || w <= nx) continue;
      if (mp[ny][nx] == '#') continue;
      if (0 < cost[ny][nx] && cost[ny][nx] <= dist + 1) continue;
      cost[ny][nx] = dist + 1;
      que.push_back(P(ny, nx));
      // cout << ny << " " << nx << " " << cost[ny][nx] << endl;
    }
  }
  /*
  for(int ih = 0; ih < h; ++ih)
  {
    for(int iw= 0; iw < w; ++iw)
    {
      cout << cost[ih][iw];
    }
    cout << endl;
  }
  //*/
  cout << cost[gy][gx] - 1;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int v[n];
    rep(i, 0, n) cin >> v[i];
    sort(v, v + n);
    double ans = v[0];
    rep(i, 1, n) {
        ans = double(ans + v[i]) / 2;
    }
    cout << fixed;
    cout << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int INF = 1e9;

int n,A,B,C;
vector<int> l(8);

int solve(int i,int a,int b, int c){

  if(i == n){
    if(a == 0 || b == 0 || c ==0) return INF;
    else  return abs(a-A)+abs(B-b)+abs(C-c); //ここで合成無しで調節する
  }

  int ans = solve(i+1,a,b,c);
  int adda=0,addb=0,addc=0;

  if(a != 0) adda = 10;
  if(b != 0) addb = 10;
  if(c != 0) addc = 10;
 
  ans = min(solve(i+1,a+l[i],b,c)+adda,ans);
  ans = min(solve(i+1,a,b+l[i],c)+addb,ans);
  ans = min(solve(i+1,a,b,c+l[i])+addc,ans);

  return ans;
}

int main(){
  cin>>n>>A>>B>>C;

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

  cout<<solve(0,0,0,0)<<endl;

  return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();
            int[] memo = new int[51];

            for (int i = 9; i >= 0; i--)
                for (int j = 9; j >= 0; j--)
                    for (int k = 9; k >= 0; k--)
                        for (int l = 9; l >= 0; l--)
                            memo[i + j + k + l]++;

            string input;
            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int n = int.Parse(input);
                sb.AppendLine(memo[n].ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int n = S.size() - 1;
  ll res = 0;
  for (int i = 0; i < (1 << n); i++) {
    ll tmp = S[0] - '0';
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        res += tmp;
        tmp = 0;
      }
      tmp *= 10;
      tmp += S[j + 1] - '0';
    }
    res += tmp;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;


int main(int argc, const char * argv[]) {
    
    string s, t, u;
    int a, b;
    
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    
    if(u == s) a = a - 1;
    else b = b - 1;
    
    cout << a << " " << b << endl;
    
    return 0;
}


Measured memory_bytes: 256
/** */

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

reader.on("line", function (line) {
  lines.push(line);
});
reader.on("close", function () {
  const input = (lines[0] as string).split("");
  const a = +input[0];
  const b = +input[1];
  const c = +input[2];

  let res: number = 0;

  input.forEach((element) => {
    if (element == "1") res++;
  });

  console.log(res);
});


Measured memory_bytes: 7500
# -*- coding: utf-8 -*-
s = input()
K = int(input())

dict_set = set([])


for strlen in range(1,K+1):
    for j in range(len(s)-strlen+1):
        # print(s[j:j+strlen])
        dict_set.add(s[j:j+strlen])

dict_list = sorted(list(dict_set))

print(dict_list[K-1])


Measured memory_bytes: 4592
x1, y1, x2, y2 = map(int, input().split())

a = x2 - x1
b = y2 - y1

x3 = x2 - b
y3 = y2 + a
x4 = x3 - a
y4 = y3 - b

print(f'{x3} {y3} {x4} {y4}')

Measured memory_bytes: 9084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{

    public class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').ToArray();
            var k = int.Parse(nk[1]);
            var h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Console.WriteLine(h.Count(x=>x>=k));
        }
    }
}


Measured memory_bytes: 17376
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int s,w;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe";
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main() {
	int N;
	int A[100010];
	cin >> N;
	pair<int, int> seito[100010];
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		seito[i] = make_pair(A[i], i);
	}
	sort(seito + 1, seito + N + 1);
	for (int i = 1; i <= N; i++) {
		cout << seito[i].second << " ";
	}
}

Measured memory_bytes: 2048
fun main(args: Array<String>) {
    val (r, g, b) = readInputLine().split(" ").map { it.toInt() }
    if ((r * 100 + g * 10 + b) % 4 == 0) {
        println("YES")
    } else {
        println("NO")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 35952
from sys import stdin
import math
import fractions

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
for aa in a:
    count += aa

if n - count < 0:
    print(-1)
else:
    print(n - count)



Measured memory_bytes: 10960
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	char a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		string b;
		for(int l=0;l<i;l++)
		{
			b+=a[l];
		}
		string c;
		for(int l=i;l<n;l++)
		{
			c+=a[l];
		}
		if(b==c)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if( !(a == b && b == c) && !(a != b && b != c && c != a) ){
    cY;
  }
  else{
    cN;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	int tmp = a * 10 + b;
	int tmp2 = c * 10 + d;
	if (1 <= tmp && tmp <= 12) {
		if (1 <= tmp2 && tmp2 <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (1 <= tmp2 && tmp2 <= 12) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

const int INF = 1001001001;

int main() {
  int A,B;
  int a,b,aa,bb;
  cin>>A>>B;
  if(A%2==0){
    a=(A*100)/8;
    aa=a+12;
  }
  else{
    a=(A*100)/8+1;
    aa=a+11;
  }
  b=B*10;
  bb=(B+1)*10-1;
//  printf("%d,%d,%d,%d\n",a,aa,b,bb);
  bool h=false;
  for(int i=a;i<=aa;i++){
    if(i>=b && i<=bb){
      cout<<i<<endl;
      h=true;
      break;
    }
  }
  if(h==false){
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 256
# coding: utf-8
# coding: Shift_JIS
# coding: EUC-JP
# coding: cp932
import math
while 1:
    a,b,c = map(str,input().split())
    a = int(a)
    c = int(c)
    ans = 0
    if b == "?":
        break
    if b == "+":
        ans = a + c
    if b == "-":
        ans = a - c
    if b == "/":
        ans = int(a / c)
    if b == "*":
        ans = a * c
    print(ans)



Measured memory_bytes: 5660
import collections
ans=[]
s=collections.deque()
k=int(input())
ans.append(1)
for i in range(1,k):
    for x in str(ans[i-1]):
        s.append(int(x))
    ls=len(s)-1
    while ls>=0 and s[ls]==9:
        s[ls]=0
        ls-=1
    if ls==-1:s.appendleft(1)
    else:s[ls]+=1
    while True:
        b=-1
        for i in range(0,len(s)-1):
            if abs(s[i+1]-s[i])>1:
                b=i
                break
        if b==-1:break
        if s[b+1]>s[b]:s[b]+=1
        l=max(s[b]-1,0)
        for i in range(b+1,len(s)):
            s[i]=l
            l=max(l-1,0)
    #print(s)
    t=0
    while len(s)>=1:
        x=s.popleft()
        #print("*",x)
        t=t*10+x
    ans.append(t)
print(ans[k-1])















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

int main(){
	/*入力*/
	int n;
	cin >> n;
	int* v = new int [n];
	int* c = new int [n]; 
	for(int i = 0;i < n;i++){
		cin >> v[i];
	} 
	for(int i = 0;i < n;i++){
		cin >> c[i];
	}

	/*計算*/
	int* v_c=new int [n];	//価値ーコストの一覧
	for(int i = 0; i < n; i++){
		v_c[i] = v[i] - c[i];
	}
	int o = 0;				//出力値
	bool _flag = false;		//false:全て正か負が多少　true:全て負 
	for(int i = 0; i<n; i++){
		(v_c[i] >= 0)?_flag=false:_flag=true;
      	if(_flag == false)break;
	}
	if(_flag){
		o = 0;	//選ばない
	}else{
		for(int i = 0; i < n; i++){
			if(v_c[i] >= 0){
				o+=v_c[i];
			}
		}
	}

	/*出力*/
	cout << o << endl;
	

	delete[] v;
	delete[] c;
	delete[] v_c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-7;

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  double bot = 0, top = 90, mid;
  while (top - bot > EPS) {
    mid = (bot + top) / 2;
    double t = a * tan(mid / 180 * M_PI);
    double s = t <= b ? a * b - a * t / 2 : b * (b * tan((90 - mid) / 180 * M_PI)) / 2;
    if (s < x) {
      top = mid;
    } else {
      bot = mid;
    }
  }
  cout << fixed << setprecision(7);
  cout << bot << endl;
}


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

using namespace std;
using ll = long long;

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

	ll prev = 1000000000;
	int cnt = -1;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ll H;
		cin >> H;
		if (prev >= H) {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
		prev = H;
	}

	ans = max(ans, cnt);
	cout << ans << endl;
	return 0;
}


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

const long Day_num = 365;
const long type_num = 26;

class Scoring {
public:
    Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives);
    std::vector<long> score(const std::vector<long>& arg_types);
private:
    long days;
    std::vector<long> costs;
    std::vector<std::vector<long>> incentives;
};

std::vector<long> Scoring::score(const std::vector<long>& arg_types) {
    std::vector<long> result(days);
    long satisfy = 0;
    std::vector<long> last_days(type_num, 0);


    for (long day = 1; day <= days; ++day) {
        const auto exe_type = arg_types[day-1];
        satisfy += incentives[day-1][exe_type-1];
        last_days[exe_type-1] = day;
        for (long type = 1; type <= type_num; ++type) {
            satisfy -= costs[type-1] * (day - last_days[type-1]);
        }
        result[day-1] = satisfy;
    }
    return result;
}

Scoring::Scoring(const long arg_days, const std::vector<long>& arg_costs, const std::vector<std::vector<long>>& arg_incentives) {
    days = arg_days;
    costs = arg_costs;
    incentives = arg_incentives;
}

int main() {
    long D;
    std::cin >> D;
    std::vector<long> costs(type_num);
    for (long type = 1; type <= type_num; ++type) {
        std::cin >> costs[type-1];
    }
    std::vector<std::vector<long>> incentives(D, std::vector<long>(type_num));
    for (long day = 1; day <= D; ++day) {
        for (long type = 1; type <= type_num; ++type) {
            std::cin >> incentives[day-1][type-1];
        }
    }
    std::vector<long> types(D);
    for (long day = 1; day <= D; ++day) {
        std::cin >> types[day-1];
    }

    long M;
    std::cin >> M;

    std::vector<std::array<long,2>> query(M);
    for (long index = 0; index < M; ++index) {
        std::cin >> query[index][0];
        std::cin >> query[index][1];
    }

    Scoring scoring(D, costs, incentives);
    for (long index = 0; index < M; ++index) {
        types[query[index][0]-1] = query[index][1];
        std::cout << scoring.score(types).back() << std::endl;
    }
}

Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
    ll x;
    cin>>x;
    ll a=0,b,c;
    bool ans=true;
    b=x%100;
    for(ll i=5;i>0;i--){
      //cout<<i<<" "<<a<<" "<<b<<endl;
      a+=b/i;
        c=b%i;
        b=c;
    }
    if(a<=x/100)cout<<"1"<<endl;
    else cout<<"0"<<endl;
}

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

long long int min(long long int a, long long int b){
	if(a<b) return a;
  return b;
}



int main(){
 long long int n;
  cin>>n;
 long long int a[100000 + 1];
  a[0] = 0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  
  long long int b[100000+1] = {0};
  b[2] = b[1] + abs(a[2] - a[1]);
  for(int i=3;i<=n;i++){
    b[i] = min(b[i-1] + abs(a[i] - a[i-1]), b[i-2] + abs(a[i] - a[i-2]));  
  }
  cout<<b[n]<<endl;
  return 0;
}

Measured memory_bytes: 1792
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<bool> can_win(K + 1, false);
  for (int64_t k = 0; k <= K; ++k) {
    for (int64_t i = 0; i < N; ++i) {
      const int64_t prev_k = k - A[i];
      if (prev_k >= 0) {
        if (!can_win[prev_k]) {
          can_win[k] = true;
          break;
        }
      }
    }
  }
  if (can_win[K]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

map<long long, long long> mp;

void prime_factor(long long n) {    
    for(long long i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1) mp[n]++;
    //for(auto c : mp) cout << c.first << " " << c.second << endl;
}

int main() {
    long long n;
    cin >> n;
    ll ans = 0;
    vector<int> v = {1,3,6,10,15,21,28,36};
    prime_factor(n);
    for(auto c : mp) {
        int ite;
        for(int i = 0; i < 8; i++) {
            if(v[i] <= c.second) {
                ite = i+1;
            }
        }
        ans += ite;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3628
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    let (N, M) = read!(usize, usize);
    let T = read![usize, usize, i64; M];

    let mut b = vec![];
    for &(l, r, _) in &T {
        b.push(l);
        b.push(r);
    }
    b.push(N);
    b.sort();
    b.dedup();

    let mut G = vec![vec![]; N + 1];
    for &(l, r, c) in &T {
        G[l].push((r, c));
    }

    for w in b.windows(2) {
        G[w[1]].push((w[0], 0));
    }

    // dyijkstra
    let mut dist = vec![std::i64::MAX; N + 1];
    let mut q: BinaryHeap<(Rev<i64>, usize)> = BinaryHeap::new();

    dist[1] = 0;
    q.push((Rev(0), 1));
    while let Some((Rev(d), u)) = q.pop() {
        for i in 0..G[u].len() {
            let (v, c) = G[u][i];
            if d + c < dist[v] {
                dist[v] = d + c;
                q.push((Rev(d + c), v));
            }
        }
    }

    if dist[N] == std::i64::MAX {
        println!("-1");
    } else {
        println!("{}", dist[N])
    }
}


Measured memory_bytes: 22780
#include <cstdio>

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

Measured memory_bytes: 1048
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		k: usize,
		a: [usize; n],
	}

	for i in k..n {
		if a[i-k] < a[i] {
			println!("Yes");
		}
		else {
			println!("No");
		}
	}
}



Measured memory_bytes: 5660
#include<stdio.h>
#include<math.h>
int main(void){
	int n, last, i, j = 0, s[1000], total_score = 0;
	double avg, sum = 0.0, std_dev[1000];
	do{
		scanf("%d\n", &n);
		if(n == 0){
			break;
		}
		last = n-1;
		for(i = 0; i < n; i++){
			if(i == last){
				scanf("%d\n", &s[i]);
			}else{
				scanf("%d ", &s[i]);
			}
			total_score += s[i];
		}
		avg = (double)total_score/n;
		for(i = 0; i < n; i++){
			sum += pow((s[i]-avg), 2);
		}
		std_dev[j] = sqrt(sum/n);
		total_score = 0;
		sum = 0.0;
		j++;
	}while(1);
	for(int k = 0; k < j; k++){
		printf("%f\n", std_dev[k]);
	}
	return 0;
}


Measured memory_bytes: 2056
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

class Pair<F, S>{
	public final F first;
	public final S second;

	public Pair (F first, S second) {
		this.first = first;
		this.second = second;
	}

}
class Graph{
	final int INF = Integer.MAX_VALUE/2;
	private int V,E;
	LinkedList<Pair<Integer, Integer>>[] edges;
	@SuppressWarnings("unchecked")
	public Graph(int v,int e){
		this.V = v; this.E = e;
		edges = new LinkedList[V];
	}

	public int[] dijkstra(int s){
		int[] d = new int[V];
		boolean[] used = new boolean[V];
		Arrays.fill(used,false);
		Arrays.fill(d,INF);
		d[s]=0;

		PriorityQueue<Pair<Integer, Integer>> que=new PriorityQueue<Pair<Integer, Integer>>(new Comparator<Pair<Integer, Integer>>() {
			public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {
				return o1.second - o2.second;
			}
		});

		que.add(new Pair<Integer, Integer>(s, 0));
		while(!que.isEmpty()){
			Pair<Integer, Integer> now = que.poll();
			int point = now.first;
			if(used[point]) continue;
			used[point]=true;
			for(Iterator<Pair<Integer, Integer>> it = edges[point].iterator(); it.hasNext();) {
				Pair<Integer, Integer> next = it.next();
				if(!used[next.first] && d[next.first] > d[point] + next.second) {
					d[next.first] = d[point] + next.second;
					que.add(new Pair<Integer, Integer>(next.first, d[next.first]));
				}
			}
		}
		return d;
	}
}
class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int N = sc.nextInt(), M = sc.nextInt();
			Graph g = new Graph(N, M);
			for(int i = 0; i < N; i++) {
				g.edges[i] = new LinkedList<Pair<Integer, Integer>>();
			}
			for(int i = 0; i < M; i++) {
				int s = sc.nextInt();
				int t = sc.nextInt();
				g.edges[s - 1].add(new Pair<Integer, Integer>(t - 1, 1));
				g.edges[t - 1].add(new Pair<Integer, Integer>(s - 1, 1));
			}
			int[] ans = g.dijkstra(0);
			if(ans[N - 1] <= 2) {
				System.out.println("POSSIBLE");
			}
			else {
				System.out.println("IMPOSSIBLE");
			}
		}
	}
}

Measured memory_bytes: 161968
#include<iostream>
#include<cmath>
#include<string>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    int64_t n;
    cin>>n;
    int64_t num=0,a=0,b=0,c=0;
    if(n>=500)
         a=n/500;
    num=num+a*1000;
    b=n%10;
    c=n-a*500;
    if(b>=5)
        num=num+c+(5-b) ;
    else
        num=num+c-b;
        //cout<<a<<" "<<b<<" "<<c<<endl;
    cout<<num<<endl;
    return 0;
}


Measured memory_bytes: 256
a,b,k=map(int,input().split())
i=0

aa=a
bb=b
if a>=1:
  a-=k
  k-=aa
if b>=1 and k>0:
  b-=k
  k-=bb

if a<0:
  a=0
if b<0:
  b=0
print(a,b)


Measured memory_bytes: 61732
#include<stdio.h>
int main()
{
int n,i;
  scanf("%d",&n);
  long long int a[n],sum,ans,mod;
  mod=1000000007;
  sum=0;
  ans=0;
  for(i=0;i<n;++i)
  {
  scanf("%lld",&a[i]);
  sum=sum+a[i];
  }
  for(i=0;i<n;++i)
  {
  sum=sum-a[i];
  ans=(ans+a[i]*(sum%mod))%mod;
  }

  printf("%lld",ans);
return 0;}

Measured memory_bytes: 3176
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>

using namespace std;

int N;
int M;
long long ans=0;

/*
int binarySearch(int t){
    int lo=0,hi=N-1;
    int te;
    while(true){
        int m=(lo+hi)/2;
        if(P[m]<t){
            hi=(m-1)<=1?0:m-1;
        }else if(P[m]>t){
            lo=m+1;
        }
        if(lo>=hi){
            te=hi;
        }
    }
    return te;
}*/
/*
void func(int dart,long long sum,long long index){
    ans=max(ans,sum);
    if(dart==4)return ;
    long long s=M-sum;
    auto itF = (P.begin()+index);
//    auto itF = P.begin();
//    advance(itF,index);
    
    auto it = upper_bound(P.begin(),itF,s);
    it = prev(it);

    
    for(auto i=it;i!=P.begin();i--){
        func(dart+1,sum+*i,distance(P.begin(),i));
    }
    
 
    if(sum+P[n]<=M){
        func(n-1,dart+1,sum+P[n]);
        func(n,1+dart,sum+P[n]);
        func(n-1,dart,sum);
    }
    else {
        func(n-1,dart,sum);
    }
 
    
    return ;
}
*/

vector<long long>P;
int main(){
    while(cin>>N>>M,N,M){
        P = vector<long long>(N+1,0);
        for(int i=0;i<N;i++){
            cin>>P[i];
        }
        
        vector<long long> v;
        for(int i=0;i<N+1;i++){
            for(int j=0;j<N+1;j++){
                if(P[i]+P[j]<=M)v.push_back(P[i]+P[j]);
            }
        }
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        for(int i=0;i<v.size();i++){
            long long ind = upper_bound(v.begin(),v.end(),M-v[i])-v.begin();
            ans = max(ans,v[i]+v[ind-1]);
        }
        cout<<ans<<endl;
        ans=0;
    }
    return 0;
    
}
//574 999424


Measured memory_bytes: 18972
import java.util.Scanner;

//atcoderはScannerクラスのsc.next()で行ける
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        if (str.substring(str.length() - 1).toLowerCase().equals("s")) {
            System.out.println(str + "es");
        } else {
            System.out.println(str + "s");
        }
    }
}

Measured memory_bytes: 38440
#include <iostream>
#include <map>
#include <unordered_map>
#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323

using namespace std;


ll dp[110][100010];

ll solve(vector< pair<ll,ll> > &v, ll n, ll w)
{
    if(dp[n][w]!=-1) return dp[n][w];
    if(n==0 || w==0) return 0;
    ll one=0,two=0;

    if(v[n-1].F<=w)  one=v[n-1].S+solve(v,n-1,w-v[n-1].F);
    two=solve(v,n-1,w);

    return dp[n][w]=max(one,two);
}


int main()
{
    fio;
    memset(dp,-1,sizeof(dp));
    ll x,y,n,w,ans=0;
    cin>>n>>w;
    vector< pair<ll,ll> > v(n);
    for(ll i=0;i<n;i++){
        cin>>x>>y;
        v[i]=mp(x,y);
    }
    ans=solve(v,n,w);
    cout<<ans<<"\n";

return 0;
}


Measured memory_bytes: 89600
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())

    n = N % K
    print(min(n, K - n))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61840