akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public class Combination
{
    private readonly long[] Fact;
    private readonly long[] InvFact;  // モジュラ逆数

    public Combination(long n)
    {
        Fact = new long[n + 1];
        InvFact = new long[n + 1];

        long f = 1;
        Fact[0] = f;
        for (long i = 1; i <= n; i++)
        {
            f *= i;
            f %= Mod;
            Fact[i] = f;
        }

        long inv = ModInt.GetInv(f).Num;

        InvFact[n] = inv;
        for (long i = n - 1; i >= 0; i--)
        {
            InvFact[i] = (InvFact[i + 1] * (i + 1)) % Mod;
        }
    }

    // nCr
    public ModInt GetCombination(long n, long r)
    {
        var comb = Fact[n] * InvFact[r] % Mod;
        comb = comb * InvFact[n - r] % Mod;
        return new ModInt(comb);
    }
    // nPr
    public ModInt GetPermutation(long n, long r)
    {
        return new ModInt(Fact[n] * InvFact[n - r] % Mod);
    }
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var m = vals[1];

        // A: mPn
        // B: all - bad = A - (nC1*(m-1Pn-1) + nC2*(m-2Pn-2) - ... + (-1)^(i-1) * nCi(m-iPn-i))
        var comb = new Combination(m);
        var A = comb.GetPermutation(m, n);
        var B = A;
        for (int i = 1; i <= n; i++)
        {
            var flag = i % 2 == 0 ? 1 : -1;
            B += flag * comb.GetCombination(n, i) * comb.GetPermutation(m - i, n - i);
        }

        Console.WriteLine(A * B);
    }
}

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

def solve(N: int, K: int):
    inN = N
    sum = 0.0
    rate = 1.0
    if N >= K :
        sum += (N-(K-1))*rate
        N = K - 1
    while K >= 2:
        K = math.ceil(float(K)/2.0)
        rate /= 2.0
        if N > K-1:
            sum += (N-(K-1))*rate
            N = K - 1
    print(sum/float(inN))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 998244353
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-7;
const int N=200+10,maxn=20000+10,inf=0x3f3f3f;

ll x[N],y[N];
map<pair<ll,ll>,ll>a;
ll quick(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll ans=(quick(2,n)-n-1+mod)%mod;
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++)
    {
        a.clear();
        for(int j=i+1;j<=n;j++)
        {
            ll t1=y[i]-y[j];
            ll t2=x[i]-x[j];
            ll te=__gcd(t1,t2);
            t1/=te;t2/=te;
            ++a[make_pair(t1,t2)];
        }
        for(auto x : a)
        {
            ans=(ans-quick(2,x.second)+1+mod)%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/********************

********************/


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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  long sum = 0;
  
  for (int i = 0; i < K; i++) {
    sum += p.at(i);
  }
  
  cout << sum << endl;
  return 0;
}

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

typedef long long ll;

int main()
{
	ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll res = 0;
  if(k<=a)
  {
   	res += k;
    cout<<res<<endl;
  }
  else
  {
    res += a;
    k = k - a;
    if(k<=b)
    {
      cout<<res<<endl;
    }
    else
    {
      k = k - b;
      res -= k;
      cout<<res<<endl;
    }
  }
}
    

Measured memory_bytes: 3636
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys


def tes(n):
    return int((26**(n+1)-1)/(26-1))


n = int(stdin.readline().rstrip())
b = n
data1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
         'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
data2 = []
for el in range(1, 16):
    data2.append('a'*el)
d = []
pos = 0
for el in range(12):
    d.append(tes(el))
for el in range(len(d)):
    if n < d[el]:
        pos = el-1
        break
num = d[pos]
diff = n-num
de = []
counter = 16
while True:
    de.append(diff % 26)
    diff = int(diff/26)
    counter -= 1
    if counter == 0:
        break
stri = data2[pos]
res = ''
count = 0
for el in stri:
    res += data1[de[count]]
    count += 1
print(''.join(list(reversed(res))))


Measured memory_bytes: 77236
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstring>
#include <iomanip>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;

int n, ans = 1, type;
int a[N];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

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

	for (int i = 1; i < n; i++) {
		if (type == 1 && a[i] < a[i - 1]) {
			type = 0;
			ans++;
			continue;
		}
		if (type == -1 && a[i] > a[i - 1]) {
			type = 0;
			ans++;
			continue;
		}
		if (a[i] > a[i - 1]) type = 1;
		if (a[i] < a[i - 1]) type = -1;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char,ll> m;
    ll ans=0;
    for(int i=0;i<n;i++){
        m[s.at(i)]++;
    }
    //cout << m['R'] << " " << m['G'] << " " << m['B'] << endl; 
    ans = m['R'] * m['G'] * m['B'];
    //cout << ans << endl;
    ll err=0;
    for(int i=0;i<n;i++){
        for(int k=i+1;k<n;k++){
            if((k+i)%2==0){
                if(s.at(i) != s.at(k) && s.at(k) !=s.at((k+i)/2) && s.at((k+i)/2) != s.at(i)){
                    //cout <<  s.at(i) << " " << s.at((k+i)/2) << " " << s.at(k) << endl;
                    err++;                
                }
            }
        }
    }
    cout << ans - err << endl;
}

Measured memory_bytes: 3632
n,m =map(int,input().split())

a =  sorted([int(x)//2 for x in input().split()],reverse=True)

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

import math

lcm1 = 1
for i in a:
    lcm1 = lcm(lcm1, i)
    if((lcm1//i)%2==0):
        print(0)
        exit()

print(math.ceil((m//lcm1)/2))

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

const int mod = 1e9+7;

int Pow(int a, int b)
{
	int x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b & 1) x = (ll)x * a % mod;
		a = (ll)a * a % mod;
	}
	return x;
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<vector<int>> adj(n);
	for (int i = 1, u, v; i < n; ++i)
	{
		cin >> u >> v;
		adj[--u].push_back(--v);
		adj[v].push_back(u);
	}

	vector<int> t(n), it(n);
	t[0] = it[0] = 1;
	for (int i = 1; i < n; ++i)
	{
		t[i] = t[i-1] * 2 % mod;
		it[i] = Pow(t[i], mod-2);
	}

	int ans = 0;
	vector<int> sz(n);
	function<void(int, int)> dfs = [&](int u, int p)
	{
		sz[u] = 1;
		vector<int> k;
		for (auto v : adj[u])
			if (v != p)
			{
				dfs(v, u);
				sz[u] += sz[v];
				k.push_back(sz[v]);
			}
		if (p != -1)
			k.push_back(n-sz[u]);

		ans = (ans + (ll)it[1] * (1 + mod - it[n-1])) % mod;
		for (auto i : k)
			ans = (ans + mod - (ll)(t[i] + mod - 1) * it[n-1] % mod * it[1] % mod) % mod;
	};

	dfs(0, -1);
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 31616
n,x = map(int, input().split())

a,p = [1], [1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1
    elif X<=1+a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1]+1+f(N-1,X-2-a[N-1])

print(f(n,x))

Measured memory_bytes: 3188
#include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

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

bool isPalindromic(string s) {
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int main() {
    int A, B;
    scanf("%d %d", &A, &B);

    int ans = 0;
    REP(A, i, B + 1) {
        char c[6];
        sprintf(c, "%d", i);
        if (isPalindromic(string(c))) {
            ans++;
        }
    }

    printf("%d\n", ans);

    return 0;
}


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

using namespace std;
double a[111];
int main()
{
	int n;
	double sum = 0,mins=999999999;
	int wz=-1;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		
		scanf("%lf", &a[i]);
		sum += a[i];
	}
	sum /= n;
	for (int i = 0; i < n; i++)
	{
		if (fabs(sum - a[i]) < mins)
		{
			mins = fabs(sum - a[i]);
			wz = i;
		}
	}
	printf("%d", wz);
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d\n" @@ fun n ->
  let spis = Array.init n @@ fun i -> Scanf.scanf " %s %d" @@ fun s p -> (s, p, i) in
  Array.sort (fun (s, p, _) (s', p', _) -> compare (s, ~- p) (s', ~- p')) spis;
  Array.iter (fun (_, _, i) -> Printf.printf "%d\n" (i + 1)) spis

Measured memory_bytes: 3896
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {

	ArrayList<Integer>[] graph;
	int N,K;

	private class P{
		int f,s;
		public P(int f,int s){
			this.f = f;
			this.s = s;
		}
	}

	public void solve(){
		N = nextInt();
		K = nextInt();

		graph = new ArrayList[N];
		for(int i = 0;i < N;i++){
			graph[i] = new ArrayList<Integer>();
		}

		for(int i = 0;i < N - 1;i++){
			int a = nextInt() - 1;
			int b = nextInt() - 1;

			graph[a].add(b);
			graph[b].add(a);
		}

		int ans = 0;

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

			Queue<P> q = new LinkedList<P>();
			q.add(new P(i,0));
			boolean[] used = new boolean[N];
			int connected = 0;

			if(K % 2 == 1){
				q.add(new P(graph[i].get(0),0));
			}

			while(q.size() > 0){

				P p = q.poll();

				if(used[p.f])continue;
				if(p.s > K / 2)continue;
				used[p.f] = true;
				connected++;
				for(int n : graph[p.f]){
					q.add(new P(n,p.s + 1));
				}
			}
			ans = Math.max(ans, connected);
		}
		out.println(N - ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 19184
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll k; cin>>k;
    queue<ll> q;
    for(int i=1;i<=9;i++)q.push(i);
    int i=0;
    while(1){
        ll a=q.front();
        q.pop();
        i++;
        if(i==k){
            cout<<a<<endl;
            return 0;
        }
        else for(ll l=a%10-1;l<=a%10+1;l++){
            if(l<0||l==10)continue;
            q.push(a*10+l);
        }
    }
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		br.readLine();

		String line = br.readLine();

		List<Integer> ary =  Arrays.asList(line.split(" ")).stream().map(Integer::valueOf).sorted().collect(Collectors.toList());

		int nagaiHen = ary.get(ary.size() - 1);
		ary.remove(ary.size() - 1);

		int hokanoHen = 0;

		for(int i : ary){
			hokanoHen += i;
		}

		System.out.println(nagaiHen < hokanoHen ? "Yes" : "No");

	}
}


Measured memory_bytes: 27984
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;

#define REP(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define sz size()
#define INF (1<<25)
#define all(a) (a).begin(),(a).end()
#define V 10100
typedef pair<int,int> P;

struct edge{
  int from,to,cost,cap,rev;
  bool operator<(const edge x)const{return cost>x.cost;}
};

vector<edge> G[V];
int d[V];
bool use[V];
int h[V],pv[V],pe[V];
int v,e;

void add_edge(int s,int g,int c,int p){
  G[s].pb((edge){s,g,c,p,G[g].sz});
  G[g].pb((edge){g,s,-c,0,G[s].sz-1});
}

int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+v,0);
  while(f>0){
    priority_queue<P ,vector<P> ,greater<P> > q;
    fill(d,d+v,INF);
    d[s] = 0; q.push(P(0,s));
    while(q.sz){
      P p = q.top();q.pop();
      int u = p.second;
      if(d[u] > p.first)continue;
      REP(i,G[u].sz){
	edge &e = G[u][i];
	if(e.cap>0 && d[e.to] > d[u] + e.cost + h[u] - h[e.to]){
	  d[e.to] = d[u] + e.cost + h[u] - h[e.to];
	  pv[e.to] = u; pe[e.to] = i;
	  q.push(P(d[e.to],e.to));
	}
      }
    }
    if(d[t]==INF)return -1;
    REP(u,v)h[u] += d[u];

    int x = f;
    for(int u=t;u!=s;u=pv[u])x = min(x,G[pv[u]][pe[u]].cap);
    f -= x;
    res += x*h[t];
    for(int u=t;u!=s;u=pv[u]){
      edge &e = G[pv[u]][pe[u]];
      e.cap -= x; G[u][e.rev].cap += x;
    }
  }
  return res;
}

int n;
int a[1010],b[1010];
vector<int> len;

int main(){
  scanf("%d",&n);
  len.clear();

  for(int i=0;i<n;i++){
    scanf("%d%d",&a[i],&b[i]);
    len.pb(a[i]); len.pb(b[i]);
  }

  sort(all(len));
  len.erase(unique(all(len)),len.end());

  v = n + len.size() + 3;
  for(int i=0;i<v;i++)G[i].clear();

  for(int i=0;i<n;i++){
    add_edge(v-2,i,0,1);
    add_edge(i,v-3,0,1);
    int tmp = lower_bound(all(len),a[i])-len.begin() + n;
    add_edge(i,tmp,-b[i],1);
    tmp = lower_bound(all(len),b[i])-len.begin() + n;
    add_edge(i,tmp,-a[i],1);
  }

  for(int i=0;i<len.size();i++)add_edge(n+i,v-1,0,1);
  add_edge(v-3,v-1,0,INF);

  printf("%d\n",-1*min_cost_flow(v-2,v-1,n));
}

Measured memory_bytes: 1876
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

	int t;
	int n,h;
	int bef;
	int hi,lo;

	cin>>t;

	while(t--){
		cin>>n;
		bef=-1,hi=0,lo=0;
		while(n--){
			cin>>h;
			if(bef!=-1){
				if(bef<h){
					hi=max(hi,h-bef);
				}
				else{
					lo=max(lo,bef-h);
				}
			}
			bef=h;
		}
		cout<<hi<<" "<<lo<<endl;
	}


	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;
	int e;
	
	scanf("%d %d", &a, &b);
	
	c = a * b;
	d = (2 * a) + (2 * b);
	
	printf("%d %d\n", c, d);
	
	return (0);
}

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

using namespace std;

int dp[1024][1024], num;
struct deck { int top, bottom; };
const int  INF = (1 << 30);

int main()
{

	cin >> num;
	vector<deck> mount(128);

	for(int i = 0; i < num; i++)
	{
		cin >> mount[i].top >> mount[i].bottom;

		for(int j = 0; j < num; j++)
		{
			if(i == j) continue;
			dp[i][j] = INF;
		}

	}


	for(int w = 1; w < num; w++)
	{
		for(int i = 0; i + w < num; i++)
		{
			int j = i + w;
			for(int k = i; k < j; k++)
			{
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + mount[i].top * mount[k].bottom * mount[k+1].top * mount[j].bottom );
			}
		}
	}

	cout << dp[0][num -1] << endl;
}

Measured memory_bytes: 1500
/*

I will just keep trying.I know can do it.And I will!!. 

 
   PPPPPPPP    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   PP    PP    UU      UU     CC          CC           HH     HH     UU      UU
   PP    PP    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   PPPPPPPP    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   PP          UU      UU     CC          CC           HH     HH     UU      UU
   PP          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
  

*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    string s;
    cin >> s;
    int n = s.length();
    int rm=0;
    int m = 2019;
    vi rmn(2019);
    rmn[0]=1;
    int x=1,ans=0;
    
    for(int i=n-1;i>=0;i--){
    	rm = (rm + (s[i]-'0')*x)%m;
    	rm = rm %m;
    	x = (x*10)%m;
    	ans+=rmn[rm];
    	rmn[rm]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3768
N = int(input())

ND_list = []
for i in range(1,int(N**0.5)+1):
    if N % i == 0:
        ND_list.append([i, N//i])

length_list = []

for i in range(len(ND_list)):
    ND_i = ND_list[i]
    x, y  = ND_i[0], ND_i[1]
    length = x**2 + y**2
    length_list.append(length)

idx = length_list.index(min(length_list))
print(ND_list[idx][0] + ND_list[idx][1] -2)


Measured memory_bytes: 3688
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int n; cin >> n && n;)
	{
		int y, idx = 0;
		double mx = 0;
		
		cin >> y;
		
		rep(i, n)
		{
			int b, t, r;
			cin >> b >> r >> t;
			
			double pnt = (t - 1 ? pow(1.0 + r / 100.0, y) : 1.0 + y * r / 100.0);
			if(mx < pnt)
			{
				mx = pnt;
				idx = b;
			}
		}
		
		cout << idx << endl;
	}
}

Measured memory_bytes: 0
N=input()

if len(N)==1:
    print(int(N))
elif len(N)==2:
    print(9)
elif len(N)==3:
    print(9+int(N)-99)
elif len(N)==4:
    print(909)
elif len(N)==5:
    print(909+int(N)-9999)
else:
    print(90909)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
s = input().rstrip()
mod = 998244353

dic = {'R': 0, 'G': 0, 'B': 0}

answer = 1
for x in s:
    f, s, t = sorted(dic.values())
    if dic[x] < s:
        answer *= s - dic[x]
    elif dic[x] < t:
        answer *= t - s
    # t<=dic[x]
    else:
        answer *= n - dic[x]
    dic[x] += 1
    answer %= mod

print(answer % mod)

Measured memory_bytes: 3704
N, M = map(int, input().split())
a = [sorted(list(map(int, input().split()))[1:]) for _ in range(N)]
b = [i for i in range(1, M + 1)]
c = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(len(b)):
    if (not b[j] in a[i]) and b[j] in c:
      c.remove(b[j])
print(len(c))


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

int n, m = 1;
int a[100000];

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	vector<pair<int, int>> c;
	c.push_back(make_pair(a[n - 1], 1));

	for (int i = n - 2; i >= 0; i--) {
		if (a[i] >= c.back().first) {
			m++;
			c.push_back(make_pair(a[i], m));
		}
		else {
			int j = 0;

			while (a[i] >= c[j].first)
				j++;

			c[j].first = a[i];

			while (j > 0 && c[j].first < c[j - 1].first) {
				swap(c[j], c[j - 1]);
				j--;
			}
		}
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 100000;
const long long INF = 1LL << 60;

int main() {
	int N, K;
	long long X[MAX];

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}

	long long ans = INF;

	for (int i = 0; i <= N - K; i++) {
		long long L = X[i];
		long long R = X[i + K - 1];

		if (L < 0 && R < 0) ans = min(ans, -L);
		else if (L > 0 && R > 0)ans = min(ans, R);
		else ans = min(ans, R - L + min(abs(R),abs(L)));
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

int main(){
    ll n,c,ans=0;
    cin >> n;
    vector<ll> a(n),b(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    for(ll i=0;i<n;i++) cin >> b[i];
    for(ll i=0;i<n;i++){
         c = a[i]-b[i];
         if(c>0)    ans+=c;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	std::int64_t A, B, K;
	std::cin >> A >> B >> K;
	auto z = std::min(A, K);
	A -= z;
	K -= z;
	B -= std::min(B, K);
	std::cout << A << " " << B << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main(){
    char s[100005];
    int dp[100010] = {0};
    char t[4][8]={"dream","dreamer","erase","eraser"};

    scanf("%s", s);

    dp[0] = 1;
    for(int i = 0; i < strlen(s); ++i){
        if(dp[i] == 0) continue;
        for(int j = 0; j < 4; ++j){
            int k = 0;
            int flag = 1;
            while(t[j][k] != '\0'){
                if(s[i + k] != t[j][k]){
                    flag = 0;
                    break;
                }
                k++;
            }
            if(flag == 1) dp[i + strlen(t[j])] = 1;
        }
    }

    puts(dp[strlen(s)] ? "YES" : "NO");

    return 0;
}

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

int main() {
	// your code goes here
	char a[3];
	int i,l=0,m=0;
	for(i=0;i<3;i++)
	{
	    cin>>a[i];
	    if(a[i]=='5')
	    l++;
	    else if(a[i]=='7')
	    m++;
	}
	if(m==1&&l==2)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;

class CF2016FB
{
	static public void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int t = 0;
		int u;
		for(int i=1; i <= N; i++)
		{
			t += i;
			if(t >= N)
			{
				u = t - N;
				for(int j=1; j<=i; j++)
				{
					if(j != u)
						Console.WriteLine(j);
				}
				return;
			}
		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(998244353)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,m,K;cin>>n>>m>>K;
  ll ans = 0;
  //n-1個のうち何色を同じにしますか？
  rep(k,K+1){
    ans += nCr(n-1, k) * mpow(m-1, (n-1-k)) % MOD * m % MOD;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}

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


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

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> t(n);
    ll a = 0;
    for(int i = 0; i < n; i++) {
        cin >> t[i];
        if(!i) a = t[i];
        else a = a / gcd(a, t[i]) * t[i];
    }

    cout << a << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
#include <string>

#pragma warning(disable:4996)
#define MAX_N 10


struct Light {
	std::vector<int> connect;
	int p;
};

bool compare(Light& l, Light& r) {
	return l.connect.size() < r.connect.size();
}


std::vector <Light> lights;
std::vector <int > sw;
int sum = 0;

void refunc(int i) {
	if (i == sw.size()) {
		bool NG = false;
		for (int j = 0; j < lights.size(); ++j) {
			int sn = 0;
			for (int k = 0; k < lights[j].connect.size(); ++k) {
				int c = lights[j].connect[k]-1;
				if (sw[c] == 1) ++sn;
			}
			if (sn % 2 != lights[j].p) {
				NG = true;
				break;
			}
		}
		if (NG == false) ++sum;
		return;
	}

	sw[i] = 0;
	refunc(i + 1);
	sw[i] = 1;
	refunc(i + 1);
}

int main(void) {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; ++i) {
		sw.push_back(-1);
	}

	for (int i = 0; i < m; ++i) {
		Light light;
		int k = 0;
		scanf("%d", &k);
		for (int j = 0; j < k; ++j) {
			int s;
			scanf("%d", &s);
			light.connect.push_back(s);
		}
		lights.push_back(light);
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d", &lights[i].p);
	}
	refunc(0);
	printf("%d", sum);
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
ll X[100005];

ll modpow(ll n) {
    ll s = 1, p = n;
    for (ll i = 0; (1LL << i) <= MOD - 2; ++i, p = (p * p) % MOD) {
        if (((MOD - 2) & (1 << i)) == 0)
            continue;
        s *= p;
        s %= MOD;
    }
    return s;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> X[i];
    }
    ll P = 1;
    REP(i, N - 1) {
        P = (P * (i + 1)) % MOD;
    }

    ll p = 0;
    ll ans = 0;
    REP(i, N - 1) {
        ll x = X[i + 1] - X[i];
        p = (p + modpow(i + 1) * P) % MOD;
        ans = (ans + p * x) % MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
S = list(input())
list1 = []
list2 = []
for i in range(len(S)):
    if i % 2 == 0:
        list1.append(S[i])
    else:
        list2.append(S[i])
if not "L" in list1 and not "R" in list2:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
import java.util.*;
import java.lang.*;

// class Pair implements Comparable<Pair>{
//   long a;
//   int cnt;
//   public Pair(long i, int j){
//     this.a = i;
//     this.cnt = j;
//   }
//   public int compareTo(Pair p){
//     if(this.cnt>=2 && p.cnt >=2 && this.a<p.a) return -1;
//     if(this.cnt<2 && p.cnt>=2) return -1;
//     return 1;
//   }
// }

class Main{
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = Integer.parseInt(sc.next());
      ArrayList<Long> l = new ArrayList<Long>();
      for(int i = 0; i<N; i++){
        long c = Long.parseLong(sc.next());
        if(i == 0) l.add(c);
        else{
          long p = l.get(i-1);
          l.add(c+p);
        }
      }
      long diff = Long.MAX_VALUE;
      for(int i = 0; i<N-1; i++){
          long arai = l.get(N-1)-l.get(i);
          long d = Math.abs(l.get(i)-arai);
          diff = Math.min(diff,d);
      }
      System.out.println(diff);
  }
}

Measured memory_bytes: 68288
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    cin >>a>>b>>c;
    
    if(a > b){
        swap(a,b);
    }
    if(b > c){
        swap(b,c);
    }
    if(a > b){
        swap(a,b);
    }
    
    cout <<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
//   最後だから残ってたとしたら=k
  int xc = k;
//   xbは0だから総和に特に関係ないから除外
  int ans = xa - xc;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3536
from collections import deque
que = deque([])

n = int(input())

for _ in range(n):
    input_command = input()
    if input_command == "deleteFirst":
        que.popleft()
    elif input_command == "deleteLast":
        que.pop()
    else:
        command, x = input_command.split()
        if command == "insert":
            que.appendleft(x)
        elif command == "delete":
            try:
                que.remove(x)
            except:
                pass
print(" ".join(que))


Measured memory_bytes: 69732
#include <iostream>
#include <map>
using namespace std;
typedef map<int, int> M;

int main() {
  int i, j, k, p, q, r, t;
  string s;
  M m;
  pair<M::iterator, bool> res;
  while (cin >> p >> q) {
    r = p%q;
    i = 0;
    s.clear();
    m.clear();
    while (1) {
      if (!r) {
        cout << s << endl;
        break;
      }

      res = m.insert(M::value_type(r, i));
      if (!res.second) {
        cout << s << endl;
        j = res.first->second;
        for (k=0; k<j; k++) cout << " ";
        for (k=j; k<i; k++) cout << "^";
        cout << endl;
        break;
      }

      r *= 10;
      t = r/q;
      r = r - t*q;
      s += (char)('0' + t);
      i++;
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int a[10] = {};
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 10);
	reverse(a, a + 10);
	long long int ans1, ans2;
	ans1 = (a[0] / 2) * a[1] * a[2];
	ans2 = a[0] * a[1] * a[2] - ans1;
	cout << max(ans1, ans2) - min(ans1, ans2) << endl;
	return 0;
}

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

using namespace std ;

int n, x, mx, ans;

int main() {
   cin >> n ;
   for( int i = 0 ; i < n ; i ++ ) {
        cin >> x ;
        if( x >= mx ) {
            mx = x ;
            ans ++ ;
        }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int n, a, b, c;
vi l(12);

//as, bs, csはそれぞれ,a, b, cに使う竹の長さのそれぞれの合計
int dfs(int cur, int as, int bs, int cs) {
  if (cur == n) {
    if(min({as,bs,cs}) > 0) {
      // 最初の1本を選ぶときにも、MPを+10してしまっているので、a, b, cの3本分-30しておく
      return abs(as-a) + abs(bs-b) + abs(cs-c) - 30;
    }
    else return INF;
  }
  int ret0 = dfs(cur+1, as, bs, cs);
  int ret1 = dfs(cur+1, as+l[cur], bs, cs) + 10;
  int ret2 = dfs(cur+1, as, bs+l[cur], cs) + 10;
  int ret3 = dfs(cur+1, as, bs, cs+l[cur]) + 10;
  return min({ret0, ret1, ret2, ret3});
}

int main () {
  cin >> n >> a >> b >> c;
  rep(i,n) cin >> l[i];
  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = in.nextToken();

        out.println(s.startsWith("YAKI") ? "Yes" : "No");
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

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


/*
  let's try computer shogi!!!
 */

int main(){
  string str;
  const string atoz = "abcdefghijklmnopqrstuvwxyz";
  vector<long int> cnt;
  cnt.resize(26);
  cin >> str;
  long int out = 1;
  for(long int i=0; i< str.length();++i){
    int id = -1;
    for(int j = 0; j<26;++j){
      if(str[i] == atoz[j]){
	cnt[j]++;
	id = j;
	break;
      }
    }
    if(id == -1){
      cerr<<"unr"<<endl;
    }
    //cerr<<i<<","<<id<<","<<cnt[id]<<","<<(i+1 - cnt[id])<<endl;
    out += (i+1 - cnt[id]);
  }
  cout<<out<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N; cin >> N;
    vector<int> a(N); REP(i,N) cin >> a[i];

    int max_n = *max_element(all(a));
    int min_n = *min_element(all(a));

    cout << max_n - min_n << endl;
}

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

int main(){
  int64_t K;

  while(std::cin >> K){
    int d = 0;

    int ans = -1;
    int i = 1;

    while(true){
      d = (d * 10 + 7) % K;

      if(d == 0){
        ans = i;
        break;
      }

      ++i;

      if(i > K) break;
    }
    

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

  return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
int main(void)
{
int i, j, n, m, a[1000], sum, min;
 
while(scanf("%d",&n))
{
if(n==0)
break ;
for(i = 0; i < n ; i++)
{
scanf("%d",&a[i]);
}
min = 1000000;
for(i = 0; i < n ; i++)
{
for(j = i+1; j<n;j++)
{
sum = a[i]-a[j];
if(sum<0)
sum = sum*(-1);
if(sum<min)
min=sum;
}
}
printf("%d\n",min);
}

return 0;
}


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

#include <iostream>

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define FORR(i, a, b) for(int i = b;i >= a;--i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  lint a,b; cin >> a >> b;
  lint x = a*b;
  lint temp;
  if(a<b){
    temp = a;
    a = b;
    b = temp;
  }
  lint r = a%b;
  while(r != 0){
    a = b;
    b = r;
    r = a%b;
  }
  cout << x/b;
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
const int N = (int)(1e6) + 5;
int D[N];
char str[N];
int dp[N];
map < int , int > M;
int main(void)
{
    cin>>(str + 1);
    int n = strlen(str + 1);
    for (int i = 1;i <= n;++i)
        D[i] = D[i - 1] ^ (1 << (str[i] - 'a'));
    M[0] = 0;
    for (int i = 1;i <= n;++i)
    {
        dp[i] = 1e9;
        if (M.count(D[i]))
            dp[i] = min(dp[i],M[D[i]] + 1);
        for (int k = 0;k < 26;++k)
            if (M.count(D[i] ^ (1 << k)))
                dp[i] = min(dp[i],M[D[i] ^ (1 << k)] + 1);
        if (!M.count(D[i])) M[D[i]] = 1e9;
        M[D[i]] = min(M[D[i]],dp[i]);
    }
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 14464
#include <iostream>
using namespace std;
int main(void){
    long long s[100];
    int n;
    cin >>n;
    
    s[0]=2;
    s[1]=1;
    for(int i=2;i<=n;i++){
        s[i]=s[i-2]+s[i-1];
    }
    cout <<s[n]<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ba;

  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ba.push_back(make_pair(b, a));
  }
  sort(ba.begin(), ba.end());

  ll total = 0;
  rep(i, n) {
    total += ba[i].second;
    if (total > ba[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long LL;

LL GCD(LL a,LL b){
    if(a < b)swap(a,b);
    if(a % b)return GCD(b,a % b);
    return b;
}

LL LCM(LL a, LL b){
    return a * b / GCD(a,b);
}

int main(){
    LL A,B,C,D,X,Y,Z;

    cin >> A >> B >> C >> D;

    X = B / C - (A - 1) / C;
    Y = B / D - (A - 1) / D;
    Z = B / (LCM(C,D)) - (A - 1) / (LCM(C,D));

    cout << (B - A + 1) - (X + Y - Z) << endl;

    return 0;
}


Measured memory_bytes: 256
int main(){
    int n,i, tmp;
    long maxv, minv;
    maxv = -10000000000;
    scanf("%d", &n);
    scanf("%d", &minv);
    for(i=1; i<n; i++) {
        scanf("%d", &tmp);
        if(tmp-minv>maxv) maxv=tmp-minv;
        if(tmp<minv) minv=tmp;
    }
    printf("%li\n", maxv);
    return 0;
}

Measured memory_bytes: 596