akhauriyash/Code-Regression huggingface dataset:
from sys import exit
N = int(input())
T,A = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
mnear = 0
mint = (1 << 20)
for i in range(N):
    # print(T - H[i]*0.006)
    if abs(A - (T - H[i]*0.006)) < mint:
        mint = abs(A - (T - H[i]*0.006))
        mnear = i

print(mnear+1)
exit()


Measured memory_bytes: 3060
#pragma once

#include<iostream>
#include<string>
//#include<stdio.h>

using namespace std;

string s;
string a, b;


int main(){

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

	for (int i = 4; i < 12; i++)
	{
		b += s[i];
	}

	cout << a <<' ' << b << endl;

	return 0;
}






Measured memory_bytes: 256
N, M = map(int,input().split())
s = [0]*M
c = [0]*M

for i in range(M):
    s[i], c[i] = map(int,input().split())

ans = [0]*N
if N != 1:
    ans[0] = 1
error = 0

assign = [0]*N
for i in range(M):
    assign[s[i]- 1] += 1

    if assign[s[i] - 1] > 1 and ans[s[i] - 1] != c[i]:
        error += 1

    ans[s[i] - 1] = c[i]
    


if ans[0] == 0 and N != 1:
    error += 1 

if error == 0:
    for i in range(N):
        print(ans[i], end = "")
    print()
else:
    print(-1)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <numeric> 
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
    int x; cin >> x;
    int ans = 0;
    
    ans = (x/500 * 1000) + (x%500)/5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N,*D = map(int, open(0).read().split())
m = 998244353
if D[0] > 0:
    print(0)
else:
    dc = Counter(D)
    dci = [x for x in dc.items()]
    ans = 1
    if dc[0] > 1:
        print(0)
    else:
        for i in range(1,max(dci)[0]+1):
            if dc[i] == 0:
                print(0)
                break
            else:
                ans = (ans*pow(dc[i-1],dc[i],m)) % m
        else:
            print(ans)

Measured memory_bytes: 25524
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node *right;
  Node *left;
  Node *parent;
};

Node *root;
Node *NIL;

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

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

Node * treeSuc(Node *x){
  if(x->right != NIL) return treeMin(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDel(Node *z){
  Node *y;
  Node *x;

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

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

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

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

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

  free(y);
}


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

  z = (Node *)malloc(sizeof(Node));
  z->key= k;
  z->left= NIL;
  z->right= NIL;

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

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

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

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

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin >> com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }
    else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com=="delete"){
      scanf("%d",&x);
      treeDel(find(root,x));
    }
  }

  return 0;
}



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

using namespace std;

int main() {

	string s;
	cin >> s;
	if (s[0] == s[1] && s[0] == s[2]) {
		cout << "Yes" << endl;
	}
	else if (s[1] == s[2] && s[1] == s[3]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 764
#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
#define inf 2147483647
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define N 200004

int main() {
    IosF;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll res = max(a * d, max(b * c, max(a * c, b * d)));
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

int main(){
	string s, t;
	int n, m;
	while(getline(cin, s)){
		getline(cin, t);
		n = s.size();
		m = t.size();

		int res = 0;
		for(int i = -n + 1; i < m; i++){
			int c = 0;
			int ind = max(i, 0);
			while(ind - i< n && ind < m){
				c = 0;
				while(ind - i < n && ind < m && s[ind-i] == t[ind]){
					c++;;
					ind++;
				}
				ind++;
				res = max(c, res);
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] hs = new int[n + 1];
			for (int i = 0; i <= n; i++) {

				hs[i] = sc.nextInt();
			}
			for (int i = 0; i <= n; i++) {
				int d = 0;
				if (i < 2)
					d = hs[i + 2] - hs[i + 1];
				else {
					d = hs[i - 1] - hs[i - 2];
				}
				boolean flag = true;
				for (int j = 0; j < n; j++) {
					int dd = 0;
					if (j == i)
						if (j != 0)
							dd = hs[j + 1] - hs[j - 1];
						else
							continue;
					else if (j + 1 == i) {
						continue;
					} else
						dd = hs[j + 1] - hs[j];
					if (dd != d) {
						flag = false;
						break;
					}
				}
				if (flag) {
					System.out.println(hs[i]);
					i = n + 1;
				}
			}
		}
	}

	public static void main(String[] args) {

		new Main().run();
	}
}

Measured memory_bytes: 33660
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

weeks = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

S = input()
d = weeks.index(S)

print(7 - d)


Measured memory_bytes: 38384
n, m = map(int, input().split())
s = input()[::-1]
now = 0
L = []
while now<n:
  t = s[now:now+m+1].rfind("0")
  if t==0:
    print(-1)
    exit()
  else:
    L.append(t)
    now += t
print(*L[::-1])

Measured memory_bytes: 6408
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
   //  String[] nyu=sc.nextLine().split("");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
int D=Integer.parseInt(nyu);


//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

int res=D/3;


System.out.println(res);





	}
}

Measured memory_bytes: 21844
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local s, t = read.ll()
s=s:totable()
t=t:totable()
table.sort(s)
table.sort(t)
s=table.concat(s, "")
t=table.concat(t, "")
t=t:reverse()
print(s<t and "Yes" or "No")


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int N, M, K;
long long A[20010], dp[20010];

int main() {
    cin >> N >> M >> K;
    REP(i, N) { cin >> A[i]; }
    fill_n(dp, 20010, llINF);
    dp[0] = 0;

    REP(i, N) {
        long long mx = A[i], mn = A[i];
        for (int j = 1; j < M + 1; j++) {
            if (i + j < N + 1) {
                dp[i + j] = min(dp[i + j], dp[i] + j * (mx - mn) + K);
                mx = max(mx, A[i + j]);
                mn = min(mn, A[i + j]);
            }
        }
    }

    cout << dp[N] << endl;
}


Measured memory_bytes: 3420
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 500001
#define MAX 1000000
using namespace std;

/* 🐣🐥 */
int h[100001];
int dp[100001];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	printf("%d", dp[n - 1]);

	return 0;
}

Measured memory_bytes: 896
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


vector<pll>adj[Max+10];

ll n;



ll color[Max+10];


void dfs(ll s,ll p)
{


    for(auto x  : adj[s])
    {
        if(x.F!=p)
        {
            if(x.S&1)
                color[x.F]=color[s]^1;

            else color[x.F]=color[s];

            dfs(x.F,s);
        }
    }
}
int main()
{

   fastread();

   ll i,j,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n;

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

          adj[a].eb(b,c);

          adj[b].eb(a,c);
      }

      color[1]=1;

      dfs(1,1);

      for(i=1; i<=n; i++)
        cout<<color[i]<<endl;













}



Measured memory_bytes: 57632
H,W=map(int,input().split())
c=[]
for i in range(10):
    C=list(map(int,input().split()))
    c.append(C)
A=[]
for i in range(H):
    a=list(map(int,input().split()))
    A.append(a)

for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][j]>(c[i][k]+c[k][j]):
                c[i][j]=c[i][k]+c[k][j]
ans=0
for i in range(H):
    for j in A[i]:
        if j!=-1:
            ans+=c[j][1]

print(ans)

Measured memory_bytes: 40540
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> vec(N);
  for(auto& d : vec) {
    cin >> d;
  }

  sort(vec.begin(), vec.end()); 
  int ans = 1;
  for(int i = 0; i < N; i++) {
    if(i == 0) { continue; }
    if(vec[i] > vec[i-1]) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 120000
using namespace std;
int a[N],b[N],c[N],tot,cnt,n,k,ans=0x7fffffff;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)if(a[i]==0)k--;
	for(int i=1;i<=n;i++){if(a[i]>0)b[++tot]=a[i];}
	for(int i=n;i>=1;i--){if(a[i]<0)c[++cnt]=-a[i];}
	for(int i=1;i<=tot;i++)if(k-i>0&&c[k-i]!=0)ans=min(ans,b[i]+c[k-i]+min(b[i],c[k-i]));
	if(b[k]!=0)ans=min(ans,b[k]);
	if(c[k]!=0)ans=min(ans,c[k]);
	if(k==0)ans=0; 
	printf("%d\n",ans);
	return 0; 
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


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

signed main(){

	int H, W;
	cin >> H >> W;
	int dist[1002][1002];
	char A[1002][1002];

	rep(i, 1002)rep(j, 1002){
		dist[i][j] = INF;
		A[i][j] = '!';
	}

	queue<P> que;

	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			cin >> A[i][j];
			if (A[i][j] == '#'){
				dist[i][j] = 0;
				que.push(P(i, j));
			}
		}
	}

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

		for (int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (A[nx][ny] == '.' && dist[nx][ny] == INF){
				que.push(P(nx, ny));
				dist[nx][ny] = dist[p.first][p.second] + 1;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= H; i++){
		for (int j = 1; j <= W; j++){
			ans = max(ans, dist[i][j]);
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 25396
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if((n/10)%111==0){
      System.out.println("Yes");
    }else if((n%1000)%111==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

int main() {
  
  int N; int64_t X; cin >> N >> X;
  
  if (N == 1) {
    int64_t x; cin >> x;
    cout << abs(X - x) << endl;
    return 0;
  }
  
  vector<int64_t> vec(N), dif(N - 1);
  
  for (int i = 0; i < N; i++) {
    int64_t x; cin >> x;
    x = abs(x - X);
    vec[i] = x;
  }
  
  int64_t ans = vec[0];
  
  for (int i = 0; i < N - 1; i++) {
    ans = __gcd(ans, abs(vec[i + 1] - vec[i]));
  }
  
  cout << ans << endl;
  
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    double y, x;
} p_t;

int main() {   
    Int n, m;
    cin >> n >> m;
    dump(n == m ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#define KAKUSUKO
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200;
int N;
string S[MAX_N];

                            
struct edge { int to, cost; };
const int MAX_V = MAX_N, INF = 1e9;

// Vの初期化を忘れない。
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void add_edge(int v, int u, int cost) {
  G[v].push_back((edge){u, cost});
  G[u].push_back((edge){v, cost});
}

void dijkstra(int s) {
  fill(d, d+V, INF);
  priority_queue<Pii, vector<Pii>, greater<Pii> > pque;
  d[s] = 0;
  pque.push(Pii(0, s));


  while (!pque.empty()) {
    Pii p = pque.top(); pque.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; 
        pque.push(Pii(d[v]+ e.cost, e.to));
      }
    }
  }
}

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

  cin >> N;
  rep(i, N) {
      cin >> S[i];
  }
  V = N;

  rep(i, N) {
    rep(j, N) {
      if (S[i][j] == '1') add_edge(i, j, 1);
    }
  }

  int ans = -1;
  for (int s = 0; s < N; ++s) {
    dijkstra(s);
    vector<Pii> vpii;
    for (int i = 0; i < N; ++i) {
      vpii.push_back(Pii(d[i], i));
    }
    sort(all(vpii));
    vector<vector<int>> vvi(vpii[N-1].fi + 1);
    for (int i = 0; i < N; ++i) {
      vvi[vpii[i].fi].push_back(vpii[i].sc);
    }
    bool ok = true;
    for (int i = 0; i < len(vvi); ++i) {
      vector<int>& sameDistList = vvi[i];
      for (int j = 0; j < len(sameDistList); ++j) {
        for (int k = 0; k < len(sameDistList); ++k) {
          if (S[sameDistList[j]][sameDistList[k]] == '1') {
            ok = false;
            break;
          }
        }
        if (!ok) break;
      }
      if (!ok) break;
    }
    if (ok) {
      ans = max(ans, len(vvi));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
s = raw_input()
s = s[::-1]
i = 0
dream = False
while i < len(s):
	p = s[i:i+7]
	
	if p == "remaerd":
		i += 7
	elif p[:6] == "resare":
		i += 6
	elif p[:5] == "maerd" or p[:5] == "esare":
		i += 5
	else:
		break
	
if i >= len(s):
	print "YES"
else:
	print "NO"
		

Measured memory_bytes: 2948
n, m = map(int, input().split())
red = [0 for _ in range(n)]
red[0] = 1
balls = [1 for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().split())
    if balls[x-1]:
        balls[x-1] -= 1
        balls[y-1] += 1
        if red[x-1]:
            red[y-1] = 1
            if balls[x-1] == 0:
                red[x-1] = 0
cnt = 0
for i in range(n):
    if red[i] and balls[i]:
        cnt += 1
print(cnt)

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

int main() {

	int n; cin >> n;
	int ans = 0;
	int maxh = 0;
	for (int i = 0; i < n; i++) {
		int  h; cin >> h;
		if (maxh <= h) {
			maxh = h;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#define N 100
#define INFINITY 200000000
using namespace std;
int n,k,u,v,c,M[N][N],d[N],p[N],mincost,i,j;
string color[N];
void dijkstra(void);
int main(){
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    cin >> u;
    cin >> k;
    for(j=0;j<k;j++){
      cin >> v >> c;
      M[u][v]=c;
    }
  }
  dijkstra();
  return 0;
}
void dijkstra(){
  for(i=0;i<n;i++) color[i]="WHITE",d[i]=INFINITY;
  d[0]=0;
  p[0]=-1;
  while(1){
    mincost=INFINITY;
    for(i=0;i<n;i++){
      if(color[i]!="BLACK"&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INFINITY) break;
    color[u]="BLACK";
    for(i=0;i<n;i++){
      if(color[i]!="BLACK"&&M[u][i]!=-1){
	if(d[u]+M[u][i]<d[i]){
	  d[i]=d[u]+M[u][i];
	  p[i]=u;
	  color[i]="GLAY";
	}
      }
    }
  }
  for(i=0;i<n;i++) cout << i << ' ' << d[i] << endl;
}


Measured memory_bytes: 3216
n = int(input())
cnt = [[0] * n for i in range(26)]

for i in range(n):
    s = input()
    for j in range(len(s)):
        x = ord(s[j]) - 97
        cnt[x][i] += 1

ans = ''
for i in range(26):
    ans += min(cnt[i]) * chr(i+97)
print(ans)

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

int main()
{
  string s;
  cin >> s;
  
  int N = s.length();
  int k, l;
  
  for(int i = 0; i < N; i++)
  {
    if(s[i] == 'A')
    {
      k = i;
      break;
    }
  }
  for(int i = N - 1; i >= 0; i--)
  {
    if(s[i] == 'Z')
    {
      l = i;
      break;
    }
  }
  
  cout << l - k + 1 << endl;
  return 0;
}
    


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s, t; cin >> s >> t;
  int n = sz(s), m = sz(t);
  int i, j, z, ans = inf;
  for (i = 0; i+m-1 < n; i++) {
    string u = s.substr(i, m);
    int now = 0;
    for (j = 0; j < m; j++)
      if (t[j] != u[j]) now++;
    ans = min(ans, now);
  }
  cout << ans;
  return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = min(c, b/a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char Color[3] = {'R', 'G', 'B'};

int main(){

    int n; cin >> n;
    vector<int> h(n);
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin >> h[i] >> w[i];
    string C;
    for(int i = 0; i < 4; i++){
        string tmp; cin >> tmp;
        C = C + tmp;
    }

    queue<pair<int, int> > que;                  //cost bit(一致していたら1そうでなければ0)
    
    vector<bool> used((1 << 16), false);
    used[0] = true;
    que.push({0, 0});

    while(!que.empty()){

        int bit = que.front().second;
        int cost = que.front().first;
        //cout << cost << " " << str << endl;
        que.pop();

        if(bit == (1 << 16) - 1){
            cout << cost << endl;
            break;
        }

        for(int ii = 0; ii < n; ii++){

            for(char color : Color){

                //cout << i << " " << color << endl;
                for(int si = -3; si <= 3; si++){
                    for(int sj = -3; sj <= 3; sj++){
                        int gi = si + h[ii] - 1;
                        int gj = sj + w[ii] - 1;

                        int next;
                        next = bit;
                        //cout << i << " " << si << " " << gi << " " << sj << " " << gj << " " << endl;
                        for(int i = max(si, 0); i <= min(gi, 3); i++){
                            for(int j = max(sj, 0); j <= min(gj, 3); j++){            
                                int idx = i * 4 + j;
                                if(C[idx] == color) next = next | (1 << idx);
                                else next = next & ~(1 << idx);
                            }
                        }

                        if(!used[next]){
                            //cout << "ok" << endl;
                            used[next] = true;
                            que.push({cost + 1, next});
                        }

                    }
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3340
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int k,n;
    cin>>k>>n;
    vi a(n+1,0);
    FOR(i,0,n){
        cin>>a[i];
    }
    a[n]=a[0]+k;
    int mx=0;
    FOR(i,0,n){
        a[i]=a[i+1]-a[i];
        mx=max(mx,a[i]);
    }
    cout<<k-mx<<endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define lo long
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>h(n);
	vector<int>a(n);
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int base=1;
	while(base<n){
		base*=2;
	}
	vector<ll>tree(2*base,0);
	vector<ll>dp(n+1,0);
	for(int flower=0;flower<n;flower++){
		int l=base;
		int r=h[flower]+base-1;
		ll res=0;
		for(;l<r;l>>=1,r>>=1){
			if(l&1)
				res=max(res,tree[l++]);
			if(r&1)
				res=max(res,tree[--r]);
		}
		// cout<<"i:"<<flower<<" "<<res+a[flower]<<"\n";
		dp[h[flower]]=res+a[flower];
		tree[h[flower]+base-1]=max(tree[h[flower]+base]-1,dp[h[flower]]);
		for(int p=h[flower]+base-1;p>1;p>>=1)
			tree[p>>1]=max(tree[p],tree[p^1]);

	}
	ll result=0;
	for(int i=0;i<=n;i++){
		result=max(result,dp[i]);
	}
	cout<<result;
	return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;
//const ll INF = mod * mod;

int main() {
    ll a,b,n;
    cin >> a >> b >> n;
    ll l = 1,r = n;
    ll ans = 0;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        ll k = a * mid / b - a * (mid / b);
        if(k >= ans)  {
            ans = k;
            l = mid;
        }
        else r = mid;
    }
    ll x = a * r / b - a * (r / b);
    ans = max(ans,x);
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
struct Node {
	int key;
	Node*next;
	Node*prev;
};
Node *nil;//头节点
void init() {
	nil = (Node*)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}
void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}
void deleteNode(Node *t) {
	if (t == nil)
		return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}
Node * search(int key) {
	Node *cur = nil->next;
	while (cur->key != key &&cur != nil) {
		cur = cur->next;
	}
	return cur;
}
void deleteLast() {
	deleteNode(nil->prev);
}
void deleteFirst() {
	deleteNode(nil->next);
}
void deleteKey(int key) {
	deleteNode(search(key));
}
void Print() {
	Node * cur = nil->next;
	int isf = 0;
	while (true) {
		if (cur == nil) break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}
int main() {
	init();
	int n;
	char com[21];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int key;
		scanf("%s",com);
		if(com[0]=='i'){
			scanf("%d",&key);
			insert(key);
		}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				if(com[6]=='L')deleteLast();
			}else{
				scanf("%d",&key);
				deleteKey(key);
			}
		}
	}
	Print();
	return 0;
}



Measured memory_bytes: 33928
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i=0; i<n; i++) cin >> arr[i];
    sort(arr.begin(), arr.end());
    cout << arr[n/2] - arr[n/2-1];
}

Measured memory_bytes: 640
/*
 * FileName:     binary_tree_1
 * CreatedDate:  2020-04-22 21:32:11 +0900
 * LastModified: 2020-04-23 00:47:13 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define node_max 500000
typedef struct _node{
    int number;
    struct _node *pare;
    struct _node *left;
    struct _node *right;
}_node;
void insert_node(_node *pare, _node *new){
    if(pare==NULL){
        return;
    }
    if(pare->left==NULL&&pare->number>new->number){
        pare->left=new;
        new->pare=pare;
    }
    else if(pare->left!=NULL&&pare->number>new->number){
        insert_node(pare->left,new);
    }
    else if(pare->right==NULL&&pare->number<new->number){
        pare->right=new;
        new->pare=pare;
    }
    else{
        insert_node(pare->right,new);
    }
}
void print_node(_node *pare,int order){
    if(pare==NULL){
        return ;
    }
    if(order==0){
        printf(" %d",pare->number);
        print_node(pare->left,order);
        print_node(pare->right,order);
    }
    else{
        print_node(pare->left,order);
        printf(" %d",pare->number);
        print_node(pare->right,order);
    }
}
int main(void){
    int n,count=0;
    scanf("%d",&n);
    _node *nn = (_node*)malloc(sizeof(_node));
    nn->left=NULL;
    nn->right=NULL;
    nn->pare=NULL;
    char tmp[7];
    scanf("%s %d",tmp,&nn->number);
    _node *pare = nn;
    _node *node = (_node*)malloc(n*sizeof(_node));
    for(int i=1;i<n;i++){
        char *command = (char*)malloc(7*sizeof(char));
        scanf("%s",command);
        if(strcmp(command,"insert")==0){
            scanf("%d",&(node+count)->number);
            insert_node(pare,node+count);
            count++;
            pare=nn;
        }
        else{
            print_node(pare,1);
            printf("\n");
            print_node(pare,0);
            printf("\n");
        }
        free(command);
    }
    free(nn);
    free(node);
    return 0;
}



Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

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

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size(),m = t.size();
    if(n<m){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    vector<string> con;
    rep(i,n-m+1){
        bool ok = true;
        rep(j,m){
            ok &= (s[i+j]==t[j] || s[i+j]=='?');
        }
        if(ok){
            string tmp = "";
            rep(j,n){
                if(j==i) {tmp += t; j += m-1;}
                else if(s[j]=='?') tmp += 'a';
                else tmp += s[j];
            }
            con.push_back(tmp);
        }
    }
    sort(con.begin(),con.end());
    if(con.size()==0){
        cout << "UNRESTORABLE" << endl;
    }else{
        cout << con[0] << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    if(n >= 1000) cout << "ABD" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    ans = []
    ans_sum = 0
    for i in range(1, N+1):
        ans_sum += i
        ans.append(i)
        if N <= ans_sum:
            dis = ans_sum - N
            for a in ans:
                if a != dis:
                    print(a)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 42460
#include <iostream>

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << static_cast<char>(a[0] - 'a' + 'A')
       << static_cast<char>(b[0] - 'a' + 'A')
       << static_cast<char>(c[0] - 'a' + 'A') << endl;
  return 0;
}


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

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<long long> h(n);
	for(int i = 0; i < n; i++){
	    cin >> h[i];
	}
	sort(h.begin(), h.end());
	long long x = 0;
	if(n <= k) {
	    cout << 0;
	}
	else {
	   for(int i = 0; i < n - k; i++) {
	       x += h[i];
	   }
	   cout << x;
	}
	return 0;
}

Measured memory_bytes: 1792
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 *
 * AND WATCH OUT FOR OFF BY ONE!!!
 */

#include <bits/stdc++.h>
const bool unsyncedio=std::ios::sync_with_stdio(false);
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll (i)=0; (i)<(n); (i)++)

bool isMonth(char c1, char c2) {
    int i1=c1-'0';
    int i2=c2-'0';
    int m=i1*10+i2;
    return m>=1 && m<=12;
}

int main() {
    string s;
    cin>>s;
    
    // "YYMM" vs "MMYY"
    // year numbers can be any numbers, but months are limited to 01 - 12
    bool yymm=isMonth(s[2], s[3]);
    bool mmyy=isMonth(s[0], s[1]);
    if(!yymm && !mmyy)
        cout<<"NA";
    else if(yymm && !mmyy)
        cout<<"YYMM";
    else if(!yymm && mmyy)
        cout<<"MMYY";
    else
        cout<<"AMBIGUOUS";
    cout<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll minn(ll x, ll y){
    if(x<y)
        return x;
    return y;
}
int main() {
    ll n, h[100009],ans[100009],i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>h[i];
    }
    ans[0]=0;ans[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++){
        ans[i] = minn(ans[i-1] + abs(h[i]-h[i-1]), ans[i-2] + abs(h[i]-h[i-2]));
    }
    cout<<ans[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stack> 
#include <algorithm> 
#include <vector> 
#include <string> 
using namespace std;

int main()
{
    stack<int> s1;
    stack<pair<int,int> > s2;
    int  i = 0;
    char ch;
    int sum = 0, a = 0;

    while(cin>>ch)
    {
        i++;
        if (ch=='\\')
        { 
            s1.push(i); 
        }else if (ch=='/' && s1.size()>0)
        { 
            int j = s1.top();
            s1.pop();
            sum += i - j;
            a = i - j;
            while(s2.size()>0 && s2.top().first>j)
            {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j,a));
        }
    }
    vector<int> ans;
    while (s2.size()>0)
    { 
        ans.push_back(s2.top().second);
        s2.pop();
    }  
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for (int i = 0; i < ans.size(); i++)
    {
        cout<<" ";
        cout<<ans[i];
    } 
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef std::pair<int,int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool greaterPair(const ipair& l, const ipair& r){return l.second > r.second;}

int main(void){
  int N,K;
  cin >> N >> K;
  vector<int> A(N, 0);
  for(int i = 0; i < N; i++){
    int temp;
    cin >> temp;

    A[temp]++;
  }

  vector<ipair> A_with_index;
  for(int i = 0; i < N; i++){
    A_with_index.push_back(ipair(i, A[i]));
  }
    partial_sort(A_with_index.begin(), A_with_index.begin()+K, A_with_index.end(), greaterPair);

    int diff = 0;
    for(int i = 0; i < K; i++){
      int temp = 0;
      temp = (A_with_index.begin() + i) -> second;
      diff += temp;
    }
    if(N-diff >= 0){
      cout << N-diff << endl;
    } else {
      cout << 0 << endl;
    }
  return 0;
}

Measured memory_bytes: 3188
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <sstream>
#include <regex>
//#include <atcoder/all>

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

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

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

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

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

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

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


int main()
{
	int n, k; cin >> n >> k;
	vector<int> l(k), r(k); rep(i, k)cin >> l[i] >> r[i];
	vector<int> dp(n), sdp(n + 1);
	dp[0] = 1;
	int MOD = 998244353;
	rep(i, n)
	{
		rep(j, k)
		{
			int left = max(0, i - r[j]);
			int right = max(0, i - l[j] + 1);
			dp[i] += sdp[right] - sdp[left];
			dp[i] %= MOD;
			if (dp[i] < 0)dp[i] += MOD;
		}
		sdp[i + 1] = sdp[i] + dp[i];
		sdp[i + 1] %= MOD;
	}
	cout << dp[n - 1] << endl;
}

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

int main() {
    int X, N;
    cin >> X >> N;
    bool num[110] = {};
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        num[p] = true;
    }

    int diff = 1000, ans;
    for (int i = 0; i < 110; i++) {
        if (num[i]) continue;
        if (diff > abs(X - i)) {
            diff = abs(X - i);
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"29"# => "Yes",
// r#"24"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        c1: chars,
        mut c2: chars,
    }
    c2.reverse();

    if c1 == c2 { "YES" } else { "NO" }.to_string()
}

Measured memory_bytes: 4352
fun main(args: Array<String>) {
//    val mod = 1000000007L
    val mod = 2019
    val N = readLine()!!.toInt()
    val P = readLine()!!.split(" ").map(String::toInt).toList()

    var isSwap = 0

    for ((i,p) in P.withIndex()) {
        if (i+1 != p) isSwap++
    }
    println(if(isSwap <= 2) "YES" else "NO")
}

Measured memory_bytes: 37612
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long dp[2100][2100];
long long gl[2100][2100];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	dp[0][0]=1;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			if(!dp[i][j])continue;
			int now=i+j;
			int nx=now-now%(c-1)+c-1;
			if(i<a)dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			if(j+nx-now<=b){
				dp[i][j+nx-now]=(dp[i][j+nx-now]+dp[i][j])%mod;
			}
			if(now%(c-1)==0){
				for(int k=1;k<c;k++){
					if(i+k<=a&&j+c-k<=b)gl[i+k][j+c-k]=(dp[i][j]+gl[i+k][j+c-k])%mod;
				}
			}
		}
	}
	long long ret=0;
	for(int i=1;i<=a;i++)for(int j=1;j<=b;j++){
		if((a-i)%(c-1)==0&&(b-j)%(c-1)==0){
	//		printf("%d %d: %lld\n",i,j,gl[i][j]);
			ret=(ret+gl[i][j])%mod;
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 67712
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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 a,b;
  cin >> a >> b;
  int x = 1;
  int ans = 0;
  while(x < b){
    ++ans;
    x += a-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
py=[]
ans=[0]*m
for j in range(m):
    py.append(list(map(int,input().split()))+[j])
py.sort(key=lambda x:x[1])
p=[0]*n
for i in range(m):
  p[py[i][0]-1]+=1
  ans[py[i][2]]='0'*(6-len(str(py[i][0])))+str(py[i][0])+'0'*(6-len(str(p[py[i][0]-1])))+str(p[py[i][0]-1])
for k in range(m):
    print(ans[k])

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    string s;
    cin >> N >> s;

    int r = N-1;
    int res = 0;
    for (int w=0; w<N; ++w) {
        if (s[w] == 'W') {
            while (r >= 0 && s[r] == 'W') --r;
            if (w < r) {
                swap(s[w], s[r]);
                ++res;
            } else {
                break;
            }
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3776
#include <iostream>

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

using namespace std;

int main(){
	string s;
	bool abc[3];
	REP(i,3) abc[i] = false;
	cin >> s;
	REP(i,3) abc[s[i]-97] = true;
	REP(i,3){
		if (!abc[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256