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

struct UnionFind {
  vector<int> par;
  
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par.at(i) = i;
  }
  
  int root(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }
  
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par.at(rx) = ry;
  }
  
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  
  UnionFind tree(N);
  
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    tree.unite(x - 1, y - 1);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (tree.same(i, P.at(i) - 1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3984
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vi a(n);
  int mx = 0;
  rep(i, n){
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int right = mx + 1, left = 0;
  while(left + 1 < right){
    int middle = (right + left) / 2;
    int cnt = 0;
    rep(i, n) cnt += ceil((double)a[i] / middle) - 1;
    if(cnt <= k) right = middle;
    else left = middle;
  }
  cout << right << endl;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll n,m,sum,a;

int main(){

  cin >> n >> m;
  rep(i,0,m){
    cin >> a;
    sum += a;
  }
  cout << (n >= sum ? n-sum : -1) << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int a,b,ans;
    cin >> a >> b;
    if(a<= 2*b)ans=0;
    else ans = a-2*b;
    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int h, w;
    string s[2000];
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> s[i];

    vector<vector<int>> row, cul;
    // cout << "a" << endl;
    for (int i = 0; i < h; i++)
    {
        vector<int> tmp;
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
                tmp.push_back(j);
        }
        row.push_back(tmp);
    }
    // cout << "a" << endl;
    for (int i = 0; i < w; i++)
    {
        vector<int> tmp;
        for (int j = 0; j < h; j++)
        {
            if (s[j][i] == '#')
            {
                tmp.push_back(j);
                // cout << "(" << j << "," << i << ")" << endl;
            }
        }
        cul.push_back(tmp);
    }
    // cout << "a" << endl;
    // for (int i = 0; i < w; i++)
    // {
    //     for (int j = 0; j < cul[i].size(); j++)
    //         cout << cul[i][j] << " ";
    //     cout << endl;
    // }

    int mx = -1;
    for (int i = 0; i < h; i++)
    // for (int i = 1; i < 2; i++)
    {
        for (int j = 0; j < w; j++)
        // for (int j = 1; j < 2; j++)
        {
            int tmp = 0;
            if (s[i][j] != '#')
            {
                // row
                if (row[i].size() == 0)
                    tmp += w;
                else
                {
                    auto itr = upper_bound(all(row[i]), j);
                    if (itr == row[i].end())
                    {
                        tmp += (w - j);
                    }
                    else
                    {
                        tmp += (*itr - j);
                    }

                    if (itr - row[i].begin() == 0)
                    {
                        // cout << "a";
                        tmp += j;
                    }
                    else
                    {

                        tmp += (j - (row[i][itr - row[i].begin() - 1]) - 1);
                    }
                }
                // cout << "=" << tmp << endl;

                // cul
                if (cul[j].size() == 0)
                    tmp += (h - 1);
                else
                {
                    auto itr = upper_bound(all(cul[j]), i);
                    if (itr == cul[j].end())
                    {
                        tmp += (h - i - 1);
                    }
                    else
                    {
                        tmp += (*itr - i - 1);
                    }

                    if (itr - cul[j].begin() == 0)
                    {
                        tmp += i;
                    }
                    else
                    {
                        tmp += (i - (cul[j][itr - cul[j].begin() - 1]) - 1);
                    }
                }
                // cout << "=" << tmp << endl;
                mx = max(mx, tmp);
            }
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 67072
//quming
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int P;
inline int up(R int x){return x<0?x+P:x;}
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
    R int res=1;
    for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
    return res;
}
typedef pair<int,int> pi;
const int N=505;
pi st[N];int c[N],a[N],dp[N],top,n,res;
inline int f(R int x,R int y){R int r=0;while(r<(n<<1)&&r*r+y*y<x*x)++r;return r;}
inline int g(R int x,R int y){R int r=0;while(r<(n<<1)&&r*r+y*y<=x*x)++r;return r;}
int main(){
    scanf("%d%d",&n,&P);
    fp(i,0,n-1)st[++top]=pi(f(n,i),-i);
    fp(i,n,(n<<1)-1)st[++top]=pi(g(n<<1,i),1);
    fp(i,0,n-1)c[i]=g(n<<1,i);
    sort(st+1,st+1+top);
    fp(k,0,n){
        memset(dp,0,(k+1)<<2);
        dp[0]=1;
        int s1=0,s2=0;
        fp(p,1,top)if(st[p].se==1){
            fp(i,0,s2)dp[i]=mul(dp[i],up(st[p].fi-s1-i));
            ++s1;
        }else{
            fd(i,s2,0){
                upd(dp[i+1],mul(dp[i],up(st[p].fi-s1-i)));
                dp[i]=mul(dp[i],up(c[-st[p].se]-(n+k+s2-i)));
            }
            ++s2;
        }
        upd(res,(k&1)?P-dp[k]:dp[k]);
    }
    printf("%d\n",res);
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(),(x).rend()

typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;

const int mod=1e+9+7;


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

	deque<int> deq;
	if(n%2==0){
		for (int i = 0; i < n; ++i){
			int a;
			cin>>a;
			if(i%2==0){
				deq.push_back(a);
			}else{
				deq.push_front(a);
			}
		}
	}else{
		for (int i = 0; i < n; ++i){
			int a;
			cin>>a;
			if(i%2==0){
				deq.push_front(a);
			}else{
				deq.push_back(a);
			}
		}
	}

	while(deq.size()){
		cout<<deq.front()<<" ";
		deq.pop_front();
	}

	cout<<endl;


	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    int n=s.size();
    int mi=(1<<30);
    for(int i=0;i+2<n;i++)
    {
        int x=100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
        mi=min(mi,abs(753-x));
    }
    for(int i=0;i+2<n;i++)
    {
        int x=100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
        if(abs(753-x)==mi)
        {
            cout<<abs(753-x)<<"\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n, m, x, y = map(int,input().split())
lx = list(map(int,input().split()))
ly = list(map(int,input().split()))
lx.append(x)
ly.append(y)
lx_max = max(lx)
ly_min = min(ly)

if lx_max >= ly_min:
  print('War')
else:
  print('No War')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    ll k;
    cin >> k;
    vector<ll> a(50, k / 50 + 1);
    for(int i = 0; i < 50; i++) {
        a[i] += i;
    }
    int q = 50 - k % 50;
    while(q--) {
        auto ind = max_element(all(a));
        *ind -= 51;
        for(int i = 0; i < 50; i++) {
            a[i] += 1;
        }
    }
    cout << 50 << endl;
    for(auto e : a) {
        cout << e << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
#print(A)
X = A[-1]
key = bisect.bisect_left(A,A[-1] // 2)
if key + 1 == N:
  Y = key - 1
elif key - 1 == -1:
  Y = key + 1
else:
  if (A[-1] / 2) - A[key-1]  <= A[key] - (A[-1] / 2):
    Y = A[key-1]
  else:
    Y = A[key]
print(X,Y)

Measured memory_bytes: 14052
#include <iostream> 
#include <cstdio> 
#include <cstdlib>  
#include <algorithm> 
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int yn = 1 << n;
    int ans = 1e9;
    for (int ms = 0; ms < yn; ms++) {
        vector<int> sum(m);
        int cost = 0;
        for (int i = 0; i < n; i++) {
            if ((ms >> i) & 1) {
                cost += c[i];
                for (int j = 0; j < m; j++) {
                    sum[j] += a[i][j];
                }
            }
        }
        bool yes = true;
        for (int j = 0; j < m; j++) {
            if (sum[j] < x) yes = false;
        }
        if (yes) ans = min(ans, cost);
    }
    if (ans == 1e9) cout << -1 << endl;
    else cout << ans << endl;
}


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

int main(){
    string s;
    cin >> s;
    vector<int> v(s.size(),0);
    for(int i = 0;i < s.size();i ++){
        int cntr = 0,cntl = 0,j;
        while(s[i]=='R') {cntr ++;i ++;}
        if(cntr%2)  {v[i] += cntr/2,v[i-1] += (cntr/2)+1;}
        else        {v[i] += cntr/2;v[i-1] += cntr/2;}

        j = i;

        while(i<s.size() && s[i]=='L') {cntl ++;i ++;}
        if(cntl%2)  {v[j] += cntl/2+1,v[j-1] += cntl/2;}
        else        {v[j] += cntl/2;v[j-1] += cntl/2;}
        i --;
    }
    for(int i = 0;i < s.size();i ++){
        cout << v[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


ll GCD(ll a, ll b){
	//if(a < b) swap(a, b);
	if(b == 0) return a;
	return GCD(b, a%b);
}

ll LCM(ll a, ll b){
	//return a * b/GCD(a, b);;
	return a/GCD(a, b) * b; //オーバーフローしないように先にgcd(a, b)で割る
}

int num_2(ll x){
	int res = 0;
	while(x%2 == 0){
		res++;
		x /= 2;
	}
	return res;
}

int main(){
	int N;
	ll M;
	cin >> N >> M;
	vector<ll> a(N);
	for(int i=0; i<N; i++) cin >> a[i];
	
	for(int i=0; i<N; i++) a[i] = a[i]>>1;
	for(int i=0; i<N-1; i++){
		if(num_2(a[i]) != num_2(a[i+1])){
			cout << 0 << endl;
			return 0;
		}
	}
	// cout << " a: "; print_vec(a);
	// cout << " num2: " << num_2(a[0]) << endl;
	if(N == 1 ) a.push_back(1);
	ll lcm = LCM(a[0], a[1]);
	for(int i=0; i<N; i++){
		lcm = LCM(lcm, a[i]);
	}
	// cout << " gcd: " << GCD(a[0], a[1]) << " lcm: " << lcm << endl;
	if(lcm > M){
		cout << 0 << endl;
		return 0;
	}

	ll ans = (M/lcm+2-1) /2; // (M/lcm) / 2の切り上げ;
	cout << ans << endl;


}



Measured memory_bytes: 3988
#include<cstdio>
#include<cstdlib>
#include<algorithm>

using namespace std;

int a,b;

int main(){
	scanf("%d%d",&a,&b);
	if(a>=13) printf("%d\n",b);
	else if(a>=6&&a<=12) printf("%d\n",b/2);
	else puts("0");
	return 0;
}

Measured memory_bytes: 888
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define vcin(V) for (int i = 0; i < (V).size(); i++) { cin >> (V).at(i); }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define nn int n=0
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool; 
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
//BEGIN OF CODE.
int a = 0, b = 0, c = 0, cnt = 0, ans = 0, n = 0;
string s, t;
int main(void){
	int m;
	cin >> n >> m;
	Yes(n == m);
	please AC;
}
//THE END.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

void cal(string s, string x, string y, map<pair<string, string>, ll>& a) {
	if(sz(s) == 0) {
		a[mp(x,y)]++;
		return;
	}
	cal(s.substr(1), x + s.substr(0,1), y, a);
	cal(s.substr(1), x, y + s.substr(0,1), a);
}

ll solve(string s, string t) {
	map<pair<string, string>, ll> a, b;
	string x,y;
	x = y = "";
	cal(s,x,y,a);
	cal(t,x,y,b);
	ll ret = 0;
	for(auto e : a) {
		auto key = e.F;
		if(b.find(key) != b.end()) {
			ret += e.S * b[key];
		}
	}
	return ret;
}



int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	string t = s.substr(n);
	reverse(all(t));
	cout << solve(s.substr(0,n), t) << '\n';
}

Measured memory_bytes: 82176
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
long i,j,k,n,m;
string s;

int main() {
  cin >>n >>k;
  vector<pair<long,long>> v;
  for(i=0;i<n;++i) {
    int a,b;cin >>a >>b;
    v.push_back(make_pair(a,b));
  }
  sort(v.begin(),v.end(),[](pair<long,long>& a,pair<long,long>& b){return a.first < b.first;});
  long sum =0;
  for(i=0;i<n;++i) {
    sum += v[i].second;
    if(sum >=k) {
      cout << v[i].first << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2420
// https://atcoder.jp/contests/abc088/tasks/abc088_a
#include <bits/stdc++.h>
using namespace std;

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

  int mod = N % 500;
  (mod <= A) ? cout << "Yes" : cout << "No";
  return 0;
}


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

N,M = map(int,input().split())

AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
ans=0
count = 0
money=0
i=0
while count < M:
    count += AB[i][1]
    if count >= M:
        count -= AB[i][1]
        money+=AB[i][0]*(M-count)
        break
    else:
        money+=AB[i][0]*AB[i][1]
    i+=1
        
print(money)


Measured memory_bytes: 56412
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

x = INT()
if x < 1200:
    print('ABC')
else:
    print('ARC')

Measured memory_bytes: 62700
n = int(input())
t, x, y = 0, 0, 0
for _ in range(n):
    D = list(map(int, input().split()))
    dt = D[0] - t
    dx = D[1] - x
    dy = D[2] - y
    l = abs(dx) + abs(dy)
    if dt < l:
        print('No')
        exit()
    if dt % 2 != l % 2:
        print('No')
        exit()
    t, x, y = dt, dx, dy
print('Yes')        


Measured memory_bytes: 3064
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    if(n%2==0 || n%5==0){
        cout<<"-1"<<endl;
        return;
    }
    ll ans=1;
    ll temp=7;
    while(temp%n!=0){
        temp=(temp*10+7)%n;
        ans++;
    }
    cout<<ans<<endl;

}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}

Measured memory_bytes: 3640
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let s: Vec<usize> = i::s()
        .iter()
        .map(|&c| c as i32 - '0' as i32)
        .map(|i| i as usize)
        .collect();
    let mut left = vec![n; 10];
    let mut right = vec![0; 10];

    for i in 0..n {
        left[s[i]] = min(left[s[i]], i);
        right[s[n - i - 1]] = max(right[s[n - i - 1]], n - i - 1);
    }

    //dbg!(&left, &right);

    let mut set = HashSet::new();

    for i in 1..(n - 1) {
        let k = s[i];
        for l_i in 0..10 {
            let l = left[l_i];
            for r_i in 0..10 {
                let r = right[r_i];
                //println!("{} {} {}", l, k, r);
                if l < i && i < r {
                    let s = format!("{}{}{}", l_i, k, r_i);
                    // println!("{}", s);
                    set.insert(s);
                }
            }
        }
    }
    println!("{}", set.len());
    //  dbg!(set);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[15];
int main() {
	scanf("%s", in);
	int N = strlen(in);

	if (in[0] != 'A') return !printf("WA\n");

	int i;
	for (i = 2; in[i]; i++) if (in[i] == 'C') break;
	if (i >= N - 1) return !printf("WA\n");
	int p = i;
	for (i = 1; in[i]; i++) if (i != p && (in[i] < 'a' || in[i] > 'z')) return !printf("WA\n");
	return !printf("AC\n");
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   int a, b;
   cin >> a >> b;
   int ret = a;
   ret += b;
   if (ret >= 10) cout << "error" << endl;
   else cout << ret << endl;	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
import math

n,a,b=map(int,input().split())

 
def comb(n,k,mod):
    """power_funcを用いて(nCk) mod p を求める"""
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    k=min(n-k,k)
    #分母
    deno=1
    #分子
    mole=1

    for i in range(1,k+1):
        mole=mole*(n-i+1)%mod
        deno=deno*i%mod

    return (mole*pow(deno,mod-2,mod))%mod


def power_func(a,b,p):
    """a^b mod p を求める"""
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
    return d*d %p
    
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p

mod=10**9+7
print((pow(2,n,mod)- 1 - comb(n,a,mod) - comb(n,b,mod))%mod)
#2**n - 1 -nCa -nCb

Measured memory_bytes: 3064
import numpy as np

def SolveNegBinary(N):
    if N == 0:
        print "0"
    else:
        r = N
        # ansTrue allocates the "True" index for -2nary expression
        ansTrue = []

        while r != 0:
            ind = (- np.sign(r) + 1)/2
            s = (-2)**ind
            while np.abs(s) < np.abs(r):
                ind +=2
                s += (-2)**ind

            ansTrue.insert(0,ind)
            r = r - (-2)**ind

        disAnswer = ""
        for k in range(ansTrue[-1] + 1)[::-1]:
            if k in ansTrue:
                disAnswer += "1"
            else:
                disAnswer += "0"


        print disAnswer
    

N = input()
SolveNegBinary(N)    

Measured memory_bytes: 10420
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long x;

int main()
{
	scanf("%lld", &x);
	
	long long r = x % 500;
	long long m = x / 500 * 1000 + r / 5 * 5;
	
	printf("%lld\n", m);
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

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

	void solve(){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		
		int MinCount=100;
		for(int i=0;i<s.length();i++) {
			char target=s.charAt(i);
			
			String t2=s;
			int count=0;
			while(true) {
				String t1="";
				for(int j=0;j<t2.length()-1;j++) {
					if(t2.charAt(j)==target) {
						t1+=t2.charAt(j);
					}else if(t2.charAt(j+1)==target){
						t1+=t2.charAt(j+1);
					}else {
						t1+=t2.charAt(j);
					}
				}
				boolean flag=true;
				for(int j=0;j<t2.length()-1;j++) {
					if(t2.charAt(j)!=t2.charAt(j+1))flag=false;
				}
				if(flag)break;
				count++;
				t2=t1;
			}
			MinCount=Math.min(count, MinCount);
		}
		System.out.println(MinCount);
	}
}


Measured memory_bytes: 88164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, k;
    cin >> a >> b >> k;
    
    int cnt = 0;
    for (int i = min(a,b); i >=1; --i)
    {
        if (a%i==0 && b%i==0)
        {
            ++cnt;
            if (k==cnt)
            {
                cout << i << endl;
            }
        }
    }
    
    return 0;
}

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

int main(){
  int n; cin >>n;
  string s,t;
  cin >>s >>t;
  for(int i = n; 0<=i; i--){
    if(s.substr(n-i)==t.substr(0,i)) {
      cout << 2*n-i << endl;
      return 0;
    }
  }
  return 0; 
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define N 20
#define mo 1000000007
#define ll long long
using namespace std;
int n,m,a[N],len[32768],bz[32768];
ll f[32768],e[N*N];
int main()
{
	scanf("%d%d",&n,&m);
	e[0]=1;fo(i,1,15*7) e[i]=e[i-1]*2%mo;
	fo(i,1,m)
	{
		int x,y;scanf("%d%d",&x,&y);
		a[x]|=e[y-1];
	}
	fo(i,0,e[n]-1)
	{
		fo(j,1,n) if((i&e[j-1])>0) len[i]++;
		bz[i]=(((i&1)>0)==((i&2)>0));
	}
	f[0]=1;
	fo(s,1,e[n]-1)
	if(bz[s])
	{
		for(int t=s;;t=(t-1)&s)
		if(bz[t])
		{
			ll jy=1;
			fo(i,1,n)
			{
				if(((s-t)&e[i-1])>0) jy=(jy*(e[len[a[i]&t]]-1))%mo;
				if((t&e[i-1])>0) jy=jy*e[len[a[i]&(s-t)]]%mo;
			}
			f[s]=(f[s]+jy*f[s-t])%mo;
			if(t==0) break;
		}
	}
	ll ans=e[m];
	ans=(ans-f[e[n]-1]+mo)%mo;
	printf("%lld\n",ans);
}

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

int B[101];

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

    int ans;
    cin >> ans;

    int prev = ans;

    for (int i = 2; i <= N - 1; ++i) {
        int b;
        cin >> b;

        ans += prev < b ? prev : b;
        prev = b;
    }

    ans += prev;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define PRIME_MAX 1000000

using namespace std;

int main() {
	bool is_prime[PRIME_MAX];
	
	is_prime[0] = false;
	is_prime[1] = false;
	REP(i,2,PRIME_MAX) { is_prime[i] = true; }
	REP(i,2,PRIME_MAX) {
		if (is_prime[i]) {
			for(int j=i+i; j<PRIME_MAX; j+=i) { is_prime[j] = false; }
		}
	}

	int ans;
	int prime_cnt;
	int a,d,N;
	while(cin >> a >> d >> N) {
		if (a==0&&d==0&&N==0) { break; }
		ans = a;
		prime_cnt=0;
		while (true) {
			if (is_prime[ans]) { 
				prime_cnt++;
			}
			if (prime_cnt >= N) { break; }
			ans+=d;
		}
		cout << ans << endl;
	}

	return 0;
}

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

    int ans;
    rep(i,n){
        int tmp;cin >> tmp;
        ans = (i)?gcd(ans,tmp):tmp;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;
#define MOD 1000000007


int main() {
    ll N;
    cin >> N;

    ll A[N];
    set<ll> st;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        st.insert(A[i]);
    }

    bool flg = false;

    if(st.size() == 1 && *st.begin() == 0) flg = true;

    if(st.size() == 2 && N % 3 == 0) {
        auto itr = st.begin();
        ll a = *itr;
        ll b = *(++itr);
        if(a > b) {
            ll tmp = a;
            a = b;
            b = tmp;
        }
        if(a == 0) {
            ll cnt_b = 0;
            for(int i=0; i<N; i++) if(A[i] == b) cnt_b++;
            if(cnt_b == 2 * N / 3) flg = true;
        }
    }

    if(st.size() == 3 && N % 3 == 0) {
        auto itr = st.begin();
        ll a = *itr;
        ll b = *(++itr);
        ll c = *(++itr);

        ll cnt_a = 0;
        ll cnt_b = 0;
        ll cnt_c = 0;
        for(int i=0; i<N; i++) {
            if(A[i] == a) cnt_a++;
            if(A[i] == b) cnt_b++;
            if(A[i] == c) cnt_c++;
        }
        if(cnt_a == N / 3 && cnt_b == N / 3 && cnt_c == N / 3) {
            if(a == (b^c) && b == (a^c) && c == (a^b)) flg = true;
        }
    }

    if(flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
	int iInputA;
	int iInputB;
	int iAveAB;
	cin >> iInputA >> iInputB;

	iAveAB = ( ( iInputA + iInputB ) / 2 ) +( ( iInputA + iInputB ) % 2 );

	cout << iAveAB << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = Integer.parseInt(s.next());
		int b = Integer.parseInt(s.next());
		int c = Integer.parseInt(s.next());
		s.close();

		int min = a+b;
		if(b+c < min) min = b+c;
		if(a+c < min) min = a+c;

		System.out.println(min);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<P>> g(n);
  rep(i,m) {
    int u, v, c;
    cin >> u >> v >> c;
    u--; v--;
    g[u].emplace_back(make_pair(v, c));
    g[v].emplace_back(make_pair(u, c));
  }
  
  set<int> st;
  auto calc = [&](int s){
    priority_queue<P, vector<P>, greater<P>> que;
    vector<int> d(n, INF);
    vector<int> to(n, -1);
    d[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
      auto p = que.top(); que.pop();
      if (d[p.second] < p.first) continue;
      for (auto e : g[p.second]) {
        if (d[e.first] > d[p.second] + e.second) {
          d[e.first] = d[p.second] + e.second;
          to[e.first] = p.second;
          que.push(make_pair(d[e.first], e.first));
        }
      }
    }
    for (int i = 0; i < n; i++) {
      int j = i;
      while (j != -1) {
        int a = j, b = to[j];
        if (a > b) swap(a, b);
        if (a != -1) st.insert(a * n + b);
        j = to[j];
      }
    }
  };


  for (int i = 0; i < n; i++) calc(i);
  cout << m - st.size() << endl;
  return 0;
}


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

int main(void){
        string s;

        cin >> s;

        int slen;
        slen = s.length();
        int start_indx;
        for(int i=0;i<slen;i++){
                if(s.substr(i,1)=="A") {
                        start_indx=i+1;
                        break;
                }

        }
        int goal_indx;
        for(int i=slen-1; i>=0; i--){
                if(s.substr(i,1)=="Z") {
                        goal_indx=i+1;
                        break;
                }
        }
        cout << (goal_indx-start_indx+1) << endl;
        return 0;
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=1e5+100;

int a[N],b[N];

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

    int p,q,m;
    cin>>p>>q>>m;
    for(int i=1;i<=p;i++)
        cin>>a[i];
    for(int i=1;i<=q;i++)
        cin>>b[i];
    int ans=*min_element(a+1,a+p+1)+
            *min_element(b+1,b+q+1);
    while(m--)
    {
        int x,y,c;
        cin>>x>>y>>c;
        ans=min(ans,a[x]+b[y]-c);
    }
    cout<<ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s; cin >> s;
    if((s[0] == s[1] && s[0] == s[2]) || (s[1] == s[2] && s[1] == s[3])) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int l;
	cin >> l;
	int bit[21] = {};
	int maxbit = -1;
	for(int i = 20; i >= 0; i--){
		if(l >= (1 << i)){
			l -= (1 << i);
			bit[i] = 1;
			maxbit = max(maxbit, i);
		}
	}
	int nodenum = maxbit + 1;
	int edgenum = 0;
	vector<vector<pair<int, int> > > edge(21, vector<pair<int, int> >());
	for(int i = 0; i < nodenum - 1; i++){
		edge[i].push_back(make_pair(i + 1, 0));
		edge[i].push_back(make_pair(i + 1, (1 << (maxbit - i - 1))));
		edgenum += 2;
	}
	int num = 0;
	for(int i = maxbit; i > 0; i--){
		if(bit[i] == 1){
			num += (1 << i);
			i--;
			while(i >= 0 && bit[i] == 0) i--;
			if(i == -1) break;
			i++;
			edge[0].push_back(make_pair(nodenum - i, num));
			edgenum++;
		}
	}
	cout << nodenum << " " << edgenum << endl;
	for(int i = 0; i < nodenum; i++){
		for(int j = 0; j < edge[i].size(); j++){
			cout << i + 1 << " " << edge[i][j].first + 1 << " " << edge[i][j].second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
n, m, q = gets.split.map(&:to_i)
a, b, c, d = Array.new(q) { gets.split.map(&:to_i) }.transpose
max = 0

[*1..m].repeated_combination(n) do |arr|
  tmp = 0
  a.zip(b, c, d).each do |a, b, c, d|
    tmp += d if arr[b - 1] - arr[a - 1] == c
  end

  max = tmp if max < tmp
end

puts max

Measured memory_bytes: 14688
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
typedef long long ll;

using namespace std;

long countIfLarger(vector<long>& B, long target){
    if(B.size() == 0){return 0;}
    int l=0;
    int r=B.size()-1;
    while(l<r){
        int m=(l+r)/2;
        if(B[m] < target){
            l = m+1;
        }else{
            r = m;
        }
    }
    if(l == B.size()-1){
        if(B.back() < target){
            return 0;
        }
    }
    return (long)(B.size()-l);
}

int main(){
    long N, K;
    cin >> N >> K;
    map<long, vector<long>> B;
    long sum=0;
    B[1] = vector<long>();
    B[1].push_back(-1);
    long res=0;
    for(long i=0;i<N;i++){
        long A;
        cin >> A;
        sum += (A % K);
        sum %= K;
        long key = (sum % K) - (i % K);//(int)((sum-(i%K)) % K);
        if(key < 0){key+=K;}
        if(B.count(key) > 0){
            res += countIfLarger(B[key], i-K+1);
        }
        if(B.count(key) == 0){
            B[key] = vector<long>();
        }
        B[key].push_back(i);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 22144
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    string s=stin();
    vec v;
    rep(i,s.length()){
        if(s[i]=='A')v.pb(0);
        else if(s[i]=='B'){
            if(i<s.length()-1){
                if(s[i+1]=='C'){
                    v.pb(1);
                    i++;
                }else{
                    v.pb(-1);
                }
            }else{
                v.pb(-1);
            }
        }else{
            v.pb(-1);
        }
    }
    ll cnt_0=0,ans=0;
    REP(x,v){
        if(x==0){
            cnt_0++;
        }else if(x==1){
            ans+=cnt_0;
        }else{
            cnt_0=0;
        }
    }
    cout<<ans<<endl;
}


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

using ll = long long;
using ul = unsigned long long;
using ld = long double;

int main()
{
    int N, K; cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());

    ll ans = 0;
    for (int i = 0; i < K; i++) {
        ans += p[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 1e5 + 5;
ll dp[N];

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n,w; cin>>n>>w;
	forn(i,N) dp[i] = 1e18;
	dp[0] = 0;
	forn(i,n)
	{
	    ll a,b; cin>>a>>b;
	    for(int j=N-b-1;j>=0;j--) dp[j+b] = min(dp[j+b],dp[j]+a);
	}
	for(int i=N-1;i>=0;i--)
	{
	    if(dp[i]<=w){ cout<<i; return 0; }
	}
	cout<<0;
	return 0;
}


Measured memory_bytes: 1152
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

Measured memory_bytes: 14480
#include <stdio.h>

int decode(char s[10]){
  int i,j;
  int r=0;
  for( i=0;s[i]!='\0';i++){
    if( '2'<=s[i] && s[i]<='9' ){
      s[i]-='0';
      continue;
    }
    j=i-1;
    if( s[i]=='m' ){
      if( i==0 ) r+=1000;
      else r+= s[j]*1000;
    }else if( s[i]=='c' ){
      if( i==0 || s[j]=='m' ) r+=100;
      else r+= s[j]*100;
    }else if( s[i]=='x' ){
      if( i==0 || s[j]=='m'||s[j]=='c' ) r+=10;
      else r+= s[j]*10;
    }else{
      if( i==0||s[j]=='m'||s[j]=='c'||s[j]=='x' ) r+=1;
      else r+=s[j];
    }

  }
  return r;
}

int main(void){ 
  int n,lp;
  char s1[10],s2[10];
  int j,sum;

  scanf("%d ",&n);
  for( lp=0;lp<n;lp++ ){
    scanf("%s %s ",s1,s2);

    sum = decode(s1)+decode(s2);
    if( (j=sum/1000)>0 ){
      if( j==1 ) printf("m");
      else       printf("%dm",j); sum = sum%1000;
    }
    if( (j=sum/100)>0 ){
      if( j==1 ) printf("c");
      else       printf("%dc",j); sum = sum%100;
    }
    if( (j=sum/10)>0 ){
      if( j==1 ) printf("x");
      else       printf("%dx",j); sum = sum%10;
    }
    if( sum>0 ){
      if( sum==1 ) printf("i");
      else         printf("%di",sum);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>

using namespace std;

int main(){
    int a,b,k;
  	cin >> a >> b >> k;
    int ans = 101;
    int cnt = 0;
    while (cnt != k){
        ans -= 1;
        if((a % ans == 0)&&(b % ans == 0)){
            cnt += 1;
        }
    }
    cout << ans << endl;
 }


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

using namespace std;

int main(){
    int i,j,s,t,n,m;
    cin>>n;
    cin>>m;
    char picturea[n][n];
    char pictureb[m][m];
    for(i=0;i<n;i++) scanf("%s",picturea[i]);
    for(i=0;i<m;i++) scanf("%s",pictureb[i]);

    /*for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            printf("%c",picturea[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<m;i++){
        for(j=0;j<m;j++){
            printf("%c",pictureb[i][j]);
        }
        printf("\n");
    }*/
    int k=n-m;//k=1
    int ct=0;
    int hantei=0;

    for(s=0;s<=k;s++){//0~1
        for(t=0;t<=k;t++){//0~1
            ct=0;
            if(picturea[s][t]!=pictureb[0][0]) ct=1;

            if(picturea[s][t]==pictureb[0][0]){
                for(i=0;i<m;i++){//s=0 0~1 s=1 1~2
                    for(j=0;j<m;j++){
                        if(picturea[i+s][j+t]!=pictureb[i][j]) ct++;
                    }
                }
            }
            if(ct==0)  hantei=1;
        }
    }
    if(hantei==0) printf("No\n");
    else printf("Yes\n");


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n,k; cin>>n>>k;
    cout<<(n+k-3)/(k-1)<<endl;
    return 0;
}


Measured memory_bytes: 256