akhauriyash/Code-Regression huggingface dataset:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    m, n = map(int, input().split())
    horizontal, vertical = [], []
    X, Y = {-INF, 0, INF}, {-INF, 0, INF}

    for _ in range(m):
        x0, x1, y = map(int, input().split())
        horizontal.append((x0, x1, y))
        X.add(x0)
        X.add(x1)
        Y.add(y)
    for _ in range(n):
        x, y0, y1 = map(int, input().split())
        vertical.append((x, y0, y1))
        X.add(x)
        Y.add(y0)
        Y.add(y1)
    X = sorted(X)
    Y = sorted(Y)

    # compress
    m, n = len(X), len(Y)
    cX = {v : i for i, v in enumerate(X)}
    cY = {v : i for i, v in enumerate(Y)}

    # make grid
    grid_hor = [[True] * n for _ in range(m)]
    grid_ver = [[True] * n for _ in range(m)]
    for x0, x1, y in horizontal:
        y = cY[y]
        for x in range(cX[x0], cX[x1]):
            grid_hor[x][y] = False
    for x, y0, y1 in vertical:
        x = cX[x]
        for y in range(cY[y0], cY[y1]):
            grid_ver[x][y] = False

    # bfs
    ans = 0
    queue = deque([(cX[0], cY[0])])
    used = [[False] * n for _ in range(m)]
    used[cX[0]][cY[0]] = True
    while queue:
        x, y = queue.popleft()
        if x == 0 or y == 0 or x == m - 1 or y == n - 1:
            print("INF")
            return
        ans += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
        # up
        if y + 1 < n and grid_hor[x][y + 1] and not used[x][y + 1]:
            used[x][y + 1] = True
            queue.append((x, y + 1))
        # down
        if y - 1 >= 0 and grid_hor[x][y] and not used[x][y - 1]:
            used[x][y - 1] = True
            queue.append((x, y - 1))
        # right
        if x + 1 < m and grid_ver[x + 1][y] and not used[x + 1][y]:
            used[x + 1][y] = True
            queue.append((x + 1, y))
        # left
        if x - 1 >= 0 and grid_ver[x][y] and not used[x - 1][y]:
            used[x - 1][y] = True
            queue.append((x - 1, y))

    print(ans)
resolve()

Measured memory_bytes: 369800
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 998244353

using namespace std;
using ll = long long;

int main() {
	ll n, s, ans = 0;
	cin >> n >> s;
	vector<int> a(n + 1);
	rep(i,n) cin >> a[i];
	vector<int> dp(s + 1);
	dp[0] = 1; // ０個目までの部分集合で、和が0になるように選べる個数

	rep(i,n) {
		vector<int> bef(s + 1);
		swap(dp, bef);
		rep(k, s + 1) {
			dp[k] += ((bef[k] % MOD) * 2) % MOD;
			if (k + a[i] <= s) dp[k + a[i]] += bef[k] % MOD;
		}
	}
	ans = dp[s] % MOD;
	cout << ans << endl;
	return 0;
}


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


int main() {
    ll a, b;
    cin >> a >> b;
    ll gcd = __gcd(a, b);
    ll ans = 0;
    for(int i = 2; i <= sqrt(gcd); ++i){
        if(gcd%i==0){
            ans++;
            while(gcd%i==0) {
                gcd/=i;
            }
        }
    }
    ans++;
    if(gcd!=1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
using namespace std;
int H,N;
long long sum = 0;
int main(){
    cin>>H>>N;
    int A[N];
    for(int i =0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    if(sum>=H){cout<<"Yes";}
    if(sum<H){cout<<"No";}
}


Measured memory_bytes: 4012
N, M, X, Y = gets.split.map(&:to_i)
MAX_X = gets.split.map(&:to_i).max
MIN_Y = gets.split.map(&:to_i).min

if X < Y && (X + 1 .. Y).find{|z| MAX_X < z && z <= MIN_Y}
  puts "No War"
else
  puts "War"
end


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(void)
{
    int n, a, YJSNPI[10][100];
    char ch;
 
    cin >> n;
 
    for (int i = 0; i < n; i++)
    {
        cin >> ch >> a;
        if (ch == 'S')
            YJSNPI[0][a]=a;
        else if (ch == 'H')
            YJSNPI[1][a]=a;
        else if (ch == 'C')
            YJSNPI[2][a]=a;
        else if (ch == 'D')
            YJSNPI[3][a]=a;
    }
    for (int i = 1; i <= 13; i++)
    {
        if (YJSNPI[0][i] != i)
            cout << 'S' << " " << i << endl;
    }
    for (int i = 1; i <= 13; i++)
    {
 
        if (YJSNPI[1][i] != i)
            cout << 'H' << " " << i << endl;
    }
    for (int i = 1; i <= 13; i++)
    {
 
        if (YJSNPI[2][i] != i)
            cout << 'C' << " " << i << endl;
    }
    for (int i = 1; i <= 13; i++)
    {
        if (YJSNPI[3][i] != i)
            cout << 'D' << " " << i << endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size(); i++) {
    for(int j = i; j <= s.size(); j++) {
      int cnt = 0;
      for(int k = i; k < j; k++) {
        char c = s[k];
        if(c=='A'||c=='T'||c=='C'||c=='G') {
          cnt++;
        }
      }
      if(cnt == j-i) {
        ans = max(ans,cnt);
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  if(N/2+(N%2)>=K){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

  return 0;
}

    
  
  

Measured memory_bytes: 3580
N,M=map(int,input().split())
E=[]
for i in range(N):
  E.append(list(map(int,input().split())))
E.sort(key=lambda x:x[0])

ans=0
i=0
while M>0:
  A,B=E[i]
  ans+=A*min(B,M)
  M=max(M-B,0)
  i+=1
print(ans)

Measured memory_bytes: 29020
#include <stdio.h>

int main(void) {
    int a, b, k, i = 100, cnt = 0;

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

    while (cnt < k) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
        }
        i--;
    }

    printf("%d\n", i + 1);

    return 0;
} 


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

int main(){
	int N;
	cin >> N;
	int ans = 0;

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

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

int main()
{
    long long n;
    cin >> n;

    long long res[4][3][10];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                res[i][j][k] = 0;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        res[b - 1][f - 1][r - 1] += v;
    }

    for (long long i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << res[i][j][k];
            }
            cout << endl;
        }
        if (i < 3)
        {
            cout << "####################" << endl;
        }
    }
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
            cout<<c<<endl;
    }
    else if(a==c){
            cout<<b<<endl;
    }
    else{
            cout<<a<<endl;
    }
}


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

typedef long long ll;

using namespace std;

int main(){
  ll Q,H,S,D; cin >> Q >> H >> S >> D;
   long double N; cin >> N;
  
  ll sum = 0; 
  
  ll X = min(min(D,2*S),min(4*H,8*Q)); //2リットル以上
  ll Y = min(S,min(2*H,4*Q)); //1リットル以上2リットル未満
  ll Z = min(H,2*Q); //０.５リットル以上1リットル未満
  
  while( N >= 2.0){
     N -= 2.0; sum += X;}
  while( 1.0 <= N && N < 2.0){
    N -= 1; sum += Y;}
  while( 0.5 <= N && N < 1.0){
    N -= 0.5; sum += Z;}
  while( 0.0 < N && N < 0.5){
    N -= 0.25; sum += Q;}
  
  cout << sum << endl; return 0;}
    

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

int main(){
    string S;
    cin >> S;
    int A = 0, B = 0;
    for(int i = 0; i < S.length(); i++){
        if(i % 2 == 0){
            if(S[i] == '1'){
                A++;
            }else{
                B++;
            }
        }else{
            if(S[i] == '0'){
                A++;
            }else{
                B++;
            }
        }
    }
    cout << min(A, B) << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back

typedef long long LL;
typedef long double LD;

const LL INF = (1LL << 60);

typedef vector<LL> VLL;
LL knapsack_01(VLL& v, VLL& w, int n, LL W);

int main() {

  ios_base::sync_with_stdio(0); cin.tie(0);

  int n; LL W;
  cin >> n >> W;

  VLL v, w;
  v.assign(n + 1, 0);
  w.assign(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> v[i] >> w[i];
  }

  LL ans = knapsack_01(v, w, n, W);

  cout << ans << endl;

  return 0;
}

/**
 *
 * tested on http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
 */
LL dp[105][10005];
LL knapsack_01(VLL& v, VLL& w, int n, LL W) {
  LL sum = 0;
  for (int val : v)
    sum += val;

  LL ans = 0;
  for (int j = 1; j <= sum; j++)
    dp[0][j] = INF;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
      dp[i][j] = dp[i-1][j];
      if (v[i] <= j)
        dp[i][j] = min(dp[i][j],
                       dp[i-1][j-v[i]] + w[i]);
      if (ans < j && dp[i][j] <= W)
        ans = j;
    }
  }

  return ans;
}


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

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)



Measured memory_bytes: 54088
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)
 
const int MAXN = 1e3+5;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int check(int x, int n) {
    return (int)(x*1.08) == n;
}
int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    int x = n/1.08;
    if(check(x,n)) cout << x << endl;
    else if(check(x-1,n)) cout << x-1 << endl;
    else if(check(x+1,n)) cout << x+1 << endl;
    else cout << ":(\n";
    return 0;
}


Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    a,b,c,d = map(int, input().split())
    x = b//c - (a-1)//c
    y = b//d - (a-1)//d
    e = c*d//gcd(c,d)
    z = b//e - (a-1)//e
    ans = b-a+1 -x-y +z
    print(ans)

if __name__=="__main__":
    main()


Measured memory_bytes: 65380
#include<cstdio>
#include<algorithm>
using namespace std;
int a[110];
int main() {
	int n;
	scanf("%d", &n);
	int gap = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		gap += a[i];
	}
	sort(a + 1, a + n + 1);
	if (gap % 10)
	{
		printf("%d", gap);
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (a[i] % 10)
		{
			gap -= a[i];
			printf("%d", gap);
			return 0;
		}
	}
	puts("0");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>;
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

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

int main() {
  int n; cin >>n;
  map<int, int> mp;
  for(int i = 0; i < n; ++i){
    int a;cin >>a;
    ++mp[a];
  }
  if(n%2==0){
    int i=1;
    for(auto it : mp){
      if(it.first !=i ||  it.second!=2){
        cout << 0 << endl;
        return 0;
      }
      i+=2;
    }
  }
  else{
    int i =2;
    for(auto it : mp){
      if(it.first==0&& it.second==1){
        continue;
      }
      if(it.first!=i ||  it.second!=2){
        cout << 0 << endl;
        return 0;
      }
      i+=2;
    }
  }
  ll ans = modpow(2, n/2, MOD);
  cout << ans << endl;
}


Measured memory_bytes: 3200
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;
     
using namespace std;

int n, q, k, dp[404][404], a[maxn], pref[maxn];
bool was[404][404];

int get(int l, int r){
	return pref[r] - pref[l - 1];
}

int rec(int l, int r){
	if (was[l][r])
		return dp[l][r];
	if (r == l)
		return 0;
	if (r - l == 1)
		return dp[l][r] = get(l, r);
	was[l][r] = true;
	int sum = inf;
	for (int x = l; x < r; x++)
		sum = min(sum, rec(l, x) + rec(x + 1, r));
	dp[l][r] = sum + get(l, r);
	return dp[l][r];	
}

void solve(){
	cin >> n;

	for (int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] += pref[i - 1] + a[i];
	}
	
	cout << rec(1, n);
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
//#define pw (ll)pow 
#define MAX 1000005
#define MOD (ll)1e9+7
using namespace std;

int main()	
{
	int n;
	cin >> n;
	if(n%1000)	cout << 1000-n%1000 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3516
N, Y = map(int, input().split())

answer = [-1, -1, -1]

for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if k < 0:
            continue
        if i+j+k == N and i*10000 + j*5000 + k*1000 == Y:
            answer[0] = i
            answer[1] = j
            answer[2] = N-i-j

print("{} {} {}".format((answer[0]),(answer[1]),(answer[2])))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int modpow(ll x, ll y) {
	ll r = 1, a = x % MOD;
	while (y > 0) {
		if ((y & 1) == 1) r = (r*a) % MOD;
		a = (a*a) % MOD;
		y /= 2;
	}
	return r;
}

inline ll mod_inverse(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		swap(a -= t * b, b);
		swap(u -= t * v, v);
	}
	return (u % m + m) % m;
}

int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	string s;
	cin >> s;
	m = s.size();
	vector<ll> dp(n + 1);
	dp[0] = 1;
	REP(_, n) {
		vector<ll> nxt(n + 1);
		REP(i, n) dp[i] %= MOD;
		REP(i, n) nxt[max(0, i - 1)] += dp[i];
		REP(i, n) nxt[i + 1] += 2 * dp[i];
		swap(dp, nxt);
	}
	cout << dp[m] % MOD * mod_inverse(modpow(2, m), MOD) % MOD << endl;
	return 0;
}


Measured memory_bytes: 384
while True :
    y=int(input())
    if y==0 : break
    x=1000-y
    a=(x//500)
    b=(x%500//100)
    c=(((x%500)%100)//50)
    d=(((x%500)%100)%50//10)
    e=((((x%500)%100)%50)%10//5)
    f=(((((x%500)%100)%50)%10)%5)
    print(a+b+c+d+e+f)



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
ll h,w,ch,cw,dh,dw;
ll X[]={-1,1,0,0},Y[]={0,0,1,-1},xxx[]={-1,-1,1,1,-2,-2,-2,-2,-2,-1,-1,0,0,1,1,2,2,2,2,2},yyy[]={1,-1,-1,1,-2,-1,0,1,2,-2,2,-2,2,-2,2,-2,-1,0,1,2};
bool safe(ll x,ll y)
{
    if(x>-1 and y>-1 and x<h and y<w)return true;
    return false;
}
int main()
{
     io;
    int T=1;
    //T=gg();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
        ll i,j,k,l,cnt=0;
        cin>>h>>w>>ch>>cw>>dh>>dw;
        vector<string> v(h);
        for(auto &x:v)cin>>x;
        ch--,cw--,dh--,dw--;
        queue<pl> qq({{ch,cw}}),pp;v[ch][cw]='#';
        while(true){
            if(!qq.empty())
            {
                while(!qq.empty())
                {
                    pl u=qq.front();
                    if(u.ff==dh and u.ss==dw)
                    {
                        cout<<cnt;
                        return 0;
                    }
                    pp.push(u);
                    qq.pop();
                    for(i=0;i<4;i++)
                    {
                        ll x=u.ff+X[i],y=u.ss+Y[i];
                        if(safe(x,y) and v[x][y]=='.')
                        {
                            v[x][y]='#';
                            qq.push({x,y});
                        }

                    }
                }
            }
            else if(!pp.empty())
            {
                while(!pp.empty())
                {
                    pl u=pp.front();
                    pp.pop();
                    for(i=0;i<20;i++)
                    {
                        ll x=u.ff+xxx[i],y=u.ss+yyy[i];
                        if(safe(x,y) and v[x][y]=='.')
                        {
                            v[x][y]='#';
                            qq.push({x,y});
                        }
                    }

                }
                cnt++;
            }
            if(pp.empty() && qq.empty()){
                cout << -1;
                return 0;
            }
        }
    return 0;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			//long n = long.Parse(Console.ReadLine());
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long a = array[0];
			long b = array[1];
			long area = a * b;
			long length = (a + b) * 2;

			Console.WriteLine($"{area} {length}");
			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 16336
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
int main(){
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	printf("%d\n",((n-1)/x+1)*t);
	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int n;
int data[300000];
int go(int now,int want){
  if(now==0&&data[now]>=want)
    return 1;
  if(now==0&&data[now]<want)
    return 0;
  if(data[now]>=want)
    want=10;
  else
    want+=10;
  return go(now-1,want);
}
int come(int now,int want){
  if(now==n-1&&data[now]>=want)
    return 1;
  if(now==n-1&&data[now]<want)
    return 0;
  if(data[now]>=want)
    want=10;
  else
    want+=10;
  return come(now+1,want);
}
int main(void){
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    scanf("%d",&data[i]);
  int f=0;
  f+=go(n-2,10);
  f+=come(1,10);
  if(f==2)
    printf("yes\n");
  else
    printf("no\n");
  return 0;
}

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

int n, ans = 1;
double t, a, ansh = 9999999999;

int main() {
  cin >> n >> t >> a;
  for(int i = 0; i < n; ++i) {
    double x, now;
    cin >> x;
    now = t - x * 0.006;
    if(fabs(now - a) < fabs(ansh - a)) {
      ans = i + 1;
      ansh = now;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(void)
{
    int N, D;
    cin >> N >> D;

    using vi = vector<int>;
    vector<vi> X(N, vi(D));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < D; j++)
            cin >> X[i][j];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int sum = 0;
            for (int k = 0; k < D; k++) {
                int d = X[i][k] - X[j][k];
                sum += d * d;
            }

            int n = sqrt(sum);
            if (sum == n * n)
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10, mod = 1e9+7;

vector<int> g[N];
int dis[N];
int sol = 0;
int col[N];

void bfs(int a) {
    memset(dis, 63, sizeof(dis));
    memset(col, 0, sizeof(col));
    queue<int> q;

    dis[a] = 0;
    q.push(a);
    while (q.size()) {
        int curr = q.front();
        q.pop();

        int c = 1;
        for (int b : g[curr]) {
            if (dis[b] > dis[curr] + 1) {
                dis[b] = dis[curr] + 1;
                q.push(b);

                if (c == col[curr]) ++c;
                col[b] = c++;

                sol = max(sol, (int) g[curr].size());
            }
        }
    }
}

void solve() {
    int n; cin >> n;
    int id[n + 1];

    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;

        id[i] = b;

        g[a].push_back(b);
        g[b].push_back(a);
    }
    bfs(1);

    cout << sol << endl;
    for (int i = 1; i < n; ++i) {
        cout << col[id[i]] << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    // cin >> t;
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 13444
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

#define MAX_E 10000

class DisjointSet {
public:
  vector <int> rank, p;
  
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }

  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    }else {
      p[x] = y;
      if (rank[x] == rank[y]) {
	rank[y]++;
      }
    }
  }

  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

class edge {
public:
  int u, v, cost;
  edge(int u = 0, int v = 0, int cost = 0): u(u), v(v), cost(cost) {}
  bool operator < (const edge &e) const {
    return cost > e.cost;
  }
};

bool comp(const edge &e1, const edge &e2) {
  return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int solve() {
  sort(es, es+E, comp);
  int ret = -1;
  for (int i = 0; i < E; i++) {
    DisjointSet ds = DisjointSet(V);
    int minv = es[i].cost;
    ds.unite(es[i].u, es[i].v);
    int cost = 0;
    for (int j = i+1; j < E; j++) {
      edge e = es[j];
      if (!ds.same(e.u, e.v)) {
	ds.unite(e.u, e.v);
	cost = max(e.cost-minv, cost);
      }
    }
    bool ok = true;
    for (int j = 1; j < V; j++) {
      if (!ds.same(0, j)) {
	ok = false;
	break;
      }
    }
    if (ok) {
      if (ret == -1) {
	ret = cost;
      }else {
	ret = min(ret, cost);
      }
    }
  }

  return ret;
}

int main() {
  solve();
  while (true) {
    cin >> V >> E;
    if (V == 0 && E == 0) break;

    for (int i = 0; i < E; i++) {
      int a, b, w;
      cin >> a >> b >> w;
      a--; b--;
      es[i] = edge(a, b, w);
    }

    cout << solve() << endl;
  }
}

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

#define maxn 10007
const int INF=0x3f3f3f3f;


int main()
{
    int a,b,c;
    a=b=c=0;
    int n,i,j,k,x,y;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x%4==0) c++;
        else if(x%2==0) b++;
        else a++;
    }
    if(c>=a)
    {
        printf("Yes\n");
        return 0;
    }
    if(c==a-1&&b==0)
    {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	// your code goes here
	ll n,m,x;
	cin>>n>>m>>x;
	vector<ll> c(n);
	vector<vector<ll>> a(n,vector<ll>(m));
	for(int i=0;i<n;i++){
	    cin>>c[i];
	    for(int j=0;j<m;j++){
	        cin>>a[i][j];
	    }
	}
	ll mcost = 1e7;
	for(ll i=0; i< 1LL<<n; i++){
	    vector<ll> count(m,0);
	    ll cost = 0;
	    for(ll j = 0; j<n;j++){
	        if(i & (1LL<<j)){
	            cost += c[j];
	            //cout<<"hi ";
	            for(ll k = 0;k<m;k++){
	                count[k]+=a[j][k];
	            }
	        }
	    }
	    //cout<<endl;
	    bool flag = 0;
	    for(ll j = 0; j< m;j++){
	        if(count[j]<x){
	            flag = 1;
	        }
	    }
	    if(flag == 0){
	        mcost = min(mcost, cost);
	    }
	    
	}
	if(mcost < 1e7) cout<<mcost<<"\n";
	else cout<<"-1\n";
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
string s[100];
char c[100][1000];
int m,n;
int main(){
	scanf("%d%d",&m,&n);
	for(int i=0;i<m;i++){
		cin>>s[i];
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			c[i][j]=s[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(c[i][j]=='.'){
				ans=0;
				if(c[i+1][j+1]=='#')ans++;
				if(c[i][j+1]=='#')ans++;
				if(c[i+1][j]=='#')ans++;
				if(c[i-1][j]=='#')ans++;
				if(c[i][j-1]=='#')ans++;
				if(c[i+1][j-1]=='#')ans++;
				if(c[i-1][j+1]=='#')ans++;
				if(c[i-1][j-1]=='#')ans++;
				c[i][j]=ans+'0';
			}
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cout<<c[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import bisect
n,m,k = map(int,input().split())
a_list = [0]+list(map(int,input().split()))
b_list = list(map(int,input().split()))
b_added = [0]
for b_i in b_list:
    b_added.append(b_added[-1]+b_i)
    if b_added[-1]>k:
        break
    
max_book = 0
temp_ki = 0
break_flag = False
for i in range(len(a_list)):
    temp_ki += a_list[i]
    if temp_ki > k:
        if i-1>max_book:
            max_book = i-1
        break_flag = True
        break
    temp_j = bisect.bisect(b_added,k-temp_ki)-1
    if i+temp_j > max_book:
        max_book = i+temp_j
        
print(max_book)

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

using namespace std;

const int P = 998244353;

template <typename T>
void add(T &x, T y) {
	x = (x + y) % P;
}

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

	string s;
	cin >> s;

	int K;
	cin >> K;

	while(!s.empty() && s.back() == '0') {
		s.pop_back();
	}

	while(!s.empty() && *s.begin() == '1') {
		s.erase(s.begin());
	}

	s += '0';

	int n = s.size();
	int cnt = 0;

	vector<int> black;

	for(int i = 0; i < n; ++i) {
		if(s[i] == '1') {
			cnt += 1;
		}
		if(s[i] == '0') {
			black.emplace_back(cnt);
			cnt = 0;
		}
	}

	int m = black.size();
	
	reverse(black.begin(), black.end());

	vector<vector<vector<int> > > dp(n + 1, vector<vector<int> > (n + 1, vector<int> (n + 1, 0)));
	dp[0][0][0] = 1;

	int sum = 0;

	for(int i = 0; i < m; ++i) {
		for(int j = 0; j <= sum; ++j) {
			for(int k = 0; k <= sum; ++k) {
				for(int d = -j; d <= black[i]; ++d) {
					add(dp[i + 1][j + d][k + (d < 0 ? 0 : d)], dp[i][j][k]);
				}
			}
		}
		sum += black[i];
	}

	int ans = 0;
	for(int i = 0; i <= min(K, sum); ++i) {
		add(ans, dp[m][0][i]);
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 114044
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let cs: Vec<char> = s.chars().collect();
    let ans = cs[0] == 'A'
        && cs[2..(cs.len() - 1)].iter().filter(|&&c| c == 'C').count() == 1
        && (cs[1].is_lowercase()
            && cs[2..(cs.len() - 1)]
                .iter()
                .all(|&c| c == 'C' || c.is_lowercase())
            && cs[cs.len() - 1].is_lowercase());
    println!("{}", if ans { "AC" } else { "WA" });
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,t;
    cin >> a >> b >> t;
    cout << (b * (t / a)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  ll n = sz(s);
  ll ans = n;
  rep(i,n-1){
      if(s[i] != s[i+1]){
            ll v = max((ll)(i+1), n - i - 1LL);
            ans = min(ans, v);
        }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stdio.h>
#include <numeric>
#include <functional>
using namespace std;

vector<int> ana(string s) {
	vector<int> res('z' - 'a' + 1);
	for (char c : s) ++res[c - 'a'];
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int n, m;
	cin >> n>>m;
	vector<pair<int, int>> data(n);
	for (int i = 0; i < n; ++i)
		cin >> data[i].first >> data[i].second;
	sort(data.begin(), data.end());
	int l = 0;
	multiset<int, greater<int>> jobs;
	long long res = 0;
	for (int i = m; i >=0; --i) {
		while (l < n && data[l].first + i <= m) {
			jobs.insert(data[l].second);
			++l;
		}
		if (jobs.size()) {
			auto mx = *jobs.begin();
			jobs.erase(jobs.begin());
			res += mx;
		}
	}
	cout << res << endl;
	/*int n, m, k;
	cin >> n >> m >> k;
	vector <tuple<int, int, int>> edges(m);
	for (int i = 0; i < m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		if (x > y) swap(x, y);
		edges[i] = make_tuple(w, x, y);
	}
	sort(edges.begin(), edges.end());
	vector <tuple<int, int, int>> paths;
	int curmin = get<0>(edges[0]);
	int ind = 0;
	int cnt = 0;
	while (get<0>(edges[ind]) == curmin && cnt < k) {
		paths.push_back(edges[ind]);
		++ind;
		++cnt;
	}
	while (cnt < k) {
		curmin = get<0>(edges[ind]);
		bool added = false;
		for (int i = 0; i < paths.size(); ++i)
			for (int j = i + 1; j < paths.size(); ++j) {
				int xi = get<1>(paths[i]);
			}

	}*/
	/*int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	vector<int> powers(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
		++powers[a];
		++powers[b];
	}
	vector<pair<int, int>> sorted(n);
	for (int i = 0; i < n; ++i) {
		sorted[i].first = powers[i];
		sorted[i].second = i;
	}
	sort(sorted.begin(), sorted.end());
	if (m % 2) {
		cout << -1 << endl;
		return 0;
	}*/
	//cout << get<0>(paths[k - 1]);
	return 0;
}


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

using namespace std;


int W, H;

char ma[16][16];
char g[16][16];
bool v[16][16];

int maxIce[128];
int ice[128];

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

int ans;
int px, py;
int sx, sy, gx, gy;

bool getMin(int ty, int tx, int turn)
{

    if (turn + abs(ty - gy) + abs(tx - gx) >= ans){
        return (false);
    }

    if (ty == gy && tx == gx){
        ans = turn;
        return (true);
    }

    for (int i = 0; i < 4; i++){
        int mx = tx + dx[i], my = ty + dy[i];
        if (0 <= mx && mx < W && 0 <= my && my < H && px != mx && py != my && v[my][mx]){
            return (false);
        }
    }

    for (int i = 0; i < 4; i++){
        int mx = tx + dx[i], my = ty + dy[i];
        px = tx, py = ty;
        if (0 <= mx && mx < W && 0 <= my && my < H && ma[my][mx] != '#' && !v[my][mx]){
            if (g[my][mx] == -1){
                v[my][mx] = true;
                if (getMin(my, mx, turn + 1)) return (true);
                v[my][mx] = false;
            }
            else if (maxIce[g[my][mx]] >= ice[g[my][mx]] + 1){
                ice[g[my][mx]]++;
                v[my][mx] = true;
                if (getMin(my, mx, turn + 1)) return (true);
                v[my][mx] = false;
                ice[g[my][mx]]--;
            }
        }
    }

    return (false);
}

void label(int ty, int tx, int p)
{
    g[ty][tx] = p;
    maxIce[p]++;

    for (int i = 0; i < 4; i++){
        int mx = tx + dx[i], my = ty + dy[i];

        if (0 <= mx && mx < W && 0 <= my && my < H &&
                    ma[my][mx] == 'X' && g[my][mx] == -1){
            label(my, mx, p);
        }
    }
}

int main()
{
    int idx;

    while (1){
        scanf("%d %d", &W, &H);

        if (W + H == 0){
            break;
        }

        for (int i = 0; i < H; i++){
            scanf("%s", ma[i]);
            for (int j = 0; j < W; j++){
                if (ma[i][j] == 'S'){
                    ma[i][j] = '.';
                    sx = j, sy = i;
                }
                if (ma[i][j] == 'G'){
                    ma[i][j] = '.';
                    gx = j, gy = i;
                }
            }
        }

        memset(g, -1, sizeof(g));
        memset(maxIce, 0, sizeof(maxIce));

        idx = 0;
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                if (ma[i][j] == 'X' && g[i][j] == -1){
                    label(i, j, idx);
                    maxIce[idx++] /= 2;
                }
            }
        }

        memset(ice, 0, sizeof(ice));
        memset(v, 0, sizeof(v));
        px = py = -1;
        v[sy][sx] = true;

        ans = 0;
        while (!getMin(sy, sx, 0)){
            memset(ice, 0, sizeof(ice));
            memset(v, 0, sizeof(v));
            px = py = -1;
            v[sy][sx] = true;
            ans++;
        }

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

    return (0);
}

Measured memory_bytes: 3152
N,M=map(int,input().split())
H=list(map(int,input().split()))
H2=[True]*N
for i in range(M):
    A,B=map(int,input().split())
    if H[A-1]<=H[B-1]:
        H2[A-1]=False
    if H[B-1]<=H[A-1]:
        H2[B-1]=False
        
print(H2.count(True))

Measured memory_bytes: 20152
module Main where

import           Control.Monad

main :: IO ()
main = do
    [h, _] <- (map read . words) <$> getLine
    list   <- map (map read . words) <$> (replicateM h) getLine
    let res1 = (map goRight . enumerate2d) list
    let
        result = concat
            [(concatMap fst) res1, (fst . goRight . map (last . snd)) res1]

    putStr
        $(unlines .((show . length) result :) . map ((unwords . map show) . (\((a, b), (c, d)) -> [a, b, c, d])))
        result

goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight []  = ([], [])
goRight [x] = ([], [x])
goRight (a@(aPoint, aValue) : b@(bPoint, _) : xs) = if even aValue
    then mapSnd (a :) (goRight (b : xs))
    else
        let (resMove, resMap) = goRight (mapSnd (+ 1) b : xs)
        in  ((aPoint, bPoint) : resMove, mapSnd (subtract 1) a : resMap)

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)

mapTuple :: (t1 -> a) -> (t2 -> b) -> (t1, t2) -> (a, b)
mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst :: (t1 -> a) -> (t1, b) -> (a, b)
mapFst = flip mapTuple id

mapSnd :: (t2 -> b) -> (a, t2) -> (a, b)
mapSnd = mapTuple id


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

int main() {
  int N, numberOfSeats = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l;
    int r;
    cin >> l >> r;
    numberOfSeats += r - l + 1;
  }
  cout << numberOfSeats << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mina = min(a)
maxa = max(a)
w = maxa - mina + 3
abucket = [0] * w
for i in range(n):
  abucket[a[i] - mina] += 1
  abucket[a[i] - 1 - mina] += 1
  abucket[a[i] + 1 - mina] += 1
print(max(abucket))

Measured memory_bytes: 14008
#include<bits/stdc++.h>
#define REP(n)    for(int i = 0; i < (n); ++i)
#define RREP(n)   for(int i = (n); i >= 0; --i)
#define FOR(m, n) for(int i = (m); i < (n); ++i)
#define SZ(x)       ( (int)(x).size() )
#define BIT(n)      ( 1LL << (n) )
#define EXIST(x)    ( (x).find()		!= (x).end() )
#define DEBUG(n)    cerr << #n << " : " << n << '\n';
#define PB  push_back
#define MP  make_pair
#define UB  upper_bound			//k <
#define LB  lower_bound			//k	<= 
#define F   first
#define S   second
#define INF 1.0e9


using namespace std;

typedef long long			ll;
typedef pair<int, int>		pii;
typedef pair<long long, long long>   pll;
typedef vector<int>			vi;
typedef vector<double>		vd;
typedef vector<long long>   vll
;

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

int r_up(const int a, const int b){ return (a + b - 1) / b; }

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

struct UFT{
  vi	p;
  UFT(){}
  UFT(int N)       { p.resize( N, -1 ); }
  int	par(int a)   { if( p[a] >= 0 ){ p[a]  = par( p[a] ); return p[a]; } return a;  }
  int size(int a)  { return -p[par(a)]; }
  bool	same(int a, int b) { return par(a)	 == par(b); }
  void unite(int	a, int b){
	a													  = par(a);  b = par(b);
	if( a == b ) return;
	if( size(a) < size(b) ) swap(a,b);
	p[a]												 -= size(b);
	p[b]												  = a;
  }
};

int n,k;


int main(){
  cin>>n>>k;
  vector<pll> vp;
  REP(n){
	ll x,y;cin>>x>>y;
	vp.PB(MP(y,x));
  }
  sort(vp.rbegin(),vp.rend());

  vll ans(n+1,0);
  vi typ(n+1,0);
  int cnt=0;
  
  ll tmp=0;

  REP(k){
	tmp+=vp[i].F;
	if(typ[vp[i].S]==0)cnt++;
	typ[vp[i].S]++;
  }
  ans[cnt]=tmp+(ll)cnt*cnt;

  
  while(1){
	int org=-1,tar=-1;
	FOR(k,n)
	  if(typ[vp[i].S]==0){tar=i;break;}
	RREP(k-1)
	  if(typ[vp[i].S]>1){org=i;break;}

	if(org>-1&&tar>-1){
	  typ[vp[org].S]--; typ[vp[tar].S]++;
	  tmp-=vp[org].F;
	  tmp+=vp[tar].F;
	  swap(vp[org],vp[tar]);
	  vp.erase(vp.begin()+k,vp.begin()+tar);
	  cnt++;
	  ans[cnt]=tmp+(ll)cnt*cnt;
	}
	else break;
  }

  sort(ans.rbegin(),ans.rend());
  cout<<ans[0]<<endl;

  
  return 0;
}


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

int main(){
    int n,t;
    cin>>n>>t;
    int a[n];
    long long ans=0;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]-a[i-1]>t){
            ans+=t;
        }else{
            ans+=a[i]-a[i-1];
        }
    }
    ans+=t;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4348
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define TURN(a) (a==1?0:1)
#define SENTINEL 1000000007
typedef long long ll;

int main()
{
    int h, w, i, j;
    char s[100][100];
    int maskh[100]={0}, maskw[100]={0};
    scanf("%d %d",&h, &w);
    for(i=0; i<h; i++) {
        scanf("%s",&s[i]);
    }
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(s[i][j]=='#') {
                maskh[i] = 1;
                maskw[j] = 1;
            }
        }
    }

    for(i=0; i<h; i++) {
        if(maskh[i]==1) {
            for(j=0; j<w; j++) {
                if(maskw[j]==1)
                    printf("%c",s[i][j]);
            }
            puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  string s;
    cin >> s;
  int cnt=0;
    for(int i=0; i<4; i++)
      if(s[i]=='+') cnt++;
    cout << cnt-(4-cnt) << endl;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._
  val Array(a,b,h,m) = readLine().split(" ").map(_.toDouble)
  val rM = m/60 * 2 * Math.PI
  val rH = (h/12 + m/60 * 1/12) * 2 * Math.PI
  var ans = a * a + b * b - 2 * a * b * Math.cos(Math.abs(rH - rM))
  println(Math.sqrt(ans))
}

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

int main() {
  int n, sum;
  cin >> n;
  sum = 0;
  
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    sum += (b - a) + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    MOD = 10**9+7
    S = list(map(int, input().split()))

    if n % 2 == 0:
        sn = (1 + (n-1)) * (n // 2)
    else:
        sn = (2 + (n-1)) * (n//2)

    ss = sum(S)

    print((2**(n//2))%MOD if ss == sn else 0)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 13880
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0];
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a[]={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};
    int k;
    scanf("%d",&k);
    printf("%d",a[k-1]);
}

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

int main(){
   
    string S;cin>>S;
    if(S[0]==S[1]) cout<<1<<" "<<2<<endl;
    else{
        bool check=false;
        for(int i=2;i<S.size();i++){
            if(S[i]==S[i-2]){
                cout<<i-1<<" "<<i+1<<endl;
                check=true;
                break;
            }else if(S[i]==S[i-1]){
                cout<<i<<" "<<i+1<<endl;
                check=true;
                break;
            }
        }
        if(!check) cout<<-1<<" "<<-1<<endl;
    }
}


Measured memory_bytes: 512
n, q = map(int, input().split(' '))
s = input()
c = [0] * n
for i in range(1, n):
    c[i] += c[i-1]
    if s[i-1:i+1] == 'AC':
        c[i] += 1
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(c[r-1] - c[l-1])


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

int main(){
    int n,i;
    long long int ans=0,counter=0;
    std::cin >> n;
    long long int a[n];
    for (i=0;i<n;i++){
        std::cin >>a[i];
        if (a[i]<0){
            counter++;
            a[i]= -a[i];
        }
    }
    if (counter%2==0){
        for (i=0;i<n;i++)
        ans+=a[i];
    }
    if(counter%2==1){
        sort(a, a+n);
        for (i=1;i<n;i++){
            ans+=a[i];
        }
        ans-=a[0];
    }
    std::cout <<ans << std::endl;
}

Measured memory_bytes: 1024