akhauriyash/Code-Regression huggingface dataset:
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include <bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li      int64_t
#define ld      double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define repir(i,v)  for(i=v.rbegin();i!=v.rend();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl          cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpli;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define rtr reverse_iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={+1,+1,-1,-1,+2,+2,-2,-2};li dy[]={+2,-2,+2,-2,+1,-1,+1,-1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

string s;

void solve(){
  li i,n;cin>>s;
  n=s.length();
  li cnt=0;
  rep(i,0,n){
    if(s[i]=='1') cnt++;
  }
  cout<<cnt;
}

int main(){
  opt
  #ifndef ONLINE_JUDGE
  #endif
  li t=1;
  //cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;
signed main()
{
int N;
int a[105];
int ans = 0;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> a[i];
ans += a[i];
}
sort(a, a+N);
ans -= a[N-1];
ans += a[N-1] / 2;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();
    String t = sc.next();

    Character[] trans = new Character[128];

    for (int i = 0; i < s.length(); i++) {
      char sch = s.charAt(i);
      char tch = t.charAt(i);
      if (trans[tch] != null && trans[tch] != sch) {
        os.println("No");
        return;
      }
      trans[tch] = sch;
    }

    Set<Character> occur = new HashSet<>();
    for (char c = 'a'; c <= 'z'; c++) {
      if (trans[c] == null) continue;
      if (occur.contains(trans[c])) {
        os.println("No");
        return;
      }
      occur.add(trans[c]);
    }

    os.println("Yes");
  }

}


Measured memory_bytes: 27000
#!python3

import sys

iim = lambda: map(int, input().rstrip().split())

def popcnt2(n):
    a = (
        0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
        4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
    )
    ans = 0
    while n:
        ans += a[n&0xff]
        n >>= 8
    return ans

def resolve():
    N = int(input())
    S = list(input())
    Q = int(input())

    c0 = ord('a')
    smap = [1<<(i-c0) for i in range(c0, ord('z')+1)]

    T = [0]*N + [smap[ord(S[i])-c0] for i in range(N)]

    for i in range(N-1, 0, -1):
        i2 = i << 1
        T[i] = T[i2] | T[i2|1]

    ans = []
    #print(T)
    for cmd, i, j in zip(*[iter(sys.stdin.read().split())]*3):
        i = int(i) - 1
        if cmd == "1":
            if S[i] == j:
                continue

            S[i] = j
            i0 = N + i
            T[i0] = smap[ord(j)-c0]
            while i0 > 1:
                i0 = i0 >> 1
                T[i0] = T[i0+i0] | T[i0-~i0]
        elif cmd == "2":
            i += N
            j = int(j) + N

            d1 = 0
            while i < j:
                if i & 1:
                    d1 |= T[i]
                    i += 1
                if j & 1:
                    j -= 1
                    d1 |= T[j]

                i >>= 1; j >>=1

            ans.append(popcnt2(d1))

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 33212
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let prr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let p = Array.fold_left (fun (minN, ans) x -> if minN >= x then (x, ans+1) else (minN, ans)) (prr.(0), 0) prr in
  Printf.printf "%d\n" (snd p)

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

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define PI 3.14159265358979323846264338327950L
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
int t;

void slove()
{
	string s;
	cin >> s;
	int n = s.size();
	vector<int> sum(n + 1);
	sum[0] = (s[0] == 'B');
	for(int i = 1;i < s.size();i ++){
		sum[i] = sum[i-1] + (s[i] == 'B');
	}
	ll ans = 0;
	for(int i = s.size() ;i >= 0;i --)
	{
		if(s[i] == 'W')
			ans += sum[i];
	}
	cout << ans << endl;
}
int main()
{
	SIS;
	slove();
}

Measured memory_bytes: 4316
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int a, b, k;
	cin >> a >> b >> k;
	if (k <= a) {
		cout << a - k << " " << b << endl;
	}
	else if (k <= a + b) {
		cout << 0 << " " << b - (k - a) << endl;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
class Edge:
    def __init__(self, to, id):
        self.to = to
        self.id = id
N = int(input())
graph = {}
ans = [0] * (N-1)
def dfs(v, c=-1, p=-1):
    global graph, ans
    k = 1
    for edge in graph[v]:
        nv = edge.to
        if nv == p:continue
        if k == c:k += 1
        ans[edge.id] = k
        dfs(nv, k, v)
        k += 1
def main():
    global N, graph, ans
    for i in range(N):
        graph[i] = set()
    for i in range(N-1):
        a, b = map(int, input().split())
        graph[a-1].add(Edge(b-1, i))
        graph[b-1].add(Edge(a-1, i))
    color_count = 0
    for i in range(N):
        color_count = max(color_count, len(graph[i]))
    dfs(0, 0, -1)
    print(color_count)
    for x in ans:
        print(x)
if __name__ == "__main__":
    main()

Measured memory_bytes: 109532
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	ansmax := 0

	for i := 1; i*i <= n; i++ {
		// iのpowの最大値を求める
		ipowmax := 0
		for j := 0; j <= 10; j++ {
			if pow(i, j) <= n {
				ipowmax = max(ipowmax, pow(i, j))
			}
		}
		ansmax = max(ansmax, ipowmax)
	}

	fmt.Println(ansmax)

}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
n, k = gets.chomp.split.map(&:to_i)
s = gets.chomp

score = 0

length = n

n.times do |i|
  next if i == 0
  if s[i-1] == s[i]
    score += 1
    length -= 1
  end
end

if length == 1
  puts score
elsif length >= 2
  if length % 2 == 1
    max = length / 2
    score += [max, k].min * 2
    puts score
  else
    max = length / 2
    if max <= k
      score += (max - 1) * 2 + 1
    else
      score += k * 2
    end
    puts score
  end
end


Measured memory_bytes: 1916
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}
 

 
int main(void){
    string s,t;
    cin>>s>>t;
    int n = s.length();
    int m = t.length();
    int ans = inf;
    for(int i=0;i<=n-m;i++){
        int tmp = 0;
        for(int j=0;j<m;j++){
            if(s[i+j]!=t[j])tmp++;
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	
	uint N;
	cin >> N;
	
	vector<vector<int>> P(N, vector<int>(N, -1));
	
	for(uint i=0; i<N; i++) {
		uint A;
		cin >> A;		
		for(uint j=0; j<A; j++) {
			int x, y;
			cin >> x >> y;
			P[i][x-1] = y;
		}
	}
	
	uint ans = 0;
	
	for(uint i=0; i<pow(2, N); i++) {
		boost::dynamic_bitset<> tf;
		tf.append(i);
		
        if(ans >= tf.count()) continue;

		bool judge = true;
		for(uint l=0; l<N && judge; l++) {
			if(tf[l]) {
				for(uint m=0; m<N && judge; m++) {
					if(P[l][m] == -1 || l == m) {
						continue;						
					} else if(P[l][m] != tf[m]) {
						judge = false;
					}
				}
			}
		}
		uint tans = tf.count();
		ans = (judge) ? max(ans, tans) : ans;
	}
		
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4012
#include<stdio.h>

int main(void){
	int h,w,i,j;
	char map[100][100],been[100][100];
	scanf("%d%d",&h,&w);
	while(h!=0 && w!=0){
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				scanf(" %c ",&map[i][j]);
				been[i][j]=0;
			}
		}
		i=0;
		j=0;
		while(map[i][j]!='.' && been[i][j]!=1){
			been[i][j]=1;
			if(map[i][j]=='>'){
				j++;
			}else if(map[i][j]=='<'){
				j--;
			}else if(map[i][j]=='v'){
				i++;
			}else if(map[i][j]=='^'){
				i--;
			}
		}
		if(been[i][j]==0){
			printf("%d %d\n",j,i);
		}else{
			printf("LOOP\n");
		}
		scanf("%d%d",&h,&w);
	}
	return 0;
}

Measured memory_bytes: 636
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }


        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] b = cin.ReadIntArray(n);
            List<int> bList = b.ToList();

            List<int> ans = new List<int>();
            bool flag = true;
            while (flag && bList.Count > 0)
            {
                flag = false;
                for (int i = bList.Count; i > 0; i--)
                {
                    if (bList[i - 1] == i)
                    {
                        flag = true;
                        ans.Add(i);
                        bList.RemoveAt(i - 1);
                        break;
                    }
                }
            }

            if (ans.Count == b.Length)
            {
                ans.Reverse();
                Console.WriteLine(String.Join("\n", ans));
            }
            else
            {
                Console.WriteLine("-1");
            }
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005


int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

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

int main(void){

  int r[200000], i, j, n, co = 1000000001, coo = -1000000000;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &r[i]);
  }

  for(i = 0; i < n; i++){
    if(co < r[i]) continue;
    co = r[i];
    for(j = 1+i; j < n; j++){
      if(coo < r[j] - r[i]){
	coo = r[j] - r[i];
      }
    }
  }

  printf("%d\n", coo);

  return 0;
}

Measured memory_bytes: 1380
import sys

N, K, *X = map(int, sys.stdin.read().split())

ans = 10**20
for l, r in zip(X, X[K-1:]):
    if l*r < 0:
        dist = min(-2*l + r, 2*r - l)
    else:
        dist = max(abs(l), abs(r))
    if ans > dist:
        ans = dist
print(ans)


Measured memory_bytes: 14052
from itertools import product


def solve(T, PTTN):
    lst = [l[i] for i, t in enumerate(PTTN) if t == T]
    ANS = 10 ** 5
    if lst:
        ANS = (len(lst) - 1) * 10
        ANS += abs(sum(lst) - tgt[T])
    return ANS


tgt = list(map(int, input().split()))
l = [int(input()) for _ in range(tgt[0])]

ans = 10 ** 5
for pttn in product([0, 1, 2, 3], repeat=tgt[0]):
    tmp = sum(solve(i + 1, pttn) for i in range(3))
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 77680
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long LL;

const int MAXN = 500000;
const int MOD = 998244353;

inline int Add(int x, const int &y) {
	return (x += y) >= MOD ? x - MOD : x;
}

inline int Mul(const int &x, const int &y) {
	return (LL)x * y % MOD;
}

int Pow(int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1)
			ret = Mul(ret, x);
		y >>= 1;
		x = Mul(x, x);
	}
	return ret;
}

int N, M;
int Fac[2 * MAXN + 5], InvFac[2 * MAXN + 5];

int C(int n, int m) {
	return Mul(Fac[n], Mul(InvFac[m], InvFac[n - m]));
}

int InvC(int n, int m) {
	return Mul(Mul(Fac[m], Fac[n - m]), InvFac[n]);
}

int main() {
	scanf("%d%d", &N, &M);
	if (N < M) std::swap(N, M);
	Fac[0] = 1;
	for (int i = 1; i <= 2 * N; i++)
		Fac[i] = Mul(Fac[i - 1], i);
	InvFac[2 * N] = Pow(Fac[2 * N], MOD - 2);
	for (int i = 2 * N - 1; i >= 0; i--)
		InvFac[i] = Mul(InvFac[i + 1], i + 1);
	int Ans = 0;
	for (int i = 1; i <= M; i++)
		Ans = Add(Ans, Mul(C(2 * i, i), C(N - i + M - i, N - i)));
	Ans = Mul(Ans, Mul(Pow(2, MOD - 2), InvC(N + M, N)));
	printf("%d", Add(Ans, N));
}


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

int n,s[10000],q,t,c=0,j;

int main() {
	cin >> n;
	rep(i,0,n) cin >> s[i];
	cin >> q;
	rep(i,0,q){
		cin >> t;
		rep(j,0,n){
			if(t==s[j]){
				c++;
				break;
			}
		}
	} 
	cout << c << endl;
	return 0;
}


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

int main(){
  int n, m, d, dx, dy;
  vector< vector<int> > ab, cd;
  cin >> n >> m;
  ab.resize(n);
  for(int i=0;i<n;i++){
    ab[i].resize(2);
  }
  cd.resize(m);
  for(int i=0;i<m;i++){
    cd[i].resize(2);
  }
  for(int i=0;i<n;i++){
    cin >> ab[i][0] >> ab[i][1];
  }
  for(int i=0;i<m;i++){
    cin >> cd[i][0] >> cd[i][1];
  }
  for(int i=0;i<n;i++){
    int min = 1000000000, min_pos;
    for(int j=0;j<m;j++){
      dx = ab[i][0] - cd[j][0];
      if(dx<0)dx *= -1;
      dy = ab[i][1] - cd[j][1];
      if(dy<0)dy *= -1;
      d = dx + dy;
      if(min>d){
        min = d;
        min_pos = j+1;
      }
    }
    cout << min_pos << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using LL = long long;
LL N, M, S;
LL A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) s += max(0ll, ceil(A[i]+x+1-N, N+1));
  return s <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-N*N); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    
    bool N = false;
    bool W = false;
    bool S = false;
    bool E = false;
    rep(i,n){
        if(s[i] == 'N')N = true;
        if(s[i] == 'W')W = true;
        if(s[i] == 'S')S = true;
        if(s[i] == 'E')E = true;
    }
    
    if(N != S || W != E)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define ll long long
#define xmod 1000000007
using namespace std;

int n,a[105],ans;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for (int i=1;i<=n;i++){
		if (a[i] > a[i-1])
		ans+=(a[i]-a[i-1]);
	}
	printf("%d\n",ans);
    return 0;
}
//3 4 5 6 7

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()

typedef unsigned long long ll;

int main(){
    int N,A,B; cin >> N >> A >> B;
    rep(i,100){
        if(i % 2 == 0 && B - A == 1){
            cout << "Borys"<< endl;
            break;
        }
        else if(i % 2 == 1 && B - A == 1){
            cout << "Alice" << endl;
            break;
        }
        if(i % 2 == 0){
            A++;
        }
        else{
            B--;
        }
    }
}

Measured memory_bytes: 256
N, M = map(int,input().split())
P = 1000000007
a = []
for _ in range(M):
    a.append(int(input()))
a.append(N+3)
dp = [0]*(N+2)
dp[0] = 0
dp[1] = 1
t = 0
for i in range(N):
    if i+1 == a[t] :
        t += 1
        continue
    else:
        dp[i+2] = (dp[i+1] + dp[i])%P
print(dp[N+1])


Measured memory_bytes: 7848
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
     ll k,n,sum=0;
         cin>>k>>n;
         for(ll i=0; i<n; i++){
            ll l; cin>>l;
            sum+=l;}
            
            if(sum<k)
            cout<<"No"<<endl;
            else
            cout<<"Yes"<<endl;
          
         }
//aaaaa


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int A,B,Q;
  cin>>A>>B>>Q;
  vector<ll> s,t;
  for(int i=0;i<A;i++){
      ll x;
      cin>>x;
      s.push_back(x);
  }
  for(int i=0;i<B;i++){
      ll x;
      cin>>x;
      t.push_back(x);
  }
  vector<ll> X;
  for(int i=0;i<Q;i++){
      ll x;
      cin>>x;
      X.push_back(x);
  }

  for(int i=0;i<Q;i++){
      ll sl=upper_bound(s.begin(),s.end(),X[i])-s.begin();
      ll tl=upper_bound(t.begin(),t.end(),X[i])-t.begin();
      ll sr=lower_bound(s.begin(),s.end(),X[i])-s.begin();
      ll tr=lower_bound(t.begin(),t.end(),X[i])-t.begin();
      ll ans=1e18;
      ll left=1e18,right=1e18;
      if(sl!=0&&tl!=0){
          ans=min(ans,X[i]-min(s[sl-1],t[tl-1]));
      }
      if(sr!=A&&tr!=B){
          ans=min(ans,max(s[sr],t[tr])-X[i]);
      }

      if(sl!=0&&tr!=B){
          ll mi=min(X[i]-s[sl-1],t[tr]-X[i]);
          ll ma=max(X[i]-s[sl-1],t[tr]-X[i]);
          ans=min(ans,mi*2+ma);
      }
      if(tl!=0&&sr!=A){
          ll mi=min(X[i]-t[tl-1],s[sr]-X[i]);
          ll ma=max(X[i]-t[tl-1],s[sr]-X[i]);
          ans=min(ans,mi*2+ma);
      }
      cout<<ans<<endl;
  }
  

  return 0;
}


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

int i=0;
int N=100000;

int main(){
	char *moji=malloc(N*sizeof(char));
	char *ans=malloc(N*sizeof(char));
	scanf("%s",moji);

	while (moji[i]!=0){
		if (i==(i/2)*2){
			ans[i/2]=moji[i];
		}
		i++;
	}

	printf("%s\n",ans);
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int length = S.size();
  ll res = 0;
  int tmp_position = 0;
  ll tmp_res = 0;
  for (int i = 1; i < length; i++) {
    if (S[i] == 'W') {
      for (int j = tmp_position; j < i; j++) {
        if (S[j] == 'B') tmp_res++;
      }
      tmp_position = i;
      res += tmp_res;
    }
  }
  cout << res;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll wt[109];
ll price[109];
ll dp[109][100000];
ll knapsack(ll n,ll w)
{
    if(n==0 or w==0)
    {
        return 0;
    }
    ll inc=0,exc=0;
    if(w>=wt[n-1])
    {
        inc=price[n-1]+knapsack(n-1,w-wt[n-1]);
    }
    exc=knapsack(n-1,w);
    return max(inc,exc);
} 
ll topdown(ll n,ll w)
{
    if(n==0 or w==0)
    {
        dp[n][w]=0;
        return 0;
    }
    if(dp[n][w]!=-1)
    {
        return dp[n][w];
    }
    ll inc=0,exc=0;
    if(w>=wt[n-1])
    {
        inc=price[n-1]+topdown(n-1,w-wt[n-1]);
    }
    exc=0+topdown(n-1,w);
    dp[n][w]=max(inc,exc);
    return dp[n][w];
}
int main()
{
    
    memset(dp,-1,sizeof dp);
    ll n,w;
    cin>>n>>w;
    for(ll i=0;i<n;i++)
    {
        cin>>wt[i]>>price[i];
    }
    cout<<topdown(n,w)<<endl;
    return 0;
}

Measured memory_bytes: 88780
#include <iostream>
#include <vector>

using namespace std;

void PrintChessboard(vector<vector<int>> data){

    for ( vector<int> elem : data) {
        int height = elem[0];
        int width = elem[1];
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if( (j + i)%2 == 1)
                    cout << ".";
                else
                    cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}

int main(){
    // ---------------------------
    // ITP_1_5_A: Print a Rectangle
//    int w, h;
//    std::vector<std::vector<int>> data;
//    while (true){
//        std::cin >> h >> w;
//        if (h == 0 && w ==0)
//            break;
//        data.push_back({h, w});
//    }
//    PrintRectangle(data);
    // ---------------------------

    // ---------------------------
    // ITP_1_5_B: Print a Frame
//    int w, h;
//    std::vector<std::vector<int>> data;
//    while (true){
//        std::cin >> h >> w;
//        if (h == 0 && w ==0)
//            break;
//        data.push_back({h, w});
//    }
//    PrintFrame(data);
    // ---------------------------

    // ---------------------------
    // ITP_1_5_C: Print a Chessboard
    int w, h;
    std::vector<std::vector<int>> data;
    while (true){
        std::cin >> h >> w;
        if (h == 0 && w ==0)
            break;
        data.push_back({h, w});
    }
    PrintChessboard(data);
    // ---------------------------

    // ---------------------------
    // ITP_1_5_D: Structured Programing
    // ---------------------------

    return 0;
}


Measured memory_bytes: 3128
def main():
    x,k,d = map(int,input().split())
    x = abs(x)
    if x < k*d:
        # minimum = min(d-(x%d),x % d)
        cnt, amari = divmod(x,d)
        if abs(amari-d) < amari:
            amari = abs(amari - d)
            cnt += 1
        if (k-cnt)%2==0:
            print(amari)
        else:
            print(abs(amari-d))

    else:
        print(x-k*d)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 61912
#include <bits/stdc++.h>
#define ll long long
#define fr(i,n) for(ll i=0;i<n;i++)
using namespace std;
const ll mod=1e6+7;


int main() {
ll n,m,g,ans=1;
cin>>n>>m;



g=__gcd(n,m);
for(ll i=2;i<mod;i++){
    if(g%i)continue;
    while(g%i==0)g/=i;ans++;


    }
    if(g!=1)ans++;
cout<<ans;
}


Measured memory_bytes: 3612
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    s = input()
    x, y = map(int, input().split())
    """
    x, y方向独立に考えられることには気づいたけど、その後の遷移が2^N通りで無理だと思い込んでた。。。
    もらうdpで考えれば確かにO(N^2)で片付く。
    """
    C = [deque([]), []]
    direction = 0 # = X
    cnt = 0
    for c in s:
        if c == 'F':
            cnt += 1
            continue
        if c == 'T':
            C[direction].append(cnt)
            cnt = 0
            direction = 1 - direction
    C[direction].append(cnt)
    
    X = [0] * 16001
    if s[0] == 'F':
        start = C[0].popleft()
        X[8000 + start] = 1
    else:
        X[8000] = 1
    for cnt in C[0]:
        X_new = [0] * 16001
        for i in range(16001):
            if 0 <= i - cnt and i + cnt <= 16000:
                X_new[i] = 1 - (1 - X[i - cnt]) * (1 - X[i + cnt])
            elif 0 <= i - cnt:
                X_new[i] = X[i - cnt]
            else:
                X_new[i] = X[i + cnt]
        X = X_new

    Y = [0] * 16001
    Y[8000] = 1
    for cnt in C[1]:
        Y_new = [0] * 16001
        for i in range(16001):
            if 0 <= i - cnt and i + cnt <= 16000:
                Y_new[i] = 1 - (1 - Y[i - cnt]) * (1 - Y[i + cnt])
            elif 0 <= i - cnt:
                Y_new[i] = Y[i - cnt]
            else:
                Y_new[i] = Y[i + cnt]
        Y = Y_new
    
    if X[8000 + x] == 1 and Y[8000 + y] == 1:
        print("Yes")
    else:
        print("No")

    


if __name__ == "__main__":
    main()


Measured memory_bytes: 97512
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = [INT() for _ in range(N)]

A.sort()
#print(A)
ans = float('INF')
for i in range(N-K+1):
	a = A[i+K-1]-A[i]
	#print(a)
	ans = min(a, ans)
print(ans)

Measured memory_bytes: 44764
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    
    int N6 = N / 100000 % 10;
    int N5 = N / 10000 % 10;
    int N4 = N / 1000 % 10;
    int N3 = N / 100 % 10;
    int N2 = N / 10 % 10;
    
    int result = 0;
    if(N6 == 1){
      result = 90909;
    } else if(N5 != 0){
      result = (N - 9999) + 909;
    } else if(N4 != 0){
      result = 909;
    } else if(N3 != 0){
      result = (N - 99) + 9;
    } else if(N2 != 0){
      result = 9;
    } else {
      result = N;
    }
    
    System.out.println(result);
  }
}


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

int main() {
  int64_t n, k, y;
  cin >> n >> k;
  int64_t x = n;

  if(n > k){
    x -= n / k * k;
  }
  while(1){
    y = x;
    x = abs(x - k);
    if(y <= x)
      break;
  }

  cout << y;
}

Measured memory_bytes: 3640
import sys
from collections import Counter

def main():
    
    # sys.stdin = open('input155c.txt')
   
    n = int(input())
    
    a = []
    for _ in range(n):
        a.append(input())

    b = Counter(a)    
    max_val = max(b.values())
    max_val = [key for key in b if b[key] == max_val]

    sort_val = sorted(max_val)
    
    for i in sort_val:
        print(i)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template <class T> inline auto __lcm(T &a, T &b)
{ return a * b / __gcd(a, b); }


int main() {
    int A, B; cin >> A >> B;
    if (A <= 5) print(0);
    else if (A >= 13) print(B);
    else print(B/2);

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  string s; cin>>s;
  vector<string> a;
  for (int i=0; i<(int)(s.length()); i++) {
    string b="";
    while (s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T') {
      b+=s[i];
      i++;
    }
    a.push_back(b);
  }
  int len=0;
  for (int i=0; i<(int)(a.size()); i++) {
    if (len<(int)(a[i].length())) {
      len = (int)(a[i].length());
    }
  }
  cout << len << endl;
}

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


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

using namespace std;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
int main() {
    string S;
    int N;
    cin >> N >> S;
    int white = count(S.begin(), S.end(), '.');
    int tmp = white;
    int black = 0;
    REP(i, S.size()) {
        if (S[i] == '#') {
            black++;
        } else {
            white--;
        }
        if (tmp > white + black) {
            tmp = white + black;
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    char c;
    while(cin>>a>>c>>b){
        if(c=='+')cout<<(a+b)<<endl;
        else if(c=='-')cout<<(a-b)<<endl;
        else if(c=='*')cout<<a*b<<endl;
        else cout<<(a/b)<<endl;
    }
    return 0;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    ll maxcount;
    scanf("%lld", &N);
    vector<ll> H(N);
    REP(ll,i,0,N) scanf("%lld", &H.at(i));

    maxcount = 0LL;
    ans = 0LL;
    REP(ll,i,0,N-1){
        if ( H.at(i) >= H.at(i+1) ){
            maxcount++;
            ans = max(ans, maxcount);
        }
        else{
            maxcount = 0LL;
        }
    }
    ans = max(ans, maxcount);

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
import sys

H, W = map(int, raw_input().split())
a = []
for i in range(H):
	_a = list(raw_input())
	a.append(_a)
a = np.array(a)

row_exist = [False] * H
col_exist = [False] * W
for i in range(H):
	if '#' in a[i, :]:
		row_exist[i] = True
for i in range(W):
	if '#' in a[:, i]:
		col_exist[i] = True
for i in range(H):
	for j in range(W):
		if row_exist[i] and col_exist[j]:
			sys.stdout.write(a[i, j])
	if row_exist[i]:
		print ""


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

#define int long long
#define pii pair<int, int>
#define pb push_back
int dist(int x, int y){
    return abs(y - x);
}
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, x, y;
    cin >> n >> x >> y;
    int a[n]{};
    for(int i = 1 ; i <= n ; i++){
        for(int j = i + 1; j <= n ; j++){
            int d = dist(j,i);
            d = min(d, 1 + dist(i,x) + dist(j, y));
            d = min(d, 1 + dist(i,y) + dist(j, x));
            a[d]++;
        }
    }
    for(int i = 1 ; i <= n - 1; i++){
        cout << a[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int main(){
    int s,w;cin>>s>>w;
    if(s>w)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=1e9+7;
ll Pow(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return Pow(x*x%mod,n/2)%mod;
    else return x*Pow(x%mod,n-1)%mod;
}
int main(void){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    ll tmp0[k+1];
    rep(0,i,k){
        ll d=k-i;
        ll tmp=Pow(k/d,n);
        //cout<<tmp<<endl;
        rep(2,j,k+1){
            ll nd=j*d;
            if(nd>k)break;
            else{
                tmp=(tmp-tmp0[nd]+mod)%mod;//Pow(k/nd,n);
            }
            //cout<<tmp<<endl;
        }
        tmp0[d]=tmp;
        ans=(ans+d*tmp)%mod;
        ans%=mod;
        //cout<<ans<<endl;
    }
    ans%=mod;
    cout<<ans;
}

Measured memory_bytes: 4404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int N = 2e5 + 100;
VI G[N], rG[N];
int indeg[N], vis[N], order[N];


int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int n,m; cin >> n >> m;
    REP(i, n-1+m)
    {
        int a,b; cin >> a >> b;
        a; b;
        indeg[b]++;
        G[a].push_back(b);
        rG[b].push_back(a);
    }

    queue<int> q;
    VI seq;

    REP(i,n)
    {
        if(indeg[i] == 0)
        {
            vis[i] = 1;
            q.push(i);
            seq.pb(i);
        }
    }
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        for(int v : G[u])
        {
            if(--indeg[v] == 0)
            {
                q.push(v);
                seq.pb(v);
            }
        }
    }
    FOR(i, 0, seq.size())
    {
        order[seq[i]] = i; 
    }
    FOR(u,1,n+1)
    {
        int parent = 0;
        for(int v : rG[u])
        {
            if(parent == 0 || order[v] > order[parent]) parent = v;
        }
        cout << parent << endl;
    }



}


Measured memory_bytes: 18044
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int gcd(int a,int b){
    if(a<b) swap(a,b);
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    int n; cin  >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans;
    rep(i,n-1){
        ans=gcd(a[i],a[i+1]);
        a[i+1]=ans;
    }
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 640
N = gets.to_i
As = gets.split.map(&:to_i)

head = 0
tail = 0
ret = 0
x = 0
while tail < N do
  ret += 1
  if head == tail
    head += 1
    if As[head] & As[tail] != 0
      tail += 1
    end
    x = As[head] | As[tail]
  else
    if (head < N-1) && (x & As[head + 1] == 0)
      ret += (head - tail)
      head += 1
      x |= As[head]
    else
      x ^= As[tail]
      tail += 1
    end
  end
  # pp ret, [tail, head]
end
puts ret


Measured memory_bytes: 15364
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <array>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <stack>

int main()
{
	long long a, b, x;
	std::cin >> a >> b >> x;

	std::cout << std::fixed << std::setprecision(15);

	if (a * a * b / 2.0 <= x)
	{
		double alpha = std::atan2(2 * (a * a * b - x), a * a * a);
		std::cout << alpha * 180.0 / M_PI << std::endl;
	}
	else
	{
		double beta = std::atan2(2 * x, a * b * b);
		std::cout << 90.0 - beta * 180.0 / M_PI << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll qpow(ll a,ll b,ll M) {ll s=1;while(b){if(b&1)s=(s*a)%M;a=(a*a)%M;b>>=1;}return s; }
int n;char s[maxn];
int ans[maxn];
int dfs(int k)
{
    int cnt = 0;
    rep(i,0,25){
        if((k>>i)&1) cnt++;
    }
    return ans[k%cnt]+1;
}
void init()
{
    int n = 2e5+2;
    ans[0] = 0;
    rep(i,1,n) ans[i] = dfs(i);
}
int main()
{
    fastio();
    init();
    cin>>n>>s+1;
    int cnt = 0;
    rep(i,1,n){
        if(s[i]=='1') cnt++;
    }
    int x=0,z=0;
    rep(i,1,n){
        if(s[i]=='1'){
            if(cnt-1>1) x = (x*2+1)%(cnt-1);
            if(cnt!=n) z = (z*2+1)%(cnt+1);
        }else{
            if(cnt-1>1) x = (x*2)%(cnt-1);
            if(cnt!=n) z = (z*2)%(cnt+1);
        }
    }
    rep(i,1,n){
        if(s[i]=='1') {
            if(cnt!=1) {
                int res = (x-qpow(2,n-i,cnt-1)+cnt-1)%(cnt-1);
                cout<<ans[ res ]+1<<endl;
            }
            else cout<<0<<endl;
        }
        else {
            int res = (z+qpow(2,n-i,cnt+1))%(cnt+1);
            cout<<ans[ res ]+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b;
  cin >> a >> b;
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
using System;

namespace AGC021A
{
  class Program
  {
    static void Main(string[] args)
    {
      long N = long.Parse(Console.ReadLine());
      int dig = (int)Math.Log10(N);
      long n = (long)Math.Pow(10, dig);
      long res = 0;


      if (N < (n - 1) * 2) {
        res = 9 * dig;
      } else {
        long k = N / n;
        if (n * (k + 1) - 1 > N) {
          res = 9 * dig + k - 1;
        }
        else {
          res = 9 * dig + k;
        }
      }

      Console.WriteLine(res);
    }
  }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int x=fs.nextInt(), n=fs.nextInt();
		int[] a=fs.readArray(n);
		HashSet<Integer> set=new HashSet<>();
		for (int i:a) set.add(i);
		int offset=0;
		while (true) {
			if (!set.contains(x-offset)) {
				System.out.println(x-offset);
				return;
			}
			else if (!set.contains(x+offset)) {
				System.out.println(x+offset);
				return;
			}
			offset++;
		}
	}

	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 32768
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
  vector<int> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(all(a));
  cout << 10*a[2]+a[1]+a[0] << endl;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int d = max(abs(x2-x1),abs(y2-y1));
    int vx = x2-x1;
    int vy = y2-y1;

    cout << x2-vy << ' ' << y2+vx << ' ' << x1-vy << ' ' << y1+vx <<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  cin>>n;
  long long s[n][2];
  for(int i=0;i<n; i++) {
    cin>>x>>y;
    s[i][0] = x;
    s[i][1] = y;
  }
  long long res = INT_MIN;
  long long mxPlus = INT_MIN, mxSub = INT_MIN, mnPlus = INT_MAX, mnSub = INT_MAX;
  for(int i=0; i<n; i++) {
    mxPlus = max(mxPlus, s[i][0]+s[i][1]);
    mxSub = max(mxSub, s[i][0]-s[i][1]);
    mnPlus = min(mnPlus, s[i][0]+s[i][1]);
    mnSub = min(mnSub, s[i][0]-s[i][1]);
  }
  res = max(mxPlus-mnPlus, mxSub-mnSub);
  cout<<res;
  return 0;
}


Measured memory_bytes: 6744