akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,m) for(int i = 0; i < m; i++)
using ll = long long;

int main(){
  ll n,T;
  cin >> n >> T;
  vector<ll> t(n);
  rep(i,n) cin >> t.at(i);
  ll ans = 0;
  rep(i,n-1){
    ll dif = t.at(i+1)-t.at(i);
    if(dif>=T){
      ans+=T;
    }else ans+=dif;
  }
  ans+=T;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

static const int N = 100;
int main(){
    int M[N][N];
    int n, u, k, v;
    cin >> n;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            M[i][j] = 0;

    for(int i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
}


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

typedef double ld;

int main(){
  int n, W;
  while(cin >> n >> W, n|W){
    ld ink[55];
    fill(ink, ink+55, 0);
    int v;
    for(int i = 0 ; i < n ; i++){
      cin >> v;
      ink[v/W]++;
    }
    
    ld Max = 0;
    ld bar = 0;
    
    for(int i = 0 ; i < 55 ; i++){
      Max = max(Max, ink[i]);
      if(ink[i]) bar++;
    }
    
    int pos = -1;
    for(int i = 54 ; i >= 0 ; i--){
      if(ink[i]){
	pos = i; break;
      }
    }
    
    
    ld color = pos;
    ld ans = 0;
    
    for(int i = 0 ; i <= pos ; i++){
      //cout << i << ' ' << ink[i] << endl;
      //double tmp = (ld)((ld)(color)/(pos) * (ld)(ink[i]/Max));
      //cout << color/(bar-1) << ' ' << ink[i]/Max << endl;
      // cout << tmp << endl;
	//cout << (ld)((ld)(color)/(bar-1) * (ld)(ink[i]/Max)) << endl;
      
      ans += (ld)((ld)(color--)/(pos) * (ld)(ink[i]/Max));
    }
    printf("%.15f\n", ans+0.01);
  }
  
  return 0;
}

Measured memory_bytes: 1188
/**
 * C - Anti-Division
 * https://atcoder.jp/contests/abc131/tasks/abc131_c
 **/
#include<iostream>

using namespace std;

long gcd(long a, long b) {
    if(a < b) {
        long tmp_a = a;
        a = b;
        b = tmp_a;
    } else if (a == b) {
        return a;
    }
    long r = a%b;
    while(r != 0) {
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

int main() {
    long A, B, C, D;
    cin >> A >> B >> C >> D;
    long lcm_c_d = C * D / gcd(C, D);
    long q_num_1 = (long)B/C + (long)B/D - (long)B/lcm_c_d;
    long q_num_2 = (long)(A-1)/C + (long)(A-1)/D - (long)(A-1)/lcm_c_d;
    cout << B - A  + 1 - (q_num_1-q_num_2) << endl;
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    string S;
    string T;
    cin >> S >> T;
    string sum;
    for (long long i = 0; i < N; ++i) {
        sum += S[i];
        sum += T[i];
    }
    cout << sum << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x, n;
    cin >> x >> n;
    vector<bool> vis(110, 0);
    for (int i = 0; i < n; i++) {
        int u;
        cin >> u;
        vis[u] = true;
    }
    pair<int, int> mn = make_pair(101, 101);
    for (int i = -10; i <= 110; i++) {
        if (i < 0) {
            mn = min(mn, make_pair(abs(x - i), i));
        } else {
            if (vis[i]) continue;
            mn = min(mn, make_pair(abs(x - i), i));
        }
    }
    cout << mn.second << '\n';
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200005;
const int INF = (LL)1e9 + 5;

string s;
int dp[MAXN][30];
char add[MAXN][30] = {0};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> s;
	for (int i = 0; i < 26; i++) {
		dp[s.size()][i] = 1;
	}
	
	for (int i = s.size() - 1; i >= 0; i--) {
		int pos = min_element(dp[i + 1], dp[i + 1] + 26) - dp[i + 1];
		int len = dp[i + 1][pos];
		for (int j = 0; j < 26; j++) {
			if (s[i] == j + 'a') {
				dp[i][j] = len + 1;
				add[i][j] = pos;
			}
			else {
				dp[i][j] = dp[i + 1][j];
				add[i][j] = -1;
			}
		}
	}
	
	string ans;
	int cur = min_element(dp[0], dp[0] + 26) - dp[0];
	ans.push_back(cur + 'a');
	for (int i = 0; i < s.size(); i++) {
		if (add[i][cur] != -1) {
			ans.push_back(add[i][cur] + 'a');
			cur = add[i][cur];
		}
	}
	
	cout << ans << "\n";
	
	return 0;
	
	/**** Note MAXN ****/
}


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

using ll=int64_t;

int main(){
  string A,B; cin >>A >>B;
  ll temp1=A.size(),temp2=B.size();

  if (temp1>temp2) cout <<"GREATER" <<endl;
  else if (temp1<temp2) cout <<"LESS" <<endl;
  else if (temp1==temp2) {
    if (A>B) cout <<"GREATER" <<endl;
    else if (A<B) cout <<"LESS" <<endl;
    else cout <<"EQUAL" <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

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

using namespace std;

class ab{
  public:
  int a;
  int b;
};

int main()
{
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N), B(N);
  rep(i,N) cin >> A[i] >> B[i];
  
  vector<pair<int, int>> AB(N);
  rep(i,N) AB[i] = make_pair(A[i], B[i]);
  
  sort(AB.begin(), AB.end());
  
  long long ans = 0;
  
  for(int i=0; i<N; i++)
  {
    // 購入する本数
    // 買えるだけ買う
    int cnt = min(AB[i].second, M);
    M -= cnt;
    ans += (long long)cnt * AB[i].first;
//    cout << AB[i].first << ", " << AB[i].second << endl;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    import sys
    
    i = list(map(int, input().split()))
    N = i[0]
    K = i[1]
    
    p = list(map(int, sys.stdin.readline().split()))
    max_s = 0
    s_current = 0
    
    for i in range(N - K + 1):
        if i == 0:
            p_list = p[:K]
            max_s = sum(p_list)
            s_current = max_s
        else:
            s_current = s_current - p[i - 1] + p[i + K - 1]
            if s_current > max_s:
                max_s = s_current
        
    ans = (max_s + K) / 2.0
    print(ans)

Measured memory_bytes: 25632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define rrp(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc() ; !isdigit(tmp) ; tmp = gc())
    key = (tmp == '-');
  for ( ; isdigit(tmp) ; tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 200010;
int pla[N], n, len, val[N];
ll ans, rec[2][N];
void prework() {
  rep (i, 1, n-1) val[i] = pla[i+1] - pla[i];
  rep (i, 1, n-1)
    rec[0][i] = rec[0][i-1] + 1ll * (n-i) * val[i];
  rep (i, 1, n-1)
    rec[1][i] = rec[1][i-1] + 1ll * (i-1) * val[i];
}
ll calc(int l,int r) {
  if (l == r) return 0;
  if (l+1 == r) return pla[l] + len - pla[r];
  ll ret = 0;
  int mid = (l + r) >> 1;
  ret += (rec[0][mid-1] - rec[0][l-1]) * 2ll + 1ll * (pla[mid] - pla[l]) * ((r-l-1) - (2*n - 2*l));
  ret += (rec[1][r-1] - rec[1][mid]) * 2ll + 1ll * (pla[r] - pla[mid+1]) * ((r-l-2) - (2*r - 4));
  ret += 1ll * (r - l) * (pla[l] + len - pla[r]);
  return ret;
}
int main() {
  read(len), read(n);
  rep (i, 1, n) read(pla[i]);
  prework();
  rep (i, 1, n)
    ckmx(ans, pla[i] + calc(i, n));
  rep (i, 1, n) pla[i] = len - pla[i];
  reverse(pla+1, pla+n+1);
  prework();
  rep (i, 1, n)
    ckmx(ans, pla[i] + calc(i, n));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#pragma GCC optimize("O2")
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int IMIN=(1<<31);
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix(int A[],const int N)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,N)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,N){temp[--u[A[N-1-i]>>8*k&255]]=A[N-1-i];}k++;
    rep(i,N)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,N)A[--v[temp[N-1-i]>>8*k&255]]=temp[N-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,minus=0,A[200000],B[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  Radix(A,p),Radix(B,m);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*B[i]*B[minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;minus=1;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(minus)r=-mid-1l;else r=mid-1l;}else{if(minus)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

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

int main() {
    long n, ans = 0;
    cin >> n;
    rep(i, n) {
        if((i + 1) % 3 && (i + 1) % 5) ans += i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    cout << (n%10 == n/100 ? "Yes" : "No") << endl;
    return 0;
}

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

int main(void) {
	char in[101];
	int i,len,ok,count;
	count=0;
	while(1) {
		if(scanf("%s",in)==-1)break;
		len=strlen(in);
		ok=1;
		for(i=0;i<len/2;i++) {
			if(in[i]!=in[len-1-i]) {
				ok=0;
				break;
			}
		}
		if(ok)count++;
	}
	printf("%d\n",count);
	return 0;
}

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

int main(){
  ll N,Y;cin>>N>>Y;
  bool flag=false;
  for(int i=0;i<=N;++i){
    for(int j=0;j<=N-i;++j){
      int k=N-i-j;
      if(10000*i+5000*j+1000*k==Y){
        flag=true;
        cout << i << " " << j << " " << k << endl;
        break;
      }
    }
    if(flag)break;
  }
  if(flag);
  else cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

var n int
var G map[int]map[int]bool

func initGraph() {
	G = make(map[int]map[int]bool, n)
}

func add(from, to int) {
	if _, ok := G[from]; !ok {
		G[from] = make(map[int]bool)
	}
	G[from][to] = true
}

var seen map[int]bool
var ba, bb int

func dfs(v int) {
	seen[v] = true
	for t := range G[v] {
		if seen[t] {
			continue
		}
		if (v == ba && t == bb) || (v == bb && t == ba) {
			continue
		}
		dfs(t)
	}
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n = readInt()
	m := readInt()
	initGraph()

	type bridge struct{ a, b int }
	bs := make([]bridge, m)
	for i := 0; i < m; i++ {
		a, b := readInt(), readInt()
		add(a, b)
		add(b, a)
		bs[i] = bridge{a, b}
	}

	ans := 0
	for _, bv := range bs {
		ba, bb = bv.a, bv.b
		seen = make(map[int]bool, n)
		dfs(1)
		if len(seen) != n {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
/*1 insert(T, z)
2     y = NIL // x の親
3     x = 'T の根'
4     while x ≠ NIL
5         y = x // 親を設定
6         if z.key < x.key
7             x = x.left // 左の子へ移動
8         else
9             x = x.right // 右の子へ移動
10    z.p = y
11
12    if y == NIL // T が空の場合
13        'T の根' = z
14    else if z.key < y.key
15        y.left = z // z を y の左の子にする
16    else
17        y.right = z // z を y の右の子にする*/

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
  x = x->left;
}
return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
   x = x->right;
 }
 return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
  if(k < u->key) u = u->left;
  else u = u->right;
}
return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
Node y;
y = x->parent;
while(y !=NIL && x == y->right){
  x = y;
  y = y->parent;
}
return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
else y = treeSuccessor(z);

if(y->left != NIL) x = y->left;
else x = y->right;

if(x != NIL) x->parent = y->parent;

if(y->parent == NIL) root = x;
else if(y == y->parent->left) y->parent->left = x;
else y->parent->right = x;

if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 while(x != NIL){
   y = x;
   if(z->key < x->key) x = x->left;
   else x = x->right;
 }
 z->parent = y;

 if(y == NIL) root = z;
 else if(z->key < y->key) y->left = z;
 else y->right = z;


}

void inorder(Node u){
  if(u != NIL){
      inorder(u->left);
      printf(" %d", u->key);
      inorder(u->right);
    }
    else return;
}
void preorder(Node u){
  if(u != NIL){
      printf(" %d", u->key);
      preorder(u->left);
      preorder(u->right);
    }
    else return;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25240
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	
	while(cin>>n)
	{
		if(n>=30)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string a, b; cin >> a >> b;
	ll x = stoi(a + b);
	
	bool ans = false;
	for(ll i = 0; i * i <= x; i++){
		if(i * i == x)ans = true;
	}
	print(ans? "Yes" : "No")
	
	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;
using P = pair<int,int>;

const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll sum = 0;
  rep(i, n) sum = (sum + a[i]) % MOD;

  ll ans = 0;
  rep(i, n) {
    ans = (ans + (sum - a[i]) * a[i] % MOD) % MOD;
  }
  if (ans < 0) ans += MOD;
  if (ans % 2 == 0) ans /= 2;
  else ans = (ans + MOD) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
L = list(map(int,input().split()))
A = L[0]
B = L[1]
C = L[2]
D = L[3]
E = L[4]
F = L[5]
dmax = 0
wmax = 0
smax = 0

a = 1
while a*A*100 <= F:
	b = 0
	while (a*A+b*B)*100 <= F:
		water = (a*A+b*B)*100
		c = 0
		while water + c*C <= F and c*C <= water*E/100:
			d = 0
			while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
				dens = (c*C+d*D) / (water + c*C + d*D)
				if dmax <= dens:
					dmax = dens
					wmax = water
					smax = c*C + d*D
				d += 1
			c += 1
		b += 1
	a += 1
a = 0
b = 1
while (a*A+b*B)*100 <= F:
	water = (a*A+b*B)*100
	c = 0
	while water + c*C <= F and c*C <= water*E/100:
		d = 0
		while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
			dens = (c*C+d*D) / (water + c*C + d*D)
			if dmax <= dens:
				dmax = dens
				wmax = water
				smax = c*C + d*D
			d += 1
		c += 1
	b += 1
print(wmax+smax,smax)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    a--;
    b--;
    c--;
    d--;
    if(c>d){
        bool ch=false;
        for(int i=b-1;i<min(n-3,d);i++){
            if(i>=c)break;
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
                ch=true;
                break;
            }
        }
        if(!ch){
            fin("No");
            return 0;
        }
    }
    for(int i=a+1;i<c-1;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            fin("No");
            return 0;
        }
    }
    for(int i=b;i<d-1;i++){
        if(s[i]=='#'&&s[i+1]=='#'){
            fin("No");
            return 0;
        }
    }
    fin("Yes");
    
//////////////////////////////////////////////////////
return 0;}

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

int main(){
  int a,b,k;
  cin>>a>>b>>k;
  
  vector<int>mod(a+1);
  mod.at(0)=0;
  for(int i=1;i<=a;i++){
    if(a%i==0&&b%i==0){
      mod.at(i)=i;
    }
    else{
      mod.at(i)=0;
    }
  }
  
  sort(mod.begin(),mod.end());
  reverse(mod.begin(),mod.end());
  
    cout<<mod.at(k-1);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	long a, b, n;
	scanf("%ld%ld%ld", &n, &a, &b);
	printf("%ld",n==1 ? (a!=b ? 0 : 1) : (a > b ? 0 : (b*(n-1)+a) - (a*(n-1)+b) + 1));
	return 0;
}

Measured memory_bytes: 128
H, W = map(int, input().split())
S = []
T = []
for i in range(H):
    S.append(input())
    T.append([0 for i in range(W)])

for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            continue
        for dx,dy in [(1,0), (-1,0), (0,1), (0,-1), (-1,-1), (-1,1), (1,1), (1,-1)]:
            x,y = j+dx,i+dy
            if x >= W or x < 0 or y < 0 or y >= H:
                continue
            T[y][x] += 1
for i in range(H):
    for j in range(W):
        print('#' if S[i][j] == '#' else T[i][j], end='')
    print()

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

const int maxn = 205;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, L[maxn];

int main()
{
	n = gi() * 2;
	for (int i = 1; i <= n; ++i) L[i] = gi();
	sort(L + 1, L + n + 1);
	int ans = 0;
	for (int i = 1; i <= n; i += 2) ans += L[i];
	printf("%d\n", ans);
	
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] A = new String[N];
		int tmp = 0;
		int answer = 0;

		for (int i = 1; i <= N; i++) {
			tmp = sc.nextInt();
			A[tmp - 1] = String.valueOf(i);
		}

		System.out.println(String.join(" ", A));
	}
}


Measured memory_bytes: 68028
integer(16),allocatable,dimension(:)::A
integer(16),allocatable,dimension(:)::B
integer(16),allocatable,dimension(:)::C
integer(16) N,M
integer cindex
read*,N,M
allocate(A(N),B(M),C(M))
read*,A
call heapsort(N,A)
do i=1,M
  read*,B(i),C(i)
end do
call neoheapsort(M,C,B)
cindex=M
do i=1,N
  if(C(cindex)>A(i))then
    A(i)=C(cindex)
    B(cindex)=B(cindex)-1
    if(B(cindex)==0)cindex=cindex-1
    if(cindex==0)exit
  else
    exit
  endif
end do
print"(I0)",sum(A)

contains

subroutine neoheapsort(n,array,b)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16),intent(inout) :: b(1:n)
  integer(16)::i,k,j,l
  integer(16):: t,tb

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
        tb=b(l)
     else
        t=array(k)
        tb=b(k)
        array(k)=array(1)
        b(k)=b(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           b(1)=tb
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           b(i)=b(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
     b(i)=tb
  enddo
  return
end subroutine neoheapsort

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

Measured memory_bytes: 5504
/*BINH :))*/
#include<bits/stdc++.h>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(x,a,b) for (int x=a,u,v;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL cout<<endl
#define maxn 1005
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#pragma GCC optimize("Ofast")
ll n,m,k,kc,xa;
ll a[1000000],f[1000000];
int main(){
    IO
    cin>>n>>k;
    FOR(i,1,n){
        cin>>a[i];
    }
    FOR(i,2,n){
        f[i] = 1e9;
        FOR(j,1,k){
            if(i-j<=0) break;
            f[i] = min(f[i],abs(a[i]-a[i-j])+f[i-j]);
        }
    }
    cout<<f[n];
}
    

Measured memory_bytes: 5120
#include <iostream>
#include <stdio.h>
 
using namespace std;
 
main(){
  int N;
  scanf("%d",&N);
  int n=N%10;
  if(n==3)printf("bon");
  else if(n==0||n==1||n==6||n==8)printf("pon");
  else printf("hon");
  return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int ans = 0;
  int minF = 9;
  int lastA = -1;
  vector<int> A(5);
  rep(i, 5)cin >> A[i];

  rep(i, 5) if(minF > (A[i]-1)%10){minF = A[i]%10; lastA = i;}

  rep(i, 5){
    if(i!=lastA) ans += ((A[i]-1)/10 + 1) * 10;
    else ans += A[i];
  }
  cout << ans << endl;
  return 0;
}



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

namespace WelcomeAtcordet
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            string[] n_row = new string[N];
            string[] m_row = new string[M];

            for (int i = 0; i < N; i++)
            {
                n_row[i] = Console.ReadLine();
            }
            for (int i = 0; i < M; i++)
            {
                m_row[i] = Console.ReadLine();
            }


            for (int i = 0; M <= N - i; i++)
            {
                if (n_row[i].Contains(m_row[0]))
                {
                    if (n_row.Length == 1)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }

                    int seach_point = n_row[i].IndexOf(m_row[0]);

                    while (seach_point > 0)
                    {
                        for (int j = 1; j < M; j++)
                        {
                            if (n_row[i + j - 1].IndexOf(m_row[j - 1], seach_point - 1) != n_row[i + j].IndexOf(m_row[j], seach_point - 1))
                            {
                                break;
                            }
                            if (j == M - 1)
                            {
                                Console.WriteLine("Yes");
                                return;
                            }
                        }
                        seach_point = n_row[i].IndexOf(m_row[0], seach_point+1);
                    }
                }
            }

            Console.WriteLine("No");
        }
    }
}


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

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

  if (A + B == 3)
    cout << 3 << endl;
  if (A + B == 4)
    cout << 2 << endl;
  if (A + B == 5)
    cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int x, y; cin >> x >> y;
	for (int i = 0; i <= x; ++i)
	{
		int l = 2 * i + 4 * (x - i);
		if (l == y)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3620
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	x := nextInt()

	m := 1
	for b := 2; b*b <= x; b++ {
		c := b
		for c*b <= x {
			c *= b
		}
		if m < c {
			m = c
		}
	}

	fmt.Println(m)
}


Measured memory_bytes: 640
n = int(input())

x = n

ans = []

if x == 0:
    print(0)
else:
    while  x != 0:
        ans.append(abs(x%(-2)))
        x = (x - ans[-1])/(-2)


    for i in range((len(ans)-1),-1,-1):
        print(int(ans[i]),end="")

    print()

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

int main(){
    ll n;
    cin>>n;
    int minf = inf;
    int m = sqrt(n);
    for(int i=1;i<=m;i++){
        if(n%i==0){
            string a=to_string(i);
            string b=to_string(n/i);
            int f = max(a.size(),b.size());
            minf = min(minf,f);
        }
    }
    cout<<minf<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n) { //初期化
    int N=n+1;
    par.resize(N); rank.resize(N);
    rep(i,N) {par[i] = i, rank[i] = 0;}
  }

  int root(int x) { //ノードの根を返す
    if (par[x] == x) return x; //親が自分なら自分を返す
    else {
      int r = root(par[x]); //根まで遡る
      return par[x] = r;
    }
  }

  bool issame(int x, int y) { //同じ根ならtrue,ちがうならfalse
    return root(x) == root(y);
  }

  bool merge(int x, int y) { //ノードを接続する
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x; //ランクの小さい方に接続
    return true;
  }
};

void Main(){

  int N,K,L;

  cin>>N>>K>>L;

  UnionFind tree1(N);
  UnionFind tree2(N);

  rep(i,K){
    int p,q;
    cin>>p>>q;
    tree1.merge(p-1,q-1);
  }

  rep(i,L){
    int r,s;
    cin>>r>>s;
    tree2.merge(r-1,s-1);
  }

  vector<pair<ll, int>> p;
  rep(i,N){
    int r1,r2;
    r1=tree1.root(i);
    r2=tree2.root(i);
    p.emplace_back((ll) r1*1000000+r2,i);
  }

/*
  map<pair<ll, ll>, ll> mp;
  rep(i,N){
    mp[{tree1.root(i),tree2.root(i)}]++;
  }
  rep(i,N){
    cout << mp[{tree1.root(i),tree2.root(i)}] <<" ";
  }
*/

  int ct=1;

  SORT(p);

  ll pp=p[0].first;

  int ans[N];

  reps(i,1,N){
    if(p[i].first==pp) ct++;
    else{
      rep(j,ct){
        ans[p[i-j-1].second]=ct;
      }
      pp=p[i].first;
      ct=1;
    }
  }

  rep(j,ct){
    ans[p[N-j-1].second]=ct;
  }

  rep(i,N){
    cout << ans[i] <<" ";
  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 9328
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(int argc, char const *argv[]) {
  long long N, A, B, C, D, E;
  std::cin >> N;
  std::cin >> A;
  std::cin >> B;
  std::cin >> C;
  std::cin >> D;
  std::cin >> E;
  long long temp = min(A, min(B, min(C, min(D, E))));
  temp = (N % temp == 0) ? N/temp + 4 : N/temp + 5;
  std::cout << temp << '\n';

  return 0;
}


Measured memory_bytes: 256
input_str = STDIN.gets
input_list = input_str.split(" ")
stack = []

input_list.each do |value|
  case value
  when '+'
    b = stack.pop
    a = stack.pop
    c = a + b
    stack.push c
  when '-'
    b = stack.pop
    a = stack.pop
    c = a - b
    stack.push c
  when '*'
    b = stack.pop
    a = stack.pop
    c = a * b
    stack.push c
  else
    value_int = value.to_i
    stack.push value_int
  end
end

answer = stack.pop
puts answer.to_i



Measured memory_bytes: 6868
#include <iostream>
#include <string>
#define int long long
signed main(){
  int N,ans=0;
  std::string bef,aft,S;
  std::cin>>N>>S;
  for (int i=0;i<N;i++){
    if(i==0){
      bef=S[0];
      ans++;
    }
    else{
      aft=S[i];
      if(bef==aft){
        ans=ans;
      }else{
        ans ++;
        bef=aft;
      }
      }
  }
  std::cout<<ans<<std::endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 2e5 + 10; int a[N], sum;
signed main() {
	int n; read (n);
	for (int i = 1; i <= n; ++i) read (a[i]), sum ^= a[i];
	for (int i = 1; i <= n; ++i) printf ("%d ", sum ^ a[i]);
	return puts (""), 0;
}

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

int n;
int a[40000];
int b[40000];
int cnt[40000];

int solve()
{
	sort(a, a + n, greater<int>());
	sort(b, b + n, greater<int>());
	memset(cnt, 0, sizeof cnt);
	for (int i = 0, j = 0; i < n; i++){
		while (j < n && a[j] > b[i]) j++;
		if (j == n) break;
		cnt[j++] = 1;
	}
	for (int i = 1; i < n; i++) cnt[i] += cnt[i - 1];
	for (int i = 0; i < n; i++) cnt[i] = i + 1 - cnt[i];
	
	for (int i = 0; i < n - 1; i++){
		if (i + 1 < cnt[i] * 2) return i + 1;
	}
	return -1;
}

int main()
{
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			scanf("%d", a + i);
		}
		for (int i = 0; i < n; i++){
			scanf("%d", b + i);
		}
		int res = solve();
		if (compl res) printf("%d\n", res);
		else puts("NA");
	}
}

Measured memory_bytes: 1684
N = int(input())
_M = [] 
_A = [] 
_R = [] 
_C = [] 
_H = [] 

for i in range(N):
    x = input()
    if x[0] == 'M':
        _M.append(x)
    elif x[0] == 'A':
        _A.append(x)
    elif x[0] == 'R':
        _R.append(x)
    elif x[0] == 'C':
        _C.append(x)
    elif x[0] == 'H':
        _H.append(x)

m = len(_M)
a = len(_A)
r = len(_R)
c = len(_C)
h = len(_H)

x = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h

print(x)


Measured memory_bytes: 10208
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _n = read::<usize>();
    let hs = read_vec::<usize>();

    let mut ans = 0;
    let mut count = 0;
    let mut cur = 0;

    for h in hs {
        if cur < h {
            ans = std::cmp::max(ans, count);
            count = 0;
            cur = h;
        } else {
            count += 1;
            cur = h;
        }
    }
    ans = std::cmp::max(ans, count);

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

Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define debug 1
int main(int argc,char **argv) {
	char a,b,c;
	char d,e,f;
	int ans=0;
	cin>>a>>b>>c;
	cin>>d;
	if(d=='\n') cin>>d;
	cin>>e>>f;
	if(a==d) ans++;
	if(b==e) ans++;
	if(c==f) ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	string s;
	cin >> s;
	for (int i = 2; i < s.size(); i++) {
		if (s[i] == s[i - 1]) {
			cout << i << ' ' << i+1;
			return 0;
		}
		if (s[i] == s[i - 2]) {
			cout << i - 1 << ' ' << i+1;
			return 0;
		}
	}
	if (s[0] == s[1]) {
		cout << "1 2";
		return 0;
	}
	cout << "-1 -1";
}

Measured memory_bytes: 512
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <string>

using namespace std;

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

typedef long long ll;
const int MAX = INT_MAX;

int G[201][201] = { 0 };

void gcd(int a, int b) {
	int s = a, t = b;
	if (a < b)  swap(a, b);
	int r;
	while (b > 0) {
		r = a % b;
		a = b;
		b = r;
	}
	G[s][t] = a;
}

int tgcd(int a, int b, int c)
{
	return G[G[a][b]][G[b][c]];
}

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

	int sum = 0;
	lrep(i, 1, 201) {
		lrep(j, 1, 201) {
			gcd(i, j);
		}
	}

	lrep(i, 1, n + 1) {
		lrep(j, 1, n + 1) {
			lrep(k, 1, n + 1) {
				sum += tgcd(i, j, k);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-8;

double dot(P a, P b){ return real(conj(a)*b);}
double cross(P a, P b){ return imag(conj(a)*b);}

int ccw(P a, P b, P c){
    c -= a;
    b -= a;
    if(cross(b, c) > EPS) return 1;
    if(cross(b, c) < -EPS) return -1;
    if(dot(b,c) < -EPS) return 2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

bool isIntersect(L s1, L s2){
    return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
             ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0);
}

P crossPoint(L l, L m){
    double A = cross(l.second - l.first, m.second - m.first);
    double B = cross(l.second - l.first, l.second - m.first);
    if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
    else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

double area(vector<P> v){
    double sum = 0.0;
    int n = v.size();
    for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
    return fabs(sum / 2.0);
}

string ans(vector<P> v){
    double a = area(v);
    if(a < EPS) return "kyo";
    if(a < 100000.0-EPS) return "syo-kichi";
    if(a < 1000000.0-EPS) return "kichi";
    if(a < 1900000.0-EPS) return "chu-kichi";
    return "dai-kichi";
}

int main(){
    double x1,y1,x2,y2;
    while(cin >> x1 >> y1 >> x2 >> y2 && (x1||y1||x2||y2)){
        L v[3];
        vector<P> p;
        bool f = false;
        v[0] = L(P(x1,y1),P(x2,y2));
        for(int i=1;i<3;i++) {
            cin >> x1 >> y1 >> x2 >> y2;
            v[i] = L(P(x1,y1),P(x2,y2));
            if(!isIntersect(v[0],v[i])) f = true;
            else p.push_back(crossPoint(v[0],v[i]));
        }
        if(!isIntersect(v[1],v[2])) f = true;
        else p.push_back(crossPoint(v[1],v[2]));

        if(!f){
            for(int i=0;i<3;i++){
                for(int j=i+1;j<3;j++){
                    if(abs(p[i]-p[j]) < EPS) f = true;
                }
            }
        }

        if(f) cout << "kyo" << endl;
        else cout << ans(p) << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int a = sc.nextInt();

        Set<String> set = new HashSet<>();

        for (int i=0; i<a; i++) set.add(sc.next());

        System.out.println(set.size());
    }
}


Measured memory_bytes: 78412
#include<iostream>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<complex>
using namespace std;

typedef pair<int, int> yxp;

yxp subt_pair(yxp a, yxp b) {
	return make_pair(a.first - b.first, a.second - b.second);
}

int cross_product(yxp a, yxp b) {
	return a.second*b.first - b.second*a.first;
}

int main() {
	yxp *p, *aa1, *aa2, vec1, vec2;
	int n, x, y, k, l;
	cin >> n;
	p = new yxp[n + 6];
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		p[i] = make_pair(y, x);
	}
	sort(p, p + n);
	aa1 = new yxp[n + 6];
	aa2 = new yxp[n + 6];
	aa1[0] = p[0];
	k = 0;
	for (int i = 1; i < n; i++) {
		if (k == 0) {
			aa1[++k] = p[i];
			continue;
		}
		for (; k > 0; k--) {
			vec1 = subt_pair(aa1[k], aa1[k - 1]);
			vec2 = subt_pair(p[i], aa1[k]);
			if (cross_product(vec1, vec2) <= 0) break;
		}
		aa1[++k] = p[i];
	}
	aa2[0] = p[0];
	l = 0;
	for (int i = 1; i < n; i++) {
		if (l == 0) {
			aa2[++l] = p[i];
			continue;
		}
		for (; l > 0; l--) {
			vec1 = subt_pair(aa2[l], aa2[l - 1]);
			vec2 = subt_pair(p[i], aa2[l]);
			if (cross_product(vec1, vec2) >= 0) break;
		}
		aa2[++l] = p[i];
	}

	cout << k + l + (aa1[k] == aa2[l] ? 0 : 1) << endl;
	for (int i = 0; i <= l; i++) {
		cout << aa2[i].second << " " << aa2[i].first << endl;
	}
	if (aa1[k] != aa2[l]) {
		cout << aa1[k].second << " " << aa1[k].first << endl;
	}
	k--;
	for (; k > 0; k--) {
		cout << aa1[k].second << " " << aa1[k].first << endl;
	}
	delete[] p;
	delete[] aa1;
	delete[] aa2;
	return 0;
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
 
//############################ENDOFTEMPLATE############################

bool compare(vi& a,vi& b){
  if(a[1]<b[1]){
    return true;
  }
  else if(a[1]==b[1]){
    if(a[0]<b[0])
      return true;
  }

  return false;
}


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

  vector<vi> inv(n,vi(2));

  for(int i = 0;i<n;i++){
    int x,l;
    cin>>x>>l;
    inv[i][0] = x-l;
    inv[i][1] = x+l;
  }

  sort(inv.begin(),inv.end(),compare);

  int ans = 1;
  int cl = inv[0][0],cr = inv[0][1];
  //cout<<cl<<" "<<cr<<endl;
  for(int i = 1;i<n;i++){
    int x = inv[i][0] ,y = inv[i][1];
    //cout<<x<<" "<<y<<endl;
    if(x>=cr){
      cl = x;
      cr = y;
      //cout<<cl<<" "<<cr<<endl;
      ans++; 
    }
  }

  cout<<ans;


} 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("moobuzz.in","r",stdin);
  //freopen("moobuzz.out","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(c - a) <= d) 
    cout << "Yes" << endl;
  else if (abs(b - a) <= d && abs(c - b) <= d) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll left = 0;
  ll right = 0;
  rep(i, N) {
    if (S[i] == '(') {
      right++;
    } else {
      if (right > 0) {
        right--;
      }
    }
  }

  repr(i, N - 1) {
    if (S[i] == ')') {
      left++;
    } else {
      if (left > 0) {
        left--;
      }
    }
  }

  rep(i, left) {
    cout << "(";
  }
  cout << S;
  rep(i, right) {
    cout << ")";
  }
  ENDL;

  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Data.List

main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]

  let
    a = n*(n+1)`div`2
    k = (sum xs) `div` a
    ys = zipWith (\x y -> x-y-k) xs (last xs : init xs)


  putStrLn $ if (sum xs) `mod` a == 0 && all (\y -> y `mod` n == 0 && y `div` n <= 0) ys then "YES" else "NO"


Measured memory_bytes: 33148
# ------------------------------------------------------------
# THIS IS METADATA FOR ATCODER_TOOLS
# BE CAREFULL WHEN YOU CHANGE THE VALUE
# 
# METADATA::START
# test-1
# input: "2 5\n"
# output: "10\n"
# test-2
# input: "100 100\n"
# output: "10000\n"
# MODE: TEST
# METADATA::FINISH
# 
# 
# select MODE from NONE, DEBUG, RUN, TEST
# problem: https://atcoder.jp/contests/abc169/tasks/abc169_a
# -------------------------------------------------------------

arr = gets.split(' ').map(&:to_i)
puts(arr[0] * arr[1])


Measured memory_bytes: 14260
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

ab1 = []
ab2 = []

for i in ab:
    if i[0] == 1:
        ab1.append(i[1])
    elif i[1] == n:
        ab2.append(i[0])

jud = ab1 + ab2
if len(jud) == len(set(jud)):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Measured memory_bytes: 64100