akhauriyash/Code-Regression huggingface dataset:
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Numoeba
public class Main{
	
	class R{
		int id, val, pre;
		R parent;
		Set<R> child, copy;
		boolean candidateLeaf;
		public R(int id, int val, R parent) {
			this.id = id;
			pre = this.val = val;
			this.parent = parent;
			child = new HashSet<R>();
			copy = new HashSet<R>();
		}
		void nextVal(){
			pre = val;
			val = 3*val+1;
			while((val&1)==0)val>>=1;
			val%=L;
			candidateLeaf = child.isEmpty() && pre < val;
			for(R r:child)r.nextVal();
		}
		void shrink(){
			if(val==1){
				parent.child.remove(this);
				if(child.size()==1){
					R r = null;
					for(R t:child)r=t;
					r.parent = parent;
					parent.child.add(r);
					r.shrink();
				}
				return;
			}
			copy.clear();
			copy.addAll(child);
			for(R r:copy)r.shrink();
			if(candidateLeaf){
				int k = (val+1)>>1;
				if((k&1)==0)k++;
				child.add(new R(ID++, k, this));
			}
		}
		void findLeader(){
			cnt++;
			if(max < val){
				next = this;
				max = val;
				c = 1;
			}
			else if(max==val)c++;
			for(R r:child)r.findLeader();
		}
		void rev(R p){
			child.remove(p);
			if(parent==null){
				parent = p;
				return;
			}
			parent.rev(this);
			child.add(parent);
			parent = p;
		}
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + id;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			R other = (R) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (id != other.id)
				return false;
			return true;
		}
		private Main getOuterType() {
			return Main.this;
		}
		
	}
	
	int cnt, max, c, ID, L = 12345678;
	R next;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			ID = 0;
			R root = new R(ID++, n, null);
			int res = 1, T = 1;
			for(;;T++){
				root.nextVal();
				if(root.val==1)break;
				root.shrink();
				cnt = max = c = 0;
				next = null;
				root.findLeader();
				if(c==1){
					int k = (next.val+1)>>1;
					if((k&1)==0)k--;
					if(1<k){
						cnt++;
						next.child.add(new R(ID++, k, next));
					}
					root = next;
					if(root.parent!=null){
						root.parent.rev(root);
						root.child.add(root.parent);
						root.parent = null;
					}
				}
				res = Math.max(res, cnt);
			}
			System.out.println(T+" "+res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 16000
using System;

class kyopro
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		int ans = (n+1)*n/2;
		/*for(int i = 1; i <= n; i++)
		{
			ans += i;
		}*/
		
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);
        int INF = Integer.MAX_VALUE/2;

        int n = sc.nextInt();
        int[] kirime = new int[n-1];
        for(int i=0; i<n-1; i++) kirime[i] = sc.nextInt();

        int[][][] dp = new int[2][n/2+1][2]; // dp[お菓子どこまで見たか][Aの所持分][今見ている一片をAとBどちらに取り分けたか];
        for(int i=0; i<2; i++)
            for(int j=0; j<=n/2; j++) Arrays.fill(dp[i][j], INF);
        dp[0][0][1] = 0; //最初の一片をBに取り分ける
        dp[0][1][0] = 0; //Aに取り分ける
        int idx = 1;
        for(int i=1; i<n; i++){
            for(int j=0; j<=n/2; j++){
                int n1 = INF, n2 = INF;
                if(j!=0){
                    n1 = Math.min(dp[1-idx][j-1][0], //(i-1)番目をAのものにした時。
                                  dp[1-idx][j-1][1] + kirime[i-1]); //(i-1)番目をBのものにした時。所持者が変わるのでお菓子を切る。
                }
                n2 = Math.min(dp[1-idx][j][0] + kirime[i-1], //(i-1)番目をAのものにした時。所持者が変わるのでお菓子を切る。
                              dp[1-idx][j][1]); //(i-1)番目をBのものにした時。
                if(j!=0) dp[idx][j][0] = Math.min(dp[idx][j][0], n1);
                dp[idx][j][1] = Math.min(dp[idx][j][1], n2);
            }
            idx = 1-idx;
            for(int j=0; j<=n/2; j++) Arrays.fill(dp[idx][j], INF);
        }
        System.out.println(Math.min(dp[1-idx][n/2][0], dp[1-idx][n/2][1]));
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 37600
import numpy as np
import itertools

def main():
	#N, D = [int(x) for x in input().split()]
	N = int(input())
	c = []
	for i in range(N):
		x, y = [int(x) for x in input().split()]
		c.append([x, y])
	
	c = np.array(c)
	
	patterns = list(itertools.permutations(range(N)))

	a = 0
	dic = {}
	for p in patterns:
		for row in range(N-1):
			if str(p[row])+str(p[row+1]) in dic:
				a += dic[str(p[row])+str(p[row+1])]
				continue
			d = np.linalg.norm(c[p[row]] - c[p[row+1]])
			dic[str(p[row])+str(p[row+1])] = d
			a += d
	print(a/len(patterns))

if __name__ == "__main__":
	main()


Measured memory_bytes: 26396
s = input()
s_l = list(s)
n = len(s_l)
hugs = 0

for i in range(n):
    tail = n-1-i
    if s_l[i] != s_l[tail]:
        hugs += 1
    if (i == tail) or (tail == i + 1):
        break
    
print(hugs)
        

Measured memory_bytes: 2940
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    # a = [v[i] for i in range(n) if i % 2 == 0]
    # b = [v[i] for i in range(n) if i % 2 == 1]

    # a_count = Counter.most_common(Counter(a))
    # b_count = Counter.most_common(Counter(b))

    # half_n = n // 2
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        print(n - ac[0][1] - bc[0][1])
    else:
        if len(bc) == 1 or len(ac) == 1:
            print(n // 2)
        else:
            print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

    # ans = 0

    # half_n = n // 2
    # eq = a_count[0][0] == b_count[0][0]
    # h_ac0 = half_n - a_count[0][1]
    # h_bc0 = half_n - b_count[0][1]

    # if len(a_count) == 1 and len(b_count) == 1:
    #     if eq:
    #         print(half_n)
    #         exit()
    #     else:
    #         print(ans)
    #         exit()

    # if a_count[0][1] > b_count[0][1]:
    #     ans += h_ac0
    #     if eq:
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_bc0
    # elif a_count[0][1] < b_count[0][1]:
    #     ans += h_bc0
    #     if eq:
    #         ans += half_n - a_count[1][1]
    #     else:
    #         ans += h_ac0
    # else:
    #     if eq:
    #         ans += h_ac0
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_ac0
    #         ans += h_bc0
    # print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15588
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int A,B,AB,x,y;
        long ans = 5000*100000*2;
        cin >> A >> B >> AB >> x >> y;
        for (long ab = 0; ab <= 200000; ab+=2) {
                long a = x - ab/2;
                long b = y - ab/2;
                if(a<0) a=0;
                if(b<0) b=0;
                long cost = A*a + B*b + AB * ab;
                if(cost<ans) ans=cost;
        }
        cout << ans <<endl;
        return 0;
}


Measured memory_bytes: 256
import sys
for s in sys.stdin:
  a=map(int,s.split(" "))
  w=a[0]
  a=sorted(a[1:])
  A=[]
  while a:
    A+=[a.pop(0)]
    if a==[]: break
    A=[a.pop()]+A
    if a==[]: break
    A+=[a.pop()]
    if a==[]: break
    A=[a.pop(0)]+A
  a=A[0]+A[-1]
  for i in range(len(A)-1): a+=2*(A[i]*A[i+1])**.5
  print ["OK","NA"][a>w]

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

int main() {
        int n, s, t;
        scanf("%d%d%d", &n, &s, &t);
        s --, t --;
        vector<vector<int>> g(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                scanf("%d %d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<int> depth(n);
        vector<int> par(n);
        function<void (int, int)> dfs = [&](int u, int prev) {
                par[u] = prev;
                for (auto v : g[u]) if (v != prev) {
                        depth[v] = depth[u] + 1;
                        dfs(v, u);
                }
        };
        par[0] = -1;
        dfs(t, -1);
        int l = depth[s] - depth[t];
        int cur = s;
        int up = l % 2 == 0 ? l / 2 - 1 : l / 2;
        while (up --) {
                cur = par[cur];
        }
        int ans = 0;
        function<void (int, int)> dfs2 = [&](int u, int prev) {
                ans = max(ans, depth[u]);
                for (auto v : g[u]) if (v != prev) {
                        dfs2(v, u);
                }
        };
        dfs2(cur, par[cur]);
        ans --;
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 12928
n, y = [int(i) for i in input().split()]
for i in range(n+1):
    for j in range(n-i+1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)


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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  ll ans = 1;
  while (k>0) {
    if(b-a<2||ans<a||k<2) {
      ans++;
      k--;
    }
    else {
      ans += b-a;
      k -= 2;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [x, t] <- map readInt . BS.words <$> BS.getLine
  print $ solve x t

solve :: Int -> Int -> Int
solve x t = max 0 $ x - t

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


Measured memory_bytes: 380
<?php
$rank1 = $rank2 = $rank3 = 0;
for ($i = 0; $i < 10; $i++) {
  $line = readline();
  readline_add_history($line);
  $x = intval($line);
  if ($x > $rank1) {
    $rank3 = $rank2;
    $rank2 = $rank1;
    $rank1 = $x;
  } else if ($x > $rank2) {
    $rank3 = $rank2;
    $rank2 = $x;
  } else if ($x > $rank3) {
    $rank3 = $x;
  }
}
echo "{$rank1}\n{$rank2}\n{$rank3}\n";
?>

Measured memory_bytes: 6520
#include<stdio.h>
int main(){
  int a[10001]={0},i,j,n;
    for(i=2;i<=10000;i++){
      if(a[i]==0){
    for(j=2;i*j<=10000;j++){
      a[i*j]=1;
    }     
      }
    }

    while(1){
      scanf("%d",&n);
      if(n==0)
		  break;
      for(i=n;i>=2;i--){
    if(a[i]==0&&a[i-2]==0){
      printf("%d %d\n",i-2,i);
      break;


    }
      }
    }
    return 0;
}

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

int main() {

    int a, b;
    cin >> a >> b;
    if(a < b) cout << "a < b" <<endl;
    else if(a > b) cout << "a > b" << endl;
    else cout << "a == b" << endl;

}


Measured memory_bytes: 3096
h1,m1,h2,m2,k= list(map(int,input().split()))
t2 = h2*60+m2
t1 = h1*60+m1
owari = t2 - k
benkyou = owari - t1
if benkyou ==0 :
    print("0")
else:
    print(benkyou)

Measured memory_bytes: 9172
#line 1 "test/aoj/GRL_6_A.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A"
#line 2 "test/aoj/../../graph/max-flow-dinic.hpp"
// 蟻本 p.194
#include <vector>
#include <queue>

struct max_flow {
  struct edge { int to, cap, rev; };
  int INF_ = 1<<30;
  int V;
  std::vector<std::vector<edge>> G; // グラフの隣接リスト表現
  std::vector<int> level; // sからの距離
  std::vector<int> iter; // どこまで調べ終わったか
  max_flow(int V): V(V), G(V), level(V), iter(V) {}
  void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});
  }

  // sからの最短距離を計算する
  void bfs(int s) {
    level.assign(V, -1);
    std::queue<int> q;
    level[s] = 0;
    q.push(s);
    while (!q.empty()) { 
      int v = q.front(); q.pop();
      for (int i = 0; i < (int)G[v].size(); ++i) { 
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) { 
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }

  // 増加パスを探す
  int dfs(int v, int t, int f) { 
    if (v == t) return f;
    for (int &i = iter[v]; i < (int)G[v].size(); ++i) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) { 
        int d = dfs(e.to, t, std::min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  // sからtへの最大流を求める
  int run(int s, int t) {
    int flow = 0;
    while (true) {
      bfs(s);
      if (level[t] < 0) return flow;
      // FIXME: ここ毎回初期化しない方法もありそう？
      // https://snuke.hatenablog.com/entry/2019/05/07/013609
      iter.assign(V, 0);
      int f;
      while ((f = dfs(s, t, INF_)) > 0) {
        flow += f;
      }
    }
    return flow;
  }
};
#line 3 "test/aoj/GRL_6_A.test.cpp"

#include <iostream>
using namespace std;

typedef long long ll;

int main() {
  int V, E;
  cin >> V >> E;
  max_flow mf(V);
  for (int i = 0; i < E; ++i) {
    int from, to, cap;
    cin >> from >> to >> cap;
    mf.add_edge(from, to, cap);
  }
  cout << mf.run(0, V-1) << endl;
}



Measured memory_bytes: 3192
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  string a;
  cin>>a;
  int b=0,c=0;
  rep(i,a.size()){
  if(i==0){
  b+=a[0]-49;
   
  }
    else{
    b+=9;
    }
     c+=a[i]-48;
  }
  out(max(b,c));
}

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

using namespace std;

void solve()
{
	int N, L, Q;
	cin >> N;
	vector<int> xs(N);
	for (int i = 0; i < N; i++)
	{
		cin >> xs[i];
	}
	cin >> L >> Q;
	vector<vector<int>> memo(20, vector<int>(N, N));
	for (int i = N-1; i >= 0; i--)
	{
		int ok = i, ng = N;
		while(ok+1 < ng)
		{
			int m = (ok + ng) / 2;
			(xs[i] + L >= xs[m] ? ok : ng) = m;
		}
		memo[0][i] = ok;
		int pos = ok;
		for (int j = 0; j < 19 && pos < N; j++)
		{
			pos = memo[j+1][i] = memo[j][pos];
		}
	}

	while (Q--)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (a > b) swap(a, b);
		int ans = 0;
		while(a < b)
		{
			int ok = 19, ng = 0;
			while(ok > ng+1)
			{
				int m = (ok + ng) / 2;
				(memo[m][a] >= b ? ok : ng) = m;
				//cout << a << ' ' << b << ' ' << ok << ' ' << memo[ok][a] << endl;
			}
			a = memo[ng][a];
			ans += pow(2, ng);
		}
		cout << ans << endl;
	}
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 9080
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[2][n];
		int[][] sum = new int[2][n];
		for(int i=0; i<2; i++){
			a[i][0] = sc.nextInt();
			sum[i][0] = a[i][0];
			for(int j=1; j<n; j++){
				a[i][j] = sc.nextInt();
				sum[i][j] += sum[i][j-1] + a[i][j];
			}
		}
		int max = sum[0][0]+sum[1][n-1];
		for(int i=1; i<n; i++){
			max = Math.max(max, sum[0][i]+sum[1][n-1]-sum[1][i-1]);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int dp[3005][3005][2] = {0};

int__ main() {
	fast;
	int n; cin >> n;
	vi a(n);

	for(int i=0;i<n;i++) {cin >> a[i]; dp[i][i][0] = a[i]; dp[i][i][1] = -a[i];}

	for(int i=n-1;i>=0;i--) {
		for(int j=i+1;j<n;j++) {
			dp[i][j][0] = max(a[i] + dp[i+1][j][1],a[j] + dp[i][j-1][1]);
			dp[i][j][1] = min(-a[i] + dp[i+1][j][0],-a[j] + dp[i][j-1][0]);
		}
	}

	cout << dp[0][n-1][0] << endl;
}

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    rep(i,k){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}

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

int BFS(const vector<string> &board){
  using coord= pair<int, int>;
  constexpr char block= '#';
  constexpr int TBC= INT_MAX;
  const vector<coord> diff= {make_pair(1,0), make_pair(0,1)};

  const int H= board.size();
  const int W= board.at(0).size();
  const coord start= make_pair(0, 0);
  const coord goal = make_pair(H-1, W-1);

  vector<vector<int>> dist(H, vector<int>(W, TBC));
  dist.at(0).at(0)= (board.at(0).at(0)==block) ? 1
                                               : 0;
  deque<coord> bfs;
  bfs.push_front(start);
  while( !bfs.empty() ){
    coord p= bfs.front();
    bfs.pop_front();
    int x,y;
    tie(x,y)= p;
    for(auto &ds:diff){
      int dx,dy;
      tie(dx,dy)= ds;
      if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) continue;
      else if(dist.at(x+dx).at(y+dy) > dist.at(x).at(y)+ 1 && board.at(x+dx).at(y+dy)==block && board.at(x).at(y) != block){
        dist.at(x+dx).at(y+dy)= dist.at(x).at(y)+ 1;
        bfs.push_back(make_pair(x+dx, y+dy));
      }
      else if(dist.at(x+dx).at(y+dy) > dist.at(x).at(y) && !(board.at(x+dx).at(y+dy)==block && board.at(x).at(y) != block)){
        dist.at(x+dx).at(y+dy)= dist.at(x).at(y);
        bfs.push_front(make_pair(x+dx, y+dy));
      }
    }
  }

  return dist.back().back();
}

int main(){
  int H,W;
  cin >> H >> W;

  vector<string> data(H);
  for(int i=0; i<H; i++){
    cin >> data.at(i);
  }

  int ans= BFS(data);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

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

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H;
		int W;
		
		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();
			StringBuilder sb = new StringBuilder();
			
			//0 0?????????
			if (H ==0 && W ==0) {
				break;
			}
			

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if(i==0 || i==H-1 || j==0 || j==W-1){
						sb.append("#");
					}
					else {
						sb.append(".");
					}
				}
				//?¬??????????????????????
				sb.append("\n");
			}
			//??????
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 20768
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n, x;
  cin >> n >> x;
  int cnt = 0;
  int t = 0;
  vi l(n);
  rep(i, n) cin >> l[i];
  int i = 0;
  while (t <= x) {
    cnt++;
    if (i <= n - 1) {
      t = t + l[i];
      i++;
    } else {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int a[100000+10];
int main()
{
    int n,c=0;
    long long int i,s=1,b[6];
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==a[i-1])
        {c++;
        s*=a[i];
        a[i-1]=0;}
        if(c==2) break;
    }
    if(c>=2) cout<<s<<endl;
    else cout<<'0'<<endl;
}

Measured memory_bytes: 1024
//abc158_d.cpp
//Sat Mar  7 20:43:24 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	int q;
	cin >> q;

	int sdir = 0;
	string sento;
	string matsu;
	for (int i=0;i<q;i++){
		int t;
		cin >> t;
		if (t==1){
			sdir++;
		}else {
			int f;
			cin>>f;
			char c;
			cin >> c;
			if (f==1){
				if (sdir%2==0){
					sento+=c;
				}else {
					matsu+=c;
				}
			}else {
				if (sdir%2==0){
					matsu+=c;
				}else {
					sento+=c;
				}
			}
		}
	}

	if (sdir%2==0){
		reverse(sento.begin(),sento.end());
		cout << sento << s << matsu <<endl;
	}else {
		reverse(s.begin(),s.end());
		reverse(matsu.begin(),matsu.end());
		cout << matsu << s << sento << endl;
	}
}

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

using namespace std;

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define in insert
#define sz(x) (int) x.size()
#define sqr(x) ((x) * (x))
#define fi first
#define se second

template<typename T>
void vout(T x) {
    cout << x << endl;
    exit(0);
}

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

const int inf = 1e9 + 1;
const ll INF = 1e18 + 1e2;
const int mod = 1e9 + 7;

int main() {
    fast_io

    int n; cin >> n; n %= 10;
    if(n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon";
    } else if(n == 3) {
        cout << "bon";
    } else {
        cout << "hon";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3660
N = int(input())
K = int(input())
x = list(map(int, input().split()))

sum = 0

for i in range(N):
  if x[i] >= K - x[i]:
    sum += 2 * (K - x[i])
  
  else:
    sum += 2 * x[i]

print(sum)

Measured memory_bytes: 9004
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var split = Console.ReadLine().Split(' ');
		var a = new List<int>();
		for(int i=0;i<n;i++){
			a.Add(int.Parse(split[i]));
		}
		var min = a.Min();
		while(a.Count(x=>x%min!=0) != 0){
			min = a.Select(x=>x%min).Where(x=>x!=0).Min();
		}
		Console.WriteLine(min);
	}
}


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

int main()
{
   #ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
  #endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


   
   
      int x;
      cin>>x;

      for(int i=1;i<=x;i++)
      {
        int m=360*i;

        if(m%x==0) {
          cout<<m/x<<endl;
          break;
        }
      }
  
} 





Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>

using namespace std;

int ara[200000];

int main(void)

{
    int i, j, N, K, Q;
    scanf("%d%d%d", &N, &K, &Q);

    for(i = 0; i < Q; i++){
        scanf("%d", &j);
        ara[j]++;
    }
    for(i = 1; i <= N; i++){
        if(K-Q+ara[i] >= 1){
            printf("Yes\n");
        }
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll N, M;
	cin >> N >> M;
	ll a, b;
	vector<ll> es[N];
	vector<bool> use(N, false);
	rep(M){
		cin >> a >> b;
		a--; b--;
		es[a].push_back(b);
		es[b].push_back(a);
	}
	
	vector<ll> ans;
	ans.push_back(0);
	use[0] = true;
	while(true){
		bool flag = true;
		for(ll to : es[ans[0]]){
			if(!use[to]){
				flag = false;
				use[to] = true;
				ans.insert(ans.begin(), to);
				break;
			}
		}
		for(ll to : es[(int)ans.back()]){
			if(!use[to]){
				flag = false;
				use[to] = true;
				ans.push_back(to);
				break;
			}
		}
		if(flag) break;
	}
	
	cout << (ll)ans.size() << endl;
	rep((int)ans.size()-1){
		cout << ans[i]+1 <<  " ";
	}
	cout << ans.back()+1;
}


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

const int maxn = 6010;
int n, L[maxn], R[maxn], sum[maxn];
char s[maxn], t[maxn];

int main() {
    scanf("%s %s", s + 1, t + 1), n = strlen(s + 1);
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
        t[i + n] = t[i + n + n] = t[i];
        if (t[i] == '1') flag = 0;
    }
    if (flag) {
        for (int i = 1; i <= n; i++) {
            if (s[i] == '1') printf("-1\n"), exit(0);
        }
        printf("0\n"), exit(0);
    }
    L[0] = -1e9, R[3 * n + 1] = 1e9;
    for (int i = 1; i <= 3 * n; i++) {
        L[i] = t[i] == '1' ? i : L[i - 1];
        sum[i] = sum[i - 1] + t[i] - '0';
    }
    for (int i = 3 * n; i; i--) {
        R[i] = t[i] == '1' ? i : R[i + 1];
    }
    int ans = 1e9;
    for (int i = -n; i <= n; i++) {
        int num = 0;
        vector<pair<int, int>> V;
        for (int j = 1; j <= n; j++) {
            if (s[j] == t[i + j + n]) continue;
            int l = i + j + n, r = j + n; num++;
            if (l > r) swap(l, r);
            if (sum[l - 1] == sum[r]) {
                V.push_back(make_pair(l - L[l], R[r] - r));
            }
        }
        V.push_back({0, 0});
        sort(V.begin(), V.end()), reverse(V.begin(), V.end());
        int mx = 0;
        for (auto p : V) {
            if (max(p.first, mx) <= 1e8) ans = min(ans, 2 * (p.first + mx) + abs(i) + num);
            mx = max(mx, p.second);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
using namespace std;
int main() {
	while (true) {
		int n;
		int a[100] = { 0 };
		scanf("%d", &n);
		if (n == 0) break;
		char b[100];
		vector<int> player;
		int stage = 0;
		int nowplay = 0;
		scanf("%s", &b);
		for (int i = 0;i < n;++i) {
			player.push_back(0);
		}
		for (int i = 0;i < 100;++i) {
			if (b[i] == 'M') {
				player[nowplay]++;
			}
			else if (b[i] == 'S') {
				stage += 1 + player[nowplay];
				player[nowplay] = 0;
			}
			else {
				player[nowplay] += stage + 1;
				stage = 0;
			}
			nowplay++;
			if (nowplay == n) nowplay = 0;
		}
		sort(player.begin(), player.end());
		for (int i = 0;i < n;++i) {
			printf("%d ", player[i]);
		}
		printf("%d\n", stage);
	}
}


Measured memory_bytes: 1056
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
s = [K-Q]*N

for i in range(Q):
    s[A[i]-1] += 1

for i in range(N):
    if s[i] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 10472
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
}c[200005];
int cmp(node x,node y){
	if(x.b==y.b)
		return x.a>y.a;
	return x.b<y.b;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%d%d",&c[i].a,&c[i].b);
	long long ans=0;
	sort(c,c+n,cmp);
	int f=0;
	for(int i=0;i<n;i++){
		ans+=c[i].a;
		if(ans>c[i].b){
			f=1;
			break;
		}
	}
	if(f)
		puts("No");
	else puts("Yes");
} 

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  string s;
  cin >> s;

  for (char c = 'a'; c <= 'z'; ++c) {
    if (s.find(c) + 1) continue;
    else {
      cout << c << "\n";
      return 0;
    }
  }

  cout << "None" << "\n";

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s;cin >> s;
    if(s[2]==s[3]&&s[4]==s[5])cout << "Yes" <<endl;
    else cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {                                                                
    const int START = 500;                                                      
    int n, anssize;                                                             
    char xstr[1000], ystr[1000], answer[1000];                                  
                                                                                
    scanf("%d", &n);                                                            
    while (n > 0) {                                                             
        anssize = 999;                                                          
        answer[anssize--] = '\0';                                               
        memset(xstr, '0', 1000);                                                
        memset(ystr, '0', 1000);                                                
        scanf("%s", &xstr[START]);                                              
        scanf("%s", &ystr[START]);                                              
        int xsize = strlen(&xstr[START]) - 1;                                   
        int ysize = strlen(&ystr[START]) - 1;                                   
        int carry = 0;                                                          
        while (xsize >= 0 || ysize >= 0) {                                      
            int x = xstr[START + xsize--] - '0' + ystr[START + ysize--] - '0' +\
 carry;                                                                         
            answer[anssize--] = (x % 10) + '0';                                 
            carry = x / 10;                                                             }                                                                       
        if (carry) {                                                                        answer[anssize--] = '1';                                            
        }                                                                       
        if (anssize > 917) {                                                    
            printf("%s\n", &answer[anssize+1]);                                 
        } else {                                                                
            printf("overflow\n");                                               
        }                                                                       
        n--;                                                                    
    }                                                                           
    return 0;                                                                   
}

Measured memory_bytes: 588
import java.util.Scanner;





public class Main {
	static class P{
		double x,y;
		P(double x, double y)
		{
			this.x = x;
			this.y = y;
		}
	}
	
	static void kock(int n,P p1, P p2)
	{
		if(n==0)
		{
			return;
		}
		
		P s=new P(0.0, 0.0);
		P t=new P(0.0, 0.0);
		P u=new P(0.0, 0.0);
		
		s.x=(2.0*p1.x+p2.x)/3.0;
		s.y=(2.0*p1.y+p2.y)/3.0;
		t.x=(p1.x+2.0*p2.x)/3.0;
		t.y=(p1.y+2.0*p2.y)/3.0;
		u.x=(t.x-s.x)/2.0 - (t.y-s.y)*Math.sqrt(3.0)/2.0+s.x;
		u.y=(t.x-s.x)*Math.sqrt(3.0)/2.0 + (t.y-s.y)/2.0+s.y;
		
		kock(n-1, p1, s);
		System.out.println(s.x+" "+s.y);
		kock(n-1, s, u);
		System.out.println(u.x+" "+u.y);
		kock(n-1, u, t);
		System.out.println(t.x+" "+t.y);
		kock(n-1, t, p2);
	}
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();
			System.out.println(0.000000+" "+0.0000000);
			kock(n, new P(0.0, 0.0), new P(100.0, 0.0));
			System.out.println(100.000000+" "+0.000000);
		}
	}
}



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

int main() {
    int N; cin >> N;
    LL ans = 0;
    for (int a = 1; a < N; a++) {
        ans += (N - 1) / a;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;

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

int main(){
	ll N,x; cin>>N>>x;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];
	ll ans=0;
	rep(i,N-1){
		if(A[i]>x){
			ans+=A[i]-x;
			A[i]=x;
		}
		if(A[i]+A[i+1]>x){
			ans+=A[i]+A[i+1]-x;
			A[i+1]-=A[i]+A[i+1]-x;
		}
	}
	cout<<ans;
}

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

int main(){
    ll a, b;
    ll x;
    cin >> a >> b >> x;

    double z = double(2.0 * x) / double(a * b);
    double harf = double(a * a * b) / 2.0;
    double k = M_PI;
    double ans = 0.0;

    if(harf >= x){
        ans = atan(b / z) * 180 / k;
    }else{
        double height = double(x / a) / a;
        double len = double(b) - height;
        harf = a * a * b - x;
        z = (2.0 * harf) / (a * a);
        ans = atan(z / a) * 180 / k;
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int c[26] = {};
  bool f = true;
  string w;cin >> w;
  int i;
  for(i=0;i<w.size();i++) c[w[i]-'a']++;
  for(i=0;i<26;i++) f&=(c[i]%2==0);
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <complex>
#include <vector>

using namespace std;
typedef complex<double> P;
int main(){
  int n;
  P p1(0.0,1.0),p2(0.0,-1.0);
  while(scanf("%d",&n)&&n){
    P p[n];
    double x,y;
    for(int i=0;i<n;++i){
      scanf("%lf,%lf",&x,&y);
      p[i].real()=x;p[i].imag()=y;
    }
    int a=1;
    for(int i=0;i<n;++i){
      for(int j=i+1;j<n;++j){
	vector<P> v;
	P c((p[i].real()+p[j].real())/2,(p[i].imag()+p[j].imag())/2);
	if(abs(p[i]-p[j])==2.0)  v.push_back(c);
	else if(abs(p[i]-p[j])<2.0){
	  P va=p[i]-p[j];
	  P x1=(va*p1)/abs(va);
	  P x2=(va*p2)/abs(va);
	  double l=sqrt(1-abs(va)*abs(va)/4);
	  P c1=c+x1*l;
	  P c2=c+x2*l;
	  v.push_back(c1);v.push_back(c2);
	}
	if(v.empty()) continue;
	int m1=2;
	int m2=2;
	for(int k=0;k<n;++k){
	  if(i!=k&&j!=k&&abs(v[0]-p[k])<=1.0) m1++;
	  if(i!=k&&j!=k&&abs(v[1]-p[k])<=1.0) m2++;
	  a=max(a,max(m1,m2));
	}
      }
    }
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 1092
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n;
	
	cin >> n;

	int a[n];
	//map<int, int> m;
	int c[100010];
	memset(c, 0, sizeof(c));

	rep(i, n)
	{
		cin >> a[i];
		//map[a[i]]++;
		c[a[i]]++;
		if (a[i] > 0)
		{
			c[a[i] - 1]++;
		}
		
		c[a[i]+1]++;
	}

	//sort(a, a+n);
	/*
	map<int, int> m;

	rep(i, n)
	{
		if (i == 0)
		{
			m[a[i]] = 0;
		}
		else
		{
			if (m[a[i]] == 0)
			{
				m[a[i]] = i;
			}
		}
	}

	map<int, int>::iterator it = map.begin();
	int max_s = 0;

	for(int i = 0; i < n; i++)
	{
		int next_a = a[i] + 1;
		int next_na  = a[i] + 2;

		if (m.find(next_na) != m.end())
	}
	*/

	/*
	int max_s = 0;

	for(int i = 0; i < n; i++)
	{
		int next_a = a[i] + 1;
		int next_na  = a[i] + 2;

		if (m.find(next_na) != m.end())
		{

		}
	}
	*/

	int max_s = 0;
	for (int i = 0; i < 100000; i++)
	{
		if (c[i] > max_s)
		{
			max_s = c[i];
		}
	}

	cout << max_s << endl;

	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	int k, x;
	cin >> k >> x;
	k--;
	for (int i = max(-1000000, x - k); i <= min(1000000, x + k); ++i)
		cout << i << " ";
	cout << endl;
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(a, b);

    cout << max(0LL, a-b-b) << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter 
def main():
    N = int(readline())
    tasks = []
    for _ in range(N):
        a, b = map(int, readline().split())
        tasks.append((a, b))
    tasks.sort(key=itemgetter(1))
    time = 0
    for a, b in tasks:
        time += a
        if time > b:
            print('No')
            return  
    print('Yes')
if __name__ == '__main__':
    main()


Measured memory_bytes: 31828
wall = "#" * 20
n = int(input())
dat = []
for _ in range(12):
    dat.append([0] * 10)

for _ in range(n):
    b,f,r,v = map(int, input().split())
    dat[3 * (b - 1) + ( f-1)][r - 1] += v
for i in range(12):
    print(" ",end="")
    print(" ".join(map(str, dat[i])))
    if i % 3 == 2 and i!=11:
        print(wall)



Measured memory_bytes: 5604
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int r, c;
class T {
public:
    int mode, v, ope;
    bool operator<(const T&a)
    {
        return v < a.v;
    }
};
int getnum(int x, int y)
{
    if (y == 0)
        return x;
    else if (x == 0)
        return r + r + c + c - y;
    else if (x == c)
        return x + y;
    else if (y == r)
        return r + c + c - x;
    else return -1;
}

vector<T>a;
stack<int>sve;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i, j, k, m, n;
    int x1, x2, y1, y2;
    cin >> r >> c >> n;
    int tempa, tempb;
    for (int i = 1; i <= n; ++i)
    {
        cin >> y1 >> x1 >> y2 >> x2;
        tempa = getnum(x1, y1);
        tempb = getnum(x2, y2);
        if (tempb == -1 || tempa == -1)continue;
        if (tempb < tempa)swap(tempa, tempb);
        a.push_back({ 1,tempa,tempb });
        a.push_back({ 2,tempb,tempa });
    }
    sort(all(a));
    for (int i = 0; i < a.size(); ++i)
    {
        if (a[i].mode == 1)
            sve.push(a[i].ope);
        else if (sve.top() == a[i].v)
                sve.pop();
        else
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;
#define ll long long int

void solve(){

	int N,n=1000;
	cin>>N;
    
    while(n<N){
    	n=n+1000;
    }

    cout<<n-N<<"\n";

}




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

    
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

   
    solve();
   
    return 0;
}


Measured memory_bytes: 3652
def ge():
    return map(int,input().split())
def main():
    a,b,c,d=ge()
    #a=list(map(int,input().split()))
    #a=input()
    #a=int(input())
    ans=max(a*c,a*d,b*c,b*d)
    print(ans)

main()

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

int main() {
	char b; cin >> b;
	if (b == 'A') cout << 'T' << endl;
	else if (b == 'T') cout << 'A' << endl;
	else if (b == 'G') cout << 'C' << endl;
	else if (b == 'C') cout << 'G' << endl;
}

Measured memory_bytes: 256