akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {

    set<char>a;
    SS(string,s);
    rep(i,4)a.insert(s[i]);
    Yes(a.size()==2);
}

Measured memory_bytes: 256
X, N = map(int, input().split())
try:
    P = list(map(int, input().split()))
except:
    P = []

tmp = 10**9
ans = 10**9

if P:
    for p in range(-20, 110):
        if p in P:
            continue
        abs_PX = abs(X-p)
        if abs_PX < tmp:
            ans = p
            tmp = abs_PX
else:
    ans = X

print(ans)


Measured memory_bytes: 9188
n=int(input())
a= [list(map(int, input().split())) for i in range(n)]
t,x,y=0,0,0
for i in a:
    e=i[0]-t
    l=abs(x-i[1])+abs(y-i[2])
    t,x,y=i
    if(e>=l and (e-l)%2==0):
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 27300
#(x,y)...xt+yが書かれる
from collections import deque
N,M=map(int,input().split())
G=[{} for i in range(N)]
for i in range(M):
    u,v,s=map(int,input().split())
    u-=1;v-=1
    G[u][v]=s;G[v][u]=s
H=[(0,0) for i in range(N)]
t=None
q=deque([0])
H[0]=(1,0)
while(q):
    r=q.pop()
    for p in G[r]:
        s=G[r][p]
        tmp=(-H[r][0],s-H[r][1])
        if H[p]==(0,0):
            H[p]=tmp
            q.append(p)
        elif H[p]==tmp:
            pass
        else:
            if H[p][0]==tmp[0]:
                print(0)
                exit()
            else:
                a=H[p][1]
                b=tmp[1]
                if H[p][0]==-1:
                    a,b=b,a
                #t+a=-t+b
                #2t=b-a
                if (b-a)%2:
                    print(0)
                    exit()
                else:
                    t=(b-a)//2
'''
t+a>=0:t>=-a
-t+b>=0:t<=b
inf=max(a)
sup=min(b)
'''
if t==None:
    inf=0
    sup=10**18
    for i in range(N):
        if H[i][0]==1:
            inf=max(inf,-H[i][1])
        else:
            sup=min(sup,H[i][1])
    print(max(sup-inf-1,0))
else:
    ans=[None for i in range(N)]
    q=deque([0])
    ans[0]=t
    while(q):
        r=q.pop()
        for p in G[r]:
            if ans[p]==None:
                ans[p]=G[r][p]-ans[r]
                q.append(p)
    flag=1
    for i in range(N):
        for j in G[i]:
            if ans[i]+ans[j]!=G[i][j]:
                flag=0
                break
        if flag==0:
            break
    if flag and min(ans)>0:
        print(1)
    else:
        print(0)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

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

int main(){
	int n;
	cin>>n;
	char ct[8][8];
	int dt[8][8];
	for(int i=0;i<n;i++){
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				cin>>ct[j][k];
				dt[j][k]=ct[j][k]-'0';
			}
		}
		int x,y;
		cin>>x>>y;
		queue<pair<int,int> > que;
		que.push(pair<int,int>(x-1,y-1));
		while(!que.empty()){
			int nowX=que.front().first;
			int nowY=que.front().second;
			dt[nowY][nowX]=0;
			que.pop();
			for(int p=-3;p<=3;p++){
				if((nowY+p)>=0 && (nowY+p)<8){
					if(dt[nowY+p][nowX]){
						dt[nowY+p][nowX]=0;
						que.push(pair<int,int>(nowX,nowY+p));
					}
				}
				if((nowX+p)>=0 && (nowX+p)<8){
					if(dt[nowY][nowX+p]){
						dt[nowY][nowX+p]=0;
						que.push(pair<int,int>(nowX+p,nowY));
					}
				}
			}
		}
		cout<<"Data "<<i+1<<":"<<endl;
		for(int j=0;j<8;j++){
			for(int k=0;k<8;k++){
				cout<<dt[j][k];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>

int main()
{
    int N;
    scanf("%d", &N);
    std::vector<long long> A(N);
    for(int i=0; i<N; i++) scanf(" %lld", &A[i]);

    long long sum = A[0], s_xor = A[0];
    long long count = 0;
    for(int i=0, j=0; j<N;){
        // printf("%d, %d, ", i, j);
        if(sum == s_xor){
            count += j-i+1; j++;
            sum += A[j]; s_xor ^= A[j];
        }
        else{
            sum -= A[i]; s_xor ^= A[i]; i++;
        }
        // printf("count = %lld\n", count);
    }

    printf("%lld\n", count);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    int a[n];
    int b[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        for(int j=0;j<m;j++)
        cin>>b[i][j];
    }
    int ans=INT_MAX;
    for(int i=0;i<(1<<n);i++)
    {
        int c[m];
        memset(c,0,sizeof(c));
        int sum=0;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                sum+=a[j];
                for(int k=0;k<m;k++)
                c[k]+=b[j][k];
            }
        }
        int f=0;
        for(int k=0;k<m;k++)
        {
            if(c[k]<x)
            f=1;
        }
        if(!f)
        ans=min(ans,sum);
    }
    if(ans!=INT_MAX)
    cout<<ans<<"\n";
    else
    cout<<-1<<"\n";
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static int gcd(int a,int b){
	if(b==0){return a;}
	return gcd(b,a%b);
}

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
        long n=s.nextLong();
         if(n%2l==1){out.write(0+"\n");}
        else{
        	long res=n/10,tmp=50l;
        	while(tmp<=n&tmp>0){
        		res+=n/tmp;
        		tmp=(long)tmp*5;
        	}
        	out.write(res+"\n");
        }
      
        
        out.flush();
  }
}


Measured memory_bytes: 22100
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

set <pii> Sx1;
set <pii> Sx2;
set <int> conn1[100050];
set <int> conn2[100050];

vector <pii> Vu;

int r[100050];
int root(int x) {
	return (x == r[x]) ? x : (r[x] = root(r[x]));
}
int cnt[100050];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn1[t1].insert(t2);
		conn1[t2].insert(t1);
		Sx1.emplace(t1, t2);
		Sx1.emplace(t2, t1);
		cnt[t1]++, cnt[t2]++;
	}
	for (i = 1; i < N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn2[t1].insert(t2);
		conn2[t2].insert(t1);
		if (Sx1.count(pii(t1, t2))) Vu.emplace_back(t1, t2);
		Sx2.emplace(t1, t2);
		Sx2.emplace(t2, t1);
		cnt[t1]++, cnt[t2]++;
	}
	
	for (i = 1; i <= N; i++) r[i] = i;
	for (i = 0; i < Vu.size(); i++) {
		int x = root(Vu[i].first), y = root(Vu[i].second);
		if (!Sx1.count(pii(x, y))) continue;

		if (cnt[x] > cnt[y]) swap(x, y);
		r[x] = y;
		cnt[y] += cnt[x];
		cnt[x] = 0;

		vector <pii> Vu3;
		Sx1.erase(pii(x, y));
		Sx1.erase(pii(y, x));
		vector <int> Vu2;
		for (auto it : conn1[x]) if (it != y) Vu2.push_back(it);
		conn1[x].clear();
		conn1[y].erase(x);
		for (auto it : Vu2) {
			conn1[it].erase(x);
			conn1[it].insert(y);
		}
		for (auto it : Vu2) {
			conn1[y].insert(it);
			Sx1.erase(pii(x, it));
			Sx1.erase(pii(it, x));
			Sx1.insert(pii(y, it));
			Sx1.insert(pii(it, y));
			if (Sx2.count(pii(y, it))) Vu3.emplace_back(y, it);
		}
		Vu2.clear();

		for (auto it : conn2[x]) if (it != y) Vu2.push_back(it);
		conn2[x].clear();
		conn2[y].erase(x);
		for (auto it : Vu2) {
			conn2[it].erase(x);
			conn2[it].insert(y);
		}
		for (auto it : Vu2) {
			conn2[y].insert(it);
			Sx2.erase(pii(x, it));
			Sx2.erase(pii(it, x));
			Sx2.insert(pii(y, it));
			Sx2.insert(pii(it, y));
			if (Sx1.count(pii(y, it))) Vu3.emplace_back(y, it);
		}
		Vu2.clear();

		for (auto it : Vu3) if (Sx1.count(it) && Sx2.count(it)) Vu.push_back(it);
	}
	for (i = 1; i <= N; i++) if (conn2[i].size()) return !printf("NO\n");
	return !printf("YES\n");
}

Measured memory_bytes: 50808
import math

def main():
    strA = input()
    listA = strA.split(" ")

    N = int(listA[0])
    K = int(listA[1])

    x = N
    y = 0
    while(1):
        x = math.floor(x/K)

        y = y + 1
        if(x < K):
            if (x != 0):
                y = y + 1
            break

    print(y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int compareInt(const void* a, const void* b)
{
    int aNum = *(int*)a;
    int bNum = *(int*)b;

    return aNum - bNum;
}

int equalNumCheck(int* array, size_t size)
{
  for (size_t i = 0; i < size-1; i++) {
    if (array[i] == array[i+1]) {
      return 1;
    }
  }
  return 0;
}

int main()
{
  int n;
  int text[101];
  int i,j,k;
  int list[3];
  int count=0;
  scanf("%d", &n);
  for (i=0; i<n; i++) {
    scanf("%d", &text[i]);
  }

  for (i=0; i<n-2; i++) {
    for (j=i+1; j<n-1; j++) {
      for (k=j+1; k<n; k++) {
        list[0]=text[i];
        list[1]=text[j];
        list[2]=text[k];
        qsort(list, SIZE_OF_ARRAY(list), sizeof(int), compareInt);
        if (!equalNumCheck(list, SIZE_OF_ARRAY(list))) {
          if (list[0]+list[1] > list[2]) {
            count++;
          }
        }
      }
    }
  }
  printf("%d", count);
  return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int64_t ans=1;
  int n=A.size()-K;
  ans+=n/(K-1);
  if(n%(K-1)!=0){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 896
let s = read_line ()
let ans = ref max_int
let f i = Char.code s.[i] - 48
let _ =
  for i = 0 to String.length s - 3 do ans := min !ans @@ abs @@ f i * 100 + f (i + 1) * 10 + f (i + 2) - 753 done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 2432
s = input()
s = s[::-1]
lis = ['remaerd', 'resare', 'esare', 'maerd']
i = 0
j = 0
#s = s[::-1]
while i < len(s):
    tmp = ''
    while j < len(s):
        tmp += s[j]
        #print(tmp)
        if len(tmp) == 8:
            print('NO')
            quit()
        elif tmp in lis:
            i = j + 1
            j = i
            break
        else:
            j += 1
print('YES')

Measured memory_bytes: 3188
def is_all_on(on_switches):
    on_cnt = 0
    for i in range(M):#電球の数
        cnt = 0
        for on in on_switches:
            if on in lights[i]: #i個目の電球と繋がってるスイッチの中にonになってるものがあるか
                cnt += 1
        if cnt % 2 == P[i]:        
            on_cnt += 1
    return True if on_cnt == M else False        
            
N,M = map(int,input().split())
lights = []
for m in range(M):
    lights.append(list(map(lambda x:int(x) - 1,input().split()))[1:])
P = list(map(int,input().split()))
#print(lights)

ans = 0
for i in range(1 << N): #スイッチon/offの全パターン数
    on_switches = []
    for j in range(N): #スイッチの数
        if ((i >> j) & 1) == 1: #１が立ってるスイッチがonのスイッチ
            on_switches.append(j) 
    if is_all_on(on_switches): ans += 1 #全ての電球が点灯しているかをチェック
    #print(i,on_switches)    
print(ans)    
            

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    string s, t;    cin >> s >> t;
    int ans = 99999;
    for (int i = 0; i < s.length(); i++) {
        if (t.length() + i > s.length())
            break;
        int tmp = 0;
        for (int j = 0; j < t.length(); j++) {
            if (s[i+j] != t[j])
                tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static ArrayList<Integer>[] edge;
	static long mod=1000000007;
	static long[][] dp;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		edge=new ArrayList[n];
		dp=new long[2][n];
		Arrays.fill(dp[0],1);
		Arrays.fill(dp[1],1);
		for(int i=0; i<n; i++){
			edge[i]=new ArrayList<>();
		}
		for(int i=1; i<n; i++){
			int x=sc.nextInt()-1;
			int y=sc.nextInt()-1;
			edge[x].add(y);
			edge[y].add(x);
		}
		dfs(0,0);
		System.out.println((dp[1][0]+dp[0][0])%mod);
	}
	static void dfs(int now,int from){
		for(int i:edge[now]){
			if(i!=from){
				dfs(i,now);
				dp[0][now]=(dp[0][now]*(dp[0][i]+dp[1][i]))%mod;
				dp[1][now]=dp[1][now]*dp[0][i]%mod;
			}
		}
	}
}

Measured memory_bytes: 117720
#include <unordered_set>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <cstring>
#include <cassert>
#include <fstream>
#include <climits>
#include <cstdio>
#include <vector>
#include <string>
#include <memory>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;


int main()
{
  int x,y;
  scanf("%d%d",&x,&y);
  if((x+y)%3==0||x%3==0||y%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;

void add_self(int& a, int b)
{
	a += b;
	if (a >= MOD)
	{
		a -= MOD;
	}
}

void sub_self(int& a, int b)
{
	a -= b;
	if (a < 0)
	{
		a += MOD;
	}
}



int main()
{

	FAST_IO;

	ll x, k;
	cin >> x >> k;
	ll p = x / k;
	cout << min(abs(x - p * k), min(abs(x - (p - 1)*k), abs(x - (p + 1)*k)));
	return 0;
}


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

int main(){
  int K,X,sum=0;
  cin >> K >> X;
  for(int i = 0;i<K;i++){
  		sum += 500;
    }
  if(sum >= X){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

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


int Judge(int i){
	int flag=1;
	for(int j=2;j<=sqrt(i);j++){
		if(i%j==0){
			flag=0;
		}
	}
	return flag;

}

int main() {	

	
	int n,a;
	int count=0;
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>a;
		if(Judge(a)){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3100
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
  int n, testcase = 0;
  while (scanf("%d", &n), n) {
    int x0, y0, x1, y1, x2, y2;
    scanf("%d%d%d%d", &x0, &y0, &x1, &y1);
    x1 -= x0; y1 -= y0;
    int area = 0;
    for (int i = 2; i < n; ++i) {
      scanf("%d%d", &x2, &y2);
      x2 -= x0; y2 -= y0;
      area += x1*y2 - x2*y1;
      x1 = x2; y1 = y2;
    }
    printf("%d %.1lf\n", ++testcase, fabs(area / 2.0));
  }
}

Measured memory_bytes: 0
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP LongestPath
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int n, m, x, y, ans;
vector<int> adj[100005];
int memo[100005];
bool visited[100005];
stack<int> topSort;

void dfs(int a)
{
    if (visited[a])
        return;
    visited[a] = 1;
    for (int i = 0; i < adj[a].size(); i++)
        dfs(adj[a][i]);
    topSort.push(a);
}

int dp(int a)
{
    if (memo[a])
        return memo[a];
    int res = 1;
    for (int i = 0; i < adj[a].size(); i++)
        res = max(res, 1 + dp(adj[a][i]));
    return memo[a] = res;
}

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        adj[x - 1].pb(y - 1);
    }
    for (int i = 0; i < n; i++)
        if (!visited[i])
            dfs(i);

    while (!topSort.empty())
    {
        ans = max(ans, dp(topSort.top()));
        topSort.pop();
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 14476
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
    int begin;
    int end;
} Range;

inline int length(Range r) {
    return r.end - r.begin + 1;
}

void shuffle(vector<Range> &ranges, int x, int y) {
    int count = 1;
    int pos_x;
    int pos_y;
    vector<Range> tmp;
    tmp.clear();

    for (int i=0; i < ranges.size(); i++) {
        int len = length(ranges[i]);
            
        if (count + len > x) {
             Range new_range;
             new_range.end = ranges[i].end;

             ranges[i].end -= (count + len - 1 - x);
             if (count + len - 1 != x) {
                 new_range.begin = ranges[i].end + 1;
                 ranges.insert(ranges.begin() + i+1, new_range);
             }

             pos_x = i+1;
             break;
        }

        count += len;
    }

    count = 1;
    for (int i=0; i < ranges.size(); i++) {
        int len = length(ranges[i]);

        if (count + len > y) {
            Range new_range;
            new_range.end = ranges[i].end;

            ranges[i].end -= (count + len - 1 - y);
            if (count + len - 1 != y) {
                new_range.begin = ranges[i].end + 1;
                ranges.insert(ranges.begin() + i+1, new_range);
            }

            pos_y = i+1;
            break;
        }

         count += len;
     }

     for (int i=pos_y; i < ranges.size(); i++) {
         tmp.push_back(ranges[i]);
     }

     for (int i=pos_x; i < pos_y; i++) {
         tmp.push_back(ranges[i]);
     }

     for (int i=0; i < pos_x; i++) {
         tmp.push_back(ranges[i]);
     }

     ranges.swap(tmp);
}

int main() {
    while (1) {
        int n;
        int m;
        int p, q, r;
        int count;
        int num;
        Range first_range;
        vector<Range> ranges(1);
    
        scanf("%d", &n);
        if (n == 0) return 0;

        scanf("%d", &m);
        scanf("%d %d %d", &p, &q, &r);
    
        first_range.begin = 1;
        first_range.end = n;
        ranges[0] = first_range;
    
        for (int i=0; i<m; i++) {
            int x, y;
    
            scanf("%d %d", &x, &y);
            shuffle(ranges, x, y);
        }

        num = 0;
        count = 1;
        for (vector<Range>::iterator itr = ranges.begin(); itr != ranges.end(); itr++) {
             int start;
             int end;
             int len = length(*itr);
    
             if (count > q) break;
    
             if (count + len > p) {
                 end = itr->end;
                 start = itr->begin;
    
                 if (count < p) {
                     start += (p - count);
                 } 
    
                 if (count + len > q) {
                     end -= (count + len - q - 1);
                 }
    
                 if (start <= r) {
                     if (end <= r) {
                         num += end - start + 1;
                     } else {
                         num += r - start + 1;
                     }
                 }
             }
    
             count += len;
        }

        printf("%d\n", num);   
    }
}

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

#define ll int long long
#define dll double long long
#define forei(i,n,x) for(int i=n;i<=x;i++)
#define fored(i,n,x) for(int i=n;i>=x;i--)
#define forni(i,n,x) for(int i=n;i<x;i++)
#define fornd(i,n,x) for(int i=n;i>x;i--)
#define SQ(a) (a)*(a)
#define MOD 1000000007
#define sortvi(v) sort(v.begin(),v.end())
#define sortvd(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pv(v) for(auto it: v) cout<<it
#define endl '\n'   //Take care in case of interactive problems
#define MAX1 100005
#define MAX2 200005
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

ll gcda(ll i, ll j ,ll k)
{
    ll temp;
    temp=gcd(i,j);
    temp=gcd(temp,k);
    return temp;
}

int main() 
{ 
   ll k;cin>>k;
   ll sum=0;
   forni(i,1,k+1)
   {
       forni(j,1,k+1)
       {
           forni(l , 1 ,k+1)
           {
               sum+=gcda(i,j,l);
           }
       }
   }
   cout<<sum<<endl;
   
   
    return 0; 
} 


Measured memory_bytes: 3636
building = [[[0 for i in range(10)] for i in range(3)]for i in range(4)]

n = input()

for i in range(n):
    b,f,r,v = map(int,raw_input().split())
    building[b-1][f-1][r-1] += v

for B in range(4):
    for F in range(3):
        print " "+ " ".join(map(str,building[B][F]))
    if B != 3:
        print "#"*20

Measured memory_bytes: 6464
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    vector<ll> x(n), y(n);

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

    set<ll> pp, pm, mp, mm;

    for (int i = 0; i < n; i++)
    {
        pp.insert(x[i] + y[i]);
        pm.insert(x[i] - y[i]);
        mp.insert(-x[i] + y[i]);
        mm.insert(-x[i] - y[i]);
    }

    cout << max({*pp.rbegin() - *pp.begin(), *pm.rbegin() - *pm.begin(), *mp.rbegin() - *mp.begin(), *mm.rbegin() - *mm.begin()}) << endl;
    ;
}


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

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

void solve(long long R, long long G, long long B, long long N){
    int counter = 0;
    rep(i, N / R + 1) {
        rep(j, (N - i*R) / G + 1) {
            if ((N - i*R - j*G) % B == 0) {
                counter++;
            }
        }
    }
    cout << counter << endl;
}

int main(){
    long long R;
    scanf("%lld",&R);
    long long G;
    scanf("%lld",&G);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    solve(R, G, B, N);
    return 0;
}


Measured memory_bytes: 256
from math import ceil

n,h= map(int,input().split())
A=[]
B=[]

for _ in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

max_a = max(A)

finish = []
for b in B:
  if b > max_a:
    finish.append(b)    
    
ans = 0
if sum(finish) < h :
  ans += len(finish)
  ans += ceil((h-sum(finish))/max_a)
else:
  damage = 0
  for d in sorted(finish,reverse=True):
    damage += d
    ans += 1
    if damage >= h:
      break

print(ans)      

Measured memory_bytes: 12936
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

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

	int N, M, K;

	int P[200000];
	int A[200001];
	cin >> N;
	rep(i, 0, N) {
		int a;
		cin >> a;
		P[i] = a;
		A[a] = i;
	}

	int ans = 0;
	rep(i, 0, N) {
		int x = P[i];
		if (A[x] == -1)
			continue;
		A[x] = -1;
		int score = 1;
		int pos = i;
		for (j = x+1; j <= N; j++) {
			if (A[j] == -1) {
				break;
			}
			else if (A[j] > pos) {
				score++;
				pos = A[j];
				A[j] = -1;
			}
			else {
				break;
			}


		}
		ans = max(ans, score);
	}
	cout << N - ans;

	return 0;
}

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

using namespace std;

int main()
{
    int n, l;
    int sum = 0;
    int sa = 100010, ans = 100010;

    cin >> n >> l;

    for (int i = 1; i <= n; i++) {
        sum += l+i-1;
    }

    for (int i = 1; i <= n; i++) {
        int tmp = sum;
        tmp -= (l+i-1);
        if (abs(sum - tmp) < sa) {
            sa = abs(sum - tmp);
            ans = tmp;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

void dfs(vector<int> G[], int node, vector<bool> &visited, vector<int> &topo){
    visited[node] = true;
    for(auto e: G[node]){
        if(!visited[e])
            dfs(G, e, visited, topo);
    }
    topo.push_back(node);
}

int main(){
    int N, M;
    cin >> N >> M;

    vector<int> G[N+1];
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
    }

    vector<int> topo;
    vector<bool> visited(N+1, false);
    for(int i=1; i<=N; i++){
        if(!visited[i]){
            dfs(G, i, visited, topo);
        }
    }

    reverse(topo.begin(), topo.end());

    vector<int> dp(N+1, 0);
    for(auto v:topo){
        for(auto u:G[v]){
            dp[u] = max(dp[u], dp[v] + 1);
        }
    }

    int ans = 0;
    for(auto p:dp){
        ans = max(ans, p);
    }

    cout << ans << "\n";

    return 0; 
} 

Measured memory_bytes: 10104
N, M = map(int, input().split())
s = [0 for i in range(M)]
for i in range(M):
    s[i] = list(map(int, input().split()))
ex = [[0] * 2 for i in range(N)]
for i in range(M):
    if s[i][0] == 1:
        ex[(s[i][1] - 1)][0] = 1
    if s[i][1] == N:
        ex[(s[i][0] - 1)][1] = 1
if [1, 1] in ex:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 66136
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  vector<ll>vec(a);
  for(ll i=1;i<=a;i++){
    ll b;
    cin>>b;
    vec.at(b-1)=i;
  }
  for(ll i=0;i<a;i++){
    cout<<vec.at(i)<<' ';
  }
  cout<<endl;
  return 0;
  
  
      
                        
                        
}


Measured memory_bytes: 3984
#include<stdio.h>

int main(){
  int n,i,j,k,l,m;
  int M1[101], M2[101][101];

  scanf("%d",&n);
  for(i=1; i<=n; i++)

    scanf("%d%d",&M1[i-1],&M1[i]);

  for(i=1; i<=n; i++)
    M2[i][i] = 0;

  for(j=2; j<=n; j++){

    for(i=1; i<=n-j+1; i++){
      l = i+j-1;
      M2[i][l] = 1000000;

      for(k=i; k<=l-1; k++){
	m = M2[i][k] + M2[k+1][l] + M1[i-1]*M1[k]*M1[l];
	if(M2[i][l] >= m)
	  M2[i][l] = m;
      }
    }
  }

  printf("%d\n",M2[1][n]);

  return 0;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

int n, k, c;
string s;
vector<int> ans;

bool ok(int i){
    return s[i] == 'o';
}


void solve() {
    // 最短を探す
    vector<int> min_route;
    int last = 0;
    for(int i=0;i<k;i++){
        // cout << "i=" << i << endl;
        int start;
        if(i == 0){
            start = 0;
        }else{
            start = last+1+c;
            // cout << "st: " << start << endl;
        }

        for(int j=start;j<n;j++){
            if(ok(j)){
                min_route.push_back(j);
                last = j;
                // cout << "last: " << last << endl;
                break;
            }
        }
    }
    for(auto& v :min_route){
        // cout << v << endl;
    }

    // 最遅を探す
    vector<int> max_route;
    for(int i=k-1;0<=i;i--){
        // cout << "i=" << i << endl;
        int start;
        if(i == k-1){
            start = n-1;
        }else{
            start = last-1-c;
            // cout << "st: " << start << endl;
        }

        for(int j=start;0<=j;j--){
            if(ok(j)){
                max_route.push_back(j);
                last = j;
                // cout << "last: " << last << endl;
                break;
            }
        }
    }
    for(auto& v :min_route){
        // cout << v << endl;
    }

    for(int i=0;i<k;i++){
        if(min_route[i] == max_route[k-i-1]){
            cout << min_route[i] + 1 << endl;
        }
    }
}

int main(){
    cin >> n >> k >> c;
    cin >> s;

    solve();

    return 0;
}


Measured memory_bytes: 3448
#include<iostream>
#include<cstdio>

using namespace std;
#define MAX 100000
int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return i * 2 + 1; }

int main(){
	int H, i, A[MAX + 1];
	cin>>H;
	for (i = 1;i <= H;i++) {
		cin >> A[i];
	}
	for (i = 1;i <= H;i++) {
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1) {
			cout << "parent key = " << A[parent(i)] << ", ";
		}
		if (left(i) <= H) {
			cout << "left key = " << A[left(i)] << ", ";
		}
		if (right(i) <= H) {
			cout << "right key = " << A[right(i)] << ", ";
		}
		cout << endl;
	}
	return 0;

}


Measured memory_bytes: 3092
n=int(input())
for _ in range(n):
    y,m,d=list(map(int,input().split()))
    c=0
    for i in range(1,y):
        if i%3:c+=195
        else:c+=200
    for i in range(1,m):
        if y%3:
            if i%2:c+=20
            else:c+=19
        else:
            c+=20
    c+=(d-1)
    print(196470-c)


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    if(s.size() <= 2){
        puts("0");
        return 0;
    }
    int n = s.size();
    s += "X";
    string t;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'B' && s[i+1] == 'C') t += "X", i++;
        else t += s[i];
    }
    ll ans = 0, x = 0;
    for (auto &&j : t) {
        if(j == 'A') x++;
        else if(j == 'X') ans += x;
        else x = 0;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 776
#include <iostream>

int main(int argc, char *argv[]) {
  int a, b, c, k;
  std::cin >> a >> b >> c >> k;
  int xa = std::min(a, k);
  k -= xa;
  int xb = std::min(b, k);
  k -= xb;
  int xc = k;
  int sum = xa - xc;
  std::cout << sum << std::endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

ll gcd_func(ll a, ll b) {
    if (a < b) return gcd_func(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm_func(ll a, ll b) {
    return a / gcd_func(a, b) * b;
}

int main() {
    ll N, M, ans = 0;
    cin >> N >> M;
    vi A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll a = 0, c = 1;
    while (A[0] % 2 == 0) {
        A[0] /= 2;
        a++;
        c *= 2;
    }
    for (ll i = 1; i < N; i++) {
        ll b = 0;
        while (A[i] % 2 == 0) {
            A[i] /= 2;
            b++;
        }
        if (a != b) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll l = 1;
    for (ll i = 0; i < N; i++) {
        l = lcm_func(l, A[i]);
    }

    ans = ceil(double(floor(M / (l*c/2))) / 2);
    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

/////////////         modの計算

#define MOD_IS_PRIME
const ll mod = 1000000007LL;

class modlong {
public:
	modlong() { x = 0; }
	modlong(ll num) { x = adjust(num); }
	inline operator ll() const { return x; }
	inline bool operator ==(ll num) { return this->x == num; }
	inline bool operator !=(ll num) { return !(*this == num); }
	inline void operator = (ll num) { x = adjust(num); }
	inline void operator += (ll num) { x = adjust(x + num); }
	inline void operator ++() { this->operator+=(1); }
	inline modlong operator + (ll num) const { modlong m(this->x); m += num; return m; }
	inline void operator -= (ll num) { x = adjust(x - num); }
	inline void operator --() { this->operator-=(1); }
	inline modlong operator - (ll num) { modlong m(this->x); m -= num; return m; }
	inline void operator *= (ll num) { x = adjust(x * num); }
	inline modlong operator * (ll num) { modlong m(this->x); m *= num; return m; }
private:
	inline ll adjust(ll a) {
		if (a >= mod) { return a % mod; }
		if (a < 0) { return mod - 1 + ((a + 1) % mod); }
		return a;
	}
	ll x;
};

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

	constexpr int K = 16;

	vector<modlong> v_e = { 0, 765144583, 346175634, 347662323, 5655049, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };
	vector<modlong> v_o = { 539588932, 729548371, 700407153, 404391958, 962779130, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };

	int T, N; cin >> T;
	for (int _t = 0; _t < T; _t++) {
		cin >> N;
		modlong x = N;
		if (N % 2 == 0) {// even
			modlong ans = v_e[K - 1];
			for (int i = K - 2; i >= 0; i--) {
				ans *= x;
				ans += v_e[i];
			}
			cout << (ll)ans << endl;
		}
		else {// odd
			modlong ans = v_o[K - 1];
			for (int i = K - 2; i >= 0; i--) {
				ans *= x;
				ans += v_o[i];
			}
			cout << (ll)ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define NIL -1
using namespace std;
  
typedef struct{
    int key;
    int right;
    int left;
    int parent;
}node;
  
void insert(vector<node> &T, int i, int *root) {
    int x=*root, y = NIL;
    while(x != NIL){
        y = x;
        T[i].key<T[x].key?x=T[x].left:x=T[x].right;
    }
    T[i].parent = y;
    if(y == NIL) *root = i;
    else if(T[i].key < T[y].key) T[y].left = i;
    else T[y].right = i;
}
 
void inorder(vector<node> &T, int i){
    if(T[i].left != NIL) 
        inorder(T,T[i].left);
    cout << " " << T[i].key;
    if(T[i].right != NIL)
        inorder(T,T[i].right);
}
  
void preorder(vector<node> &T, int i){
    cout << " " << T[i].key;
    if(T[i].left != NIL)
        preorder(T,T[i].left);
    if(T[i].right != NIL)
        preorder(T,T[i].right);
}
  
int find(vector<node> &T, int i, int k) {
    int result = NIL;
    if(T[i].key == k) return i;
    else if(T[i].key > k) {
        if(T[i].left != NIL)
            result = find(T,T[i].left,k);
    } else if(T[i].key < k) {
        if(T[i].right != NIL)
            result = find(T,T[i].right,k);
    }
    return result;
}
 
int minimum(vector<node> &T,int a){
    while(T[a].left != NIL) a = T[a].left;
    return a;
}
 
int successor(vector<node> &T, int z){
    int x = T[z].parent,y;
    if(T[z].right != NIL) return minimum(T,T[z].right);
    while(1) {
        if(x != NIL && T[x].right == z) break;
        y = x;
        x = T[x].parent;
    }
    return x;
}
 
void erase(vector<node> &T, int *root, int z){
    int x,y;
    T[z].left==NIL||T[z].right==NIL?y = z:y = successor(T,z);
    T[y].left!=NIL?x=T[y].left:x=T[y].right;
 
    if(x != NIL) T[x].parent = T[y].parent;
    if(T[y].parent == NIL) *root=x;
    else if(y == T[T[y].parent].left) T[T[y].parent].left = x;
    else T[T[y].parent].right = x;
 
    if(y!=z) T[z].key = T[y].key;
    T[y].parent = NIL;
    T[y].left = NIL;
    T[y].right = NIL;
    T[y].key = 0;
}
 
int main(void) {
    int judge,n,i,x,root=NIL;
    string od;
    vector<node> T;
    cin >> n;
    T.resize(n);
    rep(i,n) {
        T[i].key = 0;
        T[i].right = NIL;
        T[i].left = NIL;
        T[i].parent = NIL;
    }
    rep(i,n){
        cin >> od;
        if(od == "insert"){
            cin >> T[i].key;
            insert(T,i,&root);
        } else if(od == "print") {
            inorder(T,root);
            cout << endl;
            preorder(T,root);
            cout << endl;
        } else if(od == "find") {
            cin >> x;
            judge = find(T,root,x);
            if(judge != NIL) cout << "yes";
            else cout << "no";
            cout << endl;
        } else if(od == "delete"){
            cin >> x;
            judge = find(T,root,x);
            if(judge != NIL) erase(T,&root,judge);
        }
    }
    return 0;
}

Measured memory_bytes: 8984
/**
	Language: C++ 11
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FASTIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define DEBUG(var) cerr << '\n' << #var << "\t:\t" << var << '\n'
#define FORF(i, L, U) for (ll i = (L); i <= (U); ++i)
#define FORR(i, U, L) for (ll i = (U); i >= (L); --i)
#define FORE(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	FASTIO();
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (char c : s) {
    if (c == 'A')++a;
    else ++b;
  }
  if (a == 0 || b == 0) cout << "No\n";
  else cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int n;
map<string, int> mp;
int main() {
    scanf("%d", &n);
    string s = "";
    for(int i = 1; i <= n; ++i) {
        s += to_string(i);
    }
    int idx = 1;
    do {
        mp[s] = idx;
        idx++;
    } while(next_permutation(s.begin(), s.end()));
    string a = "", b = "";
    for(int i = 0; i < n; ++i) {
        int d;
        scanf("%d", &d);
        a += to_string(d);
    }
    for(int i = 0; i < n; ++i) {
        int d;
        scanf("%d", &d);
        b += to_string(d);
    }
    int pa = mp[a], pb = mp[b];
    int ans = abs(pa - pb);
    printf("%d\n", ans);
    return 0;
}

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

#define ll long long int
using namespace std;
int main()
{
    int n,m=INT_MAX;
    string s,x;
    cin>>s;
    for(int i=0;i<=s.size()-3;i++)
    {
        x = s.substr(i,3);

        stringstream ss(x);
        ss>>n;
        m = min(m,abs(n-753));
    }
    cout<<m<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll sumR[4010], sumG[4010], sumB[4010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    REP(i, 0, N) {
        if (S[i] == 'R') {
            sumR[i]++;
        } else if (S[i] == 'G') {
            sumG[i]++;
        } else {
            sumB[i]++;
        }
        if (i > 0) {
            sumR[i] += sumR[i - 1];
            sumG[i] += sumG[i - 1];
            sumB[i] += sumB[i - 1];
        }
    }
    ll ans = 0;
    REP(i, 0, N) {
        REP(j, i + 1, N) {
            if (S[i] == S[j]) {
                continue;
            }
            if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
                ans += sumB[N - 1] - sumB[j];
                if (j + (j - i) < N && S[j + (j - i)] == 'B') {
                    ans--;
                }
            }
            if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
                ans += sumR[N - 1] - sumR[j];
                if (j + (j - i) < N && S[j + (j - i)] == 'R') {
                    ans--;
                }
            }
            if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
                ans += sumG[N - 1] - sumG[j];
                if (j + (j - i) < N && S[j + (j - i)] == 'G') {
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3700
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,t;
    cin>>n>>t;
    int min=t;
    int ans=inf;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if(a<=ans&&b<=t){
            ans=a;
        }
    }
    if(ans!=inf)cout<<ans<<endl;
    else cout<<"TLE"<<endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,weight=map(int,input().split())
    WV=[tuple(map(int,input().split())) for i in range(n)]
    dp=[[0]*(weight+1) for _ in range(n+1)] #品物iまでについて，ナップサックの重さの総和がjのときの価値の総和
    for i in range(n):
        ni=i+1
        w,v=WV[ni-1]
        for j in range(weight+1):
            dp[ni][j]=max(dp[ni][j],dp[i][j])
            if j+w<=weight and (j==0 or dp[i][j]>0):
                dp[ni][j+w]=max(dp[ni][j+w],dp[i][j]+v)
    print(max(dp[n]))
            



if __name__=='__main__':
    main()

Measured memory_bytes: 118384