akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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;
}
using namespace std;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int pre[200005];//ある色について今見ている位置より前において、どこに出てきたか
void solve(){
    int n;
    cin>>n;
    vector<ll>dp(n+5,0);
    vector<int>c(n);
    memset(pre,-1,sizeof(pre));
    rep(i,n){
      cin>>c[i];
    }
    dp[0]=1;pre[c[0]]=0;
    for(int i=1;i<n;++i){
      if(c[i-1]==c[i]||pre[c[i]]==-1)dp[i]=dp[i-1];//色が１つ前と同じだったり、はじめてその色が出てきた時は1つ前と方法の数は変わらず
      else dp[i]=(dp[i-1]+dp[pre[c[i]]])%mod;
      pre[c[i]]=i;
    }
    cout<<dp[n-1]<<"\n";
    return;
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct UnionFind
{
  vector<int> par;
  vector<int> siz;
  UnionFind(int N) : par(N), siz(N, 1) {for (int i = 0; i < N; i++) par[i] = i;}
  void init(int N) {
    siz.assign(N, 1);
    par.resize(N);
    for(int i = 0; i < N; ++i) par[i] = i;
  }
  int root(int x) {
    while(par[x] != x) {x = par[x] = par[par[x]];}
    return x;
  }
  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool isSame(int x, int y) {return root(x) == root(y); }
  int size(int x) { return siz[root(x)]; }
};
int main()
{
  int n, m;
  cin >> n >> m;
  UnionFind uf(n+1);
  rep(i, m) {
    int x, y, z; cin >> x >> y >> z;
    uf.unite(x, y);
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(uf.par[i] == i) ++ans;
  }
  cout << ans << endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int h, a;
	cin >> h >> a;
	cout << (h - 1) / a + 1;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

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

int main(){
    int n, max=0, cnt=0; cin >> n;
    rep(i, n){
        int l;
        cin >> l;
        cnt+=l;
        if(max<l) max=l; 
        }
    if(max<(cnt-max)) out("Yes");
    else out("No");
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int n;
    cin >> n;
    int tmp;
    int compare = -1;
    int ans = 0;
    rep(i,n)
    {
        cin >> tmp;
        if(compare <= tmp)
        {
            ans++;
            compare = tmp;
        }
    }
    cout << ans << endl;

        


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n,i,ans=0;
  string s;
  cin >> n >> s;
  i=0;
  while (i<n){
    while (i<n && s[i]==s[i+1]) i++;
    ans++;
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
H, W, K = map(int, input().split())
cake = [input() for _ in range(H)]
rows = []
has_strawberry = False
for i in range(H):
    if "#" in cake[i]:
        if has_strawberry:
            rows.append(i)
        else:
            has_strawberry = True

rows += [H]

cols = [[] for _ in range(len(rows))]
prev_r = 0
for r in range(len(rows)):
    has_strawberry = False
    for j in range(W):
        if any(cake[i][j] == "#" for i in range(prev_r, rows[r])):
            if has_strawberry:
                cols[r].append(j)
            else:
                has_strawberry = True
    cols[r].append(W)
    prev_r = rows[r]

ans = [[-1] * W for _ in range(H)]
curr_color = 1
prev_r = 0
for r in range(len(rows)):
    prev_c = 0
    for c in range(len(cols[r])):
        for i in range(prev_r, rows[r]):
            for j in range(prev_c, cols[r][c]):
                ans[i][j] = curr_color
        curr_color += 1
        prev_c = cols[r][c]
    prev_r = rows[r]
[print(*row) for row in ans]


Measured memory_bytes: 13748
n = int(input())
s = [1 if i=="R" else 2 if i=="G" else 4 for i in input()]
r = s.count(1)
g = s.count(2)
b = s.count(4)
ans = r*g*b
for i in range(n-1):
    for j in range(1, (n-i-1)//2+1):
        if s[i] + s[i+j] + s[i+j+j] == 7:
            ans -= 1
print(ans)

Measured memory_bytes: 9092
input1 = int(input())
input_list = list(map(int, input().split()))

done_dict = {}
sum = 0
for i in range(input1):
    for j in range(input1):
        if i != j and (not done_dict.get(j)):
            sum += input_list[i] * input_list[j]
#            print("i:", i, "j:", j, " ", input_list[i] * input_list[j])
    done_dict[i] = True
print(sum)


Measured memory_bytes: 2940
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def n_based(n:int, base:int) -> str:
    if n == 0:
        return "0"
    
    ans = ""
    res = n
    
    while abs(res) > 0:
        q = res%base
        if q>=0:
            ans = str(q) + ans
            res //= base
        else:
            q += abs(base)
            ans = str(q) + ans
            res //= base
            res += 1
        
    return ans

n = ni()
print(n_based(n,-2))

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

/*----------------------------- DEFINES ------------------------------*/

#define eps 1e-9
#define mod 1000000007
#define ump unordered_map // operations take less time compared to map
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define mp make_pair
#define ps(x) push(x) // for stack and queue
#define T top() //  for stack
#define FR front()// for queue
#define BA back()// for queue
#define PP pop()// for queue and stack
#define B begin()
#define E end()
#define F first
#define S second
#define tostr(x) to_string(x)
#define SZ(x) ((int)x.size())
#define ins insert
#define MAE max_element
#define MIE min_element
#define cnt(x) count(x)
#define lb(x) lower_bound(x) // returns an it ptng to the element >=x if no such returns end
#define ub(x) upper_bound(x) // returns an it ptng to the element >x if no such returns end
#define rep(i,x,y) for(int i=x;i<y;i++)
#define per(i,x,y) for(int i=x;i>y;i--)
#define repi(i,x,y) for(int i=x;i<=y;i++)
#define peri(i,x,y) for(int i=x;i>=y;i--)
#define reps(i,x,y,k) for(int i=x;i<y;i+=k)
#define sper(i,x,y,k) for(int i=x;i>y;i-=k) 
#define all(x) ((x.B),(x.E))
#define inf (ll)LLONG_MAX
#define ds1(i,x) for(auto i=x.begin();i!=x.end();i++)
#define ds2(i,x) for(auto i:x) // easy method to iterate through a ds
#define sq(a) (a)*(a)
#define fib(n) ceil(pow((1+sqrt(5),n)-pow((1-sqrt(5),n)/(float)(pow(2,n)*sqrt(5)// compute fib(n) in O(1)
#define FIO {ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}// fast i/o
#define dig(n) (int)(log10(n)+1) // num of digits
#define ss(x,k) substr(x,k)  // x is the start pos and k is the length of substr.
#define f(x) find(x)
#define set(x,k) memset(x,k,sizeof x)

/*------------------------------ TYPEDEFS-----------------------------*/

typedef long long ll;
typedef long l;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<pair<int,int> > vpii;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef ump<int,int> umpii;

/*-----------------------------START FROM HERE -----------------------*/

int main(){
	FIO
	
	int n;cin>>n;cout<<n*(n+1)/2;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(ll x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,k,now=0;
ll ans;
map<int,int>mp,m;
int main(){
	read(n),read(k);
    mp[0]=1;
    for(int i=1;i<=n;i++){
  		int x;
        read(x);
		now=(now+x-1)%k;
    	m[i+1]=now;
        if(i>=k)mp[m[i-k+1]]--;
        ans+=mp[now],mp[now]++;
    }
    write(ans);
}

Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

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

	int sz = T.length();

	if(S == T.substr(0,sz-1)){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
		return 0;
}



Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define MN 1000
#define MM 200000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
vector<int> v[MN+5],w[MN+5],V[MN+5],W[MN+5];
int n,m,bel[MN+5],head[MN+5],cnt,Ans[MM+5],q[MN+5],cc,in[MN+5],now,vis[MN+5];
int top,dfn[MN+5],low[MN+5],c[MN+5],num,dn,inq[MN+5],mx[MN+5],mn[MN+5],f[MN+5];
struct edge{int to,next,w;}e[MM+5];
inline void ins(int f,int t,int w){e[++cnt]=(edge){t,head[f],w};head[f]=cnt;}
void MarkMn(int x,int c)
{
	mn[x]=c;
	for(int i=0;i<v[x].size();++i) 
		if(!(x==now&&i+1>c)&&mn[v[x][i]]==n) MarkMn(v[x][i],c);
}
void MarkMx(int x,int c)
{
	mx[x]=c;
	for(int i=0;i<v[x].size();++i) 
		if(!(x==now&&i+1<c)&&!mx[v[x][i]]) MarkMx(v[x][i],c);
}
void Solve()
{
	for(int i=1;i<=num;++i) for(int j=head[c[i]];j;j=e[j].next) 
		if(bel[e[j].to]==cc) v[c[i]].push_back(e[j].to),w[c[i]].push_back(e[j].w);
	for(int i=1;i<=num;++i)
	{
		for(int j=1;j<=num;++j) mx[c[j]]=0,mn[c[j]]=n;now=c[i];
		for(int j=0;j<v[c[i]].size();++j) if(mn[v[c[i]][j]]==n) MarkMn(v[c[i]][j],j+1);
		for(int j=v[c[i]].size()-1;~j;--j) if(!mx[v[c[i]][j]]) MarkMx(v[c[i]][j],j+1);
		for(int j=1;j<=num;++j) 
			if(i!=j&&mn[c[j]]==mx[c[j]]) Ans[w[c[i]][mn[c[j]]-1]]=1;
	}
}
void Tarjan(int x)
{
	dfn[x]=low[x]=++dn;q[++top]=x;inq[x]=1;
	for(int i=head[x];i;i=e[i].next)
		if(!dfn[e[i].to]) Tarjan(e[i].to),low[x]=min(low[x],low[e[i].to]);
		else if(inq[e[i].to]) low[x]=min(low[x],dfn[e[i].to]);
	if(dfn[x]==low[x])
	{
		for(num=0,++cc;q[top+1]!=x;inq[q[top--]]=0) c[++num]=q[top],bel[q[top]]=cc;
		Solve();	
	}
}
void dfs(int x)
{
	vis[x]=1;
	for(int i=0;i<V[x].size();++i)
		if(++in[V[x][i]],!vis[V[x][i]]) dfs(V[x][i]);	
}
inline void R(int&x,int y){x=min(2,x+y);}
int main()
{
	n=read();m=read();
	for(int i=1,j;i<=m;++i) j=read(),ins(j,read(),i);
	for(int i=1;i<=n;++i) if(!dfn[i]) Tarjan(i); 
	for(int i=1;i<=n;++i) for(int j=head[i];j;j=e[j].next) if(bel[i]!=bel[e[j].to]) 
		V[bel[i]].push_back(bel[e[j].to]),W[bel[i]].push_back(e[j].w);
	for(int i=1;i<=cc;++i)
	{
		memset(f,0,sizeof(f));
		memset(in,0,sizeof(in));
		memset(vis,0,sizeof(vis));
		f[i]=1;q[top=1]=i;dfs(i);
		for(int j=1;j<=top;++j)
			for(int k=0;k<V[q[j]].size();++k)
				if(R(f[V[q[j]][k]],f[q[j]]),!--in[V[q[j]][k]]) q[++top]=V[q[j]][k];
		for(int j=0;j<V[i].size();++j) if(f[V[i][j]]!=1) Ans[W[i][j]]=1;
	}
	for(int i=1;i<=m;++i) puts(Ans[i]?"diff":"same");
	return 0;
}



Measured memory_bytes: 7296
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let time: i64 = (1900 * m + 100 * (n - m)) as i64;

    let e: i64 = 2_i64.pow(m as u32);

    let ans: i64 = time * e;

    return ans.to_string();
}


Measured memory_bytes: 4352
n,m = map(int,input().split())
city = []
for i in range(n):
    city.append([i,0])

for i in range(m):
    a,b = map(int,input().split())
    city[a-1][1] += 1
    city[b-1][1] += 1

for j in range(n):
    print(city[j][1])


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
    int W, H, x, y, r, f=0;
    scanf("%d%d%d%d%d", &W,&H,&x,&y,&r);
    if(x-r<0 || W<x+r) f=1;
    if(y-r<0 || H<y+r) f=1;
    puts(f?"No":"Yes");
}

    
    


Measured memory_bytes: 2076
#include <stdio.h>

int main(void) {
  int i, j, k, n, ans = 1, now = 1, a;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(a) ++now;
    else {
      if(ans < now) ans = now;
      now = 1;
    }
  }
  if(now > ans) ans = now;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2680
N, K, Q = map(int, input().split())
A = {i:K - Q for i in range(1, N+1)}
for i in range(Q):
  A[int(input())] += 1

for i in range(1, N+1):
  if A[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 17900
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <stack>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef bitset<128> Bit;

int n, m;
string input[128];
int memo[177147];               // 3^11
Bit table[11];
Bit iniS;
// qS[i] = j : iツ氾板姪堋づ個篠ソツ姪「ツづーyes/noツづ猟伉用

int dfs(int qS) {
  if (memo[qS] >= 0) return memo[qS];
  int tmp = qS;
  int res = INF;
  Bit manS = iniS;
   tmp = qS;
  REP(i, m) {
    if (tmp%3==1)
      manS &= table[i];
    else if(tmp%3==2)
      manS &= ~table[i];
    tmp /= 3;
  }
  if (manS.count() <= 1) return memo[qS] = 0;
  int hoge = 1;
  tmp = qS;
  REP(i, m) {
    if (tmp%3 == 0) {
      int nextqS1 = qS + hoge;
      int nextqS2 = qS + hoge*2;
      //cout << dfs(nextqS1) << " " << dfs(nextqS2) << endl;
      res = min(res, max(dfs(nextqS1), dfs(nextqS2)) + 1);
    }
    hoge *= 3;
    tmp /= 3;
  }
  // cout << manS << " ";
  // tmp = qS;
  // REP(i, m) {
  //   cout << tmp%3;
  //   tmp/=3;
  // }
  // cout << " " << res << endl;
  return memo[qS] = res;
}

int main() {
  while(cin>>m>>n,n||m) {
    REP(i, n) cin >> input[i];
    REP(j, m) {
      table[j].reset();
      REP(i, n)
        if (input[i][j] == '1')
          table[j].set(i);
    }
    iniS.reset();
    REP(i, n) iniS.set(i);
    memset(memo,-1,sizeof(memo));
    cout << dfs(0) << endl;
  }
}

Measured memory_bytes: 1632
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '?')
            s[i] = 'D';
    }

    cout << s << endl;

    // int ans = 0;
    // for (int i = 0; i < s.size(); i++)
    // {
    //     if (s[i] == 'P')
    //         continue;
    //     else if (i - 1 >= 0 && s[i] == 'D' && s[i - 1] == 'P')
    //         ans++;
    //         ans++;
    //     else if (s[i] == 'D')
    //         ans++;
    // }

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


Measured memory_bytes: 3724
#include<stdio.h>
int main(void)
{
	int a,s[200],d[200],f[200],g[200],h[200],z[200],x[200],j,i;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		scanf("%d %d %d",&s[i],&d[i],&f[i]);
		g[i]=0;
		h[i]=0;
		z[i]=0;
		x[i]=0;
	}
	for(i=1;i<=a;i++){
		for(j=i+1;j<=a;j++){
			if(s[i]==s[j]){
				g[i]=1;
			}
			if(d[i]==d[j]){
				h[i]=1;
			}
			if(f[i]==f[j]){
				z[i]=1;
			}
		}
	}
	for(i=1;i<=a;i++){
		for(j=i-1;j>=0;j--){
			if(s[i]==s[j]){
				g[i]=1;
			}
			if(d[i]==d[j]){
				h[i]=1;
			}
			if(f[i]==f[j]){
				z[i]=1;
			}
		}
	}
	for(i=1;i<=a;i++){
		if(g[i]==0){
			x[i]=x[i]+s[i];
		}
		if(h[i]==0){
			x[i]=x[i]+d[i];
		}
		if(z[i]==0){
			x[i]=x[i]+f[i];
		}
	}
	for(i=1;i<=a;i++){
		printf("%d\n",x[i]);
	}
	return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;

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

		int A = sc.nextInt();
		int P = sc.nextInt();
		int count = 0;
		int sum = 0;

		for (int i = 0; i < A; i++) {
			count += 3;
		}

		System.out.println((count + P) / 2);
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int a[MAX_N];
int b[MAX_N];


int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int K;
  cin >> K;


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

  int ar[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << ar[K-1] << endl;
  

  return 0;
  
}


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

long long int dp[110][1<<16];

int main(int argc, char *argv[]){
  int n;
  while(cin >> n, n){
    int m;
    vector<int> l(n, 0), t(n, 0);
    for (int i = 0; i < n; i++) {
      cin >> m >> l[i];
      int s, e;
      for (int j = 0; j < m; j++) {
        cin >> s >> e;
        for (int k = s - 6; k < e - 6; k++)
          t[i] |= 1<<k;
      }
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < (1<<16); j++) {
        dp[i][j] = -1;
      }      
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < (1<<16); j++) {
        if(dp[i][j] < 0)continue;
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        if((t[i]&j) > 0)continue;
        dp[i + 1][j | t[i]] = max(dp[i + 1][j | t[i]], dp[i][j] + l[i]);
      }
    }
    long long int ans = 0;
    for (int i = 0; i < (1<<16); i++) {
      ans = max(ans, dp[n][i]);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 54712
# -*- coding: utf-8 -*-
a = int(input())
b = list(map(int,input().split()))
z_o_cnt = []
max_b = max(b)
base = 0
while True:
    z_o_cnt.append(sum(list(map(lambda x:x%2,b))))
    b = list(map(lambda x:x//2,b))
    max_b //=2
    if max_b==0:
        break
ret = 0
for i,v in enumerate(z_o_cnt):
    ret+=(2**i*(v * (a-v)))%(10**9+7)
print(ret%(10**9+7))

Measured memory_bytes: 137024
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
A.sort()
sumA=sum(A)

# N-1 .. 0
cnum = 1
for i in range(N-1,0,-1):
    sumA -= A[i]
    if sumA * 2 < A[i]:
        break
    else:
        cnum += 1
print(cnum)


Measured memory_bytes: 14304
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long L;
typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define fst first
#define snd second

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

const string type = "BW";


void dfs(vector< vector< pair<char, int> > >& area, int curx, int cury, int t) {
	int H = area.size();
	int W = area[0].size();

	for (int i = 0; i < 4; i++) {
		int x = curx + dx[i];
		int y = cury + dy[i];

		if (!(0 <= x && x < W && 0 <= y && y < H) ||
			type.find(area[y][x].fst) != string::npos ||
			area[y][x].snd & t
			) {
			continue;
		}

		area[y][x].snd |= t;
		dfs(area, x, y, t);
	}
}

int main(void) {
	for (int W, H; cin >> W >> H, W; ) {
		vector< vector< pair<char, int> > > area(H, vector< pair<char, int> >(W, pair<char, int>('.', 0)) );
		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				cin >> area[y][x].fst;
			}
		}

		for (int t = 0; t < 2; t++) {
			for (int y = 0; y < H; y++) {
				for (int x = 0; x < W; x++) {
					if (type.find(area[y][x].fst) == t) {
						dfs(area, x, y, t + 1);
					}
				}
			}
		}

		// cnt
		int cnt[2] = {0, 0};
		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if (area[y][x].snd == 1 || area[y][x].snd == 2) {
					cnt[area[y][x].snd - 1]++;
				}
			}
		}

		//
		cout << cnt[0] << " " << cnt[1] << endl;
	}


	return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int a, b;
  string res;
  cin >> a>>b;

  if(a==1) a=14;
  if(b==1) b=14;

  if(a>b) res="Alice";
  if(a==b)res="Draw";
  if(a<b) res="Bob";
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
//#include <cmath>
#include <cstdlib>

using namespace std;

int main(){

    int n;
    cin >> n;
    int a=0,b=0,c=0;
    for(int i=0;i<n;i++){
        int d;
        cin >> d;
        if(d%4 == 0) c++;
        else if(d%4 == 2) b++;
        else a++;
    }

    if(b == 0){
        if(c >= n/2) cout << "Yes";
        else cout << "No";
    }else{
        if(c >= a) cout << "Yes";
        else cout << "No";
    }
  	//cout << endl << a << b << c;

    
    return 0;
}

Measured memory_bytes: 256
/*input
10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776
*/
#include <bits/stdc++.h>
using namespace std;

int n, now;
int ans = 0;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> now;
        while (now % 2 == 0) {
            now /= 2;
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
/**
 * Created by iainws on 4/09/16.
 */

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReaderMain in = new InputReaderMain(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskMain solver = new TaskMain();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskMain {
    public void solve(int taskNumber, InputReaderMain in, PrintWriter out) {
        String a;
        String b;
        String c;
        a = in.next();
        b = in.next();
        c = in.next();
        char q = a.charAt(a.length() - 1);
        a = a.substring(0, a.length() - 1);
        while (true) {
            if (q == 'a') {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                q = a.charAt(0);
                a = a.substring(1, a.length());
            }
            else if (q == 'b') {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                q = b.charAt(0);
                b = b.substring(1, b.length());
            }
            else if (q == 'c') {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                q = c.charAt(0);
                c = c.substring(1, c.length());
            }
        }
    }
}

class InputReaderMain {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReaderMain(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

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

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

}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n), b(n);
    for (auto &x : a) cin >> x;
    for (auto &x : b) cin >> x;

    int ans = 0;
    vector<int> bb(n);
    for (int i = 0, t = 1; i < 29; ++i) {
        for (int j = 0; j < n; ++j)
            bb[j] = b[j] % (2 * t);

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

        ll cnt = 0;
        for (int j = 0; j < n; ++j) {
            const int aa = a[j] % (2 * t);

            // a_j + b_k \in [T, 2T)
            cnt += distance(lower_bound(bb.begin(), bb.end(), t - aa),
                            lower_bound(bb.begin(), bb.end(), 2 * t - aa));

            // a_j + b_k \in [3T, 4T)
            cnt += distance(lower_bound(bb.begin(), bb.end(), 3 * t - aa),
                            lower_bound(bb.begin(), bb.end(), 4 * t - aa));
        }

        // Update
        ans += (cnt % 2) * t;
        t *= 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

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

ll N,M,x,y,z;
bool visited[100002];
vector<vector<ll> > edge(100002);

void dfs(ll i){
    // visitedにする
    visited[i] = true;

    //繋がっているてんのうち、visitedじゃない点を選んでdfsする
    llrep(j,edge[i].size()){
        ll cur = edge[i][j];
        if (!visited[cur]){
            dfs(cur);
        }
    }
    return;
}

int main(){
    cin >> N >> M;

    llrep(i,M){
        cin >> x >> y >> z;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    ll ans=0;

    //グラフの連結成分を数える
    llRep(i,N){
        if(!visited[i]){
            dfs(i);
            ans ++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int n,d,x;  cin>>n>>d>>x;
    int sum=x;

    for(int i=0;i<n;i++){
        int a;  cin>>a;
        sum+= (d+a-1)/a;
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
def main(X, Y):
    for n_crane in range(X + 1):
        n_turtle = X - n_crane
        y = n_crane * 2 + n_turtle * 4
        if y == Y:
            print('Yes')
            return
    print('No')


if __name__ == "__main__":
    X, Y = [int(s) for s in input().split(' ')]
    main(X, Y)


Measured memory_bytes: 9016
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int N; cin >> N;

	
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		while(a % 2 == 0) {
			a /= 2;
			ans++;	
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int A,i,cnt=0;
	scanf("%d",&A);
	for(i=1;i<10;i++){
		if(A%i==0){
			if(A/i<10){
				printf("Yes");
				cnt++;
				break;
			}
		}
	}
	if(cnt==0){
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>

using namespace std;

int main ()
{
    double a, b, c, d, e, f, x, y;
    while(cin>>a>>b>>c>>d>>e>>f){
        x = (c*e - b*f) / (a*e - b*d);
        y = (a*f - c*d) / (a*e - b*d);
        x = round(x * 1000) / 1000;
        y = round(y * 1000) / 1000;
        if(fabs(x) < 1e-8) x = 0;
        if(fabs(y) < 1e-8) y = 0;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 1248
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)


def main():
    N = int(input())
    X = list(map(int,input().split()))

    ans = 10**20
    for p in range(101):
        sum = 0
        for i in range(0,N):
            sum += (X[i] - p)**2

        ans = min(ans,sum)

    print(ans)

if __name__ == "__main__":
  main()


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

using namespace std;

int dfs(int src, vector<int>& dp, vector<bool>& vis, vector<vector<int>>& lst)
{
	if (!vis[src]) {
		for (int nbr : lst[src]) {
			dp[src] = max(dp[src], 1 + dfs(nbr, dp, vis, lst));
		}
		vis[src] = true;
	}
	return dp[src];
}

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

	int n, m; cin >> n >> m;
	vector<vector<int>> lst(n + 1);
	for (int i = 0; i < m; ++i) {
		int x, y; cin >> x >> y;
		lst[x].push_back(y);
	}
	vector<int> dp(n + 1);
	vector<bool> vis(n + 1);
	int max_len = 1;
	for (int i = 1; i <= n; ++i) {
		max_len = max(max_len, dfs(i, dp, vis, lst));
	}
	cout << max_len << endl;
}


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

int main() {
	int n;
	scanf("%d", &n);
	int arr[n];
	for (int i=0; i<n; i++) scanf("%d", &arr[i]);
	long long run1=0, run2=0;
	long long ans1=0, ans2=0;
	for (int i=0; i<n; i++) {
		run1+=arr[i];
		run2+=arr[i];
		if (run1<=0 && i%2==0) {
			ans1+=-run1+1;
			run1=1;
		}
		else if (run1>=0 && i%2==1) {
			ans1+=run1+1;
			run1=-1;
		}
		if (run2>=0 && i%2==0) {
			ans2+=run2+1;
			run2=-1;
		}
		else if (run2<=0 && i%2==1) {
			ans2+=-run2+1;
			run2=1;
		}
		//printf("%lld %lld %lld %lld\n",run1,run2,ans1,ans2);
	}
	printf("%lld\n", min(ans1,ans2));
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a, b;

int main() {
	cin >> n >> a >> b;
	
	cout << (abs(a - b) % 2 == 0 ? "Alice" : "Borys") << endl;
	
	return 0;
}


Measured memory_bytes: 256
// ayy
// ' lamo
// SUBLIME HAX
	#include <bits/stdc++.h>
	using namespace std;
	template<class T,class U>
	ostream &operator<<(ostream &os,const pair<T,U> &x) {
		return os<<"("<<x.first<<","<<x.second<<")";
	}
	namespace dbg_ns {
		template<typename C>
		struct is_iterable {
			template<class T> static long check(...);
			template<class T> static char check(int,
				typename T::const_iterator = C().end());
			enum {
				value = sizeof(check<C>(0)) == sizeof(char),
				neg_value = sizeof(check<C>(0)) != sizeof(char)
			};
		};
		template<class T> ostream &_out_str(ostream &os,const T &x) {
			return os<<'"'<<x<<'"';
		}
		template<class T> ostream &_dbg2_5(ostream &,const T &);
		template<bool B,typename T=void> using eit=typename enable_if<B,T>::type;
		template<class T>
		inline ostream &_dbg3(ostream &os,eit<is_iterable<T>::neg_value,const T> &x) {
			return os<<x;
		}
		template<class T>
		inline ostream &_dbg3(ostream &os,eit<is_iterable<T>::value,const T> &V) {
			os<<"{";
			bool ff=0;
			for(const auto &E:V) _dbg2_5(ff?os<<",":os,E), ff=1;
			return os<<"}";
		}
		template<>
		inline ostream &_dbg3<string>(ostream &os,const string &x) {
			return _out_str(os,x);
		}
		template<>
		inline ostream &_dbg3<const char *>(ostream &os,const char *const &x) {
			return _out_str(os,x);
		}
		template<class T> inline ostream &_dbg2_5(ostream &os,const T &x) {
			return _dbg3<T>(os,x);
		}
		template<class T,typename... Args> ostream &_dbg2(ostream &os,vector<string>::iterator nm,const T &x,Args&&... args);
		inline ostream &_dbg2(ostream &os,vector<string>::iterator) { return os; }
		template<typename... Args>
		inline ostream &_dbg2(ostream &os,vector<string>::iterator nm,const char *x,Args&&... args) {
			return _dbg2(_dbg3<const char *>(os<<"  ",x),nm+1,args...);
		}
		template<class T,typename... Args>
		inline ostream &_dbg2(ostream &os,vector<string>::iterator nm,const T &x,Args&&... args) {
			return _dbg2(_dbg3<T>(os<<"  "<<*nm<<"=",x),nm+1,args...);
		}
		vector<string> split(string s) {
			vector<string> Z;
			string z="";
			s+=',';
			int dep=0;
			for(char c:s) {
				if(c==',' && !dep) Z.push_back(z),z="";
				else z+=c;
				if(c=='(') ++dep;
				if(c==')') --dep;
			}
			return Z;
		}
		template<typename... Args> inline ostream &_dbg1(int ln,const string &nm,Args&&... args) {
			auto nms=split(nm);
			return _dbg2(cerr<<"L"<<ln<<":",nms.begin(),args...)<<endl;
		}
	}
	#define dbg(...) dbg_ns::_dbg1(__LINE__,#__VA_ARGS__,__VA_ARGS__)
	#define sz(x) (int(x.size()))
	#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	#define fi first
	#define se second
	#define pb push_back
// END SUBLIME HAX
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
const ld eps=(ld)1e-8;
const ld tau=2*(ld)acosl(-1);
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;











int32_t main() {
	int n,m; cin>>n>>m;
	int f=1<<m;
	int Z=100*(n-m)*f + 1900*m*f;
	cout<<Z<<endl;
}













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005;
int n,o,mxl,mnr,ans,ps[N],mxL[N],mnR[N];
struct st{int l,r;}q[N];
int main()
{
	scanf("%d",&n);int mx=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		ps[++o]=q[i].l,ps[++o]=q[i].r;
		mx=max(mx,q[i].r-q[i].l+1);
	}
	ans=mx;mxl=0;mnr=o+1;
	sort(ps+1,ps+o+1);o=unique(ps+1,ps+o+1)-ps-1;
	for(int i=1;i<=o;i++)mxL[i]=0,mnR[i]=o+1;
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(ps+1,ps+o+1,q[i].l)-ps;
		q[i].r=lower_bound(ps+1,ps+o+1,q[i].r)-ps;
		mxl=max(mxl,q[i].l);mnr=min(mnr,q[i].r);
		mxL[q[i].r]=max(mxL[q[i].r],q[i].l);
		mnR[q[i].l]=min(mnR[q[i].l],q[i].r);
	}
	if(mxl<=mnr)ans=mx+ps[mnr]-ps[mxl]+1;
	int tl=0,tr=o+1;
	for(int i=1;i<=o;i++)
	{
		if(tl)ans=max(ans,max(ps[i]-ps[mxl]+1,0)+max(ps[mnr]-ps[tl]+1,0));
		tl=max(tl,mxL[i]);
	}
	for(int i=o;i;i--)
	{
		if(tr<=o)ans=max(ans,max(ps[mnr]-ps[i]+1,0)+max(ps[tr]-ps[mxl]+1,0));
		tr=min(tr,mnR[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt(), K = in.nextInt();
            int[] arr = new int[N];
            for(int i = 0; i < N; i++) {
               arr[i] = in.nextInt();
            }

            int[][] dp = new int[K + 1][3];
            for(int[] row : dp)
                Arrays.fill(row, -1);

            boolean res = false;
            for(int i = 0; i < N; i++) {
                if(isWinPossible(arr, K - arr[i], 1, dp)) {
                    res = true;
                    break;
                }
            }

            out.println(res ? "First" : "Second");
        }

        public boolean isWinPossible(int[] arr, int K, int lastPlayer, int[][] dp) {
            if(K == 0)
                return true;

            int currPlayer;
            if(lastPlayer == 1) currPlayer = 2;
            else currPlayer = 1;

            if(dp[K][currPlayer] != -1) {
                return dp[K][currPlayer] != 1;
            }

            for(int i = 0; i < arr.length; i++) {
                if(K - arr[i] >= 0 && isWinPossible(arr, K - arr[i], currPlayer, dp)) {
                    dp[K][currPlayer] = 1;
                    return false;
                }
            }

            dp[K][currPlayer] = 0;
            return true;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 42968
N=gets.to_i
(1..3500).each do |h|
    (1..3500).each do |n| 
        x=h*n*N
        y=4*h*n-N*(h+n)
        if y>0 && x%y==0
            puts "%d %d %d" % [h, n, x/y]
            exit
        end
    end
end

Measured memory_bytes: 3836
#author: raghav_0901
from math import *

mod = (10**9) + 7


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    k = int(input())
    a, b = _in()
    fl = False
    for i in range(a, b + 1):
        if(i % k == 0):
            print("OK")
            fl = True
            break
    if(not fl):
        print("NG")


Measured memory_bytes: 9184
//Created Time:2019年12月22日 星期日 21时17分49秒
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define N 100005
     
    using namespace std;
     
    int n, l, t;
    int res[N], b[N], a[N];
     
    int main(){
    	scanf("%d%d%d", &n, &l, &t);
    	int cnt = 0; int r = t % l;
    	for(int i = 1; i <= n; ++i)
    		scanf("%d%d", &a[i], &b[i]), b[i] = b[i] == 1 ? 1 : -1;
    	int p = a[1];
    	for(int i = 1; i <= n; ++i){
    		int x = a[i];
    		a[i] = (a[i] + r * b[i] + l) % l;
    		if(b[i] == b[1]) continue;
    		(cnt += 2 * (t / l) % n) %= n;
    		int dis;
    		if(b[1] < 0) dis = l - x + p;
    		else dis = x - p;
    		if(dis <= r * 2){
    			(++cnt) %= n; dis += l;
    			if(dis <= r * 2) (++cnt) %= n;
    		}
    	}
    	int pos = a[1]; if(!cnt) cnt = n;
    	sort(a + 1, a + 1 + n);
    //	for(int i = 1; i <= n; ++i) cout << a[i] << endl;
    //	return 0;
    	for(int i = b[1] < 0 ? 1 : n; b[1] < 0 ? i <= n : i; b[1] < 0 ? ++i : --i)
    		if(a[i] == pos){
    			pos = i; break;
    		}
     
    //	cout << pos << endl;
    	int j = (1 + b[1] * cnt + n) % n;
    	if(!j) j = n;
    	res[j] = a[pos]; j = j % n + 1;
    	for(int i = pos % n + 1; i != pos; i = i % n + 1, j = j % n + 1)
    		res[j] = a[i];
    	for(int i = 1; i <= n; ++i)
    		printf("%d\n", res[i]);
    	return 0;
    }

Measured memory_bytes: 2432
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int a[200000];
int main(void){
	int n=nextint();
	int ans=0;
	for(int i=0; i<n; i++){
		a[i]=nextint();
		ans^=a[i];
	}
	for(int i=0; i<n; i++){
		printf("%d ", ans^a[i]);
	}
	putchar(10);
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int cnt=0;
  
  while(true){
    bool jud=false;
    for(int i=0;i<N;i++){
      if(A[i]%2!=0){
        jud=true;
      }
    }
    if(jud){
      break;
    }
    for(int i=0;i<N;i++){
      A[i]/=2;
    }
    cnt++;
  }
  cout << cnt ;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    int k; cin >> k;
    cout << (k / 2) * ((k + 1 )/ 2) << endl;

    return 0;
}


Measured memory_bytes: 3556
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);

    ll ans = 1;
    rep(i, N) {
        if (A.at(i) == 0) ans = 0;
    }

    if(ans != 0) {
        rep(i, N) {
            if (A.at(i) > (ll)pow(10,18) / ans) {
                ans = -1;
            } else {
                ans *= A.at(i);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4024