akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <list>

using namespace std;

const int MaxN = 2e5 + 5;

vector<int> gb[MaxN], gr[MaxN];

int dep[MaxN], fa[MaxN], d[MaxN];
bool safe[MaxN], vis[MaxN];

int main() {
  ios_base::sync_with_stdio(false);
  int n, sx, sy;
  cin >> n >> sx >> sy;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    gr[x].emplace_back(y);
    gr[y].emplace_back(x);
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    gb[x].emplace_back(y);
    gb[y].emplace_back(x);
  }
  list<int> Q;
  Q.emplace_back(sy);
  fa[sy] = -1;
  vis[sy] = true;
  while (!Q.empty()) {
    int k = Q.front();
    for (int x : gb[k]) {
      if (!vis[x]) {
        Q.emplace_back(x);
        vis[x] = true;
        dep[x] = dep[k] + 1;
        fa[x] = k;
      }
    }
    Q.pop_front();
  }
  for (int i = 1; i <= n; ++i) {
    for (int k : gr[i]) {
      if (![](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
      } (i, k)) {
        safe[i] = safe[k] = true;
      }
    }
  }
  if (safe[sx]) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  memset(d, 0xff, sizeof d);
  d[sx] = 0;
  Q.emplace_back(sx);
  while (!Q.empty()) {
    int k = Q.front();
    Q.pop_front();
    if (d[k] >= dep[k]) {
      continue;
    }
    if (safe[k]) {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, dep[k] * 2);
    for (int x : gr[k]) {
      if (vis[x] && d[k] + 1 < dep[x] && [](int x, int y) -> bool {
        return fa[x] == fa[y] || fa[x] == y || x == fa[y] || fa[fa[x]] == y || x == fa[fa[y]];
        } (k, x)) {
        d[x] = d[k] + 1;
        vis[x] = false;
        Q.emplace_back(x);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 32372
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
ans = []
front = deque([item for item in range(1, (n+1) // 2 + 1)])
back = deque([item for item in range(n // 2 + 2, n + 1)])
while len(front) > 1:
    l = front.popleft(); r = front.pop()
    ans.append((l, r))
while len(back) > 1:
    l = back.popleft(); r = back.pop()
    ans.append((l, r))
for i in range(m):
    print(*ans[i])

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

#define MAX_N 100005
bool is_prime[MAX_N];
int check[MAX_N];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int Q;
  cin >> Q;
  vector<int> L(Q), R(Q);
  for (int i = 0; i < Q; i++) cin >> L[i] >> R[i];

  sieve(MAX_N);
  check[3] = 1;
  for (int i = 5; i < MAX_N; i += 4) {
    if (is_prime[i] && is_prime[(i+1)/2]) {
      check[i] = 1;
    }
  }
  for (int i = 1; i < MAX_N; i++) check[i] = check[i] + check[i-1];

  for (int i = 0; i < Q; i++) {
    int l = L[i], r = R[i];
    int ans = check[r] - check[l-1];
    cout << ans << endl;
  }
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int n;
  while(cin >> n, n) {
    bitset<100> know[100];
    bitset<100> leak;
    REP(i, n){
      int m;
      cin >> m;
      REP(j, m){
        int p;
        cin >> p;
        know[i][--p] = 1;
      }
    }
    int k;
    cin >> k;
    REP(i, k) {
      int l;
      cin >> l;
      leak[--l] = true;
    }

    int res = -1;
    REP(i, n){
      if ((know[i] & leak) == leak) {
        if (res != -1) {
          res = -1;
          break;
        }
        res = i + 1;
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3088
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int oddcount = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (a[i] % 2 == 1) {
				oddcount++;
			}
		}
		if (oddcount % 2 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 50580
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}




int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    if(a>=10 || b>=10){
        cout<<-1<<endl;
    }
    else cout<<a*b<<endl;
    return 0;
    }


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

struct UnionFind {
	vector<int> p;
	
	UnionFind(int n) : p(n) {
		for (int i = 0; i < n; i++) p[i] = i;
	}
	
	int root(int x) {
		return p[x] == x ? x : p[x] = root(p[x]);
	}
	
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) p[x] = y;
	}
	
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	rep(i, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0) uf.unite(x, y);
		if (com == 1) {
			if (uf.same(x, y)) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>

using namespace std;
bool finish(vector<int> a){
    if(a[0] == a[1] && a[1] == a[2]){
        return true;
    }else{
        return false;
    }
}

int main(){

    vector<int> ABC(3, 0);
    cin >> ABC[0] >> ABC[1] >> ABC[2];

    std::sort(ABC.begin(),ABC.end());
    int i = 0;
    for(;;){
        if(finish(ABC) == true){
            cout << i;
            return 0;
        }
        if(!(ABC[1] == ABC[2])){
            ABC[0]++;
            ABC[1]++;
        }else{
            ABC[0] += 2;
            if(ABC[0] >= ABC[1]){
                std::sort(ABC.begin(),ABC.end());
            }
        }
        i++;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long a;
    int ans = 99999999;
    for(int i=0;i<n;i++){
        cin >> a;
        int tmp = 0;
        while(a%2 == 0){
            tmp++;
            a/=2;
        }
        if(tmp<ans)ans=tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
  	int i, j, n;
  
  	scanf( "%d", &n );
  
  	double v[n], tmp, sum;
  
  	for( i = 0; i < n; i++ ) { 
      scanf( "%lf", &v[i] );
    }
  
  	for( i = 0; i < (n-1); i++ ) {
      	for( j = i+1; j < n; j++ ) {
     		if( v[i] > v[j] ) {
         		tmp = v[i];
          		v[i] = v[j];
          		v[j] = tmp;
        	}
        }
    }
  
  	sum = v[0];
  	for( i = 1; i < n; i++ ) {
     	sum = ( sum + v[i] ) / 2.0;
    }
  	printf( "%lf", sum );
  
 	return 0; 
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) 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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> A(n + 2, 0), B(m + 2, 0);
    rep(i, n){
        ll a;
        cin >> a;
        A[i + 1] = A[i] + a;
    }
    rep(i, m){
        ll b;
        cin >> b;
        B[i + 1] = B[i] + b;
    }
    A[n + 1] = LINF;
    B[m + 1] = LINF;
    int ans = 0;
    rep(i, n + 1) {
        if (A[i] > k) break;
        int books = i + upper_bound(all(B), k - A[i]) - B.begin() - 1;
        chmax(ans, books);
    }
    cout << ans << endl;
}

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


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

using namespace std;
#define int long long
#define inf 999999999999999999
#define N 666666
int arr[N];
int n,m,x;
int c[N];
int mp[666][666];
int t[N];
signed main(){
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++) cin>>mp[i][j];
	}
	int ans=inf;
	for(int i=0;i<(1<<n);i++){
		int s=0;
		for(int j=0;j<=400;j++) t[j]=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				s+=c[j];
				for(int k=1;k<=m;k++) t[k]+=mp[j][k];
			}
		}
		int f=1;
		for(int j=1;j<=m;j++){
			if(t[j]<x){
				 f=0;
				break;
			}
		}
		if(f) ans=min(ans,s);
	}
	if(ans==inf) cout<<"-1";else cout<<ans;
	return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int dp[MAX][4];
ll pre[MAX][101];
int main(){
	ull n , d;
	ull a, b;
	cin>>a>>b;
	ull p=3*2019;	
	ull mn=INT_MAX;
	for(ull i=a;i<=a+p;i++){
		for(ull j=i+1;j<=a+p;j++){
			if((i>=a&&a<=b)&&(j>=a&&j<=b)){
				mn=min((i*j)%2019 , mn);
			}
		}
	}
	cout<<mn;


}

Measured memory_bytes: 6144
n, l = list(map(int, input().split()))
t = []
for i in range(n):
    t.append(l + i)
sum_t = sum(t)
abs_diff = float('inf')
idx = 0
for i in range(n):
    if abs(sum_t - (sum(t[:i]) + sum(t[i + 1:]))) <= abs_diff:
        abs_diff = abs(sum_t - (sum(t[:i]) + sum(t[i + 1:])))
        idx = i
del t[idx]
print(sum(t))


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

int main()
{
  string S;
  int Q;
  deque<char> que;
  
  cin>>S;
  cin>>Q;
  for(char c: S)  que.push_back(c);

  int rev=0;
  while(Q--){
    int t;  cin>>t;
    if(t==1)  rev = 1 - rev;
    else{
      int f;  char c;
      cin>>f>>c;
      f--;
      if(rev^f)  que.push_back(c);
      else  que.push_front(c);
    }
  }
  if(rev)  reverse(que.begin(), que.end());
  for(auto c: que)  cout<<c;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int temp1,temp2;
int x1,x2,y1,y2,x3,y3,x4,y4;
int deal1()
{
	if(temp1*temp1+temp2*temp2>0)
	{
		x3=x2-temp2;
		y3=y2+temp1;
	}
	else
	{
		x3=x2+temp2;
		y3=y2-temp1;
	}
	return 0;
}
int deal2()
{
	if(temp1*temp1+temp2*temp2>0)
	{
		x4=x3-temp2;
		y4=y3+temp1;
	}
	else
	{
		x4=x3+temp2;
		y4=y3-temp1;
	}
	return 0;
}
int main()
{	
	cin>>x1>>y1>>x2>>y2;
	 temp1=x2-x1;
	 temp2=y2-y1;
	deal1();
	temp1=x3-x2;
	temp2=y3-y2;
	deal2();
	cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

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

struct apple {
    ll val;
    char c;
} app[3*MAXN];

bool compare(apple s, apple t)
{
    return s.val > t.val;
}

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	
	for(int i=0; i<a; i++)
	{
	    cin>>app[i].val;
	    app[i].c = 'r';
	}
	for(int i=0; i<b; i++)
	{
	    cin>>app[a+i].val;
	    app[a+i].c = 'g';
	}
	for(int i=0; i<c; i++)
	{
	    cin>>app[a+b+i].val;
	    app[a+b+i].c = 'c';
	}
	sort(app,app+a+b+c,compare);
	/*for(int i=0; i<a+b+c; i++)
	    cout<<app[i].val<<' '<<app[i].c<<endl;*/
	ll ctred = 0, ctgreen = 0, ctcless = 0,ans = 0;
	for(int i=0; i<a+b+c; i++)
	{
	    if(ctred+ctgreen+ctcless == x+y)
	        break;
	    if(app[i].c == 'r')
	    {
	        if(ctred<x)
	        {
	            ctred++;
	            ans+=app[i].val;
	        }
	    }
	    else if(app[i].c == 'g')
	    {
	        if(ctgreen<y)
	        {
	            ctgreen++;
	            ans+=app[i].val;
	        }
	    }
	    else
	    {
	        ctcless++;
	        ans+=app[i].val;
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4992
#encoding:utf-8 No.0005 2014.9.29
def lcm(a,b) #最小公倍数を求めるメソッド
 i = 1
 while true
  if (a*i)%b == 0
   break
  end
 i += 1
 end
 return a*i
end

def gcd(a,b) #最大公約数を求めるメソッド
 if a > b
  x,y = a,b
 else
  x,y = b,a
 end
 r = x%y

 until r == 0
  x = y
  y = r
  r = x%y
 end

 return y
end

numbers = []
while gets
 data = $_.split

 2.times do |i|
  data[i] = data[i].to_i
 end

 numbers.push data
end

i = 0
while i < numbers.length
 puts "#{gcd(numbers[i][0],numbers[i][1])} #{lcm(numbers[i][0],numbers[i][1])}"
 i += 1
end

Measured memory_bytes: 6112
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)  return (a / b); return (a / b + 1);}
inline ll binlen(ll n) {
    ll c = 0;
    while (n > 0)
        ++c , n /= 2;
    return c;
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}



signed main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    fast
    ll n;
    string s;
    cin >> s;
    n = s.length();
    if (s[n - 1] == 's')
        s += "es";
    else
        s += "s";
    cout << s << END;



// #ifndef ONLINE_JUDGE
//     cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}




int main() {
	ll N,K,G,M;
	cin >> N >> K;
	ll A;
	cin >> A;
	G = A;
	M = A;
	string an = "POSSIBLE";
	rep(i, N-1) {
		cin >> A;
		G = gcd(G, A);
		M = max(M, A);
	}
	if (K % G != 0 || K > M) {
		an = "IM" + an;
	}
	cout <<an << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
const int mod=924844033;
int n,f[maxn],a[maxn<<2],b[maxn<<2],c[maxn<<2],r[maxn<<2],G[40][2];
int fac[maxn],inv[maxn],siz[maxn],head[maxn],to[maxn<<1],nxt[maxn<<1],tot;

inline int read(){
	register int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return (f==1)?x:-x;
}

inline int fpow(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) ret=1ll*ret*a%mod;
	return ret;
}

inline void Gpre(){
	for(int len=1,l=0;len<=mod;len<<=1,l++){
		G[l][0]=fpow(5,(mod-1)/len);
		G[l][1]=fpow(G[l][0],mod-2);
	}
}

inline void NTT(int *f,int n,int op){
	for(int i=0;i<n;i++)
		if(i<r[i]) swap(f[i],f[r[i]]);
	int buf,tmp,x,y;
	for(int len=1,l=1;len<n;len<<=1,l++){
		tmp=(op==1)?G[l][0]:G[l][1];
		for(int i=0;i<n;i+=len<<1){
			buf=1;
			for(int j=0;j<len;j++){
				x=f[i+j];y=1ll*buf*f[i+j+len]%mod;
				f[i+j]=(x+y)%mod;f[i+j+len]=(x-y+mod)%mod;
				buf=1ll*buf*tmp%mod;
			}
		}
	}
	if(op==1) return ;
	int inv=fpow(n,mod-2);
	for(int i=0;i<n;i++) f[i]=1ll*f[i]*inv%mod; 
}

inline void Mul(int *A,int *B,int *C,int n,int m){
	int lim;
	for(lim=1;lim<(n+m);lim<<=1);
	for(int i=0;i<lim;i++) r[i]=(r[i>>1]>>1)|((i&1)?(lim>>1):0);
	NTT(A,lim,1);NTT(B,lim,1);
	for(int i=0;i<lim;i++) C[i]=1ll*A[i]*B[i]%mod;
	NTT(C,lim,-1);
	for(int i=n;i<lim;i++) A[i]=0;
	for(int i=m;i<lim;i++) B[i]=0;
}

inline void addedge(int x,int y){
	to[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}

void dfs(int x,int f){
	siz[x]=1;
	for(int i=head[x],y;i;i=nxt[i]){
		y=to[i];
		if(y==f) continue;
		dfs(y,x);siz[x]+=siz[y];
	}
}

inline int C(int n,int m){
	if(n<m) return 0;
	return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
	Gpre();
	n=read();
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=n;i++) inv[i]=1ll*inv[i]*inv[i-1]%mod;
	int x,y;
	for(int i=1;i<n;i++){
		x=read(),y=read();
		addedge(x,y);addedge(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++) c[siz[i]]++;
	for(int i=0;i<=n;i++) a[i]=1ll*c[i]*fac[i]%mod;
	for(int i=0;i<=n;i++) b[i]=inv[i];
	reverse(a,a+n+1);
	Mul(a,b,c,n+1,n+1);
	reverse(c,c+n+1);
	for(int i=1;i<=n;i++) f[i]=(f[i]-1ll*c[i]*inv[i]%mod+mod)%mod;
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++) c[n-siz[i]]++;
	for(int i=0;i<=n;i++) a[i]=1ll*c[i]*fac[i]%mod;
	for(int i=0;i<=n;i++) b[i]=inv[i];
	reverse(a,a+n+1);
	Mul(a,b,c,n+1,n+1);
	reverse(c,c+n+1);
	for(int i=1;i<=n;i++) f[i]=(f[i]-1ll*c[i]*inv[i]%mod+mod)%mod;
	for(int i=1;i<=n;i++) f[i]=(f[i]+1ll*(n+1)*C(n,i)%mod)%mod;
	for(int i=1;i<=n;i++) printf("%d\n",f[i]);
	return 0;
}

Measured memory_bytes: 29312
// inputに入力データ全体が入る
function Main(input) {
    "use strict";
    // 1行目がinput[0], 2行目がinput[1], …に入る
    const data = input.trim();
    const input_ = data.split("\n");
    const input_num = input_[1].split(" ").map(s => parseInt(s));
    let current = 1;
    let count = 0;
    for (let i = 0; i < input_[0]; ++i) {
        if (input_num[i] === current) {
            current++;
        } else {
            count++;
        }
    }
    if (count === parseInt(input_[0])) {
        console.log(-1);
    } else {
        console.log(count);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 23884
// c lib
#include <cstdio>
#include <cstdlib>
#include <cmath>

// container
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>

// Convenience
#include <algorithm>
#include <functional>

// IO
#include <iostream>

using namespace std;

void answer(int man, int gosen, int sen) {
  cout <<  man << " " << gosen << " " << sen << endl;
}

void impossible() {
  cout << "-1 -1 -1" << endl;
}

int main() {
  auto n = 0;
  auto y = 0;
  
  cin >> n >> y;

  for (int m = y / 10000; m <= n && m >= 0; m--) {
    auto gh = n - m + 1;
    auto gl = 0;
    while (1) {
      auto gc = (gh + gl) / 2;

      auto rem_n = n - m - gc;
      auto rem_y = y - m * 10000 - gc * 5000;
      auto rem_ny = rem_n * 1000;

      if (rem_y > rem_ny) {
        if (gl == gc) break;
        gl = gc;
      }
      else if (rem_y < rem_ny) {
        if (gh == gc) break;
        gh = gc;
      }
      else {
        answer(m, gc, rem_n);
        return 0;
      }
    }
  }

  impossible();
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}
template < typename T, typename U >
ostream &operator<<(ostream &os, const pair< T, U > &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c, i;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int x;
	cin >> x;
	cout << (1 - x) << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    ll a, b, c; cin >> a >> b >> c;
    ll x, y; cin >> x >> y;
    ll n = max(x, y);
    ll ans = 0;
    ll ans_min = INFINITY;
    for(int i = 0; i <= n; i++){
        ll _x = max(0LL, x - i);
        ll _y = max(0LL, y - i);
        ans = 2 * c * i + a * _x + b * _y;
        ans_min = min(ans, ans_min);
    }
    cout << ans_min << endl;
}

Measured memory_bytes: 256
def is_prime(n):
    if n<4:
        return True
    else:
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                return False
        return True

X=int(input())
while True:
    if is_prime(X):
        print(X)
        break
    else:
        X+=1

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());

        var ans = 1L;

        var sieve = new SieveOfEratosthenes(N);

        for (int n = 2; n <= N - 1; n++)
            ans += sieve.GetFactors(n).RunLengthEncode().Select(x => x.length + 1).Aggregate((s, e) => s * e);

        WriteLine(ans);
    }
}

static class RunLengthEncoderExtensions
{
    public static IEnumerable<(T element, int length)> RunLengthEncode<T>(this IEnumerable<T> collection)
    {
        var isFirst = true;
        var prevElement = default(T);
        var length = 0;

        foreach (var element in collection)
        {
            if (!isFirst && !EqualityComparer<T>.Default.Equals(prevElement, element))
            {
                yield return (prevElement, length);
                length = 0;
            }
            else
                isFirst = false;

            length++;
            prevElement = element;
        }
        if (!isFirst)
            yield return (prevElement, length);
    }

    public static IEnumerable<T> RunLengthDecode<T>(this IEnumerable<(T element, int length)> rle) => rle.SelectMany(t => Enumerable.Repeat(t.element, t.length));
}

class SieveOfEratosthenes
{
    public int MaxN { get; }

    public IEnumerable<int> Primes => primes;
    private readonly List<int> primes = new List<int>();
    private readonly int[] factors;

    public SieveOfEratosthenes(int maxN)
    {
        MaxN = maxN;
        factors = new int[maxN + 1];
        factors[0] = factors[1] = -1;

        for (int i = 2; i <= maxN; i++)
        {
            if (factors[i] != 0)
                continue;

            primes.Add(i);

            for (int j = i; j <= maxN; j += i)
                factors[j] = i;
        }
    }

    public bool IsPrime(int n)
    {
        if (MaxN < n)
            throw new ArgumentException();

        if (n < 2)
            return false;

        return factors[n] == n;
    }

    public IEnumerable<int> GetFactors(int n)
    {
        if (MaxN < n)
            throw new ArgumentException();

        var oppositeFactors = new List<int>();
        while (1 < n)
        {
            oppositeFactors.Add(factors[n]);
            n /= factors[n];
        }

        for (int i = oppositeFactors.Count - 1; i >= 0; i--)
            yield return oppositeFactors[i];
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

int main(){
  int N;
  cin >> N;
  vector<int> card_num(N);
  for(int i=0;i<N;i++){
    cin >> card_num.at(i);
    for(int j=i;j>0;j--){
      if(card_num.at(j-1)<card_num.at(j)){
        int tmp = card_num.at(j);
        card_num.at(j) = card_num.at(j-1);
        card_num.at(j-1)=tmp;
      }else{
        break;
      }
    }
  }
  int score = 0;
  for(int i=0;i<N;i++){
    score += (i%2==0)*card_num.at(i)-(i%2==1)*card_num.at(i);
  }
  cout << score << endl;
  return 0;
}


Measured memory_bytes: 256
from decimal import *
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

def solve(A, B, V, W, T):
    if A<B:
        la = A+V*T
        lb = B+W*T
        return la>=lb
    else:
        la = A-V*T
        lb = B-W*T
        return la<=lb





A, V = rrm()
B, W = rrm()
T = rri()
ans = solve(A, B, V, W, T)
if ans:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 73432
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
	// your code goes here
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 ll t,n,i,j,s=0;
	     cin>>n;
	     vector<int> ptr(n);
	vector<int> res;
	
	for(i = 0; i < n; i++)
	{
	    cin>>ptr[i];
	}
	
	sort(ptr.begin(), ptr.end(), greater<int>());
	
	res.push_back(ptr[0]);
	
	for(i = 1; i < n; i++)
	{
	    res.push_back(ptr[i]);
	    res.push_back(ptr[i]);
	}
	
	for(i = 0; i < n-1; i++)
	{
	    s += res[i];
	}
	
	cout<<s;
	return 0;
}


Measured memory_bytes: 6088
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

type interface1 interface {
	Len() int           // 要素数
	Less(i, j int) bool // i 番目の要素が j 番目の要素より小さくなる条件
	Swap(i, j int)      // i 番目の要素と j 番目の要素を入れ替えるロジック
}

func main() {
	var numStr string
	var numSlice []int
	numSlice = make([]int, 3, 3)
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		numStr = sc.Text()
	}
	numStrArray := strings.Split(numStr, " ")

	for i, valueStr := range numStrArray {
		value, _ := strconv.Atoi(valueStr)
		numSlice[i] = value
	}

	sort.Sort(sort.IntSlice(numSlice))

	var cnt int

	for i := 0; i < 3; i++ {
		value := numSlice[i]
		for j := i + 1; j < 3; j++ {
			if value == numSlice[j] {
				cnt++
			}
		}
	}

	if cnt == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(){
    while(1){
        int a,b;
        cin>>a>>b;
        if(!a&&!b)return 0;
        if(a<=b)cout<<a<<" "<<b<<endl;
        else cout<<b<<" "<<a<<endl;
    }
}


Measured memory_bytes: 3084
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int m = parseInt(sc.next());
		long[] a = new long[n];
		long[] b = new long[n];
		for (i = 0; i < n; i++) {
			a[i] = parseLong(sc.next());
			b[i] = parseLong(sc.next());
		}
		long[] c = new long[m];
		long[] d = new long[m];
		for (i = 0; i < m; i++) {
			c[i] = parseLong(sc.next());
			d[i] = parseLong(sc.next());
		}
		sc.close();
		int[] xy = new int[n];
		for (i = 0; i < n; i++) {
			long mn = 400000000L;
			for (j = 0; j < m; j++) {
				long ma = abs(a[i]-c[j])+abs(b[i]-d[j]);
				if(ma<mn) {
					mn = ma;
					xy[i]=j+1;
				}
			}
		}
		PrintWriter pw = new PrintWriter(out);
		for(i=0;i<n;i++) {
			pw.println(xy[i]);
		}
		pw.flush();
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n;
    cin>>n;
    string str;
    cin>>str;
    ll red=0,white=0;
    for(int i=0;i<n;i++){
        if(str[i]=='R') red++;
        else white++;
    }
    ll ans1=0,ans2=0;
    for(int i=0;i<red;i++){
        if(str[i]=='W') ans1++;
    }
    for(int i=red;i<n;i++){
        if(str[i]=='R') ans2++;
    }
    ll ans=max(ans1,ans2);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[1],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

long long o[111][55][55];
long long l[111][111];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> s[222][22];
priority_queue<long long,vector<long long>,greater<long long> > q;
//queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

//string r,r1;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}

void f(int n)
{
    //printf("@@@%d\n",n);
    int s[55][55];
    memset(s,0,sizeof(s));
    for(int t=1;t<=a;t++)
        for(int w=1;w<=a;w++)
        for(int h=1;h<=a;h++)
        s[t][h]+=o[n][t][w]*l[w][h]%mod,s[t][h]%=mod;
    for(int t=1;t<=a;t++)
        for(int w=1;w<=a;w++)
        l[t][w]=s[t][w];
}

int main()
{
    scanf("%d %lld",&a,&y);
    for(int t=1;t<=a;t++)
        for(int w=1;w<=a;l[t][w]=o[0][t][w],w++)
        scanf("%lld",&o[0][t][w]);

    for(int t=1;t<=100;t++)
    {
        f(t-1);
        for(int n=1;n<=a;n++)
            for(int m=1;m<=a;m++)
            o[t][n][m]=l[n][m];
    }
    memset(l,0,sizeof(l));
    for(int t=1;t<=a;t++)
        l[t][t]=1;
    for(long long i=1,h=0;i<=y;i*=2,h++)
        if((i&y))
        f(h);
    for(int t=1;t<=a;t++)
        for(int w=1;w<=a;w++)
        //printf("%lld ",l[t][w]);
        z+=l[t][w],z%=mod;
    printf("%lld",z);
}





Measured memory_bytes: 2688
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >>a >> b>> c;
    cout << min({abs(a - b) + abs(b - c), abs(a - c) + abs(c - b), abs(b - a) + abs(a - c), abs(b - c) + abs(c - a), abs(c - a) + abs(a - b), abs(c - b) + abs(b - a)}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fio ios_base::sync_with_stdio(0), cin.tie(0);
typedef long long ll;   

int main(){
    fio;
    vector<int> v(5);
    for(int i = 0; i < 5; i++){
        cin>>v[i];
        if(v[i] == 0){
            cout<<i+1;
            break;
        }
    }
}


Measured memory_bytes: 3560
n, result = map(int, input().split())

for i in range(n + 1):
  for j in range(n - i + 1):
    if 10000 * i + 5000 * j + 1000 * (n - i - j) == result:
      print(i, j, n - i - j)
      exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N = int(input())
Als = inpl()

Als.sort(reverse=True)

if N %2 !=0:
    rank = int((N-1)/2)
    sm = 0
    for j in range(1,rank):
        sm += Als[j]
    print(Als[0] + sm*2 + Als[rank])
else:
    rank = int(N/2)
    sm = 0
    for j in range(1,rank):
        sm += Als[j]
    print(Als[0] + sm*2)


Measured memory_bytes: 33116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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



	int N;
	cin >> N;
	int T[200] = {}, v[200] = {};

	rep1(i, N) {
		cin >> T[i];
		T[i] *= 2;
		T[i] += T[i - 1];
	}
	rep1(i, N) cin >> v[i];


	double V[50000];
	rep(i, 50000) V[i] = 100;

	rep(i, N) {
		for (int ii = T[i]; ii <= T[i + 1]; ii++) if (V[ii] > v[i + 1]) V[ii] = v[i + 1];
	}

	rep(i, N + 1) {
		for (int ii = T[i]; ii <= T[N]; ii++) {
			if (V[ii] > 0.5 * (ii - T[i]) + v[i]) V[ii] = 0.5 * (ii - T[i]) + v[i];
		}
		for (int ii = T[i]; ii >= 0; ii--) {
			if (V[ii] > 0.5 * (T[i] - ii) + v[i + 1]) V[ii] = 0.5 * (T[i] - ii) + v[i + 1];
		}
	}

	double kotae = 0;
	rep(i, T[N]) kotae += V[i] / 2;

	//ええ・・・もしやcoutって実数だと上6桁くらいであきらめるの・・・？
	cout << fixed << kotae << endl;
	//これで小数点以下6桁？

	Would you please return 0;
}

Measured memory_bytes: 640
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d


def main():
    n = int(input())
    data = [chr(ord("a") + i) for i in range(10)]
    generate("a", 0, n, data)


def generate(cur, max_i, n, data):
    if len(cur) == n:
        print(cur)
        return
    for i in range(max_i + 2):
        generate(cur + chr(ord("a") + i), max(max_i, i), n, data)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
s = input()
stack1 = []
stack2 = []
for i in range(len(s)):
    if s[i] == '\\':
        stack1.append(i)
    elif s[i] == '/' and stack1:
        j = stack1.pop()
        area = i-j
        while stack2:
            if stack2[-1][0] < j:
                break
            else:
                area += stack2.pop()[1]
        stack2.append((j,area))
ans = list(stack2[i][1] for i in range(len(stack2)))
print(sum(ans))
if ans:
    print(len(ans),' '.join(map(str,ans)))
else:
    print(0)


Measured memory_bytes: 6204
#include<stdio.h>
#include<math.h>

    int main(){

        long long n, i, j = 0, a, b, sum = 0, dig_sum, dig, rem;
        scanf("%lld %lld %lld", &n, &a, &b);
        for(i=1;i<=n;i++){
                dig = i;
                dig_sum = 0;
            while(dig != 0){
                rem = dig%10;
                dig_sum = dig_sum + rem;
                dig = dig/10;
            }
            if(dig_sum>=a && dig_sum<=b){
                sum = sum + i;
            }
        }
        printf("%lld", sum);
        return 0;
    }





Measured memory_bytes: 128
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> asum0(N), asum1(N + 1);
	asum1[0] = 0;
	int ap = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		ap = asum0[i] = a + ap;
	}
	ap = 0;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		ap = asum1[i + 1] = a + ap;
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans = max(ans, asum0[i] + asum1[N] - asum1[i]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool ng[10];
signed main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int d;cin>>d;
		ng[d]=true;
	}
	for(;;n++){
		stringstream ss;
		ss<<n;
		string s=ss.str();
		bool ok=true;
		for(int j=0;j<s.size();j++) if(ng[s[j]-'0']) ok=false;
		if(ok){
			cout<<n<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
 
class Main{
 
    public static void main(String[] args) throws IOException{
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int len = Integer.parseInt(br.readLine());
        int[] array = new int[len];
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str, " ");
 
        for(int i = 0; i < len; i++){
            array[i] = Integer.parseInt(st.nextToken());
        }
 
        for(int i = len - 1; i >= 0; i--){
            System.out.print(array[i]);
            if(i != 0){
                System.out.print(" ");
            }else{
                System.out.print("\n");
            }
        }
 
    }
}

Measured memory_bytes: 24200
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

map<char, int> mp;
char s[maxn];

int main()
{
	scanf("%s", s+1);
	for (int i = 1; s[i]; ++i)
		++mp[s[i]];
	for (map<char, int>::iterator p = mp.begin(); p != mp.end(); ++p)
	{
		if (p->second % 2) 
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int dp[51][51];

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


void check(int i,int j,int h,int w){
    dp[i][j]=2;
    for(int a=0;a<8;a++){
        int x=i+dx[a];
        int y=j+dy[a];
        if(x>=0&&x<h&&y>=0&&y<w){
            if(dp[x][y]==1){
                check(x,y,h,w);
            }
        }
    }
}

int main(){
    int h,w,cou;
    while(cin >> w >> h,w){
        cou=0;
        REP(i,h)REP(j,w)cin >> dp[i][j];
        REP(i,h){
            REP(j,w){
                if(dp[i][j]==1){
                    cou++;
                    check(i,j,h,w);
                }
            }
        }
        cout << cou << endl;
    }
}



Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    ll numOfR = 0, numOfG = 0, numOfB = 0;

    rep(i, n)
    {
        if (s[i] == 'R')
        {
            numOfR++;
        }
        else if (s[i] == 'G')
        {
            numOfG++;
        }
        else
        {
            numOfB++;
        }
    }

    ll numOfNotStisfingCondition = 0;
    rep(i, n - 2) REP(j, i + 1, n - 1)
    {
        int k = 2 * j - i;
        if (k >= n)
            continue;
        if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k])
            numOfNotStisfingCondition++;
    }

    ll res = numOfR * numOfG * numOfB - numOfNotStisfingCondition;

    cout << res << "\n";
}

Measured memory_bytes: 3660
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = [0]+list(mapint())
from itertools import accumulate
from collections import Counter

cAs = list(accumulate(As))
c = Counter(cAs)
ans = 0
for num, c in c.most_common():
    if c<2:
        break
    ans += c*(c-1)//2
print(ans)

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

#define ing long long

signed main(){
	string str;
	
	int n=0, m=0, ans=0;
	
	int a=0, b=0,c=0;
	cin>>n;
	
	
	//cin>>string;
	//for(int i = 1; i <= n; i++){}
	
	if(n < 1200)cout<<"ABC"<<endl;
	else if(n < 2800)cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
	
	//cout<<ans<<endl;
	//cout<<(n ?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import copy


def solve(N: int, X: "List[int]"):
    XS =  copy.deepcopy(X)
    XS.sort()

    mi = (len(XS)+1)//2

    for x in X:
        if x < XS[mi]:
            print(XS[mi])
        else:
            print(XS[max(mi-1,0)])

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 31820
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C = map(int, raw_input().split())
print min(A + B, B + C, C + A)

Measured memory_bytes: 2812