akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
S = [[] for _ in range(H)]
for i in range(H):
    S[i] = list(input())
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            num = 0
            for d in range(8):
                ni = i + dx[d]
                nj = j + dy[d]
                if ni < 0 or H <=ni:
                    continue
                if nj < 0 or W <=nj:
                    continue
                if S[ni][nj] == '#':
                    num += 1
            S[i][j] = num
for i in range(H):
    a = map(str, S[i])
    print("".join(a))

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

int gcd(int a, int b, int c) {
    return __gcd(__gcd(a, b), c);
}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int K;
    cin >> K;
    long long sum = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                sum += gcd(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    odd = sum([x % 2 == 1 for x in A])
    print("YNEOS "[odd % 2::2])
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 63084
n=int(input())
a=[int(i) for i in input().split()]

A_num=0
B_num=0
C_num=0

for i in a:
    if i%4==0:
        C_num+=1
    elif i%2==0:
        B_num+=1
    else:
        A_num+=1

def ans():
    if A_num==1:
        if C_num>=1:
            return True
        return False
    else:
        if n==2*A_num-1:
            if C_num==A_num-1:
                return True
            return False

        elif n<2*A_num-1:
            return False
        else:
            if C_num>=A_num:
                return True
            return False
if ans():
    print("Yes")
else:
    print("No")


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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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;
}

typedef long long ll;

struct Edge {
    ll from;
    ll to;
    ll cost;
    Edge(ll f, ll t, ll c)
        : from(f)
        , to(t)
        , cost(c)
    {
    }
    bool operator<(const Edge& o) const
    {
        return cost < o.cost;
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P; // first:最短距離，second:頂点番号

typedef pair<ll, int> P_ll;

struct UnionFind {
    // par[i]:データiが属する木の親の番号．i==par[i]のとき，データiは木の根ノード
    vector<int> par;
    // sizes[i]:根ノードiの木に含まれるデータの数．iが根ノードでない場合は無意味な値となる
    vector<int> sizes;

    UnionFind(int n)
        : par(n)
        , sizes(n, 1)
    {
        // 最初はすべてのデータiがグループiに存在するものとして初期化
        rep(i, n) par[i] = i;
    }

    // データxが属する木の根を得る
    int find(int x)
    {
        if (x == par[x])
            return x;
        return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す
    }

    // 2つのデータx,yが属する木をマージ
    void unite(int x, int y)
    {
        //データの根ノードを得る
        x = find(x);
        y = find(y);

        // すでに同じ木に属しているならマージしない
        if (x == y)
            return;
        // xの木がyの木より大きくなるようにする
        if (sizes[x] < sizes[y])
            swap(x, y);

        // xがyの親になるように連結
        par[y] = x;
        sizes[x] += sizes[y];
        // sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい
    }

    // 2つのデータx,yが属する木が同じならtrueを返す
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    // データxが含まれる木の大きさを返す
    int size(int x)
    {
        return sizes[find(x)];
    }
};

#define MAX_N 100000

vector<vector<ll>> lp(MAX_N + 100, vector<ll>(3, 0));
vector<vector<ll>> dp(MAX_N + 100, vector<ll>(3, 0));

// 配るDP
int main()
{
    int N;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> lp.at(i).at(0) >> lp.at(i).at(1) >> lp.at(i).at(2);
    }

    for (int i = 1; i <= N; i++) {
        chmax(dp.at(i).at(0), dp.at(i - 1).at(1) + lp.at(i).at(0));
        chmax(dp.at(i).at(0), dp.at(i - 1).at(2) + lp.at(i).at(0));

        chmax(dp.at(i).at(1), dp.at(i - 1).at(0) + lp.at(i).at(1));
        chmax(dp.at(i).at(1), dp.at(i - 1).at(2) + lp.at(i).at(1));

        chmax(dp.at(i).at(2), dp.at(i - 1).at(0) + lp.at(i).at(2));
        chmax(dp.at(i).at(2), dp.at(i - 1).at(1) + lp.at(i).at(2));
    }

    ll ans = 0;
    ans = max({ dp.at(N).at(0), dp.at(N).at(1), dp.at(N).at(2) });

    cout << ans << endl;
}


Measured memory_bytes: 13184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long a[]= new long[k];
		for(int i=0;i<k;i++) {
			a[i] = sc.nextInt();
		}
		boolean hantei =true;
		long max[] =new long[k+1];
		long min[] =new long[k+1];
		max[k]=2;
		min[k]=2;
		for(int i=k-1;i>=0;i--) {
			max[i]=max[i+1]+a[i]-1;
			if(i>0)
				max[i]=(max[i]/a[i-1])*a[i-1];
			min[i]=((min[i+1]-1)/a[i]+1)*a[i];
			if(min[i]-(min[i]%a[i])<min[i+1]||min[i]-(min[i]%a[i])>max[i+1]) {
				System.out.print(-1);
				hantei=false;
				break;
			}
		}
		if(hantei) {
			System.out.println(min[0]);
			System.out.print(max[0]);
		}
	}

}


Measured memory_bytes: 63752
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a;
    cin >> a;
    ll ans = a + a*a + a*a*a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
    	var N = int.Parse(ReadLine());
        var v = ReadLine().Split(' ').Select(s => double.Parse(s)).OrderBy(x => x).ToArray();
        var ans = v[0];

        for(int i = 1; i < N; i++)
            ans = (ans + v[i]) / 2.0;

        WriteLine(ans);
    }
}


Measured memory_bytes: 28460
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int main()
{
   IOS

    int TESTS=1;
    //cin >> TESTS;
    while (TESTS--)
    {
        char c;
        cin >> c;
        if(isupper(c))
        {
            cout<< "A"<< endl;
        }
        else
        {
            cout<< "a"<< endl;
        }


    }
    return 0;
}


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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"

typedef long long ll;

int main()
{
    ll mx;
    string s,t,lcs;

    cin>>s>>t;

    ll ls = s.size();
    ll lt = t.size();

    ll memo [ls+1][lt+1];

    for(ll i=0;i<=ls;i++)
    {
        for(ll j=0;j<=lt;j++)
        {
            if(i==0 or j==0)
                memo[i][j] = 0;
            else if(s[i-1]==t[j-1])
                memo[i][j] = memo[i-1][j-1]+1;
            else
                memo[i][j] = max(memo[i-1][j],memo[i][j-1]);
        }
    }


    for(ll i=ls,j=lt;i>0 and j>0;)
    {
        if(s[i-1]==t[j-1])
        {
            //cout<<memo[i][j]<<" ";
            lcs.push_back(s[i-1]);
            i--;
            j--;
        }
        else
        {
            if(memo[i-1][j]>memo[i][j-1])
                i--;
            else
                j--;
        }
    }

    reverse(lcs.begin(),lcs.end());

    cout<<lcs<<endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
const int N = 1e5+1;

int n;
ll h[200001], a[200001], mx;
ll dp[200001*4], ans[200001];

void update(int p, int l, int r, int i, ll v) {
    if (l==r) {
        dp[p] = v;
        return;
    }
    if (i <= (l+r)>>1) {
        update(p<<1, l, (l+r)>>1, i, v);
    } else {
        update((p<<1)+1, ((l+r)>>1)+1, r, i, v);
    }
    dp[p] = max(dp[p<<1], dp[(p<<1)+1]);
}

ll get(int p, int l, int r, int s, int e) {
    if (l >= s && r <= e) {
        return dp[p];
    }
    if (l > e || r < s) {
        return 0;
    }
    return max(get(p<<1, l, (l+r)>>1, s, e), get((p<<1)+1, ((l+r)>>1)+1, r, s, e));
}
int main() {
    //freopen("lazy.in", "r", stdin);
    IOS
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        mx = max(mx, h[i]);
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ans[h[i]] = max(ans[h[i]], get(1, 0, mx, 0, h[i]-1)+a[i]);
        update(1, 0, mx, h[i], ans[h[i]]);
        ret = max(ret, ans[h[i]]);
    }

    cout << ret << endl;




    return 0;


}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ll ans=0;
	scanf("%lld%lld",&n,&m);
	if(n>=m/2)
	{
		ans+=m/2;
	}
	else
	{
		ans+=n;
		m-=n*2;
		ans+=m/4;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{
    int n;
    int p[210000];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    int c = 0;
    int min  = 3e5;
    for (int i = 0; i < n; i++)
    {
        if (p[i] <= min)
        {
            c++;
            min = p[i];
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

ll dp[100][2];

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  for (int i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1;
  dp[45][0] = 0;
  for (int d = 44; d >= 0; --d) {
    ll mask = 1LL<<d;
    int num = 0;
    for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
    
    if (dp[d+1][1] >= 0) {
      dp[d][1] = max(dp[d][1], dp[d+1][1] + mask * max(num, N-num));
    }
    if (dp[d+1][0] >= 0) {
      if (K & (1LL<<d)) {
        dp[d][1] = max(dp[d][1], dp[d+1][0] + mask * num);
        dp[d][0] = max(dp[d][0], dp[d+1][0] + mask * (N-num));
      }
      else {
        dp[d][0] = max(dp[d][0], dp[d+1][0] + mask * num);
      }
    }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  long long  w,h,x,y;
  scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
  double s=w*h;
  s/=2;
  if(w==2*x && h==2*y)
    printf("%lf 1\n",s);
  else
    printf("%lf 0\n",s);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;

tiii next(tiii abc)
{
    int a, b, c;
    tie(a, b, c) = abc;

    if ((a+b)%2== 0 and (b+c)%2==0 and (c+a)%2==0)
        return make_tuple((a+b)/2, (b+c)/2, (c+a)/2);
    else
        return make_tuple(-1, -1, -1);
}
int main()
{
    int a, b, c;
    cin >> a >> b >>c;

    int cnt = 0;
    tiii state = make_tuple(a, b, c);
    while(true)
    {
        int a, b, c;
        tie(a, b, c) = state;

        bool f1 = a % 2 == 0 and b % 2== 0 and c % 2 == 0;
        bool f2 = a==b and b==c;
        if (not f1)
        {
            break;
        }
        else if(f2)
        {
            cnt = -1;
            break;
        }

        state = next(state);
        ++cnt;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
#define x first
#define y second
int32_t main()
{
	int n=in();int m=in();
	vector<pair<int,int>> a(n);
	trav(i,a){i.x=in();i.y=in();}
	int cost=0;
	sort(all(a));
	for(int i=0;i<n and m>0;i++)
	{
		cost+=min(a[i].y,m)*a[i].x;
		m-=min(a[i].y,m);
	}
	cout<<cost;
	
}

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

int main(){
  unsigned long long n,a,b;
  cin >> n >> a >> b;
  unsigned long long s=n/(a+b);
  unsigned long long t=n%(a+b);
  unsigned long long ans=0;
  ans+=a*s+min(a,t);
  cout << ans <<endl;
}

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

#define N_MAX 100

long a[N_MAX];

using namespace std;

int main(){
    int N, x;
    int num_max;
    long sum = 0;
    cin >> N >> x;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(&a[0], &a[N]);
    for(int i = 0; i < N; i++){
        sum += a[i];
        if(sum > x){
            num_max = i;
            cout << i << '\n';
            return 0;
        }
    }
    if(sum == x){
        cout << N << '\n';
    }else{
        cout << N-1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if ( ((x + r) > W ) || ((y + r) > H) || ((y-r) < 0) || ((x - r)< 0) )
		printf("No\n");
	else
		printf("Yes\n");

	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int a,b;
    cin>>a>>b;
    int ans = -1;

    for(int i=1;i<=1000;i++){
        if(i * 8/100 == a && i * 10/100 == b){
            ans = i;
            break;
        }
    }

    cout<<ans<<endl;
}

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

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

    bool ok = false;

    int pos[] = {0, 4, 6, 8};
    for(int bit = 0; bit < (1<<4); bit++){
        string t = "AKIHABARA";
        set<int> use;
        for(int i=0; i<4; i++){
            if(bit & (1<<i)) use.insert(pos[i]);
        }
        string sub = "";
        rep(i, t.size()){
            if(use.find(i) == use.end()) sub += (""s + t[i]);
        }
        if(s == sub) ok = true;
    }

    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<int> ans(h * w);
    int idx = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < a[i]; j++)
        {
            ans[idx] = i + 1;
            ++idx;
        }
    }
    // print(ans);
    idx = 0;
    for (int i = 0; i < h; i++)
    {
        vector<int> line;
        for (int j = 0; j < w; j++)
        {
            line.push_back(ans[idx]);
            ++idx;
        }
        if (i % 2 == 1)
        {
            reverse(line.begin(), line.end());
        }
        print(line);
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
#define MAX 26

int main(){
    int n,a[MAX];
    
    while(cin >> n,n){
        for(int i = 0 ; i < n ; i++) cin >> a[i];
        int ohajiki = 32,j = 0,d = 0;
        while(true){
            if(ohajiki == 1) break;
            if(j%2==0){
                ohajiki -= (ohajiki-1)%5;
            }
            else{
                ohajiki -= a[d++];
                if(d == n) d = 0;
            }
            j++;
            cout << ohajiki << endl;
        }
        cout << '0' << endl;
    }
    
    return 0;
}

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

using ll = long long;
using namespace std;

int main() {
  int x;
  cin >> x;
  if (400 <= x && x <= 599) {
    cout << '8' << endl;
  } else if (600 <= x && x <= 799) {
    cout << '7' << endl;
  } else if (800 <= x && x <= 999) {
    cout << '6' << endl;
  } else if (1000 <= x && x <= 1199) {
    cout << '5' << endl;
  } else if (1200 <= x && x <= 1399) {
    cout << '4' << endl;
  } else if (1400 <= x && x <= 1599) {
    cout << '3' << endl;
  } else if (1600 <= x && x <= 1799) {
    cout << '2' << endl;
  } else {
    cout << '1' << endl;
  }
  return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  
  int b[n];
  
  for (int i=0; i<n; i++) {
    cin >> b[i];
  }
  
  int now = 0;
  int min = -1;
  
  for (int i=0; i<n; i++) {
    now = b[now] - 1;
    if (now == 1) {
      min = i + 1;
      i = n;
    }
  }
  
  cout << min << endl;
  
  return 0;
}
  
  
  

Measured memory_bytes: 640
# https://atcoder.jp/contests/abc144/tasks/abc144_b

S = input()

leng = int(len(S) / 2)
mleng = int(len(S))
count = 0

for i in range(0,leng):
   j = (mleng - i) -1
   if S[j] != S[i]:
      count = count + 1

print(count)

Measured memory_bytes: 3064
MOD = 998244353

N, M, K = map(int, input().split())

combination_N_1_ = [1]
for k in range(1, K+1):
    tmp = combination_N_1_[-1] * (N-k) * pow(k, MOD-2, MOD)
    tmp %= MOD
    combination_N_1_.append(tmp)

counter = 0
for i in range(K+1):
    counter += pow(M-1, N-i-1, MOD) * M * combination_N_1_[i]
    counter %= MOD

print(counter)

Measured memory_bytes: 89832
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.

int fact[10];
void factorial(){
    fact[0]=1;
    fact[1]=1;
    for(int i=2;i<=8;i++){
        fact[i]=i*fact[i-1];
    }
}

int findSmallerDigitsOnRight(vi &arr,int idx,int num){
    int cnt=0;
    for(int i=idx+1;i<arr.size();i++){
        if(arr[i]<num){
            cnt++;
        }
    }
    return cnt;
}
int sortedPermutationRank(vi &arr){
    int n=arr.sz();
    int ans=0;
    for(int i=0;i<n;i++){
        int small=findSmallerDigitsOnRight(arr,i,arr[i]);
        ans+=(small*fact[n-1-i]);
    }
    return ans+1;
}
void solve(){
    factorial();
    int n; 
    cin>>n;
    vi A(n);
    vi B(n);
    for(int i=0;i<n;i++){cin>>A[i];}
    for(int i=0;i<n;i++){cin>>B[i];}
    int a=sortedPermutationRank(A);
    int b=sortedPermutationRank(B);
    // cout<<b<<endl;
    // cout<<a<<" "<<b<<endl;
    cout<<abs(a-b)<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }
const ll MAX = (ll)1e12;
vector<ll> all;
void gen(ll cur, ll d) {
	all.emplace_back(cur);
	for(ll t = d - 1; t <= d + 1; ++t) if(t >= 0 && t < 10) {
		ll ncur = 10 * cur + t;
		if(ncur <= MAX) gen(ncur, t);
	}
}
void solve() {
	for(ll d = 1; d < 10; ++d) gen(d, d);
	sort(all.begin(), all.end());
	all.erase(unique(all.begin(), all.end()), all.end());
	DBG(len(all));
	int k = fetch<int>() - 1;
	cout << all[k] << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 18808
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }

int solve(int n, int t, const vector<int> & a, const vector<int> & b) {
    // left
    vector<vector<int> > l(n + 1);
    l[0].resize(t);
    REP (i, n) {
        l[i + 1] = l[i];
        REP_R (j, t - a[i]) {
            chmax(l[i + 1][j + a[i]], l[i + 1][j] + b[i]);
        }
    }

    // right
    vector<vector<int> > r(n + 1);
    r[n].resize(t);
    REP_R (i, n) {
        r[i] = r[i + 1];
        REP_R (j, t - a[i]) {
            chmax(r[i][j + a[i]], r[i][j] + b[i]);
        }
    }

    // zip
    int answer = 0;
    REP (i, n) {
        REP (j, t) {
            int k = t - j - 1;
            chmax(answer, l[i][j] + r[i + 1][k] + b[i]);
        }
    }
    return answer;
}

int main() {
    int n, t; cin >> n >> t;
    vector<int> a(n);
    vector<int> b(n);
    REP (i, n) {
        cin >> a[i] >> b[i];
    }
    cout << solve(n, t, a, b) << endl;
    return 0;
}


Measured memory_bytes: 70784
from collections import defaultdict


MOD = 10 ** 9 + 7

# nを素因数分解する(O(n ^ (1 / 2)))
# primeFactorDecomposition(12): {2: 2, 3: 1}
def prime_factor_decomposition(n):
    m = defaultdict(int)
    while n > 1:
        find_factor = False

        for i in range(2, int(n ** 1/2) + 1):
            if n % i == 0:
                m[i] += 1
                n //= i
                find_factor = True
                break

        if not find_factor:
            m[n] += 1
            break
    return m


def main():
    N = int(input())
    all_m = defaultdict(int)
    for i in range(1, N + 1):
        m = prime_factor_decomposition(i)

        for k, v in m.items():
            all_m[k] += v

    ans = 1
    for v in all_m.values():
        ans *= (v + 1)
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main(){
	int a, b, c, count;
	
	cin >> a;
	count = 1;

	cin >> b;
	if (b!=a){
		count ++;
	}

	cin >> c;
	if(c!= a && c!= b){
		count ++;
	}

	if (count == 2){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int INF = 1e9;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int x=abs(a-b)+abs(b-c),y=abs(a-c)+abs(c-b),z=abs(b-a)+abs(c-a),s=abs(b-c)+abs(c-a),t=abs(c-a)+abs(a-b),u=abs(c-b)+abs(b-a);
	int ans = 0;
	ans = min(x, y);
	ans = min(ans, min(z, s));
	ans= min(ans, min(t, u));
	cout << ans << endl;
}


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

int main() {
  ll n,k,l=1e9;
  cin>>n>>k;
  vector<ll> h(n);
  for(ll i=0; i<n; i++) cin>>h[i];
  sort(h.begin(),h.end());
  for(int i=0; i<n-k+1; i++) l=min(l,h[k-1+i]-h[i]);
    cout<<l;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    string S;
    cin >> S;
    int len = S.length();
    int ans = 0;
    for(int i=0;i<len/2;i++){//切り捨てだから偶奇の場合分け要らない
        if(S.at(i)!=S.at(len-1-i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;
const int mod=1e9+7;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

inline int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

inline int F(int len,int s) {
	if (len<=7) return 0;
	return (9LL*qpow(10,len-1)-s)%mod;
}

int main()
{
	int S=gi(),l,r,s=0,pl=1,pr=1,L=0,R=0,ans=0,i;
	for (l=1,r=1;l<1e7;l++) {
		for (;s<S;r++) {
			if (r==pr) pr*=10,R++;
			s+=R;
		}
		ans+=s==S;
		if (l==pl) pl*=10,L++;
		s-=L;
	}
	for (i=1;i*i<=S;i++)
		if (!(S%i)) {
			(ans+=F(i,S/i))%=mod;
			if (i*i!=S)
				(ans+=F(S/i,i))%=mod;
		}
	cout<<(ans+S/8+mod)%mod;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int h, w;
  cin >> h >> w;

  vector<vector<string>> s(h, vector<string>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }

  char col = 'A';
  int row = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == "snuke") {
        col += j;
        row = i + 1;
        break;
      }
    }
  }

  cout << col << row << endl;

  return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
def main():
    N = int(input())
    xyh = sorted([list(map(int,input().split())) for _ in range(N)],key=itemgetter(2),reverse = True)
    for px in range(101):
        for py in range(101):
            X,Y,H = xyh[0][0],xyh[0][1],xyh[0][2]
            ph = H + abs(X-px) + abs(Y-py)
            for i in range(N):
                X,Y,H = xyh[i][0],xyh[i][1],xyh[i][2]
                tmp = max(ph - abs(X-px) - abs(Y-py),0)
                if tmp != H:
                    break
                if i == N-1:
                    print(px,py,ph)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
    long long m,n,a,b,c;
    int s;
    scanf("%d",&s);
    scanf("%lld",&a);
    s--;
    while(s--)
    {
    	scanf("%lld",&b);
	    {
	    	if(a<b)
	    	swap(a,b);
	    	m=a;
			n=b;
	    	while(b!=0)
	      	{
	        	c=a%b;
				a=b;
				b=c;
	      	}
	      	a=m/a*n;
	    }   
	}
	printf("%lld\n",a);	    
}

Measured memory_bytes: 256
s = raw_input().split()
maxLength, maxCount = 0, 0
word1, word2, count = "", "", {}
for i in range(len(s)):
	count[s[i]] = 0
for i in range(len(s)):
	count[s[i]] += 1
	if(len(s[i]) > maxLength):
		maxLength = len(s[i])
		word2 = s[i]
for i in range(len(s)):
	if(count[s[i]] > maxCount):
		maxCount = count[s[i]]
		word1 = s[i]
print word1, word2

Measured memory_bytes: 6260
/*
 * parasol 
 */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <time.h>
using namespace std;
#define ll long long
const int maxn = 1e6+5;
const int mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;

int n;
int pre[maxn];
struct node
{
    int x, pos;
    node(int _x=0, int _pos=0):x(_x), pos(_pos){}
};
vector<node>ve;
int fun(int l, int r, int num){
    
    while(l <= r){
        int mid = (l+r)>>1;
        
        if (ve[mid].x <= num) l = mid+1;
        else r = mid-1;
    }
    return l;
}

void fid(int k){
    
    int da = ve.size()-1;
    for(int i = da; i >= 0; i--){
        for(int j = i-1; j >= 0; j--){
            if ((ve[i].pos|ve[j].pos) <= k){
                printf("%d\n", ve[i].x+ve[j].x);
                return;
            }
        }
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(int i =0; i < (1<<n); i++){
        scanf("%d", &pre[i]);
    }
    
    int ans = 0;
    for(int i = 1; i < (1<<n); i++){
        int s1 = pre[0], s2 = 0;
        for(int j = i; j; j = (j-1)&i){
            if (pre[j] > s1) {s2 = s1, s1 = pre[j];}
            else if (pre[j] > s2) s2 = pre[j]; 
        }
        ans = max(ans, s1+s2);
        printf("%d\n", ans);
    } 
    
    return 0;
}



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

int judge(int a, int b, int c, int d){
    int time;

    if(a > c && a >= d){
        time = 0;
    }
    else if(a >= c && d <= b){
        time = d - a;
    }
    else if(a >= c && d > b){
        time = b - a;
    }
    else if(c >= a && d <= b){
        time = d - c;
    }
    else if(b > c && d >= b){
        time = b - c;
    }
    else{
        time = 0;
    }

    return time;
}

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

    int ans = judge(a, b, c, d);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int n;
int A[100010];
char op[100010];

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", A+i);
		if(i != n)scanf(" %c", op+i);
	}
	int pre = -1;
	ll mx = 0, mn = 0;
	for(int i=n-1;i;i--){
		if(op[i] == '-'){
			if(pre == -1){
				mx = -A[i+1];
				mn = -A[i+1];
				for(int j=i+2;j<=n;j++)mx += A[j], mn -= A[j];
			}
			else{
				ll sum = 0;
				for(int j=i+2;j<=pre;j++)sum += A[j];
				ll nmx = max(-A[i+1] + sum + mx, -A[i+1] - sum - mn);
				ll nmn = min(-A[i+1] - sum + mn, -A[i+1] - sum - mx);
				mx = nmx; mn = nmn;
			}
			pre = i;
		}
	}
	mx += A[1];
	for(int i=1;i<n;i++){
		if(op[i] == '-')break;
		mx += A[i+1];
	}
	printf("%lld\n", mx);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 768
package main

import (
	"fmt"
)

var len = 0

func main() {
	var N int
	fmt.Scanf("%d", &N)
	strs := make([]string, fac(N))
	add(strs, "", 0, N)
	for i, s := range strs {
		if i == len {
			break
		}
		fmt.Println(s)
	}
}
func add(strs []string, s string, d, N int) {
	if !check(s) {
		return
	}
	if d == N {
		strs[len] = s
		len++
		return
	}
	for i := 0; i <= d; i++ {
		add(strs, string(append([]rune(s), rune('a'+i))), d+1, N)
	}
}
func check(s string) bool {
	m := map[rune]int{}
	max := 'a'
	for _, r := range []rune(s) {
		m[r]++
		if r > max {
			max = r
		}
	}
	for i := 'a'; i < max; i++ {
		if m[i] < 1 {
			return false
		}
	}
	return true
}

func fac(N int) int {
	if N == 1 {
		return 1
	}
	return fac(N-1) * N
}


Measured memory_bytes: 47232
/**
*    created: 26.06.2020 17:14:24
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int a, b;
    cin >> a >> b;
    cout << (a-1) * (b-1) << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

struct TopologicalSort {
    int n;
    vector <set<int>> G;
    vector<bool> used;
    vector<int> indeg, p;

    TopologicalSort() {}
    TopologicalSort(int sz) : n(sz), G(n), used(n), indeg(n), p(0) {}

    void add_edge(int s, int t) {
        G[s].insert(t);
    }

    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            p.push_back(v);
            for (int u:G[v]) {
                indeg[u]--;
                if (indeg[u] == 0 && !used[u]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
    }

    vector<int> build() {
        fill(used.begin(), used.end(), 0);
        fill(indeg.begin(), indeg.end(), 0);

        for (int i = 0; i < n; i++) {
            for (int v:G[i]) {
                indeg[v]++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (indeg[i] == 0 && !used[i]) {
                bfs(i);
            }
        }

        return p;
    }
};

///////////////////////////////////////////////////////////////////////////////
vector<int> G[100005];

int main(){
  int N, M;
  cin >> N >> M;
  int a[N - 1 + M], b[N - 1 + M];
  for(int i = 0; i < N - 1 + M; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]].push_back(b[i]);
  }

  TopologicalSort ts(N);
  for(int i = 0; i < N - 1 + M; i++){
    ts.add_edge(a[i], b[i]);
  }

  vector<int> tsg = ts.build();

  int ans[N];
  fill(ans, ans + N, 0);
  for(int node : tsg){
    for(int nxt : G[node]){
      ans[nxt] = node + 1;
    }
  }

  for(int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  string T;

  cin >> T;
  if(T == "Sunny"){
    cout << "Cloudy";
  }else if(T == "Cloudy"){
    cout << "Rainy";
  }else if(T == "Rainy"){
    cout << "Sunny";
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
#define MAX_N 1000000
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

map< int, int > prime_factorization(int n){
  map< int, int > result;
  int m = n;
  for(int p = 2; p * p <= n; p++){
    int count = 0;
    while(m % p == 0){
      m /= p;
      ++count;
    }
    if(count != 0) result[p] = count;
    if(m == 1) break;
  }
  if(m != 1) result[m] = 1;
  return result;
}

ll power(ll a, ll b){
  ll result = 1;
  ll c = a;
  for(int i = 0; i < 64; i++){
    if((b & (1ll << i)) != 0) {
      result = (result * c) % MOD;
    }
    c = (c * c) % MOD;
  }
  return result;
}

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

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

  map< int, int > lm;
  for(int i = 0; i < n; i++){
    auto temp = prime_factorization(a[i]);
    for(auto m: temp){
      lm[m.first] = max(lm[m.first], m.second);
    }
  }

  ll lc = 1;
  for(auto m: lm){
    lc = (lc * power(m.first, m.second)) % MOD;
  }

  ll sum = 0;
  for(int i = 0; i < n; i++){
    ll tmp = (lc * power(a[i], MOD - 2)) % MOD;
    sum = (sum + tmp) % MOD;
  }

  cout << sum << endl;

  return 0;
}


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

int main() {
    int cnt = 0;
    int idx = 0;
    int target = 2 - 1;
    int n;
    vector<int> s;

    cin >> n;
    s = vector<int>(n);

    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        s.at(i) = tmp - 1;
    }

    for (int i = 0; i < n; i++) {
        idx = s.at(idx);
        cnt += 1;
        if (idx == target) break;
        if (i == n-1) cnt = -1;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,s;
	string a;
	cin>>x;
	cin>>a;
	for(int i=0;i<x-2;i++)
	{
		if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='C')s++;
	}
	cout<<s<<'\n';
	return 0;
}


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


void solve() {
    int v[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> v[i][j];
        }
    }
    for (int a = 0; a <= v[0][0]; a++) {
        int b = v[0][0] - a;
        bool ok = 1;
        for (int i = 1; i < 3&&ok; i++) {
            for (int j = 1; j < 3&&ok; j++) {
                int aij = v[i][0] - b;
                int bij = v[0][j] - a;
                if(aij + bij != v[i][j]) {
                    ok = 0;
                }
            }
        }
        if(ok) {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}


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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int n , a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
//yes no ではなく Yes No だった気をつけよう（戒め）

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

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(v,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;

template<typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

const int maxa = 110;
int a[maxa];
int n;
void solve() {
  cin >> n;
  rep(i,0,n)
  {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n - 1] - a[0] << endl;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int two = 0, four = 0;
	rep(i,n){
		int a;
		cin >> a;
		if(a%4 == 0) ++four;
		else if(a%2 == 0) ++two;
	}
	if(four*2 + two >= n || four*2 + 1 == n) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256