akhauriyash/Code-Regression huggingface dataset:
// abc165_c_2.cc
#include <bits/stdc++.h>
using namespace std;

// vector<int> v;
int n, m, q, ans = 0;
int a[55], b[55], c[55], d[55];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> q;
	for (int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}

	vector<int> pv(m + n - 1, 0);
	for (int i = m - 1; i < pv.size(); i++) 
		pv[i] = 1;

	vector<int> arr(n);
	do {

		int cur = 0, j = 0;
		for (int x : pv) {
			if (!x) cur++;
			else arr[j++] = cur;
		}

		int tmp = 0;
		for (int i = 0; i < q; i++) {
			if (arr[b[i]] - arr[a[i]] == c[i])
				tmp += d[i];
		}
		ans = max(ans, tmp);
	} while (next_permutation(pv.begin(), pv.end()));





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

Measured memory_bytes: 3628
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        for ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]:
                    break
            else:
                continue
            break
        else:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")


Measured memory_bytes: 3060
#include <stdio.h>
int main() {
  
  int A = 0;
  int B = 0;
  
  scanf("%d", &A);
  scanf("%d", &B);
  
  if(A > 12){
    printf("%d\n", B);
  }
  else if(5 < A && A < 13){
    printf("%d\n", B / 2);
  } else {
    printf("0");
  }
  
  return 0;
}
    
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
const int MOD = 1e9 + 7; 
int main() {
  ll n,m;
  cin >> n >> m;
  if (n < m) swap(n,m);
  ll ans;
  if (n == m) {
    ans = 2;
    rep(j,2) rep(i,n) {ans *= (i+1); ans %= MOD;}
  } else if (n == m+1) {
    ans = 1;
    rep(i,n) {ans *= (i+1); ans %= MOD;}
    rep(i,m) {ans *= (i+1); ans %= MOD;}
  }
  else ans = 0;
  cout << ans << endl;
  return 0;
}

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

int main () {
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  int ans = 0;
  rep(i, n) ans += max(0, v[i] - c[i]);
  cout << ans << endl;
  return 0;
}


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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    rep(i, tx - sx) cout << 'R';
    rep(i, ty - sy) cout << 'U';
    rep(i, tx - sx) cout << 'L';
    rep(i, ty - sy) cout << 'D';
    
    cout << 'D';
    rep(i, tx - sx + 1) cout << 'R';
    rep(i, ty - sy + 1) cout << 'U';
    cout << 'L';
    
    cout << 'U';
    rep(i, tx - sx + 1) cout << 'L';
    rep(i, ty - sy + 1) cout << 'D';
    cout << 'R';
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
 int k ,n;
 cin>>k>>n;
 vi a(n);
 rep(i,n)cin>>a[i];
 int ans = a[n-1]-a[0];
 rep(i,n-1){
     ans = min(ans,k-(a[i+1]-a[i]));
 }
 cout<<ans<<endl;
}

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 8e3 + 3;

vector< int > V[2];
int H[N+N],HH[N+N],n,X,Y,i,h,hh,ss;
char A[N];

void f(vector <int> &r){
    int i,j,x;
    for(i=0;i<r.size();i++){
        x = r[i];
        for(j=n; j>=-n+x; j--){
            if(H[j-x+N] == 1) HH[j+N] = 1;
        }
        for(j=-n;j<=n-x;j++){
            if(H[j+x+N] == 1) HH[j+N] = 1;
        }
        for(j=-n;j<=n;j++) { H[j+N] = HH[j+N]; HH[j+N] = 0; }
    }
}

int main(){
    cin >> A+1 >> X >> Y;
    n = strlen(A+1);
    for(i=1;i<=n;i++){
        if(A[i] == 'T'){
            if(h || hh) V[h].pb(ss);
            else H[ss+N] = 1;
            hh = 1;
            h = 1-h;
            ss = 0;
        }
        else ss++;
    }
    if(h || hh) V[h].pb(ss);
    else H[ss+N] = 1;
            
    f(V[0]);    
    if(H[X+N] == 0){ puts("No"); return 0; }
    memset(H , 0 , sizeof H);
    H[N] = 1;
    f(V[1]);
    puts(H[Y+N] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 384
# include<iostream>
# include<cstring>
# include<cmath>
# include<map>
using namespace std;
int main ()
{
	
     int N;
	 cin>>N;
	 map <string,int> mp;
	 int sum =0;
	 for(int i=0;i<N;i++)
	 {
	 	 string s;
	 	 cin>>s;
	 	 if(mp[s]==0)
	 	 {
	 	 	 sum++;
		  }
		  
		  mp[s]=1;
	 	 
	  } 
     cout<<sum<<endl;
	
 } 

Measured memory_bytes: 19124
use std::collections::HashMap;
use std::io::Read;
use std::io::BufRead;

fn main() {
  let nkl: Vec<usize> = read_vec();
  let (n, k, l) = (nkl[0], nkl[1], nkl[2]);
  let pqs: Vec<(usize, usize)> = read_tuples(k);
  let rss: Vec<(usize, usize)> = read_tuples(l);

  let mut ufr = UnionFind::new(n);
  for (p, q) in pqs {
    ufr.unite(p-1, q-1)
  }

  let mut uft = UnionFind::new(n);
  for (r, s) in rss {
    uft.unite(r-1, s-1)
  }

  let mut map = HashMap::new();
  for pq in (0..n).map(|p| ufr.rep(p)).zip((0..n).map(|p| uft.rep(p))) {
    let counter = map.entry(pq).or_insert(0);
    *counter += 1;
  }
  
  let mut ans: Vec<usize> = vec![];
  for i in 0 .. n {
    ans.push(*map.get(&(ufr.rep(i),uft.rep(i))).unwrap());
  }
  
  print_vec(&ans, " ");
}

struct UnionFind {
  rp: Vec<usize>,
  rk: Vec<usize>
}

impl UnionFind {
  fn new(n: usize) -> UnionFind {
    UnionFind {
      rp: (0..n).collect(),
      rk: vec![1; n]
    }
  }
  
  fn rep(&self, p: usize) -> usize {
    if self.rp[p] == p {p} else {self.rep(self.rp[p])}
  }
  
  fn rank(&self, p: usize) -> usize {
    self.rk[self.rep(p)]
  }
  
  fn same(&self, p: usize, q: usize) -> bool {
    self.rep(p) == self.rep(q)
  }
  
  fn unite(&mut self, p: usize, q:usize) {
    let rkp = self.rank(p);
    let rkq = self.rank(q);
    let (p, q) = if rkp <= rkq {(p, q)} else {(q, p)};
    
    let repp = self.rep(p);
    let repq = self.rep(q);
    self.rp[p] = repq;
    self.rp[repp] = repq;
    self.rk[repq] += self.rk[repp];
  }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  let stdin = std::io::stdin();
  stdin.lock().by_ref().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  let stdin = std::io::stdin();
  stdin.lock().by_ref().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

fn print_vec<T: std::string::ToString>(vec: &[T], sep: &str) {
  let out = vec.iter().map(|e| e.to_string()).collect::<Vec<_>>().as_slice().join(sep);
  println!("{}", out);
}

Measured memory_bytes: 29928
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void saiki(int x,int y,vector<vector<char> > &field,vector<vector<char> > &k){
    if(field[y][x] == '#' || k[y][x] == 'x'){
        return;
    }

    field[y][x] = '#';
    k[y][x] = 'x';
    saiki(x-1,y,field,k);
    saiki(x+1,y,field,k);
    saiki(x,y-1,field,k);
    saiki(x,y+1,field,k);
    field[y][x] = '.';
    return;
}

int solve(int w,int h){
    //char field[w+2][h+2];
    vector<vector<char> > field(h+2,vector<char>(w+2));
    vector<vector<char> > k(h+2,vector<char>(w+2));

    int x,y;
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            field[i][j] = '#';
        }
    }

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> field[i][j];
            if(field[i][j] == '@'){
                y = i;
                x = j;
            }
            k[i][j] = field[i][j];
        }
    }

#ifdef DEB
    cout << "X:" << x << " Y:" << y << endl;
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout << field[i][j];
        }
        cout << endl;
    }
#endif
    saiki(x,y,field,k);

    int m = 0;
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            if(k[i][j] == 'x'){
                m++;
            }
        }
    }
    cout << m << endl;
}

int main(){
    int x,y;
    while(cin >> x >> y){
        if(x==0 && y == 0){
            break;
        }
        solve(x,y);
    }
}

Measured memory_bytes: 0
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end #Using .sort.reverse instead decreases Exec Time but increases Memory Usage
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


A,B = gsmi

def calc(c)
	c += 1
	bl = c.bit_length
	ans = []
	ans << c/2%2
	1.upto(bl-1) do |i|
		if c/(2**i)%2 == 0
			ans << 0
		elsif c%(2**i)%2 == 1
			ans << 1
		else
			ans << 0
		end
	end
	ans.reverse.join.to_i(2)
end

puts calc(B) ^ calc(A-1)

Measured memory_bytes: 1788
import java.util.Scanner;                                                                     
class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(true){
            int a = in.nextInt();
            String op = in.next();
            int c = in.nextInt();

            if(op.equals("+")){
                System.out.println(a + c);
            }else if(op.equals("-")){
                System.out.println(a - c);
            }else if(op.equals("*")){
                System.out.println(a * c);
            }else if(op.equals("/")){
                System.out.println(a / c);
            }else if(op.equals("?")){
            break;
            }
        }
    }
}

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



int main(){
  string s,t;
  cin >> s >> t;
  int n=s.size()-t.size()+1;
  int ans=0;
//  cout << n << endl;
  rep(i,0,n){
    int cnt=0;
    rep(j,0,t.size()){
      if(s[i+j]==t[j]) cnt++;
    }
    ans=max(ans,cnt);
//    cout << cnt << endl;
  }
  cout << t.size()-ans<< endl;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;

#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<Int, Int> PLL;
typedef pair<double, double> PDD;
typedef complex<double> base;

const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 10000007;
const int MAX2 = 7777;
const int MAXE = 100000;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;

int p[MAX];

vector<int> g[107];
int M[107];
bool U[107];

bool dfs(int v) {
	if (U[v])  return 0;
	U[v] = 1;
	FOR(i,0,SZ(g[v]))
	{
		int to = g[v][i];
		if (M[to] == -1 || dfs(M[to])) {
			M[to] = v;
			return 1;
		}
	}
	return 0;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("distance.in",  "r", stdin);
    //freopen("distance.out", "w", stdout);
    //freopen("out.txt" , "w" , stdout);

		int n;
	cin >> n;
	VI A(n);
	int c0 = 0;
	int c1 = 0;
	int c2 = 0;
	FOR(i,0,n)
	{
		cin >> A[i];
		if (A[i]%4==0)++c2;
		else
		if (A[i]%2==0)++c1;
		else
			++c0;
	}

	if (c0+(c1>=1)>c2+1) cout<<"No"<<endl;
	else cout <<"Yes"<<endl;


    return 0;
}
















Measured memory_bytes: 640
#include <stdio.h>


int selectionSort(int A[],int N){
    int i, j, t, sw =0,minj;
    for (i=0; i <N -1; i++){
        minj = i;
        for (j=i; j<N;j++){
        if (A[j] <A[minj]) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;     // 交換する
    if (i !=minj) sw++;
    }
    return sw;
}

int main(){
    int A[100], N, i, sw;
    scanf("%d",&N);
    for(i = 0; i<N; i++) scanf("%d",&A[i]);
    
    sw = selectionSort(A,N);
    
    for (i = 0; i<N; i++){
        if(i > 0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    
    return 0;
}



Measured memory_bytes: 2140
from collections import defaultdict

class TreeNode():

  def __init__(self, val):
    self.val = val
    self.parent = -1
    self.sibling = -1
    self.left = None
    self.right = None
    self.depth = -1
    self.height = -1

  def node_type(self):
    if self.depth == 0:
      return "root"
    elif self.left or self.right:
      return "internal node"
    else:
      return "leaf"

  def get_degree(self):
    deg = 0
    if self.left: deg += 1
    if self.right: deg += 1

    return deg

  def __str__(self):
    # degree = num of children
    return "node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(
      str(self.val), str(self.parent), str(self.sibling), str(self.get_degree()), str(self.depth), str(self.height), str(self.node_type()))

def calc_depth(root, level):
  if root is None: return
  root.depth = level

  calc_depth(root.left, level+1)
  calc_depth(root.right, level+1)

def calc_height(root):
  if root is None: return 0

  leftHeight = calc_height(root.left)
  rightHeight = calc_height(root.right)

  return 1 + max(leftHeight, rightHeight)

num = int(input())
nodes = defaultdict(int)

for i in range(num):
  ins = list(map(int, input().split()))
  val = ins[0]

  if nodes[val] == 0:
    nodes[val] = TreeNode(val)
  n = nodes[val]

  left_val, right_val = ins[1], ins[2]
  
  if left_val != -1:
    # initalize treenode
    if nodes[left_val] == 0:
      nodes[left_val] = TreeNode(left_val)

    # appending to n.left
    n.left = nodes[left_val]
    n.left.parent = n.val
    # get sibling
    if right_val != -1:
      n.left.sibling = right_val

  if right_val != -1:
    if nodes[right_val] == 0:
      nodes[right_val] = TreeNode(right_val)

    n.right = nodes[right_val]
    n.right.parent = n.val
    if left_val != -1:
      n.right.sibling = left_val

root = [node for node in nodes.values() if node.parent == -1][0]
calc_depth(root, 0)
for i in range(num):
  n  = nodes[i]
  n.height = calc_height(n) - 1

sort_nodes = sorted(nodes.items(), key=lambda x:x[0] )
for _, node in sort_nodes:
  print(node)


Measured memory_bytes: 6024
#include<stdio.h>
int main(){
    int H,W;
    int i,j;
    while(1){
        scanf("%d%d", &H,&W);
        if(H == 0 && W == 0){break;}
        for(i = 1;i <= H;i++){
            for(j = 1;j <= W;j++){
                if(1 < i && i < H && 1 < j && j < W){
                    printf(".");
                }
                else{
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2044
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

long long gcd(long long a, long long b) {
    if (a < b) {
        std::swap(a, b);
    }
    while (a%b > 0) {
        long long buf = b;
        b = a%b;
        a = buf;
    }
    return b;
}

int main() {
    int n = 0;
    cin >> n;
    vector<ll> t(n);
    for (int i=0; i<n; i++) {
        cin >> t.at(i);
    }
    ll ans = t.at(0);
    for (int i=1; i<n; i++) {
        ll buf = gcd(ans, t.at(i));
        ans = ans/buf*t.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
N,M=map(int,input().split())
price_value = []
for _ in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    v = ["0"]*N
    for i in range(N):
        if i+1 in c:
            v[i] = "1"
    v = "".join(v)
    v = int(v, base=2)
    price_value.append((a, v))

INF = float("inf")
dp = [[INF] * (2**N) for _ in range(M+1)]
dp[0][0] = 0
for i in range(1, M+1):
    price, value = price_value[i-1]
    for j in range(2**N):
        dp[i][j | value] = min(
            dp[i][j | value], dp[i-1][j] + price
        )
        dp[i][j] = min(dp[i][j], dp[i-1][j])
ans = dp[-1][-1]
print(ans if ans != INF else -1)

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

int main()
{
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			int lb = upper_bound(L.begin(), L.end(), L[i] - L[j]) - L.begin();
			res += max(0, j - lb);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;

int comp[N], p[N];
vector<int> g[N];

void dfs(int i, int id);

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	for (int i = 1; i <= m; ++i) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	int nxt = 1;
	for (int i = 1; i <= n; ++i) {
		if (!comp[i]) {
			dfs(i, nxt++);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (comp[p[i]] == comp[i]) {
			++ans;
		}
	}
	cout << ans << endl;
}

void dfs(int i, int id) {
	comp[i] = id;
	for (auto &j : g[i]) {
		if (!comp[j]) {
			dfs(j, id);
		}
	}
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,i; cin >> n >> i;
    OUT(n-i+1);

    return 0;
}



Measured memory_bytes: 256
S = gets.chomp
MOD = 2019

ans = 0
counter = Hash.new(0)
counter[0] += 1

base = 1
v = 0

S.chars.reverse_each do |s|
  v += s.to_i * base
  v %= MOD

  ans += counter[v]
  counter[v] += 1

  base *= 10
  base %= MOD
end

puts ans


Measured memory_bytes: 24952
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define repi(i,a) for(auto i = a.begin(); i!= a.end() ;++i) 
#define repdi(i,a) for(auto i = a.rbegin(); i!=a.rend();++i) 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) (int)a.size() 
#define all(a) a.begin(),a.end()
#define mod 998244353
#define limit 1000
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;   

#define int long
typedef vector<int> vii;
typedef pair<ll,ll> pii;
typedef vector<pii> vpi;
typedef vector<vector<ll> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int n,m,dp[100001];
vector<int> g[100001];

int ans(int node) {
	int mx = 0 ;
	if(dp[node]!=-1) return dp[node];
	for(auto i : g[node]) {
		mx = max(mx , 1 + ans(i));
	}

	return dp[node] = mx ;
 
}

void solve() {
	cin >> n >> m ;
	fl(dp,-1);
	rep(i,0,m) {
		int x,y; cin >> x >> y ;
		g[x].eb(y);
	}
	int mx = 0 ;
	rep(i,1,n+1) { mx = max(mx , ans(i)); }
	cout << mx << nl ;
}

int32_t main() {
 
    fast; 
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve() ;
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <map>

using namespace std;

int x[50], y[50];

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

    map<pair<int, int>, int> diff;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i != j)
            {
                int dx = x[i] - x[j];
                int dy = y[i] - y[j];
                auto p = diff.find(pair<int, int>(dx, dy));
                if (p == diff.end())
                {
                    diff.insert(pair<pair<int, int>, int>(pair<int, int>(dx, dy), 1));
                }
                else
                {
                    p->second++;
                }
            }
        }
    }

    int m = 0;
    for (auto it = diff.begin(); it != diff.end(); it++)
    {
        m = max(m, it->second);
    }

    cout << n - m << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
int main(){
	int A; cin >> A;
	A--; //１個でA口増やせる 
	int B; cin >> B; //want
/*	if(B==1){
		cout<<0<<endl;
	}*/
	//else{
		cout<<((B-1)+A-1)/A<<endl;
	//}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;
long long kaizyou(int N);
long long POW(int J);

bool judge(int dt, int dx, int dy);

int main()
{
    string s;
    cin >> s;

    bool judge = true;
    for(int i=0; i<s.size()-1;i++ )
    {
        if(s[i] == s[i+1])
        {
            judge = false;
            break;
        }
    }

    if(judge)
    {
        cout << "Good";
    }else
    {
        cout << "Bad";
    }
    
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K; cin >> N >> K;
  ll X = 0, Y = 0, Z = 0;
  for(ll i = 1; i <= N; i++){
    if(i%K == 0) X++;
    if(i%K == K/2 && K%2 == 0) Y++;
  }
  cout << X*X*X+Y*Y*Y << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;


int main() {
    string str;
    cin >> str;

    if (str == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
    } else if (str.size() == 26) {
        string tmp = str;
        next_permutation(str.begin(), str.end());

        string kekka = "";
        for (int i = 0; i < int(str.size()); i++) {
            kekka += str.at(i);
            if (str.at(i) > tmp.at(i)) break;
        }

        cout << kekka;
    } else {
        map<char,int> mp;
        for (int i = 0; i < int(str.size()); i++) mp[str[i]]++;

        for (int i = 0; i < 26; i++) {
            if (mp['a' + i] == 0) {
                str += 'a' + i;
                cout << str << endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;

class Hello
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int sum = 0;
        foreach (var i in x)
        {
            int a = i * 2;
            int b = Math.Abs(i - k) * 2;
            sum += Math.Min(a, b);

        }

        Console.WriteLine(sum);
    }

}


Measured memory_bytes: 13396
N = int(raw_input())
X = map(int, raw_input().split())
indexX = []
for i in range(0, N):
	indexX.append([i, X[i]])
indexX.sort(key=lambda val:val[1])
medlist = []
for i in range(0, N):
	if i < N/2: medlist.append([indexX[i][0], indexX[N/2][1]])
	else: medlist.append([indexX[i][0], indexX[N/2-1][1]])
medlist.sort(key=lambda val:val[0])
for i in range(0, N):
	print medlist[i][1]


Measured memory_bytes: 104412
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    sumA = sum(A)

    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        return divs

    from itertools import accumulate
    divs = trial_division(sumA)
    ans = 0
    for d in divs:
        R = [a % d for a in A if a % d != 0]
        R.sort()
        S = [acc for acc in accumulate(R)]
        M = len(S)
        # print(d, R, S)
        if M == 0:
            ans = max(ans, d)
            continue
        for i in range(M-1):
            ne = S[i]
            po = d*(M-1-i) - (S[M-1] - S[i])
            if po == ne and po <= K:
                ans = max(ans, d)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41692
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
 
#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)
 
using namespace std;
typedef long long ll;
const ll N=22e4,M=N<<1,K=M<<1;
 
inline int read()
{
	int o=0; char ch=' ';
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())o=o*10+(ch^48);
	return o;
}
 
int ne[K],la[M],lb[K],c[K],bb[N][2];
int dep[M];
int y[M];
 
int fa[N],re[N];
int gs[N];
int ke[M];
int be[N],en[N];
int n,m,S,T,oo;
int d[M];
 
inline int get(int o)
{return (fa[o]==o)?(o):(fa[o]=get(fa[o]));}
 
inline void llb(int a,int b,int cc)
{ne[++oo]=la[a]; la[a]=oo; lb[oo]=b; c[oo]=cc;}
 
inline void bfs()
{
	fo(i,1,T)dep[i]=-1;
	dep[S]=0;
	int l=0,r=1;
	d[r]=S;
	while(l<r){
		int o=d[++l];
		for(int y=la[o];y;y=ne[y])
		if(c[y]==1&&dep[lb[y]]==-1){
			dep[lb[y]]=dep[o]+1;
			d[++r]=lb[y];
		}
	}
	fo(i,1,T)y[i]=la[i];
}
 
inline int flow(int o)
{
	if(o==T)return 1;
	for(;y[o];y[o]=ne[y[o]])
	if(dep[lb[y[o]]]==dep[o]+1&&c[y[o]])
	if(flow(lb[y[o]])){
		c[y[o]]=0;
		c[y[o]^1]=1;
		return 1;
	}
	dep[o]=-1;
	return 0;
}
 
inline void dg(int o)
{
	for(int y=la[o];y;y=ne[y])
	if(!fa[lb[y]]){
		fa[lb[y]]=o;
		bb[re[lb[y]]][0]=o;
		bb[re[lb[y]]][1]=lb[y];
		++oo;
		dg(lb[y]);
	}
}
 
int main()
{
	scanf("%d",&n);
	fo(i,1,n)fa[i]=i;
	fo(i,1,n-1){
		gs[i]=read();
		be[i]=oo+1; 
		fo(l,1,gs[i]){
			ke[++oo]=read();
			if(l!=1)
			if(get(ke[oo-1])!=get(ke[oo]))fa[fa[ke[oo]]]=fa[ke[oo-1]];
		}
		en[i]=oo;
	}
	int kk=get(1);
	fo(i,2,n)if(get(i)!=kk){
		puts("-1");
		return 0;
	}
	
	S=n*2,T=S^1,oo=1;
	fo(i,1,n)llb(S,i,1),llb(i,S,0);
	fo(i,1,n-1)fo(l,be[i],en[i])llb(ke[l],n+i,1),llb(n+i,ke[l],0);
	fo(i,1,n-1)llb(n+i,T,1),llb(T,n+i,0);
	
	int ans=0;
	while(true){
		bfs();
		if(dep[T]==-1)break;
		else while(flow(S))++ans;
	}
	
	if(ans!=n-1){
		puts("-1");
		return 0;
	}
	
	int root=0;
	fo(i,1,n)fa[i]=0;
	fo(i,1,n){
		int ok=0;
		for(int y=la[i];y;y=ne[y])
		if(c[y]==0&&lb[y]!=S){
			re[i]=lb[y]-n;
			ok=1; break;
		}
		if(!ok)root=i;
	}
	
	oo=0;
	fo(i,1,n)la[i]=fa[i]=0;
	fo(i,1,n)if(root!=i)
	fo(l,be[re[i]],en[re[i]])if(ke[l]!=i)llb(ke[l],i,0);
	fa[root]=-1;
	oo=0;
	dg(root);
	if(oo!=n-1)puts("-1");
	else fo(i,1,n-1)printf("%d %d\n",bb[i][0],bb[i][1]);
}

Measured memory_bytes: 26368
from functools import reduce
from fractions import gcd

N, X = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def main():
    ds = list(map(lambda n: abs(X - n), P))
    ans = reduce(lambda a, b: gcd(a, b), ds)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 16304
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int sci[4],soc[2];
	int sum=0;
	for(int i=0;i<4;i++){
		cin>>sci[i];
		sort(sci,sci+i+1,greater<int>());
	}

	for(int i=0;i<3;i++){
		sum+=sci[i];
	}
	for(int i=0;i<2;i++){
		cin>>soc[i];
		sort(soc,soc+i+1,greater<int>());
	}
	for(int i=0;i<1;i++){
		sum+=soc[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;

#define PRINT(a) cout<<(a)<<endl;

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if (a <= b&&b <= a + W) { PRINT(0); }
	else if (b > a + W) {PRINT(b - (a + W));}
	else PRINT(a - (b + W));
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> ppiii;

void solve() {
  int n;
  cin >> n;
  int ret = 0;
  while(n--) {
    int t;
    cin >> t;
    ret ^= t;
  }
  if(ret == 0) cout << "Yes\n";
  else cout << "No\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256
n = int(input())
res = []
if n%2 == 0:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n + 1:
                continue
            res.append([i, j])
elif n % 2 == 1:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n:
                continue
            res.append([i, j])
print(len(res))
for (i,j) in res:
    print(i, j)


Measured memory_bytes: 4124
a, b = (int(_) for _ in input().split())
if a < 0 and b > 0:
    print('Zero')
elif a > 0 and b > 0:
    print('Positive')
else:
    diff = abs(b - a) + 1
    if diff % 2 == 0:
        print('Positive')
    else:
        print('Negative')
    

Measured memory_bytes: 3064
//Bismillahir Rahmanir Rahim
// AtCoder-Battle
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int th,ts,ah,as;
  cin>>th>>ts>>ah>>as;
  int ahts = ceil((double) ah/ts);
  int thas = ceil((double) th/as);
  
  if(thas >= ahts) 
  cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3632
from functools import reduce
def C(n,r):
    if not 0<=r<=n: return 0
    r=min(r,n-r)
    N=reduce(lambda x,y: x*y%M, range(n,n-r,-1),1)
    D=reduce(lambda x,y: x*y%M, range(1,r+1),1)
    return N*pow(D,M-2,M)%M
def f(r,c): return C(r+c,c)
M=10**9+7
a,b,c,d=map(int, input().split())
print((f(c+1,d+1)-f(a,d+1)-f(c+1,b)+f(a,b))%M)

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

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  if(a % k == 0 || b % k == 0){
    cout << "OK" << endl;
  }else if((b - a) / k >= 1){
    cout << "OK" << endl;
  }else if(a % k > b % k){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long K = sc.nextInt();
        long ans = 0;
        long a = N/K;
        ans += a*a*a;
        if(K%2 == 1){
            System.out.println(ans);
            return;
        }else{
            long b = 0;
            if(N >= K/2) b += (N-K/2)/K+1;
            ans += b*b*b;
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int X;
    cin >> X;
    cout << 8 - (X - 400) / 200 << endl;

    return 0;
}

Measured memory_bytes: 3648
n=gets.chomp.to_i
a=gets.split.map(&:to_i)

cnt=Array.new(5){0}
a.each{|e| cnt[(e+3)%4+1]+=1}
cnt[1]+=cnt[3]
pre=-1
n.times do |i|
  if i==0
    if cnt[1]>0
      pre=1
      cnt[1]-=1
    elsif cnt[2]>0
      pre=2
      cnt[2]-=1
    elsif cnt[4]>0
      pre=4
      cnt[4]-=1
    end
  else
    if pre==1
      if cnt[4]>0
        pre=4
        cnt[4]-=1
      else
        puts 'No'
        exit 0
      end
    elsif pre==2
      if cnt[2]>0
        pre=2
        cnt[2]-=1
      elsif cnt[4]>0
        pre=4
        cnt[4]-=1
      else
        puts 'No'
        exit 0
      end
    elsif pre==4
      if cnt[1]>0
        pre=1
        cnt[1]-=1
      elsif cnt[2]>0
        pre=2
        cnt[2]-=1
      elsif cnt[4]>0
        pre=4
        cnt[4]-=1
      else
        raise
      end
    end
  end
end

puts 'Yes'

Measured memory_bytes: 8468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


class Main
{	
	
	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		int k = fs.nextInt();
		int arr[] = fs.arrayIn(n),i=0;
		while (i<k) i++;
		
		for(; i<n; i++)
		{
			if(arr[i-k] < arr[i])
				System.out.println("Yes");
			else
				System.out.println("No");
		}
		
			
	}


	
}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int[] arrayIn(int n) throws IOException
	{
		int arr[] = new int[n];
		for(int i=0; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	

Measured memory_bytes: 57412
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    string S, T;
    cin >> S >> T;
    bool ans = true;

    for (char c = 'a'; c <= 'z'; ++c) {
        auto it = find(all(S), c);
        if (it != S.end()) {
            char subst = *(T.begin() + (it - S.begin()));

            rep(i, S.size()) {
                if (S[i] == c && T[i] != subst || S[i] != c && T[i] == subst) {
                    ans = false;
                }
            }
        }
    }

    write(ans ? "Yes" : "No");
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

int main(){
	long long A, B;
	cin >> A >> B;
	if(A > 9 || B > 9) {
		cout << -1 << endl;
	} else {
		cout << A * B << endl;
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}
bool bitcheck(ll x, ll y) { return (x >> y) & 1; }

template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll n;  ////
    cin >> n;
    vector<ll> as(n);
    REP(i, n) { cin >> as[i]; }
    ll ans = 0;
    REP(i, 61) {
        vector<ll> rui1(n + 1);
        vector<ll> rui0(n + 1);
        REP(j, n) {
            if (bitcheck(as[j], i)) {
                rui0[j + 1] += rui0[j] + (1LL << i);
                rui1[j + 1] += rui1[j];
            } else {
                rui0[j + 1] += rui0[j];
                rui1[j + 1] += rui1[j] + (1LL << i);
            }
            rui0[j + 1] %= mod;
            rui1[j + 1] %= mod;
        }
        REP(j, n) {
            if (bitcheck(as[j], i)) {
                ans += rui1[n] - rui1[j + 1] + mod;
            } else {
                ans += rui0[n] - rui0[j + 1] + mod;
            }
            ans %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10300
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define all(v) v.begin(), v.end()
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
signed main() {
	int a, b;
	cin >> a >> b;
	f(i, 10000) {
		if (i * 8 / 100 == a && i / 10 == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1),B(N);
  for(int i=0;i<N+1;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  long cnt=0;
  for(int i=0;i<N;i++){
    if(B.at(i) >= A.at(i)){
      cnt += A.at(i);
      if(A.at(i+1) >= B.at(i)-A.at(i)){
        A.at(i+1) -= B.at(i)-A.at(i);
        cnt += B.at(i)-A.at(i);
      }
      else{
        cnt += A.at(i+1);
        A.at(i+1)=0;
      }
    }
    else{
      cnt += B.at(i);
      A.at(i) -= B.at(i);
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
ll n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll a = 1;
  for(ll i=2; i*i<=n; i++) if(n%i==0) a=i;
  cout << a+n/a-2 << endl;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	string s;
	int n,cnt = 0;
	cin>>s>>n;
	while(n--){
		string ss;
		cin>>ss;
		ss = ss + ss;
		//cout<<ss<<endl;
		int line = 0;
		for(int i = 0 ; i < ss.size() ; i ++){
			//cout<<cnt<<" "<<ss.substr(i,s.size())<<" "<<s<<endl;
			if(s == ss.substr(i,s.size())){
				line=1;
			}
		}
		cnt += line;
	}
	cout<<cnt<<endl;
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> x(n), y(n), z(n), w(n);
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
        z[i] = x[i] + y[i];
        w[i] = x[i] - y[i];
    }
    sort(z.begin(), z.end());
    sort(w.begin(), w.end());
    cout << max((z[n-1] - z[0]), (w[n-1] - w[0])) << endl;

    return 0;
}

Measured memory_bytes: 9592
n,a,b = map(int,input().split())
if abs(a-b)%2 == 0:
    print(abs(a-b)//2)
else:
    if a - 1 > n - b:
        print((n-b+n-a+1)//2)
    else:
        print((a-1+b-1+1)//2)

Measured memory_bytes: 38384
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric> // 最大公約数が使える
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main()
{
    ll A,B,N;
    cin >> A >> B >> N;
    ll ans;

    ll x;
    x = min((B-1),N);
    
    
    ans = floor(A*x/B) - A*floor(x/B);
    cout << ans << endl;
    
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    int x = 1,y = 1, z = 1;
    cin >> n;
    vector<int> a(n);
    for (size_t i = x; i <= 98; i++)
    {
        for (size_t j = y; j <= 98; j++)
        {
            for (size_t k = z; k <= 98; k++)
            {
                int xyz = i+j+k;
                int fn = xyz*xyz-i*j-j*k-k*i;
                if( fn <= n){
                    a[fn-1]++;
                }
            }
            
        }
        
    }
    rep(i,n){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
	long long A, B;
	cin >> A >> B;
	long long c = B / A;
	int count = 1;
	while (1) {
		if (c == 1) {
			break;
		}
		c /= 2;
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <cmath>
#define ll long long int 

using namespace std;

ll n, m, k;
int a[100100];
vector<vector<ll> > v;
int main()
{
    //freopen("a.txt", "r", stdin);
    cin >> k;
    ll sum = 10;
    v.resize(10000);
    for (int i = 0; i < 10; i++)
        v[0].push_back(i);
    int top = 0;
    while (sum <= k) {
        top++;
        for (ll i = 0; i < v[top - 1].size(); i++) {
            for (ll j = 0; j < 10; j++) {
                ll vi = v[top - 1][i];
                if (vi && abs((vi % 10) - j) < 2) {
                    v[top].push_back(vi * 10ll + j);
                }
            }
        }
        sum += v[top].size();
    }
    sort(v[top].begin(), v[top].end());
    sum -= v[top].size();
    cout << v[top][k - sum];
    return 0;
}

Measured memory_bytes: 2232