akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
int main()
{
	std::vector<std::string>result;
	for (std::string s; std::getline(std::cin, s);)
	{
		int delta = 0;
		std::stringstream ss;
		ss << s;
		while (!ss.eof())
		{
			std::string temp;
			ss >> temp;
			if (temp.length() == 3 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.')
			{
				int d1 = temp[0] - 't';
				int d2 = temp[1] - 'h';
				int d3 = temp[2] - 'e';
				for (auto i : { &d1,&d2,&d3 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3)
				{
					delta = temp[0] - 't';
					break;
				}
			}
			else if (temp.length() == 4 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.' && temp[3] != '.')
			{
				int d1 = temp[0] - 't';
				int d2 = temp[1] - 'h';
				int d3 = temp[2] - 'i';
				int d4 = temp[3] - 's';
				for (auto i : { &d1,&d2,&d3,&d4 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3 && d3 == d4)
				{
					delta = temp[0] - 't';
					break;
				}
				d1 = temp[0] - 't';
				d2 = temp[1] - 'h';
				d3 = temp[2] - 'a';
				d4 = temp[3] - 't';
				for (auto i : { &d1,&d2,&d3,&d4 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3 && d3 == d4)
				{
					delta = temp[0] - 't';
					break;
				}
			}
		}
		result.push_back(std::string(s.length(), 'a'));
		for (int i = 0; i < s.length(); i++)
		{
			result.back()[i] = 'a' <= s[i] && s[i] <= 'z' ? (s[i] - delta - 'a') % 26 + 'a' : s[i];
		}
	}
	for (auto i : result)
	{
		std::cout << i << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3120
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();

		pr.println((a + b + 1) / 2);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23124
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    String t = sc.next();
    if (t.startsWith(s)) {
      pw.println("Yes");
    } else {
      pw.println("No");
    }
  }
}


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

int main() {
  int N;
  int t[110000], x[110000], y[110000];
  cin >> N;
  t[0] = x[0] =y[0] = 0;
  for (int i = 0; i<N; i++) cin >> t[i+1] >> x[i+1]>>y[i+1];
  bool can = true;
  
  for (int i = 0; i< N; i++) {
    int dt = t[i+1] -t[i];
    int dist = abs(x[i+1]-x[i]) + abs(y[i+1] -y[i]);
    if (dt < dist) can = false;
    if (dist %2 != dt % 2) can = false;
  }
  
  if (can) cout <<"Yes" << endl;
  else cout << "No "<< endl;
}
  
    

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, a[21], b[21], c[20] = { 0 }, back = 0, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i <= n - 1; i++) {
		cin >> c[i];
	}

	for (int i = 1; i <= n; i++) {
		ans += b[a[i]];
		if (a[i] - 1 == back)ans += c[a[i]- 1];
		back = a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int N=200;
const int W=1000000000;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s,t;
	int lmax=0,l=0;
	cin >> s >> t;
	string sb;
	int i,ok;
	for(i=s.size()-t.size();i>=0;i--){
		sb = s.substr(i,t.size());
		ok=1;
		for(int j=0;j<t.size();j++){
			if(sb[j]!=t[j] && sb[j]!='?'){
				ok=0;
			}
		}
		if(ok==1)break;
	}

	if(ok==0){
		cout << "UNRESTORABLE" << endl;
	}else{
		for(int j=0;j<s.size();j++){
			if(j>=i && j+1<=i+t.size()){
				cout << t[j-i];
			}else{
				if(s[j]=='?'){
					cout << 'a';
				}else{
					cout << s[j];
				}
			}
		}
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    string str;
    cin >> str;
    str[K-1] += 'a' - 'A';
    cout << str << endl;
    return 0;
}


Measured memory_bytes: 256
#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 L, R, d;
    cin >> L >> R >> d;

    cout << R / d - (L - 1) / d << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class FSimplifiedReversi {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, Q;
        cin >> N >> Q;
        set<pair<int, int>> col, row;
        col.insert({N, N});
        row.insert({N, N});
        int num = 0;
        REP(i, Q) {
            int type, x;
            cin >> type >> x;
            if (type == 1) {
                auto itr = col.upper_bound({x, N});
                int to = itr->second;
                num += to - 2;
                row.insert({to, x});
            } else {
                auto itr = row.upper_bound({x, N});
                int to = itr->second;
                num += to - 2;
                col.insert({to, x});
            }
        }
        cout << (N-2) * (N-2) - num << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FSimplifiedReversi solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 16116
#include<vector>
#include<string>
#include<cstdint>

class RollingHash{
    using uint = uint_fast64_t;
    const uint MASK30 = (1UL << 30) - 1;
    const uint MASK31 = (1UL << 31) - 1;
    const uint MOD = (1UL << 61) - 1;
    const uint POSITIVIZER = MOD * ((1UL << 3) - 1);
    uint Base = 1007;
    std::vector<uint> powMemo;
    std::vector<uint> hash;
public:
    RollingHash() = delete;
    RollingHash(std::string& s) : powMemo(s.length()+1), hash(s.length()+1){   
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.size(); i++){
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
        }
        for (int i = 0; i < s.length(); i++){
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
        }
    }

    uint Slice(int begin, int length){
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    uint Mul(uint l, uint r){
        uint lu = l >> 31;
        uint ld = l & MASK31;
        uint ru = r >> 31;
        uint rd = r & MASK31;
        uint middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) +(middleBit >> 30);
    }

    uint CalcMod(uint val){
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
};

#include<iostream>
#include<map>

using namespace std;
int main(){
    int N;
    string S;
    cin >> N >> S;
    RollingHash A(S);
    using uint = uint_fast64_t;
    map<uint, int> mp;
    
    auto check = [&](uint len) -> bool {
        for(int left=0;left+len<=N;left++){
            uint hash = A.Slice(left, len);
            if(mp.count(hash)){
                if(left - mp[hash] >= len) return true;
            } else {
                mp[hash] = left;
            }
        }
        return false;
    };

    uint low = 0, high = N/2 + 1;
    while(high - low > 1){
        uint mid = (low + high) >> 1;
        if(check(mid)) low = mid;
        else high = mid;
    }

    cout << low << endl;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

typedef pair<int, int> P;

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> s[i][j];
    }
  }
  ll ans = -1;
  for (int sy = 0; sy < h; ++sy) {
    for (int sx = 0; sx < w; ++sx) {
      if (s[sy][sx] == '#') continue;
      ll dist[h][w];
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; ++j) {
          dist[i][j] = -1;
        }
      }
      queue<P> que;
      dist[sy][sx] = 0;
      que.push(P(sy, sx));
      while (que.size()) {
        P p = que.front();
        que.pop();
        int y = p.first, x = p.second;
        for (int d = 0; d < 4; ++d) {
          int ny = y + dy[d], nx = x + dx[d];
          if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
          if (s[ny][nx] != '#' && dist[ny][nx] == -1) {
            que.push(P(ny, nx));
            dist[ny][nx] = dist[y][x] + 1;
          }
        }
      }
      ll res = -1;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; ++j) {
          if (s[i][j] == '.') {
            res = max(res, dist[i][j]);
          }
        }
      }
      if (res != -1) ans = max(ans, res);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int a, b;
	while(cin >> a >> b){
		int p = a, q = b, r;
		while(q)
			r = p % q, p = q, q = r;
		cout << p << " " << a / p * b / p * p << endl; 
	}
	return 0;
}


Measured memory_bytes: 3048
l,r = [int(i) for i in input().split()]
ans = 100000
L = min(r,l+2019)
for i in range(l,L):
    R = min(l+2019,r)
    for j in range(i+1,R+1):
        tmp = (i*j)%2019
        if(ans>tmp):
            ans = tmp
print(ans)

Measured memory_bytes: 3188
from operator import itemgetter
from heapq import heappush, heappop

a,b = map(int, input().split())
li=[]
for i in range(b):
    s,f = map(int, input().split())
    li.append((s,f))

li = sorted(li, key=itemgetter(1), reverse=False)

ans = 1
t = li[0][1]
#print(li)
for i in range(1,b):
    if t <= li[i][0]:
        ans+=1
        t = li[i][1]
print(ans)


Measured memory_bytes: 19116
def main():
    N = int(input())

    S = []
    d = {}
    ans = 0
    for _ in range(N):
        t = input()
        t = "".join(sorted(t))
        if t in d:
            ans += d[t]
            d[t] += 1
        else:
            d[t] = 1

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 22280
#include <iostream>

using namespace std;


string myUnion(string a,string b)
{
    string res="";
    int i = 0, j = 0;
    int d1 = 0, d2 = 0;
    while(i < a.size() || j < b.size())
    {
        if(d1 > d2 || j >= b.size())
        {
            if(a[i] == '(') d1++;
            else if(a[i] == ')') d1--;
            res+=a[i++];
        }
        else if(d2 > d1|| i >= a.size())
        {
            if(b[j] == '(') d2++;
            else if(b[j] == ')') d2--;
            res+=b[j++];
        }
        else
        {
            if(a[i] == b[j])
            {
                if(a[i] == '(')
                {
                    d1++;
                    d2++;
                }
                else if(a[i] == ')')
                {
                    d1--;
                    d2--;
                }
                res+=a[i++];
                j++;
            }
            else if(a[i] == '(' || b[j] == ')')
            {
                if(a[i] == '(') d1++;
                else if(a[i] == ')') d1--;
                res+=a[i++];
            }
            else
            {
                if(b[j] == '(') d2++;
                else if(b[j] == ')') d2--;
                res+=b[j++];
            }
        }
    }
    return res;
}

string myIntersection(string a,string b)
{
    string res="";
    int i = 0, j = 0;
    int d1 = 0, d2 = 0;
    while(i < a.size() || j < b.size())
    {
        if(d1 > d2 || j >= b.size())
        {
            if(a[i] == '(') d1++;
            else if(a[i] == ')') d1--;
            i++;
        }
        else if(d2 > d1|| i >= a.size())
        {
            if(b[j] == '(') d2++;
            else if(b[j] == ')') d2--;
            j++;
        }
        else
        {
            if(a[i] == b[j])
            {
                if(a[i] == '(')
                {
                    d1++;
                    d2++;
                }
                else if(a[i] == ')')
                {
                    d1--;
                    d2--;
                }
                res+=a[i++];
                j++;
            }
            else if(a[i] == '(' || b[j] == ')')
            {
                if(a[i] == '(') d1++;
                else if(a[i] == ')') d1--;
                i++;
            }
            else
            {
                if(b[j] == '(') d2++;
                else if(b[j] == ')') d2--;
                j++;
            }
        }
    }
    return res;
}


int main()
{
   string op,s1,s2;
   while(cin>>op>>s1>>s2)
   {
       if(op=="i") cout<<myIntersection(s1,s2)<<endl;
       else cout<<myUnion(s1,s2)<<endl;
   }
}

Measured memory_bytes: 1196
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int h,w,n;
    R(h,w,n);
    W((n+max(h,w)-1)/max(h,w));
    return 0;
}


Measured memory_bytes: 256
def main():
    from collections import deque

    N = int(input())
    *a, = map(int, input().split())

    b = [0] * (10 ** 5 + 10)
    for x in a:
        b[x] += 1

    dq = deque()
    b_iter = iter(b)
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    t = sum(dq)
    ans = t
    for x in b:
        dq.append(x)
        y = dq.popleft()
        t = t + x - y
        if ans < t:
            ans = t
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14220
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int ask(int i, int j) {
	cout << "? " << i + 1 << " " << j + 1 << endl;
	cout << flush;
	cin >> i;
	return i;
}
signed main() {
	int N, S, T;;
	cin >> N >> S >> T;
	S--; T--;
	vector<int> res;
	int len = ask(S, T);


	vector<pair<int, int> > vp;
	for (int i = 0; i < N; i++) {
		if (i != S && i != T) {
			int a = ask(S, i);
			int b = ask(i, T);
			if (a + b == len) {
				vp.emplace_back(a, i);
			}
		}
	}
	vp.emplace_back(len, T);
	sort(vp.begin(), vp.end());

	
	res.push_back(S);
	res.push_back(vp[0].second);
	int cur = 0;
	for (int i = 1; i < vp.size(); i++) {
		int t = ask(vp[cur].second, vp[i].second);
		if (vp[cur].first + t + (len - vp[i].first) == len) {
			res.push_back(vp[i].second);
			cur = i;
		}

	}


	cout << "!";
	for (int i = 0; i < res.size(); i++) {
		cout << " " << res[i] + 1;
	}
	cout << endl;
	cout << flush;
}


Measured memory_bytes: 4652
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

cnt = 0
ans = []
for h in range(H - 1):
    for w in range(W):
        if A[h][w] % 2 == 1:
            cnt += 1
            ans.append((h, w, h + 1, w))
            A[h + 1][w] += 1
            A[h][w] -= 1

for w in range(W - 1):
    if A[H - 1][w] % 2 == 1:
        cnt += 1
        ans.append((H - 1, w, H - 1, w + 1))
        A[H - 1][w + 1] += 1
        A[H - 1][w] -= 1

print(cnt)
for a, b, c, d in ans:
    print(a + 1, b + 1, c + 1, d + 1)


Measured memory_bytes: 22796
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,m;
ll l,d1[310][310],d2[310][310];

void solve(){
  cin >> n >> m >> l;
  rep(i,n){
    rep(j,n){
      d1[i][j]=INF;
    }
    d1[i][i]=0;
  }
  rep(i,m){
    int a,b,c;cin >> a >> b >> c;a--;b--;
    d1[a][b]=c;
    d1[b][a]=c;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(d1[i][j]>d1[i][k]+d1[k][j]){
          d1[i][j]=d1[i][k]+d1[k][j];
        }
      }
    }
  }
  rep(i,n){
    rep(j,n){
      if(d1[i][j]<=l){
        d2[i][j]=1;
      }
      else{
        d2[i][j]=INF;
      }
    }
    d2[i][i]=0;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(d2[i][j]>d2[i][k]+d2[k][j]){
          d2[i][j]=d2[i][k]+d2[k][j];
        }
      }
    }
  }
  int q;cin >> q;
  rep(i,q){
    int s,t;cin >> s >> t;s--;t--;
    if(d2[s][t]==INF){
      cout << -1 << endl;
    }
    else{
      cout << d2[s][t]-1 << endl;
    }
  }
}

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

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

int main(){
    string S; cin >> S;
    Int K; cin >> K; K--;

    Int not1;
    rep(i, S.length()){
        if(S[i] != '1') {not1 = i; break;}
    }

    if(not1 > K) cout << 1 << endl;
    else cout << S[not1] << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"index/suffixarray"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	s := getNextString(scanner)
	bb := []byte(s)
	sa := suffixarray.New(bb)

	l := 0
	r := n>>1 + 1
	for l+1 < r {
		m := (l + r) >> 1
		ok := false
		for i := 0; i+m <= n; i++ {
			index := sa.Lookup(bb[i:i+m], -1)
			if len(index) == 0 {
				continue
			}
			for _, v := range index {
				if v < i+m {
					continue
				}
				ok = true
				break
			}
		}
		if ok {
			l = m
			continue
		}
		r = m
	}

	fmt.Fprintln(writer, l)
}


Measured memory_bytes: 12928
N,A,B,C=map(int,input().split())
L=[]
for i in range(0,N):
    L.append(int(input()))

ans=float('inf')
for i in range(0,4**N):
    a=0
    b=0
    c=0
    MP=0
    for j in range(0,16):
        if i>>(2*j) & 1==1 and i>>(2*j+1) &1==0:
            a+=L[j]
            MP+=10
        elif i>>(2*j) & 1==0 and i>>(2*j+1) &1==1:
            b+=L[j]
            MP+=10
        elif i>>(2*j) & 1==1 and i>>(2*j+1) &1==1:
            c+=L[j]
            MP+=10

    if a*b*c==0:
        continue
    else:
        MP-=30
        MP+=abs(a-A)+abs(b-B)+abs(c-C)
        ans=min(MP,ans)

print(ans)

Measured memory_bytes: 45292
#include <iostream>
using namespace std;
int main(){
  int N, ans = 0;
  cin >> N;
  int A = N / 4, B = N / 7;
  bool flag = false;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      ans = i * 4 + j * 7;
      if(ans == N) {
        flag = true;
      }
    }
  }
  if(flag){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    char a; cin >> a;
    if(islower(a)) cout << 'a' << endl;
    else cout << 'A' << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long int
void solve() {
    int x; cin >> x;
    if(x >= 30){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }   
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    //Starts here , 
                
    
        solve();
    
    return 0;
            
}

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

int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);

    long long n, a, b; cin>>n>>a>>b;
    vector<int> x(n); for(int& e: x) cin>>e;

    auto res=0LL;
    for(int i=1; i<n; ++i)
        res+=min((x[i]-x[i-1])*a, b);
    cout<<res<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
    int j, N, i, masatoy[5], koutay[5] = { 0,0,0,0,0 }, kaolin = 1, temp, L, S,ruito;
    scanf("%d", &N);
    while (1) {
        if (N == 0000) {
            break;
        }
        ruito = N;
        if (ruito == 6174) {
            printf("0\n");
            scanf("%d", &N);
            kaolin = 1;
        }
        else {
            masatoy[1] = N / 1000;
            N = N - (1000 * masatoy[1]);
            masatoy[2] = N / 100;
            N = N - (100 * masatoy[2]);
            masatoy[3] = N / 10;
            N = N - (10 * masatoy[3]);
            masatoy[4] = N;
            for (i = 1; i < 4; i++) {
                for (j = 4; j > i; j--) {
                    if (masatoy[j] > masatoy[j - 1]) {
                        temp = masatoy[j];
                        masatoy[j] = masatoy[j - 1];
                        masatoy[j - 1] = temp;
                    }
                }
            }


            L = masatoy[1] * 1000 + masatoy[2] * 100 + masatoy[3] * 10 + masatoy[4];
            S = masatoy[4] * 1000 + masatoy[3] * 100 + masatoy[2] * 10 + masatoy[1];
            N = L - S;

            if (N == 6174) {

                printf("%d\n", kaolin);
                kaolin = 1;
                scanf("%d", &N);

            }
            else {
                kaolin++;
            }
            if (L == S) {
                printf("NA\n");
                scanf("%d", &N);
                kaolin = 1;
            }
        }



       
    }
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;
 
int main(void){
 
    ll A,B; cin>>A>>B;
    ll Gcd = __gcd(A,B);
    ll ans = 1;
 
    for (ll i = 2; i*i <= Gcd; ++i) {
        if(Gcd%i==0){
            ans++;
            while(Gcd%i==0){
                Gcd /= i;
            }
        }
    }
    if(Gcd!=1) ans++;
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 256
(defun digitsp (n r)
  (and (<= (expt 10 (- r 1)) n)
       (< n (expt 10 r))))

(defun odd-digitsp (n)
  (or (digitsp n 1)
      (digitsp n 3)
      (digitsp n 5)))

(let ((n (read)))
  (princ (loop :as i
               :below n
               :when (odd-digitsp (+ 1 i))
               :count i)))

Measured memory_bytes: 57704
class exist_negative_cycle(Exception):
    pass
def warshall_floyd(g, size):
    d = [[float('inf')] * size for _ in range(size)]

    for i in range(size):
        d[i][i] = 0

    for u in g:
        for length, v in g[u]:
            d[u][v] = length

    for k in range(size):
        for i in range(size):
            for j in range(size):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    for i in range(size):
        if d[i][i] < 0:
            raise exist_negative_cycle
    return d


from collections import defaultdict
from sys import stdin
import math
readline = stdin.readline

v, e = map(int, readline().split())
g = defaultdict(list)
for i in range(e):
    s, t, length = map(int, readline().split())
    g[s].append((length, t))
try:
    d = warshall_floyd(g, v)
    for di in d:
        print(' '.join(['INF' if math.isinf(dij) else str(dij) for dij in di]))
except exist_negative_cycle:
    print('NEGATIVE CYCLE')

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

int d[100005], n, m;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0;i < m;i++)
	{
		int a, b; scanf("%d%d", &a, &b);
		d[a] ^= 1;
		d[b] ^= 1;
	}
	for (int i = 0;i < n;i++) if (d[i])
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 640
require 'mathn'

def f(x, n, a, i)
  return 1 if x == 0
  return 0 if n == 0
  return 0 if i > a
  if i * i > a
    return x.numerator == 1 && i <= x.denominator && x.denominator <= a.to_i ? 1 : 0
  end
  t = f(x, n, a, i + 1)
  loop do
    x -= 1 / i
    n -= 1
    a /= i
    break if x < 0 || n < 0 || a < 1
    t += f(x, n, a, i + 1)
  end
  t
end

loop do
  p, q, a, n = gets.split.map(&:to_i)
  break if p == 0
  p f(p / q, n, a, 1)
end



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

ll x;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>x;
    ll k=100;
    
    ll k1=0;
    
    while (k<x){
        k+=k/100;
        k1++;
    }
    
    cout<<k1;
    
    
    
    
    return 0;
}

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

int uf[100010];

int ufind(int id){
    if(uf[id] == id) return id;
    return uf[id] = ufind(uf[id]);
}

void merge(int id1, int id2) {
    id1 = ufind(id1);
    id2 = ufind(id2);
    if(id1 == id2) return;
    uf[id2] = id1;
}

int N, M, p[100010], ans;

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

    cin>>N>>M;
    for(int i = 0; i < N; i++) cin>>p[i], uf[i+1] = i+1;
    for(int m = 0; m < M; m++) {
        int a, b;cin>>a>>b;
        merge(a, b);
    }
    for(int i = 0; i < N; i++) {
        if(ufind(i+1) == ufind(p[i])) {
//            cout<<i+1<<' '<<p[i]<<'\n';
            ans++;
        }
    }
    cout<<ans<<'\n';

    return 0;
}

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

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

Measured memory_bytes: 256
//<>>><<><<<<<>>><
//03210120123452101
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5E5+10;
ll arr[N];
char s[N];
int main(){
    scanf("%s",s+1);
    ll x=strlen(s+1);
    int pos=1;
    arr[pos++]=0;
    for(int i=1;i<x;i++){
        if(s[i]=='>'&&s[i+1]=='<'){
            arr[pos++]=i;
        }
    }
    arr[pos++]=x;
    ll ans=0;
//    for(int i=1;i<pos;i++) cout<<arr[i]<<endl;
    for(int i=1;i<pos-1;i++){
        ll a=0;
        ll b=0;
        for(int j=arr[i]+1;s[j]=='<';j++){
            a++;
        }
        for(int j=arr[i+1];s[j]=='>';j--){
            b++;
        }
        ll x1=max(a,b);
        ll x2=min(a,b);
        if(x2!=0) x2--;
        ans+=x1*(x1+1)/2;
        ans+=x2*(x2+1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;

  int i = find(begin(s), end(s), X) - begin(s) + 1;
  cout << accumulate(begin(t) + i, end(t), 0) << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int d = sc.NextInt();
        int t = sc.NextInt();
        int s = sc.NextInt();

        Console.WriteLine(t * s >= d ? "Yes" : "No");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27504
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=998244353;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	vvi dp(c + 2, vi(d + 2));
	dp[c][d] = 1;
	for(int i = c; i >= 1; i--){
		for(int j = d; j >= 1; j--){
			if(i == c && j == d)
				continue;
			dp[i][j] = add(mul(j, dp[i + 1][j]), mul(i, dp[i][j + 1]));
			dp[i][j] = sub(dp[i][j], mul(i, mul(j, dp[i + 1][j + 1])));
		}
	}
	cout << dp[a][b] << endl;
}

Measured memory_bytes: 38480
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto in : x) {cerr << " [" <<  in << "]";} cerr << '\n';
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
ll mypow(ll b){
	if(b == 0){
		return 1LL;
	}
	if(b == 1){
		return 10LL;
	}
	if(b % 2 == 0){
		return ((mypow(b / 2) % 13) * (mypow(b / 2) % 13)) % 13;
	}
	return (10LL * (mypow(b - 1) % 13)) % 13;

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	string s;
	cin >> s;
	ll n = s.size();
	vector<vector<ll>> dp(n, vector<ll>(13));
	if(s[0] != '?'){
		ll tiv = s[0] - '0';
		tiv *= mypow(n - 1);
		tiv %= 13;
		dp[0][tiv] = 1;
	}
	else{
		for (ll i = 0; i <= 9;i++){
			ll tiv = i;
			tiv *= mypow(n - 1);
			tiv %= 13;
			dp[0][tiv] = 1;
		}
	}
	for (ll i = 1; i < n;i++){
		if(s[i] != '?'){
			ll tiv = s[i] - '0';
			tiv *= mypow(n - i - 1LL);
			tiv %= 13;
			for (ll j = 0; j < 13; j++){
				ll tiv2 = (j + tiv) % 13;
				dp[i][tiv2] += dp[i - 1][j];
				dp[i][tiv2] %= mod;
			}
		}
		else{
			for(ll k = 0;k <= 9;k++){
				ll tiv1 = k *  mypow(n - i - 1LL);
				tiv1 %= 13;
				for(ll j = 0;j < 13;j++){
					ll tiv2 = (j + tiv1) % 13;
					dp[i][tiv2] += dp[i - 1][j];
					dp[i][tiv2] %= mod;
				}
			}
		}
	}
	cout << dp[n - 1][5] << '\n';
	return 0;
}


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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

signed main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int r = b * 10 + c;
	PRINT(r % 4 == 0);
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int k = sc.nextInt();
    String s=sc.next();
    String ans = "";
    for(int i=0;i<s.length();i++) {
        int asc = (int) s.charAt(i);
        if((asc+k)<=90) {
            char as = (char) (asc+k);
            ans+=as;
        } else {
            char as = (char) ((asc-26) + k);
            ans+=as;
        }
    }
    System.out.println(ans);    
}
}


Measured memory_bytes: 147512
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s[0]-'0';
    bool exe = true;
    for(int i = 1; i < s.length(); i++){
    	if(s[i] != '9') exe = false;
    }
    int ans;
    if(!exe){
    	ans = n-1 + 9*(s.length()-1);
    }
    else{
    	ans = n + 9*(s.length()-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define int long long
#define double long double
using namespace std;
typedef pair<int, int> P;
 
int sx, sy, gx, gy;
int n;
int x[200000], y[200000];
vector<P> p;
int dp[200002];		//dp[length] = min(max)
const double PAI = 3.141592653589793238;
 
signed main()
{
	int i;
	
	cin >> sx >> sy >> gx >> gy;
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i] >> y[i];
	
	if (sx > gx) { swap(sx, gx); swap(sy, gy); }
	if (sy > gy) {
		sy *= -1;
		gy *= -1;
		for (i = 0; i < n; i++) { y[i] *= -1; }
	}
	
	for (i = 0; i < n; i++) {
		if (sx <= x[i] && x[i] <= gx && sy <= y[i] && y[i] <= gy) {
			p.push_back(P(x[i], y[i]));
		}
	}
	sort(p.begin(), p.end());
	
	//LIS
	int INF = 1145141919810;
	for (i = 0; i <= n + 1; i++) dp[i] = INF;
	dp[0] = -INF;
	for (i = 0; i < p.size(); i++) {
		dp[upper_bound(dp, dp + n + 1, p[i].second) - dp] = p[i].second;
	}
	for (i = n; i > 0; i--) {
		if (dp[i] < INF) break;
	}
	
	//LISの長さ
	int Count = i;
	
	//場合分け
	double ans;
	
	if (min(gx - sx, gy - sy) + 1 > Count) {
		ans = (gy - sy + gx - sx) * 100 - Count * (20.0 - PAI * 5.0);
	}
	else {
		ans = (gy - sy + gx - sx) * 100 - (Count - 1.0) * (20 - PAI * 5) + (PAI * 10 - 20);
	}
	
	printf("%.20Lf\n", ans);
	return 0;
}

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

int main(){

  int N, M, sum=0;
  cin >> N;

  vector<int> vec(N,0);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }

  cin >> M;
  vector<vector<int>> data(M,vector<int>(2,0));
  for (int i=0; i<M; i++){
    for (int j=0; j<2; j++){
      cin >> data.at(i).at(j);
    }
  }

  for (int i=0; i<M; i++){
    for (int j=0; j<N; j++){

      if (j+1==data.at(i).at(0)){
        sum += data.at(i).at(1);
      }
      else {
        sum += vec.at(j);
      }

    }
    cout << sum << endl;
    sum = 0;
  }

}


Measured memory_bytes: 256
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define endl        '\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)    (a>b?a:b)
#define min(a,b)    (a<b?a:b)

/*  For Debugging   */
#define DEBUG       cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
    ll n;
    cin>>n;
    if(n==2)
    {
        cout<<1<<endl;
        return;
    }
    if(n==3)
    {
        cout<<2<<endl;
        return;
    }
    // if(n==4)
    // {
    //  cout<<3<<endl;
    //  return;
    // }
    ll ans=0;
    ll tnum=0;
    for(ll j=2;j*j<=n;j++)
    {
        if(n%j==0)
        {
            tnum=n;
            while(tnum%j==0)
                tnum/=j;
            tnum%=j;
            ans+=(tnum==1);
        }
    }
    for(ll j=2;j*j<=n-1;j++)
    {
        if((n-1)%j==0)
        {
            ans++;
            if(j*j!=(n-1))
                ans++;
        }
    }
    ans++;
    cout<<ans+1<<endl;
    return;
}
int main()
{
    FAST
    int TESTS=1;
//  cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    TIME
    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) { 
  val m = readLine()!!.toInt()
  var a = 0
  var c = 0
  for(x in (1..m) ) { 
    c += x
    if(m <= c) {
      a = x
      break
    }
    //println("$x $c")
  }
  println(a)
}

Measured memory_bytes: 29956
import numpy as np
N, K , Q = map(int, input().split())

A =[0]*Q
audi = [0]*N
point =[K]*N
for i in range(Q):
    A[i] = int(input())
    audi[A[i]-1] += 1

for i in range(N):
    point[i] = point[i]-Q+audi[i]
    if(point[i] <=0):
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 21504
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

int a[2010];
int main(){
	int ans=0;
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int x=lower_bound(a,a+n,a[i]+a[j])-a;
			ans+=x-j-1;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++) 
using namespace std;

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

const int MAXN = 510;

int n, C[MAXN], S[MAXN], F[MAXN];

void load() {
	scanf("%d", &n);
	FOR(i, (n-1)) {
		scanf("%d%d%d", C + i, S + i, F + i);
	}
}

void solve() {
	FOR(i, n) {
		int x = 0;
		for (int j = i; j < n - 1; j++) {
			x = max(x, S[j]);
			if (x % F[j] != 0) {
				x = (x / F[j] + 1) * F[j];
			}
			x += C[j];
		}
		printf("%d\n", x);
	}
}

int main() {
	load();
	solve();
	return 0;
}


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

int main(void){
    string s;
    int n;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<n;j++){
            if(s[i]=='Z') s[i] = 'A';
            else s[i] += 1;
        }
    }    
    cout << s << endl;
}

Measured memory_bytes: 256