akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	if (k > (n - 1) * (n - 2) / 2) {
		cout << -1 << endl;
	}
	else {
		cout << n - 1 + (n - 1) * (n - 2) / 2 - k << endl;

		for (int i = 0; i < n - 1; ++i) {
			cout << 1 << " " << i + 2 << endl;
		}

		int remain = (n - 1) * (n - 2) / 2 - k;
		int start = n;

		while (1) {
			bool flag = 0;
			for (int i = 2; i < start; ++i) {
				if (!remain) {
					flag = 1;
					break;
				}
				cout << start << " " << i << endl;
				remain--;
			}

			if (flag || !remain) {
				break;
			}
			start--;
		}
	}


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,K,N,P;
	int A[1000];
	scanf("%d",&N);
	for(i=1;i<=N;i++){
	scanf("%d %d",&K,&P);
	if(K%P !=0){
		A[i]=K%P;
	}
	else{
		A[i]=P;
	}
	}
	for(i=1;i<=N;i++){
		printf("%d\n",A[i]);
	}
	return 0;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    yes();
  } else {
    no();
  }
}

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

int main(){
    int n;
    cin >> n;
    int k = 0, l = 0, m = 0;
    rep(i,n) {   
        int a;
        cin >> a;
        if(a == 1) k++;
        else if(a == 2) l++;
        else m++;
    }
    vector<vector<vector<double>>> dp(n+2,vector<vector<double>>(n+2,vector<double>(n+2,0.0)));
    rep(z,n+1){
        rep(y,n+1){
            rep(x,n+1){
                if(x+y+z > n) break; 
                if(x+y+z != 0) {
                    double a = (double)x, b = (double)y, c = (double)z, d = (double)n; 
                    if(x) dp[x][y][z] += a*dp[x-1][y][z];
                    if(y) dp[x][y][z] += b*dp[x+1][y-1][z];
                    if(z) dp[x][y][z] += c*dp[x][y+1][z-1];
                    dp[x][y][z] += d;
                    dp[x][y][z] /= (a+b+c);
                }
            }
        }
    }
    printf("%.12f\n",dp[k][l][m]);
    return 0;
}

Measured memory_bytes: 219776
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct edge {
    int to;
    ll cost;
};

vector<ll> dijkstra(int s, int n, vector<vector<edge>> &g ) {
    vector<ll> cost(n, 1e16);
    cost[s] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    que.push({0LL, s});
    while(1) {
        if ( que.empty() ) break;
        pair<ll, int> p = que.top(); que.pop();
        for ( auto v: g[p.second]) {
            ll next_cost = p.first + v.cost;
            if ( next_cost > cost[v.to] ) continue;
            cost[v.to] = next_cost;
            que.push({cost[v.to], v.to});
        }
    }
    return cost;
}

int main(){
    int n;
    cin >> n;
    vector<vector<edge>> g(n);
    rep(i, n-1) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].push_back((edge){b, c});
        g[b].push_back((edge){a, c});
    }
    int q, k;
    cin >> q >> k;
    --k;
    auto cost = dijkstra(k, n, g);
    vector<ll> ans(q);
//    cout << "test2" << endl;
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        ans[i] = cost[x] + cost[y];
    }

//    for ( auto tmp_cost : cost ) {
//        cout << tmp_cost << endl;
//    }

    rep(i, q) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int count = 0;
    if(N > 1) {
        count += (N * (N - 1)) / 2;
    }
    if(M > 1) {
        count += (M * (M - 1)) / 2;
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
// #include <fstream>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long mod = 1e9 + 7;
const int INF32 = INT32_MAX;

int main()
{
    std::ios::sync_with_stdio(false);
	std::cin.tie(0);
    
    int n; std::cin >> n;
    std::vector<int> a(n);
    std::map<long long int, int> mp;
    long long int ans = 0;
    for(auto &i : a)
    {
        std::cin >> i;
        ans += mp[i];
        mp[i]++;
    }
    for(auto i : a)
    {
        int ret = mp[i] - 1;
        std::cout << ans - ret << std::endl;
    }
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
    int n,m;
    map<string,int> s;
    cin >> n;
    rep(i,n){
        string str;
        cin >> str;
        s[str]++;
    }
    cin >> m;
    rep(i,m){
        string str;
        cin >> str;
        s[str]--;
    }
    int res = 0;
    for(auto m:s){
      chmax(res,m.second);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const ll MOD = 998244353;
 
ll mpow(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
 
ll minv(ll a) {
    return mpow(a, MOD - 2);
}

int n, s;
ll val[3005];
 
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> s;
    
    vector<int> a(n);
    for (auto& i : a) {
        cin >> i;
        
        for (int j = s - i; j >= 0; --j) {
            val[j + i] += val[j] * minv(2) % MOD;
            val[j + i] %= MOD;
        }

        val[i] += mpow(2, n - 1);
        val[i] %= MOD;
    }
    cout << val[s] % MOD;
}


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

#define ll long long int
const ll mod = 1000000007;
string k;
int n,d;
ll dp[101][10050][2];

ll rec(int rem, int idx, int flag){
    
    if(idx == n){
        return rem==0?1:0;
    }
    if(dp[rem][idx][flag]!=-1)return dp[rem][idx][flag];
    int l=9,f;
    ll cnt=0;
    if(!flag)l=k[idx]-'0';
    for(int i=0;i<=l;i++){
        f=flag;
        if(i<k[idx]-'0')f=1;
        cnt=(cnt+rec((rem+i)%d,idx+1,f))%mod;
        
    }
    return dp[rem][idx][flag]=cnt;
}


int main(){
   memset(dp,-1,sizeof(dp));
   
   cin>>k>>d;
   n=k.length();
    ll ans=rec(0,0,0);
    ans+=mod-1;
    ans%=mod;
    cout<<ans;
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 16896
package main

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

var ary []int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	for _, v := range strings.Split(strings.TrimSpace(sc.Text()), " ") {
		n, err := strconv.Atoi(v)
		if err == nil {
			ary = append(ary, n)
		} else {
			switch v {
			case "+":
				p1 := pop()
				p2 := pop()
				ary = append(ary, p2+p1)
			case "-":
				p1 := pop()
				p2 := pop()
				ary = append(ary, p2-p1)
			case "*":
				p1 := pop()
				p2 := pop()
				ary = append(ary, p2*p1)
			}
		}
	}
	fmt.Println(ary[0])
}

func pop() int {
	i := len(ary) - 1
	n := ary[i]
	ary = ary[:i]
	return n
}



Measured memory_bytes: 1116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    vector<string> si = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    int ans=7;
    cin >> s;
    rep(i,7){
        if (si[i] == s){
            ans -= i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{
    ll n;
    cin >> n;
    vector<ll> v;
    ll ans = 1e18;
    for (ll i = 1; (i * i)<= n; i++)
    {
        if (n % i == 0)
        {
            ans = min(ans, i + (n / i) - 2);
        }
    }
    c(ans)
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())

x = abs(x)

if x == 0:
    if k % 2 == 0:
        print(0)
    else:
        print(d)
    exit()

if x - k*d >= 0:
    print(abs(x) - k*d)
else:
    k -= (x//d)
    x -= (x//d)*d
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))

Measured memory_bytes: 9144
#include <iostream>
#include <utility>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int main()
{
    int h, w, cx, cy, dx, dy;
    cin >> h >> w >> cx >> cy >> dx >> dy;
    cx--, cy--, dx--, dy--;
    int mx[h][w];
    rep(i, h)
    {
        rep(j, w)
        {
            char c;
            cin >> c;
            mx[i][j] = c == '.' ? N : -1;
        }
    }

    deque<pair<int, int>> dq;
    dq.push_front({cx, cy});
    mx[cx][cy] = 0;
    int tx[] = {-1, 1, 0, 0};
    int ty[] = {0, 0, -1, 1};
    while (!dq.empty())
    {
        pair<int, int> curr = dq.front();
        dq.pop_front();
        int x = curr.first;
        int y = curr.second;
        for (int i = 0; i < 4; ++i)
        {
            int nx = x + tx[i];
            int ny = y + ty[i];
            if (nx > -1 && nx < h && ny > -1 && ny < w &&
                mx[nx][ny] != -1 && mx[nx][ny] > mx[x][y])
            {
                mx[nx][ny] = mx[x][y];
                dq.push_front({nx, ny});
            }
        }

        for (int i = x - 2; i <= x + 2; ++i)
        {
            for (int j = y - 2; j <= y + 2; ++j)
            {
                if (i > -1 && i < h && j > -1 && j < w &&
                    mx[i][j] != -1 && mx[i][j] > mx[x][y] + 1)
                {
                    mx[i][j] = mx[x][y] + 1;
                    dq.push_back({i, j});
                }
            }
        }
    }
    if (mx[dx][dy] == N)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << mx[dx][dy] << endl;
    }
}


Measured memory_bytes: 7536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		
		int[] npoints = new int[n];
		int[] a = new int[q];
		
		for(int i=0;i<n;i++){
    		npoints[i] = k-q;
		}
		
		for(int i=0;i<q;i++){
		    a[i] = sc.nextInt();
		    npoints[a[i]-1]++;
		}
		
		for(int i=0;i<n;i++){
		    if(npoints[i]>0){
		        System.out.println("Yes");
		    }else{
		        System.out.println("No");
		    }
		}
	}
}


Measured memory_bytes: 60340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int main(){
	int n;scanf("%d",&n);ll ans=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0) continue;ans+=i;
	}printf("%lld\n",ans);
}

Measured memory_bytes: 3828
#include<stdio.h>
#define N 1000000

void insertionSort(int *,int ,int);
void shellSort(int *,int);

int cnt=0;
 
int main(){
  int i,A[N],n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  shellSort(A,n);
  printf("%d\n",cnt);
 
  for(i=0;i<n;i++){
    printf("%d\n",A[i]);
  }
  return 0;
}


void insertionSort(int *A,int n, int g){
int i,v,j;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}
 
void shellSort(int *A,int n){
  int i,m=0,S[n];
  S[0] = 0;
  for(i=0;i<n;i++){
    S[i+1] = 3*S[i]+1;
    m++; 
    if(S[i+1]>N) break;
  }
  while(S[m]>n){
    m--;
  }
  printf("%d\n",m);
  
  for(i=m;i>1;i--){
    printf("%d ",S[i]);
  }
  printf(" %d\n",S[1]);
  for(i=m ; i>=0 ; i--){
    insertionSort(A,n,S[i]);
  }
}



Measured memory_bytes: 5684
#include<iostream>
#include<algorithm>
#include<vector>
#include<complex>
using namespace std;
typedef long long ll;
#define N 100010
vector<ll> g[N];
ll c[N],d[N];
bool vis[N];
ll dfs(ll x){
  if(vis[x])return 0;
  vis[x]=1;
  ll res=d[x];
  for(auto y:g[x]){
    res+=dfs(y);
  }
  return res;
}
int main(){
  ll n,m;string s;
  cin>>s>>m; n=s.size();
  for(int i=0;i<n/2;i++){
    c[i+1]=s[n-1-i]-s[i];
  }c[0]=c[n/2+1]=0;
  for(int i=0;i<n/2+2;i++){
    d[i]=c[i+1]-c[i];
    vis[i]=0;
    //cout<<d[i]<<" ";
  }//cout<<endl;
  for(int i=0;i<m;i++){
    ll l,r;cin>>l>>r;
    ll cl=(n+1)/2,cr=(n+2)/2;
    bool flag=(l<=cl)&(cr<=r);
    if(l<=cl)l=cl-l; else l=l-cr;
    if(r<=cl)r=cl-r; else r=r-cr;
    //cout<<l<<" "<<r<<endl;
    if(l<r)swap(l,r);
    l=(n+1)/2-l,r=(n+1)/2-r;
    if(flag)r--; l--;
    //cout<<l<<" "<<r<<endl;
    g[l].push_back(r);
    g[r].push_back(l);
  }
  bool ok=1;
  for(int i=0;i<n/2+2;i++){
    if(dfs(i)%26!=0)ok=0;
  }
  cout<<(ok?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 7552
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
 #include <boost/multiprecision/cpp_int.hpp>

using bint = boost::multiprecision::cpp_int;
 
 
 
 
int main(){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1);
}

Measured memory_bytes: 256
/*
AizuOnline A2490
Title Parenthese
*/
#include <stdio.h>
int N;
//
main()
{
        int i,n;
        int depth;
        char c;

        scanf("%d ",&N);

        depth=0;
        for(i=0;i<N;i++)
        {
                scanf("%c %d ",&c,&n);
                //printf("cn=%c %d\n",c,n);
                if(c=='(')
                        depth += n;
                else
                        depth -= n;
                if(depth<0)
                {
                        break;
                }
        }
        //printf("d=%d\n",depth);
        printf("%s\n",(depth==0)?"YES":"NO");
        return(0);
}

Measured memory_bytes: 584
use std::collections::HashSet;
use std::iter::FromIterator;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let hash:HashSet<usize> = HashSet::from_iter(
        (0..n).map(|_| read()).collect::<Vec<usize>>()
    );
    println!("{}", hash.len());
}

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


def solve(T: str):
    T = T.replace('?','D')
    print(T)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = next(tokens)  # type: str
    solve(T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<int, int> P; // <val, dist>
P dp[11][1 << 15];

struct S {
	int v, buy;
	P d;

	bool operator <(const S& x) const {
		return d > x.d;
	}
};

P rec(S s) {
	return dp[s.v][s.buy];
}

void save(S s) {
	dp[s.v][s.buy] = s.d;
}

struct edge {
	int to, d;
};

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

	int N, Q, M;
	while(cin >> N, N) {
		map<string, int> store[10];
		for(int i = 0; i < N; i++) {
			int k;
			cin >> k;
			for(int j = 0; j < k; j++) {
				string name;
				int val;
				cin >> name >> val;
				store[i][name] = val;
			}
		}
		cin >> Q;
		vector<string> need(Q);
		for(int i = 0; i < Q; i++) {
			cin >> need[i];
		}
		cin >> M;
		vector<edge> G[11];
		for(int i = 0; i < M; i++) {
			int a, b, d;
			cin >> a >> b >> d;
			a--, b--;
			if(a == -1) a = N;
			if(b == -1) b = N;
			G[a].push_back({ b, d });
			G[b].push_back({ a, d });
		}

		priority_queue<S> q;
		S s = { N, 0, { 0, 0 } };
		q.push(s);
		const int INF = 1 << 25;
		fill((P*)begin(dp), (P*)end(dp), P{ INF, INF });
		save(s);

		while(q.size()) {
			s = q.top();
			q.pop();
			if(rec(s) < s.d) continue;
			if(s.v != N) {
				for(int i = 0; i < Q; i++) {
					if(s.buy >> i & 1) continue;
					if(store[s.v].count(need[i]) == 0) continue;
					S ns = s;
					ns.buy |= 1 << i;
					ns.d.first += store[s.v][need[i]];
					if(rec(ns) > ns.d) {
						save(ns);
						q.push(ns);
					}
				}
			}

			for(auto e : G[s.v]) {
				S ns = s;
				ns.v = e.to;
				ns.d.second += e.d;
				if(rec(ns) > ns.d) {
					save(ns);
					q.push(ns);
				}
			}
		}

		P ans = dp[N][(1 << Q) - 1];
		if(ans.first == INF) {
			cout << "impossible" << endl;
		}
		else {
			cout << ans.first << " " << ans.second << endl;
		}
	}
}

Measured memory_bytes: 6708
n = int(input())

a_i = list(map(int, input().split()))

limit = int(1e18)

answer = 1

over = False

for a in a_i:
    answer *= a
    if answer > limit:
        over = True
        break

if min(a_i) == 0:
    over = False
    answer = 0

if over:
    print(-1)
else:
    print(answer)


Measured memory_bytes: 21644
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
   
    _FAST
    lli n,t,i,j,k,ans=0,flag=0,a,b,m;

        cin>>n;
        vector<lli> dp((lli)(1ll<<(n))+1,0);
        vector<vector<lli>> ar(n+1,vector<lli>(n+1,0));
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                cin>>ar[i][j];
        dp[0]=1;
        //k= number of set bits
        //
        for(i=0;i<(1<<n);i++)
        {
            k=__builtin_popcount(i);//0,n-1
            //cout<<i<<" "<<k<<"->";
            for(j=0;j<n;j++)
            {
                if(ar[k][j]==1 && (i&(1<<j))==0)
                {
                    dp[i|(1<<j)]+=dp[i];
                    dp[i|(1<<j)]%=mod;
                    //cout<<i<<","<<j<<","<<(i|(1<<j))<<" ";
                }
               // else
                //cout<<" ";
            }
            //cout<<"\n";
        }
       // reverse(dp.begin(),dp.end());
        //for(auto i:dp)
        //    cout<<i<<" ";cout<<"\n";
        m=1ll<<n;
        cout<<dp[m-1]<<"\n";
   // }
    return 0;
}


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

int main(){
	deque<int> a;
	int q, query, t, x;
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>query;
		if(query == 0){
			cin>>x>>t;
			if(x == 1) a.push_back(t);
			else a.push_front(t);
		} else if(query == 1){
			cin>>t;
			cout<<a[t]<<endl;
		} else {
			cin>>t;
			if(t == 1)a.pop_back();
			else a.pop_front();
		}
	}
	
	return 0;
}


Measured memory_bytes: 4676
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


const ll MOD=1e9+7;
const int N=500000;

ll gcd(ll x,ll y){
    if(x) return gcd(y%x,x);
    else return y;
}

main(){
    ll n=in();
    vecll a(100);
    rep(i,n){
        ll x=lin();
        rep(j,100){
            a[j]+=x&1;
            x/=2;
        }
    }
    ll res=1;
    ll ans=0;
    rep(i,100){
        ans+=res*(n-a[i])%MOD*a[i];
        res*=2;
        res%=MOD;
        ans%=MOD;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){

    char tmp[1000];
    fgets(tmp,sizeof(tmp),stdin);
    int num[1];
    
    num[0]=atoi(strtok(tmp," "));
    num[1]=atoi(strtok(NULL," "));
    
    if(num[0]>num[1]){
        printf("a > b\n");
    }else if(num[0]<num[1]){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }

return 0;
}

Measured memory_bytes: 524
def check(li):
    b = 0
    for eb, eh in li:
        if b + eb < 0:
            return False

        b += eh

    return True


n = int(input())
s = [input() for _ in range(n)]

l = []
r = []
sm = 0
for word in s:
    h = 0
    b = 0
    for e in word:
        if e == "(":
            h += 1
        else:
            h -= 1

        b = min(b, h)

    if h > 0:
        l.append([b, h])
    else:
        r.append([b-h, -h])

    sm += h

l.sort(reverse=True)
r.sort(reverse=True)

if check(l) and check(r) and sm == 0:
    ans = "Yes"
else:
    ans = "No"
print(ans)


Measured memory_bytes: 245968
import java.io.*;
import java.util.*;
 
/*
TASK: cardgame
LANG: JAVA
 */
public class Main {
 
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in); //new FileInputStream(new File("cardgame.in")));
        //PrintWriter out = new PrintWriter(new File("cardgame.out"));
        String s = in.next();
        if(s.length() < 4)System.out.println("No");
        else if(s.substring(0 , 4).equals("YAKI"))System.out.println("Yes");
        else System.out.println("No");
 
    }
 
    private static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
 
        public FastScanner(InputStream stream) {
            this.stream = stream;
        }
 
        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }
 
        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
        public long nextLong() {
            return Long.parseLong(next());
        }
 
        public double nextDouble() {
            return Double.parseDouble(next());
        }
 
        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
 
        public String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}

Measured memory_bytes: 21204
m, n = gets.split.map &:to_i
f = (1..m).map { gets.chomp }
e = gets.chomp.split("") + gets.chomp.split("")

hash = {}

count = 0
(0..m-2).each{|i|
	(0..n-2).each{|j|
		a = [
			f[i][j] == e[0],
			f[i][j+1] == e[1],
			f[i+1][j] == e[2],
			f[i+1][j+1] == e[3],
		]
		case a.count{|b| b}
		when 4
			count += 1
			[[i,j], [i,j+1], [i+1,j], [i+1,j+1]].each{|y, x|
				pos = [y, x]
				hash[pos] ||= Hash.new(0)
				(%w(J O I) - [f[i][j]]).each{|c|
					hash[pos][c] -= 1
				}
			}
		when 3
			k = a.index{|b| !b}
			pos = [i + k/2, j + k%2]
			hash[pos] ||= Hash.new(0)
			hash[pos][e[k]] += 1
		end
	}
}

p count + [hash.values.map(&:values).flatten.max || 0, 0].max

Measured memory_bytes: 247552
#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1000000007;
using namespace std;

vector<pair<long long, long long>> prime_factorize(long long N)
{
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        long long ex = 0;
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    long long N, ans = 0;
    cin >> N;

    for (int i = 1; i < N; i++)
    {
        ll box = N - i;
        const auto &pf = prime_factorize(box);
        long long res = 1;
        for (auto p : pf)
            res *= p.second + 1;
        ans += res;
    }
    cout << ans;
}

Measured memory_bytes: 3628
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
int n,a[1000010],s,g;
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	s=1;
	for(int i=2; i<=n; i++)
		if(a[i]!=a[i-1])
		{
			if(s>a[i-1])g+=(s-a[i-1]);
			if(s<a[i-1])g+=s;
			s=1;
		}
		else s++;	
	if(s>a[n])g+=(s-a[n]);
	if(s<a[n])g+=s;
	cout<<g<<endl;
	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    ll A[N+1], B[N];

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

    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    ll sum = 0;

    for (int i = 0; i < N; i++) {
        if (A[i] >= B[i]) {
            sum += B[i];
        }
        else {
            sum += A[i];
            if (A[i+1] >= B[i]-A[i]) {
                sum += B[i]-A[i];
                A[i+1] -= B[i]-A[i];
            }

            else {
                sum += A[i+1];
                A[i+1] = 0;
            }
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 double d,t,s;
	 cin>>d>>t>>s;
	 double needed = d/s;
	 if(needed <= t)
	 cout<<"Yes"<<'\n';
	 else
	 cout<<"No"<<'\n';
	 return 0;
}


Measured memory_bytes: 3760
s = ""
while True:
    try:
        s += input()
    except EOFError:
        break
s = s.lower()
d = dict()
for c in "abcdefghijklmnopqrstuvwxyz":
    d[c] = 0
for c in s:
    if c in "abcdefghijklmnopqrstuvwxyz":
        d[c] += 1
for c in "abcdefghijklmnopqrstuvwxyz":
    print(f"{c} : {d[c]}")


Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define ll      		long long
#define pb      		push_back
#define mp      		make_pair
#define sz(a)   		(int)(a).size()
#define all(x)  		(x).begin(), (x).end()
#define fore(i,a,b)		for(int i=a; i<b; i+=1)
#define forr(i,a)		for(int i=a; i>=0; i--)
#define F first
#define S second

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<string, int> si;
typedef vector<string> vs;
const int MAX=1e5+10;

bool isPrime(int x){
    if(x<2) return false;
    for(int i=2; i*i<=x; i++){
        if(x%i==0) return false;
    }
    return true;
}

vi primes;
void generate(int n){
    fore(i,1,n+1){
        if(isPrime(i)) primes.pb(i);
    }
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int h, a; cin>>h>>a;
    int res=h/a;
    if(h%a!=0) res++;
    cout<<res<<endl;

    return 0;
}

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

int main(void) {
  vector<int> x(3);
  for(int i = 0; i < 3; i++) cin >> x[i];
  sort(x.begin(), x.end());
  cout << x[0] << " " << x[1] << " " << x[2] << endl;
}


Measured memory_bytes: 3160
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	S := sc.next()
	if S == "SUN" {
		fmt.Println(7)
	}

	if S == "MON" {
		fmt.Println(6)
	}

	if S == "TUE" {
		fmt.Println(5)
	}

	if S == "WED" {
		fmt.Println(4)
	}

	if S == "THU" {
		fmt.Println(3)
	}

	if S == "FRI" {
		fmt.Println(2)
	}

	if S == "SAT" {
		fmt.Println(1)
	}
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
use std::io::{stdin, BufRead, BufReader};

struct Point {
    x: f32,
    y: f32,
}

fn main() {
    let input = BufReader::new(stdin());
    for line in input.lines() {
        let values: Vec<f32> = line.unwrap()
            .trim()
            .split_whitespace()
            .filter_map(|x| x.parse::<f32>().ok())
            .collect();
        if values.len() != 8 {
            continue;
        }
        let a = Point { x: values[0], y: values[1] };
        let b = Point { x: values[2], y: values[3] };
        let c = Point { x: values[4], y: values[5] };
        let d = Point { x: values[6], y: values[7] };
        if a.x - b.x == 0.0 && c.x - d.x == 0.0 {
            println!("YES");
            continue;
        }
        let ab = (b.y - a.y) / (b.x - a.x);
        let cd = (d.y - c.y) / (d.x - c.x);
        if ab == cd {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}
int main(){
  int n,i,j,k,ans = 0;cin >> n;
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++) ans += gcd(i,gcd(j,k));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
//
// main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
	ll N;
	cin >> N;
	vector<ll> as(N);
	rep(i,0,N) {
		cin >> as[i];
	}
	sort(as.rbegin(), as.rend());
	unordered_map<ll,ll> hist;
	rep(i,0,N) {
		hist[as[i]]++;
	}
	ll max = as[0];
	ll min = as[0] - as[0] / 2;
	if (as[as.size()-1] != min) {
		cout << "Impossible" << endl;
		return 0;	
	}
	if (hist[max] < 2) {
		cout << "Impossible" << endl;
		return 0;	
	}
	if (max % 2 == 1) {
		if (hist[min] != 2) {
			cout << "Impossible" << endl;
			return 0;	
		}
	} else {
		if (hist[min] != 1) {
			cout << "Impossible" << endl;
			return 0;	
		}	
	}
	rep(x,min+1,max) {
		if (hist[x] < 2) {
			cout << "Impossible" << endl;
			return 0;	
		}
	}
	cout << "Possible" << endl;
	return 0;	
}


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

int main() {
    int N;
    cin >> N;
    for (int i=1; i<=9; i++) {
        for (int j=1; j<=9; j++) {
            int ans = i * j;
            if (ans == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long LL;

const int MAXN = 200000;
const int MOD = 1000000007;
const int INF = 1000000001;

int N, X, Y, C[MAXN + 5], W[MAXN + 5];

int Min[MAXN + 5], Cnt[MAXN + 5];

int Fac[MAXN + 5], Inv[MAXN + 5];

int Pow(int x, int y) {
	int ret = 1;
	while (y) {
		if (y & 1)
			ret = (LL)ret * x % MOD;
		y >>= 1;
		x = (LL)x * x % MOD;
	}
	return ret;
}

int main() {
	scanf("%d%d%d", &N, &X, &Y);
	Fac[0] = 1;
	for (int i = 1; i <= N; i++)
		Fac[i] = (LL)Fac[i - 1] * i % MOD;
	Inv[N] = Pow(Fac[N], MOD - 2);
	for (int i = N - 1; i >= 0; i--)
		Inv[i] = (LL)Inv[i + 1] * (i + 1) % MOD;
	for (int i = 0; i <= N; i++)
		Min[i] = INF;
	for (int i = 1; i <= N; i++) {
		scanf("%d%d", &C[i], &W[i]);
		Cnt[C[i]]++;
		Min[C[i]] = std::min(Min[C[i]], W[i]);
	}
	int fir = std::min_element(Min + 1, Min + N + 1) - Min, sec = 0;
	for (int i = 1; i <= N; i++)
		if (i != fir && Min[i] < Min[sec])
			sec = i;
	for (int i = 1; i <= N; i++) { // 对于每个球
		if (W[i] != Min[C[i]] && W[i] + Min[C[i]] <= X) // 内部就可以交换
			continue;
		if (C[i] != fir && W[i] + Min[fir] <= Y) // 可交换出去
			continue;
		if (C[i] == fir && W[i] + Min[sec] <= Y) // 可交换出去
			continue;
		Cnt[C[i]]--; // 该球无法移动
	}
	int tot = 0, Ans = 1;
	for (int i = 1; i <= N; i++) // 合并每个颜色的连通块
		if (Min[i] + Min[fir] <= Y)
			Ans = (LL)Ans * Inv[Cnt[i]] % MOD, tot += Cnt[i];
	printf("%d", (LL)Ans * Fac[tot] % MOD);
}

Measured memory_bytes: 4864
import java.util.*;
public class Main {
  	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      
      int a = N % 1000;
      if (a == 0){
        System.out.println(0);
      } else {
	      System.out.println(1000 - a);
      }
    }
}

Measured memory_bytes: 35744
#include <iostream>
#include <string>

using std::string;

bool ring_found(string& s, string& p, size_t s_idx)
{
	bool found = true;
	size_t s_length = s.length();
	size_t p_length = p.length();

	for(size_t p_idx = 0; p_idx < p_length; p_idx++)
	{
		if( s[s_idx] != p[p_idx] )
		{
			found = false;
			break;
		}
		s_idx = (s_idx + 1) % s_length;
	}

	return found;
}

int main()
{
	string s,p;

	std::cin >> s >> p;

	size_t s_length = s.length();

	bool found = false;
	for(size_t i = 0; i < s_length; i++)
	{
		if( ring_found(s, p, i) == true )
		{
			found = true;
			break;
		}
	}

	if( found )
	{
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}

    return 0;
}

Measured memory_bytes: 3164
A, B, C, D, E, F = list(map(int, input().split()))

sw = 100 * A
sugar = 0
percent = 0
for k in range(F // (100 * A) + 1):
    for l in range(F // (100 * B) + 1):
        if k == 0 and l == 0:
            continue
        tmp = A * k + B * l
        if 100 * tmp > F:
            continue
        for i in range(tmp*E//C + 1):
            for j in range(tmp*E//D + 1):
                tmp2 = i * C + j * D
                if 100 * tmp + tmp2 > F:
                    continue
                if tmp2 > tmp * E:
                    continue
                t = 100 * tmp2 / (100 * tmp + tmp2)
                if t > percent:
                    percent = t
                    sw = 100 * tmp + tmp2
                    sugar = tmp2

print(sw, sugar)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
using namespace std;
int main(void)
{
	int R, t, n, max = 0, min = 0, mint = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t;
		if (i == 0) { min = t; }
		if (i == 1){
			R = t - min;
		}
		if(i > 1 && R < t - min) {
			R = t - min;
		}
		if (min > t) {
			min = t;
		}
		
	}
	cout << R << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int H, W;
	cin >> H >> W;
	vector<string>a(H);
	rep(i, H)cin >> a[i];
	vector<vector<int>>dp(H, vector<int>(W));
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '#')continue;
			if (i - 1 >= 0 && a[i - 1][j] != '#') {
				dp[i][j] += dp[i - 1][j];
				dp[i][j] %= MOD;
			}
			if (j - 1 >= 0 && a[i][j - 1] != '#') {
				dp[i][j] += dp[i][j - 1];
				dp[i][j] %= MOD;
			}
		}
	}
	cout << dp[H - 1][W - 1];
}

Measured memory_bytes: 9216
#include<iostream>
#include<cstring>

char p[10000001];

void sieve()
{
	memset( p, 1, sizeof( p ) );
	p[0] = p[1] = 0;

	for( int i = 2; i <= 10000000; ++i )
		if( p[i] )
			for( int j = i * 2; j <= 10000000; j += i )
				p[j] = 0;

	return;
}

int main()
{
	sieve();

	int n;
	while( std::cin >> n, n )
	{
		while( true )
		{
			if( p[n] && p[n-2] && p[n-6] && p[n-8] )
			{
				std::cout << n << std::endl;
				break;
			}

			--n;
		}
	}

	return 0;
}

Measured memory_bytes: 10932
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MOD = 1e9 + 7, mxN = 1e5 + 5;

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

template <typename T> void mul(T& a, T b, int mod) {
	a = a * b % mod;
}

ll dp[mxN][2];

class TaskP {
public:
	int N;
	vector<int> adj[mxN];

	void solve(std::istream& in, std::ostream& out) {
		in >> N;
		for (int i = 0; i < N - 1; i++) {
			int u, v;
			in >> u >> v;
			u--, v--;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		memset(dp, -1, sizeof(dp));
		ll ans = rec(0, -1, 0);
		out << ans;
	}

	ll rec(int u, int p, int col) {
		if (dp[u][col] != -1) return dp[u][col];
		ll ways = 1, tot = 0;
		if (col == 0) {
			for (int v : adj[u]) {
				if (v == p) continue;
				mul(ways, rec(v, u, 1), MOD);
			}
			add(tot, ways, MOD);
		}
		ways = 1;
		for (int v : adj[u]) {
			if (v == p) continue;
			mul(ways, rec(v, u, 0), MOD);
		}
		add(tot, ways, MOD);
		return dp[u][col] = tot;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskP solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

const int MX_N = 50;

int main() {
  ll n, x;
  cin >> n >> x;

  vector<ll> p(MX_N + 1), b(MX_N + 1);
  p[0] = 1;
  b[0] = 0;

  for (int i = 1; i <= MX_N; ++i) {
    p[i] = p[i - 1] * 2 + 1;
    b[i] = b[i - 1] * 2 + 2;
  }

  auto f = [&](ll n, ll x, ll a, auto f) {
    if (n < 0)
      return a;
    ll half = (p[n] + b[n] + 1) / 2;
    if (x < half)
      return f(n - 1, x - 1, a, f);
    else
      return f(n - 1, x - half, a + p[n] / 2 + 1, f);
  };
  ll ans = f(n, x, 0, f);

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
s = input()
judge = 0
if s[0] == "A":
    judge += 1

if s[1] != "C" and s[len(s) -1] != "C" and s.count("C") == 1:
    judge += 1

s = s.replace("A","a").replace("C","c")
#print(s,judge)
if s.islower() and judge == 2:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, M, ans;
    cin >> N >> M;
    vector<int> X(M);
    vector<int> D(M-1);
    REP(int,i,0,M) cin >> X.at(i);
    sort(X.begin(),X.end());
    REP(int,i,0,M-1) D.at(i) = X.at(i+1) - X.at(i);
    sort(D.begin(),D.end());
    //REP(int,i,0,M-1) cout << D.at(i) << endl;
    ans = 0;
    REP(int,i,0,M-N) ans += D.at(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024