akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace abc134_c
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var a = new int[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = Console.ReadLine().ToInteger();
            }

            var max = a.OrderByDescending(m => m).Take(2).ToArray();

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] != max[0])
                {
                    Console.WriteLine($"{max[0]}");
                }
                else
                {
                    Console.WriteLine($"{max[1]}");
                }
            }
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }
    }
}


Measured memory_bytes: 21824
fun main(args: Array<String>) {
    val (T,A,K) = readLine()!!.split(" ").map { it.toLong() }
    if (T+A <= K){
        println("0 0")
    }else {
        if (T < K){
            println("0 ${A-(K-T)}")
        }else{
            println("${T-K} $A")
        }
    }

}

Measured memory_bytes: 37992
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=100000000,cnt=0;
	sort(a,a+n);
	for(int i=a[0];i<=a[n-1];i++){
		for(int j=0;j<n;j++){
			cnt+=pow(i-a[j],2);
		}
		if(ans>cnt){
			ans=cnt;
		}
		cnt=0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(i!=minj){
      swap(A[i],A[minj]);
      ans++;
    }
  }
  for(int i=0;i<n;i++) cout<<A[i]<<" \n"[i==n-1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3072
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
getcontext().prec = 400
N=int(input())
A=list(map(int,input().split()))
if 0 in A:
    print(0)
    exit()
i=1
a=10**18
#print(A)
for n in A:
    #print(i,n)
    i*=n
    #print(i)
    if i>a:
        print(-1)
        exit()
print(i)


Measured memory_bytes: 22968
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
S = input()
if S[:N//2] == S[N//2:]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 4460
bingo = 3.times.map{gets.split.map(&:to_i)}
_b = gets.to_i.times.map{gets.to_i}

(0..2).each do |i|
  (0..2).each do |j|
    bingo[i][j] = 0 if _b.include?(bingo[i][j])
  end
end

result = false
(0..2).each do |i|
  result ||= (0..2).all? { |j| bingo[i][j] == 0 }
end
(0..2).each do |i|
  result ||= (0..2).all? { |j| bingo[j][i] == 0 }
end

result ||= (0..2).all? { |i| bingo[i][i] == 0 }
result ||= (0..2).all? { |i| bingo[2 - i][i] == 0 }

puts result ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

bool check(string str, char d[10], int k){
    rep(i,k){
        rep(j,str.size()){
            if(str[j] == d[i]) return false;
        }
    }
    return true;
}

string changeStr(int n, int len){
    string str;
    int K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

int main(){
    int n,k;
    char d[10];
    cin >> n >> k;
    rep(i,k){
        cin >> d[i];
    }
    while(true){
        if(check(changeStr(n, static_cast<int>(log10(n))), d, k)){
            cout << n << endl;
            break;
        }else{
            n++;
        }
    }
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << endl;
  return 0;
}

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

vector<int> parent, len;

int find(int n)
{
    if(parent[n] == n)
    return n;
    return parent[n] = find(parent[n]);
}
void add(int u, int v)
{
    int a = find(u);
    int b = find(v);
    if(a == v)
        return;
    if(len[b] > len[a])
        swap(a, b);
    len[a] += len[b];
    parent[b] = a;
}
int main()
{
    int n, m;
    cin >> n >>m;
    parent.resize(n+1);
    len.assign(n+1, 1);
    for(int i= 1;i <=n;i++){
        parent[i] = i;
    }
    for(int i = 0;i < m;i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        add(x, y);
    }
    set<int> unique;
    for(int i = 1;i<=n;i++)
    {
        unique.insert(find(i));
    }
    cout << unique.size();
    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define  ll    long long int
using namespace std;


int main()
{
    int d,n,p,k;
    cin>>d>>n;
    if(d==0)
    {
        if(n<=99)cout<<n<<endl;
        else if(n==100)cout<<n+1<<endl;
    }
    else if(d==1)
    {
         if(n<=99)cout<<n*100<<endl;
        else if(n==100)cout<<n*100+100<<endl;
    }
    else
    {
         if(n<=99)cout<<n*10000<<endl;
        else if(n==100)cout<<(n+1)*10000<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*********************************
Date: Sat Mar 10 17:16:33 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int main()
{
	scanf("%s",s);
	int ans = strlen(s);
	int len = ans;
	for (int i=1;s[i];++i){
		if (s[i-1] != s[i]){
			ans = min(ans,max(i,len-i));
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define vpli vector<pair<long long,int>>
#define deb(x) cout<<x<<endl;
ll MOD = 1e9+7;
void solve()
{
    char c;
    cin>>c;
    cout<<(isupper(c)?'A':'a');
}
int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi; 
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back
#define ins insert
#define del erase
#define inf INT_MAX

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int main() 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a = 1 ;
	while(a--)
	{
		int n ;
		cin >> n ;
		int w ;
		cin >> w ;
		ll wt[n],v[n]; 
		F0R(i,n)
		{
			cin >> wt[i] ;
			cin >> v[i] ;
		}
		ll ans[n+1][w+1];
		F0R(j,w+1)
		{
			F0R(i,n+1)
			{
				if(i==0||j==0)
				{
					ans[i][j]=0;
				}
				else if(wt[i-1]<=j)
				{
					ans[i][j]=max(ans[i-1][j],v[i-1]+ans[i-1][j-wt[i-1]]);
				}
				else
				{
					ans[i][j]=ans[i-1][j];
				}
			}
		}
		cout << ans[n][w] << endl;
			
			
		
		
			
		
	}	
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        cout << 'x';
    }
    cout << endl;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;

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

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


const string str = "abcdefghij";

int N;

set<string> st;

void connectS(int count, string s, int mx)
{
  count++;
  for(int i=0; i<mx+2; i++)
    {
      if(count==N)
	{
	  st.insert(s+str[i]);
	}
      else
	{
	  
	  connectS(count, s+str[i], (mx<i)?i:mx);
	}
    }
  return;
}

int main()
{
  cin >> N;
  
  connectS(0, "", -1);

  for(auto a: st)
    cout << a << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count


Measured memory_bytes: 12416
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
N,M = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
ansN = 0
ansM = 0
if N <= 1:
    ansN = 0
for i in range(1,N):
    ansN += i
if M <= 1:
    ansM = 0
for i in range(1,M):    
    ansM += i
print(ansN+ansM)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {

	private static final int mod =(int)1e9+7;
	public static void main(String[] args) throws Exception  {
	      Scanner  sc=new Scanner(System.in);
	      PrintWriter out=new PrintWriter(System.out);
	      String a=sc.next(),b=sc.next(),c=sc.next();
	      if(a.charAt(a.length()-1)==b.charAt(0)&&b.charAt(b.length()-1)==c.charAt(0)) {
	        System.out.println("YES");
	      }else {
	        System.out.println("NO");
	      }

	}


	static boolean vis[]=new boolean[10001];
	      static long gcd(long a, long b) 
	      { 
	          if (a == 0) 
	              return b; 
	          return gcd(b % a, a); 
	      } 

static long nCr(int n,int r) {
  int dp[][]=new int[2001][2001];
  for(int i=0;i<2001;i++) {
    dp[0][i]=0;
  }
  for(int i=0;i<2001;i++) {
    dp[i][0]=1;
  }
  for(int i=1;i<2001;i++) {
    for(int j=1;j<2001;j++) {
      if(i==j) {
        dp[i][j]=1;
      }else {
        dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
      }
    }
  }
  return dp[n][r];
}
      
}

Measured memory_bytes: 35624
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'o')ans += 100;
	}
	ans += 700;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define all(a) a.begin(), a.end()

const int MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<ll> A(60);
    long long num;
    rep(i, 0, N){
        cin >> num;
        rep(j, 0, 60){
            if ((num>>j)&1){
                A[j]++;
            }
        }
    }
    ll ans = 0, base = 1;
    rep(i, 0, 60){
        ll add = (N - A[i]) * A[i] % MOD * base % MOD;
        ans = (ans + add) % MOD;
        base = (2 * base) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(H: int, W: int, s: "List[str]"):
    x=y=0
    k=1 if s[y][x]=="#" else 0
    dt=[[999]*W for _ in range(H)]
    dt[y][x]=1 if s[y][x]=="#" else 0
    for y in range(H):
        for x in range(W):
            if y>0:
                dt[y][x]=min(dt[y][x], dt[y-1][x]+(1 if s[y][x]!=s[y-1][x] else 0))
            if x>0:
                dt[y][x]=min(dt[y][x], dt[y][x-1]+(1 if s[y][x]!=s[y][x-1] else 0))
    print((dt[H-1][W-1]+1)//2)
    #print("#",s,dt)
    """
    for i in range(H+W-2):
        if y<H-1 and s[y][x]==s[y+1][x]:
            y+=1
        elif x<W-1 and s[y][x]==s[y][x+1]:
            x+=1
        else:
            print(x,y,k+1)
            k+=1
            if x<W-1:
                x+=1
            else:
                y+=1
    print(k,(k+1)//2)
    """
    return
        
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<iosfwd>
#include<sstream>
#include<math.h>
#define N 100
using namespace std;

int main(void){
    int n;
    cin >> n;
    int cnt=0;
    vector<int> h(n,0);
    int max= 0;
    for(int i=0; i<n; i++){
        cin >> h[i];
        if(max<=h[i]){
            max= h[i];
            cnt++;
        }
    }
    cout << cnt <<endl;
}

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

vector<ll> cost(10000, INT64_MAX / 2);
vector<bool> neg(10000, false);
vector<vector<ll>> edge(10000);

int main(){
	ll N, M, a, b, c;
	cin >> N >> M;

	for (int i = 0;i < M;i++) {
		cin >> a >> b >> c;
		edge[i] = { a,b,-c };
	}

	cost[1] = 0;

	//ベルマンフォード法
	for (int j = 0;j <= N;j++) {
		for (int i = 0;i < M;i++) {
			if (cost[edge[i][1]] > cost[edge[i][0]] + edge[i][2]) {
				cost[edge[i][1]] = cost[edge[i][0]] + edge[i][2];
			}
		}
	}

	//「経路上にある」負閉路を検出します

	for (int i = 0;i < M;i++) {
		if (cost[edge[i][1]] > cost[edge[i][0]] + edge[i][2]) {
			neg[edge[i][1]] = 1;
		}
	}
	for (int j = 0;j <= N;j++) {
		for (int i = 0;i < M;i++) {
			if (neg[edge[i][0]]) {
				neg[edge[i][1]] = 1;
			}
		}
	}

	if (neg[N])
		cout << "inf" << endl;
	else
		cout << -cost[N] << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    rep(i, n) {
        cin >> w[i];
        sum += w[i];
    }
    int mn = INF;
    for(int i = 0; i < n; ++i){
        int a = 0;
        rep(j, i){
            a += w[j];
        }
        int b = sum-a;
        mn = min(mn, abs(a-b));
    }

    ppp(mn);




    return 0;
}


Measured memory_bytes: 256
object Main{
  def main(args: Array[String]): Unit = {
    //n <- 本数  k <- 火をつける数
    val Array(n, k) : Array[Int] = io.StdIn.readLine().split(' ').map(_.toInt)
    val candles = io.StdIn.readLine().split(' ').map(_.toInt)
    println(sunukeSetFire(n,k,candles))
  }

  /** 距離を計算する */
  def calcDistance(l:Int, r:Int) : Int = {
    if(l >= 0 && r >= 0) Math.max(l,r)
    else if(l <= 0 && r <= 0) Math.min(l,r).abs
    else if(l.abs < r) (l*2).abs + r.abs
    else l.abs + (r*2).abs
  }

  /**
    * 0以上になるときのindexを返す
    * 0以上がないときは最後のindexを返す
    */
  def getFirstIndexGreaterThanZero(candle: Seq[Int]) ={
    candle.zipWithIndex.find(_._1 >=0).map(_._2).getOrElse(candle.length-1)
  }

  /** すぬけが火を放った */
  def sunukeSetFire(n:Int, k:Int, candles: Seq[Int]):Int ={
    var distances : List[Int] = Nil
    var index = (getFirstIndexGreaterThanZero(candles) - (k-1))
    val maxIndex = index + k + k
    index = index match {
      case num if(num >= 0) => num
      case _ => 0
    }

    //indexがリストの最大かmaxIndexになるまでループ
    while(index + k <= n && index + k <= maxIndex){
      val l = candles(index)
      val r = candles(index + k -1)
      distances = calcDistance(l,r) :: distances
      index += 1
    }
    distances.min
  }
}

Measured memory_bytes: 44664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(culcDifference(a, c) > d) {
			if(culcDifference(a, b) > d || culcDifference(c, b) > d ) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

	
	public static int culcDifference(int a,int b) {
		if(a > b) return a-b;
		else return b-a;
	}
}



Measured memory_bytes: 21844
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9323372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,L=LI()

LG=10**15
DIST=[[LG for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    a,b,c = LI()
    if c <= L:
        DIST[a][b] = c
        DIST[b][a] = c

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(1, N+1):
    for j in range(1, N+1):
        DIST[i][j] = 1 if DIST[i][j] <= L else LG

for k in range(1, N+1):
    for i in range(1, N+1):
        for j in range(1, N+1):
            if DIST[i][j] > DIST[i][k] + DIST[k][j]:
                DIST[i][j] = DIST[i][k] + DIST[k][j]

for i in range(II()):
    st, en = LI()
    if DIST[st][en] >= LG:
        print(-1)
    else:
        print(DIST[st][en] - 1)


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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

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


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    unordered_map<ll, ll> m;
    ll ans = 0;
    rep(i, 0, n){
        cin >> a[i];
        m[a[i]]++;
    }
    for(pair<ll, ll> element : m){
        ll tmp = element.second;
        ans += tmp * (tmp - 1) / 2;
    }
    rep(i, 0, n){
        ll d = m[a[i]];
        if(d >= 2){
            cout << ans - (d * (d - 1) / 2) + ((d - 1) * (d - 2) / 2) << endl;
        }else{
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 9160
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    long q = long.Parse(Console.ReadLine());
    for(long i = 0; i < q; i++)
    {
      bool answer = false;
		  string[] input = Console.ReadLine().Split(' ');
      Vector2 vecA = new Vector2(decimal.Parse(input[0]), decimal.Parse(input[1]));//受け取った入力をdecimalに変換
      Vector2 vecB = new Vector2(decimal.Parse(input[2]), decimal.Parse(input[3]));
      Vector2 vecAsub = new Vector2(decimal.Parse(input[4]), decimal.Parse(input[5]));
      Vector2 vecBsub = new Vector2(decimal.Parse(input[6]), decimal.Parse(input[7]));

      if(Vector2.WhereVector(vecA, vecB, vecAsub) + Vector2.WhereVector(vecA, vecB, vecBsub) == 3
        && Vector2.WhereVector(vecAsub, vecBsub, vecA) + Vector2.WhereVector(vecAsub, vecBsub, vecB) == 3)
          answer = true;
      if(Vector2.WhereVector(vecA, vecB, vecAsub) == 5 || Vector2.WhereVector(vecA, vecB, vecBsub) == 5
        || Vector2.WhereVector(vecAsub, vecBsub, vecA) == 5 || Vector2.WhereVector(vecAsub, vecBsub, vecB) == 5)
          answer = true;
      Console.WriteLine((answer) ? "1" : "0");
    }

	}
}

class Vector2//2次元ベクトル
{
static decimal EPS = 1e-10m;//小数誤差比較

  public Vector2 (decimal X, decimal Y)
  {
    this.x = X;
    this.y = Y;
  }

  public decimal x {private set; get;}
  public decimal y {private set; get;}

  public static Vector2 operator + (Vector2 ob1, Vector2 ob2)//ベクトルの基本演算
  {
    return new Vector2 (ob1.x + ob2.x, ob1.y + ob2.y);
  }
  public static Vector2 operator - (Vector2 ob1, Vector2 ob2)
  {
    return new Vector2 (ob1.x - ob2.x, ob1.y - ob2.y);
  }
  public static Vector2 operator * (Vector2 ob, decimal scalar)
  {
    return new Vector2 (ob.x * scalar, ob.y * scalar);
  }
  public static Vector2 operator * (decimal scalar, Vector2 ob)
  {
    return new Vector2 (ob.x * scalar, ob.y * scalar);
  }

  public decimal Length()//ベクトルの長さ
  {
    return x * x + y * y;
  }
  public static decimal DotProduct(Vector2 ob1, Vector2 ob2)//内積
  {
    return ob1.x * ob2.x + ob1.y * ob2.y;
  }
  public static decimal CrossProduct(Vector2 ob1, Vector2 ob2)//外積。第2引数が反時計回り側で正。
  {
    return ob1.x * ob2.y - ob1.y * ob2.x;
  }

  public static Vector2 Projection(Vector2 beginPoint, Vector2 endPoint, Vector2 point)//点の射影
  {
    Vector2 segment = endPoint - beginPoint;
    decimal ratio = Vector2.DotProduct(point - beginPoint, segment) / segment.Length();
    return beginPoint + segment * ratio;//始点にたす
  }

public static long WhereVector(Vector2 beginPoint, Vector2 endPoint, Vector2 point)
  {//ベクトルに対する点の位置
    Vector2 segment = endPoint - beginPoint;
    Vector2 aimVec = point - beginPoint;
    if(Vector2.CrossProduct(segment, aimVec) > EPS)
      return 1;//反時計回り側
    else if(Vector2.CrossProduct(segment, aimVec) < -EPS)
      return 2;//時計回り側
    else if(Vector2.DotProduct(segment, aimVec) < -1+EPS)
      return 3;//ベクトル反対向きの側
    else if(segment.Length() < aimVec.Length())
      return 4;//ベクトル向きの側
    else
      return 5;//ベクトル上
  }
}



Measured memory_bytes: 17936
#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<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N, X, T;
	cin >> N >> X >> T;
	cout << (N / X + bool(N % X)) * T << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

#define INF 10000000

using namespace std;

int n;  //支払額
int coin[4];    //各所持枚数
int mcoin[4];
int m;
int mi;
bool flag = false;

int chng(int k, int bi){
    int cnt = 0; 
    while(k / 500){
        if(bi & (1<<3)) {
            //cout << " a " << k << " " << bi << endl;
            return INF;
        }
        k -= 500;
        cnt++;
    }
    while(k / 100){
        if(bi & (1<<2)) return INF;
        k -= 100;
        cnt++;
    }
    while(k / 50){
        if(bi & (1<<1)) return INF;
        k -= 50;
        cnt++;
    }
    while(k / 10){
        if(bi & (1<<0)) return INF;
        k -= 10;
        cnt++;
    }
    
    return cnt;
}

int main(){
    
    while(cin >> n, n){
        //input
        for(int i = 0; i < 4; i++) cin >> coin[i];
        mi = 1000000;
        int bi = 0;
        for(int a = 0; a <= coin[0]; a++){
            if(a) bi |= 1;
            for(int b = 0; b <= coin[1]; b++){
                if(b) bi |= 1<<1;
                else bi &= ~(1<<1);
                for(int c = 0; c <= coin[2]; c++){
                    if(c) bi |= 1<<2;
                    else bi &= ~(1<<2);
                    for(int d = 0; d <= coin[3]; d++){
                        if(d) bi |= 1<<3;
                        else bi &= ~(1<<3);
                        int sum;
                        if((sum = a*10 + b*50 + c*100 + d*500) >= n){
                            m = coin[0] + coin[1] + coin[2] + coin[3] - a - b - c - d;
                            m += chng(sum - n, bi);
                            if(mi > m){
                                mi = m;
                                mcoin[0] = a;
                                mcoin[1] = b;
                                mcoin[2] = c;
                                mcoin[3] = d;
                                //cout << mi << ' ' << a << ' ' << b << ' ' << c << ' ' << d << ' ' << endl;
                            }
                        }
                    }
                }
            }
        }
        
        
        //output
        if(flag) cout << endl;
        if(mcoin[0])cout << 10 << ' ' << mcoin[0] << endl;
        if(mcoin[1])cout << 50 << ' ' << mcoin[1] << endl;
        if(mcoin[2])cout << 100 << ' ' << mcoin[2] << endl;
        if(mcoin[3])cout << 500 << ' ' << mcoin[3] << endl;
        flag = true;
    }
    
    return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]), b = int.Parse(s[1]);
            int ans;
            if (a == b) ans = a * 2;
            else ans = Math.Max(a, b) * 2 - 1;
            Console.WriteLine(ans);

            
            

            
            


            
        }
    }
    //mcs Main.cs
    //mono Main.exe

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

double area(double a, double l) {
  return a * sqrt(l * l - a * a / 4.0) / 2.0;
}

int main() {
  int a, l, x;
  while (cin >> a >> l >> x) {
    double ans = area(a, l) + 2 * area(l, (l + x) / 2.0);

    printf("%.10f\n", ans);
  }
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
//const auto INF  = 0x3f3f3f3f;
const int N = 1e5+5;

struct node {
    int x, y;
    int id1, id2, id;
}maps[N], ans[N*2];

bool cmp1(const struct node &u, const struct node &v) {
    return u.x < v.x;
}

bool cmp2(const struct node &u, const struct node &v) {
    return u.y < v.y;
}

bool cmp3(const struct node &u, const struct node &v) {
    return u.x < v.x;
}

int pre[N];

int find(int x) {
    int r, i, j;
    r = x;
    while(pre[r] != r) {
        r = pre[r];
    }
    i = x;
    while(pre[i] != r) {
        j = pre[i];
        pre[i] = r;
        i = j;
    }
    return r;
}

bool mx(int x, int y) {
    int fx = find(x);
    int fy = find(y);
    if(fx != fy) {
        pre[fx] = fy;
        return true;
    }
    return false;
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        scanf("%d%d", &maps[i].x, &maps[i].y);
        maps[i].id = i;
        pre[i] = i;
    }
    sort(maps+1, maps+1+n, cmp1);
    int cnt = 0;
    for(int i=2; i<=n; i++) {
        ans[++cnt].x = maps[i].x - maps[i-1].x;
        ans[cnt].id1 = maps[i].id;
        ans[cnt].id2 = maps[i-1].id;
    }
    sort(maps+1, maps+1+n, cmp2);
    for(int i=2; i<=n; i++) {
        ans[++cnt].x = maps[i].y - maps[i-1].y;
        ans[cnt].id1 = maps[i].id;
        ans[cnt].id2 = maps[i-1].id;
    }
    sort(ans+1, ans+1+cnt, cmp3);
    int k = 0;
    LL answer = 0;
    for(int i=1; i<=cnt; i++) {
        if(mx(ans[i].id1, ans[i].id2)) {
            k++;
            answer += ans[i].x;
            if(k == n-1)
                break;
        }
    }
    
    printf("%lld\n", answer);
}











Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    if(N % 2 == 0) {
        ll ret = 0;
        for(int i = 0;i < N;i++) {
            if(i < N / 2 - 1) {
                ret += vec.at(i) * 2;
            }
            else if(i == N / 2 - 1) {
                ret += vec.at(i);
            }
            else if(i == N / 2) {
                ret -= vec.at(i);
            }
            else {
                ret -= vec.at(i) * 2;
            }
        }
        cout << ret << endl;
    }
    else {
        ll ret1 = 0;
        ll ret2 = 0;
        for(int i = 0;i < N;i++) {
            if(i < N / 2 - 1) {
                ret1 += vec.at(i) * 2;
            }
            else if(i == N / 2 - 1 || i == N / 2) {
                ret1 += vec.at(i);
            }
            else {
                ret1 -= vec.at(i) * 2;
            }
        }
        for(int i = 0;i < N;i++) {
            if(i < N / 2) {
                ret2 += vec.at(i) * 2;
            }
            else if(i == N / 2 || i == N / 2 + 1) {
                ret2 -= vec.at(i);
            }
            else {
                ret2 -= vec.at(i) * 2;
            }
        }
        cout << max(ret1,ret2) << endl;
    }
}

Measured memory_bytes: 1024
package main

import "fmt"
import "bufio"
import "os"
import "strconv"
import "sort"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	N := NextInt()
	A := NextInts(N)

	ans := A[0]
	for _, a := range A[1:] {
		ans = GCD(ans, a)
	}
	fmt.Println(ans)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextInts(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = NextInt()
	}
	return a
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func Bounded(lower, n, upper int) int {
	return Min(upper, Max(lower, n))
}

func SortInts(xs []int) {
	sort.Sort(sort.IntSlice(xs))
}

func ReverseSortInts(xs []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(xs)))
}

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}


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


int main(){
	int N;
	string S;
	cin >> N >> S;
	for(int i = 0; i < (int)S.length(); i++){
		if(S[i] + N > 'Z' )
			S[i] = S[i] + N - 26;
		else S[i] = S[i] + N;
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int Q = 301;

void solve() {
    int n,k,s;
    cin>>n>>k>>s;
    REP(i,1,n) {
        if (k>0) {
            cout<<s;
            k--;
        }
        else {
            if (s+1 >= 1e9) cout<<(s-1);
            else cout<<(s+1);
        }
        cout<<" ";
    }
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 1280
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
/*
 
 
 
 */

public class Main {

    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int t=1;
        //t = sc.ni();
        while(t-->0) {
        	solve(pw,sc);
        }
       
        pw.close();
    }
    static final int M = (int) 1e9+7;
    static long[] fac;
    private static void solve(PrintWriter pw, FastScanner sc) {
    	int n = sc.ni();
    	fac = new long[n+1];
    	fill(n);
    	
    	long ans = exp(10L,n);
    	//pw.println(ans);
    	ans = (ans-exp(8L,n)+M)%M;
    	long te =0;
    	//pw.println(ans);
    	for(int i=1;i<=n;i++) {
    		long ex = (fac[n-i]*fac[i])%M;
    		ex = exp(ex,M-2);
    		ex = (fac[n]*ex)%M;
    		ex = (exp(8L,n-i)*ex)%M;
    		te = te+ex;
    		
    		if(te>=M)
    			te=te%M;
    	}
    	//pw.println(te);
    
    	ans = (ans-(te*2)%M+M)%M;
    	
    	pw.println(ans);
    	
	}
    static void fill(int n) {
    	fac[0]=1L;
    	for(int i=1;i<n+1;i++) {
    		fac[i]=(fac[i-1]*i)%M;
    	}
    			
    }
    static long exp(long x,int n) {
    	long res=1;
    	while(n>0) {
    		if((n&1)==1) {
    			res= (res*x)%M;
    		}
    		x = (x*x)%M;
    		n=n>>1;
    	}
    	return res;
    }

	static <T> void deb(T x,int o){
       System.out.print(x);
       if(o==0) {
    	   System.out.println();
    	   
       }
    }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String ne() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String ne(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int ni() {
			return Integer.parseInt(ne());
		}
		
		long nl() {
			return Long.parseLong(ne());
		}
		
		double nd() {
			return Double.parseDouble(ne());
		}
		
	    
	}
   
}

Measured memory_bytes: 40592
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

const dp = {};
const memo = (i, m) => {
  if (m <= 0) {
    dp[i] = dp[i] || {};
    return dp[i][m] = m === 0;
  } 
  if (i === n) {
    return false;
  }

  return memo(i + 1, m) || memo(i + 1, m - Number(A[i]));
}

for (let i = 0; i < q; i++) {
  console.log(memo(0, Number(mi[i])) ? 'yes' : 'no');
}


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

int main(){
	int n;
	cin>>n;
	int a[n][3];
	for(int b=0;b<n;b++){
		for(int c=0;c<3;c++){
			cin>>a[b][c];
		}
	}
	for(int d=0;d<n;d++){
		sort(a[d],a[d]+3);
		if(a[d][0]*a[d][0]+a[d][1]*a[d][1]==a[d][2]*a[d][2]) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int N;
int x[202], y[202];

int main() {
  while (true) {
    scanf("%d", &N);
    if (N == 0) break;
    x[0] = y[0] = 0;
    for (int i=1;i<N;i++) {
      int n, d;
      scanf("%d %d", &n, &d);
      switch (d) {
      case 0:
        x[i] = x[n]-1;
        y[i] = y[n];
        break;
      case 1:
        x[i] = x[n];
        y[i] = y[n]+1;
        break;
      case 2:
        x[i] = x[n]+1;
        y[i] = y[n];
        break;
      case 3:
        x[i] = x[n];
        y[i] = y[n]-1;
        break;
      }
    }
    sort(x, x+N);
    sort(y, y+N);
    printf("%d %d\n", x[N-1]-x[0]+1, y[N-1]-y[0]+1);
  }
  return 0;
}

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

namespace ConsoleApp15
{
    class Class154
    {
        static char[,] map;
        static int[,] frag;
        static int[] dy = new int[2] { 0, 1};
        static int[] dx = new int[2] { 1, 0};
        static void Main()
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = HW[0], W = HW[1];
            map = new char[H, W];
            frag = new int[H, W];
            for(int i = 0; i < H; i++)
            {
                var r = Console.ReadLine();
                for(int j = 0; j < W; j++)
                {
                    map[i, j] = r[j];
                    frag[i, j] = int.MaxValue;
                }
            }
            var que = new Queue<Tuple<int, int, int,bool>>();
            if (map[0, 0] != '#') que.Enqueue(Tuple.Create(0, 0, 0,false));
            else que.Enqueue(Tuple.Create(0, 0, 0,true));
            frag[0, 0] = 0;
            while (que.Count > 0)
            {
                var p = que.Dequeue();
                for(int i = 0; i < 2; i++)
                {
                    int ny = p.Item1 + dy[i], nx = p.Item2 + dx[i];
                    int nc = p.Item3;bool b = p.Item4;
                    if(0<=ny&&ny<H&&0<=nx&&nx<W)
                    {
                        if (map[ny, nx] == '#') b = true;
                        if (b && map[ny, nx] != '#') { b = false;nc++; }
                        if (nc < frag[ny, nx])
                        {
                            frag[ny, nx] = nc;
                            que.Enqueue(Tuple.Create(ny, nx, nc,b));
                        }
                    }
                }
            }
            if (map[H - 1, W - 1] == '#') frag[H - 1, W - 1]++;
            Console.WriteLine(frag[H - 1, W - 1]);
        }
    }
}


Measured memory_bytes: 15820
# /user/bin/python
# -*- coding: utf-8 -*-
import sys 


a1,a2,a3 = map(int, sys.stdin.readline().rstrip().split())

def solve(i,j,k):
  ret = abs(i-j) + abs(j-k)
  return ret

s1 = solve(a1,a2,a3)
s2 = solve(a3,a1,a2)
s3 = solve(a2,a3,a1)
print(min(s1,s2,s3))

Measured memory_bytes: 3060
num = raw_input()
num = num.split()
result = True
w, h, x, y, r = int(num[0]), int(num[1]), int(num[2]), int(num[3]), int(num[4])

if x < r or (w - r) < x:
	result = False

if y < r or (h - r) < y:
	result = False

if result:
	print "Yes"
else:
	print "No"

Measured memory_bytes: 6344
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   string s;
   cin>>s;
   for(ll i=0;i<s.size();i++)
   {
       if(i%2==0 && s[i]=='L')
       {
           cout<<"No"<<endl;
           return 0;
       }
       else if(i%2==1 && s[i]=='R')
       {
           cout<<"No"<<endl;
           return 0;
       }
   }
   cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
let a, b, k = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let m = b - a + 1
let f = Printf.printf "%d\n"
let _ = if 2 * k >= m then for i = a to b do f i done else (for i = a to a - 1 + k do f i done; for i = b + 1 - k to b do f i done)

Measured memory_bytes: 2432
N, W = list(map(int, input().split()))
INF = int(1e11)
dp = [[INF for i in range(int(1e5)+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for j in range(0, int(1e5)+1):
        if j - v >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)
        dp[i][j] = min(dp[i][j], dp[i-1][j])

for j in reversed(range(int(1e5)+1)):
    for i in range(N+1):
        if dp[i][j] <= W:
            print(j)
            break
    else:
        continue
    break

Measured memory_bytes: 173556
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main()
{
	//ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	ll x;
	cin>>n;
	x = (ll)n * (n + 1) / 2;
	int ar[n];
	set<int> st;
	fore(i, 0, n)
	{
		cin>>ar[i];
		st.insert(ar[i]);
	}
	int mar[st.size()];
	int siz = st.size();
	int con = 0;
	for(set<int>::iterator it = st.begin(); it != st.end(); it++)
		mar[con] = *it, con++;
	int lo = 0, hi = siz -1;
	int mid, res = -1;
	while(lo <= hi)
	{
		mid = (lo + hi) / 2;
		//cout<<"     "<<lo<<' '<<hi<<'\n';
		ordered_set st;
		map<int,int> ma;
		st.insert(mp(0, 0));
		ma[0]++;
		int su = 0;
		ll sum = 0;
		fore(i, 0, n)
		{
			su += ar[i] >= mar[mid]? 1: -1;
			sum += st.order_of_key(mp(su, ma[su]));
			//cout<<su<<','<<sum<<' '<<'\n';
			st.insert(mp(su, ma[su]));
			ma[su]++;
		}
		//cout<<mid<<' '<<mar[mid]<<' '<<x<<' '<<sum<<'\n';
		if(sum >= x / 2 + (x&1))
			res = mid, lo = mid +1;
		else
			hi = mid -1;
		//cout<<res<<'\n';
	}
	//cout<<res<<'\n';
	cout<<mar[res];
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 15616
#include<iostream>

int N;
int K;

int greed()
{
    int sum = 1;
    for(int i = 0; i < N; i++) {
        if (sum >= K) {
            sum += K;
        } else {
            sum += sum;
        }
    }
    return sum;
}

void solve()
{
    int min_sum = greed();
    std::cout << min_sum << std::endl;
}

int main() {
    // Input
    std::cin >> N;
    std::cin >> K;

    solve();
}

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

using namespace std;


int main(){
    int h1,m1,h2,m2,k,ans,tw,ts;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    tw = h1*60 + m1;
    ts = h2*60 + m2;
    ans = ts - tw - k;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c;
  cin >> a;
  cin >>b;
  cin >>c;
  
  if(a+b>=c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
   return 0;
}


Measured memory_bytes: 888
<?php
	while (true) {
		$n = trim(fgets(STDIN));
		$n = explode(" ", $n);

		if (!$n[0] && !$n[1]) break;

		if ($n[0] < $n[1]) {
			printf("%d %d\n", $n[0], $n[1]);
		} else {
			printf("%d %d\n", $n[1], $n[0]);
		}
	}

Measured memory_bytes: 6584