akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

struct edge {int to, cost;};
typedef pair<int, int> P; // firstは最短距離, secondは頂点の番号

#define INF INT_MAX
const int MAX_V=100000;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
int pre[MAX_V];
int used[MAX_V];
int fe=0,su=0;
bool visited[MAX_V]={};

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  fill(pre,pre+V,-1);
  d[s]=0;
  que.push(P(0, s));

  while(!que.empty()){
    P p = que.top(); que.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;
        pre[e.to]=v;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

vector<int> get_path(int t){
  // s to t;
  vector<int> path;
  for(;t!=-1;t=pre[t]) path.push_back(t);
  reverse(path.begin(),path.end());
  return path;
}

void dfs(int s, int color){
  visited[s]=1;
  for(int i=0;i<G[s].size();i++){
    int ind=G[s][i].to;
    if(used[ind]==0){
      used[ind]=color;
      if(color==1) fe++;
      else su++;
    }
    if(used[ind]==color&&(!visited[ind])) dfs(ind,color);
  }
}

int main(){
  cin>>V;
  for(int i=0;i<V-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back({b,1});
    G[b].push_back({a,1});
  }
  dijkstra(0);
  vector<int> path=get_path(V-1);
  used[0]=1, used[V-1]=2;
  fe++, su++;
  for(int i=1;i<V-1;i++) used[i]=0;
  int ind=path.size()-2;
  for(int i=1;i<=d[V-1]/2;i++){
    if(used[path[i]]==0){
      used[path[i]]=1;
      fe++;
    }else{
      break;
    }
    if(used[path[ind]]==0){
      used[path[ind]]=2;
      su++;
      ind--;
    }else{
      break;
    }
  }
  dfs(0, 1);
  dfs(V-1, 2);
  //for(int i=0;i<V;i++) cout<<used[i]<<endl;
  if(fe>su) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  return 0;
}

Measured memory_bytes: 9848
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int q = in();
  map<string, int> m;
  while (q--) {
    int t = in();
    if (t == 0) {
      string k;
      int x;
      cin >> k >> x;
      m[k] = x;
    }
    if (t == 1) cout << m[in<string>()] << endl;
  }
}



Measured memory_bytes: 27800
#include <stdio.h>

#define MAX 1000000

typedef struct pp{
  char name[10];
  int time;
}P;

int head=0, tail=0;
P Q[MAX], a;

void enqueue(P);
P dequeue(void);

int main()
{
  int i, n, q, sum=0;

  scanf("%d%d", &n, &q);
  
  for(i = 0 ; i < n ; i++){
    scanf("%s%d", a.name, &a.time);
    enqueue(a);
  }
  
  while(head != tail){
    a = dequeue();
    if(a.time > q){
      a.time -= q;
      enqueue(a);
      sum += q;
    }
    else{
      printf("%s %d\n", a.name, a.time+sum);
      sum += a.time;
    }
  }
  
  return 0;
}

void enqueue(P x)
{
  Q[tail] = x;
  if (tail + 1 == MAX){
    tail = 0;
  }
  else{
    tail++;
  }
}

P dequeue()
{
  P x;
  x = Q[head];
  if (head + 1 == MAX){
    head = 0;
  }
  else{
    head++;
  }
  return x;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int a,b,h,m; cin >> a >> b >> h >> m;
  double x = (h * 60 + m) * 0.5;
  double y = m * 6;
  double cos = abs(x - y);
  if(cos > 180) cos = 360 - cos;
  double xx = cos*acos(-1)/180;
  double t = cosl(xx);
  double ans = sqrt(a*a + b*b - 2*a*b*t);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 4100
#include <stdio.h>
#include <string.h>

int main(void)
{
	int		 a,b, c,  num, max, min,  middle, i;
	
	scanf("%d",&num) ;
	
	for(i=0; i<num; i++){
		scanf("%d %d %d",&a, &b, &c);
		if((a > b) && (a>c)){
			if(a*a == ((b*b) + (c*c))){
				printf("YES\r\n");
			}
			else{
				printf("NO\r\n");			
			}
		}
		else if((b > a) && (b>c)){
			if(b*b == ((a*a) + (c*c))){
				printf("YES\r\n");
			}
			else{
				printf("NO\r\n");			
			}
		}
		else{
			if(c*c == ((a*a) + (b*b))){
				printf("YES\r\n");
			}
			else{
				printf("NO\r\n");			
			}
		}
	}
	return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <iostream>
using namespace std;
int a,b,c,d,e,f;
int main(){
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	double density=-1;
	int ans1=0,ans2=0;
	for(int i=0;i*a*100<=f;++i)
	    for(int j=0;i*a*100+j*b*100<=f;++j)
	        for(int x=0;x*c<=(i*a+j*b)*e && x*c+i*a*100+j*b*100<=f;++x){
	        	int y=min((i*a+j*b)*e-x*c,f-i*a*100-j*b*100-x*c)/d;
	        	if(1.0*(x*c+y*d)/(i*a+j*b)>density){
	        		density=1.0*(x*c+y*d)/(i*a+j*b);
	        		ans1=x*c+y*d+i*a*100+j*b*100,ans2=x*c+y*d;
	        	}
	        }
	printf("%d %d",ans1,ans2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int n;
vector<int> G[100005];
vector<bool> flg(100005, false);
vector<vector<ll>> dp(100005, vector<ll>(2, 0));

void rec(int from, int i){
    if(flg[i])return;
    flg[i] = 1;
    dp[i][0] = 1;
    dp[i][1] = 1;
    for(auto to:G[i]){
        if(to == from) continue;
        rec(i, to);
        dp[i][0] = dp[i][0]*(dp[to][0]+dp[to][1])%mod;
        dp[i][1] = dp[i][1]*dp[to][0]%mod;
    }
}


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

    cin >> n;
    for(int i=0; i<n-1; ++i){
        int x,y; cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    rec(-1, 0);
    cout << (dp[0][0]+dp[0][1])%mod << endl;

	return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n; cin>>n;
    vector<int>v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    vector<int>sum=v;
    rep(i,n)if(i)sum[i]+=sum[i-1];
    int ans=0;
    vector<bool>flag(n,false);
    flag[n-1]=true;
    for(int i=(int)v.size()-2;i>=0;i--){
        if((v[i]*2>=v[i+1]&&flag[i+1]) ||(sum[i]*2>=v[i+1]&&flag[i+1])){ans++;flag[i]=true;}
    }
    cout<<ans+1<<endl;
}


Measured memory_bytes: 1024
n,q=map(int,input().split())
l=[[] for i in range(n)]

for i in range(q):
    qry=list(map(int,input().split()))
    if qry[0]==0:
        l[qry[1]].append(qry[2])
    elif qry[0]==1:
        li=map(str,l[qry[1]])
        print(' '.join(map(str,li)))
    else:
        l[qry[1]].clear()


Measured memory_bytes: 60548
n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i)
m = 1
i = 0
while i < n
  m *= arr[i]
  if m > 10**18
    c = "over"
    m = 1
  end
  i += 1
end
if c == "over" && m != 0
  print -1
else
  print m
end

Measured memory_bytes: 24372
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(s: &str) -> bool {
    let mut cs = s.chars().collect::<Vec<char>>();
    cs.sort();

    cs[0] == cs[1] && cs[1] != cs[2] && cs[2] == cs[3]
}

fn main() {
    let s = read_line!();
    println!("{}", if solve(&s) { "Yes" } else { "No" });
}

#[test]
fn solve_test() {
    assert_eq!(solve("ASSA"), true);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h, w;
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      string snuke; cin >> snuke;
      if(snuke == "snuke"){
        cout << (char)(j + 'A') << i + 1 << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct edge {int to;int cost;};
const int M_N=300;
int L;
int n,m;
vector<edge> G[M_N+1];
P d[M_N+1][M_N+1];

void dijkstra(int s){
    d[s][s] = mp(0,L);
    vector<bool> vis(n,false);
    while(1){
        int v=-1;
        int t=0;
        int l=INF;
        for (int i = 0; i < n; i++) {
            if(vis[i])continue;
            if(d[s][i].fs<l||(d[s][i].fs==l&&d[s][i].sc>t)){
                v = i;
                l = d[s][i].fs;
                t = d[s][i].sc;
            }
        }
        if(v==-1) break;
        vis[v] = true;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(e.cost>t){
                if(d[s][e.to].fs>l+1||(d[s][e.to].fs==l+1&&d[s][e.to].sc<L-e.cost)){
                    d[s][e.to] = mp(l+1,L-e.cost);
                }
            }
            else{
                if(d[s][e.to].fs>l||(d[s][e.to].fs==l&&d[s][e.to].sc<t-e.cost)){
                    d[s][e.to] = mp(l,t-e.cost);
                }
            }
        }
    }
}




int main(){
    cin >> n >> m >> L;
    for (int i = 0; i < m; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int c;cin >> c;
        if(c>L) continue;
        G[x].pb({y,c});
        G[y].pb({x,c});
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = mp(INF,0);
        }
    }
    for (int i = 0; i < n; i++) {
        dijkstra(i);
    }
    int q;cin >> q;
    for (int i = 0; i < q; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int ans = d[x][y].fs;
        if(ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e6+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n,m;
int a[N];
int last[N];
int bit[N];
int out[N];

struct querys{
    int l,r,id;
}q[N];

bool cmp(querys a,querys b){
    return a.r<b.r;
}

int lowbit(int o){
    return o&-o;
}

void add(int o,int x){
    for(;o<=n;o+=lowbit(o))bit[o]+=x;
}

int ask(int o){
    int res=0;
    for(;o;o-=lowbit(o))res+=bit[o];
    return res;
}

int main()
{
    read(n),read(m);
    Rep(i,1,n)read(a[i]);
    Rep(i,1,m)read(q[i].l),read(q[i].r),q[i].id=i;
    sort(q+1,q+m+1,cmp);
    int now=1;
    Rep(i,1,m){
        Rep(j,now,q[i].r){
            if(last[a[j]])add(last[a[j]],-1);
            last[a[j]]=j;
            add(j,1);
        }
        now=q[i].r+1;
        out[q[i].id]=ask(q[i].r)-ask(q[i].l-1);
    }
    Rep(i,1,m)printf("%d\n",out[i]);
    return 0;
}

Measured memory_bytes: 17384
N = int(input())
Data = list(map(int,input().split()))
ans = 0
while True:
    notEven = False
    for i in range(N):
        if Data[i] % 2 == 0:
            Data[i] = Data[i] // 2
        else:
            notEven = True
            break
    if notEven:
        break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1 << 30;
double ans = 0;

int main()
{
ll n;
cin >> n;
ll t[n] = {};
ll v[n] = {};
double co[50010]={};
double ma[50010]={};
double mi[50010]={};
rep(i, n)
{
    cin >> t[i];
}
rep(i, n)
{
    cin >> v[i];
}
co[0]=0;
ll a=t[0],b=0;
rep1(i,50010){
    if(i<a*2)co[i]=v[b];
    else {
        b++;
        if(b>=n){co[i]=0;break;}
        else co[i]=min(v[b],v[b-1]);
        a+=t[b];
    }
}
rep1(i,50010){
    ma[i]=min(ma[i-1]+0.5,co[i]);
}
for (ll i = 50008; i >=0; i--){
    mi[i]=min(mi[i+1]+0.5,co[i]);
}
rep1(i,50009){
    //ans+=((double)min(ma[i],mi[i])+(double)min(ma[i-1],mi[i-1]))/2.0;
    ans+=(double)min(ma[i],mi[i]);
}

double answer=ans/2.0;

/* for (int i = 0; i <60; ++i) {
    cout << i<<" "<<co[i] << " "<<ma[i]<< " "<<mi[i]<< " "<<min(ma[i],mi[i])<< endl;
} */



cout << fixed << setprecision(10) << answer << endl;
return 0;
}

Measured memory_bytes: 1408
import java.util.*;
 
public class Main{
    public static int[] solve(int[][] treasure, int W){
        int[] save = new int[W+1];
        for(int i = 0; i < treasure.length; i++){
            for(int j = W; j >= 0; j--){
                if( save[j] != 0 && j + treasure[i][1] <= W ){
                    save[j+treasure[i][1]] = Math.max(treasure[i][0] + save[j], save[j+treasure[i][1]]);
                }
            }
            save[treasure[i][1]] = Math.max(treasure[i][0], save[treasure[i][1]]);
        }
        int max = 0;
        for(int i = 0; i <= W; i++){
             if( save[max] < save[i] ){
                max = i;
             }
        }
     
        int[] ans = new int[2];
        ans[0] = save[max];
        ans[1] = max;
        return ans;
    }
         
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int index = 0;
        int W;
        while( (W = stdIn.nextInt()) != 0 ){
            int n = stdIn.nextInt();
            int[][] treasure = new int[n][2];
            for(int i = 0; i < n; i++){
                String[] s = stdIn.next().split(",");
                treasure[i][0] = Integer.parseInt(s[0]);
                treasure[i][1] = Integer.parseInt(s[1]);
            }
            int[] ans = solve(treasure, W);
            System.out.println("Case " + (++index) + ":");
            System.out.println(ans[0]);
            System.out.println(ans[1]);
        }
    }
}

Measured memory_bytes: 24860
from collections import*
I=9**9
(h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3)
m,d=zip(*eval('(input(),[I]*w),'*h))
q=deque([(s-1,t-1,1)])
while q:
 y,x,c=q.pop()
 if d[y][x]>c:
  for a in range(25):a,b=a//5-2,a%5-2;i=a+y;j=b+x;d[y][x]=c;h>i>-1<j<w!=m[i][j]>'#'!=(abs(a)+abs(b)<2!=q.append((i,j,c)),q.appendleft((i,j,c+1)))
print(d[f-1][g-1]%I-1)

Measured memory_bytes: 255552
# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rr = rcv[::3]
cc = rcv[1::3]
vv = rcv[2::3]
rc2v = {}
for _r, _c, _v in zip(rr, cc, vv):
    rc2v[(_r-1, _c-1)] = _v

dp = [[0]*4 for c in range(C)]

for r in range(R):
    for c in range(C):
        if(c!=0):
            dp[c][0] = max(dp[c-1][0], max(dp[c]))
        else:
            dp[c][0] = max(dp[c])

        v = 0
        if (r, c) in rc2v:
            v = rc2v[(r, c)]
        for k in range(1,4):
            if(c!=0):
                dp[c][k] = max(dp[c-1][k], dp[c-1][k-1] + v, dp[c][0] + v)
            else:
                dp[c][k] = dp[c][0] + v

print(max(dp[-1]))

Measured memory_bytes: 151472
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n*2];
		
		for(int i=0; i<n*2; i++) {
			l[i] = sc.nextInt();
		}
		System.out.println(test(n, l));
		
		sc.close();

	}
	
	public static int test(int n, int[] l) {
		Arrays.sort(l);
		int sum = 0;
		for(int i=0; i<n*2; i+=2) {
			sum += l[i];
		}
		return sum;
	}

}


Measured memory_bytes: 9680
n,m = gets.split(' ').map(&:to_i)
min_limit = 1
max_limit = n
(0...m).each do |i|
  gate_info = gets.split(' ').map(&:to_i)
  min_limit = gate_info[0] if gate_info[0] > min_limit
  max_limit = gate_info[1] if gate_info[1] < max_limit
end
puts [max_limit - min_limit + 1, 0].max


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  string N;
  cin >> N;
  long t = 0;
  rep(i, N.length()) t += N[i] - 48;

  if (t % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// 1行目個数、2行目の複数の数字を配列に格納
		//   3
		//   1 2 3
		int N = Integer.parseInt(br.readLine());

		// 1行、複数文字、Listに格納
		List<String> a = Arrays.asList( br.readLine().trim().split(" ", 0) );
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();


		for(int i=N-1; i>=0; i -= 2){
			b.add(a.get(i));
		}
		int j;
		if (N%2==0) { j=0; } else { j=1; }
		for(int i=j; i<N; i += 2){
			b.add(a.get(i));
		}


		StringBuilder sb = new StringBuilder();
		for(String s: b) {
			sb.append(s);
			sb.append(" ");
		}
		sb.delete(sb.length()-1, sb.length());  // 消去：早い

//		System.out.println("[" + sb + "]");
		System.out.println(sb);
	return;
	}
	// 入力値確認：リスト
	static void checkInput(List l) { System.out.println(l); }

}


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

#define inf 1e18
#define mod 1000000007

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define tc ll T;cin >> T;while(T--)

#define ff first
#define ss second
#define pb push_back

ll func(ll x){
	ll num = sqrt(2*x);
	while((num*(num+1))/2 <=x){
		num++;
	}
	return --num;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	vector <ll> v(1e6+5,0);
	while(n%2 == 0){
		v[2]++;
		n /=2;
	}
	for(ll i = 3; i <= sqrt(n); i += 2){
		while(n%i == 0){
			v[i]++;
			n /= i;
		}
	}
	ll ans = 0;
	if(n != 1){
		ans++;
	}
	forc(i,2,1e6+4){
		if(v[i] != 0){
			ans+= func(v[i]);
		}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 11128
n = int(input())
a = list(map(int, input().split()))

a_dict = dict()
for i in a:
    if i not in a_dict:
        a_dict[i] = 1
    else:
        a_dict[i] += 1

total = 0
for k, v in a_dict.items():
    if v > 1:
        total += int(v * (v - 1) / 2)

for i in a:
    print(total - a_dict[i] + 1)


Measured memory_bytes: 86732
#include <iostream>
#include <algorithm>

using namespace std;
static const int SIZE = 101;
static const long long int INF = 1e18;
long long int d[SIZE][SIZE] = { 0 };

void solve()
{
	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			d[i][j] = INF;
		}
		d[i][i] = 0;
	}
	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; ++i)
	{
		int from, to, cost;
		cin >> from >> to >> cost;
		d[from][to] = cost;
	}
	for (int k = 0; k < V; ++k)
	{
		for (int i = 0; i < V; ++i)
		{
			for (int j = 0; j < V; ++j)
			{
				if (d[i][k] != INF && d[k][j] != INF)
				{
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
	bool isNegative = false;
	for (int i = 0; i < V; ++i)
	{
		if (d[i][i] < 0)
		{
			cout << "NEGATIVE CYCLE" << endl;
			return;
		}
	}
	for (int i = 0; i < V; ++i)
	{
		for (int j = 0; j < V; ++j)
		{
			if (j)
			{
				cout << " ";
			}
			if (d[i][j] == INF)
			{
				cout << "INF";
			}
			else
			{
				cout << d[i][j];
			}
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long num;
    while(cin>>num)
    {
        long long arr[num+5],count[num+5]={0};
        for(long long i=0;i<num-1;i++)
        {
            cin>>arr[i];
            count[arr[i]]++;
        }
        for(long long i=1;i<=num;i++)
        {
            cout<<count[i]<<endl;
        }
      break;
    }
}


Measured memory_bytes: 6716
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>


int main(){
	int n, k;
	std::cin >> n >> k;
	if(k == 1){
		std::cout << 0 << std::endl;
	}else{
		std::cout << n - k << std::endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>
#include<random>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[200010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;


int main(){
    cin>>a>>b>>x;
    C x/a*b E;
}


//g++ atcoder.cpp ; ./a.exe

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

using namespace std;

int main()
{

    int a , b , c;

    cin >> a >> b >> c;

    int p = a;

    if(a > b)
    {
        a = b;
        b = p;
    }

    if(c >= a && c <= b)
    {
        cout << "Yes" << endl;
    }
    else
       cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
/// In The Name Of God

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n;
int a[N], b[N];

vector <int> st;
ll ans;
int get(int l, int r) {
	if (l > r) return 0;
	return upper_bound(all(st), r) - lower_bound(all(st), l);
}
void solve(int k) {
	st.clear();
	int m1 = (1 << k), m2 = m1 << 1;
	for (int i = 1; i <= n; i++) {
		st.pb(a[i] % m2);
	}
	sort(all(st));
	ll cnt = 0;
	for (int i = 1; i <= n; i++) {
		int cur = b[i] % m2;

		cnt += get(m1 - cur, m2 - cur - 1);
		cnt += get(m1 + m2 - cur, m2 << 1);
	}
	if (cnt & 1) ans += 1 << k;
}
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < 30; i++) {
		solve(i);
	}
	cout << ans;
	ioi
}


Measured memory_bytes: 2936
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];

            }
            int[] A = Input.ReadIntArray();

            int[] B = new int[M];
            int[] C = new int[M];
            for (int i = 0; i < M; i++)
            {
                var line = Input.ReadIntArray();
                B[i] = line[0];
                C[i] = line[1];
            }

            Dictionary<long, long> dic = new Dictionary<long, long>();
            for (int i = 0; i < A.Length; i++)
            {
                if(!dic.ContainsKey(A[i]))
                    dic.Add(A[i], 0);
                dic[A[i]]++;
            }

            for (int i = 0; i < M; i++)
            {
                if(!dic.ContainsKey(C[i]))
                    dic.Add(C[i], 0);
                dic[C[i]] += B[i];
            }

            var lst = dic.Keys.ToList();
            lst.Sort();
            lst.Reverse();

            long c = N;
            long ret = 0;
            for (int i = 0; i < lst.Count; i++)
            {
                ret += Math.Min(c, dic[lst[i]]) * lst[i];
                c -= dic[lst[i]];
                if (c <= 0) break;
            }
            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 42120
n = int(input())
mojiretues = []
for _ in range(n):
	s = list(input())
	s.sort()
	mojiretues.append("".join(s))
mojiretues.sort()

prestr = mojiretues[0]
cnt = 1
ans = 0
for s in mojiretues[1:]:
	if prestr == s:
		ans += cnt
		cnt += 1
	else:
		prestr = s
		cnt = 1

print(ans)


Measured memory_bytes: 57944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
 
public class Main {
	static FastReader input = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
 
	static int n, w;
	static int[][] wV;
	static long[][] memo;
	static final int  _INF = (int)-1e9;
	
	static long solve (int n, int w) {
		
		if (w<0) 
			return _INF;
		
		if (n<0) return 0;
		
		if (memo[n][w]!=-1) return memo[n][w];
		long x  = wV[n][1]+solve(n-1, w-wV[n][0]); 
		long y  = solve(n-1, w); 
		
		return memo[n][w] = Math.max(x, y);
		
	}
 
	public static void main(String[] args) throws NumberFormatException, IOException {
 
		n = input.nextInt();
		w = input.nextInt();
 
		wV = new int[n][2];
 
		for (int i = 0; i < n; i++) {
			wV[i][0] = input.nextInt();
			wV[i][1] = input.nextInt();
		}
 
		memo = new long[n + 5][(int) 1e5 + 100];
 
		for (int i = 0; i < memo.length; i++)
			Arrays.fill(memo[i], -1);
		
		
		System.out.println(solve (n-1,w));
	}
 
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() throws IOException {
			while (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}
 
		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
 
		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
 
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
 
		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          string s = Input.ScanStr();
          List<int> num = new List<int>();
          
          for(int i=0;i<s.Length-2;i++)
            num.Add(int.Parse(s.Substring(i,3)));
          num = num.Select(x=>Math.Abs(753-x)).ToList();
          Console.WriteLine(num.Min());
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a <= 2 * b) {
            System.out.println(0);
            return;
        }
        System.out.println(a - 2 * b);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >>c;
    if(c<=a+b) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}


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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()
#define MP(n, m) make_pair(n, m);

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;
using ul = unsigned long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

int binary_search(VI& a, int key) {
    int left = 0, right = (int)a.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (a[mid] == key) return mid;
        else if (a[mid] > key) right = mid - 1;
        else if (a[mid] < key) left = mid + 1;
    }
    return -1;
}

void printv(VI& v){
  REP(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

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

	int n,d;
	cin>>n>>d;

  int ans = n/(2*d+1);
  if(n%(2*d+1)!=0)ans++;

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int N = int.Parse(strs[0]);
            int K = int.Parse(strs[1]);

            long sum = 0;
            long MAX = 0;
            long MIN = 0;
            for(int i = 1; i < K; i++)
            {
                MAX += N - i + 1;
                MIN += i - 1;
            }
            for (int i = K; i <= N + 1; i++)
            {
                //場合の数を数えたいが…
                //どんな数ができるか→0+1+2+3…+K-1～N+1+N+N-1+…N-K+1
                MAX += N - i + 1;
                MIN += i - 1;

                sum += MAX - MIN + 1;
                sum %= 1000000007;
            }

            Console.WriteLine(sum);
        }

        //static long calcCombination(int N, int R)
        //{
        //    long ret = 1;
        //    for(int i = 1; i <= R; i++)
        //    {
        //        ret = ret * (N - i + 1) / i;
        //    }
        //    return ret;
        //}

    }
}


Measured memory_bytes: 27464
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

	Scanner std = new Scanner(System.in);


	List<Integer> list = new ArrayList<>();
	int N = std.nextInt();
	int X = std.nextInt();

	int count = 1; //跳ねる回数
	int zahyo = 0; //座標

	for(int i = 0; i < N; i++) {
		int L = std.nextInt();
		list.add(L);

	}

	//count <= N+1 条件1
	//足していってた座標がX以下
	//

	for(int i = 0; i < N; i++) {
		zahyo += list.get(i);
		if(count > N+1 || zahyo > X) {
			break;
		}
		count++;
	}
		System.out.println(count);

	}


	}




Measured memory_bytes: 23636
#include <stdio.h>
#include <string.h>

int main() {
  char S[11];
  char T[11];
  char U[11];
  int A, B;

  scanf("%s %s",S,T);
  scanf("%d %d",&A,&B);
  scanf("%s",U);
  if (strcmp(S, U) == 0) {
    A = A - 1;
  } else {
    B = B - 1;
  }
  printf("%d %d",A,B);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	char a, b;
	cin >> a >> b;
	if (a < b) cout << "<" << endl;
	else if (a == b)cout << "=" << endl;
	else cout << ">" << endl;
}

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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
ll n,p,cto,cte;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>p;
    ll p2[60];
    p2[0]=1LL;
    rep(i,1,55) p2[i]=(2*p2[i-1]);
    while(n--){
        ll x;cin>>x;
        if(x%2) cto++;
        else cte++;
    }
    ll tot=0;
    if(cto>0){
        cout<<p2[cto+cte-1]<<endl;
    }
    else{
        if(p == 1) cout<<0<<endl;
        else cout<<p2[cto+cte]<<endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int N,target,counter[1001]={};
	ll result=1;
	cin>>N;

	FOR(i,2,N+1){
		target=i;
		FOR(j,2,i+1){
			if(target%j==0){
				while((target%j)==0){	
					target/=j;
					counter[j]++;
				}
			}
			if(target==1) break;
		}
		if(target==i) counter[i]=1;
	}
	
	FOR(i,2,N+1) if(counter[i]!=0) result=(result*(counter[i]+1))%MOD;
	

	cout<<result<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, m, i, j, min;
  int move, stay;
  int d[1000];
  int c[1000];
  int dp[1000][1000];

  // dpテ・ツ按敕ヲツ慊淌・ツ個?
  for(i = 0; i < 1000; i++){
    for(j = 0; j < 1000; j++){
      dp[i][j] = (i == 0) ? 0 : -1;
    }
  }


  scanf("%d%d", &n, &m);
  //printf("%d %d\n", n, m);
  for(i = 1; i <= n; i++){
    scanf("%d", &d[i]);
    //printf("d[%d]:%d\n", i, d[i]);
  }
  for(i = 1; i <= m; i++){
    scanf("%d", &c[i]);
    //    printf("c[%d]:%d\n", i, c[i]);
  }

  // dpテ、ツスツ愿」ツつ?
  // jテヲツ猟・テァツ崢ョテ」ツ?ォテゥツδステ・ツクツＪテ」ツ?ォテ」ツ??」ツつ凝」ツ?淌」ツつ?」ツ?ョテヲツ慊?・ツーツ湘」ツつウテ」ツつケテ」ツδ暗」ツつ津ヲツアツづ」ツつ?」ツつ?
  for(i = 1; i <= n; i++){
    for(j = i; j <= m; j++){
      // 1テヲツ猟・テ」ツ?凝」ツ?妥」ツ?ヲテ」ツつ?」ツ?」テ」ツ?ヲテ」ツ?湘」ツつ?
      move = dp[i-1][j-1] + d[i]*c[j];
      // テ・ツ可催ヲツ猟・テ」ツ?凝」ツつ嘉」ツ??」ツ?ヲテ」ツ??ァツァツサテ・ツ仰陛」ツ?療」ツ?ェテ」ツ??
      // テ・ツ可催ヲツ猟・テ」ツ?セテ」ツ?ァテ」ツ?ョテ・ツ按ーテァツ敖?ヲツδ?・ツ?アテ」ツ?古」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌・ツ?エテ・ツ青暗」ツ??ヲツュツゥテ」ツ??」ツ?ヲテ」ツ?湘」ツつ凝」ツ?療」ツ?凝」ツ?ェテ」ツ??」ツ?ョテ」ツ?ァmoveテ」ツ?ィテ・ツ青古」ツ?佚」ツ?ォテ」ツ?凖」ツつ?
      stay = (dp[i][j-1] < 0) ? move : dp[i][j-1];
      // テ・ツーツ湘」ツ?陛」ツ??ヲツ鳴ケテ」ツつ津」ツ?ィテ」ツつ?
      dp[i][j] = (move < stay) ? move : stay;
    }
  }

  /*
    // dpテ」ツ?ョテ、ツクツュティツコツォテ」ツつ津ァツ「ツコティツェツ催ッツシツ暗」ツδ?」ツδ静」ツδε」ツつーテァツ板ィテッツシツ?
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      printf("%8d", dp[i][j]);
    }
    printf("\n");
  }
  */


  // テゥツδステ・ツクツ?テ」ツ?ォテ・ツ按ーテァツ敖?」ツ?療」ツ?淌ヲツ卍づァツつケテ」ツ?ァテ」ツ?ョテ」ツつウテ」ツつケテ」ツδ暗」ツ?ョテヲツ慊?・ツーツ湘」ツつ津ヲツアツづ」ツつ?」ツつ?
  min = dp[n][n];
  for(i = n+1; i <= m; i++){
    min = min < dp[n][i] ? min : dp[n][i];
  }
  printf("%d\n", min);

  return 0;
}

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

ll k[200005] = {};
ll c[200005] = {};

int main (){
    int n;
    cin >> n;
    ll a[n+5];
    rep(i,n){
        cin >> a[i];
        k[a[i]] += 1;
    }
    ll sum = 0;
    rep(i,n){
        if(c[a[i]]==0){
            c[a[i]] = (k[a[i]] * (k[a[i]] - 1))/2;
            sum += c[a[i]];
        }
    }
    rep(i,n){
        ll ans = sum - c[a[i]];
        ans += ((k[a[i]] - 1) * (k[a[i]] - 2) / 2);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6272
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    string t=s;
    reverse(s.begin(),s.end());
    if(s.compare(t)==0)
    {
        int n=s.length();
        string ss,tt;
        for(int i=0;i<n/2;i++)
            ss.push_back(t[i]);
        for(int i=n/2+1;i<n;i++)
            tt.push_back(t[i]);
        string ssr,ttr;
        ssr=ss;
        ttr=tt;
        reverse(ss.begin(),ss.end());
        reverse(tt.begin(),tt.end());
        if(ss.compare(ssr)==0 && tt.compare(ttr)==0)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    else
    cout<<"No\n";
}

Measured memory_bytes: 256
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N+1-i):
        k = N-(i+j)
        if Y == 10000*i + 5000*j + 1000*k:
            print(i,j,k)
            sys.exit()

print(-1,-1,-1)


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << 1 << endl;
	}
	else if (a == b || b == c || c==a) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}
}

Measured memory_bytes: 256