akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ff              first
#define ss              second
//#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mci             map<char,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            long long x; cin>>x; while(x--)
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
#define ll long long 
//template <typename T> 

 signed main()
 {
   ios_base::sync_with_stdio(false);cin.tie(NULL);

int n;
cin>>n;
if(n%1000==0)
  cout<<"0\n";
else
  cout<<1000-(n%1000)<<"\n";

 cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;


return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

    private static final int GOAL_BUTTON = 2;

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Button[] buttons = new Button[n];

        for (int i = 0; i < n; i++) {
            Button bt = new Button(sc.nextInt());

            // ボタン1が初期で光っている
            if (i == 0) {
                bt.push();
            }

            buttons[i] = bt;
        }

        int next = buttons[0].push();
        int pushCount = 1;

        while (true) {
            if (next == GOAL_BUTTON) {

                // 押した結果光ったのが2なら終了
                System.out.println(pushCount);

                return;
            }

            if (buttons.length < next) {
                System.out.println(-1);

                return;
            }

            // 次に押すボタン
            Button targetButton = buttons[next - 1];

            // 押されたボタンを再度押すと無限に続くため2は光らせられない
            if (targetButton.isPushed()) {
                System.out.println(-1);

                return;
            } else {

                // 押されてなければ押して回数を加算
                next = targetButton.push();
                ++pushCount;
            }
        }
	}
}

class Button {

    /** 光らせるボタン */
    private int target;

    /** 光っているかどうか */
    private boolean on;

    /** 押された（光らせたか）どうか */
    private boolean pushed;

    public Button(int target) {
        this.target = target;
        on = false;
    }

    /** ボタンを押して光っている状態を反転後、光るボタンを返す */
    public int push() {
        on = !on;

        if (on) {
            pushed = true;
        }

        return target;
    }

    public int getTarget() {
        return target;
    }

    public void setTarget(int target) {
        this.target = target;
    }

    public boolean isOn() {
        return on;
    }

    public boolean isPushed() {
        return pushed;
    }
}

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

int main() {
  int n;
  cin >> n;
  rep(i,100000) {
    if (i * i > n) {
      cout << (i - 1) * (i - 1);
      break;
    }
  }
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    w = list(map(int, input().split()))
    ans = float('inf')
    for t in range(n-1):
        ans = min(ans, abs(sum(w[:t+1]) - sum(w[t+1:])))
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9024
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1,Q=110;
long long n,W,ans,i,j;
long long w[N],v[N];
long long dp[Q][N];
int main(){
    cin>>n>>W;
    for(i=1;i<=n;i++)cin>>w[i]>>v[i];
    for(i=1;i<=n;i++){
        for(j=0;j<=W;j++){
            if(j >= w[i])dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    for(i=1;i<=W;i++)ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 81408
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(); int b = sc.nextInt();
    sc.close();
    int sum =0;
    
    if (a>=b) {sum += a;
    	a= a-1;}
    else {sum += b;
    	b= b-1;}
    if (a>=b) {sum += a;
	a= a-1;}
else {sum += b;
	b= b-1;}
    
   
   
   
      System.out.println(sum);
	}

}

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int N,M;
int dp[2][333][333];

inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

signed main(){
    cin>>N>>M;
    dp[0][1][0]=1;
    for(int i=0;i<M;i++){
        for(int j=1;j<=N;j++){
            for(int k=0;k<M&&j+k<=N;k++){
                add(dp[(i+1)&1][j+k][0],dp[i&1][j][k]*j%mod);
                add(dp[(i+1)&1][j][k+1],dp[i&1][j][k]*(N-j-k)%mod);
                add(dp[(i+1)&1][j][k],dp[i&1][j][k]*k%mod);
                dp[i&1][j][k]=0;
            }
        }
    }
    cout<<dp[M&1][N][0]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

struct edge{
    ll u;
    ll v;
    ll cost;
    edge(){}
    edge(ll u, ll v,ll cost):u(u),v(v),cost(cost){}
};

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<vector<edge>> G(N);
    for(int i = 0; i < N-1;i++){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(edge(a,b,c));
        G[b].push_back(edge(b,a,c));
    }
    ll Q,K; cin >> Q >> K;
    K--;
    vector<ll> dist(N,LINF);
    queue<ll> q; q.push(K);
    dist[K] = 0;
    while(!q.empty()){
        ll n = q.front(); q.pop();
        for(auto e:G[n]){
            if(dist[e.v] > dist[e.u] + e.cost){
                dist[e.v] = dist[e.u] + e.cost;
                q.push(e.v);
            }
        }
    }
    for(int i = 0; i < Q;i++){
        ll x,y; cin >> x >> y;
        x--; y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}


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

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

// n^(exponent)を計算 O(logN)
ll pow(ll n, ll exponent) {
    ll pow = 1;
    while(exponent > 0) {
        if((exponent & 1) == 1) {
            pow *= n;
        }
        n *= n;
        
        // 桁をずらす
        exponent >>= 1;
    }
    return pow;
}

// n^(exponent) を mod で割った余りを計算 O(logN)
ll mod_pow(ll n, ll exponent, ll mod) {
    ll pow = 1;
    while(exponent > 0) {
        if((exponent & 1) == 1) {
            pow *= n;
            pow %= mod;
        }
        n *= n;
        n %= mod;
        
        // 桁をずらす
        exponent >>= 1;
    }
    return pow;
}

// n! を計算　O(N)
ll factorial(ll n) {
    ll factorial = 1;
    for(ll i = 1; i <= n; i++) {
        factorial *= i;
    }
    return factorial;
}

// n! を mod で割った余りを計算　O(N)
ll mod_factorial(ll n, ll mod) {
    ll factorial = 1;
    for(ll i = 1; i <= n; i++) {
        factorial *= i;
        factorial %= mod;
    }
    return factorial;
}

// xCn を計算
ll conbination(ll x, ll n) {
    return factorial(x) / (factorial(n) * factorial(x - n));
}

// xCn を　mod で割った余りを計算
ll mod_conbination(ll x, ll n, ll mod) {
    ll conb = mod_factorial(x, mod);
    
    // 逆元を求める(フェールマーの小定理を参照)
    ll reverse_n = mod_pow(mod_factorial(n, mod), mod - 2, mod);
    ll reverse_difference = mod_pow(mod_factorial(x - n, mod), mod - 2, mod);
    
    return (((conb * reverse_n) % mod) * reverse_difference) % mod;
}

int main() {
    ll n, k;
    cin >> n >> k;
    
    for(int i = 1; i <= k; i++) {
        if(i - 1 <= n - k) {
            cout << (mod_conbination(k - 1, i - 1, MOD) * mod_conbination(n - k + 1, i, MOD)) % MOD << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
use std::f64::consts::PI;

fn circumference(r: f64) -> f64 {
    (r as f64) * 2.0 * PI
}

fn area(r: f64) -> f64 {
    (r * r) as f64 * PI
}

fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let line = getline();
    let v: Vec<_> = line.trim().split(' ').collect();
    let r = v[0].parse::<f64>().unwrap();
    println!("{:.6} {:.6}", area(r), circumference(r));
}



Measured memory_bytes: 5064
import java.util.Scanner;
 
 
public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
	
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		double ans = 0.0;
		ans += Math.max(0.0,(double)(N-K+1))/(double)N;
		for(int i=1; i<=Math.min(N, K-1);i++){
			double tmp_ans = 1.0/(double)N;
			int tmp_i = i;
			while(tmp_i<K){
				tmp_ans *= 0.5;
				tmp_i *= 2;
			}
			ans += tmp_ans;
		}
		System.out.println(ans);
		
		
		sc.close();
	}
	
	
	
}

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

int main()
{
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    double max_conc = -1;
    int ans_weight = 0;
    int ans_sugar = 0;

    rep(i,31) {
        rep(j,31) {
            rep(k,1501) {
                int water = i*100*a + j*100*b;
                int sugar = k*c;
                bool in_f = (water + sugar <= f);
                bool in_e = (sugar <= water/100*e);
                if(!in_f || !in_e) break;

                rep(l,1501) {
                    int water = i*100*a + j*100*b;
                    int sugar = k*c + l*d;
                    bool in_f = (water + sugar <= f);
                    bool in_e = (sugar <= water/100*e);
                    if(!in_f || !in_e) break;

                    if(water > 0){
                        double conc = sugar/double(water+sugar);
                        if(conc > max_conc){
                            ans_weight = water + sugar;
                            ans_sugar = sugar;
                            max_conc = conc;
                        }
                    }
                }
            }
        }
    }

    cout << ans_weight << " " << ans_sugar << endl;
    return 0;
}

Measured memory_bytes: 256
def xor_sum(n):
    m1 = (n+1)//4
    m2 = (n+1)%4
    if m2 == 0:return 0
    else:
        ret = 0
        for i in range(m1*4,m1*4+m2):ret ^= i
        else: return ret

a,b = map(int, input().split())
if a==b:print(a)
else:
    ans = xor_sum(a-1) ^ xor_sum(b)
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF (1e9)+5

using namespace std;

int P[55556], n;

void Ciur()
{
    for (long long  i=2; i<=55555; i++)
    {
        if (P[i]==0)
        {
            for (long long j=i*i; j<=55555; j+=i)
                P[j]=1;
            if (n && i%5==1)
            {
                cout<<i<<" ";
                n--;
            }
        }
    }
}

int main()
{
    cin>>n;
    Ciur();
    return 0;
}


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

int a, b, c;

int main () {
  cin >> a >> b >> c;
  if ((a == (b + c)) || b == (a + c) || c == (a + b)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return;
    }
    LL v0 = 2, v1 = 1, v2;
    REP(i,1,n) {
        v2 = v1 + v0;
        v0 = v1;
        v1 = v2;
    }
    cout << v2 << endl;
}

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

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

int main(){
    int n, k; cin >> n >> k;
    vector<int> h(n);
    
  
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    //dp[i] denotes the minimum cost to reach ith stone
    // 0 < i < n - 1 are the stones
    //We are asked to dind the cost to reach last stone i.e dp[n - 1]
    //Initially there is infinite cost to reach ith stones
    vector<int> dp(n, INT_MAX);
  
    //To reach first stone there is no cost. SO dp[0] = 0
    dp[0] = 0;
   //To reach second stone the frog can jump from 0th stone costing dp[1] = abs(h[1] - h[0])
    dp[1] = abs(h[1] - h[0]);
    
    //For every other stones 2 <= i < n, the frog can jump from the (i - 1), (i - 2)...(i - k)th stones 
    for(int i = 2; i < n; i++){
      for(int j = i - 1, jump = 0; j  >= 0 && jump < k; j--, jump++){
        dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
 
      }
    }
    //Print minm cost to reach (n - 1)th stone
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int iin = sc.nextInt();
		int iik = sc.nextInt();
		int iix = 0;
		int imvsum = 0;
		for(int i=0;i<iin;i++){
			 iix = sc.nextInt();
			 if(iix<=iik/2){
				 imvsum += iix * 2;
			 }
			 else{
				 imvsum += (iik-iix) * 2; 
			 }
		}
		
		System.out.println(imvsum);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int limit = 100010;
using edge = struct{int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
    depth[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

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

    for(int i = 0; i < n - 1; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }

    int q, k;
    cin >> q >> k;
    k--;

    dfs(k, -1, 0);

    for(int i = 0; i < q; ++i){
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}

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

int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	cout << max(ll(0), (n-2)*(b-a) + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200010 
using namespace std;
int num[N]={};
vector<int> pz;
int main(){
	int n,k,a,i,kd=0,ans=0;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>a;
		num[a]++;
	}
	for(i=1;i<=n;i++)
	{
		if(num[i]!=0)
		{
			kd++;
			pz.push_back(num[i]);
		}
	}
	sort(pz.begin(),pz.end());
	for(i=kd;i>k;i--)
	{
		ans+=pz[kd-i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2168
void main() {
	auto N = ri;
	auto T = readAs!(int[]);
	auto M = ri;
	auto S = T.sum;
	foreach(i; 0..M) {
		auto ip = readAs!(int[]), P = ip[0]-1, X = ip[1];
		writeln(S-T[P]+X);
	}
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second

#define ALL(V)  V.begin(),V.end()

#define MX1     100000LL
#define MX2     1000000LL
#define Inf     1000000000000000LL
#define mod		1000000007LL
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/

    lli N,i,Y;
    cin>>N>>Y;

    lli x=-1,y=-1,z=-1;

    rep(x,0,N+1)
    {
        rep(y,0,N+1)
        {
            lli Value = 9000*x + 4000 * y;

            if(x+y <= N and (Value == Y-1000*N))
            {
                cout<<x<<' '<<y<<' '<<N-x-y;
                exit(0);
            }
        }
    }

    cout<<-1<<' '<<-1<<' '<<-1;








 return 0;
}


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

#define MOD 1000000000+7
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define inf 100000000000000000
int addMod(int x, int y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

int mulMod(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y)
    {
        if(y & 1) z = mulMod(z, x);
        x = mulMod(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int divide(int x, int y)
{
    return mulMod(x, inv(y));
}

ll gcd(int a, int b) 
{   if (a == 0) return b; 
    if (b == 0) return a;  
    if (a == b) return a; 
    if (a > b)  return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

ll h(ll* A, int N){
    ll pro = 1;
    for(int i=0; i<N; ++i) pro = mulMod(A[i], pro);
    return pro;
}

ll f(ll* A, int N){
    int alpha = A[0];
    for(int i=1; i<N; ++i){
        alpha = gcd(alpha, A[i])%MOD;
    }
    return alpha;
}


int main(){
    FIO
    long long int h, w; cin>>h>>w;
    long double alpha = h*w;
    long long int ans = ceil(alpha/2);
    if(h==1 || w==1) cout<<"1"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
min=A.min
max=A.max
ans=INF
min.upto(max) do|x|
  val=0
  A.each do|a|
    val+=(x-a)**2 
  end
  ans=min(ans,val)
end
puts ans

Measured memory_bytes: 1788
#include <stdio.h>
#include <math.h>

int vet[6], invert[6];

int olhaso(int k) {
	int n = k, t;
	for(int i = 0; i < 5; ++i) {
		t = n % 10;
		n = n/10;
		vet[4-i] = t;
		invert[i] = t;
	}
	for(int i = 0; i < 5; ++i) {
		if(vet[i] != invert[i])
			return 0;
	}
	return 1;
}

int main() {
	 int a, b, quant_pali = 0;
	 scanf("%d %d", &a, &b);
	 for(int i = a; i <= b; ++i) {
	 	if(olhaso(i))
	 		++quant_pali;
	 }
	 printf("%d\n", quant_pali);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int W[2005][2005], B[2005][2005];
int sumB[2005][2005], sumW[2005][2005];

int main(void) {
  int N, K;
  cin >> N >> K;
  int K2 = K*2;
  rep(i, 0, N) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    x %= K2; x++;
    y %= K2; y++;
    if (c=='B') B[x][y]++;
    else W[x][y]++;
  }
  
  rep(i, 1, K2+1) rep(j, 1, K2+1) {
    sumB[i][j] = sumB[i-1][j] + sumB[i][j-1] - sumB[i-1][j-1] + B[i][j];
    sumW[i][j] = sumW[i-1][j] + sumW[i][j-1] - sumW[i-1][j-1] + W[i][j];
  }
  
  int ans = 0;
  rep(i, K, K2+1) rep(j, K, K2+1) {
    int sum1 = 0, sum2 = 0;
    
    sum1 += sumB[i][j] - sumB[i-K][j] - sumB[i][j-K] + sumB[i-K][j-K]*2;
    sum1 += sumB[i-K][K2] - sumB[i-K][j];
    sum1 += sumB[K2][j-K] - sumB[i][j-K];
    sum1 += sumB[K2][K2] - sumB[i][K2] - sumB[K2][j] + sumB[i][j];

    sum2 += sumW[i][j] - sumW[i-K][j] - sumW[i][j-K] + sumW[i-K][j-K]*2;
    sum2 += sumW[i-K][K2] - sumW[i-K][j];
    sum2 += sumW[K2][j-K] - sumW[i][j-K];
    sum2 += sumW[K2][K2] - sumW[i][K2] - sumW[K2][j] + sumW[i][j];

    int tmp1 = sumW[K2][K2] - sum2;
    int tmp2 = sumB[K2][K2] - sum1;

    int mx = max(sum1+tmp1, sum2+tmp2);
     
     
    ans = max(ans, mx);
  }
  
    
  cout << ans << endl;
    return 0;
}





Measured memory_bytes: 66132
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int f(int n){
	if( n % 2 == 0){
		return n / 2;
	}else{
		return (3*n) + 1;
	}
}

int main()
{
	int s;
	cin>>s;
	set<int> numList;
	numList.insert(s);
	int ans = 1;
	s = f(s);
	while( numList.count(s) == 0){
		numList.insert(s);
		s = f(s);
		ans++;
	}
	cout<<ans+1<<endl;
	return 0;
}



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

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

struct D
{
	int t, use;
	D() : t(1000000000), use(0) { }
	bool operator< (const D& oth) const
	{
		if (t != oth.t) return (t > oth.t);
		return (use > oth.use);
	}
	D set(int T, int U)
	{
		t = T, use = U;
		return *this;
	}
} d[805][805];
char buf[805][805];
int r, c, k;
int si, sj;

int main()
{
	scanf("%d%d%d", &r, &c, &k);
	for (int i = 0;i < r;i++)
	{
		scanf("%s", buf[i]);
		for (int j = 0;j < c;j++)
		{
			if (buf[i][j] == 'S') si = i, sj = j;
		}
	}
	priority_queue<pair<D, pair<int, int> > > pq;
	pq.emplace(d[si][sj].set(0, 0), make_pair(si, sj));
	while (!pq.empty())
	{
		auto u = pq.top(); pq.pop();
		int ui = u.second.first, uj = u.second.second;
		if (ui == 0 || ui == r-1 || uj == 0 || uj == c-1)
		{
			printf("%d\n", (u.first.t+k-1)/k);
			return 0;
		}
		for (int i = 0;i < 4;i++) if (0 <= ui+dx[i] && ui+dx[i] < r && 0 <= uj+dy[i] && uj+dy[i] < c)
		{
			D alt = u.first;
			if (buf[ui+dx[i]][uj+dy[i]] == '#')
			{
				alt.use++;
				alt.t = max(alt.t, (alt.use+k-1)/k*k) + 1;
			} else alt.t++;
			if (d[ui+dx[i]][uj+dy[i]] < alt)
				pq.emplace(d[ui+dx[i]][uj+dy[i]].set(alt.t, alt.use), make_pair(ui+dx[i], uj+dy[i]));
		}
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 6524
#include <iostream>
#include <chrono>
using namespace std;
int main()
{
	std::chrono::system_clock::time_point  start, end; // 型は auto で可
	start = std::chrono::system_clock::now(); // 計測開始時間
	int a[3];
	int v=0;
	for (int i = 0; i < 3; i++){
		cin >> a[i];
	
	}
	while (true){
		end = std::chrono::system_clock::now();  // 計測終了時間
		double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); //処理に要した時間をミリ秒に変換
		if (elapsed>1950){  v = -1; goto point; }
		for (int i = 0; i < 3; i++){
	
			if (a[i] % 2 != 0)goto point;
		}
		int t[3] = { a[0] / 2, a[1] / 2, a[2] / 2 };
		a[0] = t[1] + t[2];
		a[1] = t[0] + t[2];
		a[2] = t[0] + t[1];
		v++;
	}
	point:
	cout << v << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  trait Monoid[A]{
    def op(a1: A, a2: A): A
    def zero: A
  }

  type Per = List[Int]
  type Rot = Dice => Dice

  object DiceRoll extends Monoid[Rot]{

    def op(rot1: Rot, rot2: Rot): Rot = (dice: Dice) => rot2(rot1(dice))

    def zero: Rot = (dice: Dice)=>dice

    val north = List(2,6,3,4,1,5).map(_ - 1)
    val east = List(4,2,1,6,5,3).map(_ - 1)
    val ccw = List(1,4,2,5,3,6).map(_ - 1)

    def rot(perm: Per): Rot = (dice: Dice) => Dice(perm.map(dice.pip))

    def axial(f: Rot): List[Rot] = List(zero,f,op(f,f),op(op(f,f),f))

    def enumerateTop(f: Rot = zero, n: Int = 6): List[Rot] = {
      if(n<=0)List[Rot]()
      else if(n%2==0) f :: enumerateTop(op(f,rot(north)),n-1)
      else f :: enumerateTop(op(f,rot(east)),n-1)
    }

    def enumerate: List[Rot] = enumerateTop().flatMap( e => axial(rot(ccw)).map(op(e,_)))
  }

  case class Dice(pip: List[Int])

  @tailrec
  def loop(n:Int, all: List[Dice]):Unit = if(n>0){
    val Array(a,b,_*) = readLine.split(" ").map(_.toInt)
    val res = all.filter(d => d.pip(0)==a && d.pip(1)==b)
    println(res(0).pip(2))
    loop(n-1,all)
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    val all: List[Dice] = DiceRoll.enumerate.map(_(Dice(pip)))
    val Array(n,_*) = readLine.split(" ").map(_.toInt)
    loop(n,all)
  }
}

Measured memory_bytes: 41320
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(N);
	READAR(X,N);
	ll ans=inf;
	FORI(i,0,102)
	{
		ll cans=0;
		FORI(j,0,N)
		{
			cans+=((X[j]-i)*(X[j]-i));
		}
		ans=min(ans,cans);
	}
	cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n, m, q;
int A[64], B[64], C[64], D[64];
lint ans = 0;

int X[16];
lint check(){
	lint res = 0;
	for(int i=1; i<=q; i++){
		if(X[B[i]] - X[A[i]] == C[i]) res += D[i];
	}
	return res;
}
void solve(int i){
	if(i==n+1){
		ans = max(ans, check());
		return;
	}
	for(int k=X[i-1]; k<=m; k++){
		X[i] = k; solve(i+1);
	}
}

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

	cin>>n>>m>>q;
	for(int i=1; i<=q; i++){
		cin>>A[i]>>B[i]>>C[i]>>D[i];
	}

	X[0] = 1;
	solve(1);
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << max(max(a+b,a*b),a-b) << endl;
}


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

int main(){
int t[10],al=0;
for(int i=0;i<5;i++){
cin>>t[i];
if(t[i]<40){t[i]=40;}
al+=t[i];
}
cout<<al/5<<endl;

return 0;
}


Measured memory_bytes: 3068
n, k = map(int, input().split())
x = list(map(int, input().split()))
neg_num = n

for i in range(n):
    if x[i] > 0:
        neg_num = i
        break
pos_num = n - neg_num

l = min(k, neg_num)
res = 10 ** 13
for i in range(l, -1, -1):
    r = k - i
    if r <= pos_num:
        l_val = min(0, x[neg_num - i])
        r_val = max(0, x[neg_num + k - i - 1])
        tmp = min( -l_val * 2 + r_val, -l_val + r_val * 2)
        res = min(tmp, res)
print(res)

Measured memory_bytes: 20136
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

struct Point {
  int x, y;
};

int main() {
  int n;
  while (std::cin >> n) {
    std::vector<Point> points;
    for (int i = 0; i < n; ++ i) {
      int x, y;
      std::cin >> x >> y;
      points.push_back(Point{x, y});
    }
    std::set<std::pair<int, int>> exist;
    for (int i = 0; i < n; ++ i) {
      exist.insert(std::make_pair<>(points[i].x, points[i].y));
    }
    int res = n;
    for (int i = 0; i < n; ++ i) {
      for (int j = i + 1; j < n; ++ j) {
        int temp = 0;
        int p, q;
        Point a = points[i], b = points[j];
        // a -> b
        if (b.x < a.x || b.x == a.x && b.y < a.y) {
          std::swap(a, b);
        }
        p = b.x - a.x;
        q = b.y - a.y;
        for (int k = 0; k < n; ++ k) {
          std::pair<int, int> t = std::make_pair<>(points[k].x - p, points[k].y - q);
          auto iter = exist.find(t);
          if (iter == exist.end()) ++ temp;
        }
        res = std::min(res, temp);
      }
    }
    std::cout << res << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0;
  int left = 0;
  int right = 0;
  rep(i,n){
    if(s[i] == '('){
      x++;
    }
    if(s[i] == ')'){
      if(x > 0) x--;
      else{
        left++;
      }
    }
  }
  rep(i,left) cout << '(';
  cout << s;
  rep(i,x) cout << ')';
}


Measured memory_bytes: 3644
// ABC067
// A - Sharing Cookies
#include<bits/stdc++.h>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if((a>=1 && a<=10000) && (b>=1 && b<=10000) && (c>=1 && c<=10000))
{
    if((a+b)<(a+c) && (a+b)<(b+c)){
        printf("%d\n",(a+b));
    }
    else if((b+c)<(a+c)&& (b+c)<(a+b)){
        printf("%d\n",(b+c));
    }
    else{
        printf("%d\n",(a+c));
    }
}
return 0;
}




Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf n;
    cin >>n;

    for(int i=0;i<101;i+=4){
        for(int h=0;h<101;h+=7){
            if(i+h==n){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }
    cout << "No" <<endl;
}

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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABK = ReadIntList();
            for(var i = 100; i >= 1; i--)
            {
                if(ABK[0] % i == 0 && ABK[1] % i == 0)
                {
                    ABK[2]--;
                }
                if (ABK[2] == 0)
                {
                    Console.WriteLine(i);
                    break;
                }
            }
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


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

int main(){
    int frg = 0;
    string s;
    cin >> s;
    for(int i = 0;i<2;i++)if(s[i]==s[i+1] && s[i+1]==s[i+2])frg=1;
    if(frg)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n >= (int)s.size()) {
        cout << s;
        return 0;
    }
    else {
        string ans = s.substr(0, n);
        ans += "...";
        cout << ans;
        return 0;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <map>
 
using namespace std;
 
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
 
int main(){
	cin.tie(0);                       
   	ios::sync_with_stdio(false);
   	int N;
   	cin >> N;
      vector<int> A;
      vector<int> B;
      vector<int> C;

      for(int i = 0;i < N;i++){
         int x;
         cin >> x;
         A.push_back(x);
      }
      for(int i = 0;i < N;i++){
         int x;
         cin >> x;
         B.push_back(x);
      }
      for(int i = 0;i < N;i++){
         int x;
         cin >> x;
         C.push_back(x);
      }

      sort(A.begin(),A.end());
      sort(C.begin(),C.end());
      
      long long count = 0;
      for(int i = 0;i < N;i++){
         count += (lower_bound(A.begin(),A.end(),B[i]) - A.begin()) * (C.end() - upper_bound(C.begin(),C.end(),B[i]));
      }
      cout << count << endl;
   	
   	return 0;
}

Measured memory_bytes: 1784
### subroutines

def match?(ls, k, br)
  for i in (0...5)
    return false if ls[i][k] && ls[i][k] == br[i]
  end
  true
end

def vrec()
  k = 0
  while k < 5 && ! $vls[k].empty?
    k += 1
  end
  return 1 if k >= 5

  count = 0
  for i in (0...10)
    next if $used[i]

    if match?($hls, k, $brds[i])
      $used[i] = true
      $vls[k] = $brds[i]
      count += hrec()
      $vls[k] = []
      $used[i] = false
    end
    next if $brds[i] == $rbrds[i]
    
    if match?($hls, k, $rbrds[i])
      $used[i] = true
      $vls[k] = $rbrds[i]
      count += hrec()
      $vls[k] = []
      $used[i] = false
    end
  end
  count
end

def hrec()
  k = 0
  while k < 5 && ! $hls[k].empty?
    k += 1
  end
  return 1 if k >= 5

  count = 0
  for i in (0...10)
    next if $used[i]

    if match?($vls, k, $brds[i])
      $used[i] = true
      $hls[k] = $brds[i]
      count += vrec()
      $hls[k] = []
      $used[i] = false
    end
    next if $brds[i] == $rbrds[i]
    
    if match?($vls, k, $rbrds[i])
      $used[i] = true
      $hls[k] = $rbrds[i]
      count += vrec()
      $hls[k] = []
      $used[i] = false
    end
  end
  count
end

def kaibun?(br)
  br[0] == br[4] && br[1] == br[3]
end

### main

loop do
  line = gets.strip
  break if line == 'END'

  $brds = line.split.map{|str| str.split('').map{|b| b.to_i}}
  $rbrds = $brds.map{|br| br.reverse}
  #p $brds
  #p $rbrds
  
  $hls = 5.times.map{[]}
  $vls = 5.times.map{[]}
  $used = 10.times.map{false}

  $used[0] = true
  count = 0

  $hls[0] = $brds[0]
  count += vrec()
  $hls[0] = []

  $hls[1] = $brds[0]
  count += vrec()
  $hls[1] = []

  $hls[2] = $brds[0]
  count += vrec() / 2
  $hls[2] = []

  count /= 2 if kaibun?($brds[0])
  
  puts count
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
const int N=8e5+10;
int n,m,mb,q[N],b[N];
struct dat{
	int l,r,t;
	bool operator < (const dat &rhs) const {
		return t>rhs.t;
	}
}a[N];

int Min[N<<2],tag[N<<2];
void pushdown(int rt) {
	if (!tag[rt]) return;
	Min[rt<<1]=tag[rt<<1]=tag[rt];
	Min[rt<<1|1]=tag[rt<<1|1]=tag[rt];
	tag[rt]=0; 
}
void update(int rt,int l,int r,int ql,int qr,int v) {
	if (ql<=l && r<=qr) {
		Min[rt]=tag[rt]=v;
		return;
	}
	pushdown(rt);
	int mid=l+r>>1;
	if (ql<=mid) update(rt<<1,l,mid,ql,qr,v);
	if (qr>mid) update(rt<<1|1,mid+1,r,ql,qr,v);
}

int query(int rt,int l,int r,int q) {
	if (l==q && r==q) return Min[rt];
	pushdown(rt);
	int mid=l+r>>1;
	if (q<=mid) return query(rt<<1,l,mid,q);
	if (q>mid) return query(rt<<1|1,mid+1,r,q); 
}

int main()
{
	cin>>n>>m;
	mb=0;
	for (int i=1;i<=n;i++) {
		scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].t);
		a[i].l-=a[i].t; a[i].r-=a[i].t+1;
		b[++mb]=a[i].l; b[++mb]=a[i].r;
	}
	for (int i=1;i<=m;i++) {
		scanf("%d",&q[i]);
		b[++mb]=q[i];
	}
	sort(b+1,b+mb+1);
	mb=unique(b+1,b+mb+1)-(b+1);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) {
		int l=lower_bound(b+1,b+mb+1,a[i].l)-b;
		int r=lower_bound(b+1,b+mb+1,a[i].r)-b;
		update(1,1,mb,l,r,a[i].t);
	}
	for (int i=1;i<=m;i++) {
		int t=lower_bound(b+1,b+mb+1,q[i])-b;
		int ans=query(1,1,mb,t);
		printf("%d\n",ans==0 ? -1 : ans);
	}
	return 0;
}

Measured memory_bytes: 32000
z[4000],*a=z,*b=z+2000,m,i,j,t;main(n){for(;scanf("%d",&n)*n++;m=!printf("%d\n",m))for(i=n;i--;j=a,a=b,b=j)for(j=n;j--;t>m?m=t:0)t=b[j]=n+~i&&getchar()>45?1+fmin(a[j],fmin(t,a[j+1])):0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int m;
    cin >> m;
    int ans = 48-m;
    
    cout << ans << endl;
    return 0;
}


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

int main() {
    int a[3][3];
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b[n];
    for (int i=0; i<n; i++) {
        cin >> b[i];
    }

    int checked[3][3] = {0};
    for (int i=0; i<3; i++) {
        for (int j=0; j<3; j++) {
            for (int k=0; k<n; k++) {
                if (b[k] == a[i][j]) {
                    checked[i][j] = 1;
                }
            }
        }
    }

    int v;
    int h;
    for (int i=0; i<3; i++) {
        v = 0;
        h = 0;
        for (int j=0; j<3; j++) {
            v += checked[i][j];
            h += checked[j][i];
        }
        if (v == 3 || h == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (checked[0][0] + checked[1][1] + checked[2][2] == 3
    || checked[2][0] + checked[1][1] + checked[0][2] == 3) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

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

int main() {
     int n;
     int p;
     int cnt = 0;
     cin >> n;
     for (int i=0; i<n; i++) {
          cin >> p;
          if (p != i+1) cnt++;
     }
     if (cnt > 2) cout << "NO" << endl;
     else cout << "YES" << endl;
     return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b] <- getIntList
    print $ maximum $ (a + b) : (a - b) : (a * b) : []

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int a, b;cin>>a>>b;
  int ga=-1, gb=-1;
  if(a==2)ga=3;
  else if((a==4 ||a==6)||(a==9 || a==11)){
  	ga=2;
  }else{
  	ga=1;
  }
  if(b==2)gb=3;
  else if((b==4 ||b==6)||(b==9 || b==11)){
  	gb=2;
  }else{
  	gb=1;
  }
  cout<<(ga==gb?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
int main() {
	char n;
	cin >> n;
	if (n >= 97) {
		cout << "a";
	}
	else {
		cout << "A";
	}
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0;
  cin >> N;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
  }
  ll ans = 0;
  rep(i,N-1){
    if(A[i] > A[i + 1]){
      ans += A[i] - A[i + 1];
      A[i + 1] = A[i];                   
    }
  }
  cout << ans;
}

Measured memory_bytes: 4784
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, K, A):
    tree = SegmentTree(300_300)
    for a in A:
        p = tree.query(max(0, a - K), min(300_300, a + K + 1))
        tree.modify(a, p + 1)
    print(tree.query_all())

class SegmentTree:
    __slots__ = ('__n', '__d', '__f', '__e')

    def __init__(self, n=None, f=max, identity_factory=int, initial_values=None):
        assert(n or initial_values)
        size = n if n else len(initial_values)
        d = [identity_factory() for _ in range(2 * size + 1)]
        self.__n, self.__d, self.__f, self.__e = size, d, f, identity_factory
        if initial_values:
            for i, v in enumerate(initial_values): d[size + i] = v
            for i in range(size - 1, 0, -1): d[i] = f(d[i << 1], d[i << 1 | 1])

    def get_val(self, index):
        return self.__d[index + self.__n]

    def set_val(self, index, new_value):
        i, d, f = index + self.__n, self.__d, self.__f
        if d[i] == new_value: return
        d[i], i = new_value, i >> 1
        while i: d[i], i = f(d[i << 1], d[i << 1 | 1]), i >> 1

    def modify(self, index, value):
        self.set_val(index, self.__f(self.__d[index + self.__n], value))

    def query(self, from_inclusive, to_exclusive):
        ans = self.__e()
        if to_exclusive <= from_inclusive: return ans
        l, r, d, f = from_inclusive + self.__n, to_exclusive + self.__n, self.__d, self.__f
        while l < r:
            if l & 1: ans, l = f(ans, d[l]), l + 1
            if r & 1: ans, r = f(d[r - 1], ans), r - 1
            l, r = l >> 1, r >> 1
        return ans

    def query_all(self):
        return self.__d[1]

    def bisect_left(self, func):
        '''func()がFalseになるもっとも左のindexを探す
        '''
        i, j, n, f, d, v = self.__n, self.__n + self.__n, self.__n, self.__f, self.__d, self.__e()
        while i < j:
            if i & 1:
                nv = f(v, d[i])
                if not func(nv): break
                v, i = nv, i + 1
            i, j = i >> 1, j >> 1
        while i < n:
            nv = f(v, d[i << 1])
            if func(nv): v, i = nv, i << 1 | 1
            else: i = i << 1
        return i - n

if __name__ == '__main__':
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    main(N, K, A)


Measured memory_bytes: 122864
#include"bits/stdc++.h"
using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define nl "\n"
#define sp " "
#define int long long

int32_t main()
{
	FastIO ;
	char ch;
	cin>>ch;
	if(ch>='A' && ch<='Z') cout<<"A";
	else cout<<"a";
	return 0 ;
}


Measured memory_bytes: 3600