akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    int s=0;
    REP(i,4) {
        int a;
        cin>>a;
        s+=a;
    }
    cout<<s/60<<endl;
    cout<<s%60<<endl;
    return 0;
}

Measured memory_bytes: 3104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func abs(n int) int {
	if n > 0 {
		return n
	} else {
		return -n
	}
}

func main() {
	n, m := readInt(), readInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], b[i] = readInt(), readInt()
	}
	c := make([]int, m)
	d := make([]int, m)
	for i := 0; i < m; i++ {
		c[i], d[i] = readInt(), readInt()
	}

	for i := 0; i < n; i++ {
		min := -1
		pos := -1
		for j := 0; j < m; j++ {
			d := abs(a[i]-c[j]) + abs(b[i]-d[j])
			if min == -1 || d < min {
				min = d
				pos = j + 1
			}
		}
		fmt.Println(pos)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, cmmdc, k, nrd;
int main() {
	cin>>n>>m>>k;
	cmmdc=__gcd(n,m);
	for(i=cmmdc;i>=1;i--)
	if(cmmdc%i==0)
	{
		nrd++;
		if(nrd==k)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <map>
#define int long long
using namespace std;
const int N = 3e5 + 5;
const int B1 = 23711, B2 = 63711, P1 = 998244353, P2 = 1004535809;
int n, S[N], T[N], f[N][2], inv1, inv2, ans;
map<pair<int, int>, int> t;
char s[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int ksm(int x, int y, int mod)
{
	int res = 1;
	for(; y; y >>= 1, x = x * x % mod)
		if(y & 1) res = res * x % mod;
	return res;
}
signed main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); scanf("%s", s + 1); f[0][0] = f[0][1] = 1;
	inv1 = ksm(B1, P1 - 2, P1); inv2 = ksm(B2, P2 - 2, P2);
	for(int i = 1; i <= n; i ++)
	{
		if(s[i] == '-')
		{
			f[i][0] = f[i - 1][0]; f[i][1] = f[i - 1][1];
			S[i] = (S[i - 1] - f[i][0] + P1) % P1;
			T[i] = (T[i - 1] - f[i][1] + P2) % P2;
		}
		else if(s[i] == '+')
		{
			f[i][0] = f[i - 1][0]; f[i][1] = f[i - 1][1];
			S[i] = (S[i - 1] + f[i][0]) % P1;
			T[i] = (T[i - 1] + f[i][1]) % P2;
		}
		else if(s[i] == '<')
		{
			f[i][0] = f[i - 1][0] * inv1 % P1;
			f[i][1] = f[i - 1][1] * inv2 % P2;
			S[i] = S[i - 1]; T[i] = T[i - 1];
			
		}
		else if(s[i] == '>')
		{
			f[i][0] = f[i - 1][0] * B1 % P1;
			f[i][1] = f[i - 1][1] * B2 % P2;
			S[i] = S[i - 1]; T[i] = T[i - 1];
		}
		t[make_pair(S[i], T[i])] ++;
	}
	t[make_pair(0, 0)] ++; int x, y;
	for(int i = 0; i < n; i ++)
	{
		t[make_pair(S[i], T[i])] --;
		x = (S[i] + S[n] * f[i][0] % P1) % P1;
		y = (T[i] + T[n] * f[i][1] % P2) % P2;
		ans += t[make_pair(x, y)];
	}
	printf("%lld\n", ans);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 40704
io = STDIN
n,a,b=io.gets.split.map(&:to_i)
near=[a-1,n-b].min
far=[a-1,n-b].max
if (b-a).even?
  puts (b-a)/2
else
  if (b-a)==(near*2+1)
    puts (b-a)
  elsif (b-a)>(near*2+1)
    puts ((b-a)-(near*2+1))/2+(near*2+1)
  else
    puts [b-1,n-a,near+1+((b-a-1)/2)].min
  end
end


Measured memory_bytes: 1788
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let t = read::<String>().chars().collect::<Vec<char>>();
    let n = s.len();
    let mut tos = vec![0; 200];
    let mut used = vec![false; 200];
    for i in 0..n {
        let from = s[i] as usize;
        let to = t[i] as usize;
        if tos[from] == to {
            continue;
        } else if tos[from] == 0 && !used[to] {
            tos[from] = to;
            used[to] = true;
        } else {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main(){
    int n;
    cin >> n;
    set<string> st;
    
    for(int i = 0; i < n; i++){
        string s,t;
        cin >> s >> t;
        if(s == "insert") st.insert(t);
        else{
            if(st.count(t)) cout << "yes\n";
            else cout << "no\n";
        }
    }
    
    return 0;
}


Measured memory_bytes: 32124
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int c[]={500,100,50,10,5,1};
int main(){
    int n;
    while(cin>>n,n){
        rep(i,9){
            int a;
            cin>>a;
            n-=a;
        }
        cout<<n<<endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int q,p,w[1000001],u[1000001],o;
string a;
int main()
{
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C') 
        {
            p++;
            u[p]=i+1;
        }
        else if (a[i]=='F')
        {
            q++;
            w[q]=i+1;
        }
    }
    if (q>=1 && p>=1)
    {
    for (int i=1;i<=p;i++)
    {
        for (int j=1;j<=q;j++)
        {
            if (u[i]<w[j])
            {
                o=1;
            }
        }
    }
    if (o==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl; 
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>

using std::cout;
using std::endl;
using std::cin;
// using std::cerr;

int cost_between(int hi, int hj) {
	int tmp = hi - hj;
	return tmp < 0? -tmp : tmp;
}

int min(int a, int b) { return a > b? b : a; }

int main() {

	int N;
	cin >> N;
	int h[100'010];
	for(int i = 1; i <= N; ++i) {
		cin >> h[i];
	}

	int cost[100'010];
	cost[1] = 0;
	cost[2] = cost_between(h[1], h[2]);

	for(int i = 3; i <= N; ++i) {
		int jump2Cost = cost[i-2] + cost_between(h[i-2], h[i]);
		int jump1Cost = cost[i-1] + cost_between(h[i-1], h[i]);
		cost[i] = min(jump2Cost, jump1Cost);
	}

	cout << cost[N] << endl;
//	for(int i = 0; i <= N; ++i)
//	cerr << i << " : " << cost[i] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>

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

using namespace std;

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

    set<int> ds;
    REP(i, N) {
        cin >> d;
        ds.insert(d);
    }
    cout << ds.size() << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
dp = [-10**30 for _ in range(1<<n)]
dp[0] = 0
for s in range(1, 1<<n):
	dp[s] = 0
	for i in range(n):
		for j in range(i+1, n):
			if (s>>i) & 1 and (s>>j) & 1:
				dp[s] += a[i][j]
	t = s
	while t > 0:
		t = (t-1)&s
		dp[s] = max(dp[s], dp[t] + dp[s^t])
print(dp[-1])

Measured memory_bytes: 43940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll k,x,i;
    cin>>k>>x;
    for(i=x-k+1;i<(x+k);i++)
        cout<<i<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>


using namespace std;

int main(void){
	int n;

	cin >> n;

	vector< vector<int> > f(n, vector<int>(10, 0)), p(n, vector<int>(11, 0));

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> f[i][j];
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 11; j++){
			cin >> p[i][j];
		}
	}

	int bit = 1, Max = -1001001001;

	while (bit < 1024){
		int sum = 0;
		int num = 0;

		for (int i = 0; i < n; i++){
			num = 0;
			for (int j = 0; j < 10; j++){
				if (((bit >> j) & 1) && f[i][j] == 1){
					num++;
				}
			}
			sum += p[i][num];
		}

		Max = max(Max, sum);
		bit++;
	}

	cout << Max << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		double value=0;
		double valueMin;
		double nextMin;
		Scanner sc=new Scanner(System.in);
		ArrayList<Double>material=new ArrayList<>();
		//具材の個数
		int N=sc.nextInt();
		
		for(int i=0;i<N;i++) {
			material.add(sc.nextDouble());
		}
		
		Collections.sort(material);
		
		for(int i=0;i<N-1;i++) {
			if(i==0) {
			valueMin=material.get(0);
			nextMin=material.get(1);
			value=(valueMin+nextMin)/2;
			material.remove(material.get(0));
			material.remove(material.get(0));
			material.add(value);
			
			}else{
				value=(value+material.get(0))/2;
				material.remove(material.get(0));
			}
		}
			
		System.out.println(value);
		
	}

}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "SUN") cout << 7 << endl;
    if(s == "SAT") cout << 1 << endl;
    if(s == "FRI") cout << 2 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "MON") cout << 6 << endl;
    return 0;
}

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

using namespace std;
 
#define int1(a) scanf("%d",&a)
#define int2(a,b) scanf("%d %d",&a,&b)
#define int3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define int4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
 
#define lint1(a) scanf("%lld",&a)
#define lint2(a,b) scanf("%lld %lld",&a,&b)
#define lint3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define lint4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define lli long long int
 
#define pint(x) printf("%d",x)
#define plint(x) printf("%lld",x)
#define endl '\n'
#define nl printf("\n");
#define ps printf(" "); 
 
#define all(x) x.begin(),x.end()
#define pb push_back
#define Set(a, s) memset(a, s, sizeof (a))
#define mod1 (lli)(1e9 + 7)
#define mod2 (lli)(1e9 + 9)
#define EPS 1e-9

#define fore(i,n) for(int i=n; i>=0; i--)
#define fors(i,a,n) for(int i=a; i<n; i++)
#define fora(i,ele) for(auto i: ele)
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<lli> vli;
 
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}
float roundoff(float val, float p){ return floor(val*pow(10.0,p)+0.5)/pow(10.0,p);}
lli power(lli a, lli b, lli mod){lli x=1,y=a; while(b > 0){if(b&1){x=(x*y)%mod;}y = (y*y)%mod; b /= 2;}return x;}
 
const int INF = 0x3f3f3f3f;
const float pi = 3.14159265;
 
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};
//int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1};
 
 

 
int main(void) {
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    cout.tie(NULL);
	//srand (time(NULL));
	/*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	*/
    // cout<<"Execution time : "<<tick()<<"\n";
    int n;
    cin>>n;
    
    string str;
    cin>>str;
    
    int cntr = 0, cntb = 0;
    
    fors(i,0,n){
		if(str[i]=='R') cntr++;
		else cntb++;
	}
	
	if(cntr>cntb) cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  ll x,k,d; cin>>x>>k>>d;
  x = abs(x);
  if (x/d > k){
    cout << x - d*k;
    return 0;
  }
  ll ans = -1;
  ll tmp = k - (x/d);
  if (tmp%2 == 0) ans = x%d;
  else ans = d- (x%d);
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>

int partition(int *, int, int);

int main()
{
  int n, i, index;
  int *a;

  scanf("%d", &n);
  a = (int *)malloc(n*sizeof(int));
  for(i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }

  index = partition(a, 0, n-1);
  for(i=0; i<n; i++) {
    if(i == index)
      printf("[%d]", a[i]);
    else
      printf("%d", a[i]);
    if(i != n-1)
      printf(" ");
  }
  printf("\n");

  return 0;
}

int partition(int *a, int p, int r)
{
  int x, i, j, tmp;
  x = a[r];
  i = p-1;
  for(j=p; j<=r-1; j++) {
    if(a[j] <= x) {
      i++;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
    }
  }
  tmp = a[i+1];
  a[i+1] = a[r];
  a[r] = tmp;
  
  return i+1;
}

Measured memory_bytes: 996
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    long long ans = 0;

    vector<long long> b = a;

    ans += abs(a[0] - 1);
    a[0] = 1;
    for(int i=1; i<n; i++){
        long long tmp = a[i] + a[i-1];
        if(tmp * a[i-1] >= 0){
            ans += abs(tmp) + 1;
            if(a[i-1] > 0)
                a[i] = -1;
            else
                a[i] = 1;
        }else{
            a[i] = tmp;
        }
    }

    long long ans2 = 0;
    a = b;
    ans2 += abs(a[0] + 1);
    a[0] = -1;
    for(int i=1; i<n; i++){
        long long tmp = a[i] + a[i-1];
        if(tmp * a[i-1] >= 0){
            ans2 += abs(tmp) + 1;
            if(a[i-1] > 0)
                a[i] = -1;
            else
                a[i] = 1;
        }else{
            a[i] = tmp;
        }
    }
    ans = min(ans, ans2);

    if(b[0] != 0){
        long long ans3 = 0;
        a = b;
        for(int i=1; i<n; i++){
            long long tmp = a[i] + a[i-1];
            if(tmp * a[i-1] >= 0){
                ans3 += abs(tmp) + 1;
                if(a[i-1] > 0)
                    a[i] = -1;
                else
                    a[i] = 1;
            }else{
                a[i] = tmp;
            }
        }
        ans = min(ans, ans3);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int n, k, d[100], s[100], aa, cnt = 1;
	vector<int>a;
	cin >> n >> k;
	rep(i, k) {
		cin >> d[i];
		rep(j, d[i]) {
			cin >> aa;
			a.push_back(aa);
		}
	}
	sort(a.begin(), a.end());
	rep(i,a.size()-1) {
		if (a[i] != a[i + 1])cnt++;
	}
	cout << n-cnt << endl;
	return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll x, a;
    cin>>x>>a;
    if(x<a){
        print(0);
    }
    else print(10);
        
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#define XOX
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define int long long

signed main()
{
    int k;
    cin >> k;
    int base = 1;
    int num = 0;
    for (int i = 1; i <= 1000000; i++) {
        int tmp = (base * 7)%k;
        num = (num + tmp)%k;
        base = (base * 10)%k;
        //debug(tmp, base);
        if (num == 0) {
            cout << i << "\n";
            return 0;
        }
    }
    puts("-1");
}


Measured memory_bytes: 3600
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

// LCS 最長共通部分列
template<typename T>
ll LCS(const vector<T> &A, const vector<T> &B) {
    int n = A.size(), m = B.size();
    vector<vector<ll>> lcs(n + 1, vector <ll>(m + 1));
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (i == 0 || j == 0) {
                lcs[i][j] = 1;
            }
            else if (A[i - 1] == B[j - 1]) {
                lcs[i][j] = (lcs[i][j - 1] + lcs[i - 1][j]) % MOD;
            }
            else {
                lcs[i][j] = (lcs[i][j - 1] + lcs[i - 1][j] + MOD - lcs[i - 1][j - 1]) % MOD;
            }
        }
    }
    return lcs[n][m];
}

int main() {
    int N, M; cin >> N >> M;
    vector<ll> S(N);
    vector<ll> T(M);
    input(S, T);
    cout << LCS(S, T) << endl;
    getchar(); getchar();
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
const int md=998244353;
struct Modint {
  int x;
  Modint() { x=0; }
  Modint operator+=(const Modint& oth) {
    x+=oth.x;
	if (x>=md) x-=md;
	return *this;
  }
} f[302][302][302][4],r;
int n,m,i,j,k1,lst,cur,s0,s1;
char s[302];
int main() {
  scanf("%s",s);  n=strlen(s);
  scanf("%d",&m); m=min(m,n);
  f[0][0][0][0].x=1;
  for (i=0; i<n; i++) {
    cur=s[i]-'0';
	for (j=0; j<=m; j++) for (k1=0; k1<=j; k1++) for (lst=0; lst<4; lst++) if (f[i][j][k1][lst].x) {
	  if (cur==0) {
	    f[i+1][j][k1][0]+=f[i][j][k1][lst];
		if (lst<2) f[i][j+1][k1+1][1]+=f[i][j][k1][lst];
	  } else {
	    f[i+1][j][k1][(lst/2)*2+1]+=f[i][j][k1][lst];
		if (k1>0 && lst%2==0) f[i+1][j][k1-1][2]+=f[i][j][k1][lst];
	  }
    }
  }
  for (j=0; j<=m; j++) for (lst=0; lst<4; lst++) r+=f[n][j][0][lst];
  printf("%d\n",r.x);
  return 0;
}


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



int main() {
    string s;
    int index1 = 0;
    int res;
    int index2 = 0;
    int flag = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        if(s[i] == 'A' && flag == 0) {
            index1 = i;
            flag = 1;
        }
        if(s[i] == 'Z' && flag == 1) {
            index2 = i;
        }
    }
    res = index2 - index1 + 1;
    cout << res << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  while(cin >> N,N){
    int a,b;
    int ap = 0,bp = 0;
    for(int i = 0;i < N;i++){
      cin >> a >> b;
      if(a < b)bp += a + b;
      else if(a == b){ap += a;bp += b;}
      else ap += a + b;
    }
    cout << ap << " " << bp << endl;
  }
  return 0;
}

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

def BellmanFord(graph: "List[List[int]]", s: int):
    """
    特定の始点から各点への最短距離を求めます。
    重みが負であっても動作します。
    ================
    s: 始点
    graph: 隣接リスト
    ----------------
    第一返り値: 負の閉路があるかいなか
    第二返り値: 最短距離のリスト
    """
    INF = 1e18
    n = len(graph)
    dist = [INF] * n
    dist[s] = 0
    for i in range(n):
        for v in range(n):
            for k in range(len(graph[v])):
                e  = graph[v][k]
                if dist[v] != INF and dist[e[0]] > dist[v] + e[1]:
                    dist[e[0]] = dist[v] + e[1]
                    if i == n-1 and e[0] == n-1:
                        return True, dist
    return False, dist

def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    G = [[] for _ in range(N)]
    for i in range(M):
        G[a[i]-1].append((b[i]-1, c[i]))
    flag, cost = BellmanFord(G, 0)
    if flag:
        print('inf')
    else:
        print(-cost[N-1])
    return


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
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = -1 * int(next(tokens))
    solve(N, M, a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n = int(input())
row = []
column = []
for _ in range(n):
    r, c = map(int, input().split())
    row.append(r)
    column.append(c)

dp = [[INF] * (n + 10) for _ in range(n + 10)]

"""
dp[i][j] = iからj番目の行列積に必要なスカラー積の最小値
dp[i][j] = min(dp[i][k] + dp[k+1][j] + M[i].row * M[k].col * M[j].col)
"""

for i in range(n):  # 初期条件
    dp[i][i] = 0

for i in range(n, -1, -1):
    for j in range(i+1, n):
        for k in range(i, j):
            prod = row[i] * column[k] * column[j]
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + prod)
print(dp[0][n-1])


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n;
	unordered_map<string, int> m;
	cin >> n;
	ll ans = 0;
	string tmp;
	REP(i, 0, n){
		cin >> tmp;
		sort(tmp.begin(), tmp.end());
		ans += m[tmp];
		++m[tmp];
	}
	cout << ans;

}


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

int main(void)
{
    int r, g, b;
    cin >> r >> g >> b;
    int sum = r*100 + g*10 + b;

    if(sum % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

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

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

void solve(std::string s){
    int a = 0, z = 0;
    a = s.find_first_of('A');
    z = s.find_last_of('Z');
    cout << z - a + 1<< '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int a, b;
  a = 0;
  b = 0;

  for (int x = 0; x < 3; x++){
  	if (S.at(x) == 'A')
  		a++;
  	if (S.at(x) == 'B')
  		b++;	
  }
  if (a && b)
  	cout << "Yes" << endl;
  else 
  	cout << "No" << endl;

}


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

int main() {
  int n, ac = 0, wa = 0, tle = 0, re = 0;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++)
  {
    if (s[i] == "AC")
    {
      ac++;
    }else if (s[i] == "WA")
    {
      wa++;
    }else if (s[i] == "TLE")
    {
      tle++;
    }else
    {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  n -= 2;
  string s;
  cin >> s;
  //int sz = s.size();
  int count = 0;
  //sz -= 2;
  string p = "ABC";
  string eq = "";
  rep(i, n){
    eq = eq + s.at(i);
    eq = eq + s.at(i+1);
    eq = eq + s.at(i+2);
    //cout << eq << endl;
    if(eq == p) {count++; eq = "";}
    else eq = "";
  }
  cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, B, C := ReadInt(), ReadInt(), ReadInt()
	fmt.Println(Min(C, B/A))
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template<typename T>
void chmin(T& s,T t){
    s=min(s,t);
}
template<typename T>
void chmax(T& s,T t){
    s=max(s,t);
}


int main(){
    int cnt=0;
    char prev='-';
    string s;
    cin>>s;
    for(auto &it:s){
        if(it!=prev){
            cnt++;
            prev=it;
        }
    }
    cout<<cnt-1<<endl;
    return 0;
}


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

int main()
{
  int a;
  cin >> a;
  cout << ((a / 1000 == (a / 100) % 10 && a / 1000 == (a / 10) % 10) || \
          ((a / 100) % 10 == (a / 10) % 10 && (a / 10) % 10 == a % 10) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
H.reverse()
max = 0
cnt = 0
 
for i in range(N-1):
  if H[i] <= H[i+1]:
    cnt += 1
  else:
    cnt = 0
  if cnt > max:
    max = cnt
if cnt > max:
  max = cnt
print(max)

Measured memory_bytes: 64092
import sys

sys.setrecursionlimit(10 ** 6)

def main():
    n=int(input())
    bb=list(map(int, input().split()))
    a=[0]*n
    ans=0
    for i,(b0,b1) in enumerate(zip(bb,bb[1:])):
        ans+=min(b0,b1)
    ans+=bb[0]+bb[-1]
    print(ans)

main()

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s, from = ",", to = " ";
    cin >> s;
    size_t pos = s.find(from);
    while(pos != string::npos){
        s.replace(pos, from.size(), to);
        pos = s.find(from, pos + to.size());
    }
    cout << s << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	bool ch[4]={false};
	for(int i = 0; i < 4; i++){
		cin >> n;
		if(n == 1)ch[0] = true;
		else if(n == 9)ch[1] = true;
		else if(n == 7)ch[2] = true;
		else if(n == 4)ch[3] = true;
	}
	for(int i = 0; i < 4; i++){
		if(!ch[i]){
			cout << "NO" << endl;
			break;
		}
		if(i == 3)cout << "YES" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = n / (a+b) * a;
    ans += min(n % (a+b), a);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import Data.List
import Text.Printf
import qualified Data.ByteString.Char8 as C

eps :: Double
eps = 1e-8

sign :: Double -> Int
sign x
  | x > eps = 1
  | x < (-eps) = -1
  | otherwise = 0

greaterEqual :: Double -> Double -> Bool
greaterEqual a b =
  case sign (a - b) of
    -1 -> False
    _ -> True

greater :: Double -> Double -> Bool
greater a b =
  case sign (a - b) of
    1 -> True
    _ -> False

data Point = Point Double Double
  deriving (Eq, Show)

len2 :: Point -> Point -> Double
len2 (Point x1 y1) (Point x2 y2) = (x1 - x2) ** 2 + (y1 - y2) ** 2

sub :: Point -> Point -> Point
sub (Point x1 y1) (Point x2 y2) = Point (x1 - x2) (y1 - y2)

dot :: Point -> Point -> Double
dot (Point x1 y1) (Point x2 y2) = x1 * x2 + y1 * y2

det :: Point -> Point -> Double
det (Point x1 y1) (Point x2 y2) = x1 * y2 - x2 * y1

angle :: Point -> Point -> Double
angle p1 p2 = atan2 (det p1 p2) (dot p1 p2)

type Circle = (Point, Double)
type Range = (Double, Double)

calcIntersection :: Circle -> Circle -> [Range]
calcIntersection (p1, r1) (p2, r2) = concat $ map calcRange calcAngle
  where
  d2 = len2 p1 p2
  d = sqrt d2
  a0 = angle (sub p2 p1) (Point 1 0)
  calcAngle
    | greater d2 ((r1 + r2) ** 2) = []
    | greaterEqual d2 ((r1 - r2) ** 2) = let as = acos $ (r1 * r1 + d2 - r2 * r2) / (2 * r1 * d) in
                                             [if as < 0 then pi + as else as]
    | r1 < r2 = [pi]
    | otherwise = []
  calcRange da
    | b < 0 && e < 0 = error (show a0 ++ " " ++ show da)
    | b > 2 * pi && e > 2 * pi = error (show a0 ++ " " ++ show da)
    | da == pi = [(0, 2 * pi)]
    | b < 0 = [(2 * pi + b, 2 * pi), (0, e)]
    | e > 2 * pi = [(b, 2 * pi), (0, e - 2 * pi)]
    | otherwise = [(b, e)]
    where
    a0' = if a0 < 0 then a0 + 2 * pi else a0
    b = a0' - da
    e = a0' + da

calcCover :: Double -> [Circle] -> Circle -> Int
calcCover t cs c = abs o'
  where
  c' = let (p0, r0) = c in (p0, r0 * t)
  cs' = map (\(p, r) -> (p, r * t)) $ filter ((/=)c) cs
  rs = concat $ map (calcIntersection c') cs'
  vs = sort $ concat $ map (\(l, r) -> [(l, -1), (r, 1)]) rs
  (_, o') = foldl' (\(a, o) (xx, da) -> if xx < 0 || xx > 2 * pi then error (show xx) else let a' = a + da in (a', min o a')) (0, 0) vs

main :: IO ()
main = do
  let readInts = fmap (map (fst . fromJust . C.readInt) . C.words) C.getLine
      toCircle xs =
        let [x', y', c'] = map fromIntegral xs
        in ((Point x' y'), (1.0 / c'))
  [n, k] <- readInts
  cs <- replicateM n $ fmap toCircle readInts
  let func (l, r) _ =
        let m = (l + r) * 0.5
            k' = maximum $ map (calcCover m cs) cs
        in if k' >= k - 1
             then (l, m)
             else (m, r)
      (ll, rr) = foldl' func (0, 300000) [1..100 :: Int]
  putStrLn $ printf "%.10f" ((ll + rr) * 0.5)


Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  int count=0;
  for(int i=1;i<=N;i++){
    if((1<=i&&i<=9)||(100<=i&&i<=999)||(10000<=i&&i<=99999)) count++;
  }
  std::cout << count << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main(){
 ll H;
 cin >> H;
 ll x = 1;
 ll ans = 0;
 while(x<=H){
   ans += x;
   x *= 2;
 }
  cout << ans << endl;
}


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

class Program{
    static void Main(string[] args){
        long n = Int64.Parse(Console.ReadLine());
        long[] lucas = new long[n+1];
        lucas[0] = 2; lucas[1] = 1;
        Enumerable.Range(0, (int)n-1).Select((x, i) => lucas[i+2] = lucas[i] + lucas[i+1]).ToArray();
        long a = lucas.Last();
        Console.WriteLine(a);
    }
}


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

int main(void){
    int n, k;
    std::cin >> n >> k;

    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
        std::cin >> h.at(i);
    }

    std::sort(h.begin(), h.end());

    int ans = 1e9+3;
    int diff = 0;

    for(int i = 0; i <= n - k; i++){
        diff = h.at(i+k-1) - h.at(i);
        ans = std::min(ans, diff);
    }

    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const int maxn = 1e4+5;


int main(){
	int n; cin >> n;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			if(i * j == n){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
}

Measured memory_bytes: 256
use std::cmp;
use std::cmp::Reverse;
use std::collections::{BTreeMap, BinaryHeap};

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: i64 = sc.read();
    let w: i64 = sc.read();

    let mut dist = BTreeMap::new();
    let mut heap = BinaryHeap::new();
    for i in 1..=w {
        dist.insert(i, 0);
        heap.push((Reverse(0), i));
    }
    for depth in 1..=h {
        let left: i64 = sc.read();
        let right: i64 = sc.read();
        while let Some((&cur_pos, &cur_cost)) = dist.range(left..=right).next_back() {
            let next_pos = right + 1;
            let next_cost = right + 1 - cur_pos + cur_cost;
            assert_eq!(dist.remove(&cur_pos), Some(cur_cost));
            if next_pos <= w {
                let cur = dist.entry(next_pos).or_insert(1 << 50);
                if *cur > next_cost {
                    *cur = next_cost;
                    heap.push((Reverse(next_cost), next_pos));
                }
            }
        }

        let mut ans = None;
        while let Some((Reverse(cost), pos)) = heap.pop() {
            if let Some(&stored_cost) = dist.get(&pos) {
                if stored_cost == cost {
                    ans = Some(stored_cost);
                    heap.push((Reverse(stored_cost), pos));
                    break;
                }
            }
        }

        if let Some(ans) = ans {
            sc.write(ans + depth);
        } else {
            sc.write("-1");
        }
        sc.write('\n');
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12644
#include <bits/stdc++.h>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=998244353;

int f[200100];
int64_t pow2[200100];
void upd(int i){
    ++i;
    while(i<200100){
        f[i]+=1;
        i+=i&-i;
    }
}
int get(int i){
    ++i;
    int ret=0;
    while(i){
        ret+=f[i];
        i-=i&-i;
    }
    return ret;
}
int64_t comb(int x){
    return pow2[x]-1;
}
int main() {
    ios_base::sync_with_stdio(0);
    pow2[0]=1;
    for(int i=1;i<200100;++i){
        pow2[i]=pow2[i-1]*2;
        pow2[i]%=MOD;
    }
    int n;
    cin>>n;
    vector<pair<int,int>>a;
    for(int i=0;i<n;++i){
        int x,y;
        cin>>x>>y;
        a.push_back({x,y});
    }
    sort(a.begin(),a.end());
    vector<pair<pair<int,int>,int>>b;
    for(int i=0;i<n;++i){
        b.push_back({{a[i].second,a[i].first},i});
    }
    sort(b.begin(),b.end());
    int64_t ans=0;
    for(auto bb:b){
        int i=bb.second;
        int a=get(i);
        int b=get(n)-get(i);
        int c=i-a;
        int d=n-i-1-b;
        int64_t exc=comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d);
        exc%=MOD;
        int64_t cur=(comb(n)-exc)%MOD;
        ans=(ans+cur)%MOD;
        upd(i);
    }
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
 
struct Item{
    ll va,we;
};
 
int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll n,w;
    cin >> n >>w;
    Item items[n+1]={0};
    //vector<vector<int>> nw(n+1,vector<int>(2,0));
    for(int i=1;i<n+1;i++) cin >> items[i].we >>items[i].va;
    vector<vector<ll>> dp(n+2,vector<ll>(w+2,0));
    for(int i=1;i<n+1;i++){
        for(int j=1;j<w+1;j++){
            if(j>=items[i].we){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-items[i].we]+items[i].va);
                
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout << dp[n][w];
    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

template<long long int P>
struct _mint {
  long long int x;
  _mint(long long int x = 0): x((x % P + P) % P) {}

  _mint operator-() const {
    return _mint(-x);
  }

  _mint& operator+=(const _mint a) {
    if((x += a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator-=(const _mint a) {
    if((x += P - a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator*=(const _mint a) {
    (x *= a.x) %= P;
    return *this;
  }
  _mint& operator/=(const _mint a) {
    return (*this) *= a.inv();
  }

  _mint operator+(const _mint a) const {
    _mint res(*this);
    return res += a;
  }
  _mint operator-(const _mint a) const {
    _mint res(*this);
    return res -= a;
  }
  _mint operator*(const _mint a) const {
    _mint res(*this);
    return res *= a;
  }
  _mint operator/(const _mint a) {
    _mint res(*this);
    return res /= a;
  }

  _mint pow(long long int t) const {
    if(! t) return 1;
    _mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }

  // for prime P
  _mint inv() const {
    return pow(P - 2);
  }
};
using mint = _mint<MOD>;

int main() {
  int N;
  std::cin >> N;
  int zeros = 0;

  std::map<std::pair<ll, ll>, std::pair<int, int>> cnt;
  rep(i, N) {
    ll x, y;
    std::cin >> x >> y;
    if(x == 0 && y == 0) {
      ++zeros;
      continue;
    }

    ll g = std::gcd(x, y);
    x /= g;
    y /= g;

    if(y < 0) {
      x = -x; y = -y;
    }
    if(y == 0 && x < 0) {
      x = -x;
    }

    bool rot = (x <= 0);
    if(rot) {
      ll tmp = x;
      x = y;
      y = - tmp;
    }

    if(rot) {
      ++cnt[{x, y}].first;
    } else {
      ++cnt[{x, y}].second;
    }
  }

  mint ans = 1;
  for(auto p : cnt) {
    int s = p.second.first;
    int t = p.second.second;
    mint sub = mint(2).pow(s) + mint(2).pow(t) - 1;
    ans *= sub;
  }

  ans -= 1;
  ans += zeros;

  std::cout << ans.x << '\n';
}


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

int main() 
{
  int n, l;
  cin >> n >> l;
  vector<std::string> data(n);
  for(int i = 0; i < n; i++)
  {
    cin >> data.at(i);
  }
  sort(begin(data), end(data));
  std::string r;
  for(int i = 0; i < n; i++)
  {
    r += data.at(i);
  }
  cout << r << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = input()
	LR = [None] * (2 * N)
	LR[0] = "L"
	for i in range(1, 2 * N):
		if S[i] == S[i - 1]:
			if LR[i - 1] == "L":
				LR[i] = "R"
			else:
				LR[i] = "L"
		else:
			if LR[i - 1] == "L":
				LR[i] = "L"
			else:
				LR[i] = "R"

	Lcnt = LR.count("L")
	Rcnt = LR.count("R")
	if Lcnt != Rcnt:
		print(0)
		return
	if S[0] == "W" or S[-1] == "W":
		print(0)
		return

	ans = 1; lcnt = 0; rcnt = 0
	for i in range(2 * N):
		if LR[i] == "L":
			lcnt += 1
		else:
			if lcnt - rcnt >= 1:
				ans *= lcnt - rcnt
				ans %= con
				rcnt += 1
			else:
				ans = 0

	for i in range(1, N + 1):
		ans *= i
		ans %= con

	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 42080
#include <stdio.h>

int main(void)
{

	int i;
	int join_time[9], leave_time[9], ans[9];

	for(i = 0; i < 3; i++) {
		scanf("%d %d %d", &join_time[i], &join_time[i + 3], &join_time[i + 6]);
		scanf("%d %d %d", &leave_time[i], &leave_time[i + 3], &leave_time[i + 6]);
	}

	for(i = 0; i < 3; i++) {
		if(join_time[i + 6] > leave_time[i + 6]) {
			ans[i + 6] = leave_time[i + 6] + (60 - join_time[i + 6]);
			if(leave_time[i + 3] - 1 < 0) {
				leave_time[i + 3] = 59;
				leave_time[i]--;
			}
			else {
				leave_time[i + 3]--;
			}
		}
		else {
			ans[i + 6] = leave_time[i + 6] - join_time[i + 6];
		}
		if(join_time[i + 3] > leave_time[i + 3]) {
			ans[i + 3] = leave_time[i + 3] + (60 - join_time[i + 3]);
			leave_time[i]--;
		}
		else {
			ans[i + 3] = leave_time[i + 3] - join_time[i + 3];
		}
		ans[i] = leave_time[i] - join_time[i];
	}

	for(i = 0; i < 3; i++) {
		printf("%d %d %d\n", ans[i], ans[i + 3], ans[i + 6]);
	}

	return 0;

}

Measured memory_bytes: 2668