akhauriyash/Code-Regression huggingface dataset:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    x = int(input())
    if x < 30:
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
	main()


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

using ll = long long;

int main() {
    int N, H1, H2, ans = 0, x = 0;
    cin >> N >> H1;
    rep(i, N - 1) {
        cin >> H2;
        if (H2 <= H1) {
            x++;
            ans = max(ans, x);
        } else {
            x = 0;
        }
        H1 = H2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (((x - r) >= 0) && ((y - r) >= 0) && ((x + r) <= W) && ((y + r) <= H))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int main()
{
	//fastIO;
	double r; cin >> r;
	printf("%.3f",2.0 * pi * r);
	return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
vector<vi> res;int n,m,q;
int cnt  =0;

int main(){
    ll x;cin>>x;
    int y=ceil((double)pow(x,1.0/3.0));
    rep(i,y+1){
        rep2(j,-y,y+1){
            //cout<<i<<j<<endl;
            if(pow(i,5)-pow(j,5)==x){
                cout<<i<<' '<<j<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  char a;
  cin >>a;
  
  a+=1;
  
  cout << a << endl; 
  
}


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

using namespace std;

int gcd(int a, int b){
  if (a < b){
    return gcd(b, a);
  }
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

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

  vector<int> a(n, 0);

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

  vector<int> l(n, 0), r(n, 0);

  l[0] = a[0];
  for (int i = 1; i < n; i++){
    l[i] = gcd(l[i-1], a[i]);
  }
  r[n-1] = a[n-1];
  for (int i = n-2; i > 0; i--){
    r[i] = gcd(r[i+1], a[i]);
  }

  int m = 0;
  for (int i = 0; i < n; i++){
    if (i == 0){
      m = r[1];
    }
    else if (i == n - 1){
      m = max(m, l[n-2]);
    }
    else 
      m = max(m, gcd(l[i-1], r[i+1]));
  }


  cout << m << endl;




}


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

 int main(){
     int a,b,c,d;
     cin >> a >> b >> c >> d;
     int n;
     if(c%b == 0){
         n = c/b;
     }else{
         n = c/b +1;
     }
     if(d * (n-1) < a){
         cout << "Yes" << endl;
     }else{
         cout << "No" << endl;
     }
 }


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

int main(){
  int a,b;
  cin >> a >> b;
  for(int i = 0 ; b+2 > i ; i++){
  cout << "#";
  }
  cout << endl;
  vector<char>out(b);
  for(int s = 0 ; a > s ; s++){
    cout << "#";
    for(int z = 0 ; b > z ; z++ ){
      cin >> out.at(z);
      cout << out.at(z); 
  }
    cout << "#" << endl;
 }
  for(int i = 0 ; b+2 > i ; i++){
  cout << "#";
  }
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

N = int(input().strip())
vs = list(map(int, input().strip().split(' ')))

vs.sort(reverse=True)
value = 0
for i in range(1, N+1):
    div = 2 ** i
    if i == N:
        div = 2 ** (N - 1)
    value += vs[i-1] / div
print(value)

Measured memory_bytes: 3060
N, K, Q = map(int, input().split())
A = []
for i in range(Q):
    a = int(input())
    A.append(a)

l = list()
for i in range(N):
    l.append(K-Q)

for a in A:
    l[a-1] += 1

for j in l:
    if j > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 56408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define rad2deg(a) ((a)/M_PI * 180.0)
#define deg2rad(a) ((a)/180.0 * M_PI)
const std::string yes = "Yes";
const std::string no  = "No";

bool isSame(std::string s){
    for(int i=1; i<s.size(); i++){
        if(s[i]!=s[0]) return 1;
    }
    return 0;
}

int main(){
    std::string s;
    std::cin >> s;
    std::set<char> st;
    rep(i,s.size()) st.insert(s[i]);

    int ans = 1145141919;
    for(auto itr=st.begin(); itr!=st.end(); itr++){
        char a = *itr;
        std::string t = s;
        while(isSame(t)){
            std::string nt;
            rep(i,t.size()-1){
                if(t[i]==a || t[i+1]==a){nt+=a;}
                else{nt+=t[i];}
            }
            t = nt;
        }
        ans = std::min<int>(s.size()-t.size(),ans);
    }

    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
constexpr int MOD = 1e9+7;
constexpr int MAX = 1e5+5;

long h, w, n, r, c, dp[MAX][2], fac[MAX*2], inv[MAX*2], finv[MAX*2];
vector<long> wall[MAX];

long Comb(int n,int k){
  if(n < 0 || k < 0 || n < k) return 0;
  return (fac[n] * finv[n-k] % MOD) * finv[k] % MOD;
}

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> h >> w >> n;
  for(int i = 0; i < n; ++i) {
    cin >> r >> c;
    wall[i] = {r, c};
  }
  wall[n] = {1, 1};
  wall[n+1] = {h, w};
  
  fac[0] = inv[0] = finv[0] = 1;
  fac[1] = inv[1] = finv[1] = 1;
  for(int i=2; i < MAX*2; ++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;
  }

  sort(wall, wall+n+2);

  dp[0][0] = 1;
  for(int i = 0; i < n+2; ++i) {
    for(int j = 0; j < i; ++j) {
      long way = Comb(wall[i][0]-wall[j][0]+wall[i][1]-wall[j][1], wall[i][0]-wall[j][0]);
      (dp[i][0] += dp[j][1] * way) %= MOD;
      (dp[i][1] += dp[j][0] * way) %= MOD;
    }
  }
  cout << (dp[n+1][1] - dp[n+1][0] + MOD) % MOD;
  return 0;
}

Measured memory_bytes: 8576
#include <stdio.h> 
 #include <ctype.h> 
 
 
 int main(){ 
     int count[26]={0}; 
     char ch; 
     int i, num; 
 
 
     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             num=ch-'a'; 
         }else if(isupper(ch)){ 
             num=ch-'A'; 
         }else{ 
             continue; 
         } 
         count[num]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(m, vector<int>());
    for (int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int s;
            cin >> s;
            vec[i].push_back(s);
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    { //何個めのスイッチがONか。
        bool flag = true;
        for (int i = 0; i < m; i++)
        {
            int tmp = 0;
            for (auto v : vec[i])
            {
                if (bit & (1 << v - 1))
                {
                    tmp++;
                }
            }
            if (tmp % 2 != p[i])
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	int s = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == '#') s++;
		}
	}
	if (h + w - 1 == s) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;

  S[K - 1] += 32;
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//nまでの素数
vector<int> eratosthenes(int n){
  vector<int> v(1,2);
  for(int i = 3; i<=n; i+=2) v.push_back(i);
  for(int i = 1; v[i]<=sqrt(n); i++){
    for(int j = i+1; j<v.size(); j++){
      if(v[j]%v[i]==0){
        v.erase(v.begin()+j);
        j--;
      }
    }
  }
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int X;cin >> X;
  vector<int> prime = eratosthenes(2*X);
  for(const int & p : prime){
    if(p >=X ){
      cout << p << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int a,b;
    cin >> a >> b;
    if(a<=5){
        cout<<0;
    }else if(a<=12){
        cout<<b/2;
    }else{
        cout<<b;
    }
    cout<<endl;
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<string.h>
#include<limits.h>
#include <random>
#define int long long
using namespace std;

signed main(){
	random_device rnd;
	int a = rnd();
	if (a & 1)puts("H");
	else puts("D");
}

Measured memory_bytes: 256
s = gets.chomp.bytes.sort
t = gets.chomp.bytes.sort.reverse
ans = 'No'
[s.size, t.size].max.times do |i|
  if s[i].nil?
    ans = 'Yes'
    break
  elsif t[i].nil?
    break
  elsif s[i] < t[i]
    ans = 'Yes'
    break
  elsif s[i] > t[i]
    break
  end
end
puts ans

Measured memory_bytes: 1788
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

#define ll long long
typedef int vt; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs(a - c) <= d) || ((abs(a - b) <= d) && (abs(b - c) <= d))) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from collections import Counter

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
S = [input() for _ in range(N)]

c = Counter(S)
for label in ['AC', 'WA', 'TLE', 'RE']:
    print(label, 'x', c[label])

Measured memory_bytes: 83632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct UnionFind {
    // 親の番号を入れる配列。根のときはpar[i] = i
    vector<int> par;

    // 初めは空グラフとして初期化
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++) par[i] = i;
    }

    // その点を含む成分の根を取り出す
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // xとyを同じ成分に入れる
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    // xとyが同じ成分に入っているか判定
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    for (ll i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    vector<llll> a(N), b(N);
    for (ll i = 0; i < N; i++) {
        a[i].first = x[i];
        b[i].first = y[i];
        a[i].second = i;
        b[i].second = i;
    }
    sort(ALL(a));
    sort(ALL(b));

    // cost, from, to
    vector<pair<ll, llll>> G;

    for (ll i = 0; i < N-1; i++) {
        G.push_back(make_pair(a[i+1].first - a[i].first, make_pair(a[i].second , a[i+1].second)));
        G.push_back(make_pair(b[i+1].first - b[i].first, make_pair(b[i].second , b[i+1].second)));
    }

    sort(ALL(G));

    ll ans = 0;
    ll cnt = 0;
    UnionFind tree(N);
    for (ll i = 0; i < 2*N-2; i++) {
        if(!tree.same(G[i].second.first, G[i].second.second)){
            tree.unite(G[i].second.first, G[i].second.second);
            cnt++;
            ans += G[i].first;
        }
        if(cnt == N-1){
            break;
        }
    }

    printf("%lld\n", ans);

}

Measured memory_bytes: 14296
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    a_sum = [0]
    b_sum = [0]
    for i in range(len(a)):
        a_sum.append(a_sum[i]+a[i])
    for i in range(len(b)):
        b_sum.append((b_sum[i]+b[i]))

    ans = 0
    j = m
    for i in range(n+1):
        if a_sum[i] > k:
            break
        while b_sum[j] > k - a_sum[i]:
            j -= 1
        ans = max(ans, (i+j))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 137680
N = int(input())
L = []
D = {}
for _ in range(N):
    x = input()
    L.append(x)

for x in L:
    D[x] = 0
    
for x in L:
    D[x] += 1

SortD = sorted(D.items(), key=lambda x:x[1])
maxD = SortD[-1][1]
ans = []
for x in reversed(SortD):
    if x[1] == maxD:
        ans.append(x[0])
    else:
        break
for x in sorted(ans):
    print(x)


Measured memory_bytes: 48912
#region Using directives
using System;
using static System.Console;
using static System.Convert;
using System.Collections.Generic;
#endregion

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = ToInt32(ReadLine());
            int a = ToInt32(ReadLine());
            WriteLine(n * n - a);
            ReadKey();
        }
    }
}



Measured memory_bytes: 11220
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#define ll long long
#define pb push_back
using namespace std;


int main()
{
	ll int n,m,s=0;
	cin>>n>>m;
	ll int a[n],i;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	if (s>n)
	{
		cout<<-1<<endl;
		
	}
	else
	{
		cout<<n-s<<endl;
	}
	
}



	
  
  

		
		
		
		
		
		
	
	
	 
		
		
	
	
	

	


	
	
	
   



Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> ts(n),as(n);
    rep(i,n) cin>>ts.at(i)>>as.at(i);
    
    ll t=1, a=1;
    rep(i,n){
        ll x=(t+ts.at(i)-1)/ts.at(i);
        ll y=(a+as.at(i)-1)/as.at(i);
        t=max(x,y)*ts.at(i);
        a=max(x,y)*as.at(i);
    }
    
    cout<<t+a<<endl;
}



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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

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

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi c(n + 1);
    c[0] = 3;
    mint ans = 1;
    rep(i, n) {
        if (!c[a[i]]) {
            cout << 0 << endl;
            return 0;
        }
        ans *= c[a[i]];
        c[a[i]]--;
        c[a[i] + 1]++;
    }
    cout << ans.x << endl;
}

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

int main()
{
    int flag = 0;
    int N;
    string S;

    cin >> N;

    for (int i = 0 ; i < N ; i++)
    {
        cin >> S ;
        if(S == "Y")
        flag = 1;
    }

    if(flag == 1)
    cout << "Four" << endl;
    else
    cout << "Three" << endl;

    return 0 ;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
using namespace std;
vector<int> Data;

int main(void)
{
	long n,k;
	cin >> n >> k;

	n=n % k;

	if (n == 0)
	{
		cout << n << endl;
		return 0;
	}

	if (n>=(k/2))
	{
		n = k - n;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll d; cin >> n >> d;
  vector<vector<ll>> X(2, vector<ll>(n));
  rep(i, n) cin >> X[0][i] >> X[1][i];
  two_sat ts(n);
  rep(i, n) REP(j, i+1, n) {
    rep(k, 2) rep(l, 2) {
      if(abs(X[k][i]-X[l][j])<d) {
        ts.add_clause(i, !k, j, !l);
      }
    }
  }
  if(!ts.satisfiable()) {
    cout << "No" << endk;
  } else {
    cout << "Yes" << endk;
    auto ans = ts.answer();
    rep(i, n) cout << X[ans[i]][i] << endk;
  }
  return 0;
}


Measured memory_bytes: 3792
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
    `(let ((it ,expr))
       ,then
       ,else))

(let ((a (read))
      (b (read))
      (c (read))
      (ans 0))
  (do ((i 0 (+ i 1)))
      ((some #'oddp (list a b c)) nil)
    (incf ans)
    (let ((na (/ (+ b c) 2))
          (nb (/ (+ a c) 2))
          (nc (/ (+ a b) 2)))
      (when (equal (list a b c) (list na nb nc))
        (format t "-1~%")
        (exit))
      (setf a na)
      (setf b nb)
      (setf c nc)))
  (format t "~a~%" ans))


Measured memory_bytes: 16868
#include <iostream>
using namespace std;
int main() {
  string b;
  cin >> b;
  if (b=="A") cout << "T" << endl;
  if (b=="T") cout << "A" << endl;
  if (b=="C") cout << "G" << endl;
  if (b=="G") cout << "C" << endl;
}

Measured memory_bytes: 256
import numpy as np

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

dp = np.zeros(W + 1, dtype = np.int64)

for i in range(N):
	w, v = map(int, input().split())
	np.maximum(dp[w:], dp[:-w] + v, out = dp[w:])

print(dp.max())

Measured memory_bytes: 28944
#include <stdio.h>

int main(void) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    
    while(1) {
        c -= b;
        if(c <= 0) {
            printf("Yes\n");
            return 0;
        }
        
        a -= d;
        if(a <= 0) {
            printf("No\n");
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct{
  int t_id;
  int score;
  int penalty;
  int miss[10];
}teams;

int comp(const void *p1,const void *p2){
  teams a,b;
  a=*(teams *)p1;
  b=*(teams *)p2;
  if(a.score>b.score) return -1;
  else if(a.score<b.score) return 1;

  if(a.penalty<b.penalty) return -1;
  else if(a.penalty>b.penalty) return 1;
  else return a.t_id-b.t_id;
}

int main(void){
  teams team[50];
  int i,j,k;
  char status[16];
  int T,P,R,time;
  int in_t,in_p;
  
  while(scanf("%d %d %d%*c",&T,&P,&R) && T && P && R){
    /*format structs*/
    for(i=0;i<T;i++){
      team[i].t_id=i+1;
      team[i].score=team[i].penalty=0;
      for(j=0;j<P;j++) team[i].miss[j]=0;
    }

    for(i=0;i<R;i++){
      scanf("%d%d%d%*c%15s%*c",&in_t,&in_p,&time,status);
      if(strcmp(status,"CORRECT")==0){
	team[in_t-1].score++;
	team[in_t-1].penalty+=time+1200*team[in_t-1].miss[in_p-1];
      }else team[in_t-1].miss[in_p-1]++;
    }

    qsort(team,T,sizeof(teams),comp);

    for(i=0;i<T;i++)
      printf("%d %d %d\n",team[i].t_id,team[i].score,team[i].penalty);
  }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cctype>
#include <iomanip>
#include <limits>
#include <bitset>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef unsigned long long int ull;
const ll mod = 1000000007;
const ll linf = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = (m); i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<>()
#define SUM(a) accumulate((a).begin(), (a).end(), 0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
template <typename T>
int len(T tmp)
{
	int res = 0;
	while (tmp > 0)
	{
		res++;
		tmp /= 10;
	}
	return res;
}
template <typename T>
T gcd(T a, T b)
{
	T t;
	while (b != 0)
	{
		t = a % b;
		a = b;
		b = t;
	}
	return a;
}
template <typename T>
T recfact(T start, T n)
{
	T i;
	if (n <= 16)
	{
		T r = start;
		for (i = start + 1; i < start + n; i++)
			r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
template <typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
template <typename T>
T fct(T n)
{
	return recfact<T>(1, n);
}
template <typename T>
T ncm(T n, T m)
{
	if (n < m)
		return 0;
	T x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr)
{
	if (firstItr < 0 || secondItr > int(str.size() - 1))
		return str;
	while (firstItr < secondItr)
	{
		swap(str[firstItr], str[secondItr]);
		firstItr++;
		secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str)
{
	int itr = 0;
	std::string res;
	while (itr < int(str.size()))
	{
		char tmp = str[itr++];
		int length = 1;
		while (itr < int(str.size()) && str[itr] == tmp)
		{
			++itr;
			++length;
		}
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
str split(str str, size_t first_itr, size_t second_itr)
{
	string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++)
	{
		tmp.push_back(str.at(i));
	}
	return tmp;
}

int main(void)
{
	int n, k;
	cin >> n >> k;
	vector<char> v(n);
	rep(i,n){
		cin >> v[i];
	}
	rep(i,n){
		printf("%c", (i==k-1?v[i]+32:v[i]));
	}
	return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
ans = len(T)

for i in range(len(S)-len(T)+1):
  Si = S[i:i+len(T)]
  count = 0
  for j in range(len(T)):
    if Si[j] != T[j]:
      count += 1
  if ans > count:
    ans = count

print(ans)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
using ll        = long long;
using ld        = long double;
using vl        = vector<ll>;
using vd        = vector<ld>;
using vs        = vector<string>;
using vb        = vector<bool>;
using vvl       = vector<vector<ll>>;
using vvd       = vector<vector<ld>>;
using vvs       = vector<vector<string>>;
using vvb       = vector<vector<bool>>;
using pll       = pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

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

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    string S;
    cin >> S;
    cout << S << (S[S.size()-1] == 's' ? "es" : "s") << "\n";
}

Measured memory_bytes: 3676
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	A, B := sc.NextInt(), sc.NextInt()

	if A >= 13 {
		fmt.Println(B)
	} else if A >= 6 {
		fmt.Println(B / 2)
	} else {
		fmt.Println(0)
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>		//万能头文件 
using namespace std;

int main()
{
	string a;
	int pos=0;		//记录位置 
	cin>>a;
	a=a+"D";		//为防止最后一个字母是"A",添加一个不是"C"的字母 
	while(1)
	{
		pos=a.find("A",pos);		//find()函数查找位置 
		if(pos<0)		//如果没找到，返回-1 
		{
			cout<<"No"<<endl;		//endl养成好习惯 
			break;		//跳出循环 
		}
		if(a[pos+1]=='C')		//判断"A"下一个是不是"C"
		{
			cout<<"Yes"<<endl;
			break;		//跳出循环
		}
		pos++;		//下一次从pos+1找起 
	}
	return 0;
}

Measured memory_bytes: 764
# https://atcoder.jp/contests/abc136/tasks/abc136_c

n = int(input())
nums = [int(i) for i in input().split()]

for i in range(1, n):
    if nums[i] == nums[i - 1] - 1:
        nums[i] += 1
    if nums[i] < nums[i - 1]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 63984
// Aizu Vol-1 0140: Bus Line
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;
int f;

int getInt(void)
{
	while (isspace(*p)) p++;
	return *p++ - '0';
}

void myPuts(int s, int e)
{
	if (s < e) {
		while (s <= e) {
			if (f) f = 0;
			else putchar(' ');
			putchar(s++ + '0');
		}
	}
	else {
		while (s >= e) {
			if (f) f = 0;
			else putchar(' ');
			putchar(s-- + '0');
		}
	}
}

int main()
{
	int i, n, s, e;

	gets(buf), n = atoi(buf);
	for (i = 0; i < n; i++) {
		gets(p = buf);
		s = getInt(), e = getInt(), f = 1;
		if (s <= 5) myPuts(s, e);
		else {
			if (e > s) myPuts(s, e);
			else {
				myPuts(s, 9);
				if (e == 5) putchar(' '), putchar('5');
				else if (e < 5) myPuts(5, e);
				else myPuts(5, 0), myPuts(1, e);
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 524
# AOJ 0196 Baseball Championship
# Python3 2018.6.21 bal4u

while 1:
	n = int(input())
	if n == 0: break
	team = []
	for i in range(n):
		r = list(input())
		t = r.pop(0)
		w = l = 0
		for p in r:
			if p.isdigit() == False: pass
			elif int(p) == 0: w += 1      # 勝ち数
			elif int(p) == 1: l += 1      # 負け数
		team.append((t, i, w, l))
	for i in sorted(team, key=lambda x:(-x[2],x[3],x[1])): print(*i[0])



Measured memory_bytes: 5604
// Author: πα

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

map<long, long> m;

long ans(long x)
{
    if(m.count(x))
        return m[x];
    if(x == 1)
        return 1;
    return m[x] = 1 + ans(x/2) + ans(x/2);
}

int main()
{
    long n;
    cin >> n;
    cout << ans(n);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    int op = 1;
    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        if(a == op){
            op++;
        }else{
            cnt++;
        }
    }
    if(cnt == n){
      cnt = -1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
<?php
$n = (int)fgets(STDIN);
for($i = 0; $i < $n; $i++){
    $map[] = trim(fgets(STDIN));
}
$count = 0;
for($i = 0; $i < $n; $i++){
    $flag = true;
    for($x = 0; $x < $n; $x++){
        $X = ($x+$i) % $n;
        for($y = $x + 1; $y < $n; $y++){
            if($map[$X][$y] != $map[($y+$i)%$n][$x])$flag = false;
        }
    }
    $count+=$flag;
}
echo $count*$n,"\n";


Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int era[][3] = {
	{ 0, 0, 0 },
	{ 1868, 9, 8 },
	{ 1912, 7, 30 },
	{ 1926, 12, 25 },
	{ 1989, 1, 8 },
};

string s[] = {"pre-meiji", "meiji", "taisho", "showa", "heisei"};

int main() {
	int y, m, d;
	while (cin >> y >> m >> d) {
		string name = "";
		int ny;
		for (int i = 4; i >= 0; i--) {
			int yy = era[i][0];
			int mm = era[i][1];
			int dd = era[i][2];
			ny = y - yy + 1;
			name = s[i];
			if (y < yy)
				continue;
			else if (y > yy)
				break;
			else {
				if (m > mm)
					break;
				else if (m == mm)
					if (d >= dd)
						break;
			}
		}
		if (name == s[0])
			cout << name << endl;
		else
			cout << name << " " << ny << " " << m << " " << d << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

list<int> Prime(int num) {
	list<int>P;
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (j*j > i) {
				break;
			}
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if (j*j > i + 2) {
				break;
			}
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	P.push_front(3);
	P.push_front(2);
	return P;
}

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

	cin >> N;
	auto box = Prime(55555);
	for (auto i : box) {
		if (i % 5 == 1) {
			cout << i << " ";
			N--;
			if (!N) {
				return 0;
			}
		}
	}
	return 0;
}


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

int main()
{
	int m,f,r;
	char rank;

	while(cin >> m >> f >> r){
		if(m == -1 && f == -1 && r == -1)
			break;

		int ad_p = m+f;

		if(ad_p >= 80)							rank = 'A';
		if(80 > ad_p && ad_p >= 65 )	rank = 'B';
		if(65 > ad_p && ad_p >= 50 )	rank = 'C';
		if(50 > ad_p && ad_p >= 30 )
			if(r >= 50)								rank = 'C';
			else										rank = 'D';
		if(30 > ad_p)							rank = 'F';
		if(m == -1 || f == -1)				rank = 'F';

		cout << rank << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
def gcd(x,y)
    x,y = y, x if y > x
    return x%y == 0 ? y : gcd(y, x%y)
end

n = gets.to_i
#a,b = gets.split.map(&:to_i)
#s = gets.chomp

mp = {}

hose = 0
n.times do
    a,b = gets.split.map(&:to_i)
    if a == 0 and b == 0
        hose += 1
        next
    end
    if a == 0
        mp[[0,1]] = 0 if mp[[0,1]] == nil
        mp[[0,1]] += 1
        next
    end
    if b == 0
        mp[[1,0]] = 0 if mp[[1,0]] == nil
        mp[[1,0]] += 1
        next
    end
    g = gcd(a.abs,b.abs)
    a /= g
    b /= g
    if (a*b < 0 and b < 0) or (a < 0 and b < 0)
        a = -a
        b = -b
    end
    mp[[a,b]] = 0 if mp[[a,b]] == nil
    mp[[a,b]] += 1
end

#p mp

cnt = 0
ans = 1
mod = 1000000007
mp.each do |k, v|
    next if mp[k] == 0
    if k == [0,1]
        cnt = mp[[1,0]].to_i
        mp[[1,0]] = 0 if cnt > 0
    elsif k == [1,0]
        cnt = mp[[0,1]].to_i
        mp[[0,1]] = 0 if cnt > 0
    else
        ac, bc = -k[1], k[0]
        if ac < 0 && bc < 0 
            ac = -ac
            bc = -bc
        end
        cnt = mp[[ac,bc]].to_i
        mp[[ac,bc]] = 0 if cnt > 0
    end
    a = (2.pow(v, mod) + 2.pow(cnt, mod) - 1)%mod
    ans = (a*ans)%mod
end

puts (ans+hose-1)%mod

Measured memory_bytes: 36320
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
// clang-format on
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  string s;

  cin >> s;
  int n = (int)s.length();

  stack<char> st;
  st.push(s[0]);
  for (int i = 1; i < n; ++i) {
    char c = s[i];
    if (st.empty()) {
      st.push(c);
      continue;
    }
    char t = st.top();
    if (c != t) {
      st.pop();
    } else {
      st.push(c);
    }
  }

  cout << n - st.size() << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	if ((A + B) % 2 == 0) {
		cout << (A + B) / 2 << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}



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

int main(){
  int N;
  const int INF = 1e9;
  cin >> N;
  vector<vector<int>> D(N,vector<int>(N,INF));
  vector<pair<int,int>> E;
  for(int i = 1; i < N; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    D[a][b] = 1;
    D[b][a] = 1;
    E.emplace_back(a,b);
  }
  for(int i = 0; i < N; ++i) D[i][i] = 0;
  for(int k = 0; k < N; ++k){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
        D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
      }
    }
  }
  int M;
  cin >> M;
  vector<pair<int,int>> uv;
  for(int i = 0; i < M; ++i){
    int u, v;
    cin >> u >> v;
    --u,--v;
    uv.emplace_back(u,v);
  }
  long long ans = 0;
  for(int i = 0; i < (1<<M); ++i){
    int n = N-1;
    for(auto e : E){
      bool f = false;
      for(int j = 0; j < M; ++j){
        if(not (i>>j&1)) continue;
        auto x = uv[j];
        if((D[x.first][x.second] == D[x.first][e.first]+1+D[e.second][x.second]) or
           (D[x.first][x.second] == D[x.first][e.second]+1+D[e.first][x.second])){
          f = true;
          break;
        }
      }
      if(f) --n;
    }
    if(__builtin_popcount(i)%2) ans -= 1LL<<n;
    else ans += 1LL<<n;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		
		// 計算
		long result = 0L;
		long tate = 0L;
		long yoko = 0L;
		boolean flg = false;
		for(int i = n-1; i >= 0; i--){
		    if(!flg && tate == a[i]){
		        flg = true;
		    }else if(!flg){
		        tate = a[i];
		    }else if(yoko == a[i]){
		        result = tate * yoko;
		        break;
		    }else{
		        yoko = a[i];
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 49604
#include<stdio.h>
#include<string.h>
#define MAX_N 200000
int par[MAX_N];
int rank[MAX_N];
int original_par[MAX_N];
int query_list[MAX_N][2];


void init(int n){
  int i;
  for(i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
  x =find(x);
  y =find(y);
  if(x==y){
    return ;
  }
  par[y] = x;
  /*
  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
  */
}
int same(int x,int y){
  return find(x)==find(y);
}
int main(){
  int N,Q;
  long long int ans;
  int i,j,k;
  int marked_list[MAX_N];
//??¨??¨????????§?????????????????§1?????¬???
  while(1){
    scanf("%d %d",&N,&Q);
    if(N==0&&Q==0)break;
    memset(marked_list,0,sizeof(int)*N);
    //for(i=0;i<N;i++){ marked_list[i]=0; }
    marked_list[0]=1;
    original_par[0]=0;
    ans=0;

    for(i=1;i<N;i++){
      scanf("%d\n",&original_par[i]);
      original_par[i]--;
    }
    for(i=0;i<Q;i++){
      char bc;
      scanf("%c %d\n",&bc,&query_list[i][1]);
      query_list[i][0] = bc;
      query_list[i][1]--;
    }

    init(N);
    for(i=0;i<Q;i++){
      if(query_list[i][0]=='M'){
        if(marked_list[query_list[i][1]]==1){
          query_list[i][0]='N';
        }
        marked_list[query_list[i][1]]=1;
      }
    }
    for(i=0;i<N;i++){
      if(0==marked_list[i]){
        unite(original_par[i],i);
      }
    }
    for(i=Q-1;i>=0;i--){
      if(query_list[i][0]=='Q'){
        int q_a = find(query_list[i][1])+1;
        ans += q_a;
      //  printf(":%d\n",ans);
      }else if(query_list[i][0]=='M'){
        int m = query_list[i][1];
        unite(original_par[m],m);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;

}

Measured memory_bytes: 2968
from sys import stdin
from itertools import repeat
def main():
    n = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * n))
    b = [(dat[i*2] + dat[i*2+1], dat[i*2] - dat[i*2+1]) for i in xrange(n)]
    b.sort()
    ans = 1
    c = b[0][0]
    for r, l in b:
        if l >= c:
            ans += 1
            c = r
    print ans
main()


Measured memory_bytes: 22200