akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, int> P3;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n;
    while(cin >> n, n){
        vector<P> v;
        REP(i,n){
            ll a, b;
            cin >> a >> b;
            v.push_back({b,a});
        }
        SORT(v);
        string ans = "Yes";
        ll sum = 0;
        for(auto p : v){
            sum += p.second;
            if(sum > p.first){
                ans = "No";
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;
using Graph = vector<vector<int>>;
int main(){

string s,t;
int flag=1;
long long sz,k,cnt=0;
cin >>s >> k;
sz = s.size();
long long l[sz],a=1;l[0]=1;
for (int i = 1; i < sz; ++i)
{
    if (s[i] == s[i-1])
    {
        l[i]=l[i-1]+1;
    }
    else {
        cnt+=l[i-1]/2;
        l[i]=1;
        flag = 0;
    }
    if (flag)
    {
       a++; 
    }
}

if (flag)
{
    cnt = sz*k/2;
    cout << cnt;
}
else{

    if (s[0]==s[sz-1])
    {
        cnt=cnt-a/2;
        cnt *=k;
        cnt=cnt+a/2+l[sz-1]/2 + (a+l[sz-1])/2*(k-1);
    }
    else{
        cnt+=l[sz-1]/2;
        cnt = cnt*k;
    }

    cout << cnt;
    
}
return 0;
}




Measured memory_bytes: 256
//回文
using System;

namespace tst
{
    
    class Program
    {
        public static void Main()
        {
            string text = Console.ReadLine();
            //回文が奇数か偶数かで分岐はしなくても平気
            int len = text.Length;
            //文字が一致してないときカウント
            int cnt = 0;
            for(int i=0; i <= (len / 2)-1; i++)
            {
                if (text.Substring(i,1) != text.Substring(len-1-i,1))
                {//文字が一致しなかったら
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
            
        }

    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;++i) cin>>a[i];
  int cnt2=0,cnt4=0;
  for(int i=0;i<n;++i){
    if(!(a[i]%4)) cnt4++;
    else if(!(a[i]%2)) cnt2++;
  }
  cnt2/=2;
  if(cnt2+cnt4>=n/2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int sum1=0, sum2=0, current;
	vector<int> v;
	for (int i=0; i<n; i++){
		cin >> current;
		v.push_back(current);
	}
	sort(v.rbegin(),v.rend());
	for (int i=0; i<n; i++){
		current = v[i];
		if (i%2==0) sum1+=current;
		else sum2+=current;
	}
	cout << sum1-sum2;
}


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

using namespace std;

struct UnionFind {
  std::vector<int> parent;
  int __size;
  UnionFind(int n) : parent(n, -1), __size(n) {}
  void unite(int x, int y) {
    if ((x = root(x)) != (y = root(y))) {
      if (parent[y] < parent[x]) { std::swap(x, y); }
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  int size(int x) { return -parent[root(x)]; }
  int size() { return __size; }
};

int main() {
  long long n, m; cin >> n >> m;

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

  vector<long long> ans(m);
  long long inconv = n * (n-1) / 2;

  UnionFind uf(n);
  for (int i = m-1; i >= 0; i--) {
    ans[i] = inconv;
    if (!uf.same(a[i], b[i])) {
      long long x = uf.size(a[i]);
      long long y = uf.size(b[i]);
      uf.unite(a[i], b[i]);
      inconv -= x*y;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint choose(int n,int a){
    mint x=1;
    mint y=1;
    for(int i = 0; i < a; i++) {
        x*=n-i;
        y*=i+1;
    }
    return x/y;
}

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >>a[i];
    }
    mint s=0;
    for(int i = 0; i < n; i++) {
        s+=a[i];
    }
    s=s*s;
    for(int i = 0; i < n; i++) {
        s-=(a[i]*a[i]);
    }
    s/=2;
    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 4780
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static int n;
	static int count = 0;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		System.out.println("0:");
		boolean[] array = new boolean[n + 1];
		int max = 0;
		while (max < n) {
			array[max] = true;
			System.out.print(++count + ": ");
			int index = 0;
			int count = 0;
			for (int i = 0; i < max; i++) {
				if (array[i]) {
					System.out.print(i + " ");
					++count;
				}
			}
			System.out.println(max);
			
			for (int i = 0; i < max; i++) {
				if (!array[i]) {
					array[i] = true;
					index = i;
					break;
				}
			}
			for (int j = 0; j < n - 2; j++) {
				for (int i = 0; i < index; i++) {
					if (array[i]) {
						array[i] = false;
						break;
					}
				}
			}
			if (count >= max) {
				++max;
				array = new boolean[n + 1];
			}
		}
	}
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  bool f = true;
  rep(i, a.size()) if (a[i] % 2) f = false;

  if (f) {
    cout << "Yes" << endl;
    return 0;
  }

  int four = 0;
  int two = 0;
  int other = 0;
  rep(i, a.size()) {
    if (a[i] % 4 == 0)
      four++;
    else if (a[i] % 2 == 0)
      two++;
    else
      other++;
  }

  if (two) other++;

  cout << (four >= (four + other) / 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
n = int(input())
a = [ int(elem) for elem in input().split() ]
a.sort()

def calc(a):
    new_a = [ elem % a[0] if elem % a[0] != 0 else elem for elem in a ]
    new_a.sort()
    if new_a[0] == 1:
        return new_a[0]
    elif new_a[0] == a[0]:
        return a[0]
    else:
        return calc(new_a)

print(calc(a))

Measured memory_bytes: 14252
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r*g*b

for i in range(n):
    for j in range(1,n//2+1):
        if i+2*j>=n:
            break
        
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i]!=s[i+2*j]:
            ans -= 1
print(ans)

Measured memory_bytes: 68140
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long g = gcd(a, b);
    System.out.println(g * (a / g) * (b / g));
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
}

Measured memory_bytes: 22736
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int H, W;
  ci(H, W);
  ve<ve<char>> a(H + 2, ve<char> (W + 2, '#'));
  repi(i, 1, H + 1){
    repi(j, 1, W + 1){
      ci(a.at(i).at(j));
    }
  }
  rep(i, H + 2){
    rep(j, W + 2){
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int A[] = new int [N];
        int n=0;
        int m=-1;
        for(int i=0;i<N;i++)
          A[i] = sc.nextInt();
        Arrays.sort(A);
        for(int i=0;i<N;i++){
          m = -m;
          n = n + A[N-1-i] * m;
//        System.out.println(A[N-1-i] +" " +m);
        }
        System.out.println(n);
      
   
      
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define N 21
using namespace std;
int n,m;
double L[N],a[N],b[N],ans;
int ca[N];

void calc(){
   double cal=0;
    for(int i=0;i<m;i++)
   for(int j=i+1;j<m;j++)
    cal+=pow(L[ca[i]]-L[ca[j]],2)+pow(a[ca[i]]-a[ca[j]],2)+pow(b[ca[i]]-b[ca[j]],2);
     ans=max(ans,cal);
  }


void dfs(int x,int d){
  if(d==m){ calc();return;}
  else if(x>=n){return;}
  ca[d]=x;
  dfs(x+1,d+1);
  dfs(x+1,d);
}

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>L[i]>>a[i]>>b[i];
      dfs(0,0);
        printf("%.5f\n",ans);
  return 0;
}

Measured memory_bytes: 1248
using System;

public class Input
{
    public long n;

    public long s;

    public Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        s = long.Parse(input[0]);
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        string output = Proc();

        // 出力
        Console.WriteLine(output);
    }

    static string Proc()
    {
        Input input = new Input();
        string output = string.Empty;

        long result = -1;

        // n = s
        if (input.n == input.s)
        {
            result = input.n + 1;
            output = result.ToString();
            return output;
        }

        // n < s
        if (input.n < input.s)
        {
            result = -1;
            output = result.ToString();
            return output;
        }

        // rootNまで
        long rootN = (long)Math.Sqrt(input.n);

        for (long b = 2; b <= rootN; b++)
        {
            long s = DigitSum(b, input.n);

            if (s == input.s)
            {
                result = b;
                output = result.ToString();
                return output;
            }
        }

        // rootN以降(2桁以下)

        // n = pb + q (1)
        // p + q = s  (2)

        // n = pb + (s - p)
        // pb = n - s + p
        // b = (n - s + p) / p
        // b = (n - s) / p + 1

        for (long p = rootN; p >= 1; p--)
        {
            long b = (input.n - input.s) / p + 1;
            if (b <= 1)
            {
                continue;
            }

            long s = DigitSum(b, input.n);

            if (s == input.s)
            {
                result = b;
                output = result.ToString();
                return output;
            }
        }

        output = result.ToString();
        return output;
    }

    static long DigitSum(long b, long n)
    {
        if (b > n)
        {
            return n;
        }

        long result = DigitSum(b, n / b);
        result += n % b;

        return result;
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

int lucas(int n, vector<int> &memo);

signed main() {
    int n; cin >> n;
    vector<int> memo(n + 1, -1);
    cout << lucas(n, memo) << endl;
}

int lucas(int n, vector<int> &memo) {
    if(n == 0) {
        return 2;
    } else if(n == 1) {
        return 1;
    } else {
      if(memo[n] != -1) {
          return memo[n];
      } else {
          return memo[n] = lucas(n - 1, memo) + lucas(n - 2, memo);
      }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)

int main(){
	FastIO;
	ll n;
	cin >> n;
	if(n % 1000 == 0)
		cout << 0 << "\n";
	else{
		ll r = (n / 1000) + 1;
		ll ans = (r * 1000) - n;
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<stack>
#include<utility>
using namespace std;

typedef pair<int,int> P;

int w,h,n;
string grid[1010];
bool vis[1010][1010];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

void dfs(int y,int x){
  stack<P> s;
  s.push(P(y,x));
  vis[y][x] = true;

  while(s.size()){
    P p = s.top(); s.pop();

    for(int i=0;i<4;i++){
      int ty = p.first + dy[i], tx = p.second + dx[i];
      if(ty<0 || tx<0 || h<=ty || w<=tx || grid[ty][tx] == '#')continue;
      if(!vis[ty][tx]){
	vis[ty][tx] = true;
	s.push(P(ty,tx));
      }
    }
  }
}

int main(){
  int gy,gx,x,y;
  cin >> w >> h;
  for(int i=0;i<h;i++){
    cin >> grid[i];
    for(int j=0;j<w;j++){
      vis[i][j] = false;
      if(grid[i][j] == 't'){
	gy = i;
	gx = j;
      }
    }
  }

  dfs(0,0);

  if(vis[gy][gx]){
    cout << 0 << endl;
    return 0;
  }

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> x >> y;

    grid[y][x] = '.';
    for(int j=0;j<4;j++){
      if(y+dy[j]<0 || x+dx[j]<0 || h<=y+dy[j] || w<=x+dx[j])continue;
      if(vis[y+dy[j]][x+dx[j]])dfs(y,x);
    }
 

    if(vis[gy][gx]){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 6588
import heapq
N,Q = map(int,input().split())
nati = []
for i in range(N):
    na,ti = input().split()
    nati.append([str(na),int(ti)])

now = 0
while nati:
    na,ti = nati.pop(0)
    if ti > Q:
        ti-=Q
        nati.append([na,ti])
        now+=Q
    else:
        now+=ti
        print(na,now)



Measured memory_bytes: 13068
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		boolean flag = true;
		int count = 0;
		while (flag) {
			flag = false;
			for (int i = n - 1; i > 0; i--) {
				if (a[i] < a[i - 1]) {
					int tmp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = tmp;
					flag = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(a[i]);
			if (i < n - 1) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
		}
		System.out.println(count);
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}



Measured memory_bytes: 24200
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < (int)n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
const double PI = 3.141592653589793238462;
LL sx, sy, tx, ty;
LL N;
LL X[200002], Y[200002];
PP P[200002];
LL V[200002];
double ans;
const LL OKU = 100000000;
int main() {
	//N = 500;
	//sx = rand();
	//sy = rand();
	//tx = rand();
	//ty = rand();
	//REP(i, 0, N) {
	//	X[i] = rand();
	//	Y[i] = rand();
	//}


	cin >> sx >> sy >> tx >> ty >> N;
	REP(i, 0, N) {
		cin >> X[i] >> Y[i];
	}
	if (sx > tx) {
		REP(i, 0, N) {
			X[i] = OKU - X[i];
		}
		sx = OKU - sx;
		tx = OKU - tx;
	}
	if (sy > ty) {
		REP(i, 0, N) {
			Y[i] = OKU - Y[i];
		}
		sy = OKU - sy;
		ty = OKU - ty;
	}
	int c = 0;
	REP(i, 0, N) {
		if (X[i] >= sx && X[i] <= tx && Y[i] >= sy && Y[i] <= ty) {
			P[c] = PP(X[i], Y[i]);
			++c;
		}
	}
	P[c] = PP(sx - 1, sy - 1);
	P[c + 1] = PP(tx + 1, ty + 1);
	LL M = c + 2;
	sort(P, P + M);

	fill(V, V + M, INF);
	LL num;
	REP(i, 0, M) {
		auto it = upper_bound(V, V + M, P[i].second);
		*it = P[i].second;
		if (i == M - 1) num = it - V - 1;
	}
	ans = 100 * (ty - sy + tx - sx) - num * (20 - PI * 5);
	if (num == min(ty - sy, tx - sx) + 1) {
		ans += (20 - PI * 5) + PI * 10 - 20;
	}

	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
using namespace std;
int main(){
int w,h,x,y,r;

cin>>w>>h>>x>>y>>r;
if(w<x+r||h<y+r||0>x-r||0>y-r){
cout<<"No\n";
}
else
cout<<"Yes\n";
return 0;


}

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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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

ll n,m,k;
string s;
int main() {
    INIT();

    cin >> n;
    m = n % 1000;
    if(m == 0) {
        cout << 0;
        return 0;
    }
    cout << 1000 - m;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    int n, q, m, b, e;
    cin >> n;
  	int a[n];
  	for (int i = 0; i < n; i++) cin >> a[i];
  	cin >> q;
  	for (int i = 0; i < q; i++)
  	{
        cin >> b >> m >> e;
  	    rotate(a+b,a+m,a+e);
  	}
  	for (int i = 0; i < n; i++) 
  	{
  	    cout << a[i];
  	    if (i == n-1) cout << endl;
  	    else cout << " ";
  	}
	return 0;
}


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

using namespace std;

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

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s.size() + 1 == t.size()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
	int N;
	scanf("%d",&N);
	if((N/100)!=0 && (N/100)<=12){
		if((N%100)!=0 && (N%100)<=12){
			printf("AMBIGUOUS");
		}else{
			printf("MMYY");
		}
	}else{
		if((N%100)!=0 && (N%100)<=12){
			printf("YYMM");
		}else{
			printf("NA");
		}
	}
	return 0;
}

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

int main(){

  bool adj[100][100]={};//初期化を忘れない
  int d[100]={};
  int n,u,v,k;

  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
  
  queue<int> q;
  bool pushed[100]={};
  q.push(1);
  pushed[1-1] = true;
  d[0] = 0;

  while(q.empty() == false){
    u = q.front();
    q.pop();
    for (int i=0; i<n; i++){
      if (adj[u-1][i]){
	if (pushed[i] != true){
	  d[i] = d[u-1] + 1;
	  q.push(i+1);
	  pushed[i] = true;
	}
      }
    }
  }
  
  cout << 1 << " " << 0 << endl;
  for (int i=1; i<n; i++){
    if (d[i] == 0)
      cout << i+1 << " " << -1 << endl;
    else
      cout << i+1 << " " << d[i] << endl;      
  }

}

Measured memory_bytes: 1220
#include<stdio.h>
#include<stdlib.h>
int main(){
  long int A,V,B,W,T;
  scanf("%ld",&A);
  scanf("%ld",&V);
  scanf("%ld",&B);
  scanf("%ld",&W);
  scanf("%ld",&T);
  
  if(abs(A-B) <= (V-W)*T){
  	printf("YES");
  }else{
    printf("NO");
  }
  
  return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int oo = 1e18;
const int mod   = 1e9 + 7;

int n, m;
int name[N], cnt[N][2];
bool visit[N];
vector<int> vi[N];

void solve()    {
    queue<int> pq;

    int ans = n;
    FOR(i, 1, n) if(!(cnt[i][0] * cnt[i][1]))
        ans --, pq.push(i), visit[i] = true;
    while(!pq.empty())  {
        int u = pq.front(); pq.pop();
        for(auto v: vi[u]) if(!visit[v]){
            cnt[v][name[u]] --;
            if(!cnt[v][name[u]]) {
                visit[v] = 1;
                pq.push(v);
                ans --;
            }
        }
    }
    if(!ans) cout << "No";
    else cout << "Yes";
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    cin >> n >> m;
    FOR(i, 1, n) {
        char c; cin >> c;
        name[i] = c - 'A';
    }
    FOR(i, 1, m)    {
        int u, v; cin >> u >> v;
        vi[u].pb(v); vi[v].pb(u);
        cnt[u][ name[v] ] ++;
        cnt[v][ name[u] ] ++;
    }
    return solve(), 0;
}


Measured memory_bytes: 17408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] height = new long[n];
		for(int i=0;i<n;i++) {
			height[i]=sc.nextInt();
		}
		int[] count=new int[n];
		for(int j=0;j<m;j++) {
			int a=sc.nextInt(),b=sc.nextInt();
			if(height[a-1]>height[b-1]) count[b-1]=1;
			else if(height[a-1]<height[b-1]) count[a-1]=1;
			else {
				count[a-1]=1;
				count[b-1]=1;
			}
		}
		int c=0;
		for(int i=0;i<n;i++) {
			if(count[i]==0)  c++;
		}
		System.out.println(c);
	}
}

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

using namespace std;

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

	int x;

	cin >> x;

	if(x>=30)
	{
		cout << "Yes" << '\n';
	}
	else
	{
		cout << "No" << '\n';
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx4 10005
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

struct block {
    int w, s, v;
    bool operator<(const block& b) {
        return w + s < b.w + b.s;
    }
};

int main() {
    nfs
    int i, j, n, w, s, v;
    ll ans = 0;
    ll dp[mx4] = {};
    
    cin >> n;
    
    vector <block> blocks;
    for (i = 0; i < n; i++) {
        cin >> w >> s >> v;
        blocks.pb({w, s, v});
    }
    sort(blocks.begin(), blocks.end());

    for (auto& b : blocks) {
        for (j = b.s; j >= 0; j--) {
            if (b.w + j < mx4) {
                dp[b.w + j] = max(dp[b.w + j], b.v + dp[j]);
            }
            ans = max(ans, b.v + dp[j]);
        }
    }
    cout << ans;
}

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

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define cin_cout_is_cool ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PrintBinary(n) cout << #n << " = " << bitset<64>(n) << endl
#define MEMSET(a,val) memset(a, val, sizeof a)
#define PB push_back
#define endl '\n'
#define cin(n) scanf("%d", &n)
#define popcount(x) __builtin_popcount((x))
#define popcountll(x) __builtin_popcountll((x))

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}
template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;
template<typename T> using min_pq =
	priority_queue<T, vector<T>, greater<T> >;

template<typename T>T max(T a_,T b_,T c_) { return max(a_,max(b_,c_)); }
template<typename T>T min(T a_,T b_,T c_) { return min(a_,min(b_,c_)); }
template<typename T>T min(T a_,T b_,T c_, T d_) { return min(min(a_, b_),min(c_,d_)); }
template<typename T>T max(T a_,T b_,T c_, T d_) { return max(max(a_, b_),max(c_,d_)); }

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

template<typename T> inline T ceil(T num, T d)
{ return (T)(num/d) + (num%d>(T)0 ? (T)1 : (T)0); }
#define block_no(idx) 		(idx/BLOCK_SIZE)
#define block_starting(idx) (block_no(idx)*BLOCK_SIZE)
#define block_ending(idx) 	(min(n, block_no(idx)*BLOCK_SIZE+BLOCK_SIZE-1))
#define block_rank(idx) 	(idx%BLOCK_SIZE)

const int maxn = 100010;

int n;
int a[maxn];

int32_t main () {
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	int tot = 0;
	a[0] = 0;
	a[n+1] = 0;
	for(int i=1; i<=n+1; i++) {
		tot += abs(a[i-1]-a[i]);
	}
	for(int i=1; i<=n; i++) {
		cout<<tot - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1])<<endl;
	}
	return 0;
}

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

int main() {

  int N, K, x, kyori = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> x;
  	if(x > K - x)
      kyori += (K - x)*2;
    else
      kyori += x * 2;
  }
  cout << kyori << endl;
}



Measured memory_bytes: 384
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S[] = new String[N];
		for(int i=0;i<N;i++) {
			S[i] = sc.next();
			//System.out.println(S[i]);
		}
		Map<String,Integer> map = new TreeMap<String,Integer>();
		for(int j=0;j<N;j++) {
			if(map.containsKey(S[j])) {
				map.put(S[j],map.get(S[j])+1);
			}else {
				map.put(S[j],1);
			}
		}
		Object[] mapkey = map.keySet().toArray();
        Arrays.sort(mapkey);
        
//        for (String key : map.keySet()) {
//			System.out.println(key);
//		}
        int max = 0;
        for(int k=0;k<N;k++) {
        	max = Math.max(max,map.get(S[k]));
        }
      //  System.out.println(max);
        
//        for(Integer val : map.values()){
//		    System.out.println(val);
//		}
        
        for (String key : map.keySet()) {
        	if(map.get(key)==max) {
			System.out.println(key);
		}
        }
    	  
	}
}

Measured memory_bytes: 84788
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long
#define printarray(arr, n) for(int i= 0;i<n;i++) cout<<a[i]<<' '; cout<<endl;
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define initdp(a) memset(a, -1, sizeof(a));

using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e6 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}



signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> nice1, nice2;
    int mx1 = LLONG_MIN;
    int mx2 = LLONG_MIN;
    int mn1 = LLONG_MAX;
    int mn2 = LLONG_MAX;
    vector<pair<int, int> > vec;
    for(int i= 0;i<n;i++){
        int t1, t2;
        cin>>t1>>t2;
        vec.pb(mp(t1, t2));
        nice1.pb(t1+t2);
        nice2.pb(t1-t2);
        mn1 = min(mn1, t1+t2);
        mn2 = min(mn2, t1-t2);
        mx1 = max(mx1, t1+t2);
        mx2 = max(mx2, t1-t2);
    }
    cout<<max(max(mx1-mn1, mx2-mn2),max(mn2-mx2, mn1-mx1))<<endl;

    return 0;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    rep(i, m) { cin >> a[i]; }

    // 処理
    // コスト表を作る
    int b[n + 1] = {};
    for (int i = 0; i < m; i++) {
        b[a[i]] = 1;
    }
    // check
    // rep(i, n + 1) { cout << b[i] << " "; }

    int sumX = 0;
    int minV = INF;
    for (int i = 0; i <= x; i++) {
        sumX += b[i];
    }
    int sumY = 0;
    for (int i = x; i <= n; i++) {
        sumY += b[i];
    }

    // check
    // cout << sumX << " " << sumY << endl;

    // 出力
    cout << min(sumX, sumY) << endl;

    return 0;
}


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

ans = 0

count = 1
pre_num = a[0]
for i in range(1, len(a)):
    if a[i] == pre_num:
        count += 1
    else:
        ans += count // 2
        count = 1
        pre_num = a[i]
ans += count // 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int N,i;
int64_t h[110],x[110],y[110];
int cx,cy;
int64_t memo=-1,H;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>N;
  for(i=0;i<N;i++){
    cin>>x[i]>>y[i]>>h[i];
  }

  for(cx=0;cx<=100;cx++){
    for(cy=0;cy<=100;cy++){
      memo=-1;
      for(i=0;i<N;i++){
        if(h[i]==0)continue;
        H=abs(x[i]-cx) + abs(y[i]-cy) + h[i];// 1以上
        if(memo==-1){
          memo=H;
        }else{
          if(memo!=H){
            goto E;
          }
        }
      }
      memo=H;
      for(i=0;i<N;i++){
        if(h[i]!=0)continue;
        if(H - abs(x[i]-cx) - abs(y[i]-cy) < 0)continue;
        H=abs(x[i]-cx) + abs(y[i]-cy) + h[i];
        if(memo!=H){
          goto E;
        }
      }
      cout << cx <<" "<< cy <<" "<< H <<endl;
      return 0;
      E:;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	double f,t;
	while(scanf("%lf %lf",&f,&t)!=EOF){
		if(f<35.50 && t<71.0)printf("AAA\n");
		else if(f<37.50 && t<77.0)printf("AA\n");
		else if(f<40.00 && t<83.0)printf("A\n");
		else if(f<43.00 && t<89.0)printf("B\n");
		else if(f<50.00 && t<105.0)printf("C\n");
		else if(f<55.00 && t<116.0)printf("D\n");
		else if(f<70.00 && t<148.0)printf("E\n");
		else printf("NA\n");
	}
	exit(0);
}

Measured memory_bytes: 0
n = list(map(int,input().split()))

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

tmp = Base_10_to_n(n[0], n[1])
print(len(tmp))


Measured memory_bytes: 2940
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List
import Data.Char

takeHeadAndUpper :: String -> Char
takeHeadAndUpper = toUpper . head

solve :: [String] -> String
solve [] = ""
solve (x:xs) = [(takeHeadAndUpper x)] ++ (solve xs)

main :: IO()
main = do
    s <- map BS.unpack . BS.words <$> BS.getLine
    putStrLn $ solve s


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 + 10;
int A[Maxn], Sum[Maxn];
int N;
int main()
{
#ifdef hk_cnyali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	scanf("%d", &N);
	int Max = 0, Min = 0x3f3f3f3f;
	for (int i = 1; i <= N; ++i)
		scanf("%d", &A[i]), Sum[A[i]] ++, Max = max(Max, A[i]), Min = min(Min, A[i]);
	if (N == 2 && Sum[1] == 2)
	{
		puts("Possible");
		return 0;
	}
	if (Max >= N || Min != (Max + 1) / 2)
	{
		puts("Impossible");
		return 0;
	}
	if (Sum[1])
	{
		if (Sum[1] == 1 && Sum[2] == N - 1) puts("Possible");
		else puts("Impossible");
		return 0;
	}
	if (Max & 1 && Sum[Min] != 2) {puts("Impossible"); return 0;}
	if (!(Max & 1) && Sum[Min] != 1) {puts("Impossible"); return 0;}
//	for (int i = 1; i < N / 2; ++i)
//		if (Sum[i]) {puts("Impossible"); return 0;}
	for (int i = Min; i <= Max; ++i)
	{
		if (!Sum[i])
		{
			puts("Impossible");
			return 0;
		}
		if (Sum[i] < 2 && i != Min)
		{
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define SZ(a) ((int)(a).size())
#define LL long long
#define X first
#define Y second
using namespace std;
const int INF = 1000 * 1000 * 1000;
const LL LINF = INF * (LL)INF;
const int mod = 998244353;
int mult(int a , int b)
{
	return a * (LL)b % mod;
}
int add(int a , int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int a[200005];
LL len[200005][65];
int cnt[200005];
int lastPos[200005];
vector<int> stck;
int main()
{
	ios_base::sync_with_stdio(0);
	LL n , k;
	cin >> n >> k;
	LL mx = n * k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = n - 1; i >= 0; i--)
	{
		lastPos[a[i]] = n + i;
	}
	for(int i = n - 1; i >= 0; i--)
	{
		len[i][0] = lastPos[a[i]] - i + 1;
		lastPos[a[i]] = i;
	}
	for(int step = 1; step <= 60; step++)
	{
		for(int i = 0; i < n; i++)
		{
			LL newPos = (i + len[i][step - 1]) % n;
			LL len2 = len[newPos][step - 1];
			len[i][step] = min(LINF , len2 + len[i][step - 1]);
		}
	}
	LL finalPos = 0;
	for(int j = 60; j >= 0; j--)
	{
		if(finalPos + len[finalPos % n][j] < mx)
		{
			finalPos += len[finalPos % n][j];
		}
	}
	for(LL pos = finalPos; pos < mx; pos++)
	{
		int val = a[pos % n];
		if(cnt[val])
		{
			while(cnt[val])
			{
				cnt[stck.back()]--;
				stck.pop_back();
			}
		}
		else
		{
			cnt[val]++;
			stck.PB(val);
		}
	}
	//cout << SZ(stck) << endl;
	for(auto x : stck)
		cout << x << " ";
}


Measured memory_bytes: 106356
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

  static boolean visited[];
  static Map<Integer, List<Integer>> entry;
  static int[] inDegree;
  static int[] dp;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[][] path = new int[M][2];
    entry = new HashMap<>();
    visited = new boolean[N + 1];
    inDegree = new int[N + 1];
    dp = new int[N + 1];
    for (int i = 0; i < M; i++) {
      path[i][0] = scanner.nextInt();
      path[i][1] = scanner.nextInt();

      List<Integer> orDefault = entry.getOrDefault(path[i][0], new ArrayList<>());
      orDefault.add(path[i][1]);
      entry.put(path[i][0], orDefault);
      inDegree[path[i][1]] = inDegree[path[i][1]] + 1;
    }
    System.out.println(solve(N));
  }

  private static int solve(int N) {

    for (Map.Entry<Integer, List<Integer>> en : entry.entrySet()) {
      if (!visited[en.getKey()] && inDegree[en.getKey()] == 0) {
        dfs(en.getKey());
      }
    }
    int ans = 0;
    for (int i = 0; i < dp.length; i++) {
      ans = Math.max(ans, dp[i]);
    }
    return ans;
  }

  public static void dfs(int a) {
    visited[a] = true;
    if (entry.containsKey(a)) {
      for (Integer integer : entry.get(a)) {
        dp[integer] = Math.max(dp[integer], dp[a] + 1);
        inDegree[integer]--;
        if (inDegree[integer] == 0) {
          dfs(integer);
        }
      }
    }
  }
}


Measured memory_bytes: 123952
#include<cstdio>
#include<cmath>
#include<map>
#include<algorithm>
#define ll long long
using namespace std;
const int N=20202;
int a[N];
int n,p=1e9+7;
map<int,int>st;
map<int,int>::iterator iter;
void spilt(int x){
	int m=sqrt(x);
	for (int i=2; i<=m; i++){
		if (x%i==0){
			int sum=0;
			while (x%i==0)	sum++,x/=i;
			if (st[i]<sum)	st[i]=sum;
		}
		if (x==1)	return;
	}
	if (x!=1){
		if (st[x]<1)	st[x]=1;
	}
}
int power(int a,int b){
	int sum=1;
	for (; b; b>>=1){
		if (b&1)	sum=1ll*sum*a%p;	
		a=1ll*a*a%p;
	}
	return sum;
}
int main(){
	ll ans=0,sum=1;
	scanf("%d",&n);
	for (int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		spilt(a[i]);	
	}
	for (iter=st.begin(); iter!=st.end(); iter++){
		int x=iter->first,y=iter->second;
		sum=1ll*sum*power(x,y)%p;
	}
	for (int i=1; i<=n; i++){
		int m=sqrt(a[i]);
		ll tot=sum;
		for (int j=2; j<=m; j++){
			if (a[i]%j==0){
				int cnt=0;
				while (a[i]%j==0)	cnt++,a[i]/=j;
				tot=1ll*tot*power(power(j,cnt),p-2)%p;
			}
			if (a[i]==1)	break;
		}
		if (a[i]!=1)	tot=1ll*tot*power(a[i],p-2)%p;
		ans=(ans+tot)%p;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 768
/*
				C++
				encoding: UTF-8
				Last Modified: 22/Aug/20 05:37:30 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

#define int int64_t

template < typename T > void print (const T& t) {
	cout << t << '\n';
}

template < typename T, typename U, typename... ARGS >
void print (const T& t, const U& u, const ARGS&... args) {
	cout << t << " ";
	print (u, args...);
}

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	vector< int > arr (n);
	for (auto& i : arr)
		cin >> i;

	int ans = 0, curr = arr[0];
	for (int i = 1; i < n; ++i) {
		if (arr[i] < curr) {
			ans += curr - arr[i];
		}
		curr = max (curr, arr[i]);
	}
	print (ans);
	return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

const ll MOD = 1000 * 1000 * 1000 + 7;

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

    vector<ll> T(N), A(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<PLL> data(N);
    ll h = 0;
    for (int i = 0; i < N; i++) {
        if (T[i] > h) {
            data[i] = make_pair(T[i], T[i]);
        } else {
            data[i] = make_pair(1, T[i]);
        }
        h = T[i];
    }
    h = 0;
    for (int i = N - 1; i >= 0; i--) {
        ll lb = 1, ub = A[i];
        if (A[i] > h) {
            lb = A[i];
            ub = lb;
        }
        if (ub < data[i].first || data[i].second < lb) {
            cout << 0 << endl;
            return 0;
        }
        data[i].first = max(data[i].first, lb);
        data[i].second = min(data[i].second, ub);

        h = A[i];
    }

    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= (data[i].second - data[i].first + 1);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
n = list(map(int,input().split()))
a = 0
for i in (1,2):
    if n[0] == n[i]:
        a += 1
if a == 1:
    ans = "Yes"
elif a == 2 or n[1] != n[2]:
    ans = "No"
else:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  
  int N, M; cin >> N >> M;
  vector<vector<pair<int, int>>> graph(N + 1);
  vector<int> tag(N + 1, -1);
  vector<bool> visited(N + 1, false);

  function<bool(int, int)> check;
  check = [&](int node, int name){
    if(!visited[node]) tag[node] = name;
    else if(tag[node] == name) return true;
    else return false;

    visited[node] = true;

    for(auto ele : graph[node]){
      int child = ele.F, cost = ele.S;
      if(!check(child, tag[node] + cost)) return false;
    }

    return true;
  };
    


//  auto print = [&](){
//    for(int idx = 1; idx <= N; ++idx) cout << tag[idx] << "   ";
//    cout << "\n\n";
//  };

  for(int rep = 0; rep < M; ++rep){
    int left, right, cost;
    cin >> left >> right >> cost;
    graph[left].EB(right, cost);
    graph[right].EB(left, -1 * cost);
  }

  for(int node = 1; node <= N; ++node){
    if(visited[node]) continue;
    if(!check(node, 0)){
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,x;
    cin >> a>>b>>c>>x;
    int i,j,l;
    int tmp,tmp2,tmp3;
    int h=0;
    for(i=0;(i<=a)&&(500*i<=x);i++){
        tmp=x;
        tmp=tmp-500*i;
        tmp2=tmp;
        for(j=0;(j<=b)&&(100*j<=tmp2);j++){
            tmp=tmp2;
            tmp=tmp-100*j;
            tmp3=tmp;
            for(l=0;(l<=c)&&(50*l<=tmp3);l++){
                tmp=tmp3;
                tmp=tmp-50*l;
                if(tmp==0)h++;
            }
        }
    }
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 256