akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        k: usize,
        n: usize,
        v: [usize; n]
    }
    let mut d = v[0] + k - v[n - 1];
    for i in 0..n - 1 {
        d = max(d, v[i + 1] - v[i]);
    }
    println!("{}", k - d);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
vector<string> weekday = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(void) {

    string S;
    cin >> S;
    for(int i=0;i<weekday.size();i++) {
        if(weekday[i] == S) {
            cout << 7-i << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110000;
int N, M;
int a[Max];
ll dp[Max];

int main(int argc, const char * argv[]) {
    cin >> N >> M;
    memset(a, 0, Max);
    inputArray(a, M);

    dp[0] = 1;
    int nextBroken = 0;
    for (auto i=1; i<=N; i++) {
        if (a[nextBroken] == i) {
            dp[i] = 0;
            nextBroken++;
            continue;
        }
        if (i == 1) {
            dp[i] = 1;
        } else {
            dp[i] = (dp[i-1] + dp[i-2]) % BIG;
        }
        // printf("%d, %lld\n", i, dp[i]);
    }

    output(dp[N]);

    return 0;
}

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

int main() {
  int N = 0,c = 0;
  cin >> N;
  rep(i,1000000000){
    c += i;
    if(c >= N){
      cout << i;
      return 0;
    }
  }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define Fors(n) for(int i=1;i<=n;i++)
#define For(n) for(i=0;i<n;i++)
#define ll long long
#define vint(s) vector<int> s
#define pb(x)  push_back(x)
#define mpair(x,y) make_pair(x,y)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll x=0,y=0,s=0,n=0,i=0;

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


Measured memory_bytes: 256
n = int(input())
*p, = map(int, input().split())

ans = 0
for i in range(len(p)-2):
  if ((p[i] < p[i+1]) and (p[i+1] < p[i+2])):
    ans += 1
  elif ((p[i] > p[i+1]) and (p[i+1] > p[i+2])):
    ans += 1
print(ans)


Measured memory_bytes: 3060
L = sorted(list(map(int,input().split())))

A = L[0]
B = L[1]
C = L[2]

dif1 = C - A
dif2 = C - B

if (dif1 + dif2) % 2 == 0:
  print(int((dif1 + dif2)/2))
  
else:
  print(((dif1 + dif2) // 2 ) + 2)



Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

int find_answer(int quantity, int curr) {
  pair<int, int> prices[] = {
    make_pair(1500, 2244),
    make_pair(1200, 1870),
    make_pair(1000, 1520),
    make_pair(500, 850),
    make_pair(300, 550),
    make_pair(200, 380)
  };
  auto price = prices[curr];
  int div = quantity / price.first;
  int mod = quantity % price.first;
  if (mod == 0) { return price.second * div; }
  if (curr == 5 && mod == 100) { return 999999; }

  int best = 999999;
  for (int i = 0; i <= div; ++i) {
    int answer = price.second * i +
        find_answer(quantity - (price.first * i), curr + 1);
    best = min(best, answer);
  }
  return best;
}

int main() {
  while (true) {
    int quantity;
    scanf("%d", &quantity);
    if (quantity == 0) { break; }
    printf("%d\n", find_answer(quantity, 0));
  }
  return 0;
}

Measured memory_bytes: 1012
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main(void)
{
    int N,R;
    cin >> N >> R;
    if(N>=10)
    {
        cout << R << endl;
    }
    else{
        cout << R+(100*(10-N)) << endl;
    }
}

Measured memory_bytes: 256
//test
#include<bits/stdc++.h>
using namespace std ;
 
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	
	int ans=1,x;
	for(int i=1;i<sqrt(m)+1;i++){
		if(m%i==0){
			x=m/i;
			if(i<x&&i>=n){
				ans=max(ans,x);
			}
			if(i<x&&x>=n){
				ans=max(ans,i);
			}
		}
	}
	printf("%d\n",ans);
 
	return 0 ;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x < y) x = y;}
template<class T> void chmax(T& x, T y){if(x > y) x = y;}
db H, W, x, y;

int main(){
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << H * W / 2 << " " << ((x == W / 2 && y == H / 2) ? 1 : 0) << endl;
    return 0;
}

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

// f(x) = \sum_{i=0}^{p-1} \frac{\prod_{j!=i}(x-j)}{\prod_{j!=i}(i-j)} \dot a[i]
// Let S(i,j) = \prod_{j!=i}(x-j)
// S(i,j) = \frac {\prod_{j=0}^{p-1} (x-j)}{x-i}

// all = \prod_{j=0}^{p-1} (x-j)

typedef long long LL;
const int M=3005;
int a[M],b[M];

int p;

int qp(int a,int n)
{
	int ans=1;
	while(n)
	{
		if(n&1) ans=ans*a%p;
		a=a*a%p;
		n>>=1;
	}
	return ans;
}
int inv(int a)
{
	return qp(a,p-2);
}
int add(int x,int y)
{
	x+=y;
	if(x>=p) x-=p;
	return x;
}
int sub(int x,int y)
{
	x-=y;
	if(x<0) x+=p;
	return x;
}
int mul(int x,int y)
{
	return x*y%p;
}

vector<int> mul(vector<int> &x,int j)
{
	int n=x.size();
	vector<int> ans(n+1,0);
	for(int i=0;i<n;i++)
	{
		ans[i+1]=x[i];
		ans[i]=sub(ans[i],mul(x[i],j));
	}
	return ans;
}

// cannot use vector<int> &x ,because we will modify x
vector<int> div(vector<int> x,int j)
{
	int n=x.size();
	vector<int> ans(n-1,0);
	for(int i=n-1;i>0;i--)
	{
		ans[i-1]=x[i];
		x[i-1]=add(x[i-1],mul(x[i],j));
	}
	return ans;
}

void add(vector<int> &x,vector<int> y)
{
	for(int i=0;i<p;i++)
		x[i]=add(x[i],y[i]);
}

int main()
{
	scanf("%d",&p);
	for(int i=0;i<p;i++)
		scanf("%d",&a[i]);
	vector<int> all(1,1);
	for(int i=0;i<p;i++)
		all=mul(all,i);
	// for(int i=0;i<=p;i++)
	// 	cout<<all[i]<<" ";
	// cout<<endl;
	vector<int> b(p,0);
	for(int i=0;i<p;i++)
	{
		vector<int> sij=div(all,i);
		int sii=1;
		for(int j=0;j<p;j++)
			if(j!=i) sii=mul(sii,sub(i,j));
		// for(int j=0;j<p;j++)
		// 	cout<<sij[j]<<" ";
		// cout<<endl;
		sii=mul(inv(sii),a[i]);
		for(int j=0;j<p;j++)
			sij[j]=mul(sij[j],sii);
		// for(int j=0;j<p;j++)
		// 	cout<<sij[j]<<" ";
		// cout<<endl<<endl;
		add(b,sij);
	}
	for(int i=0;i<p;i++)
		printf("%d%c",b[i],i==p-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long n,m;
    long long a,b,c,i,j,k,ans=0;
    cin>>n;
    vector<long long>v;

    for(i=0; i<n; i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
              if(v[i]==v[j])continue;
            for(k=j+1; k<n; k++)
            {
                  if(v[j]==v[k])continue;
                if(v[i]+v[j]>v[k])
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;

}



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

int main () {
  int n, a, b;
  cin >> n;
  if(n == 1) {
    cout << "Hello World" << endl;
  } else {
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import math
from bisect import bisect_left

X = int(input())

def primes_ref(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0
    x_sqrt = math.sqrt(x)

    for prime in primes:
        if prime == 0: continue 
        if prime > x_sqrt: break
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def find_ge(a, x):
  i = bisect_left(a, x)
  if i != len(a):
    return a[i]
  raise ValueError

primes = primes_ref(min(X * X, 100004))
print(find_ge(primes, X))

Measured memory_bytes: 13040
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 998244353;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int n, m, ans;
VI a[100005];

int main() {

	cin >> n >> m;

	rep(i, n) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		a[tmp1 - 1].push_back(tmp2);
	}

	priority_queue<int> que;

	rep(i, m) {
		rep(j, a[i].size()) {
			que.push(a[i][j]);
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5632
import numpy as np
n, M, X = list(map(int, input().split()))
CA = []
A = []
for _ in range(n):
    L = list(map(int, input().split()))
    CA.append(L[:])
    
ans = np.zeros(M+1)
S = [0]*n
ANS = list()
def makeCombination():
    for i in range(0, n-1):
        S[i] = 0
    rec(0, ans)
def rec(i,ans):
    if i == n:
        if all(ans[1:] >= X) == True:
            ANS.append(ans[0])
        return
    rec(i + 1,ans)
    S[i] = 1
    ans = ans   + np.array(CA[i])
    rec(i + 1, ans)
    S[i] = 0
makeCombination()
ANS.sort()
if len(ANS) >= 1:
    print(int(ANS[0]))
else:
    print(-1)


Measured memory_bytes: 27244
#include<iostream>
#include<string>
#include<array>

int main(void) {
	int x1, y1, x2, y2;
	int x3, y3, x4, y4;
	std::cin >> x1 >> y1 >> x2 >> y2;
	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	x4 = x1 - (y2 - y1);
	y4 = y1 + (x2 - x1);
	std::cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << std::endl;
}

Measured memory_bytes: 256
s = input()
t = input()
# s = 'c?????a'
# t = 'coder'
errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, i+lt)

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(5e3) + 17;

int n;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    n = sz(s);
    int ans = 0;

    forn (i, n - 1)
        ans += (s[i] != s[i + 1]);

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

#define N 10005

int a[N], n;

void get_prime(int n, vector <int> &pri) {
	pri.clear();
	if (n == 1) return;
	int up = sqrt(n);
	for (int i = 2; i <= up; i ++) if (n % i == 0) {
		pri.push_back(i);
		while (n % i == 0) n /= i;
		if (n == 1) break;
	}
	if (n > 1) pri.push_back(n);
	return;
}

bool check(int p) {
	if (a[0] % p != 0) return 0;
    for (int i = 1; i < p; i ++) {
        int res = 0;
        for (int j = n; j >= 0; j --) {
			res = (res * i + a[j]) % p;
            if (res < 0) res += p;
        }
        if (res > 0) return 0;
    }
    return 1;
}

bool vis[N];

int main() {
	scanf("%d", &n);
    int d = 0;
	for (int i = n; i >= 0; i --) {
		scanf("%d", &a[i]);
        d = __gcd(d, a[i]>0?a[i]:-a[i]);
	}
	vector <int> A;
    get_prime(d, A);
    for (int i = 2; i <= n; i ++) {
        if (!vis[i]) {
            for (int j = i * i; j <= n; j += i) vis[j] = 1;
            if (check(i)) A.push_back(i);
        }
    }
    sort(A.begin(), A.end());
    int sz = unique(A.begin(), A.end()) - A.begin();
    A.resize(sz);
    for (auto x : A) printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 256
import sys


# input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    if N %2 ==1:
        print("No")
        exit()
    else:
        half = int(N/2)
        if S[0:half] *2== S:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            var m = int.Parse(line[2]);
            if (n == 0 && k == 0 && m == 0) break;
            var res = rec(n - 1, k);
            Console.WriteLine((res + m) % n + 1);
        }
    }
    static int rec(int n, int k)
    {
        if (n == 1) return 0;
        return (rec(n - 1, k) + k) % n;
    }
}


Measured memory_bytes: 14168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int i=0;
		int x[]=new int[10000];
		int y[]=new int[10000];
		while(true){
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();

			if(x[i]==0&&y[i]==0)	break;
			else if(x[i]>y[i]){
				int val=x[i];
				x[i]=y[i];
				y[i]=val;
			}

			i++;
		}

		for(int j=0;j<i;j++)	System.out.println(x[j]+" "+y[j]);
	}
}

Measured memory_bytes: 36364
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
c_raw = lmi()
ab = llmi(N - 1)

adj = collections.defaultdict(list)
for a, b in ab:
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)

total = N * (N + 1) // 2

visited = [False] * N

visited[0] = True
stacks = [[[0, 0]] for i in range(N)]
ans = [0] * N
curr = 1

# dfs = [0]
# while dfs:
#     node = dfs[-1]
#     prev, rem = stacks[c[node]][-1]
#     diff = curr - prev - rem
#     ans[c[node]] += (diff * (diff + 1)) // 2
#     stacks[c[node]][-1][1] += diff
#     if adj[node]:
#         next_node = adj[node].pop()
#         if not visited[next_node]:
#             visited[next_node] = True


color_stack = [[0, N] for _ in range(N)]
# color_groups = [[] for _ in range(N)]


class Tree:
    def __init__(self, i, _c):
        self.i = i
        self.color = _c
        self.child_count = 0
        self.children = []

    def set_child_count(self, parent=-1):
        for node_index in adj[self.i]:
            if node_index == parent:
                continue
            self.children.append(node_index)
            trees[node_index].set_child_count(self.i)
            self.child_count += trees[node_index].child_count + 1

    def dfs(self):
        color_stack[self.color][-1] -= self.child_count + 1
        for node_index in self.children:
            color_stack[self.color].append(trees[node_index].child_count + 1)
            trees[node_index].dfs()
            ans[self.color] -= get_path_count(color_stack[self.color].pop())
            # color_groups[self.color].append(color_stack[self.color].pop())


trees = [Tree(i, c - 1) for i, c in enumerate(c_raw)]


def get_path_count(x):
    return x + x * (x - 1) // 2


ans = [get_path_count(N)] * N
trees[0].set_child_count()
trees[0].dfs()

for color in range(N):
    # v = color_groups[color] + [color_stack[color][-1]]
    # print(N + N * (N - 1) // 2 - sum(map(lambda x: x + x * (x - 1) // 2, )))
    print(ans[color]-get_path_count(color_stack[color][-1]))


Measured memory_bytes: 518036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  cin >> N;
  vector<tuple<string, int, int>> data(N);
  for (int i = 0; i < N; i++) {
    string a;
    int b;
    cin >> a >> b;
    data.at(i) = make_tuple(a, 0 - b, i);
  }
  sort (data.begin(), data.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(data.at(i)) + 1 << endl;
  }
}

Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n;
    cin>>n;

    vi v(n);
    int even = 0, odd = 0, div = 0;

    for(int &x:v){
    	cin>>x;
    	if(x&1) odd++;
    	else if(x%4==0) div++;
    	else even++;
    }

    // cout<<odd<<' '<<even<<' '<<div<<endl;

    if((n&1) && (odd == n/2 + 1)){
    	if(div == n/2) cout<<"Yes";
    	else cout<<"No";
    }
    else{
    	if(div >= odd) cout<<"Yes";
    	else cout<<"No";
    }
} 

Measured memory_bytes: 1024
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>a>>b>>x;
    ll mincat=a;
    ll maxcat=a+b;
    if(mincat<=x&&x<=maxcat) YES;
    else NO;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll sol = min(x, y) * 2 * c;
    if (x > y)
        sol += (x - y) * a;
    else
        sol += (y - x) * b;
    sol = min(sol, x * a + y * b);
    sol = min(sol, max(x, y) * 2 * c);
    cout << sol;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n+1];
        for(int i=1;i<=n;i++){
            arr[i] = sc.nextInt();
        }

        int dp[] = new int[n+1];
        dp[1] = 0;
        for(int i=2;i<=n;i++){
            int option1 = Math.abs(arr[i]-arr[i-1]) + dp[i-1];
            int option2 = (i == 2) ? Integer.MAX_VALUE :  Math.abs(arr[i]-arr[i-2]) + dp[i-2];
            dp[i] = Math.min(option1,option2);
        }

        System.out.println(dp[n]);

    }
}

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

using namespace std;

int main(){
	long long L, R;
	scanf("%lld%lld", &L, &R);
	
	int ans = 2019;
	for(long long i = L; i <= min(R, L+2024); i ++){
		for(long long j = i+1; j <= min(R, i+2024); j ++){
			ans = min(i*j%2019, (long long)ans);
		}
	}
	printf("%d", ans);
}


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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int k; cin >> k;
	int odd, even;
	odd = even = k / 2;
	if (k % 2 == 1)odd++;
	cout << odd * even << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream> 
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;

#define assert_range(x,a,b) assert((a) <= (x) and (x) <= (b))
using ll = long long;

const int M = 1<<18;
ll t[2*M];

void update(int x, ll val) {
    x += M;
    t[x] = max(t[x], val);
    while (x > 1) {
        x /= 2;
        t[x] = max(t[2*x], t[2*x+1]);
    }
}
ll get_max(int x, int y) {
    x += M;
    y += M;
    ll res = max(t[x], t[y]);
    while (x/2 != y/2) {
        if (x%2 == 0) {
            res = max(res, t[x+1]);
        }
        if (y%2 == 1) {
            res = max(res, t[y-1]);
        }
        x /= 2;
        y /= 2;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        ll max_prev = get_max(0, h[i]-1);
        ll extended_val = max_prev + a[i];
        update(h[i], extended_val);
        res = max(res, extended_val);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
char a,b;int ans;
int main()
{
  cin>>a>>b;
  if(a=='D')ans++;
  if(b=='D')ans++;
  if(ans%2==0)cout<<'H'<<endl;
  else cout<<'D'<<endl;
  return 0;
}


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

int v[1001],w[1001];
int N,W,i,j;
int dp[101][10001];
int main(){
    scanf("%d %d",&N,&W);
    for(j = 0; j < W; j++)dp[0][j] = 0;
    for(i = 1;i <= N;i++){
        scanf("%d %d",&v[i - 1],&w[i - 1]);
        for(j = 0;j <= W;j++){
            if(j - w[i - 1] < 0) dp[i][j] = dp[i - 1][j];
		    else dp[i][j] = max(dp[i - 1][j],dp[i][j - w[i - 1]] + v[i - 1]);
        }
    }
    printf("%d\n",dp[N][W]);
    return 0;
}


Measured memory_bytes: 6692
#include <stdio.h>

int main(void)
{
	int H[10000], W[10000], h, i, j,c=0;
	for (i = 0; i < 10000; i++){
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0){
			break;
		}
		c++;
	}
	for (h = 0; h < c; h++){
		for (i = 1; i <= H[h]; i++){
			for (j = 1; j <= W[h]; j++){
				if (i % 2){
					if (j % 2){
						printf("#");
					}
					else{
						printf(".");
					}
				}
				else{
					if (j % 2){
						printf(".");
					}
					else{
						printf("#");
					}
				}
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1756
#include<bits/stdc++.h>
#define mp make_pair
#define pr pair<ll,ll>
#define MAX 1000000
using namespace std;
typedef long long int ll;
#define mod 998244353
void sync(){
ios_base::sync_with_stdio;
cin.tie(NULL);
cout.tie(NULL);
}
/*
bitset<MAX> prime;
void sieve()
{ 
prime.set();
  	prime[0]=0;
  	prime[1]=0;
    for (ll p=2; p*p<=MAX; p++) 
    { 
        if (prime[p] == 1) 
        { 
            for (ll i=p*p; i<=MAX; i += p) 
                prime[i] = 0; 
        } 
    } 
} 
bool comp(vector<ll> a,vector<ll> b)
{
	if(a[0]>b[0])
	return true;
	else if(a[0]<b[0])
	return false;
	else{
		if(a[4]>b[4])
		return true;
		else return false;
	}
}
long long power(long long a,long long b){			//(a^b)%mod
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
long long fact[200005],fact_inv[200005];			//n<=2*10^5+4
void pre(){
    fact[0]=1;
    fact_inv[0]=1;
    for(long long i=1;i<200005;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        fact_inv[i]=power(fact[i],mod-2);
    }
}
long long ncr(long long n,long long r){
    if(n<0)return 1;
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
    //return x; 
}
 ll exponentiation(ll base,ll exp) //fast modulo exponentiation
{ 
    if (exp == 0) 
        return 1; 
  
    if (exp == 1) 
        return base % mod; 
  
    ll t = exponentiation(base, exp / 2); 
    t = (t * t) % mod; 
    if (exp % 2 == 0) 
        return t; 
  
    else
        return ((base % mod) * t) % mod; 
} 
*/
int main(){
	sync();
	ll t;
	t=1;
	while(t--){
		double L;
		cin>>L;
		double hei=L/(3+0.0);
		L=L-hei;
		double bred=L/(2+0.0);
		double len=L-bred;
		double ans=len*bred*hei;
		std::cout << std::setprecision(12) << ans << '\n';
	}
}


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

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

    if(s[0]==s[1]&&s[1]==s[2]){
        cout<<"No"<<endl;
        return 0;
    }
    else if(s[0]==s[1] && s[2]==s[3]){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(s[0]==s[2] && s[1]==s[3]){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(s[0]==s[3] && s[2]==s[1]){
        cout<<"Yes"<<endl;
        return 0;
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int mod = 1e9 + 7;

inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }

inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; }

inline int mul(int a, int b) { return llint(a) * b % mod; }

int powmod(int a, llint b) {
  if (b == 0) return 1;
  if (b & 1) return mul(a, powmod(a, b - 1));
  return powmod(mul(a, a), b / 2);
}

const int M = 2;

struct matrix {
  int a[M][M];
  matrix() { REP(i, M) REP(j, M) a[i][j] = 0; }

  int* operator[](int i) { return a[i]; }
  friend matrix operator*(matrix a, matrix b) {
    matrix r;
    REP(i, M) REP(j, M) REP(k, M) r[i][j] = add(r[i][j], mul(a[i][k], b[k][j]));
    return r;
  }
};

matrix power(matrix a, llint b) {
  assert(b > 0);
  b--;
  matrix r = a;
  while (b > 0) {
    if (b & 1) r = r * a;
    a = a * a, b /= 2;
  }
  return r;
}

int solve(vector<string>& v, llint K) {
  if (K <= 1) return 1;

  int N = v.size();
  int M = v[0].size();

  int count_ver = 0;
  REP(i, M) count_ver += v[0][i] == '#' && v[N - 1][i] == '#';

  int count_hor = 0;
  REP(i, N) count_hor += v[i][0] == '#' && v[i][M - 1] == '#';

  if (count_ver && count_hor) return 1;

  int count = 0;
  REP(i, N) REP(j, M) count += v[i][j] == '#';

  if (!count_ver && !count_hor) {
    return powmod(count, K - 1);
  }

  if (count_ver) {  // rotate
    vector<string> nv(M);
    REP(i, M) REP(j, N) nv[i].push_back(v[j][i]);
    v = move(nv);
    swap(N, M);
    swap(count_ver, count_hor);
  }

  assert(count_hor && !count_ver);

  int count_neighbors = 0;
  REP(i, N) {
    REP(j, M - 1) { count_neighbors += v[i][j] == '#' && v[i][j + 1] == '#'; }
  }

  matrix a;
  a[0][0] = 1;
  a[0][1] = 1;

  matrix b;
  b[0][0] = count;
  b[1][0] = sub(0, count_neighbors);
  b[0][1] = 0;
  b[1][1] = count_hor;

  a = a * power(b, K - 1);

  return a[0][0];
}

int main(void) {
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  llint K;
  cin >> K;

  vector<string> v(N);
  REP(i, N) cin >> v[i];

  cout << solve(v, K) << "\n";

  return 0;
}


Measured memory_bytes: 2432
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = Integer.parseInt(scanner.nextLine());
        switch (x) {
            case 3:
            case 5:
            case 7:
                System.out.println("YES");
                break;
            default:
                System.out.println("NO");
                break;
        }
    }
}


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

int main(){
  int n;
  cin>>n;
  int i=1;
  long long ans,nine=1,eight=1,ten=1;
  
  
  while(i<=n){
    ten*=10;
    nine*=9;
    eight*=8;
    
    ten=ten%1000000007;
    nine=nine%1000000007;
    eight=eight%1000000007;
    
    i++;
  }
  
  ten=(ten+eight)%1000000007;
  nine=2*nine%1000000007;
  
  ans=(ten-nine)%1000000007;
  ans=(ans+1000000007)%1000000007;
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 45;

ll dp [MAX_N][MAX_N][MAX_N];
ll can [MAX_N][MAX_N];

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

  n *= 2;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;

      can[i][j] = c - '0';
    }
  }

  for (int k = 0; k < n; k += 2) {
    for (int l = 0; l < n; l++) {
      int r = (l + k) % n;
      for (int m = l; true; m = (m + 1) % n) {
        if (m == l || m == r) {
          if (l == r) {
            dp[l][r][m] = 1;
          }
        } else {
          for (int p = l; p != m && (m + 1) % n != p; p = (p + 2) % n) {
            int sq = m;
            if (sq % 2 == l % 2) {
              sq = (sq + 1) % n;
            }
            for (int q = sq; true; q = (q + 2) % n) {
              for (int a = l; true; a = (a + 1) % n) {
                for (int b = (q + 1) % n; true; b = (b + 1) % n) {
                  if (can[a][b]) {
                    dp[l][r][m] += dp[l][p][a] * dp[(p + 1) % n][q][m] * dp[(q + 1) % n][r][b];
                  }
                  if (b == r) break;
                }
                if (a == p) break;
              }
              if (q == r || (q + 1) % n == r) break;
            }
          }
        }

        if (m == r) break;
      }
    }
  }

  ll ans = 0;
  for (int m = 1; m < n; m++) {
    if (can[0][m]) {
      ans += dp[1][n - 1][m];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 896
n, m = map(int, input().split())
matrix = []
lines = []
c_ele = []

for i in range(n):
    matrix.append(list(map(int, input().split())))

for j in range(m):
    lines.append(int(input()))

for k in range(n):
    sum = 0
    for l in range(m):
        sum += matrix[k][l] * lines[l]
    c_ele.append(sum)

for p in c_ele:
    print(p)



Measured memory_bytes: 6012
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

ll mod = LLONG_MAX;

ll fpow(ll a, ll b, ll md){
	ll res = 1;
	a = (a%md);
	while(b>0){
		if(b%2==1){
			res = (res*a)%md;
		}
		b = b/2;
		a = (a*a)%md;
	}
	return res%md;
}

void solve(){
	ll n,k;
	cin>>n>>k;
	ll ans = k*fpow(k-1,n-1,mod);
	cout<<ans<<endl;

}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long H = sc.nextLong();
   long ans = loop(H);
   System.out.println(ans);
 }
 static long loop(long h)
 {
   if(h==1) return 1;
   else return 2*loop(h/2) + 1;
 }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>			
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;
 
 bool appear[101], mark[100][100];
void solve() {
	int grid[3][3];
	bool flag = false;
	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			cin >> grid[i][j];
			appear[grid[i][j]] = 1;
			}
		}
		int n;
		cin >> n;
		for(int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			if(appear[x]) {
				for(int j = 0; j < 3; ++j) {
					for(int k = 0; k < 3; ++k) {
						if(grid[j][k] == x) mark[j][k] = 1;
						}
					}
				}
			}
			for(int i = 0; i < 3; ++i) {
				if(mark[0][i] && mark[1][i] && mark[2][i]) flag = true;
				}
				
			for(int i = 0; i < 3; ++i) {
				if(mark[i][0] && mark[i][1] && mark[i][2]) flag = true;
				}
				if(mark[0][0] && mark[1][1] && mark[2][2]) flag = true;
				if(mark[1][1] && mark[0][2] && mark[2][0]) flag = true;
				if(flag) cout << "Yes" << endl;
				else cout << "No" << endl;
		
}

 
	
 
int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 


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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    REP(i, sz(s) / 2) {
        if (s[i] != s[sz(s) - 1 - i]) ans++;
    }
    cout << ans << EOL;
}


Measured memory_bytes: 256
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll n,i;
  cin>>n;
  ll arr[n];
  for(i=0; i<n; i++)
    cin>>arr[i];
  ll amount=1000;
  ll minm=arr[0];
  ll pur;
  for(i=0; i<n; i++)
  {
    if(arr[i]<minm)
      minm=arr[i];

    else if(arr[i]>minm)
    {
      pur=amount/minm;
      amount-=pur*minm;
      amount+=pur*arr[i];
      minm=arr[i];
    }
  }
  cout<<amount;
  return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x,t;
    cin>>n;
    if(n&1) cout<<0;
    else{
        ll ans=0;
        for(i=5;(n/i)>=1;i*=5){
            ans+=(n/i)/2;
        }
        cout<<ans;
    }
}

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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]\n";}

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

	ll n; cin >> n;
	ll sum = 0;
	vector<ll> a(n+1); FOR (i, 1, n) cin >> a[i], sum += a[i];
	
	if (sum % (n*(n+1)/2)) {
		cout << "NO\n";
		return 0;
	}

	ll no = sum / (n*(n+1)/2);

	if (n == 1) {
		cout << "YES\n";
		return 0;
	}
	vector<ll> st(n + 1);

	FOR (i, 1, n) {
		int nxt = i == n ? 1 : i + 1;
		ll times = a[i] - a[nxt] + no;
		if (times < 0 or times % n) {
			cout << "NO\n";
			return 0;
		}
		st[nxt]+= times / n;
	}
	

	vector<ll> sti(n + 1);
	FOR (i, 1, n) sti[i] = sti[i - 1] + i*st[i];
	FOR (i, 1, n) st[i] += st[i - 1];

	FOR (j, 1, n) {
		a[j] -= (j+1)*(st[j] - st[0]);
		a[j] -= -(sti[j] - sti[0]);

		a[j] -= (n+1+j)*(st[n] - st[j]);
		a[j] -= -(sti[n] - sti[j]);

		if (a[j]) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 2560
n,m = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    uf.union(a-1, b-1)

ans=0
for i in uf.roots():
    num=uf.size(i)
    ans=max(ans,num)
print(ans)

Measured memory_bytes: 82580
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

// ceil of a/b
inline int ceildiv(int a, int b) { return (a+b-1)/b; }


signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<int> a(n);
	int ok=0;
	rep(i,n) std::cin >> a[i];
	int sum=0;
	rep(i,n) sum+=a[i];
	rep(i,n) {
		if(a[i]>=ceildiv(sum,4*m)) {
			ok++;
		}
	}
	if(ok>=m) print("Yes");
	else print("No");
	return 0;
}


Measured memory_bytes: 256
while True:
	H,W = list(map(int, input().split()))
	if (H == 0 and W == 0):
		break
	else:
		for n in range(H):
			s = ""
			for m in range(W):
				if (0 < n and n < H-1) and (0 < m and m < W-1):
					s += "."
				else:
					s += "#"
			print(s)
		print("")

Measured memory_bytes: 7688
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> rand26(1, 26);
	rep(i, n) cout << rand26(mt) << endl;;
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;

vector <ll> numnum(ll n){
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

ll gcd(ll tt, ll yy) {
  ll qq;
  if(yy>tt){
    swap(tt,yy);
  }
  while ( yy != 0 ) {
    qq = tt%yy; tt = yy; yy = qq;  
  }
  return tt;            
}


int main(){
  ll A,B;
  cin>>A>>B;
  vector <ll> aa = numnum(A);
  vector <ll> bb = numnum(B);
  vector <ll> cc;
  sort(aa.begin(),aa.end());
  sort(bb.begin(),bb.end());
  for(int i = 0;i<aa.size();i++){
    for(int k = 0;k<bb.size();k++){
      if(aa[i]<bb[k]){
        break;
      }
      if(aa[i] == bb[k]){
        cc.push_back(aa[i]);
      }
    }
  }
  
  vector <ll> dd;
  bool pp = 0;
  for(int i = 0;i<cc.size();i++){
    pp = 0;
    for(int k = 0;k<dd.size();k++){
      if(gcd(cc[i],dd[k]) != 1){
        pp = 1;
      }
    }
    if(pp == 0){
      dd.push_back(cc[i]);
    }
  }
  cout << dd.size() << endl;
  return 0;
}
      

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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

int n, m;
int c[21];
int dp[100010];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	rep(i, m)cin >> c[i];
	rep(i, 100010)dp[i] = 1001001001;
	dp[0] = 0;
	rep(i, n + 1) {
		rep(j, m) {
			if (i - c[j] >= 0)dp[i] = min(dp[i], dp[i - c[j]] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
#define over(...) printf(__VA_ARGS__),exit(0)
int a[8],b[8];
long long ans=0;
int main(){
	for(int i=1;i<=7;i++)
		scanf("%d",&a[i]);
	ans+=a[2];
	ans+=a[1]&(~1); b[1]=a[1]&1;
	ans+=a[4]&(~1); b[4]=a[4]&1;
	ans+=a[5]&(~1); b[5]=a[5]&1;
	if(b[1]&&b[4]&&b[5]) over("%lld",ans+3);
	if(b[4]&&b[5]&&a[1]>0) over("%lld",ans+1);
	if(b[1]&&b[5]&&a[4]>0) over("%lld",ans+1);
	if(b[1]&&b[4]&&a[5]>0) over("%lld",ans+1);
	printf("%lld",ans);
}

Measured memory_bytes: 128