akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int H,W,sharp=0;
  int dx[] = {0,0,1,-1};
  int dy[] = {1,-1,0,0};
  cin >> H >> W;
  char s[H+2][W+2];
  int bfs[H+2][W+2];
  FOR(i,0,H+2)FOR(j,0,W+2){
    s[i][j] = '#';
    bfs[i][j] = -1;
  }
  FOR(i,1,H+1)FOR(j,1,W+1){
    cin >> s[i][j];
    if(s[i][j] == '#')sharp++;
  }
  queue<pair<int,int>> que;
  que.push(make_pair(1,1));
  bfs[1][1] = 0;
  while(que.size()){
    FOR(i,0,4){
      int x = que.front().first + dx[i];
      int y = que.front().second + dy[i];
      if(s[x][y] == '.' && bfs[x][y] == -1){
        que.push(make_pair(x,y));
        bfs[x][y] = 1+bfs[x-dx[i]][y-dy[i]];
      }
    }
    que.pop();
  }
  if(bfs[H][W] == -1)cout << -1 << endl;
  else cout << H*W - sharp - bfs[H][W] - 1 << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private static HashMap<Integer, Integer> fibs = new HashMap<>();

    public static void main(String[] args) {
        fibs.put(0, 1);
        fibs.put(1, 1);
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(fibonacci(n));
        in.close();
    }

    private static int fibonacci(int n) {
        if (!fibs.containsKey(n)) {
            fibs.put(n, fibonacci(n-1) + fibonacci(n-2));
        }
        return fibs.get(n);
    }
}



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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;
int num;

NodePointer listSearch(int key){
  /* your code */
  NodePointer n;
  for(n = nil->next; n != nil;n = n->next){
    if(n->key == key)return n;
  }
  return nil;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /*your code*/
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t = nil->prev;
   if ( t == nil ) return;
 deleteNode(t);
 }

void delete(int key){
  /* your code */
  NodePointer d;
  if((d = listSearch(key)) != nil){
    d->prev->next = d->next;
    d->next->prev = d->prev;
    free(d);
  }
  return;
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
/* your code */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.math.*;

public class Main {

    private static Scanner sc;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

    private void solve() {
        try {
            long a;
            a = sc.nextLong();

            String b = sc.next();
            if(b.contains(".")) b= b.substring(0,1)+b.substring(2);
            
            long i = Integer.parseInt(b);
            long result = a * i;
            for(int k=0;k<b.length()-1;k++){
                            result/=10;
            }
            System.out.println(result);
        } catch (

        final Exception e) {
            e.printStackTrace();
        }
    }
}


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

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

  if (S[0] == 'S') ans = "Cloudy";
  if (S[0] == 'C') ans = "Rainy";
  if (S[0] == 'R') ans = "Sunny";

  cout << ans << endl;

  return 0;
}

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

const long long INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    string S;
    cin >> S;
    int type_num = 4;
    int dup_num[4];
    for (int i = 0; i < 4; i++) {
        dup_num[i] = 0;
    } 

    for (int i = 0; i < 4; i++) {
        if (dup_num[i] == 0) {
            for (int j = i + 1; j < 4; j++) {
                if (S[i] == S[j]) {
                    type_num--;
                    dup_num[j] = 1;
                }
            }
        }   
    }

    if(type_num == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

for count in range(k):
    range_diff = [0] * n
    for pos in range(n):
        candidate_min = pos - a[pos]
        candidate_max = pos + a[pos] + 1
        if pos - a[pos] >= 0:
            min = pos - a[pos]
        else:
            min = 0
        range_diff[min] += 1
        if candidate_max <= n-1:
            range_diff[candidate_max] -= 1
    for i in range(1, n):
        range_diff[i] += range_diff[i-1]
    a = range_diff
    if count >= 43:
        break

print(' '.join(list(map(str,a))))

Measured memory_bytes: 166568
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        k: usize,
    }
    if k % 2 == 0 || k % 5 == 0 {
        println!("-1")
    } else {
        let mut n = 0;
        let mut c = 0;
        loop {
            n = (n * 10 + 7) % k;
            c += 1;
            if n == 0 {
                println!("{}", c);
                break;
            }
        }
    }
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<setprecision(6); cout<<fixed;
  #ifdef DEBUG
  freopen("ip.txt","r",stdin);
  clock_t tStart = clock();
  #endif

  int n; cin>>n; int f[n][10],p[n][11],max=1<<31;
  for(int i=0;i<n;++i)  for(int j=0;j<10;++j) cin>>f[i][j];
  for(int i=0;i<n;++i)  for(int j=0;j<=10;++j) cin>>p[i][j];

  for(int k=1;k<1024;++k){
    bool open[10]; memset(open,false,sizeof(open)); int u=k;
    for(int i=0;i<10 && u;++i,u>>=1) if(u&1) open[9-i]=true;
    int shop[n]; memset(shop,0,sizeof(shop));
    for(int i=0;i<10;++i){
      for(int j=0;j<n;++j){
        if(open[i] && f[j][i]) shop[j]++;
      }
    }
    int sum=0;
    for(int i=0;i<n;++i)  sum+=p[i][shop[i]];
    if(sum>max) max=sum;
  }
  cout<<max<<'\n';


  #ifdef DEBUG
	cout<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)<<"s.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <valarray>
#include <iterator>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <list>
#include <map>
#include <strstream>
#include <streambuf>
#include <string>
#include <sstream>
//#include "graph.cpp"

#define vi vector<int>
#define vii vector< pair<int,int> >
#define last(arr) arr.size()-a
#define loop(i,n) for(ll i=0 ; i<n ; ++i)
#define all(v) ((v).begin()),((v).end())
#define pb push_back
#define ll long long
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace std;
ll arr[100005];
ll n;
ll valid(ll x){
    loop(i,n){
        x=(x/arr[i])*arr[i];
    }
    return x;
}
int main(){
    cin>>n;
    loop(i,n){
        cin>>arr[i];
    }
    ll st=2,en=(ll)1e18,mid=(st+en)/2;
    ll minimum=en;
    bool is_in=false;
    loop(i,65){
        mid=(st+en)/2;
        if(valid(mid) == 0){
            st=mid+1;
        }else if(valid(mid) == 2){
            en=mid;
            minimum=min(mid,minimum);
            is_in=true;
        }else{
            en=mid;
        }
    }
    st=2,en=(ll)1e18,mid=(st+en)/2;
    ll maximum=-1;
    loop(i,65){
        mid=(st+en)/2;
        if(valid(mid) == 0){
            st=mid+1;
        }else if(valid(mid) == 2){
            st=mid+1;
            maximum=max(mid,maximum);
            is_in=true;
        }else{
            en=mid;
        }
    }
    if(is_in){
        cout<<minimum<<" "<<maximum<<endl;
    }else{
        cout<<-1<<endl;
    }
}



Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

ans = 1
up = False
down = False
for i in range(1, n):
    if up:
        if a[i] < a[i - 1]:
            up = False
            ans += 1
    elif down:
        if a[i] > a[i - 1]:
            down = False
            ans += 1
    else:
        if a[i] > a[i - 1]:
            up = True
        elif a[i] < a[i - 1]:
            down = True
print(ans)

Measured memory_bytes: 14228
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K,N = map(int,readline().split())
A = list(map(int,readline().split()))
A = sorted(A)
A.append(A[0]+K)
max_dist = 0
ans = 0
for i in range(N):
    dist = A[i+1] - A[i]
    max_dist = max(max_dist,dist)
    ans += dist
print(ans-max_dist)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  for(int i=0;i<=30;i++){
    for(int j=0;j<=30;j++){
      int t = i*4+j*7;
      if(t==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }

  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void) {
	//連結性判定300マ?
	llint i,j,x,y,H,W,ans=0;cin>>H>>W;
	vector<string>S(H);
	for(i=0;i<H;i++){cin>>S[i];}
	vector<vector<bool>>kta(H,vector<bool>(W));
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(kta[i][j]){continue;}
			queue<pair<int,int>>que;
			que.push(mp(i,j));
			llint ki=0,gu=0;
			
			while(que.size()){
				int y,x;tie(y,x)=que.front();que.pop();
				if(kta[y][x]){continue;}
				kta[y][x]=1;
				if((y+x)%2==0){gu++;}else{ki++;}
				if(x>0&&S[y][x-1]!=S[y][x]){que.push(mp(y,x-1));}
				if(x<W-1&&S[y][x+1]!=S[y][x]){que.push(mp(y,x+1));}
				if(y>0&&S[y-1][x]!=S[y][x]){que.push(mp(y-1,x));}
				if(y<H-1&&S[y+1][x]!=S[y][x]){que.push(mp(y+1,x));}
				
			}
			ans+=gu*ki;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#!/bin/sh
read a b
num1=`expr $a + $b`
if [ $num1 -ge 24 ]; then
  num2=`expr $num1 \- 24`
  echo $num2
else
  echo $num1
fi
# read a b c d
# num1=`expr $a \* $b`
# num2=`expr $c \* $d`
# if [ $num1 -gt $num2 ]; then
#   echo $num1
# else
#   echo $num2
# fi

Measured memory_bytes: 660
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include<atcoder/all>

using namespace std;

using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
void Yes(bool cond) { cout << (cond ? "Yes" : "No") << '\n'; }
void YES(bool cond) { cout << (cond ? "YES" : "NO") << '\n'; }

ll op(ll a, ll b) { return max(a, b); }
ll e() { return -INF; }
ll target;
bool f(ll v) { return v < target; }


void solve() {
	int N, Q; cin >> N >> Q;
	vector<ll>A(N);
	REP(i, N)cin >> A[i];
	segtree<ll,op,e>seg(A);
	REP(_, Q) {
		int t; cin >> t;
		if (t == 1) {
			int x, v; cin >> x >> v;
			x--;
			seg.set(x, v);
		}
		else if(t==2){
			int l, r; cin >> l >> r;
			print(seg.prod(l - 1, r));
		}
		else {
			int x, v; cin >> x >> v;
			x--;
			target = v;
			int ok = N+1, ng = x;
			while (abs(ok - ng) > 1) {
				int mid = (ok + ng) / 2;
				if (seg.prod(x, mid) >= v)ok = mid;
				else ng = mid;
			}
			print(ok);
		}
	}
}



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

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}



Measured memory_bytes: 9072
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
const long long mod = 1000000007;
int main() {
    int s;
    scanf("%d", &s);
    int d[s+1];
    d[0] = 1;
    d[1] = 0;
    d[2] = 0;
    int i;
    for(i = 3; i <= s; i ++){
        d[i] = d[i - 1] + d[i - 3];
        d[i]%=mod;
    }
    printf("%d", d[s]);
    return 0;
}


Measured memory_bytes: 1712
#include <iostream>

using namespace std;

int gcd (int a, int b) {
  // a >= b
  return (b == 0) ? a : gcd(b, a%b);
}

int main() {
  int a, b;
  cin >> a >> b;
   
  (a > b) ? cout << gcd(a,b) : cout << gcd(b,a);
 
  cout << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <utility>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

int n, m;
int mat[705][705];
vector<int> G[705];

int color[705];
vector<P> vec;
bool dp[705][705];

P dfs(int v, int prev, int c)
{
	color[v] = c;
	P ret = make_pair(0, 0);
	if(color[v] == 1) ret.first++; else ret.second++;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == prev) continue;
		if(color[G[v][i]] == -c) continue;
		if(color[G[v][i]] == c) return make_pair(-1, -1);
		P res = dfs(G[v][i], v, -c);
		if(res.first == -1) return make_pair(-1, -1);
		ret.first += res.first, ret.second += res.second;
	}
	return ret;
}

int comb(int x)
{
	return x * (x-1) / 2;
}

int main(void)
{
	cin >> n >> m;
	int a, b;
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		mat[a][b] = mat[b][a] = 1;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i != j && mat[i][j] == 0) G[i].push_back(j);
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(color[i] == 0){
			P res = dfs(i, -1, 1);
			if(res.first == -1){
				cout << -1 << endl;
				return 0;
			}
			vec.push_back(res);
		}
	}
	
	int N = vec.size();
	dp[0][0] = true;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= n; j++){
			if(!dp[i][j]) continue;
			dp[i+1][j+vec[i].first] = true;
			dp[i+1][j+vec[i].second] = true;
		}
	}
	
	int ans = inf;
	for(int i = 0; i <= n; i++){
		if(!dp[N][i]) continue;
		ans = min(ans, comb(i) + comb(n-i));
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  vector<int> p(N);
  vector<int> q(N);
  int Pcount = 0, Qcount = 0;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> q[i];
  }

  iota(v.begin(), v.end(), 1);
  int num = 0;
  int a = 0, b = 0;
  do {
    num++;
    for (int i = 0; i < (int)v.size(); i++) {
      if (v[i] == p[i])
        Pcount++;
      else
        Pcount = 0;
      if (v[i] == q[i])
        Qcount++;
      else
        Qcount = 0;
      if (Pcount == N) a = num;
      if (Qcount == N) b = num;
    }
  } while (next_permutation(v.begin(), v.end()));
  int ans = abs(a - b);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

void p(int n) {
    cout << "LINE " << n << endl;
}

ll manhd(ll x1, ll x2, ll y1, ll y2) {
	return (abs(x1 - x2) + abs(y1 - y2));
}

ll manhdi(ll i1, ll i2, vector <int> &x, vector <int> &y) {
    // p(12);
    // cout << i1 << " " << i2 << endl;
    // p(14);
    return manhd(x[i1], x[i2], y[i1], y[i2]);
}

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

    ll n;
    cin >> n;
    vector <int> x(n, 0);
    vector <int> y(n, 0);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    ll i1=0,i2=0,i3=0,i4=0;
    ll c1 = x[0]+y[0];
    ll c2 = x[0]-y[0];
    ll c3 = -x[0]+y[0];
    ll c4 = -x[0]-y[0];
    for(int i = 0; i < n; i++) {
        if(x[i]+y[i] > c1) {i1 = i;c1 = x[i]+y[i];}
        if(x[i]-y[i] > c2) {i2 = i;c2 = x[i]-y[i];}
        if(-x[i]+y[i] > c3) {i3 = i;c3 = -x[i]+y[i];}
        if(-x[i]-y[i] > c4) {i4 = i;c4 = -x[i]-y[i];}
    }
    // p(39);
    ll res = manhdi(0,1, x, y);
    for(int i = 0; i < n; i++) {
        // cout << "i is " << i << endl;
        // p(43);
        if(i != i1) res = max(res, manhdi(i1, i, x, y));
        if(i != i2) res = max(res, manhdi(i2, i, x, y));
        if(i != i3) res = max(res, manhdi(i3, i, x, y));
        if(i != i4) res = max(res, manhdi(i4, i, x, y));
        // p(47);
    }
    // p(46);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4780
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


vector<int> a;

vector<vector<int>> graph;

ll dfs(int v, int pre = -1) {
    ll sum = 0;
    vector<ll> cnts;
    for (int to: graph[v]) if (to != pre) {
        ll c = dfs(to, v);
        if (c == -1) return -1;
        sum += c;
        cnts.push_back(c);
    }
    
    if (cnts.size() == 0) return a[v];
    if (pre == -1) {
        if (cnts.size() == 1) return sum == a[v] ? 1 : 0;
        return sum == a[v] * 2 ? 1 : 0;
    }
    
    cnts.push_back(a[v] * 2 - sum);
    for (ll c: cnts) if (a[v] < c || c < 0) return -1;
    return cnts.back();
}

int main() {
    int n;
    cin >> n;
    a.resize(n);
    graph.resize(n);
    cin >> a;
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    
    if (dfs(0) == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << x << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m,k;
    cin >> n >> m >> k;
    int x = 0,y = 0;
    int cur;
    int it = 0;
    int out[n][m];
    bool f = 0;
    while(k--){
        cin >> cur;
        ++it;
        while(cur--){
            out[x][y] = it;
            (f?--y:++y);
            if(y == -1 || y == m){
                f ^= 1;
                ++x;
                if(y == -1) y = 0;
                else y = m-1;
            }
        }
    }
    FORR(i,out){
        FORR(x,i)
            cout << x << ' ';
        cout << '\n';
    }
}



Measured memory_bytes: 384
import bisect
n, m = [int(x) for x in input().split()]
city = [[int(x) for x in input().split()] for i in range(m)]
city_sd = sorted(city, key=lambda y:y[1])
dict = {}
for c in city_sd:
  p, y = c
  if not p in dict.keys():
    dict[p] = []
    dict[p].append(y)
  else:
    dict[p].append(y)
for c in city:
  p, y = c
  print('{:0=6}'.format(p)+'{:0=6}'.format(bisect.bisect_left(dict[p], y) + 1))
  


Measured memory_bytes: 40716
s=input()
ans=0
temp=0
t="ACGT"
for i in range(len(s)):
  flag=False
  for j in range(4):
    if s[i]==t[j]:
      temp=temp+1
      ans=max(ans,temp)
      flag=True
  if flag==False:
    temp=0
print(ans)

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

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

const int INF = 100100100;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> hs(h + 1, INF);
  vector<P> ab(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab[i] = P(a, b);
  }
  hs[0] = 0;
  for (int i = 0; i <= h; i++) {
    rep(j, n) {
      int a = ab[j].first;
      int b = ab[j].second;
      if (i + a < h) {
        hs[i + a] = min(hs[i + a], hs[i] + b);
      } else {
        hs[h] = min(hs[h], hs[i] + b);
      }
    }
  }
  cout << hs[h] << endl;
  return 0;
}


Measured memory_bytes: 3668
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	string S;
	cin>>S;
	
	// 解法
	ll ans = false;
	if (S.substr(0,7)=="keyence") ans = true;
	else if (S.substr(0,1)=="k" & S.substr(S.length()-6,6)=="eyence") ans = true;
	else if (S.substr(0,2)=="ke" & S.substr(S.length()-5,5)=="yence") ans = true;
	else if (S.substr(0,3)=="key" & S.substr(S.length()-4,4)=="ence") ans = true;
	else if (S.substr(0,4)=="keye" & S.substr(S.length()-3,3)=="nce") ans = true;
	else if (S.substr(0,5)=="keyen" & S.substr(S.length()-2,2)=="ce") ans = true;
	else if (S.substr(0,6)=="keyenc" & S.substr(S.length()-1,1)=="e") ans = true;
	else if (S.substr(S.length()-7,7)=="keyence") ans = true;
	
	//出力
	if (ans) printf("YES\n");
	else printf("NO\n");
}


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

int main() {
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for (int i=0; i<N; i++) {
    for (int j=0; j<D; j++) {
      cin >> X[i][j];
    }
  }
  int count = 0;
  for (int i=0; i<N-1; i++) {
    for (int j=i+1; j<N; j++) {
      int dist = 0;
      for (int d=0; d<D; d++) {
        dist += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
      }
      for (int x=1; x<=dist; x++) {
        if (x*x == dist) {
          count++;
          break;
        } else if (x*x > dist) {
          break;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int H, W;
  scanf("%d",&H);
  scanf("%d",&W);
  std::string S;
  char field[H][W];
  int L[H][W];
  int R[H][W];
  int U[H][W];
  int D[H][W];
  for (int i=0; i<H; i++){
    std::cin >> S;
    for (int j=0; j<W; j++){
      field[i][j] = S[j];
    }
  }
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (field[i][j]=='#'){
        L[i][j]=0;
      } else {
        if (j==0){
          L[i][j]=1;
        } else {
          L[i][j]=L[i][j-1]+1;
        }
      }
    }
  }
  for (int i=0; i<H; i++){
    for (int j=W-1;j>=0;j--){
      if (field[i][j]=='#'){
        R[i][j]=0;
      } else {
        if (j==W-1){
          R[i][j]=1;
        } else {
          R[i][j]=R[i][j+1]+1;
        }
      }
    }
  }
  for (int j=0;j<W;j++){
    for (int i=0; i<H; i++){
      if (field[i][j]=='#'){
        U[i][j]=0;
      } else {
        if (i==0){
          U[i][j]=1;
        } else {
          U[i][j]=U[i-1][j]+1;
        }
      }
    }
  }
  for (int j=0;j<W;j++){
    for (int i=H-1; i>=0; i--){
      if (field[i][j]=='#'){
        D[i][j]=0;
      } else {
        if (i==H-1){
          D[i][j]=1;
        } else {
          D[i][j]=D[i+1][j]+1;
        }
      }
    }
  }
  int ans = 0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      //printf("i=%d, j=%d, L=%d, R=%d,U=%d,D=%d\n",i,j,L[i][j],R[i][j],U[i][j],D[i][j]);
      ans = std::max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 66688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N;
  string S;
  cin>>N>>S;
  
  ll DP[N+2][N+2];
  REP(i,N+2) REP(j,N+2) DP[i][j]=0;
  ll K=(ll)S.size();
  DP[0][0]=1;
  
  for(ll i=0; i<=N; ++i){
    DP[i+1][0]+=DP[i][0]; // B
    DP[i+1][1]+=DP[i][0]; // add
    for(ll j=1; j<=i; ++j){
      DP[i+1][j-1]+=DP[i][j]*2;
      DP[i+1][j+1]+=DP[i][j];
      DP[i+1][j-1]%=MOD;
      DP[i+1][j+1]%=MOD;
    }
  }
  
  co(DP[N][K]);
  return 0;
}

Measured memory_bytes: 199036
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

struct h
{
	INT v, w;
};

int col[100000];

void f(INT u, vector<vector<h>>& d)
{
	for (size_t i = 0; i < d[u].size(); i++)
	{
		if (col[d[u][i].v] != -1)
		{
			continue;
		}
		if (d[u][i].w % 2 == 0)
		{
			col[d[u][i].v] = col[u];
		}
		else
		{
			col[d[u][i].v] = col[u] == 0 ? 1 : 0;
		}
		f(d[u][i].v, d);
	}
}

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

	vector<vector<h>> d(n);

	for (size_t i = 0; i < n; i++)
	{
		col[i] = -1;
	}
	for (size_t i = 0; i < n-1; i++)
	{
		INT u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;

		h tmp;
		tmp.v = v;
		tmp.w = w;
		d[u].push_back(tmp);
		h tmp2;
		tmp2.v = u;
		tmp2.w = w;
		d[v].push_back(tmp2);
	}
	col[0] = 0;
	f(0, d);

	for (size_t i = 0; i < n; i++)
	{
		cout << col[i] << endl;
	}
}


Measured memory_bytes: 9600
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    var min = Int.MAX_VALUE
    for (a in (1..n/2)) {
        val b = n - a
        val aDigitSum = a.toString().toCharArray().map { it.toString().toInt()}.sum()
        val bDigitSum = b.toString().toCharArray().map { it.toString().toInt()}.sum()

        if (aDigitSum + bDigitSum < min) {
            min = aDigitSum + bDigitSum
        }
    }

    print(min)

}

Measured memory_bytes: 49520
#include <stdio.h>

#include <stdlib.h>


int main() {
 int i, j, k;
 int count;

 int n;
 scanf("%d", &n);

 int A[10000];
 for (i = 0; i != n; i++) {
  scanf("%d", &A[i]);
 }

 for (i = 0; i <n - 1; i++) {
  for (j = 0; j != n - i - 1; j++) {
   if (A[j] >A[j + 1]) {
    //swap
    k =A[j];
   A[j] =A[j + 1];
    A[j + 1] = k;
    count++;
   }
  }
 }
//bubble
 for (i = 0; i <n; i++) {
  if (i == n- 1)printf("%d\n", A[i]);
  else printf("%d ", A[i]);
 }
 printf("%d\n", count);
 return 0;
}



Measured memory_bytes: 2040
#include<stdio.h>
int main(){
	int a,b,c,n=0,s;
	int t[30][3];
	for(a=0;;a++){
		scanf("%d,%d",&t[a][0],&t[a][1]);
		if(t[a][0]==0 && t[a][1]==0){break;}
		n++;
	}
	for(a=0;a<n;a++){
		for(b=0;b<n-1;b++){
			if(t[b][1]<t[b+1][1]){
				c=t[b][0];
				t[b][0]=t[b+1][0];
				t[b+1][0]=c;
				c=t[b][1];
				t[b][1]=t[b+1][1];
				t[b+1][1]=c;
			}
		}
	}
	t[0][2]=1;
	b=1;
	for(a=1;a<n;a++){
		if(t[a][1]!=t[a-1][1]){b++;}
		t[a][2]=b;
	}
	for(;;){
		if(scanf("%d",&s)==EOF){break;}
		for(a=0;a<n;a++){
			if(s==t[a][0]){printf("%d\n",t[a][2]);}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<30;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int msn[100000],msp[100000];

int main(void){
    int n,i,j,k,c,f;
    for(i=0;7*i+1<300000;i++){
        msn[2*i]=7*i+1;
        msn[2*i+1]=7*i+6;
    }
    c=2*i;
    k=0;
    for(i=1;i<c;i++){
        f=1;
        for(j=1;msn[j]*msn[j]<=msn[i];j++){
            if(msn[i]%msn[j]==0){
                f=0;
                break;
            }
        }
        if(f){
            msp[k++]=msn[i];
        }
    }
    while(1){
        n=in();
        if(n==1)break;
        printf("%d:",n);
        rep(i,k){
            if(n%msp[i]==0)printf(" %d",msp[i]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 2160
#include <iostream>

int main() {
    int n, k;
    std::cin >> n >> k;
    bool sunuke[n] = { false };

    for (int i = 0; i < k; i++) {
        int d;
        std::cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            std::cin >> a;
            sunuke[a - 1] = true;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!sunuke[i]) {
            ans++;
        }
    }

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


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

#define MAX 200002

int n;

vector<int> vv;

long long int seg[MAX*4];
long long int laz[MAX*4];

void upd(int b){
	if(b*2+2<MAX*4){
		laz[b*2+1]+=laz[b];
		laz[b*2+2]+=laz[b];
	}
	seg[b]+=laz[b];
	laz[b]=0;
}

inline long long int query(int b,int l,int r,int ll,int rr){
	upd(b);
	if(r<=ll||rr<=l)return INT_MAX;
	if(ll<=l&&r<=rr)return seg[b];
	return min(query(b*2+1,l,(l+r)>>1,ll,rr),query(b*2+2,(l+r)>>1,r,ll,rr));
}

int dp[MAX];

vector<int> v[MAX];


inline void add(int b,int l,int r,int ll,int rr,int x){
	upd(b);
	if(r<=ll||rr<=l)return;
	if(ll<=l&&r<=rr){
		laz[b]+=x;
		upd(b);
		return;
	}
	add(b*2+1,l,(l+r)>>1,ll,rr,x);
	add(b*2+2,(l+r)>>1,r,ll,rr,x);
	seg[b]=max(seg[b*2+1],seg[b*2+2]);
}
inline void chang(int b,int l,int r,int ll,long long int x){
	upd(b);
	if(l<=ll&&ll<r){
		if(l+1==r){
			seg[b]=min(seg[b],x);
			return;
		}
		chang(b*2+1,l,(l+r)>>1,ll,x);
		chang(b*2+2,(l+r)>>1,r,ll,x);
		seg[b]=min(seg[b*2+1],seg[b*2+2]);
	}
}
int q;
int main(){
	for(int i=0;i<MAX*4;i++)seg[i]=INT_MAX;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		vv.push_back(a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		v[a].push_back(b);
	}
	for(int i=0;i<=n;i++){
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i=0;i<=n;i++){
		chang(0,0,n+1,i,dp[i]);
		dp[i]=query(0,0,n+1,i,i+1);
		if(i==n)break;
		for(int el:v[i]){
			chang(0,0,n+1,el+1,query(0,0,n+1,i,el+1));
		}
		if(vv[i]==0){
			add(0,0,n+1,i,n+1,1);
		}
		dp[i+1]=dp[i];
		if(vv[i]==1)dp[i+1]++;
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 22900
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll k,a,b;
   cin>>k>>a>>b;
   for(ll i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
   }
   cout<<"NG"<<endl;
return 0;
}


Measured memory_bytes: 8308
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-19 22:32:53

  referred to: https://atcoder.jp/contests/abc152/submissions/9630413
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

vector<int> slice_n(int n) {
    vector<int> v;
    while (n > 0) {
        v.push_back(n%10);
        n /= 10;
    }
    reverse(all(v));
    return v;
}

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

    vector<vector<int>> v(10, vector<int>(10,0));
    for (int i = 0; i < n; i++) {
        int x = i+1;
        string s = to_string(x);
        v[s.front()-'0'][s.back()-'0']++;
    }

    int ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ans += v[i][j]*v[j][i];
        }
    }

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


Measured memory_bytes: 256
fn main() {
    let n = read();
    let mut st: Vec<(i64, i64)> = Vec::new();
    for _ in 0..n {
        let tmp = read_vec::<i64>();
        let (x, l) = (tmp[0], tmp[1]);
        st.push((x - l, x + l));
    }

    st.sort_by(|a, b| a.1.cmp(&b.1));

    let mut ans = 0;
    let mut cur_end = -10e9 as i64 - 1;
    for (s, t) in st.into_iter() {
        if cur_end <= s {
            ans += 1;
            cur_end = t;
        }
    } 

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

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> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<int,int> P;


int main(){
    int n,d,a;
    cin >> n >> d >> a;
    d= d*2;
    vector<P> T(n);
    queue<pair<ll,ll>> q;
    rep(i,n){
        cin >> T[i].first >> T[i].second;
    } 
    sort(T.begin(),T.end());
    ll ans=0;
    ll tot =0;
    rep(i,n){
        ll x = T[i].first;
        ll h = T[i].second;
        while(!q.empty()&& q.front().first<x){
            tot -= q.front().second;
            q.pop();
        }
        h-= tot;
        if(h>0){
            // 切り上げは(以下のように書く)
            ll num = (h+a-1)/a;
            ans += num;
            ll damage  = num * a;
            tot += damage;
            q.emplace(x+d, damage);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define LL long long
using namespace std;

int n, ans, vis[4];

void dfs(LL x)
{
	if(x>n) return ;
	if(vis[1] && vis[2] && vis[3]) ans++;
	vis[1]++;
	dfs(x*10+3);
	vis[1]--;
	vis[2]++;
	dfs(x*10+5);
	vis[2]--;
	vis[3]++;
	dfs(x*10+7);
	vis[3]--;
}

int main()
{
	scanf("%d", &n);
	dfs(0);
	printf("%d\n", ans);
	return 0;
} 

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n;
  cin >> n;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    m[s]++;
  }

  int max = 0;
  for (const auto& kv : m) {
    UpdateMax(max, kv.second);
  }

  vector<string> ss;
  for (const auto& kv : m) {
    if (kv.second == max) {
      ss.push_back(kv.first);
    }
  }
  sort(ss.begin(), ss.end());
  for (const auto& s : ss) {
    cout << s << endl;
  }
}

Measured memory_bytes: 25584
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(turu, kame):
  if turu*2 + kame*4 == y:
    #print(turu,kame)
    return True
  else:
    return False

x,y =IL()

for turu in range(x+1):
  kame = x - turu
  if tami(turu, kame):
    print("Yes")
    exit()
else:
  print("No")


Measured memory_bytes: 70936