akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;
int main()
{
  int n,m;
  cin >> n >> m;
  map<int,set<int,greater<int> > > area;
  for(int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    area[a].insert(b);
  }
  if(area[1].size() == 0){
    cout << "Impossible" << endl;
    return 0;
  }
  int limit = *(area[1].begin());
  int ma = limit;
  int count = 1;
  while(limit < n){
    map<int,set<int,greater<int> > >::iterator it = area.begin();
    while((*it).first <= limit+1 && it != area.end()){
      ma = max(ma,*((*it).second.begin()));
      it++;
    }
    if(ma == limit){
      cout << "Impossible" << endl;
      return 0;
    }
    limit = ma;
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1208
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)
	fmt.Scan(&k)

	if e-a <= k {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long A = scan.nextLong();
		int B =(int)(scan.nextDouble()*100+0.05);

		long ans =(A * B) / 100;
		System.out.println(ans);
		scan.close();
	}

}


Measured memory_bytes: 36796
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
		int M = sc.nextInt();
		int[] s = new int[M];
		int[] c = new int[M];
		for(int i=0;i<M;i++){
			s[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		int minVal;
		if(N==1){
			minVal = 0;
		}else{
			minVal = (int)Math.pow(10,N-1);
		}
		for(int i=minVal;i<(int)Math.pow(10,N);i++){
			String tmp = String.valueOf(i);
			boolean exist = true;
			for(int j=0;j<M;j++){
				if(!tmp.substring(s[j]-1,s[j]).equals(String.valueOf(c[j]))){
					exist = false;
					break;
				}
			}
			if(exist){
				System.out.println(i);
				return;
			}
		}
		System.out.println("-1");
	}
}

Measured memory_bytes: 23892
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
    ll t;
    cin>>t;
    if(t>=30)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3560
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

static void C_GeTAC();


int main()
{
	C_GeTAC();

	fflush(stdout);
	return 0;
}


class QRange {
public:
	int left;
	int right;

	QRange() { left = right = 0; }
	~QRange() {}
};
static void C_GeTAC()
{
	static char szS[100004] = { 0 };
	static int tgCnt[100004] = { 0 };
	static QRange qrg[100004];
	int N, Q;

	scanf(" %d %d", &N, &Q);
	scanf(" %s", szS);

	for (int i = 0; i < Q; i++) {
		scanf(" %d %d", &(qrg[i].left), &(qrg[i].right));
	}

	for (int i = 0; i < N; i++) {
		if ((szS[i] == 'C') && (szS[i - 1] == 'A')) {
			tgCnt[i] = tgCnt[i - 1] + 1;
		}
		else {
			tgCnt[i] = tgCnt[i - 1];
		}
	}


	for (int i = 0; i < Q; i++) {
		int ans = tgCnt[qrg[i].right - 1] - tgCnt[qrg[i].left - 1];
		printf("%d\n", ans);
	}

}


Measured memory_bytes: 2048
#include <iostream>
using namespace std;
 
int main() {
 
  int b,r,g,c,s,t;
 
  while(1) {
 
    cin >> b >> r >>g >> c >> s >> t;
    if(b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0) break;
    
    int m = 100;
    m -= 3*t;
    int bornas = 5*b + 3*r;
    m += (b+r) * 15;
    
    for(int i=0;i<bornas;i++) m+=15;
     
    m +=7*g;
    m += 2*c;
 
    m += bornas + 3*s;
 
    cout << m << endl;
 
  }
 
  return 0;
}

Measured memory_bytes: 1160
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
lst=[0]*n
for i in range(n-1):
    lst[a[i]-1]+=1
# print(lst)
for i in range(n):
    print(lst[i])

Measured memory_bytes: 89684
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,W,H,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  N++;
  rep(i,0,N)if(i%3!=0&&i%5!=0)sum+=i;
  Out(sum);
}

Measured memory_bytes: 3648
N=input().split()
ans = 0
for i in range(4):
	if N[i] == '1':
		ans += 1
		break
for i in range(4):
	if N[i] == '9':
		ans += 1
		break
for i in range(4):
	if N[i] == '7':
		ans += 1
		break
for i in range(4):
	if N[i] == '4':
		ans += 1
		break
		
if ans == 4:
	print('YES')
else:
	print('NO')


Measured memory_bytes: 3064
#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>;

int main() {
  int c;
  string S;
  cin >> S;

  rep(i, 3) {
    if(S[i] == 'A') ++c;
  } 

  if(c == 3 || c == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
n = input()
for n in range(n):
    inputs = map(int,raw_input().split())
    if inputs[0]**2 == inputs[1]**2 + inputs[2]**2 or\
       inputs[1]**2 == inputs[0]**2 + inputs[2]**2 or\
       inputs[2]**2 == inputs[0]**2 + inputs[1]**2:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4220
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int xxxxx[] = new int[5];
	    for (int i = 0; i < 5; i++) {
	      xxxxx[i] = sc.nextInt();
	    }
	    
	    int count = 1;
	    for (int x : xxxxx) {
	      if (x == 0) {
	        System.out.println(count);
	      }
	      count++;
	    }
	    
	  }
}

Measured memory_bytes: 26968
#!/usr/bin/env python3
#aoj b
import re
from collections import deque

while 1:
    x = list(input())
    if x[0] == ".":
        break

    stack = deque()
    f = 1
    for i in range(len(x)):
        for j in range(len(x[i])):
            if x[i][j] == '(':
                stack.append('(')
            elif x[i][j] == '[':
                stack.append('[')
            elif x[i][j] == ')':
                if len(stack) == 0:
                    f = 0
                elif stack.pop() != '(':
                    f = 0
            elif x[i][j] == ']':
                if len(stack) == 0:
                    f = 0
                elif stack.pop() != '[':
                    f = 0
    if len(stack) != 0:
        f = 0
    if f:
        print('yes')
    else:
        print('no')



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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int cnt[2][2000][2000], cntx[2][2][2000];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, K, K2, ans = 0;
	for (cin >> N >> K, K2 = K << 1; N; N--) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		cnt[c == 'W'][x % K2][y % K2]++;
		cntx[c == 'W'][x % K2 >= K][y % K2]++;
	}
	for (int i = 0; i < K2; i++) {
		int sum = 0;
		for (int j = 0; j < K2; j++) {
			sum += cntx[j < K][1][j] + cntx[j >= K][0][j];
		}
		ans = max(ans, sum);
		for (int j = 0; j < K2; j++) {
			sum += cntx[0][1][j] + cntx[1][0][j] - cntx[0][0][j] - cntx[1][1][j]
				+ cntx[0][0][(j + K) % K2] + cntx[1][1][(j + K) % K2] - cntx[0][1][(j + K) % K2] - cntx[1][0][(j + K) % K2];
			ans = max(ans, sum);
		}
		for (int j = 0; j < K2; j++) {
			cntx[0][0][j] += cnt[0][(i + K) % K2][j] - cnt[0][i][j];
			cntx[0][1][j] += cnt[0][i][j] - cnt[0][(i + K) % K2][j];
			cntx[1][0][j] += cnt[1][(i + K) % K2][j] - cnt[1][i][j];
			cntx[1][1][j] += cnt[1][i][j] - cnt[1][(i + K) % K2][j];
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;
    vec A(N+2);
    A[0] = 300;
    Rep (i, N) {
        cin >> A[i+1];
    }
    A[N+1] = 30;

    vec b;
    ll money = 1000, stock = 0;
    for (ll i = 1; i <= N; i++) {
        if (stock == 0 and A[i] < A[i+1]) {
            ll num = money / A[i];
            money -= num * A[i];
            stock += num;
            // cout << "buy :" << i << "\n";
        } else if (stock > 0 and A[i] > A[i+1]) {
            money += stock * A[i];
            stock = 0;
            // cout << "sell:" << i << "\n";
        }
    }

    cout << money << endl;
}

Measured memory_bytes: 3576
import sys
input = sys.stdin.readline
from collections import deque

def solve():
  n,k = (int(i) for i in input().split())
  v = list(int(i) for i in input().split())
  ans = 0
  
  for atimes in range(min(n,k+1)):
    for btimes in range(min(n-atimes+1,k-atimes+1)):
      if [atimes,btimes] == [0,0]:continue
      
      getjewel = v[0:atimes]+v[n-btimes::]
      
      getjewel.sort()
      deletevalue = 0
      maxdeletetimes = k-atimes-btimes
      #print(getjewel,maxdeletetimes)
      for i in range(min(len(getjewel),maxdeletetimes)):
        if getjewel[i] <= 0:
          deletevalue -= getjewel[i]
      ans = max(sum(getjewel)+deletevalue,ans)
  print(ans)
solve()

Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int):
    def f(x: int, k: int):
        if x < k:
            return 1
        
        return 1+f(x//k, k)

    print(f(N, K))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

int main() {

	int a;
	cin >> a;

	int ans = 0;
	for(int i=1;i<=a;i++) {
		if (to_string(i).length() % 2 == 1)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,b,i,x[1001];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		a=0; b=0;
		scanf("%d %d",&a,&b);
		if(a%b!=0) x[i]=a%b;
		else x[i]=b;
	}
	for(i=0;i<n;i++) printf("%d\n",x[i]);
	return 0;
}	

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

typedef long long ll;

string solve(int n, ll a, ll b, ll c, ll d){
  for(int i = 0;i < n-1;i++){
    ll l = a + i * c - (n-i-1) * d; // minimum possible
    ll r = a + i * d - (n-i-1) * c; // maximum possible
    if (l > r)swap(l , r);
    if (l <= b && b <= r)return "YES";
  }
  return "NO";
}

int main(){
  int n;
  ll a, b, c, d;
  cin >> n >> a>> b >> c>> d;
  cout << solve(n, a, b, c, d) << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 * I won't be broken
 * I won't be tortured
 * I won't be beaten down
 * I have the answer
 * I can take the pressure
 * I will turn it all around
 * Lift me up above this
 * The flames and the ashes
 * Lift me up and help me to fly away
*/
#include <bits/stdc++.h>
using namespace std;
int k,arr[100005];
int main(){
        scanf("%d",&k);
        for(int i = 0; i<k; i++)
                scanf("%d",&arr[i]);
        long long minn = 2,mx =2;
        if(arr[k-1]!=2)
                printf("-1\n");
        else{
                for(int i = k-1; i>=0; i--){
                        long long L = (minn+arr[i]-1)/arr[i], R = (mx/arr[i]);
                        if(L>R){
                                printf("-1\n");
                                return 0;
                        }
                        minn = L*arr[i],mx = (R+1)*arr[i]-1;
                }
                printf("%lld %lld\n",minn,mx);
        }
        return 0;
}


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

int main() {
  int m, f, r;
  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1) {
      cout << "F";
    } else if (m + f >= 80) {
      cout << "A";
    } else if (m + f >= 65) {
      cout << "B";
    } else if (m + f >= 50) {
      cout << "C";
    } else if (m + f >= 30) {
      if (r >= 50) {
        cout << "C";
      } else {
        cout << "D";
      }
    } else {
      cout << "F";
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int H, W, i, j, k, l;
  cin >> H >> W;
  string m[H];
  
  for(i=0; i<H; i++)
    cin >> m[i];
  
  for(i=0; i<H; i++)
    for(j=0; j<W; j++) {
      if(m[i].at(j) == '.') {
        int bomb = 0;
        for(k=i-1; k<=i+1; k++)
          for(l=j-1; l<=j+1; l++)
            if(k>=0 && k<H && l>=0 && l<W && m[k].at(l) == '#')
              bomb++;
        m[i].at(j) = char(bomb + '0');
      }
    }
  
  for(i=0; i<H; i++)
    cout << m[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
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); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  int H,W;  cin>>H>>W;
  string s[H];
  rep(i,0,H) cin>>s[i];
  int d[100][100];
  rep(i,0,H)rep(j,0,W) d[i][j] = 0;
  rep(i,0,H)rep(j,0,W){
      if(s[i][j] == '#'){
        rep(k,-1,2)rep(z,-1,2){
            int nx = i+k, ny = j+z;
            if(nx<0 || ny<0 || nx>=H || ny>=W) continue;
            d[nx][ny]++;
        }
      }
  }
  rep(i,0,H){
      rep(j,0,W){
          if(s[i][j]=='#') cout<<'#';
          else{
              cout<<d[i][j];
          }
      }
      cout<<endl;
  }
  return 0;
}   

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


//vector<vector<int>> z(n,vector<int>(2));
//n番目から数えてm個の文字列をXに置換したい場合はreplace(n,m,X) teWttest
//s1.substr(3,3);
//n番目以降の文字列をm個取り出す、上だとtte

int main(){
  ll n;
  cin>>n;
  vector<ll> p(n);
  rep(i,n)cin>>p[i];
  rep(i,n)p[i]--;
  vector<ll> idx(n);
  rep(i,n) idx[p[i]]=i;
  ll ans=0;
  set<int>s;
  for(int i=n-1;i>=0;i--){
    s.insert(idx[i]);
    auto it=s.find(idx[i]);
    vector<int> l(2,-1);
    vector<int>r(2,n);
    vector<int> l1(2),r1(2);
    rep(j,2){
      if (it==s.begin())break;
      it--;
      l[j]=*it;
  //    cout<<l[j]<<'l'<<i<<endl;
    }
    it=s.find(idx[i]);
    rep(j,2){
      it++;
      if (it==s.end())break;
      r[j]=*it;
  //      cout<<r[j]<<'r'<<i<<endl;
    }
    l1[0]=idx[i]-l[0];
    l1[1]=l[0]-l[1];
    r1[0]=r[0]-idx[i];
    r1[1]=r[1]-r[0];
    ans+=ll(l1[0]*r1[1]+l1[1]*r1[0])*ll(i+1);
  //  cout<<(l1[0]*r1[1]+l1[1]*r1[0])<<endl;
  }
  cout<<ans;




  }


Measured memory_bytes: 6528
N = gets.chomp.to_i
ans = 0
odd = Array.new
(1..N).each do |i|
  odd << i if i.odd?
end
odd.each do |i|
  count = 0
  (1..i).each do |j|
    count += 1 if i % j == 0
  end
  ans += 1 if count == 8
end
puts ans


Measured memory_bytes: 1788
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int[3][3] c;
  foreach (i; 0..3) {
    c[i] = readln.chomp.split.to!(int[]);
  }

  auto h1 = c[0][0] - c[0][1];
  auto h2 = c[0][0] - c[0][2];
  auto h3 = c[0][1] - c[0][2];
  auto v1 = c[0][0] - c[1][0];
  auto v2 = c[0][0] - c[2][0];
  auto v3 = c[1][0] - c[2][0]; 
  bool f;
  foreach (i; 1..3) {
    if (h1 != c[i][0] - c[i][1]) {
      f = true;
    }
    if (h2 != c[i][0] - c[i][2]) {
      f = true;
    }
    if (h3 != c[i][1] - c[i][2]) {
      f = true;
    }
    if (v1 != c[0][i] - c[1][i]) {
      f = true;
    }
    if (v2 != c[0][i] - c[2][i]) {
      f = true;
    }
    if (v3 != c[1][i] - c[2][i]) {
      f = true;
    }
  }
  if (f) {
    writeln("No");
  } else {
    writeln("Yes");
  }
}


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

using namespace std;

int main(void) {
    int64_t N, A , B;
    cin >> N >> A >> B;
    if((A-B)%2) {
        cout << min((B+A)/2, N - (A+B)/2) << endl;
    } else {
        cout << (B-A)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b;
	cin>>a>>b;
	if(a<=b){
		cout<<a<<endl;
	}
	else{
		cout<<a-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
#l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans=''
while(n>0):
    n=n-1
    ans=ans+chr(ord('a')+n%26)
    n=n//26
print(ans[::-1])
    


Measured memory_bytes: 61596
#include<iostream>
using namespace std;
long long DP[110][100100],W[110],V[110];
int main()
{
  long long N,K;
  cin>>N>>K;
  for(int i=0;i<110;i++)
    for(int j=0;j<100100;j++)
      DP[i][j]=999999999999999999;
  for(int i=0;i<N;i++)
    cin>>W[i]>>V[i];
  DP[0][0]=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<100100;j++)
      if(DP[i][j]!=999999999999999999)
        DP[i+1][j]=min(DP[i+1][j],DP[i][j]),
  		DP[i+1][j+V[i]]=min(DP[i+1][j+V[i]],DP[i][j]+W[i]);
  for(int i=100099;i>=0;i--)
    if(DP[N][i]<=K)
    {
      cout<<i<<endl;
      return 0;
    }
}

Measured memory_bytes: 86272
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		
		int b = (int)Math.pow(a, 2);
		int c = (int)Math.pow(a, 3);
		
		System.out.println(a+b+c);
	}
}
 


Measured memory_bytes: 35784
#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>;

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

    constexpr mint inv() const {
        return pow(mod - 2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
};
ostream& operator<<(ostream & os, const mint & m) {
    os << m.x;
    return os;
}

mint comb(ll n, ll r)
{
    mint res = 1;
    for (int i = 1; i <= r; i++)
    {
        res *= n;
        res /= i;
        n--;
    }
    return res;
}

int main()
{
    int n, a, b; cin >> n >> a >> b;
    cout << mint(2).pow(n) - comb(n, a) - comb(n, b) - 1 << endl;
}


Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
    print('NO')
else:
    if -1 < ((b - a) / (v - w)) < 1:
        print('NO')
    elif 1 <= (abs(b - a) / (v - w)) <= t:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9092
#include <iostream>

typedef long long ll;

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

	ll a[ 86 ];
	a[ 0 ] = 2;
	a[ 1 ] = 1;
	for( int i = 2; i <= n; i++ ) {
		a[ i ] = a[ i - 1 ] + a[ i - 2 ];
	}

	std::cout << a[ n ] << std::endl;
	return 0;
}



Measured memory_bytes: 256
class Node
  def initialize(val)
    @val = val
    @left = nil
    @right = nil
  end
  def insert(val)
    if val < @val
      if @left
        @left.insert(val)
      else
        @left = Node.new(val)
      end
    else
      if @right
        @right.insert(val)
      else
        @right = Node.new(val)
      end
    end
  end
  def print
    puts " #{inorder([]).join(" ")}"
    puts " #{preorder([]).join(" ")}"
  end
  def preorder(list)
    #root
    list << @val
    #left
    list = @left.preorder(list) if @left
    #right
    list = @right.preorder(list) if @right
    return list
  end
  def inorder(list)
    #left
    list = @left.inorder(list) if @left
    #root
    list << @val
    #right
    list = @right.inorder(list) if @right
    return list
  end
  def find(num)
    if @val == num then
      return "yes"
    elsif @val > num
      if @left
        return @left.find(num)
      else
        return "no"
      end
    else
      if @right
        return @right.find(num)
      else
        return "no"
      end
    end
  end
  def del(num)
    if @val == num then
      # delete
      if @left && @right then
        @val = @right.next_val
        @right = @right.del(@val)
        return self
      elsif @left != nil && @right == nil then
        return @left
      elsif @left == nil && @right != nil then
        return @right
      else
        return nil
      end
    elsif @val > num
      @left = @left.del(num) if @left
      return self
    else
      @right = @right.del(num) if @right
      return self
    end
  end
  def next_val
    if @left
      return @left.next_val
    else
      return @val
    end
  end
end

n = gets.to_i
tree = nil

n.times{
  command, num = gets.split
  case command;
  when "insert";
    if tree
      tree.insert(num.to_i)
    else
      tree = Node.new(num.to_i)
    end
  when "find";
    puts tree.find(num.to_i)
  when "delete";
    tree = tree.del(num.to_i)
  when "print";
    tree.print
  end
}

Measured memory_bytes: 67032
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right,insort_left,insort_right
from heapq import heapify,heappop,heappush
from copy import deepcopy
from itertools import accumulate,groupby,permutations,combinations
from math import ceil,sqrt,cos,sin,pi,gcd

N = int(input())
A = [int(i) - 1 for i in input().split()]

cnt = [0] * N

for a in A:
    cnt[a] += 1

print(*cnt, sep="\n")

Measured memory_bytes: 33688
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> k(m);
    int s[11][11] = {};
    rep(i, m)
    {
        cin >> k[i];
        rep(j, k[i])
        {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    rep(i, (1 << n))
    {
        bool f = true;
        rep(j, m)
        {
            int cnt = 0;
            rep(l, k[j]) if (i & (1 << s[j][l])) cnt++;
            if ((cnt % 2) != p[j])
                f = false;
        }
        if (f)
            ans++;
    }
    cout << ans << endl;
}

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

int main() {
  string s;
  int n;
  cin >> s >> n;
  for(int i = 0;i < n;i++){
    string p;
    int a,b;
    cin >> p >> a >> b;
    if(p == "print"){
      cout << s.substr(a,b-a+1) << endl;
    }
    if(p == "reverse"){
      string ss = s.substr(a,b-a+1);
      reverse(ss.begin(),ss.end());
      s.replace(a,b-a+1,ss);
    }
    if(p == "replace"){
      string ss;
      cin >> ss;
      s.replace(a,b-a+1,ss);
    }
  }
}



Measured memory_bytes: 3216
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

priority_queue<int, vi, greater<int>> ql;
priority_queue<int, vi> qr;
vvll memo;
vll a;
int n;

void init()
{
	cin >> n;
	a.resize(3 * n);
	REP(i, 3 * n)
		cin >> a[i];

	memo.resize(2, vll(3 * n, 0));
}

int main()
{
	init();

	int i = 0;
	ll curl = 0;

	for (; i < n; ++i)
	{
		ql.push(a[i]);
		curl += a[i];
	}
	
	for (; i < 2 * n; i++)
	{
		memo[0][i] = curl;

		if (a[i] > ql.top())
		{
			curl += a[i] - ql.top();
			ql.pop();
			ql.push(a[i]);
		}
	}
	memo[0][i] = curl;

	ll curr = 0;
	i = 3 * n - 1;
	for (; i >= 2 * n; --i)
	{
		qr.push(a[i]);
		curr += a[i];
	}
	for (; i >= n; --i)
	{
		memo[1][i + 1] = curr;

		if (a[i] < qr.top())
		{
			curr += a[i] - qr.top();
			qr.pop();
			qr.push(a[i]);
		}

		//cout << curr << endl;
	}
	memo[1][i + 1] = curr;


	//REP(i, 3 * n)
	//	cout << memo[0][i] << " ";
	//cout << endl;
	//REP(i, 3 * n)
	//	cout << memo[1][i] << " ";
	//cout << endl;

	ll ans = -LLMAX;

	for (i = n; i <= 2 * n; i++)
	{
		chmax(ans, memo[0][i] - memo[1][i]);
	}

	cout << ans << endl;

}


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


int n,k;
int h[100005];
int dp[100005];

void func(){

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i]=abs(h[i]-h[i-1])+dp[i-1];
        for(int j=2;j<=k;j++){
          if(i-j<0){
            break;
          }
          int y=abs(h[i]-h[i-j])+dp[i-j];
          dp[i]=min(dp[i],y);
       }
    }
    cout<<dp[n-1]<<endl;
}


int main(){



   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
   #endif
   cin>>n>>k;
   for(int i=0;i<n;i++){
      cin>>h[i];
   }
   func();
}

Measured memory_bytes: 4260
import sys

def main(lines):
  N, M, X, Y = map(int, lines[0].split()) 
  x = list(map(int, lines[1].split()))
  y = list(map(int, lines[2].split()))
  x.sort()
  y.sort()
  flag = 0
  for i in range(X + 1, Y + 1):
    if x[N - 1] < i and i <= y[0]:
      flag = 1
  if flag:
    print("No War")
  else:
    print("War")


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define    ll   long long int
#define    sz   200010

using namespace std;


int main()
{
    ll n,j,a,c=0,k,i;


    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if(a>=k)c++;
    }

    cout<<c<<endl;


    return 0;
}


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

int main() {
    int N;
    cin >> N;
    ld a[N], ans = 0;
    for (auto &x : a) cin >> x;
    vector<pair<ld, int>> tmp;
    for (int i = 0; i < N; i++) {
        tmp.push_back(make_pair(a[i], i));
    }
    sort(tmp.begin(), tmp.end());
    vector<int> index;
    for (int i = N - 4; i < N; i++) {
        index.push_back(tmp[i].second);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            ld C = a[i];
            ld D = a[j];
            vector<int> MAX;
            for (int k = 3; 0 <= k && MAX.size() != 2; k--) {
                if (index[k] != i && index[k] != j) {
                    MAX.push_back(index[k]);
                }
            }
            ans = max(ans, (a[MAX[0]] + a[MAX[1]]) / (C - D));
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[1001],b[1001],c[10001];
bool used[1001];
int main(){
    int n;
    cin>>n;
    int mn=10001;
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
        mn=min(mn,a[i]);
    }
    sort(b,b+n);
    rep(i,n) c[b[i]]=i;
    ll ans=0;
    rep(i,n){
        if(used[i]) continue;
        ll sum=0;
        int mm=10001,cur=i,cnt=0;
        while(!used[cur]){
            used[cur]=true;
            mm=min(mm,a[cur]);
            sum+=a[cur];
            cur=c[a[cur]];++cnt;
        }
        ans+=min(sum+(cnt-2)*mm,mm+sum+(cnt+1)*mn);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int H, W;
string S[30];
int dist[30][30];

typedef pair<int, int> P;

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

void init()
{
    rep(i, 0, 29)
    {
        rep(j, 0, 29)
        {
            if (dist[i][j] != -1)
            {
                dist[i][j] = 0;
            }
        }
    }
}

bool dfs(int h, int w)
{
    if (dist[h][w] == -1)
    {
        return false;
    }
    queue<P> que;
    que.push(P(h, w));
    dist[h][w] = 0;
    init();

    while (que.size())
    {
        P p = que.front();
        que.pop();

        for (int i = 0; i < 4; i++)
        {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];

            if (dist[nx][ny] == 0)
            {
                if (nx == h && ny == w)
                {
                    continue;
                }
                que.push(P(nx, ny));
                dist[nx][ny] = dist[p.first][p.second] + 1;
            }
        }
    }

    return true;
}

int max_dist()
{
    int res = 0;
    repe(i, 1, H)
    {
        repe(j, 1, W)
        {
            res = max(res, dist[i][j]);
        }
    }
    return res;
}

int main()
{
    cin >> H >> W;
    repe(i, 1, W)
    {
        dist[0][i] = -1;
        dist[H + 1][i] = -1;
    }
    repe(i, 1, H)
    {
        dist[i][0] = -1;
        dist[i][W + 1] = -1;
    }
    repe(i, 1, H)
    {
        cin >> S[i];
        rep(j, 0, W)
        {
            if (S[i][j] == '#')
            {
                dist[i][j + 1] = -1;
            }
            else
            {
                dist[i][j + 1] = 0;
            }
        }
    }

    int ans = 0;
    repe(i, 1, H)
    {
        repe(j, 1, W)
        {
            bool res = dfs(i, j);
            if (res == false)
            {
                continue;
            }
            ans = max(ans, max_dist());
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2);
  return x*POW(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  if(q*4<s)s=q*4;
  if(q*8<d)d=q*8;
  if(h*2<s)s=h*2;
  if(h*4<d)d=h*4;
  printf("%lld",min(n/2*d+n%2*s,n*s));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int K;
    cin >> K;
    
    if(K%2==0){
        cout << (K/2)*(K/2) << endl;
    }else{
        cout << (K/2+1)*(K/2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    char s[h][w];
    int ans[h][w];
    int now = 0;
    rep(i,0,h-1){
        rep(j,0,w-1){
            cin >> s[i][j];
        }
    }
    rep(i,0,h-1){
        now++;
        int flg=0;
        int row = 0;
        rep(j,0,w-1){

            if(s[i][j]=='#'){
                if(row>0)now++;
                row++;
            }
            ans[i][j] = now;
        }
        if(row==0 && now == 1){
            rep(j,0,w-1){
                ans[i][j] = 0;
            }
            flg=1;
        }
        if(row==0 && now != 1){
            rep(j,0,w-1){
                ans[i][j] = ans[i-1][j];
                
            }
            flg=1;
        }
        if(flg)--now;
    }
    drep(i,h-1,0){
        rep(j,0,w-1){
            if(ans[i][j]==0){
                ans[i][j] = ans[i+1][j];
            }
        }
    }
    rep(i,0,h-1){
        rep(j,0,w-1){
            cout << ans[i][j];
            if(j==w-1)cout << endl;
            else cout << " ";
        }
    }

    //cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}

const int MOD = 998244353, INF = 2E9 + 10, MAXN = 2E5 + 100, MAX = 1E6;
int n, dp[MAXN], p[MAXN], far[MAXN];
const int K = 25;
pi st[MAX][K];
int lg[MAX + 10];
vpi v;
vi vv;

int solve(int i) {
	//error(i);
	if(i == n)
		return 1;
	if(dp[i])
		return dp[i];
	int res = 0;
	res = solve(i + 1);
	int d = v[i].fs + v[i].sd;
	int j = far[i];
	int jj = i + 1;
	while(vv[jj] < d) {
		d = max(d, v[jj].fs + v[jj].sd);
		jj++;
	}
	//error(jj, j);
	res = (res + solve(j))%MOD;
	return dp[i] = res;
}

int main() {
	cin >> n;
		for(int i =0; i < n; i++) {
		int x, d;
		cin >> x >> d;
		v.pb({x,d});
	}
	sort(all(v));
	v.pb({INF,0});
	for(int i = 0; i <= n; i++) {
		vv.pb(v[i].fs);
		if(i != n)
			st[i][0] = {v[i].fs + v[i].sd, i};
	}
		lg[1] = 0;
	for(int i = 2; i < MAX + 1; i++)
		lg[i] = lg[i/2] + 1;
	
			for(int j = 1; j < K; j++) {	
				for(int i = 0; i < n; i++) {
			if(i + (1 << j) - 1 > n - 1)
				break;
		//	error(i,j);
			if(st[i][j - 1].fs >= st[i + (1 << (j - 1))][j - 1].fs)
				st[i][j] = st[i][j - 1];
			else
				st[i][j] = st[i + (1 << (j - 1))][j - 1];
			// st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
			//st2[i][j] = __gcd(st[i][j - 1],  st[i + (1 << (j - 1))][j - 1]);
		}
	}
	for(int i = n - 1; i >= 0; i--) {
		int j = lower_bound(all(vv), v[i].fs + v[i].sd) - vv.begin();
		j--;
		int k = lg[j - i + 1];
		//error(i, j, k);
		if(st[i][k].fs >= st[j - (1 << k) + 1][k].fs)
			j = st[i][k].sd;
		else
			j = st[j - (1 << k) + 1][k].sd;
		//error(i, j);
		if(i == j) {
			j = lower_bound(all(vv), v[i].fs + v[i].sd) - vv.begin();
			far[i] = j;
		}
		else
			far[i] = far[j];
		//error(i, far[i]);
	}
	cout << solve(0);
}

Measured memory_bytes: 55664
#include<stdio.h>

void trace( int *A, int n )
{
	int i=0;
	while( i<n ) {
		printf( "%d", A[i++] );
		if( i != n ) { printf( " " ); }
	}
	printf( "\n" );
	
	return;
}

void insertionSort( int *A, int n )
{
	int i,j;
	int key;
	
  	for( i=1; i<n; i++ ) {
  		key = A[i];
  		j = i-1;
  		while( 0<=j && key<A[j] ) {
  			A[j+1] = A[j];
  			j--;
  		}
  		A[j+1] = key;
  		trace( A, n );
   	}
  
	return;
}

int main( void ) 
{
	int n;
	int A[101];
	int i;
	
	scanf( "%d", &n );
	for( i=0;  i<n; i++ ) {
		scanf( "%d", &A[i] );
    }
    trace( A, n );
    insertionSort( A, n );

	return 0;
}

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

int main() {
  int n, c, k; cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, n){cin >> t.at(i);}

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

  int ans = 0;

  int i = 0;
  while (i < n)
  {
    int theFirst = t.at(i) + k;

    int okHuman = 1;
    for (int j = i+1; j < n; j++)
    {
      if(okHuman >= c || t.at(j) > theFirst){
        break;
      } else {
        okHuman++;
      }
    }
    ans++;
    i += okHuman;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  i64 K;
  std::cin >> S >> K;

  if (S.front() != S.back()) {
    std::vector<i64> combos;
    for (auto it = S.begin(), prev_it = S.end(); it != S.end(); prev_it = it, ++it) {
      if (prev_it == S.end() || *it != *prev_it) {
        combos.push_back(0);
      }
      ++combos.back();
    }
    std::cout << std::accumulate(combos.begin(), combos.end(), static_cast<i64>(0), [](const i64& sum, const i64& combo) {
      return sum + combo / 2;
    }) * K << std::endl;
  } else {
    if (std::all_of(S.begin(), S.end(), [&S](const char& S_i) { return S_i == S.front(); })) {
      std::cout << static_cast<i64>(S.size()) * K / 2 << std::endl;
    } else {
      std::vector<i64> combos;
      for (auto it = S.begin(), prev_it = S.end(); it != S.end(); prev_it = it, ++it) {
        if (prev_it == S.end() || *it != *prev_it) {
          combos.push_back(0);
        }
        ++combos.back();
      }
      const i64 first_combo = combos.front();
      const i64 last_combo = combos.back();
      combos.erase(combos.begin());
      combos.pop_back();
      std::cout << std::accumulate(combos.begin(), combos.end(), static_cast<i64>(0), [](const i64& sum, const i64& combo) {
        return sum + combo / 2;
      }) * K + (first_combo + last_combo) / 2 * (K - 1) + first_combo / 2 + last_combo / 2 << std::endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] str = line.split(" ");
        double x1 = Double.parseDouble(str[0]);
        double y1 = Double.parseDouble(str[1]);
        double x2 = Double.parseDouble(str[2]);
        double y2 = Double.parseDouble(str[3]);
        double a = x2 - x1;
        double b = y2 - y1;
        if(Math.signum(a) < -1) {
            a = -a;
        }
        if(Math.signum(b) < -1) {
            b = -b;
        }
        double ans = (double)Math.sqrt(Math.pow((a), 2) + Math.pow((b), 2));
        System.out.println(String.format("%.6f", ans));
    
    }
 }


Measured memory_bytes: 26568
n, W = map(int, input().split())
w = []
v = []
for _ in range(n):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)

# dp[i+1][j]=i番目までの品物から重さの総和がj以下となるように選んだ時の価値の総和の最大値
dp = [[0 for j in range(W+1)] for i in range(n+1)]
for i in range(n):
    for j in range(W+1):
    # ナップザックの容量をjと仮定する
        # とi番目の品物を持てないとき
        if j < w[i]:
            # i番目の品物をスルーする
            dp[i + 1][j] = dp[i][j]
        # i番目の品物を持とうと思えば持てるとき
        else:
            # 1.i番目の品物を持たなかった場合
            # 2.i番目の品物を持った場合
            # 以上2通りの内、価値の総和が最大となる品物の選び方をする
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
print(dp[n][W])


# イメージはこんな感じ
# 入力が
# n = 4
# W = 5
# (w, v) = ((2, 3), (1, 2), (3, 4), (2, 2))
# となるとき
# → はナップザックに入ってる品物の重さ(j <= W)の総和
# ↓ はi(i <= n)番目までの品物を順に確認
# (i+1, j)は最初の品物を0番目として数えたときの、
# i番目までの品物から重さの総和がj以下となるように選んだ時の価値の総和の最大値
# i\j  0   1   2   3   4   5
#
#  0   0   0   0   0   0   0
#
#  1   0   0   3   3   3   3
#
#  2   0   2   3   5   5   5
#
#  3   0   2   3   5   6   7
#
#  4   0   2   3   5   6   7

Measured memory_bytes: 171656