akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
using P = pair<int, int>;

void f(vector<P>& po, vector<bool>& isused, P pq1, int start){
    isused[start] = true;
    for(int i = 0; i < po.size(); i++){
        if(isused[i]) continue;
        if(po[i].first == po[start].first + pq1.first
        && po[i].second == po[start].second + pq1.second){
            f(po, isused, pq1, i);
        }else if(po[i].first == po[start].first - pq1.first
        && po[i].second == po[start].second - pq1.second){
            f(po, isused, pq1, i);
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<P> po(n);
    for(int i = 0; i < n; i++) cin >> po[i].first >> po[i].second;

    vector<P> pq;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            pq.push_back(make_pair(po[i].first-po[j].first, po[i].second-po[j].second));
        }
    }

    int cost = 100;
    if(n == 1) cost = 1;
    for(int i = 0; i < pq.size(); i++){
        vector<bool> isused(n, false);
        int cocost = 0;
        for(int j = 0; j < n; j++){
            if(!isused[j]){
                cocost++;
                f(po, isused, pq[i], j);
            }
        }
        if(cost > cocost) cost = cocost;
    }

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  ll ar[n];
  rep(i,0,n)
  cin>>ar[i];
  rep(i,0,n){
    if(ar[i]%2==0)
    {
      if(ar[i]%3==0 || ar[i]%5==0) continue;
      else {cout<<"DENIED";return;}
    }
  }
  cout<<"APPROVED";
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <cmath>
typedef long long ll;
using namespace std;

int N;
int M;
int ans = 0;
vector<vector<int> > map(100);

void rcount(int current, vector<bool> been) {
    been[current] = true;
    if (all_of(been.begin(), been.end(), [](bool x){ return x; })) ans++;
    for (int i = 0; i < map[current].size(); i++) {
        if (!been[map[current][i]]) rcount(map[current][i], been);
    }
}

int main() {
    
    cin >> N;
    cin >> M;
    
    for (int i = 0; i<M; i++) {
        int _a; cin >> _a;
        int _b; cin >> _b;
        map[_a].push_back(_b);
        map[_b].push_back(_a);
    }
    
    vector<bool> been(N+1);
    for (int i = 0; i<been.size(); i++) {
        been[i] = false;
    }
    been[0] = true;
    int current = 1;
    rcount(current, been);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
mod = 998244353

n, s = gets.to_s.split.map{|e| e.to_i }
a = gets.to_s.split.map{|e| e.to_i }

dp = [0] * (s+1)
dp[0] = 1

a.each do |t|
  s.downto(0) do |j|
    dp[j] *= 2
    dp[j] += dp[j-t] if j - t >= 0
    dp[j] %= mod if dp[j] >= mod
  end
end

puts dp[s]


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

using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    deque<ll>dq;
    dq.push_back(1);
    ll dis[100005];
    memset(dis,1000000009,sizeof dis);
    dis[1]=1;
    ll vis[100005]={0};
    while(!dq.empty())
    {
        ll u=dq.front();
        dq.pop_front();
        //cout<<u<<endl;
        vis[u]=1;
        if(u==0)
        {
            cout<<dis[u]<<endl;
            break;
        }
        ll v=(u*10)%n;
        ll w=(u+1)%n;
        if(dis[v]>dis[u]){
        dq.push_front(v);
        dis[v]=dis[u];
        }
        if(dis[w]>dis[u]+1){
        dq.push_back(w);
        dis[w]=dis[u]+1;
        }
    }
    //main();
    return 0;
}


Measured memory_bytes: 1408
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (n, d) = readListOfInt()
    
    val x = 2 * d + 1
    var y = 0
    while(y * x < n) {
        y++
    }
    println(y)
    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    val rtn = v.map { it.toList() }.toList()
    return rtn 
}

fun gcd(a: Long, b: Long): Long = 
if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
if(b==0L) a else gcd(b, a % b)

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37916
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  dchar[] s; readV(s);
  s[3] = '8';
  writeln(s);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N + 1);
  for (int i = 1; i <= N; i++)
  {
    int n;
    cin >> n;
    a[i] = n;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++)
  {
    if (a[a[i]] == i)
      ans++;
  }
  cout << ans / 2 << endl;
  return 0;
}

Measured memory_bytes: 640
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
dp=[[10**6 for j in range(W)] for i in range(H)]
if s[0][0]=="#":
    dp[0][0]=1
else:
    dp[0][0]=0
for i in range(H):
    for j in range(W):
        if i>0:
            if (s[i][j],s[i-1][j])==("#","."):
                dp[i][j]=min(dp[i][j],dp[i-1][j]+1)
            else:
                dp[i][j]=min(dp[i][j],dp[i-1][j])
        if j>0:
            if (s[i][j],s[i][j-1])==("#","."):
                dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
            else:
                dp[i][j]=min(dp[i][j],dp[i][j-1])
print(dp[-1][-1])


Measured memory_bytes: 43248
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;

public class Main {
    static boolean check(int a,int b,int mid){
        if(a <= mid && b <= mid || a > mid && b > mid)return true;
        return false;
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int array[] = new int[2 * n + 1];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 1; i < 2 * n; i++)
            array[i] = Integer.parseInt(st.nextToken());
        array[0] = array[2 * n] = -1;
        int infinity = (int) 1E9 + 5;
        int low = 1;
        int high = 2 * n;
        TreeSet<Integer> zero;
        TreeSet<Integer> ones;
        while (low < high) {
            int mid = (low + high) / 2;
            int temp = -1;
            zero = new TreeSet<>();
            ones = new TreeSet<>();
            ones.add(infinity);
            ones.add(-infinity);
            zero.add(infinity);
            zero.add(-infinity);
            for (int i = 1; i < 2 * n; i++) {
                if (check(array[i],array[i - 1],mid) && i != 1) {
                    //System.out.println(array[i] + " " + mid + " " + i);
                    if (array[i] > mid) ones.add(i);
                    else zero.add(i);
                }
                if (check(array[i],array[i + 1],mid) && i != 2*n - 1) {
                    //System.out.println(array[i] + " " + mid + " " + i);
                    if (array[i] > mid) ones.add(i);
                    else zero.add(i);
                }
            }
                int beforezero = zero.floor(n);
                int afterzero = zero.ceiling(n);
                int beforeone = ones.floor(n);
                int afterone = ones.ceiling(n);
                int beforemax = Math.max(beforeone, beforezero);
                int aftermin = Math.min(afterone, afterzero);
                int min = Math.min(aftermin - n, n - beforemax);
                //System.out.println("1 " + aftermin + " " + beforemax + " " + min + " " + beforezero + " " + afterzero + " " + beforeone + " " + afterone);
                if (min == aftermin - n) {
                    if (afterone < afterzero) temp = 1;
                    else temp = 0;
                }
                if (min == n - beforemax) {
                    if (beforeone < beforezero) temp = 0;
                    else temp = 1;
            }
            if(min > n - 2){
                if((n & 1) == 0)temp = (array[n] > mid) ? 0 : 1;
                else temp = (array[n] > mid) ? 1 : 0;
            }
            //System.out.println(mid + " " + low + " " + high + " " + zero + " " + ones + " " + temp);
            if (temp == 1) low = mid + 1;
            else high = mid;
        }
        System.out.println(low);
    }
}

Measured memory_bytes: 136536
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    ll A,B,N;cin>>A>>B>>N;
    ll result;
   if (B <= N) {
       result = (A * (B - 1)) / B - A * ((B - 1) / B);
   } else {
       result = (A * N) / B -  A * (N / B);
   }
   cout << result << endl;
    return 0;
}

Measured memory_bytes: 3192
N = int(input())
H = list(map(int, input().split()))
H = [0] + H

costs = [0] * (N + 1)
costs[1] = 0
costs[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    costs1 = costs[i-2] + abs(H[i] - H[i-2])
    costs2 = costs[i-1] + abs(H[i] - H[i-1])
    costs[i] = min(costs1, costs2)


print(costs[N])

Measured memory_bytes: 52600
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]){
        int N=sc.nextInt(),M=sc.nextInt();
        String A[]=new String[N];
        boolean F=false;
        for(int i=0;i<N;i++){
            A[i]=sc.next();
        }
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<M;i++){
            sb.append(sc.next());
        }
        String temp=sb.toString();
        for(int i=0;i<=N-M&&!F;i++){
            for(int j=0;j<=N-M&&!F;j++){
                StringBuffer sa = new StringBuffer();
                for(int k=0;k<M;k++){
                    sa.append(A[i+k].substring(j,j+M));
                }
                if(sa.toString().equals(temp)){
                    F=true;
                }
            }
        }
        System.out.println(F?"Yes":"No");
    }
}

Measured memory_bytes: 39700
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


vector<int> way[SIZE];

pair<int,int> dfs(int now, int back=-1,int h=0){
  pair<int,int> ret = {h,now};

  for(int i=0;i<way[now].size();i++){
    if(way[now][i] != back)
      ret = max(dfs(way[now][i],now,h+1),ret);
  }

  return ret;
}

int ans[SIZE];

void dfs2(int now, int back=-1,int h=0){

  ans[now] = max(ans[now],h);
  for(int i=0;i<way[now].size();i++){
    if(way[now][i] != back)
      dfs2(way[now][i],now,h+1);
  }

  return;
}

int main(){
  int n;
  int u,v;
  
  scanf("%d",&n);

  for(int i=0;i<n-1;i++){
    scanf("%d%d",&u,&v);
    v--; u--;
    way[u].push_back(v);
    way[v].push_back(u);
  }

  int p1,p2;
  
  pair<int,int> ret;
  ret = dfs(0);
  p1 = ret.second;
  ret = dfs(p1);
  p2 = ret.second;

  dfs2(p1);
  dfs2(p2);

  for(int i=0;i<n;i++){
    printf("%d\n",(n-1)*2-ans[i]);
  }
  
  return 0;
}

Measured memory_bytes: 18396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

using Graph = vector<vector<int> >;

vector<int> dist;
queue<int> que;

void bfs(const Graph &G){
  while(!que.empty()){
    int v = que.front();
    que.pop();

    for(int nv : G[v]){
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }
}

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

  Graph G(n+1);
  rep(i, n){
    int u, k; cin >> u >> k;
    rep(j, k){
      int v; cin >> v;
      G[u].push_back(v);
    }
  } 

  dist.assign(n+1, -1);
  dist[1] = 0;
  que.push(1);
  bfs(G);

  REP(i, 1, n){
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}




Measured memory_bytes: 3168
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
const int MAX = 200000;
const int MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(){
	COMinit();
	int N;
	string S;
	scan(N>>S);
	ll ans=1;
	ll count[3]={};
	ll pnum=0,alonenum=0;
	rep(i,3*N){
		int c;
		if(S[i]=='B'){
			c=0;
		}
		else if(S[i]=='R'){
			c=1;
		}
		else{
			c=2;
		}
		int d1=(c+1)%3,d2=(c+2)%3;
		//printf("i:%3d c:%d count:(%lld,%lld,%lld) alone:%lld pnum:%lld\n",i,c,count[0],count[1],count[2],alonenum,pnum);
		if(count[c]>=count[d1]&&count[c]>=count[d2]){
			count[c]++;
			alonenum++;
		}
		else if(count[d1]>0&&count[d2]>0){
			ans*=pnum;
			ans%=MOD;
			count[d1]--; count[d2]--;
			pnum--;
		}
		else{
			ans*=alonenum;
			ans%=MOD;
			alonenum--;
			pnum++;
			count[c]++;
		}
		//printf("      c:%d count:(%lld,%lld,%lld) alone:%lld pnum:%lld ans:%lld \n",c,count[0],count[1],count[2],alonenum,pnum,ans);

	}
	prin(ans*fac[N]%MOD);
	return 0;
}


Measured memory_bytes: 5508
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
tmp = 0
S = [0]*N
Q = []
for i in range(N):
    tmp += A[i]
    S[i] = tmp
    Q.append(tmp)

tmp = 0
for i in range(1, N):
    tmp = S[i-1]
    for j in range(i, N):
        #print(i, j)
        v = S[j] -S[i-1]
        Q.append(v)

res = 0
while True:
    ok = 0
    for i in range(40):
        num = res + int("1" + "0"*i, 2)
        tmp = 0
        for j in range(len(Q)):
            if num & Q[j] == num:
                tmp += 1
        if tmp >= K:
            ok = num
    if res < ok:
        res = ok
    else:
        break
print(res)

Measured memory_bytes: 67196
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,k;
	cin>>n>>k;
	vector<lli> h(n);
	vector<lli> dp(n,INF);
	REP(i,0,n)cin>>h[i];

	dp[n-1]=0;

	for(lli i=n-2;i>=0;i--){
		for(lli j=1;j<=k;j++){
			if(i+j>=n)break;
			dp[i] = min(dp[i+j]+abs(h[i+j]-h[i]),dp[i]);
		}
	}
	cout<<dp[0]<<endl;
	return 0;
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,m = LI()
    sc = [LI() for _ in range(m)]
    t = [-1] * n
    for s,c in sc:
        s -= 1
        if t[s] >= 0:
            if t[s] != c:
                return -1
        else:
            t[s] = c
    if n == 1:
        if t[0] == -1:
            t[0] = 0
    else:
        if t[0] == 0:
            return -1
        if t[0] == -1:
            t[0] = 1
        for i in range(1,n):
            if t[i] < 0:
                t[i] = 0

    return JA(t, "")


print(main())





Measured memory_bytes: 6612
#include<bits/stdc++.h>
using namespace std;
int n,a[27],f[200005],g[200005],dp[200005];
char s[200005];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=26;i++)
	{
		a[i]=n+1;
		f[n+1]=n+2;
		g[n+1]=1;
		dp[n+1]=1;
	}
	for (int i=n;i>=1;i--)
	{
		a[s[i]-'a'+1]=i;
		int t=1;
		for (int j=2;j<=26;j++)
			if (dp[a[j]+1]<dp[a[t]+1])t=j;
		dp[i]=dp[a[t]+1]+1;f[i]=a[t];g[i]=t;
	}
	int now=1;
	while(now<=n+1)
	{
		putchar(g[now]+'a'-1);
		now=f[now]+1;
	}
}

Measured memory_bytes: 2816
#include <iostream>

using namespace std;

bool isRight(int a, int b, int c) {
    return a * a + b * b == c * c;
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        if (isRight(a, b, c) || isRight(b, c, a) || isRight(c, a, b)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var NM = Console.ReadLine().Split().Select(int.Parse).ToList();

            var H = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var A = new int[NM[1]];
            var B = new int[NM[1]];
            var isGoodObservatories = Enumerable.Repeat(true, NM[0]).ToArray();

            for (int i = 0; i < NM[1]; i++)
            {
                var oneLine = Console.ReadLine().Split().Select(int.Parse).ToArray();
                A[i] = oneLine[0];
                B[i] = oneLine[1];

                // H配列から高さを取得
                var heightA = H[A[i] - 1];
                var heightB = H[B[i] - 1];
                if (heightA > heightB)
                {
                    isGoodObservatories[B[i] - 1] = false;
                }
                else if (heightA < heightB)
                {
                    isGoodObservatories[A[i] - 1] = false;
                } 
                else
                {
                    isGoodObservatories[A[i] - 1] = false;
                    isGoodObservatories[B[i] - 1] = false;
                }
            }

            // いい展望台を下図を求める

            // N個の展望台がある。
            // i番目の展望台の標高はHiである
            // 展望台同士の道はM本あり、jの道はAjとBjをつないでいる


            // 展望台iが良い展望台の条件
            // 1. 展望台iから1本の道を使ってたどり着けるどの展望台よりも標高が高いこと
            // 2. 展望台iから道を使ってたどり着ける展望台がない場合

            // プログラムにすると
            // 1. ある展望台に対して接続された展望台より一番高い
            // 2. ある展望台につながる道が1つもない場合

            Console.WriteLine(isGoodObservatories.Count(x => x));



#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


Measured memory_bytes: 34584
#include <iostream>
#include <utility>
#include <cmath>
#include <cstdio>
using namespace std;

#define X first
#define Y second
typedef pair<double, double> Point;

double sq(double a) {return a*a;}

double gD(Point p1, Point p2) {
  return sqrt( sq(p1.X-p2.X)+sq(p1.Y-p2.Y) );
}

int main() {
  Point p[123456];
  char ch;
  int n=0;
  for(int i=0;cin>>p[i].X>>ch>>p[i].Y;i++) n++;
  double S=0;
  for(int i=1; i<n-1; i++) {
    double a=gD(p[0],p[i]), b=gD(p[i],p[i+1]), c=gD(p[i+1],p[0]);
    double z=(a+b+c)/2;
    S+=sqrt(z*(z-a)*(z-b)*(z-c));
  }
  printf("%.8f\n", S);
  
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main() {
    int n;cin>>n;
    vi v(n);
    ll sum=0,ans=inf;
    rep(i,n){
        cin>>v[i];
        sum+=v[i];
    }
    ll a=0,b=sum;
    rep(i,n){
        a+=v[i];b-=v[i];
        chmin(ans,max(a,b)-min(a,b));
    }
    out(ans);
}

Measured memory_bytes: 1792
import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toLong() }
    println(problem069c(n, a))
}
 
fun problem069c(n: Int, a: List<Long>): String {
    val fourCount = a.count { it % 4 == 0L }
    val twoCount = a.count { it % 4 == 2L }
    val oneCount = a.count { it % 2 == 1L }
    // 「2の倍数だけど、4の倍数ではない」数はたくさんあっても1つあるのとおなじ
    // if(twoCount >= 1) 1 else 0
  
    // このままだと4の倍数にならない数たちの個数
    // oneCount + ( if(twoCount >= 1) 1 else 0 )
  
    // これらを4の倍数のとなりに置く
    // 4の倍数のとなりは fourCount + 1 個
    return if (oneCount + ( if(twoCount >= 1) 1 else 0 ) <= fourCount + 1) "Yes" else "No"
}

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

struct Problem {

    void Solve() {
        //float a; cin >> a;
        //cout << 2 * a * 3.14159 << endl;

        UL N, M; cin >> N >> M;
        rep(i, M) {
            UL a; cin >> a;
            if (N < a) { cout << -1 << endl; return; }
            N -= a;
        }
        cout << N << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}


Measured memory_bytes: 3632
N=input()

result=''
for i in range(len(N)):
    if(N[i]=='1'):
        result+='9'
    elif(N[i]=='9'):
        result+='1'
    else:
        result+=N[i]
print (result)
#pythonは直接文字列を書き換えるのが難しいので、、、別の文字列を用意

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  string s; cin >> s;
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes";
  else cout << "No";
  return 0;
}

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

int main() {
  int A;
  int B;
  int T;
  double S;
  int R;
  cin >> A >> B >> T;
  S = T/A;
  R = floor(S);

  if (A > T) {
    cout << "0" << endl;
  }
  if (A == T) {
  cout << B << endl;
}
  if (A < T) {
    cout << R*B << endl;
}
}

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

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

    multiset<int> a;
    int x;
    rep(i, N) {
        cin >> x;
        a.insert(x);
    }
    int sum = 0;
    int k = 0;
    for (auto s : a) {
        if (k == K)
            break;
        sum += s;
        k++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define sz size
#define pb push_back
#define mper make_pair
#define all(x) x.begin(), x.end()
#define fe first
#define se second
#define erba continue
using namespace std;

ll n, a, b;

ll get_top() {

    return n - b + 1 + (n - (a + (n - b + 1)) + 1) / 2;

}

ll get_down() {

    return a - 1 + 1 + (b - (a - 1 + 1) - 1) / 2ll;

}

int main() {

    cin >> n >> a >> b;

    ll dis = b - a - 1;

    if(dis % 2 != 0) {

        cout << (dis + 1) / 2ll;

    }

    else {

        cout << min( get_top() * 1ll, get_down() * 1ll );

    }


return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

char llToChar(ll p) {
    return p;
}

ll singleChar(string s) {
    ll i;
    for(i=0; i<s.size(); i++) {
        if(s[i]!=s[0]) {
            return 0;
        }
    }
    
    return 1;
}

int main(void) {
    string s, cpyt;
    cin >> s;
    ll i, p, tmp, ans=100;
    if(s.size()==1 || singleChar(s)) {
        cout << 0 << endl;
        return 0;
    }
    
    for(p='a'; p<='z'; p++) {
        cpyt=s;
        tmp=0;
        while(1) {
            string t;
            for(i=0; i<cpyt.size()-1; i++) {
                if(cpyt[i]==llToChar(p) || cpyt[i+1]==llToChar(p)) {
                    t+=llToChar(p);
                }else {
                    t+=cpyt[i];
                }
                //cout << t << endl;
            }
            
            tmp++;
            
            if(singleChar(t)) {
                break;
            }
            cpyt=t;
        }
        ans=min(ans, tmp);
    }
    
    cout << ans << endl;
}


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

int k,n,a[1010][1010];

int main()
{
	scanf("%d",&k);
	if (k==1) return puts("1"),puts("1"),0;
	for (int i=2; i<=k; i+=2) if (i*2>=k) {n=i; break;}
	for (int i=0; i<n; i+=2) 
		for (int j=0; j<n; j++) a[i][j]=(i+j)%n;
	for (int i=1; i<n; i+=2)
		for (int j=0; j<n; j++) 
		{
			a[i][j]=(i+j)%n;
			if (a[i][j]+n<k) a[i][j]+=n;
		}
	printf("%d\n",n);
	for (int i=0; i<n; i++,puts(""))
		for (int j=0; j<n; j++) printf("%d ",a[i][j]+1);
	return 0;
}

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

inline long calc(const vector<long>& s, long M, long x, long y, long w, long h){
    return s[(x+w)+(y+h)*M] - s[(x+w)+y*M] - s[x+(y+h)*M] + s[x+y*M];
}

int main(void){
    long n, k;
    cin >> n >> k;
    vector<long> b(2*k*k, 0);
    for(long i=0; i<n; i++){
        long x, y;
        char c;
        cin >> x >> y >> c;
        y %= 2*k;
        if(c=='W'){
            x += k;
        }
        if(y>=k){
            y-=k;
            x+=k;
        }
        x %= 2*k;
        b[x+y*2*k]++;
    }
    /*
    for(long y=0; y<2*k; y++){
        for(long x=0; x<2*k; x++){
            cout << b[x+y*2*k] << " ";
        }
        cout << endl;
    }
    cout << endl;
    */
    const long M = 2*k+1;
    vector<long> s((k+1)*M, 0);
    s[1+1*M] = b[0];
    for(long i=1; i<2*k; i++){
        s[(i+1)+1*M] = s[(i-1+1)+1*M] + b[i];
    }
    for(long i=1; i<k; i++){
        s[1+(i+1)*M] = s[1+(i-1+1)*M] + b[2*k*i];
    }
    for(long x=1; x<2*k; x++){
        for(long y=1; y<k; y++){
            s[x+1+(y+1)*M] = b[x+y*2*k] + s[(x-1+1)+(y+1)*M] + s[x+1+(y-1+1)*M] - s[(x-1+1)+(y-1+1)*M];
        }
    }
    /*
    for(long y=1; y<M; y++){
        for(long x=1; x<M; x++){
            cout << s[x+y*M] << " ";
        }
        cout << endl;
    }
    cout << endl;
    */
    long max = 0;
    for(long x=0; x<k; x++){
        for(long y=0; y<k; y++){
            long t = calc(s, M, x, y, k, k-y);
            t += calc(s, M, 0, 0, x, y);
            t += calc(s, M, x+k, 0, k-x, y);
            t = t<n/2 ? n-t : t;
            //printf("%ld %ld %ld\n", x, y, t);
            max = t>max ? t : max;
        }
    }
    cout << max;
    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a.at(i);
  vector<int> dp(3,0);
  int count2 = 0,count3 = 0;
  bool flag = false;
  for(int i=0;i<n;i++){
    int m = 3;
    int count = 0;
    for(int j=0;j<3;j++){
      if(dp.at(j) == a.at(i)){
        m = min(m,j);
        count++;
      }
    }
    if(m == 3){
      flag = true;
      break;
    }
    dp.at(m)++;
    if(count == 2)count2++;
    if(count == 3)count3++;
  }
  if(flag)cout << 0 << endl;
  else{
  long long ans = 1;
  ans *= ruizyou(2,count2);
  ans *= ruizyou(3,count3);
  cout << ans % MOD << endl;
  }
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int s = 0;
  REP(i, n){
    cin >> a[i];
    s += a[i];
  }
  vector<int> factors;
  for(int p = 1; p * p <= s; ++p){
    if(s % p == 0){
      factors.push_back(p);
      factors.push_back(s / p);
    }
  }
  sort(factors.begin(), factors.end(), greater<int>());
  vector<int> b(n);
  for(auto f: factors){
    int t = 0;
    REP(i, n){
      b[i] = a[i] % f;
      t += b[i];
    }
    sort(b.begin(), b.end());
    int r = 0;
    REP(i, n - t / f){
      r += b[i];
    }
    if(r <= k){
      cout << f << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
if len(S) == 26:
    now = S[-1]
    for i in reversed(range(26)):
        if ord(now) > ord(S[i]):  # 辞書順が崩れた瞬間
            happened = list(S[:i+1])
            for j in range(26):
                if chr(ord("a") + j) not in happened and ord("a") + j > ord(S[i]):
                    print(S[:i]+chr(ord("a") + j))
                    exit()
        else:
            now = S[i]

else:
    happened = list(S)
    for i in range(26):
        if chr(ord("a") + i) not in happened:
            print(S+chr(ord("a") + i))
            exit()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s[200005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	sort(s,s+n);
	int k=0;
	string a="";
	for(int i=0;i<n;i++){
		if(s[i]==a);
		else {
			a=s[i];
			k++;
		}
	}
	cout<<k;
	
}

Measured memory_bytes: 9896
#include <stdio.h>

int main(){
  char ch;
  int i,count[26] = {0};

  while(scanf("%c",&ch) != EOF){
    if(ch=='\0') break;

    if(ch>='a'){
      int num = ch - 'a';

      count[num]++;
    }

    else{
      int num = ch - 'A';

      count[num]++;
    }
  }
    
  for(i=0; i<26; i++){
    printf("%c : %d\n",'a'+i,count[i]);
  }

  return 0;
}

Measured memory_bytes: 540
K = int(input())
D = int(input())
L = len(str(K))
k = str(K)

dp = [[[0 for _ in range(2)] for _ in range(D)] for _ in range(L+1)]
dp[0][0][0] = 1

mod = 10 ** 9 + 7

for i in range(L):
    for sum in range(D):
        for sml in range(2):
            if sml == 1:
                for d in range(10):
                    dp[i+1][(d+sum)%D][1] += dp[i][sum][1]
                    dp[i+1][(d+sum)%D][1] %= mod
            elif sml == 0:
                lim = int(k[i])
                for d in range(lim):
                    dp[i+1][(d+sum)%D][1] += dp[i][sum][0]
                    dp[i+1][(d+sum)%D][1] %= mod
                dp[i+1][(lim+sum)%D][0] += dp[i][sum][0]
                dp[i+1][(lim+sum)%D][0] %= mod

ans = dp[L][0][0] + dp[L][0][1] - 1
ans %= mod

print(ans)

Measured memory_bytes: 130268
#include <stdio.h>

int main(){
  int n;
  char *s[10];
  scanf("%d",&n);
  s[0] = "pon";
  s[1] = "pon";
  s[2] = "hon";
  s[3] = "bon";
  s[4] = "hon";
  s[5] = "hon";
  s[6] = "pon";
  s[7] = "hon";
  s[8] = "pon";
  s[9] = "hon";
  printf(s[n%10]);
  return 0;
}


Measured memory_bytes: 1728
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(A, p);
  print((A * 3 + p) / 2);
  return 0;
}

Measured memory_bytes: 256
def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    R = A[mid:right]
    L.append(('J', 1000000001))
    R.append(('J', 1000000001))
    i = 0  # L[]??¨?????????????????????
    j = 0  # R[]??¨?????????????????????
    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def partition(A, p, r):
    """
    ???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨???
    """
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r]
    A[r] = temp
    return i+1


def quick_sort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quick_sort(A, p, q-1)
        quick_sort(A, q+1, r)


if __name__ == '__main__':
    # ??????????????\???
    #cards = [('D', 3), ('H', 2), ('D', 1), ('S', 3), ('D', 2), ('C', 1)]
    #comp_cards = cards[:]
    num_of_cards = int(input())
    cards = []
    for i in range(num_of_cards):
        suit, rank = input().split(' ')
        cards.append((suit, int(rank)))
    comp_cards = cards[:]


    # ??????????????????
    data_length = len(cards)
    quick_sort(cards, 0, data_length-1)
    merge_sort(comp_cards, 0, data_length)  # ?????????????????????????????????????????¨

    # ???????????????
    stable = True  # ?????????????????????????????????????????????
    for x, y in zip(cards, comp_cards):
        if x != y:
            stable = False
            print('Not stable')
            break
    if stable is True:
        print('Stable')

    for c in cards:  # ??????????????¨???
        print('{0} {1}'.format(c[0], c[1]))

Measured memory_bytes: 19628
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    int x;
    int ans = 0;
    int num1;
    int num2;
    cin >> x;
    num1 = x / 500;
    ans += num1 * 1000;
    num2 = (x % 500) / 5;
    ans += num2 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    bool f=true;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a%2==1){
            f=!f;
        }
    }
    if(f){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 384
#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};
//---------------------------
map<int,ll> mp;
int i,j,k,N;
ll T,a;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

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

  cin>>N>>T;
  ll mn=LINF;
  for(i=0;i<N;i++){
    cin>>a;
    mn=min(mn, a);
    mp[a - mn]++;
  }
  ll index=0,ans=0;
  for(auto itr=mp.begin(); itr!=mp.end();++itr) {
    j=(itr->first);
    if(index<j){
      index=j;
      ans=(itr->second);
    }
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    cout<<(n+110)/111*111<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,l[100],i,j,k,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	sort(l,l+n);
	for(i=0;i<n-2;i++){
		for(j=i+1;j<n-1;j++){
			for(k=j+1;k<n;k++){
				if(l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]){
					if(l[i]+l[j]>l[k]) c++;
				}
			}
		}
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 1696
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define INF 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> G[3 * n];  // 点の数を3倍
  REP(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v + n);
    G[u + n].push_back(v + 2 * n);
    G[u + 2 * n].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  s--, t--;
  int dist[3 * n];
  REP(i, 3 * n) dist[i] = INF;
  dist[s] = 0;
  queue<int> que;
  que.push(s);
  while (que.size()) {
    int p = que.front();
    que.pop();
    REP(i, G[p].size()) {
      int q = G[p][i];
      if (dist[q] == INF) {
        que.push(q);
        dist[q] = dist[p] + 1;
      }
    }
  }
  if (dist[t] == INF)
    cout << -1 << endl;
  else
    cout << dist[t] / 3 << endl;
  return 0;
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}


int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n,m;
    scn2(n,m);

    vector<int>a;

    for(int i=1; i<=n; i++){
        int x;
        scn(x);
        a.pb(x);
    }

    sort(atoz(a));

    priority_queue<pii>pq;

    for(int i=1; i<=m; i++){
        int b,c;
        scn2(b,c);
        pq.push({c,b});
    }
    lli sum = 0;
    reverse(atoz(a));
    while(a.size()){

        if(pq.size()){
            pii p = pq.top();
            pq.pop();
            if(p.fi>a.back()){
                sum += p.fi;
                p.se--;
            }
            else sum += a.back();

            a.pop_back();
            if(p.se>0)pq.push(p);
        }
        else{
            sum += a.back();
            a.pop_back();
        }
    }
    cout<<sum;
    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///priority_queue< int, vector< int >, greater< int > > minHeap;
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 1784