akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

long long mod=1000000007;
long long Fermat(long long d,long long p){
    if (p==0){
        return 1;
    } else if (p==1){
        return d%mod ;
    } else if (p%2==0){
        return ((Fermat(d,p/2)%mod)*(Fermat(d,p/2))%mod)%mod;
    } else {
        return ((Fermat(d,p/2)%mod)*(Fermat(d,p/2))%mod)*d%mod;
    }
}

int main(void){
    long long n,first=0,second=0;
    scanf("%lld",&n);
    long long a[n+1],b[n],ans=n+1,minus;
    for (int i=0; i<n; i++){
        b[i]=0;
    }
    for (int i=0; i<n+1; i++){
        scanf("%lld",&a[i]);
        if (b[a[i]]==1){
            second=i+1;
        }
        b[a[i]]=1;
    }
    for (int i=0; i<n+1; i++){
        if (a[i]==a[second-1]){
            first=i+1;
            break;
        }
    }
    minus=n+first-second;
    printf("%lld\n",ans-1);
    for (long long i=2; i<=n+1; i++){
        ans=(((ans*(n+2-i))%mod)*Fermat(i,mod-2))%mod;
        long long anstmp=ans;
        if (first-1+n+1-second>=i-1){
            anstmp-=minus;
            if (anstmp<0){
                anstmp+=mod;
            }
            minus=(((minus*(n+first-second-i+1)%mod)*Fermat(i,mod-2))%mod)%mod;
        }
        printf("%lld\n",anstmp);
    }
	return 0 ;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int X,Y;
string board[110];
bool goodx[110],goody[110];
int main(){
  cin>>X>>Y;
  rep(i,X)cin>>board[i];
  rep(i,X) rep(j,Y){
    if (board[i][j]=='#'){
      goodx[i]=true;
      goody[j]=true;
    }
  }
  rep(i,X){
    if(goodx[i]){
      rep(j,Y){
        if(goody[j]){
          cout<<board[i][j];
        }
      }
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INF (1<<21)//j＼左シフトして値を大きくする
#define WHITE 0
#define GLAY 1
#define BLACK 2
#define NIL -1


int n,M[MAX][MAX];//隣接行列重みつく
void dij(){
  int u,mincost;
  int d[MAX],color[MAX];//dは最短距離ほじM[i][j]を入れる　　別からの辺のが短ければこうしん
  int i,v;
  int sum=0;
  for(i=0;i<n;i++){
    d[i]=INF;
    //親なし最短はinf
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GLAY;
  while(1){
    mincost=INF;
    u=NIL;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
        mincost=d[i];
        u=i;//最小距離を決定　閉路の場合は他の時み隣接していてdが保存してある最短から選ぶ
      }
    }

    if(mincost == INF)break;

    color[u]=BLACK;//uをTの頂点に追加
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INF){//uからvへ辺が追加
        if(d[v]>d[u]+M[u][v]){//今までのより今回のへんのが短ければ
          d[v]=d[u]+M[u][v];
          color[v]=GLAY;
        }
      }
    }
  }
    for(i=0;i<n;i++){

      printf("%d %d\n",i,d[i]);
    }
}


  int main(){
    int i,j,weight,k,v,u;
    scanf("%d",&n);
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        M[i][j]=INF;
      }
    }
    for(i=0;i<n;i++){
      scanf("%d%d",&u,&k);
      for(j=0;j<k;j++){
        scanf("%d%d",&v,&weight);
        M[u][v]=weight;
      }
    }
    dij();
    return 0;
  }



Measured memory_bytes: 2056
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



ll modpow(ll a,ll n){
    ll res = 1;
    while(n > 0){
        if(n&1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x,mod-2);
}

ll comb(ll n, ll k){
    ll ans1 = 1;
    ll ans2 = 1;
    rep(i,0,k) ans1 = ans1 * (n-i) % mod;
    rep(i,0,k) ans2 = ans2 * (i+1) % mod;
    return ans1*modinv(ans2) % mod;
}


int main(){
    FIN;
    ll n,k; cin >> n >> k;
    for(int i=1;i<=k;i++){
        cout << (comb(n-k+1,i) * comb(k-1,i-1))%mod << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenCoins solver = new BGoldenCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenCoins {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = Integer.parseInt(in.next());

            int y = x / 500;
            int z = (x - 500 * y) / 5;

            out.println(1000 * y + 5 * z);
        }

    }
}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
ll a, b, x;
signed main(){
    // [a, b] = [0, b] - [0, a)
    cin >> a >> b >> x;
    ll ret = b/x-a/x;
    if (a%x==0) ret+=1;
    cout << ret << endl;
    return 0;
}

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

int main(){
  long long int N;
  string S, T;
  cin >> S >> T;
  int ans = 0;
  if(S[0] == T[0]) ans++;
  if(S[1] == T[1]) ans++;
  if(S[2] == T[2]) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<cmath>

using namespace std;

int dp(int cur, int a, int b, int c, int *v, int *r, int n){
  if(cur == n){
  	return (min({a,b,c})>0) ? abs(a-v[0])+abs(b-v[1])+abs(c-v[2])-30 : pow(10,8.0);
  }
  
  int res1 = dp(cur+1, a, b, c, v, r, n);
  int res2 = dp(cur+1, a + r[cur], b, c, v, r, n) + 10;
  int res3 = dp(cur+1, a, b + r[cur], c, v, r, n) + 10;
  int res4 = dp(cur+1, a, b, c + r[cur], v, r, n) + 10;
  return min({res1, res2, res3, res4});
}


int main(){
  	int n;
   	int v[3];
	cin >> n >> v[0] >> v[1] >> v[2];
  
  	int r[n];
  	for(int i=0;i<n;i++) cin >> r[i];
  
	cout << dp(0, 0, 0, 0, v, r, n) <<endl;
	
    return 0;
}

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

int main(){
  char c;
  cin>>c;
  
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout<<"vowel"<<endl;
  }
  
  else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    vint a(N);
    REP(i,N) cin>>a[i];
    sort(ALL(a));

    int g=a[0];
    REP(i,N) g=__gcd(g,a[i]);
    if(K<=a[N-1] and K%g==0) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int k = in();
  string s; cin >> s;
  if(s.size() <= k) {
    cout << s;
  } else {
    cout << s.substr(0,k) << "...";
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 400005;

int32_t main() {
	int a, b, c;
	cin >> a >> b >> c;
	int dif = a-b;
	cout << (dif >= c ? 0 : c-dif) << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
    
int main(){
  int n,x; cin>>n>>x;
  vector<ll> num(n); int maxnum=x;
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(num[i]>maxnum) maxnum=num[i];
    num[i]-=x;
  }
  vector<vector<ll>> dp(n+1,vector<ll>(2*maxnum*n+1,0));//array cannot be used.
  dp[0][n*maxnum]=1;
  for(int i=1;i<=n;i++){
    for(int t=0;t<=n*maxnum*2;t++){
      if(t-num[i-1]<0 || t-num[i-1]>2*n*maxnum){
        dp[i][t]=dp[i-1][t];
      }else if(0<=t-num[i-1] && t-num[i-1]<=2*n*maxnum){
        dp[i][t]=dp[i-1][t]+dp[i-1][t-num[i-1]];
      }else{
        dp[i][t]=0;
      }
    }
  }
  cout<<dp[n][n*maxnum]-1<<endl;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define N 10000
using namespace std;

int main(){
  int n,cnt[N];
  set<int> s;
  while(1){
    cin>>n;
    if(!n)break;
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<n;i++)s.insert((i*i)%n);
    set<int>::iterator ite,ite2;
    for(ite=s.begin();ite!=s.end();ite++){
      for(ite2=s.begin();ite2!=s.end();ite2++){
	int a=*ite,b=*ite2;
	if(a==b)continue;
	int cal=a-b;
	if(cal<0)cal+=n;
	if(cal>(n-1)/2)cal=n-cal;
	cnt[cal]++;
      }
    }
    for(int i=1;i<=(n-1)/2;i++)cout<<cnt[i]<<endl;
    s.clear();
  }
  return 0;
}

Measured memory_bytes: 1472
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long a[110000];
    int n, k;
    int h[110000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    a[0] = 0;

    long long m;
    for (int i = 1; i < n; i++)
    {
        m = 1e10;
        for (int j = 1; j < k+1 && i-j >= 0; j++)
        {
            int u;
            u = a[i-j] + abs(h[i-j] - h[i]);
            if(u < m)
            {
                m = u;
            }
        }
        a[i] = m;
    }

    cout << a[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(a==b)cout << x;
  else if(b==x)cout << a;
  else cout << b;
  //if(a<=x&&x<=a+b)cout << "YES";
  //else cout << "NO";
}


Measured memory_bytes: 256
use io::*;

fn main() {
    let con =read_string();
    let mut sc =Scanner::new(&con);

    let a:i32 =sc.next();
    let b:i32 =sc.next();

    println!("{}",(a-1)*(b-1));
}

pub mod io {
    use std;
    use std::str::FromStr;
 
    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }
 
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
 
        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }
 
        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }
 
        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
 
    pub fn read_string() -> String {
        use std::io::Read;
 
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
 
    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}

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

int main(){

    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    for(int i=0;i<min(s.size(),t.size());i++){
        if(s[i]-t[i]>0){
            cout << "No" << endl;
            return 0;
        }else if(s[i]-t[i]<0){
            cout << "Yes" << endl;
            return 0;
        }
        if(i==min(s.size(),t.size())-1){
            if(s.size()<t.size()){
                cout << "Yes" << endl;
                return 0;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, W;
ll weight[110];
ll value[110];
ll dp[110][100010] = {0}; /////変数宣言はmain()の外側でしないとSegmentation faultが発生？

int main() {
    int N, W;
    ll weight[110];
    ll value[110];
    ll dp[110][100010] = {0}; /////変数宣言はmain()の外側でしないとSegmentation faultが発生？

    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];
    
    for (int i = 0; i < N; i++)
    {
        for (int sum_w = 0; sum_w <= W; sum_w++)
        {
            if (sum_w >= weight[i]) dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-weight[i]] + value[i]);
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }       
    }
    cout << dp[N][W] << endl;
    
    return 0;
}

Measured memory_bytes: 89572
#include <bits/stdc++.h>
using namespace std;
template <typename T > void read(T &t) {
	char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	t=0;
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9');
}
typedef long long ll;
const ll INF=1LL<<50;
int n;
map<ll,int> M;
map<ll,int> cnt;
ll ans;
ll solve(ll x) {
	for (ll i=2;;i++) {
		ll t=i*i*i;
		if (t>x) break;
		while (x%t==0) x/=t;
	}
	return x;
}
ll S(ll x) {
	ll l=1,r=100000;
	while (l<r) {
		ll mid=(l+r+1)>>1;
		if (mid*mid<=x) l=mid;
		else r=mid-1;
	}
	return l;
}
ll T(ll x) {
	ll A=1,B=1;
	for (ll i=2;;i++) {
		if (i*i*i>x) break;
		int ss=0;
		while (x%i==0) {
			x/=i; ss++;
		}
		if (ss==1) A*=i; else if (ss==2) B*=i;
	}
	ll tmp=S(x);
	if (tmp*tmp==x) B*=tmp;
	else A*=x;
	ll res=A*B;
	if (res>INF/A+1) res=INF; else res*=A;
	return res;
}

int main() {
	//freopen("2.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) {
		ll x; read(x);
		x=solve(x);
		//printf("%lld\n",x);
		M[x]++;
	}
	ans=0;
	for (map<ll,int>::iterator it=M.begin();it!=M.end();it++) {
		ll x=it->first;
		if (cnt[x]) continue;
		ll t=T(x);
		if (x!=t) ans+=max(it->second,M[t]);
		else ans++;
		cnt[t]++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

const int N = 100000;
const int M = 100000;

vector<int> graph[N];
bool visited[N];

void dfs(int u) {
  for (auto v: graph[u]) {
    if (visited[v]) continue;
    visited[v] = true;
    dfs(v);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i=0; i<m; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int cnt = 0;
  for (int i=0; i<n; i++) {
    if (visited[i]) continue;
    cnt ++;
    dfs(i);
  }
  cout << cnt-1 << endl;
  return 0;
}


Measured memory_bytes: 9708
from collections import deque
n, m, k = map(int, input().split())
friends = [[] for _ in range(n)]
blocks = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    friends[a-1].append(b-1)
    friends[b-1].append(a-1)
for _ in range(k):
    c, d = map(int, input().split())
    blocks[c-1].append(d-1)
    blocks[d-1].append(c-1)


grp_idx = [-1]*n
grp_szs = []
grp = 0
for i in range(n):
    if grp_idx[i]>=0:
        continue
    queue = deque([i])
    grp_idx[i] = grp
    tmp = 0
    while len(queue)>0:
        node = queue.popleft()
        for c_node in friends[node]:
            if grp_idx[c_node]>=0:
                continue
            grp_idx[c_node] = grp
            tmp += 1
            queue.append(c_node)
    grp_szs.append(tmp)
    grp += 1
ans = []
for i in range(n):
    tmp = grp_szs[grp_idx[i]]
    for j in friends[i]:
        if grp_idx[j]==grp_idx[i]:
            tmp -= 1
    for j in blocks[i]:
        if grp_idx[j]==grp_idx[i]:
            tmp -= 1
    ans.append(tmp)
print(*ans)

Measured memory_bytes: 47188
#include<stdio.h>

typedef struct dice {
  int top ; // 1
  int south ; // 2
  int east ; // 3
  int west ; // 4
  int north ; // 5
  int bottom ; // 6
} dice ;

dice roll( dice *a, char x )
{
  dice b = *a ;
  if( x == 'N' ){
    a->top = b.south ;
    a->south = b.bottom ;
    a->bottom = b.north ;
    a->north = b.top ;
  }else if ( x == 'S'){
    a->top = b.north ;
    a->north = b.bottom ;
    a->bottom = b.south ;
    a->south = b.top ;
  }else if ( x == 'E'){
    a->top = b.west ;
    a->west = b.bottom ;
    a->bottom = b.east ;
    a->east = b.top ;
  }else if ( x == 'W'){
    a->top = b.east ;
    a->east = b.bottom ;
    a->bottom = b.west ;
    a->west = b.top ;
  }
  return *a ;
}

int main()
{
  dice d ;
  scanf("%d%d%d%d%d%d",
           &d.top,&d.south,&d.east,&d.west,&d.north,&d.bottom) ;
  char command[100] ;

  char line ; //　改行文字捨てる用
  scanf("%c", &line) ; // 改行文字

  int i  = 0 ; // roop variant
  char c ;
  while( c = getchar() , c != '\n' ){
    command[i] = c ;
    i++ ;
  }

  int j ;
  for( j = 0 ; j < i ; j++ ){
    roll( &d, command[j]) ;
    // printf("%d %d %d %d %d %d\n",d.top,d.south,d.east,d.west,d.north,d.bottom);
  }

  printf("%d\n", d.top) ;

  return 0 ;
}



Measured memory_bytes: 2144
#include<stdio.h>
#include<math.h>
int main()
{
    int N,i,c=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
        if((int)(log10(i))%2==0)
        c++;
    printf("%d\n",c);
    return 0;
}



Measured memory_bytes: 384
N = int(input())
color_list=list(map(int,input().split()))

tmp_counter = 1
total_counter = 0
before_color =0
for color in color_list:
        if color == before_color:
            tmp_counter += 1
        else:
            total_counter += tmp_counter // 2
            tmp_counter=1         
        before_color = color
total_counter += tmp_counter // 2
        
print(total_counter)
            

Measured memory_bytes: 3060
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec fac, finv;

ll PowMod(ll a, ll n){
	if(n == 1) return a;
	if(n%2 == 0) return PowMod(a*a%MOD, n/2);
	return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
	return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

void init(ll n = 2e6){
	fac.resize(n+1);
	fac[0] = 1;
	repn(i, n) fac[i] = (fac[i-1]*i)%MOD;
	finv.resize(n+1);
	finv[n] = PowMod(fac[n], MOD-2);
	repr(i, n) finv[i] = (finv[i+1]*(i+1))%MOD;
	finv[0] = 1;
}

int main(void){
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = PowMod(2, n);
	ans--;
	init();

	ll c = 1;
	rep(i, a){
		c *= (n-i);
		c %= MOD;
	}
	c *= finv[a];
	c %= MOD;
	ll d = 1;
	rep(i, b){
		d *= (n-i);
		d %= MOD;
	}
	d *= finv[b];
	d %= MOD;

	ans -= c+d;
	ans %= MOD;
	ans += MOD;
	ans %= MOD;
	co(ans);

	return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    set<char> s(S.begin(), S.end());
    if(S.size() == 26){
        while(S.size()){
            char c = S.back();
            S.pop_back();
            for(char d=c+1;d<='z';d++){
                if(s.count(d) == 0){
                    cout << S << d << endl;
                    return 0;
                }
            }
            s.erase(c);
        }
        cout << -1 << endl;
    }else{
        for(int i=0;i<26;i++){
            if(s.count(i + 'a') == 0){
                cout << S << char(i + 'a') << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solveC();
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int tmp = sc.nextInt();
			if (!map.containsKey(tmp)) {
				map.put(tmp, 0);
			}
			map.put(tmp, map.get(tmp)+1);
		}
		long sum = 0L;
		for (Map.Entry<Integer, Integer> e : map.entrySet()) {
			int key = e.getKey();
			int value = e.getValue();
			if (key <= value) {
				sum += value - key;
			} else {
				sum += value;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 61452
from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import connected_components

N, M = map(int, input().split())

g = lil_matrix((N, N))
for _ in range(M):
  a, b = list(map(int, input().split()))
  g[a - 1, b - 1] = 1

c = 0
for a, b in zip(*g.nonzero()):
  g[a, b] = 0
  c += connected_components(g, return_labels=False) != 1
  g[a, b] = 1
  
print(c)  

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
$n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $v) {
	$v = (int)$v;
	if ($v % 2 === 0) {
		if ($v % 3 !== 0 && $v % 5 !== 0) {
			echo 'DENIED';
			exit();
		}
	}
}
echo 'APPROVED';

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

a = []
ans = []

for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a)
a_max1 = a_sorted[-1]
a_max2 = a_sorted[-2]
for a_value in a:
    if a_value != a_max1:
        ans.append(str(a_max1))
    else:
        ans.append(str(a_max2))

print("\n".join(ans))




Measured memory_bytes: 85468
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	vector<char> s(n);
	int r=0,b=0;
	REP(i,n){
		cin>>s[i];
		if(s[i]=='R') r++;
		else b++;
	}
	
	if(r>b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
nums=gets.strip.split(" ").map do |i|
  i.to_i
end
n=nums[0]
k=nums[1]
a=Array.new(n,0)
k.times do |i|
  d = gets.strip.to_i
  nums=gets.strip.split(" ").map do |j|
    j.to_i
  end
  d.times do |l|
    a[nums[l]-1]+=1
  end
end

sum=0

a.each do |i|
  sum+=1 if i==0
end
puts sum

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

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

vector<int> a(n);
for(int &x:a)
{
	scanf("%d",&x);
}

vector<bool> dp(k+1,false);
for(int stone=0;stone<=k;stone++)
{
	for(int x:a)
	{
		if(stone>=x && !dp[stone-x] )
			 dp[stone]=true;
	}
}

(dp[k]?cout<<"First":cout<<"Second");


	return 0;
}

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


int main(){
  int n,k;
  cin>>n>>k;
  long long int val=0;
  for(int i=0;i<n-1;i++){
    val=val+(val/(k-1)+1);
  }
  cout<<val<<endl;
  return 0;
}

Measured memory_bytes: 3112
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    T, A = 1, 1

    for i in range(N):
        t, a = map(int, input().split())
        m = max((T + t - 1) // t, (A + a - 1) // a)
        T, A = t * m, a * m
    print(T + A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()

{
	int n;
	long long a;
	cin >> n;
	vector<long long> arr(n);
	
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end());

	cout << arr[n - 1] - arr[0] << endl;

	return 0;

}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

signed main(){
	cout<<fixed<<setprecision(7);
	
	int n, a, b;
	
	cin>>n>>a>>b;
	
	cout<<min(n*a,b)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m=n1()
a=n1()

print(n-sum(a) if n-sum(a)>=0 else -1)

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

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

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

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

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

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

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int dp[3050][3050];
    REP(i, 3050) REP(j, 3050) dp[i][j] = 0;

    double num = 0;
    pair<int, int> ans;
    for(int i = 0; 100*a*i <= f; i++){
        for(int j = 0; 100*b*j + 100*i <= f; j++){
            for(int k = 0; 100*b*j + 100*a*i + c*k <= f; k++){
                for(int l = 0; 100*b*j + 100*a*i + c*k + d*l <= f; l++){
                    if(c*k + d*l > 100*(i*a + j*b) * e / 100) continue;

                    if(num <= (double)100*(k*c+l*d) / (100*(i*a+j*b) + (k*c+l*d))){
                        num = (double)100*(k*c+l*d) / (100*(i*a+j*b) + (k*c+l*d));
                        ans = make_pair(100*(i*a+j*b) + ((k*c+l*d)), (k*c+l*d));
                    }
                }
            }
        }
    }
    cout << ans.first << " " << ans.second << endl;

}


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

const int toomanybottlesofthiswinewecantpronounce = 100;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	vector < int > a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int j = 0; j < min(k, toomanybottlesofthiswinewecantpronounce); ++j) {
		vector < int > b(n + 1, 0);
		for (int i = 0; i < n; ++i) {
			if (a[i] > i)
				++b[0];
			else
				++b[i - a[i]];
			if (i + a[i] + 1 > n)
				--b[n];
			else
				--b[i + a[i] + 1];
		}
		for (int i = 1; i < n; ++i)
			b[i] = b[i - 1] + b[i];
		b.resize(n);
		a = b;
	}
	for (int i = 0; i < n; ++i)
		cout << a[i] << ' ';
	cout << '\n';
}


Measured memory_bytes: 4980
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n,m = Mi()
h = Li()
flag = [1]*(n)
for i in range(m):
  a,b = Li()
  if h[a-1] == h[b-1]:
    flag[a-1] = flag[b-1] = 0
  elif h[a-1] > h[b-1]:
    flag[b-1] = 0
  else:
    flag[a-1] = 0
print(sum(flag))

Measured memory_bytes: 18452
# -*- coding: utf-8 -*-
def solve():
    a,b,c,d = tuple(map(int, input().split()))

    p, q = c-a, d-b
    r, s = 0*p-q, p+0*q
    t, u = 0*r-s, r+0*s
    v, w = 0*t-u, t+0*u

    return str(' '.join(map(str,[c+r,d+s,c+r+t,d+s+u])))

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer,Boolean> map = new HashMap<>();
        String ans = "YES";
        for(int i = 0;i<n;i++){
            int num = sc.nextInt();
            if(map.get(num) == null){
                map.put(num, true);
            }else{
                ans = "NO";
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 100752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class  Main {
    static Integer n, arr[];
    static long mod = 998244353;

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;


        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        Set<String> hs=new HashSet<>();
        for (int i=0;i<n;i++)
        {
            hs.add(sc.next());
        }
        System.out.println(hs.size());
    }
}

Measured memory_bytes: 71652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int n;
int a[21][21];
 
int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
  	ll mod=1e9+7;
	for (int i = 0; i < n; ++i)
	{
	  for(int j=0; j<n; j++) cin>>a[i][j];
	}
  	vector<ll> dp(1<<n,0);
  dp[0]=1;
  	for(int i=0; i<(1<<n)-1; i++){
      int per=__builtin_popcount(i);
      for(int j=0; j<n; j++){
        if(a[per][j] && !(i&(1<<j))){
          dp[i|(1<<j)]=dp[i|(1<<j)]+dp[i];
          dp[i|(1<<j)]%=mod;
        }
      }
    }
  	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 16640
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
  int id;
  struct node *parent;
  struct node *leftMostChild;
  struct node *rightSibling;
} *nodePointer;
nodePointer init(int);
nodePointer make1node(void);
void printNode(nodePointer);
int getDepth(nodePointer);
void printType(nodePointer);
void printChild(nodePointer);
int main(void)
{
  int i,j;//counter
  int n;//the number of nodes
  int id;//id of each node
  int k;//the number of children
  int c1,c2;//id of children
  nodePointer *arr;
  scanf("%d",&n);
  arr=(nodePointer*)malloc(sizeof(nodePointer)*n);
  for(i=0;i<n;i++) arr[i]=init(i);
  for(i=0;i<n;i++)
    {
      scanf("%d",&id);
      scanf("%d",&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d",&c1);
	  if(j==0)
	    {
	      arr[id]->leftMostChild=arr[c1];
	    }
	  else
	    {
	      arr[c2]->rightSibling=arr[c1];
	    }
	  arr[c1]->parent=arr[id];
	  c2=c1;
	}
    }
  for(i=0;i<n;i++) printNode(arr[i]);
  return 0;
}
nodePointer init(int id)
{
  nodePointer p;
  p=make1node();
  p->id=id;
  p->parent=NULL;
  p->leftMostChild=NULL;
  p->rightSibling=NULL;
  return p;
}
nodePointer make1node(void)
{
  nodePointer p=(nodePointer)malloc(sizeof(struct node));
  return p;
}
void printNode(nodePointer p)
{
  printf("node %d: ",p->id);
  if(p->parent!=NULL) printf("parent = %d, ",p->parent->id);
  else printf("parent = -1, ");
  printf("depth = %d, ",getDepth(p));
  printType(p);
  printf(", ");
  printChild(p);
  printf("\n");
}
int getDepth(nodePointer p)
{
  if(p->parent==NULL) return 0;
  return 1+getDepth(p->parent);
}
void printType(nodePointer p)
{
  if(p->parent==NULL) printf("root");
  else if(p->leftMostChild==NULL) printf("leaf");
  else printf("internal node");
}
void printChild(nodePointer p)
{
  printf("[");
  if(p->leftMostChild!=NULL)
    {
      p=p->leftMostChild;
      printf("%d",p->id);
      for(;p->rightSibling!=NULL;p=p->rightSibling) printf(", %d",p->rightSibling->id);
    }
  printf("]");
}



Measured memory_bytes: 7216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;A.push_back(a);
    }
    
    ll start=N-1,last=0;
    REP(i,N-1){
        if(A[i]<A[i+1]){
            start=i;
            break;
        }
    }
    REP(i,N-1){
        if(A[i]<A[i+1]){
            last=i+1;
        }
    }
    
    ll money=1000,stack=0;
    
    if(start<=last){
        stack+=money/A[start];
        money-=(money/A[start])*A[start];
        for(ll i=start+1;i<last;i++){
            if(A[i]>A[i+1]){
                money+=stack*A[i];
                stack=0;
            }
            
            if(A[i]<A[i+1]){
                stack+=money/A[i];
                money-=(money/A[i])*A[i];
            }
        }
        
        money+=stack*A[last];
        stack=0;
        
    }
    
    cout << money << endl;
    
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define lli long long int 
#define dl 1000000007

lli maxi(lli a,lli b){
    if(a>=b)return a;
    return b;
}
lli mini(lli a,lli b){
    if(a<=b)return a;
    return b;
}

int main(){
    int n,k;
    cin>>n>>k;
    vector<lli> arr(n,0);
    lli sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    vector<lli> a(k+1,0);
    a[0]=1;
    for(int i=0;i<n;i++){
        vector<lli> b(k+1,0);
        b[0]=a[0];
        lli sum=a[0];
        for(int j=1;j<=k;j++){
            sum=(sum+a[j])%dl;
            b[j]=sum;
        }
        for(int j=1;j<=k;j++){
            if(j<=arr[i]){
                a[j]=b[j];
            }else{
                a[j]=b[j]-b[j-arr[i]-1];
                if(a[j]<0)a[j]=a[j]+dl;
            }
        }
    }
   cout<<a[k]<<endl;
}

Measured memory_bytes: 1792
l = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
bool = False
for i in range(-100,101):
    if max(x) < i and min(y) >= i and l[2] < i and l[3] >= i:
        bool = True
        break
if bool == True:
    print('No War')
else:
    print('War')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010
#define PI 3.1415926535
ll n,k;
ll a[M],f[M];
bool ok(ll x){
	ll val=k;
	rep(i,0,n)if(a[i]*f[i]>x)val-=(a[i]-(x/f[i]));
	return val>=0;
}
int main(){
	IOS;
	cin>>n>>k;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)cin>>f[i];
	sort(a,a+n);
	sort(f,f+n,greater<>());
	ll lo=0,hi=inf,m,ans=0;
	while(lo<=hi){
		m=(lo+hi)/2;
		if(ok(m))hi=m-1,ans=m;
		else lo=m+1;
	}
	cout<<ans;
	
	return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

const ll mod = 1e9+7;
struct mint
{
    ll x;
    mint(ll x=0) : x((x%mod+mod)%mod){}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    ll val(){ return x; }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x;}
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
};

struct Func {
    ll mod;
    vector<ll> fact, ifact;
    ll mod_pow(ll x, ll n){
        ll ans = 1;
        while(n){
            if(n & 1) ans = ans*x%mod;
            x = x*x%mod;
            n >>= 1;
        }
        return ans;
    }
    Func(ll n, ll mod) : fact(n+1), ifact(n+1), mod(mod) {
        fact[0] = 1;
        for(ll i = 1; i <= n; i++) fact[i] = fact[i-1] * i % mod;
        ifact[n] = mod_pow(fact[n], mod-2);
        for(ll i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i % mod;
    }
    ll comb(ll n, ll k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
    ll perm(ll n, ll k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k]%mod;
    }
};

int main(){
    int k; string s; cin >> k >> s;
    int n = s.size();

    Func f = Func(n+k, mod);
    mint p25 = 25;
    mint p26 = 26;
    mint ans = 0;
    for(int i = 0; i <= k; i++) {
        mint tmp = f.comb(n+k-i-1, n-1);
        tmp *= p26.pow(i);
        tmp *= p25.pow(k-i);
        ans += tmp;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35564
#include<iostream>
#include<vector>

using namespace std;

int ze(int x) {

	if (x < 0)
		return -1 * x;

	else
		return x;

}

int main(void) {

	int N, K,u,ans=0;
	cin >> N >> K;
	vector<int>x(N);
	
	for (int i = 0; i < N; i++) {

		cin >> x[i];

	}

	for (int i = 0; i < N; i++) {

		int c;

		c = K - x[i];

		u = ze(c);

		if (u > x[i])
			ans = ans + x[i]*2;

		else
			ans = ans + u*2;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
class Heap
	require 'forwardable'
	extend Forwardable

	def initialize
		@array = []
		@index = {}
	end

	def add(obj, key)
		@array << [obj, key]
		@index[obj] = @array.size - 1
		lift_up(@array.size - 1)
	end

	def swap(i, j)
		u = @array[i]
		v = @array[j]
		@index[u[0]], @index[v[0]] = j, i
		@array[i], @array[j] = v, u
	end

	def lift_up(i)
		return if i == 0
		j = (i - 1) / 2
		if (@array[i][1] <=> @array[j][1]) < 0
			swap(i, j)
			lift_up(j)
		end
	end

	def del_min
		raise "heap is empty!" if empty?
		min = @array[0]
		if size > 1
			swap(0, @array.size-1)
			@array.pop
			lift_down(0)
		else
			@array.pop
		end
		@index.delete(min[0])
		min
	end

	def inc_key(obj, diff)
		i = @index[obj]
		@array[i][1] += diff
		lift_down(i)
	end

	def dec_key(obj, diff)
		i = @index[obj]
		@array[i][1] -= diff
		lift_up(i)
	end

	def update_key(obj, new_key)
		i = @index[obj]
		return unless i
		return if (new_key <=> @array[i][1]) >= 0
		@array[i][1] = new_key
		lift_up(i)
	end

	def min_obj
		@array[0][0]
	end

	def min_key
		@array[0][1]
	end

	def lift_down(i)
		j = 2 * i + 1
		k = j + 1
		if k >= size
			return if j >= size
			if (@array[i][1] <=> @array[j][1]) > 0
				swap(i, j)
				lift_down(j)
			end
		else
			l = ((@array[j][1] <=> @array[k][1]) < 0 ? j : k)
			if (@array[i][1] <=> @array[l][1]) > 0
				swap(i, l)
				lift_down(l)
			end
		end
	end

	def_delegators :@array, :empty?, :size
end

module Graphical
	require 'set'
	def prim(start)
		h = Heap.new
		h.add(start, 0)
		reached = Set[start]
		tree_len = 0

		until h.empty?
			u, key = h.del_min
			tree_len += key

			each_out_connection_of(u){|v, d|
				if reached.include?(v)
					h.update_key(v, d)
				else
					h.add(v, d)
					reached << v
				end
			}
		end
		tree_len
	end
end

class Graph
	include Graphical

	def initialize(*options)
		@options = Set[*options]
	end

	def add_node(property = {})
		Node.new(property)
	end

	def add_edge(u, v, property = {})
		e = Edge.new(u, v, property)
		u.add_edge(e)
		v.add_edge(e)
		e
	end
	
	def del_edge(e)
		u, v = e.opposite.keys
		u.del_edge(e)
		v.del_edge(e)
		e
	end

	class Node
		def initialize(property)
			@property = property
			@edges = Set.new
		end

		def add_edge(e)
			@edges << e
		end

		def del_edge(e)
			@edges.delete(e)
		end

		def to_s
			@property[:name] || super
		end

		def each_edge
			@edges.each{|e| 
				yield e
			}
		end

		attr_reader :property
	end

	class Edge
		def initialize(u, v, property)
			@opposite = {u => v, v => u}
			@property = property
		end
		attr_reader :opposite, :property

		def to_s
			@property[:name] || super
		end

		def length
			@property[:length] || 1
		end
	end

	def each_out_connection_of(u)
		u.each_edge{|e|
			yield(e.opposite[u], e.length)
		}
	end

	alias :each_in_connection_of :each_out_connection_of
end

loop do
    n = gets.to_i
    break if n == 0
    m = gets.to_i
    
    g = Graph.new
    nodes = (1..n).map {|i| g.add_node}
    m.times do
        i, j, d = gets.split(?,).map(&:to_i)
        g.add_edge(nodes[i], nodes[j], {:length => d / 100 - 1})
    end

    p g.prim(nodes[0])
end

Measured memory_bytes: 11696
import math

x = int(input())

if x == 2:
    print(2)
    exit()

elif x%2 == 0:
    ans = x+1

else:
    ans = x


while True:
    for i in range(3, int(math.sqrt(ans))+1, 2):
        if ans%i == 0:
            ans += 2
            break
    else:
        print(ans)
        exit()


        

Measured memory_bytes: 9172
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

const int64_t cc = pow( 10, 9 );

int main()
{
    int64_t a,b,c,d;
    std::cin>> a;

    std::vector< std::vector< std::pair< int64_t, int64_t > > > list( a );
    std::vector< int64_t > s_list;

    for( int i = 0; i < a; i++ )
    {
        std::cin>> b;

        for( int r = 0; r < b; r++ )
        {
            std::cin>> c;
            std::cin>> d;
            std::pair< int64_t, int64_t > dd( c, d );
            list[i].push_back( dd );
        }
    }

    int count = 0;
    std::queue< std::vector< int64_t > > ll;
    ll.push( s_list );

    while( !ll.empty() )
    {
        std::vector< bool > ss( a, true );
        std::vector< int64_t > current = ll.front();
        ll.pop();

        for( int i = 0; i < current.size(); i++ )
        {
            ss[current[i]-1] = false;
        }

        std::vector< int64_t > check( a, -1 );
        bool ok = true;

        for( int r = 0; r < list.size(); r++ )
        {
            for( int t = 0; t < list[r].size(); t++ )
            {
                if( ss[r] )//正直者
                {
                    if( ss[list[r][t].first-1]
                        && list[r][t].second == 0 )
                    {
                        ok = false;
                        break;
                    }
                    else if( !ss[list[r][t].first-1]
                        && list[r][t].second == 1 )
                    {
                        ok = false;
                        break;
                    }
                }
            }

            if( !ok )
            {
                break;
            }
        }

        if( ok )
        {
            count = a - current.size();
            break;
        }

        int nn;

        if( current.empty() )
        {
            nn = 0;
        }
        else
        {
            nn = current.back();
        }
        
        for( int i = nn + 1; i <= a; i++ )
        {
            std::vector< int64_t > next = current;
            next.push_back( i );
            ll.push( next );
        }
    }

    std::cout<< count;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) (a)<=(n)&&(n)<(b)
typedef long long ll;
using namespace std;
const int inf=1e9;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	set<int> s;
	for(int i=1;i<=101;i++){
		int mod = a*i % b;
		if(mod == c) {
			p("YES");
			break;
		}
		if(s.find(mod)!=s.end()){
			p("NO");
			break;
		}
		s.insert(mod);
	}
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
# import sys
import math


N, M = [int(x) for x in stdin.readline().rstrip().split()]
H = list(map(int, input().split()))
d = {}
for i in range(M):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if H[a-1] < H[b-1]:
        d[a] = d.get(a, 0)+1
    elif H[a-1] > H[b-1]:
        d[b] = d.get(b, 0)+1
    else:
        d[a] = d.get(a, 0)+1
        d[b] = d.get(b, 0)+1
print(len(H)-len(d))


Measured memory_bytes: 85052