akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

vector<vector<int>> g;
int n;
vector<int> d;
vector<int> p;
vector<int> h;



int dfs(int v, int parent = -1) {
	p[v] = parent;
	for (int w : g[v]) {
	    if (w != parent) {
			h[w] = h[v] + 1;
			d[v] = max(d[v], 1 + dfs(w, v));
		}
	}
	return d[v];
}


int solve(int d, int h1, int h2) {
   if (h2 == h1) return 0;
   int ans = 0;
   ans += d;
   ans += (h2 - h1) / 2;
   return ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	int u, v;
	cin >> u >> v;
	--u;
	--v;
	g.assign(n, vector<int>{});
	
	for (int i = 0; i < n - 1; ++i) {
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		g[x].pb(y);
		g[y].pb(x);
	}
	
	h.assign(n, 0);
	d.assign(n, 0);
	p.assign(n, -1);
	
	dfs(v);
	int x = u;
	int ans = 0;
	
	while (x != -1) {
	    if (h[u] - h[x] > h[x]) break; 
		int res = h[u] - h[x];
		res += solve(d[x], h[u] - h[x], h[x]);
		ans = max(ans, res);
		x = p[x];
	}
	
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12032
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int[] d=new int[n];
		for (int i=0;i<n;++i) {
			d[i]=Integer.parseInt(scan.next());
		}
		Arrays.parallelSort(d);
		if (d[n/2]==d[n/2-1]) {
			System.out.print(0);
		}else {
			System.out.print(d[n/2]-d[n/2-1]);
		}
		
}
}
//end

Measured memory_bytes: 49008
from collections import deque
import math

def main():
    N=int(input())
    A=list(map(int,input().split()))

    A.sort(reverse=True)

    Amax=max(A)

    dp=[0]*Amax

    tmp=-1
    res=0
    for i in range(len(A)):
        a=A.pop()
        if a==tmp:
            continue
        if dp[a-1]==0:
            if len(A)>0:
                if A[len(A)-1]!=a:
                    res+=1
            else:
                res+=1
            m=2
            while (a*m)<=Amax:
                dp[a*m-1]=1
                m+=1
        tmp=a

    print(res)
if __name__=="__main__":
    main()

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

a,b = map(int,read().split())

if a > 0:
    print('Positive')
    exit()

if a <= 0 and 0 <= b:
    print('Zero')
    exit()

x = b - a + 1
if x & 1:
    print('Negative')
else:
    print('Positive')

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

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ')
            .Select(x => Int32.Parse(x)).ToArray();
        var a = l[0]; var b = l[1]; var c = l[2]; var d = l[3];
        var tl = a / d;
        if (a % d != 0) tl++;
        var al = c / b;
        if (c % b != 0) al++;
        if (tl >= al) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


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

int main() {
	int N, W;
	cin >> N >> W;
	vector<ll> w(N + 1);
	vector<ll> v(N + 1);
	for (int i = 1; i <= N; ++i) {
		cin >> w[i] >> v[i];
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= W; ++j) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j + w[i] <= W) {dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
			}
		}
	}

	ll res = 0;
	for (int i = 0; i <= W; ++i) {
		res = max(res, dp[N][i]);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 80256
for i in range(50):
    m,f,r = map(int,input().split())
    if m == f == r == -1:
        break
    if m == -1 or f == -1 or m+f < 30:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50 or r >= 50:
        print("C")
    else:
        print("D")
     
    


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


int main(){
ll k;
cin>>k;

set<ll>s;
for(ll i=0;i<k;i++)
{
    ll l;
    cin>>l;
    s.insert(l);
}
ll k1=s.size();
if(k!=k1)
{
    cout<<"NO";
}
else
{
    cout<<"YES";
}
    
}


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

int main(void){
    int n;
    cin>>n;
    
    vector<unsigned long long int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    
    bool bb=true;
    int cnt=0;
    
    while(bb){
        for(int i=0; i<n; i++){
            if(a[i]%2==1){
                bb=false;
            }
        }
        
        if(bb){
            for(int i=0; i<n; i++){
                a[i]>>=1;
            }
            cnt++;
        }
    }
    
    cout<<cnt<<endl;
    

}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    
    for(int i = 0; i < n/2; i++) {
        if(s[i] != s[n-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i < n/4; i++) {
        if(s[i] != s[n/2-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    int j = 0;
    for(int i = n/2+1; i < n/2+1+n/4; i++, j++) {
        if(s[i] != s[n-1-j]) {
            cout << "No" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [0]*m
r = [0]*m
for i in range(m):
    l[i], r[i] = map(int, input().split())
cnt = 0
l_max = max(l[:m])
r_min = min(r[:m])
for i in range(n):
    if l_max <= i+1 <= r_min:
        cnt += 1
print(cnt)

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

namespace AtCoderPre
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var W = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int[] T = new int[N];
            int W_sum = W.Sum();

            for (int i =0; i < N; i++)
            {
                int[] b = new int[i+1];
                Array.Copy(W, 0, b, 0, i+1);
                T[i] = Math.Abs(2 * b.Sum() - W_sum);
                //Console.WriteLine(T[i]);

            }

            Console.WriteLine(T.Min());


            
        }

    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  int k,n;
  cin >> n >> k;
  cout << n - k + 1 <<endl;
}

Measured memory_bytes: 256
import sys
from sys import stdin,setrecursionlimit
sys.setrecursionlimit(10**6)
input=stdin.readline
#import pysnooper

class Weighted_Union_find:
    
    def __init__(self,n):
        self.n=n
        self.root=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
        self.weight=[0]*(n+1)

    #@pysnooper.snoop()
    def find_root(self,x):# 頂点xのroot(根)頂点を見つける
        if self.root[x]==x:
            return x
        else:
            y=self.find_root(self.root[x])
            self.weight[x]+=self.weight[self.root[x]]
            self.root[x]=y
            return y
    #@pysnooper.snoop()
    def unite(self,x,y,w):#頂点xと頂点yを繋ぐ辺を追加
        rx=self.find_root(x)
        ry=self.find_root(y)
        if rx==ry:
            return 0
        if self.rank[rx]<self.rank[ry]:
            self.root[rx]=ry
            self.weight[rx]=w-self.weight[x]+self.weight[y]
        else:
            self.root[ry]=rx
            self.weight[ry]=-w-self.weight[y]+self.weight[x]
            if self.rank[rx]==self.rank[ry]:
                self.rank[rx]+=1

    def same(self,x,y):#頂点xと頂点yが連結であるか判定
        return self.find_root(x)==self.find_root(y)

    def count(self,x):#頂点xが属する木のサイズ
        return -self.root[self.find_root(x)]
    
    def diff(self,x,y):#頂点xから頂点yへのコスト
        return self.weight[x]-self.weight[y]

#@pysnooper.snoop()
def main():
    n,q=map(int,input().split())
    gragh=Weighted_Union_find(n+1)
    for _ in range(q):
        query=tuple(map(int,input().split()))
        if not query[0]:
            gragh.unite(query[1],query[2],query[3])
        else:
            if gragh.same(query[1],query[2]):
                print(gragh.diff(query[1],query[2]))
            else:
                print("?")
    #print(1111111111111111)
main()


Measured memory_bytes: 12796
#include <iostream>

using namespace std;

char A[5] = {};

int main() {
	cin >> A;
	for (int i = 0; i <= 3; i++)A[i] -= '0';
	if (A[0] + A[1] + A[2] + A[3] == 7) {
		cout << A[0] + 0 << "+" << A[1] + 0 << "+" << A[2] + 0 << "+" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] + A[1] + A[2] - A[3] == 7) {
		cout << A[0] + 0 << "+" << A[1] + 0 << "+" << A[2] + 0 << "-" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] + A[1] - A[2] + A[3] == 7) {
		cout << A[0] + 0 << "+" << A[1] + 0 << "-" << A[2] + 0 << "+" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] + A[1] - A[2] - A[3] == 7) {
		cout << A[0] + 0 << "+" << A[1] + 0 << "-" << A[2] + 0 << "-" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] - A[1] + A[2] + A[3] == 7) {
		cout << A[0] + 0 << "-" << A[1] + 0 << "+" << A[2] + 0 << "+" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] - A[1] + A[2] - A[3] == 7) {
		cout << A[0] + 0 << "-" << A[1] + 0 << "+" << A[2] + 0 << "-" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] - A[1] - A[2] + A[3] == 7) {
		cout << A[0] + 0 << "-" << A[1] + 0 << "-" << A[2] + 0 << "+" << A[3] + 0 << "=7" << endl;
		return 0;
	}
	if (A[0] - A[1] - A[2] - A[3] == 7) {
		cout << A[0] + 0 << "-" << A[1] + 0 << "-" << A[2] + 0 << "-" << A[3] + 0 << "=7" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

bool solve() {
    ll a, b, c, d;
    std::cin >> a >> b >> c >> d;
    if (a < b) return false;
    if (d < b) return false;
    if (b <= c) return true;
    ll g = gcd(d, b);
    ll m = a % g;
    ll l = c - a, r = b - a;
    if (g <= r - l - 1) return false;
    l = (g + l % g) % g;
    r = (g + r % g) % g;
    return !(0 < r && r < l);
}

int main() {
    ll t;
    std::cin >> t;
    while (t--) std::cout << (solve() ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] arg)
    {
        Console.ReadLine();
        string[] tmp = Regex.Split(Console.ReadLine(), @"\s+");

        int tmpnum = Convert.ToInt32(tmp[tmp.Length - 1]);
        int tmpvalue;
        bool flag = true;
        for (int i = tmp.Length - 2; i >= 0; --i)
        {
            tmpvalue = Convert.ToInt32(tmp[i]);
            if (tmpvalue - tmpnum > 1)
            {
                flag = false;
                break;
            }
            else if (tmpvalue - tmpnum > 0)
            {
                tmpnum = (tmpvalue - 1);
            }
            else
            {
                tmpnum = tmpvalue;
            }
        }
        Console.WriteLine((flag) ? "Yes" : "No");
    }
}


Measured memory_bytes: 33340
#include<cstdio>
#include<cstring>
char s[100100],t[100100];
long long gcd(long long x,long long y)
{
    if(!y)
        return x;
    return gcd(y,x%y);
}
int main()
{
    long long n,m;
    scanf("%lld%lld",&n,&m);
    scanf("%s",s+1);
    scanf("%s",t+1);
    long long Gcd=gcd(n,m);
    int N=n/Gcd;
    int M=m/Gcd;
    for(int i=1,j=1;i<=n,j<=m;i+=N,j+=M)
        if(s[i]!=t[j])
        {
            puts("-1");
            return 0;
        }
    printf("%lld\n",n*m/Gcd);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

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

#define n_size 500

vector<bool> prime_list(int MAX_N){

    vector<bool> is_prime(MAX_N + 1, true);

    is_prime[0] = false;
    is_prime[1] = false;

    FOR(i, 2, MAX_N + 1){
        if(is_prime[i]){
            int tmp = i * 2;
            while(tmp <= MAX_N){
                is_prime[tmp] = false;
                tmp += i;
            }
        }
    }

    return is_prime;
}

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int lcm(int a, int b){
    int x, y;
    int g = extgcd(a, b, x, y);
    a /= g;
    return a * b;
}

int lcm_multi(vec a){
    int p = a[0];
    FOR(i, 1, a.size()) p = lcm(p, a[i]);
    return p;
}

signed main(){

    vector<bool> is_prime = prime_list(100000);
    vec primes(0);
    FOR(i, n_size, is_prime.size()){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
    //cout << primes.size() << endl; 9497

    int ans[n_size][n_size];
    set<int> s;

    REP(i, n_size){
        REP(j, n_size){
            if((i - j) % 2 != 0) continue;
            ans[i][j] = (min(i, j) + 1) * primes[(j - i + n_size) / 2];
            s.insert(ans[i][j]);
        }
    }

    //int maxv = 0;

    REP(j, n_size){
        REP(i, n_size){
            if((i - j) % 2 == 0) continue;
            vec a(0);
            if(i > 0) a.push_back(ans[i - 1][j]);
            if(j > 0) a.push_back(ans[i][j - 1]);
            if(i < n_size - 1) a.push_back(ans[i + 1][j]);
            if(j < n_size - 1) a.push_back(ans[i][j + 1]);
            int p = lcm_multi(a);
            int n = 1;
            while(s.count(n * p + 1)) n++;
            ans[i][j] = n * p + 1;
            s.insert(ans[i][j]);
            //maxv = max(maxv, ans[i][j]);
        }
    }

    //cout << maxv << endl;


    /*
    set<int> s2;
    REP(i, n_size){
        REP(j, n_size){
            if(s2.count(ans[i][j]) > 0) cout << ans[i][j] << endl;
            s2.insert(ans[i][j]);
        }
    }
    */

   int N; cin >> N;
   REP(i, N){
       REP(j, N){
           cout << ans[i][j] << " ";
           //if(ans[i][j] < 1 || ans[i][j] > 1000000000000000) cout << ans[i][j] << endl;
       }
       cout << endl;
   }

    
    return 0;
}


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

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

int main () {
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }

    }
    cout<<"NG";
    
}

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


int main(void) {
  int a, b, c;
  cin >> a >> b >> c;

  for (ll i = 1; i < 100000; i++) {
    if ((a * i) % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;ll ans=0;cin>>s>>t;
  rep(i,3) if(s[i]==t[i]) ans++;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

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

	int sum = a + b + c + d;
	cout << (sum / 60) << endl << (sum % 60) << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 10000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
	int n;
	cin >> n;
	int odd = 0, even = 0, m4 = 0;
	REP(i, n){
		int a;
		cin >> a;
		if(a % 4 == 0) m4++;
		else if(a % 2 == 0) even++;
		else odd++;
	}
	if((m4 + 1) > odd) cout << "Yes" << endl;
	else if((m4 + 1) == odd && even == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N, M;
    cin >> N >> M;
    int a[51], b[51], c[51], d[51];
    a[0] = b[0] = N, c[0] = d[0] = M;

    REP(i, 1, a[0]+1) {
        cin >> a[i] >> b[i];
    }
    REP(i, 1, c[0]+1) {
        cin >> c[i] >> d[i];
    }

    REP(i, 1, a[0]+1) {
        int dist = abs(a[i]-c[1]) + abs(b[i]-d[1]);
        int p = 1;
        REP(j, 2, c[0]+1) {
            int dist_j = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if (dist > dist_j) {
                dist = dist_j;
                p = j;
            }
        }
        cout << p << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int MOD = 10000;

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

    vector<int> decide(n+1, -1);
    for(int i=0; i<k; ++i){
        int a, b;
        cin >> a >> b;
        decide[a] = b;
    }

    vector<vector<int> > dp(n+1, vector<int>(16, 0));
    dp[0][0] = 1;
    for(int i=0; i<n; ++i){
        for(int j=0; j<16; ++j){
            int a = j / 4;
            int b = j % 4;

            for(int c=1; c<=3; ++c){
                if(decide[i+1] != -1 && decide[i+1] != c)
                    continue;
                if(a == b && b == c)
                    continue;
                dp[i+1][b*4+c] += dp[i][j];
                dp[i+1][b*4+c] %= MOD;
            }
        }
    }

    int ret = accumulate(dp[n].begin(), dp[n].end(), 0);
    ret %= MOD;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 0
fun main(args:Array<String>){
    val (w,h,n)=readInts()
    var (a,b,c,d)=listOf(0,0,w,h)
    for(i in 0 until n){
        val(x,y,z)=readInts()
        when(z){
            1->a=Math.max(a,x)
            2->c=Math.min(c,x)
            3->b=Math.max(b,y)
            4->d=Math.min(d,y)
        }
    }
    if(a>c||b>d){
        println(0)
    }else{
        println((c-a)*(d-b))
    }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }

Measured memory_bytes: 37996
n, m, c = map(int, input().split())
b_list = list(map(int, input().split()))
ans = 0
for i in range(n):
    check = 0
    a_list = list(map(int, input().split()))
    for k in range(m):
        check += a_list[k] * b_list[k]
    if check + c > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      int u,k;
      cin>>u>>k;
      string a,b;
      a=to_string(u);
      b=to_string(k);
      string x="",y="";
      REP(i,u)
      y+=b;
      REP(i,k)
      x+=a;
      if(x<y)cout<<x;
      else cout<<y;  
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    constexpr int m = 3;
    int p[m][m];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            cin >> p[i][j];
        }
    }

    int n;
    cin >> n;

    vector<int> b(n);
    for (int h = 0; h < n; h++) {
        cin >> b[h];
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            for (int h = 0; h < n; h++) {
                if (b[h] == p[i][j]) p[i][j] = 0;
            }
        }
    }

    int r = 0;
    for (int i = 0; i < m; i++) {
        if (p[i][0] + p[i][1] + p[i][2] == 0) r++;
        if (p[0][i] + p[1][i] + p[2][i] == 0) r++;
    }
    if (p[0][0] + p[1][1] + p[2][2] == 0) r++;
    if (p[0][2] + p[1][1] + p[2][0] == 0) r++;

    cout << (r ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    lint n;
    cin >> n;
    lint ans = 1;
    for (lint i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans = i;
        }
    }
    cout << ans + n / ans - 2 << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = str(input())
S_list = []
cum_list = [0]
tmp = 1
count = 0

for i in range(N):
    if i == 0:
        if int(S[i]) == tmp:
             count += 1
        else:
            S_list.append(count)
            count = 1
    else:
        if S[i] == S[i - 1]:
            count += 1
            
        else:
            S_list.append(count)
            count = 1

S_list.append(count)
if S[-1] == "0":
    S_list.append(0)


now = 0
for i in range(len(S_list)):
    now += S_list[i]
    cum_list.append(now)


answer_list = []
i = 0
if 2 * K + 1 < len(cum_list):
    while i + 2 * K + 1 < len(cum_list):
        answer_list.append(cum_list[i + 2 * K + 1] - cum_list[i])
        i += 2
else:
    answer_list.append(len(S))
answer = max(answer_list)
print(answer)

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    ll ans = LONG_LONG_MAX;
    rep(bit, 1<<n) {
        vector<int> cand;
        rep(i, n) {
            if (bit & 1<<i) cand.push_back(i);
        }
        if (int(cand.size())!=k) continue;
        if (cand[0]!=0) continue;
        sort(all(cand));
        ll tmp = 0;
        vector<int> b = a;
        rep(i, k) {
            int cur = cand[i];
            if (cur>0 && b[cand[i-1]]>=b[cur]) {
                tmp += b[cand[i-1]]-b[cur]+1;
                b[cur]=b[cand[i-1]]+1;
            }
            if (i<k-1) {
                FOR(follow, cur+1, cand[i+1]) {
                    if (b[follow]>b[cur]) {
                        tmp += b[follow]-b[cur]+1;
                        b[cur] = b[follow]+1;
                    }
                }
            } else {
                FOR(follow, cur+1, n) {
                    if (b[follow]>b[cur]) {
                        tmp += b[follow]-b[cur]+1;
                        b[cur] = b[follow]+1;
                    }
                }
            }
        }
        // rep(i, k) cout << cand[i] <<((i<k-1)?" ":"\n");
        // rep(i, n) cout << b[i] <<((i<n-1)?" ":"\n");
        // cout << tmp << endl;
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N;
int A[200005];
int copyA[200005];

int main(void) {
  cin >> N;
  
  int tmp;
  for(int i=0; i<N; i++){
    cin >> tmp;
    A[i] = tmp;
    copyA[i] =tmp;
  }
  
  /*大きい順にソート*/
  int n = sizeof(copyA)/sizeof(copyA[0]);
  sort(copyA, copyA+n, greater<>());
  
  int max = copyA[0];
  int max2 = copyA[1];
  
  for(int i=0; i<N; i++){
    if(A[i]==max){
      cout << max2 << endl;
    }
    else{
      cout << max << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3200
H, W, D = map(int, input().split())
number = [[0,0] for _ in range(H*W)]
cost = [0] * (H*W)
for i in range(H):
  a = list(map(int, input().split()))
  for j in range(W):
    number[a[j]-1] = [i, j]
for i in range(D):
  cost[i] = 0
for j in range(D, H*W):
  cost[j] = cost[j-D] + abs(number[j][0]-number[j-D][0]) + abs(number[j][1]-number[j-D][1])
Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(cost[R-1] - cost[L-1])

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

using namespace std;

const double PI = acos(-1);

int main()
{
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    c = c * 30 + d / 60 * 30;
    d *= 6;
    c = abs(c - d);
    if(2 * c > 360) c = 360 - c;
    printf("%.20f\n",sqrt(a * a + b * b - 2 * b * a * cos(PI * c / 180)));
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll n,cnt=0;
    cin>>n;
    vector<string> s(n);
    vector<ll> t(n);
    rep(i,n) cin>>s[i]>>t[i];
    string x; cin>>x;
    for(int i=n-1;i>=0;i--){
        if(s[i]==x) break;
        cnt+=t[i];
    }
    cout<<cnt<<endl;
    return 0;
}

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


int main() {
	int N,A,B;
//	int TotA,TotB;
  	cin >> N >> A >> B;
	if(N*A <= B ){
    	cout << N*A;
    } else {
    	cout << B;
    }

	return 0; 
}

Measured memory_bytes: 256
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N,M,X = LI()
B = [LI() for _ in range(N)]
C = []
A = []
S = [0] * M

for ind,b in enumerate(B):
	C.append(b[0])
	A.append(b[1:])
	for i,v in enumerate(b[1:]):
		S[i]+=v

for s in S:
	if s < X:
		print("-1")
		exit(0)

def bit_all():
	minmoney = 10**7
	bit = 0
	while bit < 2**N:
		T = [X] * M
		now = 0
		#print(bit)
		for i in range(N):
			#print("\t",i)
			flg = True
			if ((bit >> i)&1):
				for ind in range(M):
					T[ind]-=A[i][ind]
					if T[ind] > 0:
						flg = False
				now+=C[i]
				if flg:
					#print(now)
					if now < minmoney:
						minmoney = now
					break
		bit+=1
	return minmoney

print(bit_all())


Measured memory_bytes: 9272
#include <stdio.h>
#include <string.h>

#define N 10000

#define MIN(A,B) (A)<(B)?(A):(B)
#define MAX(A,B) (A)>(B)?(A):(B)

int main(){
  int n, a, b;
  char S[N];
  scanf("%d", &a);
  scanf("%s", S);
  if (a<3200) printf("red\n");
  else printf("%s", S);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;
int a[200010] = {};
int n,k;
bool check(int M){
	int cnt = 0;
	rep(i,n){
		int x = a[i]/M;
		if(a[i]%M != 0)x++;
		cnt += x-1;
		if(cnt > k)return false;
	}
	return true;
}
ll bsearch(){
    // 条件を満たす最大値を求める
    // ll ok = 0;  //解が存在する値
    // ll ng = 100;//解が存在しない値 

    // 条件を満たす最小を求める
    ll ok = 1000000000;  //解が存在する値
    ll ng = 0;  //解が存在しない値 

    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}
/*----------------------------------------------------------------*/
signed main(){
	

	cin >> n >> k;
	
	rep(i,n)cin >> a[i];
	cout << bsearch() << endl;


	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://atcoder.jp/contests/abc174/tasks/abc174_b

Measured memory_bytes: 5140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int dp[3030][3030];
int main(){
    string s,t;
    cin>>s>>t;
    dp[0][0]=0;
    int n=s.size(),m=t.size();
    rep(i,n)rep(j,m){
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+(s[i]==t[j]));
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
    }
    int i=n,j=m;
    string ret="";
    while(i>0&&j>0){
        if(dp[i][j]==dp[i][j-1])--j;
        else if(dp[i][j]==dp[i-1][j])--i;
        else if(dp[i][j]==dp[i-1][j]+1){
            ret+=s[i-1];
            --i;--j;
        }
    }
    reverse(ret.begin(),ret.end());
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 35840
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
anosize = a.size
count = 0
all = 1
if a.include?(0)
    puts "0"
    exit
end
a.each do |i|
    all = all.to_i
    all = all * i
    all = all.to_s
    if all.size >= 19 
        all = all.to_i
        if all > 10 ** 18
        puts "-1"
        exit
        end
        all = all.to_s
    end
    count += 1
    if count == anosize
        puts all
    end
end

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> ss;
    for (int i = 0; i < N; ++i) {
        string si;
        cin >> si;
        ss.push_back(si);
    }

    sort(ss.begin(), ss.end());
    for (int i = 0; i < N; ++i) {
        cout << ss[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

bool prime[100009];
int is2017[100009];

void eratosthenes(int X) {
    for ( int i = 2; i*i <= X; i++ ) {
        int v = i*2;
        while( v <= X) {
            prime[v] = false;
            v += i;
        }
    }
}

bool ck(int x){
    return (prime[x]&&prime[(x+1)/2]);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,100009)prime[i]=1;
    prime[1]=0;
    eratosthenes(100003);
    for(int i=1;i<=100000;i+=2){
        if(ck(i)) is2017[i]=1;
    }
    
    rep(i,100000) is2017[i+1]+=is2017[i];
    
    int Q;
    cin>>Q;
    rep(i,Q){
        int l,r; cin>>l>>r;
        cout1(is2017[r]-is2017[l-1])
    }
}

Measured memory_bytes: 1152
#include <stdio.h>

int n, m;
char d[128][12345];

int eSumLeft[12345], wSumRight[12345];

int main(void) {
	int i, j;
	int score = 999999999;
	int answer = 0;
	if (scanf("%d%d", &n, &m) != 2) return 1;
	for (i = 0; i < m; i++) {
		if (scanf("%12344s", d[i] + 1) != 1) return 1;
	}
	for (i = 1; i <= n; i++) {
		for (j = 0; j < m; j++) {
			if (d[j][i] == 'E') eSumLeft[i]++;
			if (d[j][i] == 'W') wSumRight[i]++;
		}
	}
	for (i = 1; i <= n; i++) eSumLeft[i] += eSumLeft[i - 1];
	for (i = n - 1; i >= 0; i--) wSumRight[i] += wSumRight[i + 1];
	for (i = 1; i <= n + 1; i++) {
		int candidate = eSumLeft[i - 1] + wSumRight[i];
		if (candidate < score) {
			score = candidate;
			answer = i;
		}
	}
	printf("%d %d\n", answer - 1, answer);
	return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <array>
#include <bitset>
#include <functional>
#include <cstdint>
#include <deque>
#include <iostream>
#include <memory>
#include <limits>
#include <vector>

auto main() -> int {
  int N, A, B, C;
  std::cin >> N >> A >> B >> C;

  // N 本の竹
  std::vector<int> ls(N);
  for (auto i = 0; i < N; ++i) {
    std::cin >> ls[i];
  }

  std::function<int(int, int, int, int)> f = [&f, N, A, B, C, &ls](int i, int a, int b, int c) {
    if (i == N) {
      if (std::min({a, b, c}) > 0)
        return std::abs(a - A) + std::abs(b - B) + std::abs(c - C);
      else
        return 10000000;
    }

    const auto r1 = f(i + 1, a, b, c);                        // l[i] を使わない
    const auto r2 = f(i + 1, a + ls[i], b, c) + (a ? 10 : 0); // A の材料にする
    const auto r3 = f(i + 1, a, b + ls[i], c) + (b ? 10 : 0); // B の材料にする
    const auto r4 = f(i + 1, a, b, c + ls[i]) + (c ? 10 : 0); // C の材料にする

    return std::min({r1, r2, r3, r4});
  };

  std::cout << f(0, 0, 0, 0) << std::endl;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
struct Acc {
  vector<T> v;
  Acc() {
    v.push_back(0);
  }
  // returns sum of (begin, end]
  T query(int begin, int end) {
    return v[end] - v[begin];
  }
  void append(T x) {
    v.push_back(v.back() + x);
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> v(n);
    each (i, v) cin >> i;

    Acc<lli> a;
    each (i, v) a.append(i);

    const lli inf = 1LL << 60;
    auto fn = [&] (int i, int j, int k) {
      unless (i < j) return inf;
      unless (j < k) return inf;
      lli x = max({a.query(0, i), a.query(i, j), a.query(j, k), a.query(k, n)});
      lli y = min({a.query(0, i), a.query(i, j), a.query(j, k), a.query(k, n)});
      return x - y;
    };

    lli mn = inf;
    int i = 1;
    int k = 3;
    for (int j = 2; j < n - 1; ++j) {
      while (i + 1 < j) {
        lli x = abs(a.query(0, i + 0) - a.query(i + 0, j));
        lli y = abs(a.query(0, i + 1) - a.query(i + 1, j));
        if (x > y) ++i;
        else break;
      }
      k = max(k, j + 1);
      while (k + 1 < n) {
        lli x = abs(a.query(j, k + 0) - a.query(k + 0, n));
        lli y = abs(a.query(j, k + 1) - a.query(k + 1, n));
        if (x > y) ++k;
        else break;
      }
      mn = min(mn, fn(i, j, k));
    }
    cout << mn << endl;
  }
  
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var day = int.Parse(Console.ReadLine());
        if(day == 25)
        {
            Console.WriteLine("Christmas");
        }
        else if(day == 24)
        {
            Console.WriteLine("Christmas Eve");
        }
        else if(day == 23)
        {
            Console.WriteLine("Christmas Eve Eve");
        }
        else if(day == 22)
        {
            Console.WriteLine("Christmas Eve Eve Eve");
        }
    }
}

Measured memory_bytes: 11092
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
if b == 1:
  x = list(range(1,n+1))
  print(*x)
  exit()
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
x = list(zip(*ans_true))[0]
print(*x)

Measured memory_bytes: 118748
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll mod=1e9+7,N,ans=1;

int main(){
    cin>>N;
    repi(i,1,N+1){
        ans=(ans*i)%mod;
    }
    out(ans);
}


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


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

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

	sort(a.begin(), a.end(), greater<int>());

	int count = 1;
	for (int i = 1; i < N; i++)
	{
		if (a[i - 1] > a[i])
			count++;
	}

	cout << count << "\n";

	return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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


int main(){
	
	string str;cin >> str;
	stack<char> st;
	int ans = 0;
	
	REP(i, str.size()){
		if(!st.empty() && st.top() != str[i]){
			st.pop();
			ans++;
		}
		else{
			st.push(str[i]);
		}
	}
	
	cout << ans * 2 << endl;
	
	return 0;
}


Measured memory_bytes: 512
from bisect import bisect_left
s = input()
t = input()
dic = {}
for ind, c in enumerate(s):
    if c in dic:
        dic[c].append(ind)
    else:
        dic[c] = [ind]
loop = 0
ind = 0
try:
    for c in t:
        if ind > dic[c][-1]:
            ind = dic[c][0] + 1
            loop += 1
            continue
        tmp = bisect_left(dic[c], ind)
        ind = dic[c][tmp] + 1
    print(len(s)*loop+ind)
except:
    print(-1)

Measured memory_bytes: 7668
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

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


int main() {
	int h, w;
	string s[102];
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < w+2; i++) {
		s[0].push_back('#');
		s[h + 1].push_back('#');
	}
	cout << s[0] << "\n";
	for (int i = 1; i <= h; i++)cout << "#" << s[i] << "#\n";
	cout << s[h + 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long t,i,j,k,a,b,c=0,d=0,n;
  cin>>n;
  long long A[n],B[n];
for(i=0;i<n;i++)
cin>>A[i]>>B[i];
for(i=0;i<n;i++)
{
  if(A[i]==B[i]) c++;
  else c=0;
  if(c>=3)
  {
     cout<<"Yes"<<endl;
     return 0;
  }
}
cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3608
#include <iostream>
 using namespace std; int main(void){ 
    int a;
    int d=0;
    cin>>a;
    char s[50];
    for(int i=0;i<a;i++){
    cin>>s[i];
        }
   for(int i=0;i<a;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                     d++;
                    }
                }
             }
          }
    

    cout<<d;
    return 0;
    }


Measured memory_bytes: 256