akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let s: Vec<char> = sc.cin::<String>().chars().collect();
    let mut maxlen = 0;
    for offset in 1..n {
        let mut len = 0;
        for i in 0..n {
            let j = i + offset;
            if j >= s.len() { break }
            if s[i] == s[j] {
                len += 1;
            } else {
                len = 0;
            }
            if maxlen < len && len <= offset {
                maxlen = len;
            }
        }
    }
    put!(maxlen);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int N,T;
int to[3030],from[3030];
vector<pair<int,int>> V;

void solve(){
  cin>>N>>T;
  rep(i,N){
    int A,B; cin>>A>>B;
    V.push_back({A,B});
  }
  sort(V.begin(),V.end());
  for(auto p:V){
    int A=p.first,B=p.second;
    fill(to,to+T+1,0);
    rep(i,T){
      to[i]=max(to[i],from[i]);
      int k=min(T,A+i);
      to[k]=max(to[k],from[i]+B);
    }
    to[T]=max(to[T],from[T]);
    swap(to,from);
  }
  int ans=0;
  rep(i,T+1) ans=max(ans,from[i]);
  cout<<ans<<endl;
}

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

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

int n, m, k, P, f[105][105], g[105][105], fac[105], ifac[105], pw[105][10005], trans[105][105];

int power(int a, int x) {
	int ans = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P)
		if (x & 1) ans = 1ll * ans * a % P;
	return ans;
}

int main() {
	scanf("%d%d%d%d", &n, &m, &k, &P);
	for (int i = 0; i <= k; ++i)
		for (int j = pw[i][0] = 1; j <= n * m; ++j)
			pw[i][j] = 1ll * pw[i][j - 1] * i % P;
	for (int i = fac[0] = 1; i <= max(n, m); ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	ifac[max(n, m)] = power(fac[max(n, m)], P - 2);
	for (int i = max(n, m); i; --i) ifac[i - 1] = 1ll * ifac[i] * i % P;
	f[0][0] = 1;
	for (int i = 1; i <= k; ++i) {
		for (int b = 0; b <= m; ++b)
			for (int c = 0; c <= n; ++c)
				trans[c][b] = 1ll * ifac[c] * pw[i][c * (m - b)] % P * pw[k - i + 1][c * b] % P;
		for (int a = 0; a <= n; ++a)
			for (int c = 0; a + c <= n; ++c)
				for (int b = 0; b <= m; ++b)
					g[a + c][b] = (g[a + c][b] + 1ll * f[a][b] * trans[c][b]) % P;
		memcpy(f, g, sizeof g);
		memset(g, 0, sizeof g);
		for (int a = 0; a <= n; ++a)
			for (int c = 0; c <= m; ++c) {
				int tmp = 1ll * ifac[c] * pw[i][c * (n - a)] % P * pw[k - i + 1][c * a] % P;
				for (int b = 0; b + c <= m; ++b)
					g[a][b + c] = (g[a][b + c] + 1ll * f[a][b] * tmp) % P;
			}
		memcpy(f, g, sizeof g);
		memset(g, 0, sizeof g);
		for (int b = 0; b <= m; ++b)
			for (int c = 0; c <= n; ++c)
				trans[c][b] = 1ll * ifac[c] * pw[i][c * (m - b)] % P * pw[k - i][c * b] * (c & 1 ? -1 : 1) % P;
		for (int a = 0; a <= n; ++a)
			for (int c = 0; a + c <= n; ++c)
				for (int b = 0; b <= m; ++b)
					g[a + c][b] = (g[a + c][b] + 1ll * f[a][b] * trans[c][b]) % P;
		memcpy(f, g, sizeof g);
		memset(g, 0, sizeof g);
		for (int a = 0; a <= n; ++a)
			for (int c = 0; c <= m; ++c) {
				int tmp = 1ll * ifac[c] * pw[i][c * (n - a)] % P * pw[k - i][c * a] * (c & 1 ? -1 : 1) % P;
				for (int b = 0; b + c <= m; ++b)
					g[a][b + c] = (g[a][b + c] + 1ll * f[a][b] * tmp) % P;
			}
		memcpy(f, g, sizeof g);
		memset(g, 0, sizeof g);
	}
	int ans = 1ll * f[n][m] * fac[n] % P * fac[m] % P;
	printf("%d\n", (ans + P) % P);
	return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 500000 + 5;


int main()
{
    string S, T;
    cin >> S >> T;
    int ans = T.length();
    for (int i = 0; i + T.length() <= S.length(); i ++){
        int cnt = 0;
        for (int j = 0; j < T.length(); j ++){
            if(S[i + j] != T[j]){
                cnt ++;
            }
        }
        if (cnt < ans){
            ans = cnt;
        }
    }
    cout << ans;
    system("pause");
    return 0;
}

Measured memory_bytes: 3660
import collections
import sys

S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()

for i, j in enumerate(sys.stdin.readline()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while S2 and (S2[-1] > left_edge):
                if S2[-1] > left_edge:
                    S2.pop()
                    new_puddle += S3.pop()
            S2.append(left_edge)
            S3.append(new_puddle)
        else:
            pass


print(sum(S3))

print(len(S3), *S3)

Measured memory_bytes: 8356
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X) count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC104_A solver = new ABC104_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC104_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            if (n < 1200) {
                out.print("ABC");
            } else if (n < 2800) {
                out.print("ARC");
            } else {
                out.print("AGC");
            }
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
    if(k<e-a){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
}

Measured memory_bytes: 3644
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
can_make = [[None for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        x = A[i][j] - B[i][j]
        if i == j == 0:
            can_make[i][j] = set([abs(x)])
            continue
        st = set()
        ub = 80 * (W - i + H - j)
        if i > 0:
            for y in can_make[i-1][j]:
                if abs(y + x) <= ub:
                    st.add(abs(y + x))
                if abs(y - x) <= ub:
                    st.add(abs(y - x))
        if j > 0:
            for y in can_make[i][j-1]:
                if abs(y + x) <= ub:
                    st.add(abs(y + x))
                if abs(y - x) <= ub:
                    st.add(abs(y - x))
        can_make[i][j] = st
print(min(can_make[-1][-1], key=lambda x: abs(x)))



Measured memory_bytes: 752136
package main

import (
	"fmt"
	"os"
)

func pop(s *string) string {
	str := *s
	r := string(str[0])
	*s = string(str[1:])
	return r
}

func check(s, disp string) {
	if len(s) == 0 {
		fmt.Println(disp)
		os.Exit(0)
	}
}

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)

	t := pop(&a)
	for {
		switch t {
		case "a":
			check(a, "A")
			t = pop(&a)
		case "b":
			check(b, "B")
			t = pop(&b)
		case "c":
			check(c, "C")
			t = pop(&c)
		}
	}
}


Measured memory_bytes: 512
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        double[] d = new double[6];
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            for(int i=0; i<d.length; i++) {
                d[i] = sc.nextDouble();
            }
            double adbc = d[0]*d[4] - d[1]*d[3];
            if(Double.compare(adbc, 0.0f) == 0) {
                continue;
            }
            double[][] m1 = {{ d[4]/adbc, -d[1]/adbc},
                             {-d[3]/adbc,  d[0]/adbc}};
            double[][] m2 = {{d[2]}, {d[5]}};
            double x = m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0];
            double y = m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0];
            System.out.println(String.format("%.3f %.3f", x, y));
        }
    }
}

Measured memory_bytes: 28164
#include<iostream>

int satr(int n,int A[],int m){
	
	if(n==0){
		if(m-A[n]==0){
			return 0;
		}else{
		return m;
		}
	}
	if(satr(n-1,A,m-A[n])==0){
		return 0;
	}else if(satr(n-1,A,m)==0){
		return 0;
	}
	
	
	return 1;
}







int main(){

  int n;
  std::cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    std::cin>>A[i];
  }
  int q;
  std::cin>>q;
  int m[q];
  for(int i=0;i<q;i++){
    std::cin>>m[i];
  }

  for(int x=0;x<q;x++){
  	if(satr(n,A,m[x])==0){
  		std::cout<<"yes\n";
  	}else{
  		std::cout<<"no\n";
  	}

  }

  return 0;
}



Measured memory_bytes: 3060
n = int(input())
S = []
for _ in range(n):
    S.append(str(input()))

m = int(input())
T = []
for _ in range(m):
    T.append(str(input()))

W = S + T

ans = 0

for w in W:
    can = S.count(w) - T.count(w)
    if can >= ans:
        ans = can

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int n,k; cin >> n >> k;
    bool flag = false;
    for(int l=0;l<=n;l++)
    {
        if(((l*2)+((n-l)*4))==k)
        {
            flag = true;
            break;
        }
    }
    flag ? cout << "Yes\n" : cout << "No\n";
    //main();
    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;
int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  llong sum = 0;
  rep(i, n) { sum += a[i]; }
  if (h - sum <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
(* Vicfred
 * https://atcoder.jp/contests/abc170/tasks/abc170_a
 * implementation
 * *)
open Printf
open Scanf

let solve a b c d e = 15 - a - b - c - d - e

let main =
    scanf "%d %d %d %d %d" solve |> printf "%d\n"



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N, Z, W; cin >> N >> Z >> W;
    vi A(N); rep(i, N) cin >> A[i];

    int res = 0;

    res = max(res, abs(A[N - 1] - W));
    if (N > 1) res = max(res, abs(A[N - 1] - A[N - 2]));

    cout << res << endl;
}


Measured memory_bytes: 3592
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double Real;

#define SIZE 100010

struct P3 {
  ll x, y, z;
  P3(ll x = 0, ll y = 0, ll z = 0): x(x), y(y), z(z) {}

  P3 operator-(const P3 &B) const {
    return P3(x - B.x, y - B.y, z - B.z);
  }
};

ll dot(P3 a, P3 b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

P3 cross(P3 a, P3 b) {
  ll x = a.y * b.z - a.z * b.y;
  ll y = a.z * b.x - a.x * b.z;
  ll z = a.x * b.y - a.y * b.x;
  return P3(x, y, z);
}

Real abs(P3 a) {
  return sqrtl(dot(a, a));
}

ll norm(P3 a) {
  return dot(a, a);
}

Real distanceSP(P3 &a, P3 &b, P3 &c) {
  if (dot(b-a, c-a) <= 0) return abs(c-a);
  if (dot(a-b, c-b) <= 0) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

#define W 2000

bool solve() {
  int N, M, R;
  P3 S[2000], T[15], E;
  int r[2000], b[15];

  scanf("%d%d%d", &N, &M, &R);

  if (!N) return false;

  for (int i=0; i<N; i++) {
    int x, y, z;
    scanf("%d%d%d%d", &x, &y, &z, r+i);
    S[i] = P3(x, y, z);
  }

  for (int i=0; i<M; i++) {
    int x, y, z;
    scanf("%d%d%d%d", &x, &y, &z, b+i);
    T[i] = P3(x, y, z);
  }

  {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    E = P3(x, y, z);
  }

  bitset<W> v[15];

  for (int i=0; i<M; i++) {
    for (int j=0; j<N; j++) {
      bool inA = norm(E - S[j]) <= r[j] * r[j];
      bool inB = norm(T[i] - S[j]) <= r[j] * r[j];

      if (inA && inB) {
        //
      } else if (inA ^ inB) {
        v[i][j] = 1;
      } else {
        if (distanceSP(E, T[i], S[j]) < r[j] + 1e-8)
          v[i][j] = 1;
      }
    }
  }

  Real intensity[15];

  for (int i=0; i<M; i++) {
    intensity[i] = (Real)b[i] / norm(T[i] - E);
  }

  Real ans = 0;


  for (int i=0; i<(1<<M); i++) {
    bitset<W> sumv;
    Real sumi = 0;
    for (int j=0; j<M; j++) {
      if (i & (1 << j)) {
        sumv |= v[j];
        sumi += intensity[j];
      }
    }

    if (sumv.count() <= R) {
      ans = max(ans, sumi);
    }
  }

  printf("%.10lf\n", (double)ans);

  return true;
}

int main() {
  while(solve());
}



Measured memory_bytes: 3212
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      String s = f.readLine();
      
      if(s.equals("ABC")){
         out.println("ARC");
      } else {
         out.println("ABC");
      }
      
      
      
      
      
      
      
      
      
      out.close();
   }
   
      
}

Measured memory_bytes: 32708
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll x;
    cin >> x;
    ll il_pel = x / 11;
    ll odp = 2 * il_pel;
    x -= 11 * il_pel;
    if (x > 0)
    {
        x -= 6;
        ++odp;
    }
    if (x > 0)
    {
        x -= 5;
        ++odp;
    }
    cout << odp;
    return 0;
}



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

using namespace std;

const int maxn = 110, maxl = 1e5 + 10, mod = 1e9 + 7;
int a[maxn], dp[maxn][maxl], ps[maxl], n, k;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k;

    for (int i = 1; i <= n; i++)
        cin >> a[i];
    dp[0][0] = 1;
    fill(ps, ps + maxl, 1);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            dp[i][j] = ps[j];
            if (j - a[i] > 0)
                (dp[i][j] -= ps[j - a[i] - 1] - mod) %= mod;
        }
        ps[0] = dp[i][0];
        for (int j = 0; j <= k; j++)
            ps[j] = (ps[j - 1] + dp[i][j]) % mod;
    }

    cout << dp[n][k];

    return 0;
}


Measured memory_bytes: 40832
import sys
input = sys.stdin.readline

"""
a,b,c -> b+c,a+c,a+b
a-b,b-c,c-a -> b-a,c-b,a-c
"""

A,B,C,K = map(int,input().split())
x = A - B
if K&1:
    x = -x
print(x)

Measured memory_bytes: 3060
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,x = inpl()
a = inpl()
now = abs(a[0]-x)
for i in range(1,n):
    now = math.gcd(abs(a[i] - x),now)
print(now)

Measured memory_bytes: 90444
#include<bits/stdc++.h>
using namespace std;
int arr[100005];
int main()
{
int n, ans=0;
cin>>n;
for(int a=1; a<=n; a++)
cin>>arr[a];
for(int a=1; a<=n; a++)
{
if(arr[a]==a)
{
ans++;
swap(arr[a], arr[a+1]);
}
}
cout<<ans;
return 0;
}

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

using namespace std;

int main(){
	//~ freopen("input.txt", "r", stdin);
	//~ freopen("output.txt", "w", stdout);
	int n;
	scanf("%d", &n);
	vector <int> v(n);
	int ans = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &v[i]);
		ans ^= v[i];
	}
	for (int i = 0; i < n; i++){
		printf("%d ", ans ^ v[i]);
	}
	printf("\n");
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> road(N);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    road.at(a - 1) ++;
    road.at(b - 1) ++;
  }
  
  for(int i = 0; i < N; i++){
    cout << road.at(i) << endl;
  }
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def g(i, N):
    tmp = N // i
    return int(i*tmp*(tmp+1)/2)


def main():
    N = II()
    ans = 0
    for i in range(1, N+1):
        ans += g(i, N)
    print(ans)


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()


Measured memory_bytes: 64216
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  int N;
  int a[300001];
  int l[200001], r[200001];
  int ans = -INF;
  
  cin >> N;
  Rep(i, 3*N) cin >> a[i];

  priority_queue<int, vector<int>, greater<int> > q1;
  priority_queue<int> q2;
  int sum = 0;
  Rep(i, N) {
    q1.push(a[i]), sum += a[i];
  } 
  l[N-1] = sum;
  
  for(int i=N; i<2*N; i++) {
    sum += a[i];
    q1.push(a[i]);
    sum -= q1.top();
    l[i] = sum;
    q1.pop();
  }

  sum = 0;
  for(int i=3*N-1; i>=2*N; i--) {
    q2.push(a[i]), sum += a[i];
  }
  r[2*N] = sum;
  
  for(int i=2*N-1; i>=N; i--) {
    sum += a[i];
    q2.push(a[i]);
    sum -= q2.top();
    r[i] = sum;
    q2.pop();
  }

  for(int i=N; i<2*N+1; i++) ans = max(ans, l[i-1] - r[i]);

  cout << ans << endl;
  
}


Measured memory_bytes: 7540
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, c := scanInt(), scanInt()

	a := make([][]pair, c)
	for i := 0; i < n; i++ {
		in := scanInts(3)
		a[in[2]-1] = append(a[in[2]-1], pair{in[0], in[1]})
	}

	t := []pair{}
	for k := 0; k < c; k++ {
		if len(a[k]) == 0 {
			continue
		}
		sort.Slice(a[k], func(i, j int) bool { return a[k][i].a < a[k][j].a })
		for m := 0; m < len(a[k])-1; m++ {
			if a[k][m].b == a[k][m+1].a {
				a[k][m+1].a = a[k][m].a
			} else {
				t = append(t, a[k][m])
			}
		}
		t = append(t, a[k][len(a[k])-1])
	}

	b := make([]int, 1e5+1)
	for i := 0; i < len(t); i++ {
		b[t[i].a-1]++
		b[t[i].b]--
	}
	ans := 0
	cnt := 0
	for i := 0; i < 1e5+1; i++ {
		cnt += b[i]
		ans = max(ans, cnt)
	}
	fmt.Fprintln(wr, ans)

}

type pair struct{ a, b int }


Measured memory_bytes: 12112
import java.util.*;
public class Main{
	
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);	
      	int m1 = sc.nextInt();
      	int d1 = sc.nextInt();
      	int m2= sc.nextInt();
      	int d2 = sc.nextInt();
      if(m1==m2)
        System.out.println("0");
      else if(d2-d1<0)
        System.out.println("1");
    
    }
}

Measured memory_bytes: 21588
package main

import (
  "fmt"
)

func sumInt(a ...int) int {s := 0; for _, v := range a {s += v}; return s}

func main() {
  a := make([]int, 3)
  for i := 0; i < 3; i++ {
    fmt.Scan(&a[i])
  }
  if sumInt(a...) < 22 {
    fmt.Println("win")
  } else {
    fmt.Println("bust")
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
using ll = long long;
using namespace std;
using pii = pair<int, int>;
using pdi = pair<double, int>;

int N, L, T;
vector<int> X;
vector<int> W;

int main() {
	cin >> N >> L >> T;
	for (int i = 0; i < N; i++)
	{
		int tmpX;
		int tmpW;
		cin >> tmpX >> tmpW;
		X.push_back(tmpX);
		W.push_back(tmpW);
	}

	vector<int> Xd;
	for (int i = 1; i < N; i++)
	{
		if (W.at(i) != W.at(0)) {
			Xd.push_back(X.at(i) * 2);
		}
	}

	int cnt = 0;
	const int Ld = L * 2;
	const int Td = T * 2;
	const int X0d = X.at(0) * 2;
	for (int i = 0; i < Xd.size(); i++)
	{
		int td = 0;
		if (W.at(0) == 1) {
			td += (Xd.at(i) - X0d) / 2;
		}
		else {
			td += (Ld - Xd.at(i) + X0d) / 2;
		}
		if (td < Td) {
			cnt++;
		}
		else {
			continue;
		}
		cnt += ((Td - td - 1) / (Ld / 2)) % N;
		cnt %= N;
	}
	vector<int> Xfinal;
	int X0final;
	for (int i = 0; i < N; i++)
	{
		int tmpXfinal = X.at(i);
		if (W.at(i) == 1) {
			tmpXfinal += T;
		}
		else {
			tmpXfinal -= T;
		}
		tmpXfinal %= L;
		tmpXfinal += L;
		tmpXfinal %= L;
		Xfinal.push_back(tmpXfinal);
		if (i == 0) {
			X0final = tmpXfinal;
		}
	}
	sort(Xfinal.begin(), Xfinal.end());

	int did;
	if (W.at(0) == 1) {
		for (int i = 0; i < N; i++)
		{
			if (Xfinal.at(i) == X0final) {
				did = i - cnt;
				break;
			}
		}
	}
	else {
		for (int i = N - 1; i >= 0; i--)
		{
			if (Xfinal.at(i) == X0final) {
				did = i + cnt;
				break;
			}
		}
	}
	did += N;
	did %= N;

	for (int i = 0; i < N; i++)
	{
		cout << Xfinal.at((i + did) % N) << endl;
	}

	return 0;
}


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc62
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            int ans = 0;
            if (H % 3 == 0 || W % 3 == 0)
            {
                ans = 0;
            }else
            {
                int ans1 = 0;
                int ans2 = 0;
                if (H % 2 == 0)
                {
                    ans1 = H / 2;
                }else
                {
                    int a = W / 3;
                    int b = H / 2;
                    if (W % 3 == 1)
                    {
                        ans1 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a), Math.Max(2 * a + 1, a + b + 1));
                    }else
                    {
                        ans1 = Math.Max(2 * a + 1, a + b + 1);
                    }
                }
                if (W % 2 == 0)
                {
                    ans2 = W / 2;
                }
                else
                {
                    int a = H / 3;
                    int b = W / 2;
                    if (H % 3 == 1)
                    {
                        ans2 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a), Math.Max(2 * a + 1, a + b + 1));
                    }
                    else
                    {
                        ans2 = Math.Max(2 * a + 1, a + b + 1);
                    }
                }
                ans = Math.Min(ans1, ans2);
            }
            Console.WriteLine(Math.Min(ans,Math.Min(H,W)));
        }
    }
}


Measured memory_bytes: 13140
s =list(input())
N = len(s)
mod = pow(10,9)+7
dp = [[0]*13 for i in range(N)]
if s[0] == '?':
        dp[0][0:9] = [1 for i in range(10)]
else:
    dp[0][int(s[0])] = 1
for i in range(1,N):
    if s[i] == '?':
        for j in range(10):
            for m in range (13):
                 dp[i][(m*10+j)%13] += dp[i-1][m]%mod
    else:
        for m in range(13):
            dp[i][(m*10+int(s[i]))%13] += dp[i-1][m]%mod
print(dp[-1][5]% mod)

Measured memory_bytes: 66884
n,m=map(int,input().split())
ab,cd=[list(map(int,input().split())) for _ in range(n)],[list(map(int,input().split())) for _ in range(m)]
for i in ab:
  r=[]
  for j in cd: r.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
  print(r.index(min(r))+1)

Measured memory_bytes: 9008
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int A[100000];
char kotae[800000], * it = kotae;
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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


	int N, K, kari;
	N = getint();
	K = getint();

	int k = N - K;

	if (k <= K) {
		rep(i, k) A[i] = getint();
		rep(i, K - k) {
			if (ci - owa > 0) {
				memcpy(cn, owa, CL);
				ci -= CM;
				fread(cn + CL, 1, CM, stdin);
			}
			ll tmp = *(ll*)ci;
			if ((tmp & ma0) ^ ma0) {
				ci += (__builtin_ctzll((tmp & ma0) ^ ma0) + 4 >> 3);
			}
			else {
				ci += 8;
				while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
			}
		}
		rep(i, k) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
		}
	}
	else if (K == 1) {
		int mae = getint();
		rep(i, k) {
			kari = getint();
			if (kari > mae) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
			mae = kari;
		}
	}
	else {
		rep(i, K) A[i] = getint();
		int kazu = k / K;
		int amari = k % K;
		rep(j, kazu) rep(i, K) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
			A[i] = kari;
		}
		rep(i, amari) {
			kari = getint();
			if (kari > A[i]) {
				*it++ = 'Y';
				*it++ = 'e';
				*it++ = 's';
				*it++ = '\n';
			}
			else {
				*it++ = 'N';
				*it++ = 'o';
				*it++ = '\n';
			}
		}
	}

	fwrite(kotae, 1, it - kotae, stdout);


	Would you please return 0;
}

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

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

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

	sort(v.begin(), v.end());
	double cur = v[0];
	for (int i = 1; i < n; i++) {
		cur = (cur + (double) v[i]) / 2.0;
	}
	cout << cur << endl;



	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main()
{
	int i;
	char str[1000];
	scanf("%s",str);
	for(i=0;i<strlen(str);i++)printf("%c",(((str[i]-'A'+23)%26)+'A'));
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

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

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }


int main() {
    int n;
    cin >> n;
    auto dp = make_v(n, n, INF<ll>/100);
    vector<ll> S(n+1);
    ll s = 0;
    for (int i = 0; i < n; ++i) {
        ll k;
        cin >> k;
        s += k;
        S[i+1] = s;
        dp[i][i] = 0;
    }
    for (int j = 1; j <= n; ++j) {
        for (int l = 0; l < n; ++l) {
            int r = l+j;
            if(r >= n) continue;
            for (int mid = l; mid < r; ++mid) {
                dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid+1][r] + S[r+1]-S[l]);
            }
        }
    }
    cout << dp[0][n-1] << "\n";
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	uint64_t a, b, x;
	cin >> a >> b >> x;

	uint64_t b1 = (b / x) + 1;	
	uint64_t b2 = (a > 0) ? ((a - 1) / x + 1) : 0;
	cout << b1 - b2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;

constexpr int MAX_N = 500000;
int n;
int l[MAX_N], r[MAX_N];

int leafs[MAX_N + 1];
int depth[MAX_N + 1];
long long memo[MAX_N][2];
int in[MAX_N + 1];
int out[MAX_N + 1];

long long dfs(int v, bool used) {
	if(v == n) return 0;

	long long &res = memo[v][used];
	if(res != -1) return res;

	if(used) {
		res = dfs(l[v], true) + dfs(r[v], true) + depth[v] + 2;
	}
	else {
		res = min({dfs(l[v], false) + dfs(r[v], true)  + 2 - (leafs[r[v]] - 1) * depth[v],
				   dfs(l[v], true)  + dfs(r[v], false) + 2 - (leafs[l[v]] - 1) * depth[v],
				   dfs(l[v], false) + dfs(r[v], false) + 2 + depth[v]});
	}

	return res;
}

void init() {
	stack<tuple<int, int, int>> sta;
	sta.push(make_tuple(1, 0, 0));

	int res;
	while(!sta.empty()) {
		int v, d, cnt;
		tie(v, d, cnt) = sta.top();

		if(v == n) {
			depth[v] = d;
			res = leafs[v] = 1;
			sta.pop();
		}
		else if(cnt == 0) {
			depth[v] = d;
			++get<2>(sta.top());
			sta.push(make_tuple(l[v], d + 1, 0));
		}
		else if(cnt == 1) {
			leafs[v] += res;
			++get<2>(sta.top());
			sta.push(make_tuple(r[v], d + 1, 0));
		}
		else {
			res = (leafs[v] += res);
			sta.pop();
		}
	}
}

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

	cin >> n;

	for(int i = 1; i < n; ++i) {
		cin >> l[i] >> r[i];
	}

	init();

	memset(memo, -1, sizeof(memo));
	for(int v = n - 1; v > 1; --v) {
		dfs(v, false);
		dfs(v, true);
	}
	cout << dfs(l[1], false) + dfs(r[1], false) + 2 << endl;

	return EXIT_SUCCESS;
}

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

typedef long long ll;
#define rep(a, b) for(i=a; i<b; i++)

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	ll arr[4] = {0,0,0,0};
	cin>>t;
	while(t--){
		char c[3];
		cin>>c;
		if(strcmp(c, "AC") == 0){
			arr[0]++;

		}
		else if(strcmp(c, "WA")==0){
			arr[1]++;
		}
		else if(strcmp(c, "TLE")==0){
			arr[2]++;
		}
		else if(strcmp(c, "RE")==0){
			arr[3]++;
		}
	}
	cout<< "AC x "<<arr[0]<<"\n"<< "WA x "<<arr[1]<<"\n"<< "TLE x "<<arr[2]<<"\n"<< "RE x "<<arr[3]<<"\n";
	return 0;
}


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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll n,p;
    string s;
    cin>>n>>p>>s;

    ll ans = 0;
    if( p == 2 )
    {
        for(int i=0;i<n;i++)
        {
            if( (s[i]-'0')%2 == 0 )
                ans += (i+1);
        }
    }
    else if( p == 5 )
    {
        for(int i=0;i<n;i++)
        {
            if( (s[i]-'0')%5 == 0 )
                ans += (i+1);
        }
    }
    else
    {
        map<ll,ll>mp;
        ll cur = 0, pw = 1;
        mp[0]++;
        for(int i=n-1;i>=0;i--)
        {
            cur = mod( cur + (s[i]-'0')*pw, p );
            ans += mp[cur];
            mp[cur]++;
            pw = mod( pw*10, p );
        }
    }
    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 1044
x = int(input())
if x == 2:
    print(2)
    exit()
i = 3
f = False
while True:
    if x % 2 == 0:
        x += 1
        continue
    while i * i <= x:
        if x % i == 0:
            i += 2
            f = True
            break
        else:
            i += 2
    if not f:
        print(x)
        exit()
    x += 1
    i = 3
    f = False

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repd(i,n) for(ll i = (n); i >= 0; i--)
#define FOR(i,t,n) for(ll i = (t); i < (n); i++)
#define FORD(i,t,n) for(ll i = (n); i >= t; i--)
#define ALL(x) x.begin(),x.end()
#define asort(x) sort(ALL(x))

ll row[300100], col[300100];
ll X[300100], Y[300100];
ll vr[300100], vc[300100];

int main() {
    ll H, W, M;
    cin >> H >> W >> M;
    vector<ll> R, C;
    ll rm = 0, cm = 0;
    rep(i,M) {
        ll h, w;
        cin >> h >> w;
        row[h]++; col[w]++;
        X[i] = h; Y[i] = w;
    }
    rep(i,H+1) {
        if(row[i] > rm) {
            rm = row[i];
            R.clear();
            R.push_back(i);
        } else if(row[i] == rm) {
            R.push_back(i);
        }
    }
    rep(i,W+1) {
        if(col[i] > cm) {
            cm = col[i];
            C.clear();
            C.push_back(i);
        } else if(col[i] == cm) {
            C.push_back(i);
        }
    }
    rep(i,R.size()) {
        vr[R[i]] = 1;
    }
    rep(i,C.size()) {
        vc[C[i]] = 1;
    }
    int cnt = 0;
    rep(i,M) {
        if(vr[X[i]] && vc[Y[i]]) cnt++;
    }
    if(cnt == R.size() * C.size()) cout << rm + cm - 1 << endl;
    else cout << rm + cm << endl;
}

Measured memory_bytes: 21940
import java.util.Arrays;

public class Main {


  private static void solve() {
    int d = ni();
    int g = ni() / 100;
    int[][] p = ntable(d, 2);
    for (int i = 0; i < d; i ++) {
      p[i][1] /= 100;
    }

    long[][] dp = new long[d + 1][g + 1];
    for (long[] v : dp) Arrays.fill(v, Long.MAX_VALUE / 3);
    dp[0][0] = 0;

    for (int i = 0; i < d; i ++) {
      for (int j = 0; j <= g; j ++) {
        for (int k = 0; k <= p[i][0]; k ++) {
          int u = Math.min(g, j + (i + 1) * k + (k == p[i][0] ? p[i][1] : 0));
          dp[i + 1][u] = Math.min(dp[i + 1][u], dp[i][j] + k);
        }
      }
    }
    System.out.println(dp[d][g]);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 31632
using System;

namespace AtCoder_20190705
{
    class Program
    {
        static int Solve()
        {
            int money = int.Parse(Console.ReadLine());
            int balance = money - int.Parse(Console.ReadLine());
            int someCake = int.Parse(Console.ReadLine());
            while (balance >= someCake)
            {
                balance -= someCake;                
            }
            return balance;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
    }
}


Measured memory_bytes: 11092
function main(input) {
  var N = input[0].split(" ")[0]-0;
  var M = input[0].split(" ")[1]-0;
  var map = {};
  var ans = [0,0];
  var tmpwa = {};
  for(var i=1;i<=M;i++){
    var p = input[i].split(" ")[0];
    var s = input[i].split(" ")[1];
    if(!map[p]){
      if(s=="AC"){
        ans[0]++;
        ans[1] += (tmpwa[p]||0);
        map[p] = true;
      }else{
        tmpwa[p] = (tmpwa[p]||0)+1;
      }
    }
  }
  console.log(ans.join(" "));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n; cin >> n;
    V<ll> x(n), y(n);
    V<ll> h(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];

    int nz = 0;
    for(int i = 0; i < n; i++){
        if(h[i]){
            nz = i;
            break;
        }
    }

    for(ll i = 0; i <= 100; i++){
        for(ll j = 0; j <= 100; j++){
            bool ok = true;
            ll H = h[nz] + abs(x[nz] - i) + abs(y[nz] - j);
            for(int k = 0; k < n; k++){
                ll tmp = max(H - abs(x[k] - i) - abs(y[k] - j), 0LL);
                if(h[k] == tmp) continue;
                else{
                    ok = false;
                    break;
                }
            }
            if(ok){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

public class Main {
 	public static void main(String[] args) {
     	Scanner sc = new Scanner(System.in);
      	PrintWriter out = new PrintWriter(System.out);
      	int[] arr = new int[sc.nextInt()];
      	int wrong = 0;
      	for (int i = 0; i < arr.length; i++) {
         	arr[i] = sc.nextInt(); 
          	if (arr[i] != i + 1) {
             	wrong++; 
            }
        }
      	out.println(wrong == 2 || wrong == 0 ? "YES" : "NO");
      	out.close();
   }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  cout<<(a+b+1)/2<<endl;

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 764
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}
void M1(){
  cout << "-1\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  ll f = a*60+b;
  ll g = c*60+d;
  print(g-f-e);
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int m;
vector<ld> a(505,0);

ld dp[505][505];

ld sum[505];

int main(){
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    for(int i = 0;i < 505;i++){
        for(int j = 0;j < 505;j++){
            dp[i][j] = -1e9;
        }
    }

    dp[0][0] = 0;
    rep(i,1,n){
        rep(j,1,m){
            rep(from,0,i - 1){
                dp[i][j] = max(dp[i][j] , dp[from][j - 1] + (sum[i] - sum[from])/(i - from));
            }
        }
    }
    cout << fixed << setprecision(8);

    cout << dp[n][m] << endl;


}


Measured memory_bytes: 7292
#include<iostream>
using namespace std;
int main()
{
int a,b,c,x,ia,ib,av,w=0;
cin>>a>>b>>c>>x;
for(ia=0;ia<=a;ia++)
{
for(ib=0;ib<=b;ib++)
{
av=x-ia*500-ib*100;
if(av>=0&&av<=c*50)
{
w++;
}
}
}
cout<<w;
return 0;
}


Measured memory_bytes: 256