akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <queue>
using namespace std;

const int MAX_SIZE = 1000;
typedef pair<int, int> P;
typedef pair<int, P> Q;

int calc(int f[][MAX_SIZE], queue<Q> q, int H, int W) {
  P d[] = {P(-1, -1), P(-1, 0), P(-1, 1), P(0, -1), P(0, 1), P(1, -1), P(1, 0), P(1, 1)};
  int n = 0;
  while (q.size()) {
    int c = q.front().first;
    P p = q.front().second;
    q.pop();
    if (c > n) n++;
    for (int k = 0; k < 8; ++k) {
      int i = p.first  + d[k].first;
      int j = p.second + d[k].second;
      if (i >= 0 && i < H && j >= 0 && j < W && --f[i][j] == 0) {
        q.push(Q(c + 1, P(i, j)));
      };
    }
  }
  return n;
}

int main() {
  int H, W;
  int f[MAX_SIZE][MAX_SIZE];
  queue<Q> q;

  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    string str;
    cin >> str;
    for (int j = 0; j < W; ++j) {
      if (str[j] == '.') {
        f[i][j] = 0;
        q.push(Q(0, P(i, j)));
      } else {
        f[i][j] = str[j] - '0';
      }
    }
  }
  cout << calc(f, q, H, W) << endl;
}

Measured memory_bytes: 5608
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ns = sc.next();
        int n = Integer.parseInt(ns);
        String p = "";
        for(int i=0;i<ns.length();i++)p+=ns.charAt(0);
        if(n<=Integer.parseInt(p))System.out.println(p);
        else{
            p = "";
            for(int i=0;i<ns.length();i++)p+=((char)(ns.charAt(0)+1));
            System.out.println(p);
        }

    }
}

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


int main(){
	int R, G, B, n,x,y, ans = 0;
	cin >> R >> G >> B >> n;
	for (int i = 0; i<= n/R; i++){
		x = n - (R*i);
		for (int j = 0; j <= x / G;j++){
			y=x - G*j;
			if (y%B == 0){
				ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")//防止栈溢出！！！
#include<stdio.h> 
#include<iostream>
using namespace std; 
#include<stdlib.h>
#include<malloc.h> 
#include<cstring> 
#include<algorithm> 
#include<math.h> 
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include<time.h>
#include<ctype.h>
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define For(i,x,y)  for(long long i=(long long)(x);i<(long long)(y);++i)
#define rFOR(I,S,N) for(long long I=N;I>=S;I--)
#define SWAP(x,y) {(x) = (x)^(y); (y)=(x)^(y); (x)=(x)^(y);} 
#define D(x) cerr<<#x<<" = "<<x<<endl
#define ms(a,b) memset(a,b,sizeof(a)) 
#define lowbit(x) ((x)&(-x))  
#define max(a,b) a>b?a:b
 typedef   long long    ll;
typedef unsigned long long   ull;
const double eps=1e-8;
const int mod = 1e9+7 ;
const int MOD = 1e9+6;
const int INF = 0x3f3f3f3f;
const int maxn = 1024;
const double pi=acos(-1.0);
template<class T>inline void rd(T &x){int Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
 
ll abs(ll a,ll b){ ll ans=a-b; return ans>0?ans:(-ans);}
  
struct node{
	int w;
	int s;
	int id;
} ;
int a[maxn]; 
int main(int argc, char** argv)   
{   
      //	freopen("E://dev//input.in","r",stdin);  
 	int	 u,   b ,n  ,m, res,st=-1,maxnn;
	int	t ;
  	while(~scanf("%d%d",&n,&m)){ 
	   
  		printf("%d\n",n+m/2 ); 
	} 
  	 
    return 0;  
}  


	













Measured memory_bytes: 256
x = int(input())

def score(x):
 if  400 <= x <= 599:
        print("8")
 elif 600 <= x <= 799:
        print("7")
 elif 800 <= x <= 999:
        print("6")
 elif 1000 <= x <= 1199:
        print("5")
 elif 1200 <= x <= 1399:
        print("4")
 elif 1400 <= x <= 1599:
        print("3")
 elif 1600 <= x <= 1799:
        print("2")
 elif 1800 <= x <= 1999:
        print("1")

score(x)

Measured memory_bytes: 9192
S = input()
l1 = []
l2 = []
rev = False
for _ in range(int(input())):
    l = [s for s in input().split()]
    if l[0] == "1":
        rev = not rev
    elif l[1] == "1":
        if rev:
            l2.append(l[2])
        else:
            l1.append(l[2])
    else:
        if rev:
            l1.append(l[2])
        else:
            l2.append(l[2])

if rev:
    ret = "".join(l2)[::-1] + S[::-1] + "".join(l1)
else:
    ret = "".join(l1)[::-1] + S + "".join(l2)

print(ret)


Measured memory_bytes: 5724
object Main {
  def main(args: Array[String]) {
    if (sys.env.getOrElse("TEST", "") == "1") {
      println(test());
    } else {
      val input = io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input: String): String = {
    val arr = input.split("\n")(1).split(" ").map(_.toInt)
    val t = arr.foldLeft((0, 0))((t, e: Int) => {
      if (t._1 <= e) {
        (e, t._2 + 1)
      } else {
        t
      }
    })
    return t._2.toString
  }

  val tests = List(
    """4
      |6 5 6 8""".stripMargin ->
      """3""",
    """5
      |4 5 3 5 4""".stripMargin -> "3",
    """5
      |9 5 6 8 4""".stripMargin -> "1");

  def test(): String = {
    return tests.map { case (i, o) => (i.trim(), o.trim()) }
      .zipWithIndex.map {
      case ((input, outputExpect), i) => {
        val output = solve(input).trim();
        s"test${i + 1}:" + (if (output == outputExpect) {
          "Passed"
        } else {
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }
    }
      .mkString("\n");
  }
}


Measured memory_bytes: 27324
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp=[[0 for i in range(n)] for j in range(2)]
dp[0][0]=a[0]
for i in range(1,n):
    dp[0][i]=a[i]+dp[0][i-1]
dp[1][0]=dp[0][0]+b[0]
for i in range(1,n):
    dp[1][i]=max(dp[0][i],dp[1][i-1])+b[i]
print(dp[1][n-1])



Measured memory_bytes: 62148
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.reverse()
for i in range(n-1):
    a[i]-=a[i+1]
a[n-1] = 0
a.append(k-sum(a))
ans = k-max(a)
print(ans)

Measured memory_bytes: 26436
#https://atcoder.jp/contests/abc158/tasks/abc158_b
# -*- coding: utf-8 -*-
N,A,B = map(int,input().split())
syou = N//(A+B)
amari = N%(A+B)
if amari>A:
  amari=A
ans = syou*A+amari
print(ans)

Measured memory_bytes: 38384
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] table = new int[r + 1][c + 1];
		int[] sumC = new int[c + 1];

		for(int i = 0; i < r ; i++){
			for(int j = 0; j < c; j++){
				int n = scan.nextInt();
				table[i][j] = n;
			}
		}

		for(int i = 0; i < r + 1; i++){
			int sum = 0;
			for(int j = 0; j < c + 1; j++){
				if(i != r){
					if(j != c){
						sum = sum + table[i][j];
						sumC[j] = sumC[j] + table[i][j];
					} else if(j == c){
						table[i][c] = sum;
						sumC[c] = sumC[c] + table[i][c];
					}
				} else if(i == r){
					table[r][j] = sumC[j];
				}
			}
		}

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.printf((j != c) ? "%d " : "%d\n", table[i][j]);
			}
		}
	}
}

Measured memory_bytes: 50428
#include <iostream>
#include <vector>
#define M 1000000007l
using namespace std;

typedef long long int ll;
typedef vector<ll> vll;

ll pow_mod_M(ll base, ll power){
	if(power == 0)
		return 1;
	else if((power & 1) == 0){
		ll h = power / 2;
		ll x = pow_mod_M(base, h);
		return (x * x) % M;
	}else{
		return (base * pow_mod_M(base, power - 1)) % M;
	}
}

int main(){

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin >> n;

	vll a = vll(n + 1);
	for(ll i = 1; i <= n; i++)
		cin >> a[i];

	ll fact_mod_m = 1;
	for(ll i = 1; i <= n; i++){
		fact_mod_m = (fact_mod_m * i) % M;
	}

	vll pi = vll(n + 1);
	for(ll i = 1; i <= n; i++){
		pi[i] = (fact_mod_m * pow_mod_M(i, M - 2)) % M;
	}

	vll prefix = vll(n + 1, 0);
	prefix[1] = pi[1];
	for(ll i = 2; i <= n; i++){
		prefix[i] = (prefix[i - 1] + pi[i]) % M;
	}

	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		ll delta = (a[i] * (prefix[i] + prefix[n - i + 1] - prefix[1] + M) % M) % M;
		ans = (ans + delta) % M;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int sum = 0, sum2 = 0;
    for(int i = 0; i < n; i += 2)
        sum += a[i];
    for(int i = 1; i < n; i += 2)
        sum2 += a[i];
    cout << sum - sum2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll x=0, y=0;
    ll count = 0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        if(a[i] >= x){
            if(i != 0){
                y = max(y, x);
            }
            x = max(x, a[i]);
        }
        if(a[i] < x){
            y = max(y, a[i]);
        }
    }

    for(ll i=0;i<n;++i){
        if(a[i] == x){
            count++;
        }
    }
    for(ll i=0;i<n;++i){
        ll ans = x;
        if(a[i] == x and count == 1){
            ans = y;
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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


 string s;
 cin>>s;
 cout<<s[0]<<s[1]<<s[2]<<endl;

return 0;
}



Measured memory_bytes: 3616
def addition():
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	odd_count = 0
	for x in a:
		if x%2==1:
			odd_count+=1
	if odd_count%2==1:
		print "NO"
	else:
		print "YES"


if __name__ == "__main__":
	addition()

Measured memory_bytes: 11324
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<vector<int>> G;
vector<int> check;

void dfs(int cur = 0, int par = -1){
    for(auto v: G[cur]){
        if(v != par){
            dfs(v, cur);
        }
    }
    if(par != -1 && !check[cur] && !check[par]){
        check[cur] = 1;
        check[par] = 1;
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    G.resize(N);
    rep(i, N - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    check.assign(N, 0);
    dfs();
    
    bool ok = false;
    rep(i, N) if(!check[i]) ok = true;
    
    if(ok){
        output("First");
    }
    else{
        output("Second");
    }
    
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  vector<ll> v1(n);
  double goukei=0;
  rep(i,n){
    cin >> v[i];
    goukei+=v[i];
    v1[i]=ll(goukei);
  }
  goukei/=2;
  ll a=1145141919810;
  rep(i,n){
    if(i==n-1){
      break;
    }
    ll tmp=ll(fabs(v1[i]-goukei)*2);
    if(tmp<a){
      a=tmp;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3328
/*      Welcome to my Code      */

#include <bits/stdc++.h>
#define ll                      long long int
#define i(a,n)                  int a=n;
#define l(a,n)                  ll a=n;
#define d(a,n)                  double a=n;
#define s(a)                    string a;
#define c(a)                    ll a; cin>>a;a
#define cd(a)                   double a; cin>>a;
#define cs(a)                   string a; cin>>a;
#define ci(a)                   cin>>a;
#define co(a)                   cout<<a;
#define cos(a)                  cout<<a<<" ";
#define con(a)                  cout<<a<<endl;
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl;
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i];
#define caa(arr,n)              c(n); ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define T                       ll t=1; cin>>t; while(t--)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;

using namespace std;

int main()
{
    fast;
    caa(a,n);
    l(t,0);
    sort(a,a+n);
    f(i,n) f1(j,i+1,n) f1(k,j+1,n) if((a[i]+a[j])>a[k] && a[i]!=a[j] && a[j]!=a[k]) t++;
    con(t);
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
int n;
long long ans,a[10];
char s[101010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    scanf("%s",s);
	    if(s[0]=='M') a[1]++;
	    if(s[0]=='A') a[2]++;
	    if(s[0]=='R') a[3]++;
	    if(s[0]=='C') a[4]++;
	    if(s[0]=='H') a[5]++;
	}
	for(int i=1;i<=3;i++)
	for(int j=i+1;j<=4;j++)
	for(int k=j+1;k<=5;k++)
	ans+=a[i]*a[j]*a[k];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;

		int atk[20];
		for(int i=0;i<n;i++){
			scanf("%d",atk+i);
		}

		int diff=numeric_limits<int>::max();
		for(int S=0;S<=(1<<n)-1;S++){
			int sumA=0;
			int sumB=0;
			for(int i=0;i<n;i++){
				if(S & (1<<i)) sumA+=atk[i];
				else sumB+=atk[i];
			}
			diff = min(diff,abs(sumA-sumB));
		}

		printf("%d\n",diff);
	}
}

Measured memory_bytes: 880
def f(a, b):
    if b:
        return f(b, a%b)
    return a

N, K = map(int, input().split())
A = list(map(int, input().split()))

if N == 1:
    print("POSSIBLE" if K==A[0] else "IMPOSSIBLE")
    exit()

p = f(A[0], A[1])

for i in A[1:]:
    p = f(p, i)

print("POSSIBLE" if p==f(p, K) and K <= max(A) else "IMPOSSIBLE")

Measured memory_bytes: 14224
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

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

    vector<int> value(n);
    float cmp = 0;
    rep(i, 0, n) {
        cin >> value[i];
        cmp += value[i];
    }
    cmp /= 4 * m;

    sort(value.begin(), value.end());
    if (value[n - m] >= cmp) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3612
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    println(Array(n, {i -> br.readLine().toInt() }).toSet().size)
}

fun err(print: Any) {
    System.err.println(print)
}

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

typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

const int level = 62;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int n;
  LL k;
  cin >> n >> k;

  vector <int> a (n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  vector <vector <int> > nxt (n + 1, vector <int> (65, 0));
  for (int i = 1; i <= n; i++) nxt[i][0] = a[i];
  for (int i = 1; i <= level; i++) {
    for (int node = 1; node <= n; node++) {
      nxt[node][i] = nxt[nxt[node][i - 1]][i - 1];
    }
  }

  int cur = 1;
  for (int i = 0; i <= 62; i++) {
    if ((k >> i)&1) cur = nxt[cur][i];
  }

  cout << cur << endl;
  return 0;
}



Measured memory_bytes: 61788
a, b, c, d = map(int, input().split())

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x * y // gcd(x, y)

def ans(num, x, y):
    return num - (num // x + num // y - num // lcm(x, y))

print(ans(b, c, d) - ans(a-1, c, d))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<map>
using namespace std;
vector <int> v;
map<int,int> m;
int main()
{
	int n;
	cin>>n;
	int x,count=0;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(!m[x])
		    v.push_back(x);
		m[x]++;		
	}
	for(int i=0;i<v.size();i++)
	{
		x=v[i];
		if(m[x]>x)count+=(m[x]-x);
	    if(m[x]<x)count+=m[x];
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 5112
N,M,K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ReadA = [0]*(N+1)
ReadB = [0]*(M+1)
for TA in range(0,N):
    ReadA[TA+1] = ReadA[TA]+A[TA]
for TB in range(0,M):
    ReadB[TB+1] = ReadB[TB]+B[TB]
MAX = 0
MAXTB = M
for TA in range(0,N+1):
    if ReadA[TA]>K:
        break
    else:
        for TB in range(MAXTB,-1,-1):
            if ReadA[TA]+ReadB[TB]<=K:
                MAXTB = TB
                if MAX<TA+TB:
                    MAX = TA+TB
                break
print(MAX)

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

int main()
{
    int n,flag=0;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        b[i]=a[i];
    }
    sort(&a[0],&a[n]); //location of 1st and last element or sort(a,a+n)= same thing
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            flag++;
        }
    }
    if(flag<=2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int W,a,b;
	cin >> W >> a >> b;

	int x_r,diff;

	if(a < b){
		x_r = a + W;
		diff = b - x_r;
	}
	else{
		x_r = b + W;
		diff = a - x_r;
	}

	if(diff <= 0) cout << 0 << endl;
	else cout << diff << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    const int MXX = 100 + 5;

    int main ()
    {
        string s;
        cin>>s;
        map<char, int>mp;
        for(auto c: s)mp[c]++;
        for(auto c: s)
        {
            if(mp[c] % 2 ==1)return cout<<"No"<<endl, 0;
        }
        cout<<"Yes"<<endl;
        return 0;
    }


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


using namespace std;
using vi=vector<int>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi d(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d", &d[i]);
		}
		sort(d.begin(), d.end());

		int ans=1;
		for(int i=1;i<n;i++)
		{
			if(d[i]>d[i-1]) ans++;
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0;i < n;i++){
            int t = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(x+y > t || t%2 != (x+y)%2){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main(void){
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>m;
    ans=min(n,m/2);
    n-=ans;
    m-=ans*2;
    ans+=m/4;
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
N=int(input())

l=[]

for i in range(N):
  x,y=[int(x) for x in input().rstrip().split()]
  l.append([x,y])

l=sorted(l,key=lambda x:x[1] )

flag=0
now=0
ans=0
for i,j in l:
  now+=i
  if j<now:
    print("No")
    flag=1
    break
if flag==0:
  print("Yes")


Measured memory_bytes: 39648
#!/usr/bin/env python3
import sys, math
def solve(N: int):
    count = 0
    for i in range(1, N):
        a = N//i
        if i* a < N:
            count += a
        else:
            count += a-1
    print(count)
    return
def main():
    solve(int(sys.stdin.readline().rstrip()))

if __name__ == '__main__':
    main()


Measured memory_bytes: 63140
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  vector <int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<tuple>
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    int i,j,k;
    int nibeki[K+1];
    nibeki[0]=1;
    for(i=1; i<=K; i++){
        nibeki[i]=2*nibeki[i-1];
    }
    bool oki=0;
    vector<tuple<int,int,int,int> > vec;
    for(i=0; i<=K; i++){
        for(j=0; j<=K; j++){
            for(k=0; k<=K; k++){
                vec.push_back(make_tuple(A*nibeki[i],B*nibeki[j],C*nibeki[k],i+j+k));
            }
        }
    }
    for(i=0; i<vec.size(); i++){
        A = get<0>(vec[i]);
        B = get<1>(vec[i]);
        C = get<2>(vec[i]);
        j = get<3>(vec[i]);
        if(A<B && B<C && j<=K) oki=1;
    }
    if(oki==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3640
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int x = ni();
    s = na(n);
    Arrays.sort(s);
    memo = new int[n][x + 1];
    for (int[] v : memo)
      Arrays.fill(v, -1);

    int ret = dfs(n - 1, x);
    System.out.println(ret);
  }

  private static int mod = (int) 1e9 + 7;
  private static int[] s;
  private static int[][] memo;

  private static int dfs(int i, int x) {
    if (memo[i][x] >= 0) {
      return memo[i][x];
    }

    long ret;
    if (i == 0) {
      ret = x % s[i];
    } else {
      ret = dfs(i - 1, x % s[i]);
      ret += (long) i * dfs(i - 1, x) % mod;
      ret %= mod;
    }

    memo[i][x] = (int) ret;
    return memo[i][x];
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 126932
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
dp=[False]*(K+1)
dp[0]=False
for i in range(1,K+1):
    for j in range(len(A)):
        if((i-A[j])>=0):
            dp[i]= (dp[i] or (not dp[i-A[j]]))
# print(dp)
if(dp[K]==True):
    print("First")
else:
    print("Second")

Measured memory_bytes: 74208
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {cout << "Cloudy" << endl;}
  else if (S == "Cloudy") {cout << "Rainy" << endl;}
  else {cout << "Sunny" << endl;}
}

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

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

const int INF = 1e9;
const int mod = 1e9+7;

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

    int ans = INF;
    for(int i = 1; i < s.length()-1; i++){
        int num = (s[i-1]-'0')*100 + (s[i]-'0')*10 + s[i+1]-'0';
        ans = min({ans,abs(753+num),abs(753-num)});
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i,n,k;
    cin>>n>>k;
    pair<int,long long int> a[n];
    for(i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    
    sort(a,a+n);
    
    long long int now=0;
    for(i=0;i<n&&now<k;i++){
        now+=a[i].second;
    }
    
    cout<<a[i-1].first<<endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<pd> vpd; 

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MX  = 2e5+5; 
const int MOD = 1e9+7; // 998244353;
const ll  INF = 1e18; 
const ld  PI  = acos((ld)-1);

const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; 
}
template<class T> bool ckmax(T& a, const T& b) { 
	return a < b ? a = b, 1 : 0; 
} 

constexpr int pct(int x) { return __builtin_popcount(x); } // number of ones 
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
template<class T> T cdiv(T a, T b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 

int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}

template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); 
}

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); 
}
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

// FILE I/O
void setIn(str S) { freopen(S.c_str(),"r",stdin); }
void setOut(str S) { freopen(S.c_str(),"w",stdout); }
void setIO(str S = "") {
	ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(S)) { setIn(S+".in"), setOut(S+".out"); } // for USACO
}
	
int32_t main() { 
	
	setIO();

    int n; cin >> n;

    str res = "";

    F0R(i,n) res += "ACL";

    cout << res << "\n";

}	

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
const double PI  = acos(-1.0);

//-------------------------------------------

int n,k;
LL ans = 0;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n>>k;

    for(int b=1;b<=n;b++){
    ans+= (n/b)*max(0,b-k);
    ans+= max(0,n%b-k+1);
    }
    if(k==0)
    ans-=n;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
long long int a,c,d,e,k,j,b,l,m;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
while(1)
{
 c=c-b;
 a=a-d;
 if(a<=0 || c<=0)
 break;
}
if(c<=0)
printf("Yes\n");
else
printf("No\n");
return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    int h,w;
    cin>>h>>w;
    vvc s(h,vc(w));
    rep(i,h)rep(j,w)cin>>s[i][j];
    queue<P>q;
    q.push(P(0,0));
    vvi used(h,vi(w,INF));
    vvi d(h,vi(w,INF));
    d[0][0]=0;
    int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    while(q.size()){
        P now=q.front();q.pop();
        used[now.first][now.second]=1;
        if(now.first==h-1&&now.second==w-1)break;
        rep(i,4){
            int nx=now.first+dx[i],ny=now.second+dy[i];
            if(nx<0||nx>=h||ny<0||ny>=w)continue;
            if(s[nx][ny]=='#')continue;
            if(used[nx][ny]==1||d[nx][ny]!=INF)continue;
            d[nx][ny]=min(d[nx][ny],d[now.first][now.second]+1);
            q.push(P(nx,ny));
        }
    }
    if(d[h-1][w-1]==INF){
        cout<<-1<<endl;
        return 0;
    }


    int cnt=0;
    rep(i,h)rep(j,w){
        if(s[i][j]=='.')cnt++;
    }
    int ans=cnt-d[h-1][w-1]-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
s = int(input())

def func(n):
    if n%2 == 0:
        return n/2
    else:
        return 3*n+1
    
l = [s]
m = 2

while 1:
    n = func(l[-1])
    if n in l:
        print(m)
        exit()
    l.append(n)
    m += 1

Measured memory_bytes: 3060
use std::io;

const MOD: usize = 1_000_000_007;

fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    for i in 0..k {
        let m = Modulo::new(2001, MOD);
        println!("{}", m.comb(n - k + 1, i + 1) * m.comb(k - 1, i) % MOD);
    }
}

pub struct Modulo {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    modulo: usize,
}

impl Modulo {
    pub fn new(n: usize, modulo: usize) -> Self {
        let mut fact = vec![0; n + 1];
        let mut inv = vec![0; n + 1];
        let mut inv_fact = vec![0; n + 1];
        inv[1] = 1;
        for i in 2..n + 1 {
            inv[i] = inv[modulo % i] * (modulo - modulo / i) % modulo;
        }
        fact[0] = 1;
        inv_fact[0] = 1;
        for i in 0..n {
            fact[i + 1] = fact[i] * (i + 1) % modulo;
        }
        for i in 0..n {
            inv_fact[i + 1] = inv_fact[i] * inv[i + 1] % modulo;
        }
        Modulo {
            fact: fact,
            inv_fact: inv_fact,
            modulo: modulo,
        }
    }

    pub fn comb(&self, n: usize, r: usize) -> usize {
        if n < r { return 0; }
        self.fact[n] * self.inv_fact[r] % self.modulo * self.inv_fact[n - r] % self.modulo
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4476
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


Measured memory_bytes: 5624
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    L = list(map(int, input().split('/')))
    print('Heisei') if L <= [2019, 4, 30] else print('TBD')
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,x,y;
long long ans;
int main()
{
    //freopen("ce.in","r",stdin);
    cin>>a>>b>>c>>x>>y;
    ans=x*a+y*b;
    for(long long i=2;i/2<=max(x,y);i+=2) ans=min(ans,c*i+max(0ll,(x-i/2))*a+max(0ll,(y-i/2))*b);
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std; 

#define N 100010
#define M 65540

int n, G[N], x, ans, u, v, w; 
int f[N], inf, sum[20]; 

int dfs(int x) {
    if(!x) return 0; 
    if(f[x] < inf) return f[x]; 
    for(int i = 0 ; i < 16 ; i++) {
        if((x >> i) & 1) {
            for(int j = 0 ; j < 16 ; j++) {
                if (i != j && (x >> j) & 1) {
                    int p = i ^ j, u = x ^ (1 << i) ^ (1 << j) ^ (1 << p); 
                    if(x >> p & 1) f[x] = min(f[x], dfs(u) + 2); 
                    else f[x] = min(f[x], dfs(u) + 1); 
                }
            }
        }
    }   
    return f[x]; 
}

int main() {
    scanf("%d",&n); 
    for(int i = 1 ; i < n ; i++) {
        scanf("%d%d%d",  & u,  & v,  & w); 
        G[u] ^= w, G[v] ^= w; 
    }
    for(int i = 0 ; i < n ; i++) sum[G[i]]++; 
    for(int i = 1 ; i < 16 ; i++) {
        ans += (sum[i] >> 1); 
        x += (1 << i) * (sum[i] & 1); 
    }
    memset(f, 127, sizeof(f)); 
    inf = f[0]; 
    printf("%d\n", ans + dfs(x)); 
    //system("pause");
    return 0; 
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main(){
  
  int i,N;
  scanf("%d",&N);
  
  int A[N + 2];
  A[0] = 0;
  A[N + 1] = 0;
  for(i = 1 ; i <= N ; i++){
    scanf("%d",&A[i]);
  }
  
  int way[N],normal_way = 0; //normal_way:当初予定していた移動金額
  for(i = 1 ; i <= N + 1 ; i++){
    normal_way += abs(A[i - 1] - A[i]);
  }
  for(i = 1 ; i <= N ; i++){
    way[i] = normal_way - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]);
    printf("%d\n",way[i]);
  }
  
  return 0;
}

Measured memory_bytes: 1920
N, M = map(int, input().split())
ac = [0 for i in range(N)]
wa = [0 for i in range(N)]
for _ in range(M):
    p, s = input().split()
    if s == "AC":
        ac[int(p)-1] = 1
    elif s == "WA":
        if ac[int(p)-1] != 1:
            wa[int(p)-1] += 1
print(sum(ac), sum([i*j for i, j in zip(ac, wa)]))


Measured memory_bytes: 11344
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

MOD = 1000000007

n,m = get_nums_l()
breaks = map(int, sys.stdin.readlines()) if m>0 else []

dp = [0] * (n+1)

for a in breaks:
    dp[a] = -1

dp[n] = 1

for i in range(n-1, -1, -1):
    if dp[i] == -1:
        continue
    
    x = 0
    if dp[i+1] != -1:
        x += dp[i+1]
    
    if i <= (n-2) and dp[i+2] != -1:
        x += dp[i+2]
    
    dp[i] = x % MOD

print(dp[0])

Measured memory_bytes: 10800