akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


template <typename T>
struct ReRooting
{
  using F = function<T(T, int)>;
  using F2 = function<T(T, T)>;
  int V;
  vector<vector<int>> E;
  vector<vector<T>> dp;
  //dp_v = g(merge(f(dp_c1,c1), f(dp_c2,c2), ..., f(dp_ck,ck)) , v)
  F f, g;
  F2 merge;
  T mi; //identity of merge
 
  ReRooting(int V_, F f_, F2 merge_, T mi_, F g_ = [](T a, int b) { return a; })
      : V(V_), f(f_), merge(merge_), mi(mi_), g(g_)
  {
    E.resize(V);
    dp.resize(V);
  }
 
  void add_E(int a, int b) //辺を追加
  {
    E[a].push_back(b);
    E[b].push_back(a);
  }
 
  T dfs1(int p, int v)
  {
    T res = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      dp[v][i] = dfs1(v, E[v][i]);
      res = merge(res, f(dp[v][i], E[v][i]));
    }
    return g(res, v);
  }
 
  void dfs2(int p, int v, T add)
  {
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
      {
        dp[v][i] = add;
        break;
      }
    }
 
    vector<T> pL(E[v].size() + 1), pR(E[v].size() + 1);
    pL[0] = mi;
    for (int i = 0; i < E[v].size(); ++i)
      pL[i + 1] = merge(pL[i], f(dp[v][i], E[v][i]));
    pR[E[v].size()] = mi;
    for (int i = E[v].size(); i > 0; --i)
      pR[i - 1] = merge(pR[i], f(dp[v][i - 1], E[v][i - 1]));
 
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      T val = merge(pL[i], pR[i + 1]);
      dfs2(v, E[v][i], g(val, v));
    }
  }
 
  void calc(int root = 0) //根を頂点0とした前計算
  {
    for (int i = 0; i < V; ++i)
      dp[i].resize(E[i].size());
    dfs1(-1, root);
    dfs2(-1, root, mi);
  }
 
  T solve(int v) //根を頂点vとしたときの解を得る
  {
    T ans = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      ans = merge(ans, f(dp[v][i], E[v][i]));
    }
    return g(ans, v);
  }
};


int main(){
    int n,m;
    cin >> n >> m;
    auto f=[&](ll a,int v){
        return (a+1)%m;
    };
    auto merge=[&](ll a,ll b){
        return a*b%m;
    };
    ReRooting<ll> re(n,f,merge,1);
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--; y--;
        re.add_E(x,y);
    }
    re.calc();
    rep(i,n){
        cout << re.solve(i) << endl;
    }
    return 0;
}

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

using ll=long long; 

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

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        if(i==k-1)
        {
            if(str[i]=='A')
                cout<<"a";
            else if(str[i]=='B')
                cout<<"b";
            else if(str[i]=='C')
                cout<<"c";
        }
        else
        {
            cout<<str[i];
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int A = stoi(s.substr(0,1));
  int B = stoi(s.substr(1,1));
  int C = stoi(s.substr(2,1));
  int D = stoi(s.substr(3,1));
  
  char X,Y,Z;
  
  if(A + B + C + D == 7){
    X = '+';
    Y = '+';
    Z = '+';
  }
  if(A + B + C - D == 7){
    X = '+';
    Y = '+';
    Z = '-';
  }
  if(A + B - C + D == 7){
    X = '+';
    Y = '-';
    Z = '+';
  }
  if(A - B + C + D == 7){
    X = '-';
    Y = '+';
    Z = '+';
  }
  if(A - B - C + D == 7){
    X = '-';
    Y = '-';
    Z = '+';
  }
  if(A - B + C - D == 7){
    X = '-';
    Y = '+';
    Z = '-';
  }
  if(A + B - C - D == 7){
    X = '+';
    Y = '-';
    Z = '-';
  }
  if(A - B - C - D == 7){
    X = '-';
    Y = '-';
    Z = '-';
  }
  
  cout << A << X << B << Y << C << Z << D << "=7" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

#define PI 3.1415926535

double x[110],y[110];
double ans[110];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lf%lf",x+i,y+i);
	rep(i,0,n){
		double m[20],M[20];
		int cnt[20];
		rep(t,0,20)m[t]=INF,M[t]=-INF,cnt[t]=0;
		rep(j,0,n)if(i!=j){
			double s=atan2(y[j]-y[i],x[j]-x[i]);
			s=(s+PI)/(2*PI);
			if(s>=1)s=0;
			if(s<0)s=0;
			int t=s*20;
			cnt[t]++;
			m[t]=min(m[t],s);
			M[t]=max(M[t],s);
		}
		rep(k,0,20)if(cnt[k]){
			int t=1;
			while(!cnt[(k+t)%20])t++;
			if(t<10)continue;
			double s=m[(k+t)%20]-M[k];
			if(s<0)s++;
			if(s==0)s=1;
			if(s<0.5)continue;
			ans[i]=s-0.5;
			break;
		}
	}
	rep(i,0,n)printf("%.9f\n",ans[i]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

//↓combination(ll a, ll b) でaCr計算。
//------------------------------------------------------------------------------------------
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}
ll kj(ll x){
    ll s = 1;
    for(ll i = 1; i <= x; i++){
        s = s * i % MOD;
    }
    return s;
}
ll combination(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < b || a < 0) return 0;
    return (kj(a) * mpow(kj(b), MOD-2) % MOD) * mpow(kj(a-b), MOD-2) % MOD;
}
//---------------------------------------------------------------------------------------------
//↑combination(ll a, ll b) でaCr計算。

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int train = A*N;
    int taxi = B;
    int ans=min(train,taxi);
    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    private final static int M = 1000000007;

    private static int solve(int N, boolean[][] a) {
        int states = 1 << N;
        int[] count = new int[states];
        boolean[] added = new boolean[states];
      
        Queue<Integer> q = new ArrayDeque<>();
        q.add(0);
        count[0] = 1;
      
        while (!q.isEmpty()){
          int state = q.poll();          
          int i = Integer.bitCount(state);
          
          for (int j = 0; j < N; j++) {
            if (!a[i][j]) continue;

            int newState = state | (1 << j);
            if (newState == state) continue;
            count[newState] = (count[newState] + count[state]) % M;
            
            if (i+1 < N && !added[newState]){
              q.add(newState);
              added[newState] = true;
            }
          }
        }

        return count[states-1];
    }

    public static int run(Scanner scanner) {
        int N = scanner.nextInt();
        boolean[][] a = new boolean[N][N];
        for (int i=0; i < N; i++)
            for (int j=0; j < N; j++)
                a[i][j] = scanner.nextInt() == 1;

        return solve(N, a);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}

Measured memory_bytes: 66772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(int i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000
typedef long long ll;
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; }


int main(){
  ios::sync_with_stdio(false);
  
  int R;
  cin>>R;
  
  cout<<fixed<<setprecision(5)<<2*R*M_PI;
  
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s;
  cin >> s;
  int isA = 0, res, sum = 0;
  for(auto& e : s){
    if(e == 'A' && !isA) isA = 1;
    if(isA){
      sum++;
      if(e == 'Z') res = sum;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main(){
  int h1,m1,h2,m2,k,ans;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  h1 *=60;
  h2 *=60;
  ans = (h2+m2)-(h1+m1+k);
  cout << ans;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>

using namespace std;

long long i,j,k,A,B,N,x,ans;

int main()
{
  cin>>A>>B>>N;
  
  if(N>=B-1)
  {
    ans=(A/B)*(B-1)+(B-1)*(A%B)/B;
  }
  else
  {
    ans=(A/B)*N+N*(A%B)/B;
  }
  cout<<ans;

  
}

Measured memory_bytes: 3596
// 長方形の中の円

#include <iostream>
using namespace std;

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (r <= x && x <= W-r && r <= y && y <= H-r)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for i in range(1,2*N):
        ans += L[i-1]
        L[i] -= L[i-1]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9248
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

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

  int n; cin >> n;
  set<int> s;
  rep(i, n) {
    int a; cin >> a;
    s.insert(a);
  }

  cout << s.size() << endl;

  return 0;
}

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

#define MOD 998244353

long long Calc(long long x, long long y) {
	if (y == 0) return 1;
	if (y % 2 == 0) {
		long long z = Calc(x, y / 2);
		return (z * z) % MOD;
	}
	return (x * Calc(x, y - 1)) % MOD;
}

int main() {
	int N, A[300], Sum = 0;
	long long Nans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		Sum += A[i];
	}
	static long long DP[310][90500] = {}, DPX[310][90500] = {};
	DP[0][0] = 1, DPX[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= Sum; j++) {
			DP[i + 1][j] = (DP[i + 1][j] + DP[i][j] * 2) % MOD;
			DPX[i + 1][j] = (DPX[i + 1][j] + DPX[i][j]) % MOD;
			DP[i + 1][j + A[i]] = (DP[i + 1][j + A[i]] + DP[i][j]) % MOD;
			DPX[i + 1][j + A[i]] = (DPX[i + 1][j + A[i]] + DPX[i][j]) % MOD;
		}
	}
	for (int i = (Sum + Sum % 2) / 2; i <= Sum; i++) {
		Nans += DP[N][i];
		Nans = Nans % MOD;
	}
	if (Sum % 2 == 0) Nans -= DPX[N][Sum / 2];
	long long ans = Calc(3, N - 1);
	ans = (ans + MOD - Nans) % MOD;
	cout << (ans * 3) % MOD;
}

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

#define DEBUG 0

using namespace std;

void debug(string msg) {
#if DEBUG
  cerr << msg << endl;
#endif
}

  
class UnionFind {
protected:
  int size;
  vector<int> _leader;
  vector<int> _rank;
  
public:
  UnionFind(int s);
  int leader(int i);
  int merge(int i, int j);
};

UnionFind::UnionFind(int s) {
  size = s;
  _leader = vector<int>(size);
  for (int i = 0; i < size; i++) { _leader.at(i) = i; }
  _rank = vector<int>(size, 1);
}

int UnionFind::leader(int i) {
  int cur = i;
  int nxt = _leader.at(cur);
  vector<int> seen;
  while (cur != nxt) {
    seen.push_back(cur);
    cur = nxt;
    nxt = _leader.at(cur);
  }
  for (auto j : seen) _leader.at(j) = cur;
  return cur;
}

int UnionFind::merge(int i0, int j0) {
  int li = leader(i0);
  int lj = leader(j0);
  if (li == lj) return li;
  int ri = _rank.at(li);
  int rj = _rank.at(lj);
  if      (ri < rj)  return _leader.at(li) = lj;
  else if (ri > rj)  return _leader.at(lj) = li;
  else {
    (_rank.at(lj))++;
    return _leader.at(li) = lj;
  }
}

class MyUnionFind : public UnionFind {
  vector<int> _gsize;
public:
  MyUnionFind(int s) : UnionFind(s) { _gsize = vector<int>(size, 1); }
  int gsize(int i) { return _gsize.at(leader(i)); }
  int merge(int i0, int j0) {
    int li = leader(i0);
    int lj = leader(j0);
    if (li == lj) return li;
    int newLeader = UnionFind::merge(li, lj);
    _gsize.at(newLeader) = _gsize.at(li) + _gsize.at(lj);
    return newLeader;
  }
};

long long combi(long long k) { return k * (k-1) / 2; }

int main() {
  debug("A");
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  debug("B");
  MyUnionFind uf(n+1);
  vector<long long> diff(m, 0);
  for (int i = m - 1; i >= 0; i--) {
    int xa = a.at(i);
    int xb = b.at(i);
    int la = uf.leader(xa);
    int lb = uf.leader(xb);
    if (la == lb)  continue;
    long long sizePrev = combi(uf.gsize(la)) + combi(uf.gsize(lb));
    int newL = uf.merge(xa, xb);
    diff.at(i) = combi(uf.gsize(newL)) - sizePrev;
  }
  debug("C");
  long long sum = 0;
  for (int i = 0; i < m; i++) {
    sum += diff.at(i);
    cout << sum << endl;
  }

  return 0;
}



Measured memory_bytes: 4096
A = int(input())
B = int(input())
C = int(input())
X = int(input())
total = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            num = (500 * a) + (100 * b) + (50 * c)
            if num == X:
                total += 1
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> dat;
    
    int half = n / 2;
    if (half & 1) half--;
    
    int l = 1, r = m;
    while (l < r) dat.emplace_back(l++, r--);
    
    l = m + 1; r = 2 * m + 1;
    if ((r - l) & 1 == (m - 1) & 1) l++;
    while (l < r) dat.emplace_back(l++, r--);
    
    
    for (const auto &e : dat) {
        int a, b; tie(a, b) = e;
        cout << a << ' ' << b << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int t,n,hnow,hbef,U,D;
    cin>>t;
    for(int i=0;i<t;i++){
	cin>>n;
	U=0;D=0;
	for(int j=0;j<n;j++){
	    hbef=hnow;
	    cin>>hnow;
	    if(j>0&&hnow-hbef>U)U=hnow-hbef;
	    if(j>0&&hbef-hnow>D)D=hbef-hnow;
	}
	cout<<U<<" "<<D<<endl;
    }
}

Measured memory_bytes: 0
<?php
$N = intval(trim(fgets(STDIN)));
$A = explode(' ', trim(fgets(STDIN)));
$c1=$c2=$c3=0;
foreach($A as $a){
    if($a == '1')$c1++;
    if($a == '2')$c2++;
    if($a == '3')$c3++;
}
$dp = array_fill(-1, $N+3, array_fill(-1,$N+3, array_fill(-1,$N+3,0)));
for($k = 0; $k <= $c3; ++$k){
    $dpk = &$dp[$k];
    for($j = 0, $J = $c2 + $c3 - $k; $j <= $J; ++$j){
        for($i = 0, $I = $c1+$c2+$c3-$k-$j; $i <= $I ; ++$i){
            if($i==0&&$j==0&&$k==0)continue;
            $dpk[$j][$i] = ($N + $i*$dpk[$j][$i-1] + $j*$dpk[$j-1][$i+1] + $k*$dp[$k-1][$j+1][$i])/($i+$j+$k);
        }
    }
}
echo $dp[$c3][$c2][$c1];

Measured memory_bytes: 926200
#include<iostream>

int n,a[200000],m,b[200000],tmp;

int main(){

    std::cin>>n;

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

    for(int i=n;i>=1;i--){
        for(int j=i;j<=n;j+=i){
            tmp+=b[j-1];
        }
        if((tmp%2)!=a[i-1])b[i-1]=1;
        tmp=0;
    }

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

    std::cout<<m<<std::endl;

    for(int i=0;i<n;i++){
        if(b[i]==1){
            std::cout<<i+1;
            m--;
            if(m!=0)
            std::cout<<' ';
        }
    }

    std::cout<<std::endl;

    return 0;
}

Measured memory_bytes: 2432
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353

gyaku=pow(2,mod-2,mod)
N2=pow(2,N-1,mod)
dp=[0 for n in range(3001)]
for n in range(N):
    a=A[n]
    for s in range(0,S+1)[::-1]:
        if s+a<=S:
            dp[s+a]+=dp[s]*gyaku%mod
            dp[s+a]%=mod
    dp[a]+=N2
    dp[a]%=mod

print(dp[S])


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


int main() {
    int ans=0;
    int N,M;
    cin >> N >> M;
    vector<vector<int>> G(N); 
    int h[N];
    rep(i,N){cin >> h[i];}
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        // 頂点番号を 0-indexed とする
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<N;i++){
      int ma=0;
      while(G[i].size() != 0){
        int q=G[i].back();
        G[i].pop_back();
        ma=max(ma,h[q]);
      }
      if(h[i]>ma)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8808
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int K;
        Input(out K);
        if(K % 2 == 0) {
            Console.WriteLine(K / 2 * K / 2);
        } else {
            Console.WriteLine(K / 2 * (K / 2 + 1));
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print(object o) => Out.WriteLine(o);
    static void Print(string s) => Out.WriteLine(s);
    static void Print(params string[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };


int main() {
	int n;
	std::cin >> n;
	std::cout << 0 << std::endl;
	std::string a, b;
	std::cin >> a;
	if (a == "Vacant")flag = false;
	if (flag) {
		std::cout << n - 1 << std::endl;
		std::cin >> b;
		if (b == "Vacant")fl = false;
	}
	if (flag&&fl) {
		int l = 0, r = n - 1;
		for (int i = 0;i < 18;i++) {
			int mid = (l + r) / 2;
			std::cout << mid << std::endl;
			std::string s;
			std::cin >> s;
			if (s == "Vacant")break;
			else {
				if (a == s && (mid - l) % 2 == 1)r = mid, b = s;
				else if (a != s && (mid - l) % 2 == 0)r = mid, b = s;
				else if (b != s && (r - mid) % 2 == 0)l = mid, a = s;
				else if (b == s && (r - mid) % 2 == 1)l = mid, a = s;
			}
		}
	}

}

Measured memory_bytes: 852
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
ll n,m;cin>>n>>m;
vector<ll>a(n);rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
map<ll,ll>memo;
vector<ll>b(m),c(m);
rep(i,m)cin>>b[i]>>c[i];
rep(i,m)memo[c[i]]=0;
rep(i,m)memo[c[i]]+=b[i];
auto itr=a.begin();
auto citr=memo.end();
bool flag=1;
while(flag){
    citr--;
    ll tnum=citr->first;
    ll tcnt=citr->second;
    rep(i,tcnt){
        if(*itr>tnum||itr==a.end()){
            flag=0;break;
        }
        itr++;
    }
    if(citr==memo.begin())break;
}
ll cnum=distance(a.begin(),itr);
ll ans=0;
for(itr;itr!=a.end();itr++)ans+=*itr;
auto iitr=memo.end();
if(ans!=0){
    ll cnt=0;
    iitr--;
    while(cnt+iitr->second<cnum){
        ans+=iitr->first*iitr->second;
        cnt+=iitr->second;
        iitr--;
    }
    ans+=(cnum-cnt)*iitr->first;
    cout<<ans<<endl;
}
else {
    ll cnt=0;
    iitr--;
    while(cnt+iitr->second<n){
        ans+=iitr->first*iitr->second;
        cnt+=iitr->second;
        iitr--;
    }
    ans+=(n-cnt)*iitr->first;
    cout<<ans<<endl;
}

}


Measured memory_bytes: 8832
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}

int main()
{
	string w;
  cin>>w;
  int n=w.size();
  bool same=1;
  for(int i=0; i<n-1; i++){
    if(w[i]!=w[i+1]){
      same=0;
      break;
    }
  }
  if(same){
    cout<<n<<endl;
    cout<<1<<endl;
    return 0;
  }
  random_device rnd;
  mt19937_64 mt(rnd());
  uniform_int_distribution<ll> rndn(2, MOD-2);
  ll b=rndn(mt);
  ll s[500001]; s[0]=0;
  ll bp=1;
  for(int i=1; i<=n; i++){
    s[i]=s[i-1]+bp*((ll)(w[i-1]-'a'));
    s[i]%=MOD;
    bp=bp*b%MOD;
  }
  ll bv=inv(b);
  ll bpv[500001];
  bpv[0]=1;
  for(int i=1; i<=n; i++) bpv[i]=bpv[i-1]*bv%MOD;
  
  bool nuee[500001]={};
  for(int d=1; d<=n; d++){
    ll s0=s[d];
    for(int i=2; i*d<=n; i++){
      ll s1=(s[i*d]-s[(i-1)*d]+MOD)*bpv[(i-1)*d]%MOD;
      if(s0!=s1) break;
      nuee[i*d]=1;
    }
  }
  if(!nuee[n]){
    cout<<1<<endl;
    cout<<1<<endl;
    return 0;
  }
  cout<<2<<endl;
  for(int d=1; d<=n; d++){
    ll s0=(s[n]-s[n-d]+MOD)*bpv[n-d]%MOD;
    for(int i=2; i*d<=n; i++){
      ll s1=(s[n-(i-1)*d]-s[n-i*d]+MOD)*bpv[n-i*d]%MOD;
      if(s0!=s1) break;
      nuee[n-i*d]=1;
    }
  }
  int ans=0;
  for(int i=1; i<n; i++){
    if(!nuee[i]) ans++;
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
long long calc(long long x){
  x++;
  long long cnt, loop;
  long long ans = 0;
  for(int i=0; i<50; i++){
    loop = 1LL << i+1;
    cnt = (x / loop) * (loop / 2);
    cnt += max(0LL, (x % loop) - (loop / 2));
    if(cnt % 2 == 1){
      ans += 1LL << i;
    }
  }
   return ans;
}
  
               
int main(){
  long long A,B;
  cin >> A >> B;
  long long ans;
  ans = calc(B) ^ calc(A-1);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int N;
	scanf("%d", &N);
	char S[N][N];
	for (int i = 0; i < N; ++i){
		scanf("\n");
		for (int j = 0; j < N; ++j)	scanf("%c", &S[i][j]);
	}
	int answer = 0;
	for (int i = 0; i < N; ++i){
		bool flag = true;
		for (int j = 0; j < N - 1; ++j){
			for (int k = j + 1; k < N; ++k){
				if(S[(j + i) % N][k] != S[(k + i) % N][j]){
					flag = false;
					break;
				}
			}
			if(!flag) break;
		}
		if(flag) answer += N;
	}
	printf("%d\n", answer);
	return 0;
}

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

int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  int l = abs(B - A) - 1;
  if (l & 1) puts("Alice");
  else puts("Borys");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
#define ll long long
using namespace std;

int main(){
	string a,b,c;

	cin>>a>>b>>c;
	
	if(a.substr(a.size()-1,1)==b.substr(0,1) && b.substr(b.size()-1,1)==c.substr(0,1)){
		cout<<"YES"<<endl;
		return 0;
	}
	
	cout<<"NO"<<endl;
   	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n=1000;
	int t;
	int total=0;
	scanf("%d",&t);
	if(t%n==0)
	{
		printf("0");
	}
	else 
	{
		total = n-(t%n);
		printf("%d",total);
	}
}

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

using namespace std;

typedef long long ll;

#define eps 1e-9
#define all(a)   a.begin(),a.end()
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define sz size()
#define rd(inp) scanf("%lld",&inp)
#define rd2(inp1, inp2) scanf("%lld %lld",&inp1, &inp2)
#define rl(inp) scanf("%d",&inp)
#define pf(out) printf("%lld\n", out);

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int inf = 1e9;

ll fpow(ll base,ll power){
	ll result = 1;
	while (power > 0){
		if (power%2 == 1) result=(result*base);
  		base = (base*base);
  		power /= 2;
  	}
	return result;
}

ll sing, two, zero;
#define maxn 100100
ll a[maxn];

ll solve(ll x){
	ll sum = 0;
	while (x % 2 == 0){
		sum ++;
		x /= 2;
	}
	return sum;
}

int main(){
	ll n, i;
	cin >> n;
	for ( i = 0 ; i < n ; i ++ ){
		cin >> a[i];
		ll here = solve(a[i]);
		if ( here >= 2 ){
			two ++;
		}
		else if ( here == 1 ){
			sing ++;
		}
		else{
			zero ++;
		}
	}
	ll prev = 0;
	if ( zero ){
		zero --;
		prev = 0;
	}
	else if ( sing ){
		sing --;
		prev = 1;
	}
	else{
		two --;
		prev = 2;
	}
	for ( i = 1 ; i < n ; i ++ ){
		if ( prev == 0 ){
			if ( two ){
				two --;
				prev = 2;
			}
			else{
				return 0 * printf("No\n");
			}
		}
		else if ( prev == 1 ){
			if ( sing ){
				sing --;
				prev = 1;
			}
			else if ( two ){
				two --;
				prev = 2;
			}
			else{
				return 0 * printf("No\n");
			}
		}
		else{
			if ( zero ){
				zero --;
				prev = 0;
			}
			else if ( sing ){
				sing --;
				prev = 1;
			}
			else if( two ) {
				two --;
				prev = 2;
			}
			else{
				return 0 * printf("No\n");
			}
		}
	}
	return 0 * printf("Yes\n");;
}

Measured memory_bytes: 1024
/* FALTU HI LIKH ... BUT KHALI NI BAITHNA */
#include<bits/stdc++.h>

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define endl '\n'
#define int long long
#define ld long double
#define pb emplace_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define pii pair<int,int>
#define ff first
#define ss second
#define N (int)(2e5 + 10)

using namespace std;



int32_t main() {
	fast
	int t_c = 1;
//	cin >> t_c;
	while (t_c--) {
//		cout << "#: ";
		int n;
		cin >> n;
		for (int i = -118; i <= 119; i++) {
			for (int j = -119; j <= 118; j++) {
				if (pow(i, 5) - pow(j, 5) == n) {
					cout << i << " " << j;
					return 0;
				}
			}
		}
	}
}

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

using namespace std;

//#define FILE_IO

int N;
int v[200005];
int b[200005];

bool median(int val)
{
    for(int i = 1; i <= 2 * N - 1; i++) b[i] = (v[i] <= val);
    int cnt = 0;
    for(int i = 1; i < 2 * N - 1; i++)  if(b[i] == b[i + 1])    cnt++;
    if(!cnt)    return b[1];

    for(int l = 0; l < N; l++)
    {
        if(b[N - l] == b[N - l - 1])    return b[N - l];
        if(b[N + l] == b[N + l + 1])    return b[N + l];
    }

    return false;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= 2 * N - 1; i++) scanf("%d", &v[i]);

    int p = 1;
    int u = 2 * N - 1;
    int ans = 0;
    while(p <= u)
    {
        int mij = p + (u - p) / 2;

        if( median(mij) )
        {
            ans = mij;
            u = mij - 1;
        }
        else
            p = mij + 1;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main (){
  int A,B;
  cin>>A>>B;
  if(A>12){
    cout<<B<<endl;
  }
  else if(12>=A&&A>=6){
    cout<<B/2<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, K; cin >> N >> K;
    if (K >= N) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> H(N);
    ll sum = 0;
    rep (i, N) {
        cin >> H.at(i);
        sum += H[i];
    }
    sort(begin(H), end(H), greater<int>());
    rep(i,K) {
        sum -= H[i];
    }

    cout << sum << endl;
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

int main(){
    string s; cin >> s;
    ll r = 0, ans = 0;
    REP(i, 0, s.size()){
        if(s[i] == 'W'){
            ans += (i-r);
            r++;
        }else{
        }
    }  
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main(){
    ll l,r; cin >> l >> r;
    ll ans=2018;
    if (r-l>=2019) r=2019+l-1;
    for(ll i=l; i<=r; i++){
        for (ll j=i+1; j<=r; j++){
            ll x=i*j%2019;
            ans=min(x,ans);
        }
    }
    cout << ans;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

const int INF = 125283025;

char sa[2521],sb[2521];
int n;

typedef bitset<2048> bit;
bit a,b;
bit rsft[4252], lsft[4252];

int solve(){
  a.reset();
  b.reset();
  REP(i,n)if(sa[i]=='1')a.set(i);
  REP(i,n)if(sb[i]=='1')b.set(i);
  {
    bit tmp = b;
    rsft[0] = b;
    FOR(i,1,4252){
      if(tmp[0])tmp.set(n);
      tmp >>= 1;
      rsft[i] = rsft[i-1] | tmp;
    }
  }
  {
    bit tmp = b;
    lsft[0] = b;
    FOR(i,1,4252){
      tmp <<= 1;
      if(tmp[n]){
        tmp.reset(n);
        tmp.set(0);
      }
      lsft[i] = lsft[i-1] | tmp;
    }
  }
  bit mask;
  REP(i,n)mask.set(i);
  int ans = INF;
  REP(head,n){
    bit po = ((a>>head) | (a<<(n-head))) & mask;
    po = po ^ b;
    po = ((po<<head) | (po>>(n-head))) & mask;
    int lsval = 2521;
    REP(rsval,2521){
      while(lsval>0){
        bit howa = rsft[rsval] | lsft[lsval-1];
        if((howa&po) == po){
          lsval--;
        }else{
          break;
        }
      }
      if(rsval==0 && lsval==2521){
        break;
      }
      int tmp = po.count() + rsval + lsval;
      // if(tmp <= 2){
      //   DEBUG(head);
      //   DEBUG(lsval);
      //   DEBUG(rsval);
      //   DEBUG(po);
      //   DEBUG(a);
      //   DEBUG(b);
      //   DEBUG(rsft[rsval]);
      //   DEBUG(lsft[lsval]);
      // }
      swap(rsval, lsval);
      // rs -> ls
      int rlhead = (head + lsval) % n;
      CHMIN(ans, tmp + rsval + min(rlhead, n-rlhead));
      // ls -> rs
      int lrhead = (head - rsval + n) % n;
      CHMIN(ans, tmp + lsval + min(lrhead, n-lrhead));

      swap(rsval, lsval);
    }
  }
  return ans;
}

int main(){
  scanf("%s%s",sa,sb);
  n = strlen(sa);
  int ans = solve();
  // reverse(sa,sa+n);
  // reverse(sb,sb+n);
  // CHMIN(ans,solve());
  if(ans==INF){
    ans = -1;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2432
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

# mod m での aの逆元
# mが素数のときのみ有効
def modinv(a, m)
  b = m; u = 1; v = 0

  while b != 0
    t = a / b
    a -= t * b
    c = a; a = b; b = c
    u -= t * v
    c = u; u = v; v = c
  end
  u %= m
  u += m if u < 0
  u
end


def nCk(n, k, mod)
  ue = 1
  shita = 1
  k.times do |a|
    ue = ue * (n - a) % mod
    shita = shita * (k - a) % mod
  end
  ue * modinv(shita, mod) % mod
end

def nHk(n, k, mod)
  nCk(n+k-1, k, mod)
end

N, M = get_ints
MOD = 10 ** 9 + 7

require 'prime'

divisions = Prime.prime_division(M)

count = 1
divisions.map do |p, num|
  count *= nHk(N, num, MOD)
  count = count % MOD
end

puts count


Measured memory_bytes: 14640
#include<bits/stdc++.h>
#include <vector>
#define endl '\n';
using namespace std;

int main()
{   
    int n, m; cin >> n >> m;
    int s[51][2];
    int p[51][2];
    for (int i = 0; i < n; ++i)
        cin >> s[i][0] >> s[i][1];
    for (int i = 0; i < m; ++i)
        cin >> p[i][0] >> p[i][1];
    for (int i = 0; i < n; ++i) {
        int mn = INT_MAX;
        int chosen = i;
        int xindx = -1;
        for (int j = 0; j < m; ++j) {
            int val = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1]);
            if (val < mn) 
                mn = val, chosen = j + 1, xindx = p[j][0]; 
            else if(val == mn && p[j][0] < xindx) 
                mn = val, chosen = j + 1, xindx = p[j][0];
        }
        cout << chosen << "\n";
    }
    return 0;
}

Measured memory_bytes: 3568
while True:
    pos=[[0]*2 for i in range(21)]
    N =input()
    if N == 0: break
    for i in range(N):
        l = map(int, raw_input().split())
        pos[i][0]=l[0]
        pos[i][1]=l[1]
    initx=10
    inity=10
    K = input()
    count=0
    for i in range(K):
        dx=0
        dy=0
        d,l = raw_input().split()
        l = int(l)
        if d == 'N': dy=1
        if d == 'S': dy=-1
        if d == 'W': dx=-1
        if d == 'E': dx=1

        for j in range(l):
         initx=initx+dx
         inity=inity+dy
         for k in range(N):
             if initx==pos[k][0] and inity==pos[k][1]:
                 count+=1
                 pos[k][0]=pos[k][1]=-1
    if count==N: print 'Yes'
    else: print 'No'

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int INF = 1e9+10;

string vs[50];

int r,c,ans;

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

bool ok(int i,int j){
	return i>=0&&i<r&&j>=0&&j<c&&vs[i][j]=='.';
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>r>>c;
	for(int i=0;i<r;++i)
		cin>>vs[i];
	for(int i=0;i<r;++i){
		for(int j=0;j<c;++j){
			if(vs[i][j]!='.') continue;
			queue<pair<int,int>> q;
			vector<vector<int>> dist(r,vector<int>(c,INF));
			dist[i][j]=0;
			q.push({i,j});
			while(!q.empty()){
				int x = q.front().ff,y = q.front().ss;
				q.pop();
				for(int k=0;k<4;++k){
					if(ok(x+dx[k],y+dy[k]) && dist[x][y]+1 < dist[x+dx[k]][y+dy[k]]){
						q.push({x+dx[k],y+dy[k]});
						dist[x+dx[k]][y+dy[k]]=dist[x][y]+1;
						ans = max(ans,dist[x][y]+1);
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X, Y = MAP()
dic = defaultdict(int)
for i in range(1, N+1):
    for j in range(1, N+1):
        tmp = min(abs(i - j), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(X-j))
        dic[tmp] += 1
for i in range(1, N):
    print(dic[i]//2)        



Measured memory_bytes: 55644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;
const int MAX_N=110000;
int dp[MAX_N];
int main(){
    int N;
    cin>>N;
    for(int i=0;i<MAX_N;i++){
        dp[i]=N;
    }
    dp[0]=0;
    for(int n=1;n<=N;n++){
        for(int pow6=1;pow6<=n;pow6*=6){
            dp[n]=min(dp[n],dp[n-pow6]+1);
        }
        for(int pow9=1;pow9<=n;pow9*=9){
            dp[n]=min(dp[n],dp[n-pow9]+1);
        }
    }
    cout<<dp[N]<<endl;
    return 0;
}

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

double L;

int main(){

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

	cin >> L;
	
	double a = L/3;
	
	double ans = a*a*a;
	
	cout << fixed << setprecision(12) << ans;
	
	return 0;
}


Measured memory_bytes: 256
int main(void){
	int A,B,winner=0;
	
	scanf("%d %d", &A,&B);
	
	if(A == 1 || B == 1){
		if(A != 1){
			winner = 2;
		}else if(B != 1){
			winner = 1;
		}else{
			winner = 0;
		};
	}else{
		if(A > B){
			winner = 1;
		}else if(A < B){
			winner = 2;
		}else{
			winner = 0;
		};
	};
	
	if(winner == 1){
		printf("Alice");		
	}else if(winner == 2){
		printf("Bob");
	}else{
		printf("Draw");
	};
}

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

#define RREP(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define INVREP(i,a,b) for(int i=a;i>=b;--i)
#define MOD 1000000007ll
#define FACT(n) 
#define BIT(n) (1LL<<(n)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }//aに更新したいものを
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using ll = long long int;
//繰り返し2乗
ll modpow(ll N, ll P, ll M=MOD) {if (P == 0) return 1;if (P % 2 == 0) {ll t = modpow(N, P / 2, M);return t * t % M;}return (N * modpow(N, P - 1, M))%M;}
//階乗
pair<vector<ll>, vector<ll>> fact(ll n) {vector<ll>f(n, 1);RREP(i, 2, n) f[i] = (f[i - 1]*i) % MOD;vector<ll>invf(n, 1);invf[n - 1] = modpow(f[n - 1],MOD-2,MOD);INVREP(i, n - 1, 2) invf[i - 1] = (invf[i]*i) % MOD;return pair<vector<ll>, vector<ll>>(f,invf);}
ll modmult(ll a, ll b, ll M = MOD) { return (a*b) % M; }
ll modadd(ll a, ll b, ll M = MOD) { return (a + b) % M; }
ll comb(pair<vector<ll>, vector<ll>>p, int n, int r) {return modmult(modmult(p.first[n], p.second[r]), p.second[n - r]); }
/*
	auto a = fact(200009);
	cout << comb(a,15,5) << endl;
*/

int main()
{
	/* collection
	int n;
	cin >> n;
	vector<int> A;
	REP(i, n) cin >> A[i];
	vector<pair<int, int>> AB;
	REP(i, n) {cin >> AB[i].first;cin >> AB[i].second;}
	
	sort(ALL(vec),greater<int>());

	map<int, int> mp;
	map<int, int, greater<int>> mp;
	REP(i, 100) mp[i] = i * 10;
	cout << mp.lower_bound(50)->second<<endl;
	cout << mp.upper_bound(50)->second << endl;
	cout << next(mp.upper_bound(50))->second << endl;
	cout << prev(mp.upper_bound(50))->second << endl;
	*/

	int n,x,y;
	cin >> n;
	cin >> x;
	cin >> y;
	x = x - 1;
	y = y - 1;

	for(int k=1;k<n;k++) {
		//cout << "k=" << k << endl;
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (i <= x - k) {
				//前
				ans++;
				//cout << i << "front";
			}
			else if (i <= x) {
				//3つ、前
				int p3 = y + (k - (x-i + 1));
				int p2 = y - (k - (x-i + 1));
				int p1 = i + k;
				if (p3 <= n - 1 && p3!=p2) ans++;
				/*if (p3 <= n - 1) cout << i << " frontaaa" << endl;*/
				if (p1 < p2) { ans += 2; /*cout<<i << " 2hit" << endl;*/ }
				else if (p1 == p2) { ans += 1; /*cout << i << " 1hit";*/ }
			}
			else if (i <= x + k - 1 && i<= (x+y-1)/2) {
				//3つ、中
				int p3 = y + (k - (i - x + 1));
				int p2 = y - (k - (i - x + 1));
				int p1 = i + k;
				//cout << i;
				if (p3 <= n - 1 && p3 != p2) { ans++; /*cout << "frontbbb" << endl;*/ }
				if (p1 < p2) { ans += 2; /*cout << "hit2 u" << endl;*/ }
				else if (p1 == p2) { ans += 1;/* cout << "hit1 u" << endl;*/ }
			}
			else {
				//1つのみ
				if (i + k <= n - 1) { ans++; /*cout << i << "hit left" << endl;*/ }
			}
		}
		cout << /*endl <<*/ ans << endl;
	}
}

Measured memory_bytes: 256
a,b,m=map(int, input().split())  
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=min(A)+min(B)
xyc=[]
for i in range(m):
    x,y,c=map(int, input().split())
    x-=1
    y-=1
    ans=min(ans, A[x]+B[y]-c)
print(ans)

Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
 cin>>n;
 int a[200001];
 int i=1;
 int k=0;int h=0;
 for(int g=0;g<n;g++)
   cin>>a[g];
 for(int j=0;j<n;j++)
 { if(a[j]==i)
   {h++;
    i++;
    }
   else 
     continue;
 
 
 
 }
 if(h>0)
  cout<<n-h;
 else 
   cout<<-1;
return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main(int argc, char** argv)
{
   int A, B, C;
   int sum;
   std::cin >> A >> B >> C;

   if(A + B < B + C){
      if(A + B < C + A){
         std::cout << A + B << std::endl;
      } else std::cout << C + A << std::endl;
   } else {
      if(B + C < C + A) std::cout << B + C << std::endl;
      else std::cout << C + A << std::endl;
   }

   return 0;
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let line = get_input();
    let mut nab = line.split_whitespace();
    let n: u32 = nab.next().unwrap().parse().unwrap();
    let a: u32 = nab.next().unwrap().parse().unwrap();
    let b: u32 = nab.next().unwrap().parse().unwrap();

    let mut sum = 0;
    for i in 1..n+1 {
        let mut s:u32 = 0;
        let v:Vec<char> = i.to_string().chars().collect();
        for _v in v {
            s = s + _v.to_digit(10).unwrap();
        }
        if a <= s && s <= b {
            sum = sum + i;
        }
    }

    println!("{}", sum);
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    rep(i,n) cin >> x[i] >> y[i];

    vector<int> a(n);
    rep(i,n) a[i] = i;
    double total_distance = 0;
    int cnt = 0;
    do{
        
        double distance = 0;
        rep(i,n-1)
            distance += sqrt(pow((x[a[i]] - x[a[i+1]]),2) + pow((y[a[i]] - y[a[i+1]]),2));

        total_distance += distance;
        cnt++;
    } while(next_permutation(a.begin(), a.end()));

    cout << fixed << setprecision(10) << total_distance / cnt << endl;

    return 0;

}

Measured memory_bytes: 3844