akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let mut dist: HashMap<String, i64> = HashMap::new();
  let n = read::<i64>();
  for _ in 0..n {
    let word = read::<String>();
    let current = dist.entry(word).or_insert(0);
    *current += 1;
  }

  let m = read::<i64>();
  for _ in 0..m {
    let word = read::<String>();
    let current = dist.entry(word).or_insert(0);
    *current -= 1;
  }

  let mut ans_max = 0;
  let mut ans = "";
  for (k, v) in dist.iter() {
    if ans_max < *v {
      ans = k;
      ans_max = *v;
    }
  }

  println!("{}", ans_max);
}




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

int main() {
    long long n; cin >> n;
    map<int, long long> m;
    for (int i = 0; i < n; i++) {
        int a; cin >> a; m[a]++;
    }
    vector<long long> w;
    for (auto &x: m) w.emplace_back(x.second);
    sort(w.rbegin(), w.rend());
    vector<long long> c(w.size()+1, 0);
    for (int i = 0; i < w.size(); i++) c[i+1] = c[i] + w[i];
    for (int q = 1; q <= n; q++) {
        if (w.size() < q) {
            cout << 0 << "\n";
            continue; 
        }

        long long remain = n - c[q];
        int left = 0; int right = n+1;
        while (right - left > 1) {
            int mid = (right + left) / 2;
            int l = -1; int r = q;
            while (r - l > 1) {
                int mi = (r + l) / 2;
                if (w[mi] > mid) l = mi;
                else r = mi;
            }
            long long val = (long long) (q-r) * mid - (c[q] - c[r]);
            if (remain >= val) left = mid;
            else right = mid; 
        }
        cout << left << "\n";
    }
    return 0;
}

Measured memory_bytes: 24684
function Main(input){
  input = input.split(' ').map(num => Number(num));

  var array = ['a'];

  input.map(compare => {
    if(input.indexOf(compare) == input.lastIndexOf(compare)){
      array.push(compare);
    }
});
  
  var total = array.length;
  if(total > 3) {
      total = total - 1;
  }
  console.log(total);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N, D = map(int,input().split())
zahyo = [list(map(int,input().split())) for i in range(N)]

ans=0
kyori=0

#
for i in range(N-1):
    
  for j in range(i+1,N):
    
    for k in range(D):
      kyori+=(zahyo[i][k]-zahyo[j][k])**2
    if (kyori**0.5).is_integer():
      ans+=1
      
    kyori=0
    
print(ans)

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

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t;
    cin>>n>>x>>t;
    int ans = n/x;
    if(n%x != 0){
        ans++;
    }
    cout<<(ans)*t;
    return 0;
}

Measured memory_bytes: 3648
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  3 20:25:27 2019
//
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	if N == 1 && M == 1 {
		fmt.Println(1)
	} else if N == 1 || M == 1 {
		fmt.Println(N*M - 2)
	} else {
		fmt.Println(N*M - 2*N - 2*M + 4)
	}
}


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

void no(){
	puts("No");
	exit(0);
}

const int N = 1e6+10;
char str[N];
int main(){
	int ns;
	cin >> ns;
	
	vector<pair<int,int>> pos;
	vector<tuple<int,int,int>> neg;
	
	int soma = 0;
	
	fr(iii,ns){
		int n; scanf("%s", str);
		n = strlen(str);
		
		int ac = 0;
		int max_sub = 0;
		fr(i,n){
			if(str[i]=='(') ac++;
			else ac--;
			max_sub = min(max_sub,ac);
		}
		soma+=ac;
		if(ac>=0){
			pos.emplace_back(-max_sub,ac);
		} else{
			neg.emplace_back(-max_sub+ac,-max_sub,ac);
		}
	}
	
	if(soma!=0){
		puts("No");
		return 0;
	}
	sort(all(pos));
	sort(all(neg),greater<tuple<int,int,int>>());
	
	int ac = 0;
	for(auto &par : pos){
		int max_sub, add_tot; tie(max_sub,add_tot) = par;
		/*prin(ac);
		prin(max_sub);
		prin(add_tot);
		cout << endl;*/
		if(max_sub>ac) no();
		ac+=add_tot;
	}
	//cout << "Neg" << endl;
	for(auto &par : neg){
		int dif, max_sub, add_tot; tie(dif,max_sub,add_tot) = par;
		/*prin(ac);
		prin(max_sub);
		prin(add_tot);
		cout << endl;*/
		if(max_sub>ac) no();
		ac+=add_tot;
	}
	puts("Yes");
}

Measured memory_bytes: 13276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)80+5;
int a[maxn][maxn],b[maxn][maxn],dp[maxn][maxn][maxn*maxn*2];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,w;cin>>h>>w;
    rep(i,1,h)rep(j,1,w)cin>>a[i][j];
    rep(i,1,h)rep(j,1,w)cin>>b[i][j];
    dp[1][1][abs(a[1][1]-b[1][1])]=1;
    rep(i,1,h)rep(j,1,w)rep(k,0,80*80*2)if(dp[i][j][k]){
        if(i<h){
            dp[i+1][j][abs(k+a[i+1][j]-b[i+1][j])]=1;
            dp[i+1][j][abs(k-a[i+1][j]+b[i+1][j])]=1;
        }
        if(j<w){
            dp[i][j+1][abs(k+a[i][j+1]-b[i][j+1])]=1;
            dp[i][j+1][abs(k-a[i][j+1]+b[i][j+1])]=1;
        }
        
    }
    rep(k,0,80*80*2)if(dp[h][w][k]){cout<<k<<endl;break;}
}
/* 
网格上，每个格子里有两个数字。从1，1 走到h,w ,每经过一格 选一个到集合a，一个到b，问最后两个集合的差绝对值最小是多少。
最优性不能传递？
注意到所有数字的范围都是80以内，把数值也作为状态
wr 最大值是什么？
bool 表：DP[i][j][k] = Can the unbalancedness of a path to square (i, j) be k?

bitset 加速。
 */

Measured memory_bytes: 385408
#include<iostream>
using namespace std;
int main()
{
	string c;
	cin>>c;
	if(c=="++++")cout<<4;
	if(c=="+++-")cout<<2;
	if(c=="++-+")cout<<2;
	if(c=="+-++")cout<<2;
	if(c=="-+++")cout<<2;	
	if(c=="--++")cout<<0;
	if(c=="-+-+")cout<<0;
	if(c=="-++-")cout<<0;
	if(c=="+--+")cout<<0;
	if(c=="+-+-")cout<<0;
	if(c=="++--")cout<<0;
	if(c=="+---")cout<<-2;
	if(c=="-+--")cout<<-2;
	if(c=="--+-")cout<<-2;
	if(c=="---+")cout<<-2;
	if(c=="----")cout<<-4;
	return 0;
}

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

int main(){

    double L, R, d;
    int l_pepe, r_pepe;
    int add_n = 0;
    std::cin >> L >> R >> d;

    l_pepe = (int)round(floor(L/d));
    r_pepe = (int)round(floor(R/d));

    if((int)L%(int)d == 0.0){
        add_n = 1;
    }

    std::cout << r_pepe - l_pepe + add_n; 

}

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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int k, a, b;
	cin >> k >> a >> b;
	cout << (a/k != b/k || a%k==0 ? "OK\n" : "NG\n");
}

Measured memory_bytes: 3652
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int main(void){
    int a,b;
    cin >> a >> b;
    cout << (a+b+1)/2 << endl;
}

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

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

int main() {
	long long int N, K;
	cin >> N >> K;

	long long int temp;
	int min = N;
	for (int i = 0;; i++) {
//		temp = abs(N - K);
//		if (N >= temp) {
//			if(N > K){
//				N %= K;
//			}
//			else{
//				N = temp;
//			}
//		}
//
//		if(min > N){
//			min = N;
//		}
//		else{
//			break;
//		}

		temp = abs(N -K);
		if(N - K <= 0){
			if(N >= temp){
				N = temp;
			}


			break;
		}
		else{
			N %= K;
		}

	}

	cout << N << endl;

}


Measured memory_bytes: 256
function Main(input) {
    var result;
    const N = parseInt(input.shift())
    const A = parseInt(input.shift())
    const B = parseInt(input.shift());
    const C = parseInt(input.shift())
    const D = parseInt(input.shift())
    const S = input[0];
    
    // 2連続があったらOUT
    const LastIndex = Math.max(C,D);
    var prevStone = false;
    for (var i = A - 1; i < LastIndex; i++) {
        var element = S.charAt(i);
        if(element === "#") {
            if(prevStone) {
                console.log("No");
                return;
            }
        }
        prevStone = element === "#";
    }
    
    // 追い越す必要があるとき
    if(D < C) {
        var spaceCount = 0;
        for (var i = B - 2; i < D + 1; i++) {
            var elem = S.charAt(i);
            if(elem === ".") {
                spaceCount++;
            } else {
                spaceCount = 0;
            }
            if(spaceCount == 3){
                console.log('Yes');
                return;
            }
        }
        console.log("No");
    } else {
        console.log("Yes");
    }
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

using namespace std;

#define N 100010
#define M 65540

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

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

int main() {
    scanf("%d",&n); 
    for(int i = 1 ; i < n ; i++) {
        scanf("%d%d%d", &u,&v,&w);
        s[u] ^= w, s[v] ^= w; 
    }
    for(int i = 0 ; i < n ; i++) sum[s[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: 896
#include <iostream>
using namespace std;
int main() {
	long long int h, n, a,damage=0;
	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		damage += a;
	}
	if (damage>=h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = ARGF.gets.to_i
a = ARGF.gets.split.map(&:to_i)
b = ARGF.gets.split.map(&:to_i)
c = ARGF.gets.split.map(&:to_i)

#$stderr.puts "#{a}"

a0 = -100
sum = a.inject(0) do |s, aa|
  old = a0
  a0 = aa
#  $stderr.puts "sum=#{sum}, b=#{b[aa-1]}, c=#{(old + 1 == aa) ? c[old-1] : 0}"
  s + b[aa-1] + ((old + 1 == aa) ? c[old-1] : 0)
end
puts sum


Measured memory_bytes: 1788
#include <cstdio>

int main()
{
	for (unsigned int i = 1; i <= 9; i++)
	{
		for (unsigned int j = 1; j <= 9; j++)
		{
			std::printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	return 0;
}


Measured memory_bytes: 2660
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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 () {
  int n;
  cin >> n ;
  unordered_map<int,vector<P>> list;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    vector<P> nlist(a);
    //todo:a=0のとき

    rep(j,a)
    {P npair;
    cin >> npair.first >> npair.second;
    npair.first--;
    nlist.at(j)=npair;
    }
   list[i]=nlist;
  }

  int ansmax = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<15> s(tmp);  // 最大20個なので20ビットのビット列として扱う
    bool exist=true;
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int sum = 0;

    //それぞれの人の証言を見ていく
    rep(i,n)
    {       //その桁の数字が1,つまり正直者と仮定している人なら、証言を検証する
       if (s.test(i)) {
        sum++;
        //正直者の人数カウント(sum)を足している


        rep(j,list[i].size())
        {   // その人の証言一つ一つについて、矛盾しているかチェック
            //　0(不親切)と証言している人のbitが1になっていたら、それは矛盾
            //　しているので、existをfalseにしてループを抜ける
           int taishou = list[i][j].first;
           int shougen = list[i][j].second;
           if(shougen==0&&s.test(taishou)==1)
           {exist=false; break;}
           if(shougen==1&&s.test(taishou)==0)
            {exist=false; break;}
            
        }
           //
        }


      }

    
    if(exist==true)
    {ansmax=max(ansmax,sum);}

  }
  cout << ansmax << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

li fact(li a){
  // vector,repa 必須
  static vector<li> f(1,1);

  if(f.size()>a)return f[a];
  if(df)print(a,"!");
  int n=f.size();
  repa(i,n,a+1){
    f.push_back(f[i-1]*i%MOD);
    if(df)print(" =",f[i]);
  }
  return f[a];
}

int find(int a,vector<int>& uf){
  if(uf[a]<0) return a;
  return uf[a]=find(uf[a],uf);
}

int unite(int a,int b,vector<int>& uf){
  a=find(a,uf); b=find(b,uf);
  if(a==b)return 1; 
  if(uf[a]>uf[b]) swap(a,b);
  uf[a]+=uf[b];
  uf[b]=a;
  return 0;
}

int size(int a,vector<int>& uf){
  a=find(a,uf);
  return -uf[a];
}


int main(){
  int n; cin >>n;
  vector<int> uf(n,-1),p;
  int f=0;
  rep(i,n){
    int a; cin >>a; a--;
    if(a==-2){
      p.push_back(i);
      continue;
    }
    if(unite(a,i,uf)) f++;
  }
  if(df) print("uf",uf,"f",f);
  int ps=p.size();li s=0;
  rep(i,ps){
    int sz=size(p[i],uf);
    s+=sz;
    p[i]=sz;
  }
  if(df)print("p",p);
  s=n-s;
  vector<vector<li>> sgm(ps,vector<li>(ps,0));
  vector<li> pow(ps+1,1);
  repa(i,1,ps+1) pow[i]=pow[i-1]*(n-1)%MOD;
  if(df) print("pow",pow);
  if(ps==0){
    print(n-f);
    return 0;
  }
  
  sgm[0][0]=p[0];
  repa(i,1,ps){
    sgm[i][0]=(sgm[i-1][0]+p[i])%MOD;
    repa(j,1,i+1){
      sgm[i][j]=(sgm[i-1][j]+sgm[i-1][j-1]*p[i]%MOD)%MOD;
    }
  }
  
  if(df) rep(i,ps) print("sgm",sgm[i]);
  li mn=0;
  rep(i,ps){
    li s=sgm[ps-1][i]*pow[ps-1-i]%MOD;
    (mn+=s*fact(i)%MOD)%=MOD;
    if(df) print("-",s*fact(i));
  }
  if(df)print("mn",mn);
  (s=n*pow[ps-1])%=MOD;
  (s*=ps)%=MOD;
  if(df) print("s",s);
  (s+=(n-ps-f)*pow[ps]%MOD)%=MOD;
  if(df)print("+",(n-ps-f)*pow[ps]);
  print((s+MOD-mn)%MOD);
}


Measured memory_bytes: 198704
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
const int N = 1e5 + 5;
const ll M = (ll)1e18;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
ll cost[105],val[105],sum=0ll;
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n,w,ans=0;
        cin>>n>>w;
        for(int i=1;i<=n;++i){
            cin>>cost[i]>>val[i];
            sum+=val[i];
        }
        vector<ll>dp(sum+1,M);
        dp[0]=0;
        for(int i=1;i<=n;++i){
            for(int j=sum-val[i];j>=0;--j){
                dp[j+val[i]]=min(dp[j+val[i]],dp[j]+cost[i]);
            }
        }
        for(int i=1;i<=sum;++i){
            if(dp[i]<=w)ans=max(ans,i);
        }
        cout<<ans<<endl;
    }
    return 0;
}



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

int main() {
  int x,y;
  cin >>x>>y;
  if (x == 2 || y == 2) cout << "No" <<endl;
  else if (y <= 7 || x >= 8) {
    if ((x + y) % 2 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else {
    if (x + y % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

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

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

struct edge{
    int to;
    ll cost;
    edge(int a, ll b){
        to=a;
        cost=b;
    }
};
ll INF=1e18;
struct D{
    vector<edge> G[100008];
    ll d[100008];

    void AddEdge(int from, int to, ll cost){
        G[from].push_back(edge(to, cost));
    }

    void dijkstra(int n, int s){
        priority_queue<P, vector<P>, greater<P> > q;
        fill(d,d+n+1,INF);
        d[s]=0;
        q.push(P(0,s));
        while(!q.empty()){
            P p=q.top();
            q.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    q.push(P(d[e.to],e.to));
                }
            }
        }
    }
};




int main(void){
    int n,m,s,t;
    ll z=1e15,g[100000];
    D y,x;// yen, snuke
    cin>>n>>m>>s>>t;
    s--;
    t--;
    for(int i=0;i<m;i++){
        int u,v;
        ll a,b;
        cin>>u>>v>>a>>b;
        u--;
        v--;
        y.AddEdge(u, v, a);
        y.AddEdge(v, u, a);
        x.AddEdge(u, v, b);
        x.AddEdge(v, u, b);
    }
    y.dijkstra(n, s);
    x.dijkstra(n, t);
    fill(g, g+n, 0);
    for(int i=0;i<n;i++){
        g[i]=y.d[i]+x.d[i];
    }
    for (int i=n-2;i>=0;i--){
        g[i]=min(g[i], g[i+1]);
    }
    for(int i=0;i<n;i++){
        //cout<<g[i]<<endl;
        cout<<(z-g[i])<<endl;
    }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

inline bool ok(string& s) {
    li n = sz(s);
    if (s[0] == '0') {
        return false;
    }
    if (s[n - 1] == '1') {
        return false;
    }
    rep(i, (n - 1) / 2) {
        if (s[i] != s[n - 2 - i]) {
            return false;
        }
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    li n = sz(s);
    if (!ok(s)) {
        puts("-1");
        return 0;
    }

    li head = 1;
    repp(i, 1, n) {
        cout << head << " " << i + 1 << endl;
        if (s[i - 1] == '1') {
            head = i + 1;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
n,m,x,y=map(int,input().split())
listx=list(map(int,input().split()))
listy=list(map(int,input().split()))
if max(listx)>=y:
    print("War")
elif min(listy)<=x:
    print("War")
elif max(listx)>=min(listy):
    print("War")
else:
    print("No War")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int64 INF = 1LL << 40 - 1;
constexpr int64 LINF = 1LL << 60 + 1;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;
    
// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
    
// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;
    
// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
    
    
signed main() {
    INIT;
    VAR(int, n);
    map< int, int > mp;
    vector< int > a;
    REP(i, n) {
        VAR(int, j);
        a.push_back(j);
        mp[j]++;
    }
    
    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());
    
    int ans = 0;
    RREP(i, a.size()) {
        RREP(j, 31) {
            if (mp[a[i]] == 0) break;
            if ((a[i] << 1) > (1LL << j)) break;
            int target = (1 << j) - a[i];
            if (target == a[i]) {
                int tmp = mp[target] / 2;
                mp[target] -= tmp * 2;
                ans += tmp;
            } else {
                int tmp1 = mp[target];
                int tmp2 = mp[a[i]];
                mp[target] -= min(tmp1, tmp2);
                mp[a[i]] -= min(tmp1, tmp2);
                ans += min(tmp1, tmp2);
            }
        }
    }
    
    OUT(ans)BR;
    
    return 0;
}

Measured memory_bytes: 36720
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
using namespace std;

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

const int INF = 1e9;
int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

int A, B, C, D;

int main() {
  cin >> A >> B >> C >> D;

  int a, b;
  a = min(A, B);
  b = min(C, D);

  cout << a + b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void)
{
    unsigned int n, m;
    vector<unsigned int> a;
    vector<tuple<unsigned int, unsigned int>> b;
    unsigned int tmp;
    unsigned int tmpb, tmpc;
    unsigned long long int s;
    cin >> n >> m;
    a.reserve(n);
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    for (int i = 0; i < m; i++) {
        cin >> tmpb >> tmpc;
        b.push_back(make_tuple(tmpc, tmpb));
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<tuple<unsigned int, unsigned int>>() );

    unsigned int k = 0;
    for (unsigned int i = 0; i < m; i++) {
        for (unsigned int j = 0; j < get<1>(b[i]); j++) {
            if (a[k] < get<0>(b[i])) a[k] = get<0>(b[i]);
            else {
                i = m;
                break;
            }
            k++;
            if (k >= n) {
                i = m;
                break;
            }
        }
    }
    s = accumulate(a.begin(), a.end(), 0LL);
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 1784
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> n_q = Stream.of(sc.nextLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        int q = n_q.get(1);
        Queue<String> qu = new ArrayBlockingQueue<>(n_q.get(0));
        int t = 0;
        while(sc.hasNext()) {
            qu.add(sc.nextLine());
        }
        while(!qu.isEmpty()) {
            String[] name_time = qu.poll().split(" ");
            int time = Integer.parseInt(name_time[1]);
            if (time > q) {
                time -= q;
                t += q;
                qu.add(name_time[0] + " " + time);
            } else {
                t += time;
                System.out.println(name_time[0] + " " + t);
            }
        }
    }
}




Measured memory_bytes: 113700
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Char
import Control.Monad

solve :: VU.Vector Int -> Int -> Int -> IO Int
solve vec n x = do
        vec' <- VU.unsafeThaw vec
        res <- forM [0..n-2] $ \i -> do
                adjust vec' (i,i+1) x
        return $ sum res
    where
        adjust :: VUM.IOVector Int -> (Int, Int) -> Int -> IO Int
        adjust vec (i,j) x = do
            iv <- VUM.read vec i
            jv <- VUM.read vec j
            let diff = max (iv+jv-x) 0
            unless (diff == 0) $ do
                if (jv >= diff)
                    then do
                        VUM.write vec j (jv-diff)
                    else do
                        VUM.write vec j 0
                        VUM.write vec i (iv + (jv-diff))
            return diff

main = do
    [n, x] <- map read . words <$> getLine :: IO [Int]
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    solve as n x >>= print

Measured memory_bytes: 10748
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner sc=new Scanner(System.in);
         for(int i=1; i>0; i++){
         int x= sc.nextInt();
         if(x == 0)
             break;
             System.out.println("Case "+i+ ": "+x);
                }
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    for (int i=0; i<m; i++) cin >> a[i] >> b[i];

    vector<int> c(n);
    for (int i=0; i<n; i++) c[i] = 0;
    for (int i=0; i<m; i++) {
        c[a[i]-1]++;
        c[b[i]-1]++;
    }

    for (int i=0; i<n; i++) {
        cout << c[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int main() {

    int n;
    scanf("%d", &n);
    printf("%d", n * n * n);

    return 0;
}

Measured memory_bytes: 256
str1 = input()

num = str1.count('R')

if num == 3:
    print('3')
elif num == 2:
    if str1[1] == 'S':
        print('1')
    else:
        print('2')
elif num == 1:
    print('1')
else:
    print('0')

    
    


Measured memory_bytes: 9096
#include<iostream>
#include<cstdio>
#include<cstring>

typedef long long ll;

const int N=301000,MOD=998244353;

ll inv(int x){return (x==1 || x==-1)?x:(-(MOD/x)*inv(MOD%x)%MOD);}

int fact[N],ifact[N];

int C(int n,int m){if(n<m)return 0;return (ll)fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;}

void initialize()
{
	fact[0]=1;
	for(int i=1;i<N;i++)fact[i]=(ll)fact[i-1]*i%MOD;
	ifact[N-1]=inv(fact[N-1]);
	for(int i=N-1;i;i--)ifact[i-1]=(ll)ifact[i]*i%MOD;
}

int n;
ll a,b,k;

int main()
{
	initialize();

	scanf("%d%lld%lld%lld",&n,&a,&b,&k);

	int ans=0;

	for(int i=0,j;i<=n && i*a<=k;i++)
		if((k-i*a)%b==0)
		{
			j=(k-i*a)/b;
			ans=(ans+(ll)C(n,i)*C(n,j))%MOD;
		}

	ans=(ans+MOD)%MOD;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int N, M;
vector<long long int>x, y, z;

vector<long long int> W;

int main(void) {

	cin >> N >> M;

	long long int tmp;

	for (int i = 0; i < N; i++) {
		cin >> tmp; x.push_back(tmp);
		cin >> tmp; y.push_back(tmp);
		cin >> tmp; z.push_back(tmp);
	}

	int cx[] = { 1,1,1,1,-1,-1,-1,-1 }, cy[] = { 1,1,-1,-1,1,1,-1,-1 }, cz[] = {1,-1,1,-1,1,-1,1,-1};
	long long  int ans = 0;
	for (int k = 0; k < 8; k++) {
		W.clear();
		for (int i = 0; i < N; i++) {
			W.push_back(cx[k] * x[i] + cy[k] * y[i]+cz[k] * z[i]);
		}
		sort(W.rbegin(), W.rend());

		long long int val = 0;
		for (int j = 0; j < M; j++) {
			val += W[j];
		}
		ans = max(ans, val);
	}
	cout << ans << endl;

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

Measured memory_bytes: 256
// B - Power Socket

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

int main(){
	int A, B;
	cin >> A >> B;

	int n_plug = 1;
	int ans = 0;
	while (n_plug < B) {
		ans++;
		n_plug = n_plug - 1 + A;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input =  sys.stdin.readline

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
  u, v = map(int, input().split())
  u -= 1
  v -= 1
  G[u].append(v)
  G[v].append(u)
seen = [-1]*n
p, q, r = 0, 0, 0
def dfs(v):
  global p, q
  stack = [(v, 0)]
  seen[v] = 0
  f = False
  while stack:
    v, c = stack.pop()
    for nv in G[v]:
      if seen[nv] == -1:
        seen[nv] = c^1
        stack.append((nv, c^1))
      else:
        if seen[nv]^c == 0:
          f = True
  if f:
    p += 1
  else:
    q += 1
for v in range(n):
  if seen[v] != -1:
    continue
  if not G[v]:
    r += 1
  else:
    dfs(v)
ans = r*(2*n-r) + (p+q)*(p+q) + q*q
print(ans)

Measured memory_bytes: 36944
n,m=map(int,input().split())
a_list=list(map(int,input().split()))


sumn=0
for a in a_list:
    sumn+=a

lim=1.*sumn/(4.*m)

cnt=0
for a in a_list:
    if a >= lim:
        cnt+=1

if cnt >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N;
    cin>>N;
    for(int i=1;i<=50000;i++){
        int n=i*1.08;
        if(n==N){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}


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

#define skip continue

typedef long long ll;

const int N = 1e5 + 10;

ll n;
ll k, sum, a[N], d[N], cnt;

int main(){
	cin >> n;
	for(int i = 1; i <= n; ++ i){
		cin >> a[i];
		sum += a[i];
	}
	k = sum / ((n + 1) * n / 2);
	if(k * (n + 1) * n / 2 != sum){
		cout << "NO";
		return 0;
	}
	d[n] = a[1] - a[n];
	for(int i = 1; i < n; ++ i){
		d[i] = a[i + 1] - a[i];
	}
	for(int i = 1; i <= n; ++ i){
		if((d[i] - k) % n != 0 || d[i] - k > 0){
			cout << "NO";
			return 0;
		}
		cnt += (d[i] - k) / n;
	}
	if(cnt == -k) cout << "YES";
	else cout << "NO";
	//cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t N;

    std::cin >> N;

    int64_t count = 0;
    for (int64_t i = 0; i < N; ++i) {
        int64_t d1, d2;
        std::cin >> d1 >> d2;
        if (d1 == d2) {
            count++;
        } else {
            count = 0;
        }

        if (count >= 3) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define MAXN 100000

using namespace std;

string str;

int main() {
   // fstream cin("A.in");
   // ofstream cout("A.out");
    int i,n,begin;
    ios::sync_with_stdio(false);
    cin >> str;
    n = str.size();
    for(char ch = 'a'; ch <= 'z'; ch++) {
      int sum = -2;
      for(i = 0; i < n; i++) {
         int x;
         if(str[i] == ch)
            x = 1;
         else
            x = -1;
         if(sum + x >= x)
            sum += x;
         else {
            sum = x;
            begin = i;
         }
         if(sum > 0 && begin < i) {
            cout << begin + 1 << " " << i + 1 << endl;
            return 0;
         }
      }
    }
    cout << -1 << " " << -1 << endl;
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.lang.Math;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        int j;
        for(int i=0;i<n;i++){
            A[i]=0;
        }
        for(int i=1;i<n;i++){
            j = sc.nextInt()-1;
            A[j]++;
        }
        for(int i=0;i<n;i++){
            System.out.println(A[i]);
        }
    }
}

Measured memory_bytes: 60380
from itertools import accumulate, product, permutations, combinations
def solve():
    N, M = map(int, input().split())
    A = [list(map(int,input().split())) for _ in range(M)]
    P = list(map(int, input().split()))
    ans = 0
    for p in product([0,1],repeat = N):
        for i in range(M):
            xor = 0
            for j in range(1,A[i][0]+1):
                xor ^= p[A[i][j]-1]
            if xor != P[i]:
                break
        else:
            ans += 1
    return ans
print(solve())

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

int main()
{
	int N,M,tmp;
    cin >> N >> M;
	vector<int> A(N);
	int i;
	for(i=0;i<N;i++){
		cin >> tmp;
		A.push_back(tmp);
	}
	
	sort(A.begin(), A.end(), greater<int>());
	int sum = accumulate(A.begin(), A.end(), 0);
	if(A[M-1]*4*M<sum)	cout << "No" << endl;
	else			cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
from time import time
from random import randint
from numpy import int32

def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, sys.stdin.buffer.read().split())
    s = int32(s)
    x = int32(([*range(26)] * 15)[:d])
    M = func(s, x)
    while time() - start < 1.88:
        y = x.copy()
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i = randint(0, d - 16)
            j = randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    print(*x + 1, sep='\n')

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('func', 'i4(i4[:], i4[:])')(func)
    cc.compile()

if __name__ == '__main__':
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import func
    main()

Measured memory_bytes: 27996
if __name__ == '__main__':
   n, m = map(int,input().split())
   a = set([int(input()) for i in range(m)])
   broken = [False] * (n+1)
   for i in range(n+1):
      if i in a:
         broken[i] = True

   MOD = 1000000007


   dp = [0 for i in range(n+1)]
   dp[0] = 1
   if 1 in a:
      dp[1] = 0
   else:
      dp[1] = 1

   for i in range(2,n+1):
      if broken[i-1] and broken[i-2]:
         dp[i] = 0
      elif broken[i-1]:
         dp[i] = dp[i-2] % MOD
      elif broken[i-2]:
         dp[i] = dp[i-1] % MOD
      else:
         dp[i] = (dp[i-1] + dp[i-2]) % MOD

   print(dp[n])


Measured memory_bytes: 18804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		sc.close();

		if (K <= A) {
			A = A - K;
		} else if (K >= A + B) {
			A = 0;
			B = 0;
		} else {
			B = B - K + A;
			A = 0;
		}
		System.out.println(A + " " + B);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
const int mod=1e9+7;
int n,k,a[maxn],b[maxn];
inline int  read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main()
{
  scanf("%d%d",&k,&n);
  for(int i=1;i<=n;i++)
  {
  scanf("%d",&a[i]);
  }
  sort(a+1,a+n+1);
  for(int i=1;i<=n-1;i++)
  b[i]=a[i+1]-a[i];
  b[n]=a[1]+k-a[n];
  sort(b+1,b+n+1);
  printf("%d",k-b[n]);
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
// - 0 00 1 01 001 11
const int N=3e5+10,p=1e9+7;
const int tran[2][7]={{1,2,1,4,5,4,6},{3,0,1,6,3,4,6}};
int f[N][7],n;char s[N];
int main(){
    scanf("%s",s+1);n=strlen(s+1);f[0][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<7;j++){
            if(s[i]!='1') (f[i][tran[0][j]]+=f[i-1][j])%=p;
            if(s[i]!='0') (f[i][tran[1][j]]+=f[i-1][j])%=p;
        }
    printf("%d\n",(f[n][3]+f[n][6])%p);
}

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

using namespace std;

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

  long long x, k, d;
  cin >> x >> k >> d;

  if (x < 0) x = -x;
  if (k & 1) {
    x -= d;
    if (x < 0) x = -x;
  }
  k /= 2;
  d *= 2;

  long long jump = min(x / d + 1, k);
  long long ans = abs(x - d * jump);
  if (jump > 0) ans = min(ans, abs(x - d * (jump - 1)));
  cout << ans << '\n';

  return 0;
}


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

int main(){
	stack<int> S;
	string input;
	getline(cin, input);
	stringstream ss; ss << input;
	while(!ss.eof()){
		string value; ss >> value;
		if(value == "+"){
			int tmp1 = S.top();
			S.pop();
			int tmp2 = S.top();
			S.pop();
			S.push(tmp1+tmp2);
		}
		else if(value == "-"){
			int tmp1 = S.top();
			S.pop();
			int tmp2 = S.top();
			S.pop();
			S.push(tmp2 - tmp1);
		}
		else if(value == "*"){
			int tmp1 = S.top();
			S.pop();
			int tmp2 = S.top();
			S.pop();
			S.push(tmp1*tmp2);
		}
		else{
			S.push(stoi(value));
		}
	}
	cout << S.top() << endl;

	return 0;
}

Measured memory_bytes: 3204
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        ArrayList<Integer> b_list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            b_list.add(Integer.parseInt(sc.next()));
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0, a = 0; j < m; j++) {
                a = Integer.parseInt(sc.next());
                sum += a * b_list.get(j);
            }
            sum += c;
            if (sum > 0) {
                ans++;
            }
        }
        out.println(ans);
        sc.close();
        out.close();
    }

}

Measured memory_bytes: 35792
#include<iostream>
#include<cmath>
#include<algorithm>
typedef long long ll;
using namespace std;
ll fastpow(int x) {
	ll res = 1, base = 2;
	while (x) {
		if (x % 2 == 1) res = res*base;
		base = base * base;
		x >>= 1;


	}


	return res;


}
int main() {
	ll h;
	cin >> h;
	ll sum = 0;
	int p = 0;
	while (h) {
		sum += fastpow(p);
		h = h / 2;
		p++;

	}
	cout << sum;
	return 0;

} 

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
ok = [0]*n
count = 0
check = [0]*n
for i in range(m):
    x, y = list(map(int, input().split()))
    if h[x-1] > h[y-1]:
        ok[x-1] += 1
    if h[y-1] > h[x-1]:
        ok[y-1] += 1
    check[x-1] += 1
    check[y-1] += 1

for i in range(n):
    if check[i] == ok[i]:
        count += 1

# print(ok)
# print(check)
print(count)


Measured memory_bytes: 20128
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
 
using namespace std;
 
int n, m;
double data[16][1<<16];
double input[16][16];

double func(int d, int s){
  if(d == n) return 1.0;
  if(s == (1<<m)) return 0.0;
  if(data[d][s] != -1) return data[d][s];
  double res = 0.0;
  for(int i=0;i<m;i++){
    if(s & (1 << i)) continue;
    double np = 1.0, sum = 0.0;
    for(int j=d;j<n;j++){
      sum += func(j, s|(1<<i)) * np * (1.0 - input[j][i]);
      np *= input[j][i];
    }
    sum += np * func(n, s|(1<<i));
    res = max(res, sum);
  }
  return data[d][s] = res;
}
 
main(){
  fill(data[0], data[16], -1.0);  
  cin >> m >> n;
  for(int j=0;j<m;j++){
    for(int i=0;i<n;i++){
      cin >> input[i][j];
    }
  }
  //cout << func(0, 0) << endl;
  printf("%.15f\n", func(0, 0));
}

Measured memory_bytes: 9440
import java.util.*; 
import java.io.*; 

public class Main {
	public static void main(String[] args) throws IOException {
     Scanner sc = new Scanner(System.in);
     int n = sc.nextInt(); 
     int m = sc.nextInt(); 
     System.out.println(n == m ? "Yes" : "No"); 
}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef pair<int,int> Paint;
int iland[100001];
int  size[100001];


void init(int n){
  for(int i = 0; n > i; i++){
    iland[i] = i;
    size[i] = 1;
  }
}
int root(int x){
  if(iland[x] == x){
    return x;
  }
  return iland[x] = root(iland[x]);
}
int same(int i, int j){
  return root(i) == root(j);
}
void unite(int i, int j){
  i = root(i);
  j = root(j);
  if(i == j)return;
  iland[j] = i;
  size[i] += size[j];
}
int sizer(int i){
  return size[root(i)];
}


int main(){
  int n,m;cin>>n>>m;
  vector<Paint> q;
  for(int i = 0; m > i; i++){
    int te,mp;cin>>te>>mp;
    q.push_back(make_pair(te-1,mp-1));
  }
  reverse(q.begin(),q.end());
  init(n);
  vector<long long> ans;
  ans.push_back((long long)n*(n-1)/2);



  for(int i = 0; m-1 > i; i++){
    if(same(q[i].first,q[i].second)){
      ans.push_back((long long)ans[i]);
    }else{
      ans.push_back((long long)ans[i]-sizer(q[i].first)*sizer(q[i].second));
    }
    unite(q[i].first,q[i].second);
  }

  for(int i = ans.size()-1; 0 <= i; i--){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

int main(){

    ll R,C,K;
    scanf ("%lld %lld %lld",&R,&C,&K);

    vector<vector<ll>> lis(R+1,vector<ll> (C+1,0));
    rep(i,0,K){
        ll r,c,v;
        scanf ("%lld %lld %lld",&r,&c,&v);
        r--;
        c--;
        lis[r][c] += v;
    }

    vector<vector<vector<ll>>> dp(C+1,vector<vector<ll>> (R+1,vector<ll> (4,0)));

    rep(j,0,C+1){
        rep(i,0,R+1){
            rep(k,0,4){
                //取る
                if (k != 3){

                    //右に行く
                    if (j != C){
                        dp[j+1][i][k+1] = max(dp[j+1][i][k+1],dp[j][i][k] + lis[i][j]);
                    }
                    //下に行く
                    if (i != R){
                        dp[j][i+1][0] = max(dp[j][i+1][0] , dp[j][i][k] + lis[i][j]);
                    }
                }
                //取らない

                //右に行く
                if (j != C){
                    dp[j+1][i][k] = max(dp[j+1][i][k],dp[j][i][k]);
                }
                //下に行く
                if (i != R){
                    dp[j][i+1][0] = max(dp[j][i+1][0] , dp[j][i][k]);
                }
                
            }
        }
    }

    cout << max(dp[C][R][0],max(dp[C][R][1],max(dp[C][R][2],dp[C][R][3]))) << endl;
}

Measured memory_bytes: 706660
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split(' ');
            var T = double.Parse(ss[0]);
            var X = double.Parse(ss[1]);
            Console.WriteLine(T / X);
        }
    }
}


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

struct edge{
	int s, t, c;
	bool operator< (const edge &e) const{
		return c < e.c;
	}
} e[10000];

int par[10001];

int find(int x){
	return x != par[x] ? par[x] = find(par[x]) : x;
}

int main(){
	int n, m;
	while( scanf("%d%d", &n, &m) != EOF && n != 0 ){
		for(int i = 1; i <= n; ++i){
			par[i] = i;
		}
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &e[i].s, &e[i].t, &e[i].c);
		}

		sort(e, e + m);

		int u = n / 2;
		for(int i = 0; i < m; ++i){
			int x = find(e[i].s);
			int y = find(e[i].t);
			if( x == y ) continue;
			par[x] = y;

			if( --u == 0 ){
				printf("%d\n", e[i].c);
				break;
			}
		}
	}
}

Measured memory_bytes: 1332