akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;

typedef long long int ll;
 
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 10005;
const ll mod = 998244353;
const long long int inf = 10e17;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;


}

	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M,R;
    cin >> N >> M >> R;
    vector<int>r(R);
    for(int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    sort(r.begin(),r.end());
    vector<vector<int>>cnt(N,vector<int>(N,INF));
    for(int i = 0; i < M; i++) {
        int A,B,C;
        cin >> A >> B >> C;
        A--;B--;
        cnt[A][B] = C;
        cnt[B][A] = C;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                cnt[j][k] = min(cnt[j][k],cnt[i][j]+cnt[i][k]);
            }
        }
    }
    int ans = INF;
    do {
        int sum = 0;
        for(int i = 0; i < R-1; i++) {
            sum+=cnt[r[i]][r[i+1]];
        }
        ans = min(ans,sum);
    }while(next_permutation(r.begin(),r.end()));
    cout << ans << endl;
}


Measured memory_bytes: 3952
S=input()
ans=0
if len(S)==1:
    print(0)
else:
    tmp=S[0]
    for s in S[1:]:
        if s==tmp:
            ans+=1
            if s=="0":
                tmp="1"
            else:
                tmp="0"
        else:
            tmp=s
    print(ans)


Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int mod = 1'000'000'007;

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

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

int pw(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}

const int MXN = 25'009;
const int MXK = 409;

int a[MXN];
int fac[MXK];
int f[MXN][MXK];
int s[MXK];
int ways[MXN][MXK];
int sways[MXN][MXK];
bool was[MXK];

int main() {
  int n, k, m;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", a + i);
  }
  memset(was, false, sizeof was);
  bool good = false;
  for (int i = 0, j = 0; i < m; ++i) {
    if (!was[a[i]]) {
      was[a[i]] = true;
      if (i - j + 1 == k) {
        good = true;
      }
    } else {
      while (a[j] != a[i]) {
        was[a[j]] = false;
        ++j;
      }
      ++j;
    }
  }
  int ans = 1;
  for (int i = 0; i < n - m; ++i) {
    ans = mul(ans, k);
  }
  ans = mul(ans, n - m + 1);
  if (good) {
    printf("%d\n", ans);
    return 0;
  }
  fac[0] = 1;
  for (int i = 1; i < MXK; ++i) {
    fac[i] = mul(fac[i - 1], i);
  }
  int inv_k = pw(fac[k], mod - 2);
  memset(f, 0, sizeof f);
  memset(s, 0, sizeof s);
  f[0][0] = 1;
  s[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k - 1; ++j) {
      add(f[i + 1][j + 1], mul(f[i][j], k - j));
    }
    for (int j = 1; j < k; ++j) {
      add(f[i + 1][j], s[j]);
    }
    memset(s, 0, sizeof s);
    for (int j = k - 1; j >= 1; --j) {
      s[j] = s[j + 1];
      add(s[j], f[i + 1][j]);
    }
  }
  memset(ways, 0, sizeof ways);
  for (int i = 1; i <= n; ++i) {
    for (int j = min(k - 1, i); j >= 1; --j) {
      ways[i][j] = ways[i][j + 1];
      add(ways[i][j], f[i][j]);
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= k; ++j) {
      ways[i][j] = mul(ways[i][j], mul(fac[k - j], inv_k));
    }
  }
  memset(sways, 0, sizeof sways);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < k; ++j) {
      sways[i][j] = sways[i][j - 1];
      add(sways[i][j], ways[i + j - 1][j]);
    }
  }
  memset(was, false, sizeof was);
  int pref = 0;
  while (pref < m && !was[a[pref]]) {
    was[a[pref]] = true;
    ++pref;
  }
  if (pref == m) {
    for (int i = 0; i + m - 1 < n; ++i) {
      int co = 1;
      for (int j = 0; m + j < k && i + m - 1 + j < n; ++j) {
        int len = n - 1 - (i + m - 1 + j);
        if (len == 0) {
          add(ans, mod - mul(ways[i + m + j][m + j], co));
        } else {
          add(ans, mod - mul(mul(ways[i + m + j][m + j], sways[len][m + j]), co));
        }
        co = mul(co, k - m - j);
      }
    }
    printf("%d\n", ans);
    return 0;
  }
  reverse(a, a + m);
  memset(was, false, sizeof was);
  int suff = 0;
  while (suff < m && !was[a[suff]]) {
    was[a[suff]] = true;
    ++suff;
  }
  for (int i = 0; i + m - 1 < n; ++i) {
    add(ans, mod - mul(ways[i + pref][pref], ways[n - 1 - (i + m - 1) + suff][suff]));
  }
  printf("%d\n", ans);
}


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

struct item{
    int wt,val;
};

long long solve(vector<item> ar,int n , int W ){
    
    long long dp[n+1][W+1];
    
    for(int i=0;i<=W;i++){
        dp[1][i]=0;
    }
    
    dp[1][ar[1].wt]=ar[1].val;
    
    for(int i=2;i<=n;i++){
        for(int w=0;w<=W;w++){
            dp[i][w]=dp[i-1][w];
            if(ar[i].wt>w)
                continue;
            dp[i][w]=max(dp[i][w],ar[i].val+dp[i-1][w-ar[i].wt]);
        }
    }
    return *max_element(dp[n],dp[n]+W+1);
   
}

int main() {
	// your code goes here
	int n,W;
	cin>>n>>W;
	vector<item> ar(n+1);
	for(int i=1;i<=n;i++){
	    cin>>ar[i].wt>>ar[i].val;
	}
	cout<<solve(ar,n,W)<<endl;
	return 0;
}


Measured memory_bytes: 81680
n,m = map(int, input().split())
mo = list(map(int,input().split()))
dp = [float("inf") for i in range(n+2)]
dp[0] = 0
for i in range(n+1):
    for j in mo:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
print(dp[n])


Measured memory_bytes: 7384
import numpy as np
from collections import Counter


def calc_prime_factors(n):
    # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
    """ Returns a array of primes, p < n """
    # assert n >= 2
    sieve = np.ones(n // 2, dtype=np.bool)
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i // 2]:
            sieve[i * i // 2::i] = False
    return np.r_[2, 2 * np.nonzero(sieve)[0][1::] + 1]


n = int(input())
primes_smaller_than_1000 = [x for x in calc_prime_factors(1000)]
primes = []
for num in range(1, n + 1):
    for prime_number in primes_smaller_than_1000:
        while num % prime_number == 0:
            num /= prime_number
            primes.append(prime_number)
counter_primes = Counter(primes)
res = 1
for i in counter_primes.values():
    res *= (i + 1)
    res %= 1000000007
print(res)


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct RangeMaxQuery{
  ll dat[(1<<19)-1];
  int size;

  void init(int n_){
    size=1;
    while(size<n_) size*=2;
    for(int i=0;i<2*size-1;i++)dat[i]=-INF;
  }

  void update(int k,ll a){
    k+=size-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }

  ll subquery(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return -INF;
    if(a<=l&&r<=b)return dat[k];
    else{
      return max(subquery(a,b,k*2+1,l,(l+r)/2),subquery(a,b,k*2+2,(l+r)/2,r));
    }
  }
  
  ll query(int a,int b){
    return subquery(a,b,0,0,size);
  }
};

ll n;
ll a[200010],h[200010];
vector<int> idx;
RangeMaxQuery rmq;

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

  cin>>n;
  rep(i,n)cin>>h[i];
  rep(i,n)cin>>a[i];
  rep(i,n)idx.push_back(i);
  sort(all(idx),[=](const int& x,const int& y){ return h[x] < h[y]; });

  rmq.init(n);
  rep(j,idx.size()){
    ll i=idx[j];
    ll mx=max(0LL,rmq.query(0,i))+a[i];
    rmq.update(i,mx);
  }
  cout<<rmq.query(0,n)<<endl;

  return 0;
}


Measured memory_bytes: 8436
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
n, k = map(int, input().split())
ds = [0] * k
As = [0] * n

for i in range(k):
    ds[i] = input()
    A = list(map(int, input().split()))
    for a in A:
        As[a - 1] += 1
ans = 0
for A in As:
    if (A == 0):
        ans += 1

print(ans)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
int main()
{
  int n,t;
  cin>>n>>t;
  long long int sums=0;
  int temp;
  for(int i=0;i<t;i++)
  {
    cin>>temp;
    sums+=temp;
  }
  if(sums>n)
  cout<<"-1\n";
  else
  cout<<(n-sums);
  return 0;
}

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

using namespace std;


int box[100005];
bool red[100005];//记录有可能出现红球的盒子
int main()
{
	//有n个盒子，1号盒子一定有红球
	//做m次操作
	int n, m;
	int x, y;
	int ans = 0;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		box[i] = 1;
	}
	red[1] = true;
	
	for (int i = 1; i <= m; i++)
	{
		cin >> x >> y;
		//如果x盒子有红球，那么y盒子就有可能有红球（有红球,球数肯定大于1除了第一个盒子外）
		if (red[x] == 1)
		{
			red[y] = 1;
		}
		//将x的球移动到y盒子中
		box[x]--;
		box[y]++;
		//x盒子如果没球，那么直接置0
		if (box[x] == 0)
		{
			red[x] = 0;
		}
	}
	for (int j = 1; j <= n; j++)
	{
		ans += red[j];
	}

	cout << ans << endl; 
	

//	system("pause");
	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int x = scanner.nextInt();
		
		int y = scanner.nextInt();
		
		if(x > y) {
			System.out.println("a > b");
		}else if(x < y) {
			System.out.println("a < b");
		}else {
			System.out.println("a == b");
		}
		
		
		
		
		
		scanner.close();
		
	}

}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    ll x;
    cin >> N >> x;
    V<ll> a(N);
    rep(i, N) cin >> a[i];
    ll ans = 0, la = a[0];
    for (int i = 1; i < N; ++i) {
        ll s = la + a[i];
        if (s <= x) {
            la = a[i];
            continue;
        }
        ll d = min(a[i], s - x);
        a[i] -= d;
        s -= d;
        ans += d;
        if (s > x) {
            ans += s - x;
        }
        la = a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a > b)
                System.out.println("a > b");
            else if (a < b)
                System.out.println("a < b");
            else
                System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26316
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int p[5010], c[5010];
long long s[5010][35];
int d[5010][35];

long long cal(int x, int y) {
    if(y <= 0) return -1e9;
    long long ret = 0;
    for(int i = 29; i >= 0; i--) {
        if(y >= (1<<i)) {
            y -= (1<<i);
            ret += s[x][i];
            x = d[x][i];
        }
    }
    return ret;
}

int main() {
    int n, m, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
    }
    for(int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
    }
    for(int i = 1; i <= n; i++) {
        d[i][0] = p[i];
    }
    for(int j = 1; j < 30; j++) {
        for(int i = 1; i <= n; i++) {
            d[i][j] = d[d[i][j - 1]][j - 1];
        }
    }
    for(int i = 1; i <= n; i++) {
        s[i][0] = c[p[i]];
    }
    for(int j = 1; j < 30; j++) {
        for(int i = 1; i <= n; i++) {
            s[i][j] = s[i][j - 1] + s[d[i][j - 1]][j - 1];
        }
    }
    long long ans = -1e9;
    for(int i = 1; i <= n; i++) {
        long long now = 0, np = p[i];
        for(int j = 1; j <= min(n, k); j++) {
            now += c[np];
            np = p[np];
            ans = max(ans, now);
        }
        for(int j = k; j >= k - n; j--) {
            ans = max(ans, cal(i, j));
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 5852
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S;
  cin >> S;
  const int32_t length = static_cast<int32_t>(S.length());
  int32_t count_0 = 0;
  int32_t count_1 = 0;
  for (int32_t i = 0; i < length; ++i) {
    const int32_t val = S.c_str()[i] - '0';
    const int32_t expected_0 = (i % 2);
    if (val == expected_0) {
      ++count_0;
    } else {
      ++count_1;
    }
  }
  cout << min(count_0, count_1) << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val k = cin.nextLong()

    val a = 2*100000 + 1

    val jumpto = Array<Int>(n, { -1 })
    val now_tail = Array<Int>(a, { -1 })
    val head = Array<Int>(a, { -1 })
    val values = Array<Int>(n, { -1 })

    for (i in 0..n-1) {
        val t = cin.nextInt()
        values[i] = t
        if (now_tail[t] != -1) {
            jumpto[now_tail[t]] = i
        }
        now_tail[t] = i
        if (head[t] == -1) {
            head[t] = i
        }
    }

    for (i in 0..n-1) {
        if (jumpto[i] == -1) {
            jumpto[i] = head[values[i]]
        }
    }

    val round = Array<Int>(n, { -1 })
    val passed = Array<Boolean>(n, { false })

    var now = 0
    var now_round = 0
    while(!passed[now]) {
        passed[now] = true
        round[now] = now_round
        if (now >= jumpto[now]) {
            now_round += 1
        }
        now = jumpto[now] + 1
        if (now == n) {
            now_round += 1
            now = 0
        }
    }
    val cycle = now_round - round[now]
    val first = round[now] + 1
    val last = (k - first) % cycle

    var exceed = last.toInt()
    while(true) {
        if (exceed == 0 && now >= jumpto[now]) {
            break
        }
        if (now >= jumpto[now]) {
            exceed -= 1
        }
        now = jumpto[now] + 1
        if (now == n) {
            exceed -= 1
            now = 0
            if (exceed == -1) {
                break
            }
        }
    }

    val ans: MutableList<Int> = mutableListOf()
    while(n > now && exceed >= 0) {
        if (jumpto[now] > now) {
            now = jumpto[now] + 1
        } else {
            ans.add(values[now])
            now += 1
        }
    }

    for (i in 0..ans.size-1) {
        print(ans[i])
        print(" ")
    }
    println()
}

Measured memory_bytes: 110696
#include <stdio.h>
int main(void){
    // Your code here!
    int A,B,C;
    
    scanf("%d %d %d",&A,&B,&C);
    
    if(A==B)
    {
        printf("%d",C);
}
else if(B==C)
{
    printf("%d",A);
}
else if(A==C)
{
    printf("%d",B);
}
return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
int mod = 1000000007;

/*FUNCs=================================================*/
vi move1 = {0,0,1,-1};
vi move2 = {1,-1,0,0};
/*prime_test=================================================*/
bool prime_test(int num) {
    if (num < 2) return false;           // 0 と 1 除く
    else if (num == 2) return true;      //2はtrue
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    int sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0) return false;  // 素数ではない
    }
    // 素数である
    return true;
}
/*============================================================*/
/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int x; cin >>x;
    for(int i = x; ; i++) {
        if(prime_test(i)) {
            cout << i << '\n';
            break;
        }
    }
}


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

int main() {
	int L, R;cin>>L>>R;

	long long ans = 1e18;

	if (L / 2019 == R / 2019)
	{	
		for (long long i = L; i <= R; i++)
		{
			for (long long j = i + 1; j <= R; j++)
			{
				long long x = i*j;
				ans = min(ans, x%2019);
			}
		}

		cout<<ans<<endl;
	}
	else
	{
		cout<<0<<endl;
	}

	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);

	string s;
	long long int r = 0, c = 0;

	cin >> s;

	for (unsigned int i = 0; i < s.length(); i++) {
		if (s[i] == 'W') {
			r += i - c;
			c++;
		}
	}

	cout << r;

	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int h, w, s;
int sumMin;		//??°?????????????????????
int u[32][32];
int ru[33][33];
P dp[33][33][33][33];

int yobi(int ly, int lx, int ry, int rx) {
	return ru[ry][rx] - ru[ry][lx] - ru[ly][rx] + ru[ly][lx] - sumMin;
}

P dfs(int ly, int lx, int ry, int rx) {
	if (dp[ly][lx][ry][rx].first != -1) {
		return dp[ly][lx][ry][rx];
	}
	
	P ret = P(1, yobi(ly, lx, ry, rx));
	
	//[ly, y), [y, ry)
	for (int y = ly + 1; y < ry; y++) {
		if (yobi(ly, lx, y, rx) >= 0 && yobi(y, lx, ry, rx) >= 0) {
			P res1 = dfs(ly, lx, y, rx);
			P res2 = dfs(y, lx, ry, rx);
			
			if (ret.first < res1.first + res2.first || (ret.first == res1.first + res2.first && ret.second < min(res1.second, res2.second))) {
				ret.first = res1.first + res2.first;
				ret.second = min(res1.second, res2.second);
			}
		}
	}
	for (int x = lx + 1; x < rx; x++) {
		if (yobi(ly, lx, ry, x) >= 0 && yobi(ly, x, ry, rx) >= 0) {
			P res1 = dfs(ly, lx, ry, x);
			P res2 = dfs(ly, x, ry, rx);
			
			if (ret.first < res1.first + res2.first || (ret.first == res1.first + res2.first && ret.second < min(res1.second, res2.second))) {
				ret.first = res1.first + res2.first;
				ret.second = min(res1.second, res2.second);
			}
		}
	}
	return dp[ly][lx][ry][rx] = ret;
}

int main() {
	while (cin >> h >> w >> s) {
		if (!h) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> u[i][j];
				ru[i + 1][j + 1] = u[i][j];
			}
		}
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				ru[i][j] += ru[i][j - 1];
			}
		}
		for (int j = 1; j <= w; j++) {
			for (int i = 1; i <= h; i++) {
				ru[i][j] += ru[i - 1][j];
			}
		}
		sumMin = ru[h][w] - s;
		
		for (int i = 0; i <= h; i++) for (int j = 0; j <= w; j++) for (int k = 0; k <= h; k++) for (int l = 0; l <= w; l++) dp[i][j][k][l].first = -1;
		P ans = dfs(0, 0, h, w);
		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 12384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long k = sc.nextInt();
		sc.close();

		long ans = Math.min(a, k);
		k -= a;
		k -= b;
		if (k > 0) {
			ans -= k;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35676
count = 0

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L, R = A[left: left + n1], A[mid: mid + n2]
    global count

    L.append(2000000000)
    R.append(2000000000)

    i, j = 0, 0
    for k in range(left, right):
        #print("k", k, "l", left, "m", mid, "r", right, "L", L, "R", R)
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            count += len(L) - 1 - i
            j += 1


def mergeSort(A, left, right):
    #print("l", left, "r", right)
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


n = int(input())
input_list = list(map(int, input().split(' ')))

mergeSort(input_list, 0, n)
print(count)



Measured memory_bytes: 27480
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())
    print("YES" if abs(b - a) <= t * (v - w) else "NO")
resolve()

Measured memory_bytes: 61728
S=list(input())
N=len(S)
s=reversed(S)
X=[0]*N
for i in range(N):
    m=1
    if i>0 and S[i]=="R" and S[i]==S[i-1]:
        m=k-1
        if m%2==0:
            X[i+m]+=1
        else:
            X[i+m-1]+=1
    else:

        if S[i]=="R":
            while 1:
                if S[i]!=S[i+m]:
                    break
                m+=1
            if m%2==0:
                X[i+m]+=1
            else:
                X[i+m-1]+=1
    if i>0 and S[i]=="L" and S[i]==S[i-1]:
        m=k+1
        if m%2==0:
            X[i-m]+=1
        else:
            X[i-m+1]+=1
    else:
        if S[i]=="L":
            while 1:
                if S[i]!=S[i-m]:
                    break
                m+=1
            if m%2==0:
                X[i-m]+=1
            else:
                X[i-m+1]+=1
    k=m
for i in range(N):
    print(X[i])
        
        


Measured memory_bytes: 55288
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void exawizards2019_a(vector<vector<int>> v) {

    int a = v[0][0];
    int b = v[0][1];
    int c = v[0][2];
    
    cout << (a==b && b==c  ? "Yes" : "No") << endl;






}

int main() {

//    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    exawizards2019_a(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


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

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


int main()
{
	int n,m;cin>>n>>m;
	multiset<int> st;
	rep(i,0,n-1){
	    int a;cin>>a;
	    st.insert(a);
	}
	rep(i,1,m){
	    auto it = st.rbegin();
	    st.insert(*it/2);
	    st.erase(std::prev(st.end()));
	}
	ll ans = 0;
	for(auto it = st.begin(); it!=st.end(); ++it){
	    ll x = *it;
	    ans += x;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4992
abc = list(map(int, input().split()))

if abc[0] > abc[1]:
    abc[0], abc[1] = abc[1], abc[0]
if abc[1] > abc[2]:
    abc[1], abc[2] = abc[2], abc[1]
if abc[0] > abc[1]:
    abc[0], abc[1] = abc[1], abc[0]

print("{} {} {}".format(abc[0], abc[1], abc[2]))


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn =  new Scanner(System.in);
        
        while(true){
            double x = stdIn.nextInt();
            double h = stdIn.nextInt();
            
            if(x == 0 && h == 0){
                break;
            }
            
            System.out.println(x * x + x * Math.sqrt(h * h + x / 2 * x / 2) * 0.5 * 4);
        }
    }
}



Measured memory_bytes: 26492
n = gets.to_i

while n != 0
	tmp = []
	n.times do 
		tmp.push(gets.split.map(&:to_i))
	end
	m = gets.to_i
	ans = []
	xy_first = [10,10]
	m.times do
		dir,val = gets.split(" ")
		val = val.to_i
		val.times do 
			flag = 0
			if dir == "N"
				xy_first[1] += 1
			elsif dir == "E"
				xy_first[0] += 1
			elsif dir == "S"
				xy_first[1] -= 1
			elsif dir == "W"
				xy_first[0] -= 1
			end
			tmp.each do |xy|
				if xy == xy_first 
					flag = 1
					xy.shift
				else
					flag = 0
				end
				ans.push(flag) if flag == 1
			end
		end
	end
	if n == ans.length
		puts "Yes"
	else
		puts "No"
	end
	n = gets.to_i
end

Measured memory_bytes: 8772
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//x numero de animais e y numero de pernas

int main(){
	int x, y, eq=0, eq2=0;
	scanf("%d %d", &x, &y);

	if (y%2!= 0)
		printf("No");
	else{
		eq= (y-2*x)/2;
		eq2= x-eq;
		if (eq2>= 0 && eq >= 0)
			printf("Yes");
		else 
			printf("No");
	}
	printf("\n");

	return 0;	
}

Measured memory_bytes: 1696
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: u64 = read();
  if n >= 1000 {
    println!("ABD")
  } else {
    println!("ABC")
  }
}


Measured memory_bytes: 4352
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	string s;

	cin >> s;
	ll n = s.size();
	ll ans = n;
	REP(i, n-1) {
		if (s[i] != s[i + 1]) {
			chmin(ans, max(i + 1, n - i - 1));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
import scala.io.StdIn

object Main {
  def main(args: Array[String]){
    val input = StdIn.readLine().split(" ").map(_.toInt)
    println(gcd(input.max,input.min))
  }

  def gcd(x: Int, y: Int):Int = {
    if(0 < y && y < x) { gcd(y, x % y) } 
    else { x }
  }
}

Measured memory_bytes: 43992
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    Yn(n%findSumOfDigits(n)==0);

    return 0;
}

Measured memory_bytes: 256
n, m, x = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

r = (n+1)*[0]
for i in a:
    r[i] = 1

if(sum(r[0:x]) > sum(r[x:])):
    print(sum(r[x:]))
else:
    print(sum(r[0:x]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int k, x;
  cin >> k >> x;
  if (500 * k >= x) puts("Yes");
  else
    puts("No");
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    ll A, B;
    cin >> A >> B;
    ll C = __gcd(A, B);
    vector<ll> hoge;
    for (ll i = 2; i * i <= C; i++) {
        if (C % i == 0) {
            hoge.push_back(i);
            while (C % i == 0) {
                C /= i;
            }
        }
    }
    if (C != 1) {
        hoge.push_back(C);
    }
    cout << hoge.size() + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b,c,d;
    double f,m,n;
    
    cin >> a>>b;
    
    c=a/b;
    d=a%b;
    
    m=a;  n=b;
    
    f=m/n;
    
    cout << c << " " <<d<<" "<<fixed<<setprecision(8)<<f<<endl;
    
    
}



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

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

    if(n%500==0){
        cout<<"Yes"<<endl;
    }
    else if(n%500<=a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    ll a,b;cin>>a>>b;
    cout<< a + b/2;
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int T=1;while(T--){solve();}return 0;
}/*Solved By:- RITIK AGARWAL*/

Measured memory_bytes: 3548
#include<iostream>
#include<stdlib.h>

using namespace std;

typedef long long ll;

void chmin(ll &a,ll b){
  if(a > b) a = b;
}

int main(){
  ll N,K;
  ll h[111111];
  ll i,j;
  cin >> N >> K;
  for(i=0;i<=N-1;i++)
    cin >> h[i];
  ll dp[111111];
  for(i=1;i<=N-1;i++)
    dp[i] = 1111111111111;
  dp[0] = 0;
  for(i=1;i<=K-1;i++)
    for(j=i;j<=i;j++)
      chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
  for(i=K;i<=N-1;i++)
    for(j=1;j<=K;j++)
      chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
#define N 100000

int main(void){
	char s[N];
	int g = 0, p = 0;
	int score = 0;

	cin >> s;

	for (int i = 0; i < strlen(s); i++){
		if (s[i] == 'g'){
			if (p < g){
				p++;
				score++;
			}
			else g++;
		}
		if (s[i] == 'p'){
			if (p < g){
				p++;
			}
			else{
				g++;
				score--;
			}
		}
	}

	cout << score << endl;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
vector<int> e[100010];
int f[100010];
int done[100010];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		--x; --y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for (int i = 0; i < n; i++) {
		f[i] = -1;
	}
	priority_queue<pair<int, int> > q;
	int m;
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		--x;
		f[x] = y;
		done[x] = 1;
		q.push(make_pair(y, x));
	}
	while (q.size()) {
		int x, y;
		x = q.top().second;
		y = q.top().first;
		q.pop();
		for (int i = 0; i < e[x].size(); i++) {
			int z = e[x][i];
			if (f[z] == -1) {
				if (!done[z]) {
					f[z] = y - 1;
					q.push(make_pair(y-1, z));
					done[z] = 1;
				}
			} else {
				if (!(f[z] == y + 1 || f[z] == y - 1)) {
					puts("No");
					return 0;
				}
				if (!done[z]) {
					q.push(make_pair(f[z], z));
					done[z] = 1;
				}
			}
		}
	}
	puts("Yes");
	for (int i = 0; i < n; i++) {
		printf("%d\n", f[i]);
	}
	return 0;
}


Measured memory_bytes: 8308
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<vector>
 
#define mx(ans, cnt) ans = max(ans, cnt)
#define fauto(a) for(auto i : a) cout << i << " "; cout << endl;
#define sp(n) fixed << setprecision(n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _ << " " <<
#define swp(x, y) if (x > y) swap(x, y);
#define swpg(x, y) if (x < y) swap(x, y);
#define ff first
#define ss second
#define xx first
#define yy second
#define pb push_back
#define nn end1
 
 
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main ()
{
    ll n,i,j,k,c=0;
    vector<ll> v;
    cin>>n;
    for(i=0;i<n;i++)
    {ll q; cin>>q; v.pb(q);}
    for(i=1;i<v.size();i++)
    {
        if(v[i-1]>v[i])
        {
            k=(v[i-1]-v[i]);
            c=c+k;
            v[i]=v[i]+k;
        }
    }
    cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 5356
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;
const int ALP = 26;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

template<typename T>
void dump_line(T *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

ll mod_pow(ll x,ll n,ll mod){
	if(n==0) return 1;
	ll res=mod_pow(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}

int priority[9]={1,7,4,5,3,2,9,6,8};
int match[9]={2,5,5,4,5,6,3,7,6};
bool A[9]={};

map<int,int> ans;

bool dfs(int i,int n){
	if(n==0) return true;
	if(i==9) return false;

	while(i<9 && !A[priority[i]-1]) i++;
	if(i==9) return false;

	int num=priority[i];//マッチで作る数字
	for(int j=n/match[num-1];j>=0;j--){
		if(dfs(i+1,n-j*match[num-1])){
			ans[num]=j;
			return true;
		}
	}
	return false;
}

const int N=1e5;
ll a[N],b[N];

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

	int n;
	cin >> n;
	ll suma=0,sumb=0;
	rep(i,n){
		cin >> a[i];
		suma+=a[i];
	}
	rep(i,n){
		cin >> b[i];
		sumb+=b[i];
	}
	if(suma < sumb){
		cout << "-1\n";
		return 0;
	}

	vector<int> savings;
	ll lack=0;
	int ans=0;
	rep(i,n){
		if(a[i] < b[i]){
			lack+=b[i]-a[i];
			ans++;
		}
		else if(a[i] > b[i]){
			savings.push_back(a[i]-b[i]);
		}
	}
	sort(savings.begin(),savings.end());

	for(auto i=savings.rbegin();i!=savings.rend();i++){
		if(lack<=0){
			cout << ans << "\n";
			return 0;
		}
		ans++;
		lack-=*i;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

using namespace std;

const int oo = 0x3f3f3f3f;

ll n;

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x; 
}

int main()
{
	cin >> n;
	cout << n * (n - 1) / 2;
	return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  const int64_t MOD = 1000000007;
  cin >> n;
  int64_t a[n] = {};
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  
  int64_t ans = 0;
  for(int i=0;i<60;i++){
    int64_t countOne = 0;
    int64_t now = 0;
  	for(int j=0;j<n;j++){
      if( ((a[j]>>i)&1) !=0)countOne++;
  	}
    now = countOne*(n-countOne)%MOD;
    for(int j=0;j<i;j++){
      now *= 2;
      now %= MOD;
    }
    ans += now;
    ans %= MOD;
  }

  cout << ans%MOD << endl;
  
  return 0;
}




Measured memory_bytes: 6008
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)a[i]=i;
  int x[n],y[n];
  rep(i,n)cin >> x[i] >> y[i];
  double sum = 0;
  do {
    rep(i,n-1)sum += sqrt((x[a[i]]-x[a[i+1]])*(x[a[i]]-x[a[i+1]])+(y[a[i]]-y[a[i+1]])*(y[a[i]]-y[a[i+1]]));
  } while(next_permutation(a, a + n));
  int n_k = 1;
  int t = n;
  while(t>0){
    n_k*=t;
    t--;
  }
  printf("%.10f\n",sum/n_k);
}


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

int main() {
    int N; cin >> N;
    int o = 0;
    rep(i, 1, N + 1) if(i % 2) o++;
    double ans = (double)o / N;
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
a = list(input())
if max(a)==a[0]:
        print(a[0]*3)
elif min(a)==a[0]:
        print((int(a[0])+1)*111)        
elif max(a)==a[1]:
        print((int(a[0])+1)*111) 
elif max(a)==a[2] and a[0]<=a[1]:
        print((int(a[0])+1)*111)               
elif max(a)==a[2] and a[0]>a[1]:
        print(a[0]*3)

Measured memory_bytes: 3064