akhauriyash/Code-Regression huggingface dataset:
def main():
    n,p = map(int,input().split())
    s = input()
    l = [0 for i in range(p)]
    l[0] = 1
    ten = 1
    cnt = 0

    ans = 0
    if p == 2 or p == 5:
        for i in range(n):
            if int(s[i]) % p == 0:
                ans += i+1
    else:
        for i in range(n):
            cnt = (cnt + int(s[-i-1]) * ten) % p
            l[cnt] += 1
            ten = (ten * 10) % p
        for i in l:
            if i > 1:
                ans += i * (i - 1) // 2

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;


int main(){
  ll N;
  cin >>N;
  ll A[N];
  rep(i,N){cin >>A[i];}
  	ll ans=0,count=0;
  for(ll i=N-2;i>=0;i--){
    if(A[i]>=A[i+1]){count++;}
    else{ans=max(ans,count);count=0;}
  }
    ans=max(ans,count);
  cout<<ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
int n,k;
double ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(k);
	for(ri i=1;i<=n;++i){
		if(i>=k) ans+=1./n;
		else{
			double res=1./n;
			int t=i;
			while(t<k)
				res/=2,t*=2;
			ans+=res;
		}
	}
	printf("%.10f",ans);
	return 0;
}

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

int main()
{
    int d;
    cin >> d;
    d = 25 - d;
    string s = "Christmas";
    for (int i = 0; i < d; i++)
    {
        s += " Eve";
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
//二分探索
//反省点 floor(A/B)=(A+A%B)/B

#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll N,K;
  cin>>N>>K;
  vector<ll>A(N),F(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cin>>F[i];
  sort(rng(A));
  sort(rng(F));
  reverse(rng(F));
  ll l=-1;
  ll r=pow(10,12);
  ll m;
  while(r-l>1){
    m=(l+r)/2;
    ll c=0;
    for(int i=0;i<N;i++){
      if(A[i]*F[i]>m){
        c+=A[i]-m/F[i];
      }
      if(c>K)break;
    }
    if(c>K)l=m;
    else r=m;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3456
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b,c,count = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i = a; i <= b; i++){
        if(c%i == 0) count++;
    }
    printf("%d\n",count);
}



Measured memory_bytes: 2760
def F(a, b):
    count = 0
    c = max(a, b)
    while c >= 10:
        c = c / 10
        count += 1
    return count+1
 
N = int(input())
minimum = 15
for num in range(1,10**5+1):
    if N % num == 0:
        minimum = min(minimum, F(num, N/num))
print(minimum)

Measured memory_bytes: 3060
N=int(input())
S=input()
ret = 0
for j in range(1,N-1):
  if S[j]=='R':
    ret += S[:j].count('G')*S[j+1:].count('B')
    ret += S[:j].count('B')*S[j+1:].count('G')
    for i in range(j):
      if j+j-i<N:
        if S[i]!=S[j+(j-i)] and S[i]!='R' and S[j+(j-i)]!='R':
          ret -=1
  elif S[j]=='G':
    ret += S[:j].count('B')*S[j+1:].count('R')
    ret += S[:j].count('R')*S[j+1:].count('B')
    for i in range(j):
      if j+j-i<N:
        if S[i]!=S[j+(j-i)] and S[i]!='G' and S[j+(j-i)]!='G':
          ret -=1
  elif S[j]=='B':
    ret += S[:j].count('R')*S[j+1:].count('G')
    ret += S[:j].count('G')*S[j+1:].count('R')
    for i in range(j):
      if j+j-i<N:
        if S[i]!=S[j+(j-i)] and S[i]!='B' and S[j+(j-i)]!='B':
          ret -=1
print(ret)

Measured memory_bytes: 68404
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b){
    printf("a > b\n");
  }
  if(a<b){
    printf("a < b\n");
  }
  if(a==b){
    printf("a == b\n");
  }
  return(0);
}

Measured memory_bytes: 2572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string s;cin >> s;
    if("zyxwvutsrqponmlkjihgfedcba"==s)cout << -1 <<endl,exit(0);
    if(s.size()==26){
        set<char> st;
        char x;
        per(i,25){
            st.ins(s[i+1]);
            if(s[i]>s[i+1])s.erase(i+1);
            else{
                x=s[i];
                s.erase(i);
                break;
            } 
        }
        x=*st.upper_bound(x);
        cout << s<<x <<endl;
        return 0;
    }
    set<char> st;
    rep(i,s.size())st.ins(s[i]);
    rep(i,26){
        if(!st.count('a'+i)){
            //cout << i <<endl;
            char x='a'+i;
            cout << s <<x<<endl;
            return 0;
        }
    }
}

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

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

	int N;
	scanf("%d", &N);

	vector<int> A(N + 1);
	vector<int> B(N + 1);

	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}

	int j, sum_i;
	int count = 0;
	for (int i = N; i >= 1; i--) {
		j = 2;
		sum_i = 0;
		while (i * j <= N) {
			sum_i ^= B[i * j];
			j++;
		}
		B[i] = sum_i ^ A[i];
		if (B[i]==1){
			count++;
		}
	}

	printf("%d\n",count);
	
	for (int i = 1; i <= N; i++) {
		if (B[i] == 1) {
			printf("%d ", i);
		}
	}
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x =sc.nextInt(),y =sc.nextInt();
	if (y>4*x||y%2==1||y<2*x) System.out.println("No");
	else System.out.println("Yes");
	sc.close();}}


Measured memory_bytes: 35688
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;

const int kx[8] = {-2, -2, -1, 1, -1, 1, 2, 2}, ky[8] = {1, -1, -2, -2, 2, 2, -1, 1}; //knight
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1}; //king
const int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

bool gridCheck(int x, int y,int n, int m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

int main(){
        _
        int h,w; cin >> h >> w;
        string board[100];
        for(int i = 0; i<h; i++){
            cin >> board[i];
        }

        for(int i = 0; i<h; i++){
            for(int j = 0; j<w; j++){
                if(board[i][j]=='#')continue;

                    int cnt = 0;
                    for(int d = 0; d<8; d++){
                        int ni = i+dx8[d];
                        int nj = j+dy8[d];
                        if(gridCheck(ni, nj,h,w) and board[ni][nj]=='#'){
                            cnt++;
                        }
                    }
                board[i][j] = char(cnt+'0');
            }
        }

        for(int i = 0; i<h; i++)cout<<board[i]<<endl;


return 0;
}



Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include <bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,M,dp[5000],a,b,c;

int main(){
    cin>>N>>M;
    rep(i,5000)dp[i]=1e9;
    dp[0]=0;
    rep(i,M){
        cin>>a>>b;
        int now=0;
        rep(j,b){
            cin>>c;
            c--;
            now+=(1<<c);
        }
        rep(j,(1<<N)){
            if(dp[j]==1e9)continue;
            dp[now|j]=min(dp[now|j],dp[j]+a);
        }
    }
    if(dp[(1<<N)-1]==1e9)out(-1);
    else out(dp[(1<<N)-1]);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,ans=0;
	scanf("%d",&n);
	for(i=0;i<=n/4;i++)
	{
		for(j=0;j<=n/7;j++)
		{
			if(i*4+j*7==n)
			{
				ans=1;
				break;
			}
		}
	}
	if(ans)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int>student(N);
  vector<int>ans(N);
  
  for(int i=0; i<N; i++) cin >> student.at(i);
  
  for(int i = 0; i<N; i++){
    ans.at(student.at(i)-1) = i+1;
  }
  
  for(int i=0; i<N; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A = in(),B = in(),K = in();
    int count = 0;
    int answer = 0;
    RREPS(i,min(A,B)){
        if(A%i == 0 && B % i == 0)count++;
        if(K == count){
            answer = i;
            break;
        }
    }
    cout << answer << "\n";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int n,k;
	cin >> n;
	cin >> k;
	long long int r = 1000000000000;
	vector<int>p(n);
	for (int i = 0; i < n; i++)cin >> p[i];
	sort(p.begin(), p.end());
	for (int i = k-1; i <n; i++) {
		r=min(r,(long long int)(p[i]-p[i-k+1]));
	}
//	sort(p.begin(), p.end());
	cout << r << endl;
	return 0;

}

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

int main(void){
    int N, ret=0;
    
    cin>>N;
    int arr[N];

    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    for(int i=N-1;i>=0;i--){
        int size = i;
        int cnt = 0;
        for(int j=i-1;j>=0;j--){
            if(!(arr[i]<arr[j])){
                cnt++;
            }
            if(cnt == size) ret+=1;
            // cout<<"ret: "<<ret<<endl;
            // cout<<cnt<<", "<<size<<endl;
            // cout<<arr[i]<<" "<<arr[j]<<endl;
        }
        //cout<<endl;
    }
    //가장 서쪽 산은 무조건 바다가 보이니 1추가
    cout<<ret+1<<"\n";
    return 0;
}

Measured memory_bytes: 256
line = input()
a, b = [int(n) for n in line.split()]

soma0= a + b

soma1 = a 
a = a-1
soma1 = soma1 + a 
a = a-1 

soma2 = b
b = b-1
soma2 = soma2 + b
b = b-1

if soma0>=soma1 and soma0>=soma2:
    print(soma0)

elif soma1>=soma0 and soma1>=soma2:
    print(soma1)

else:
    print(soma2)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	string s, t;
	cin >> s;
	cin >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<int>());
	if (s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

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

for i in range(M):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

def dfs(i, visited):
    if all(visited):
        return 1
    total = 0
    for j in graph[i]:
        if not visited[j]:
            nvisited = visited[:]
            nvisited[j] = True
            total += dfs(j, nvisited)
    return total

def main():
    """ main """
    visited = [False] * N
    visited[0] = True
    print(dfs(0, visited))

if __name__ == '__main__':
    main()


Measured memory_bytes: 43484
// ProblemURL : https://atcoder.jp/contests/apc001/tasks/apc001_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	if x%y == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(x)
	}
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC146A()
{
	map<string, int> x;
	x["SUN"] = 7;
	x["MON"] = 6;
	x["TUE"] = 5;
	x["WED"] = 4;
	x["THU"] = 3;
	x["FRI"] = 2;
	x["SAT"] = 1;
	string S;
	cin >> S;
	cout << x.find(S)->second << endl;
}
int main()
{
	ABC146A();
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main() {
	int number = 0;
	int train = 0;
	int taxi = 0;

	scanf("%d", &number);

	scanf("%d", &train);

	scanf("%d", &taxi);


	if (taxi > (number*train)) {
		printf("%d", (number*train));
	}
	else {
		printf("%d", taxi);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);

    ll a_max = 0;
    rep(i,n){
        ll a_i;
        cin >> a_i;
        a[i] = a_i;
        a_max = max(a_max, a_i);
    }
    vector<int> cnt(a_max);
    rep(i,n){
        if(cnt[a[i] - 1] <= 1){
            ll j = 1;
            while(a[i] * j <= a_max){
                cnt[a[i] * j - 1]++;
                j++;
            }
        }
    }
    int ans = 0;
    rep(i,n){
        if(cnt[a[i] - 1] == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8800
from collections import deque

s = input()
k = int(input())

def index_Multi(List,liter):
    #Listはリスト本体・literは検索したい文字
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L

def substr(s, k, j):
    n = ord("a")

    while True:
        l = index_Multi(s, chr(n+j))
        word = []
        if len(l) == 0:
            n += 1
        else:
            for p in l:
                for i in range(k):
                    word.append(s[p:p+i+1])
            sword = set(word)
            if len(sword) >= k:
                tword = list(sword)
                tword.sort()
                #print(tword, sword)
                return tword[k-1]
            else:
                return substr(s, k-len(sword), j+1)
            break

print(substr(s, k, 0))

Measured memory_bytes: 10760
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

c = 0
for i in range(n):
    ai = a[i]
    bi = b[i]
    if ai < bi:
        c += (bi-ai)//2
    else:
        c -= (ai-bi)
print('Yes' if c >= 0 else 'No')


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

int main(){
    string s;
    cin >> s;
    int flag = 0;
    if(s == "AAA" || s == "BBB"){
        flag = 1;
    }

    if(flag == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)return 0;
		int b[100];
		for (int i = 0; i < n; i++)cin >> b[i];
		sort(b, b + n);
		int res = 0;
		for (int i = 1; i < n - 1; i++)res += b[i];
		cout << res/(n-2) << endl;
	}
}


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

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

  if(N == 1)
    cout << "Hello World" << endl;
  else if(N == 2){
    cin >> A >> B;
    cout << A + B << endl;
  }

  return 0;
}

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

#define INF (ULLONG_MAX/3)
using ull = unsigned long long;
constexpr int MAXN = 3e2;
ull path[MAXN][MAXN];
ull tour[MAXN][MAXN];

int main(void) {
    int N, M, L;
    cin >> N >> M >> L;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) path[i][j] = 0;
            else path[i][j] = INF;
        }
    }
            
    for (int i = 0, u, v, w; i < M; i++) {
        cin >> u >> v >> w;
        path[u-1][v-1] = w;
        path[v-1][u-1] = w;
    }

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                path[i][j] = min(path[i][j], path[i][k] + path[k][j]);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) tour[i][j] = 1;
            else if (path[i][j] <= L) tour[i][j] = 1;
            else tour[i][j] = INF;
        }
    }
    
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                tour[i][j] = min(tour[i][j], tour[i][k] + tour[k][j]);

    int Q, s, t; cin >> Q;
    while (Q--) {
        cin >> s >> t;
        s--; t--;
        if (tour[s][t] == INF) cout << "-1\n";
        else cout << tour[s][t] - 1 << "\n";
    }
}

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

int main()
{
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
P = Line(N,1)

place = [-1]*(N+1)
for i in range(N):
    place[P[i]] = i

max_ascend = 0
temp = 1
for i in range(2,N+1):
    if place[i]>place[i-1]:
        temp += 1
    else:
        if max_ascend<temp:
            max_ascend = temp
        temp = 1

if max_ascend<temp:
    max_ascend = temp

print(N-max_ascend)

Measured memory_bytes: 52828
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll mod=1e9+7;
ll dp[2020][2020];
int main()
{
	int n,k;
	cin>>n>>k;
	int i,j;
	//calculating nCr using dynamic programming
	//using the fact nCr=n-1Cr+ n-1Cr-1
	dp[0][0]=1;
	for(i=1;i<=2000;i++)
	{
		for(j=0;j<=i;j++)
		{
			if(j==0 or j==i)
				dp[i][j]=1;
			else
				dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
		}
	}
	for(i=1;i<=k;i++)
	{
		cout<<(dp[n-k+1][i]*dp[k-1][i-1])%mod<<endl;
	}
	return 0;
}

Measured memory_bytes: 30336
import sys
from itertools import groupby


fin = sys.stdin.readline
S = fin().rstrip("\n")
grp = [len(list(v)) for k, v in groupby(S)]
result = [0] * len(S)
cur_idx = 0
# print(grp)
for i in range(0, len(grp), 2):
    num_Rs, num_Ls = grp[i], grp[i + 1]
    center = num_Rs + cur_idx - 1
    for j in range(cur_idx, num_Rs + num_Ls + cur_idx):
        dist = abs(center - j) % 2
        result[center + dist] += 1
    cur_idx += num_Rs + num_Ls
print(*result)


Measured memory_bytes: 50976
dic = {}

for i in range(int(input())):
    order = list(input().split())

    if order[0] == "0":
        if order[1] in dic:
            dic[order[1]] = int(order[2])
        else:
            dic[order[1]] = int(order[2])
    elif order[0] == "1":
        if order[1] in dic:
            print(dic[order[1]])
        else:
            print(0)
    elif order[0] == "2":
        if order[1] in dic:
            dic.pop(order[1])


Measured memory_bytes: 37520
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll vmin = (n - 1) * a + b;
  ll vmax = a + (n - 1) * b;
  ll ans = vmax - vmin + 1;
  if (0 <= ans)
    cout << ans << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}

int main() {
  int n; cin>>n;
  if (n==1) {
    cout<<"Yes\n2\n1 1\n1 1"<<endl;
    return 0;
  }
  int p=0;
  while(n > p*(p+1)/2) p++;
  if (n != p*(p+1)/2) {
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  cout<<p+1<<endl;
  int d[p+2]; int id=0, nw=1;
  for(int i=0;i<=p;i++) {
    cout<<p<<" ";
    for(int j=0;j<id;j++) {
      cout<<d[j]++<<" ";
    }
    d[id]=nw;
    for(int j=id;j<p;j++) {
      cout<<nw++<<" ";
    }
    id++;
    cout<<endl;
  }
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vint a = in(n), b = in(n), c = in(n);
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    ll ans = 0;

    vint bn(n);
    rep(i, n)
    {
        auto citr = upper_bound(ALL(c), b[i]);
        bn[i] = n - (citr - c.begin());
    }

    vll bs(n + 1);
    rep(i, n)
    {
        bs[i + 1] = bs[i] + bn[i];
    }

    auto l_bitr = b.begin();

    rep(i, n)
    {
        int ca = a[i];
        auto bitr = upper_bound(l_bitr, b.end(), ca);
        l_bitr = bitr;

        ans += (bs[n] - bs[bitr - b.begin()]);
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")
import heapq


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    XYZ = [X, Y, Z]
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    ABC = [A, B, C]

    base = A[0]+B[0]+C[0]
    cand = [[0, 0, 0, 0]]
    heapq.heapify(cand)
    # print(cand)
    for i in range(K):
        a = heapq.heappop(cand)
        for j in range(1, 4):
            if a[j]+1 < XYZ[j-1]:
                b = [a[0]+ABC[j-1][a[j]]-ABC[j-1][a[j]+1],
                     a[1]+int(j == 1),
                     a[2]+int(j == 2),
                     a[3]+int(j == 3)]
                if b not in cand:
                    heapq.heappush(cand, b)
        # print(cand)
        print(base-a[0])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(X)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(Y)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(Z)]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int K;
    cin >> K;

    long long num = 7;
    long long count = 1;

    if(K % 2 == 0){
        cout << "-1" << endl;
        return 0;
    }

    while(1){
    
        num %= K;

        if(num == 0){
            cout << count << endl;
            return 0;
        }

        count++;
        num *= 10;
        num += 7;

        if(count == 100000000){
            break;
        }
    }

    cout << "-1" << endl;

}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 101;
int a[N];
int ans;
int main() {
	ios_base::sync_with_stdio(0);
	
	int k,s;
	cin >> k >> s;
	for(int i = 0; i <= k; i++)
		for(int j = 0; j <= k; j++){
			int p = s - (i + j);
			if (p >= 0 && p <= k && i + j + p == s)
						ans++;
		}
		
		
	cout << ans << endl;
  	return 0;
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int A[220000], B[220000];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i];
    for (int i = 0; i < N; i++)cin >> B[i];
    for (int i = 0; i < N; i++) {
        if (A[i] > B[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    priority_queue<pint> pq;
    for (int i = 0; i < N; i++)if (A[i] != B[i])pq.push(pint(B[i], i));
    int ans = 0;
    while (!pq.empty()) {
        int idx = pq.top().second;
        pq.pop();
        int tar = max(B[(idx + 1) % N], B[(idx + N - 1) % N]);
        int diff = B[(idx + 1) % N] + B[(idx + N - 1) % N];
        int need = (B[idx] - tar) / diff + 1;
        if ((B[idx] - A[idx]) % diff == 0) {
            int need2 = (B[idx] - A[idx]) / diff;
            if (need >= need2) {
                ans += need2;
                B[idx] = A[idx];
                continue;
            }
        }
        ans += need;
        B[idx] -= need * diff;
        pq.push(pint(B[idx], idx));
        if (B[idx] < A[idx]) {
            cout << -1 << endl;
            return 0;
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 9628
#include<stdio.h>
int isprime(int n){
    int i;
    for(i = 2; i < n; i ++ ){
        if(n % i == 0)return 0;
    }
    return 1;
}
int main(void){
    const int NUM = 10000;
    int i,n,prime[NUM],p1,q1;
    for(i = 2; i < NUM; i ++ ){
        prime[i] = isprime(i);
    }
    
    while(1){
        scanf("%d",&n);
        if(n == 0)break;
        for(i = n; i >= 2; i --){
            if(prime[i] == 1 && prime[i - 2] == 1){
                    q1 = i;
                    p1 = i - 2;
                    printf("%d %d\n",p1,q1);
                    break;
            }
        }
    }
    return 0;
}

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

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

  int MAX = min(A, B);
  int min = N - A - B;

  if (min < 0) min = abs(min);
  else min = 0;

  cout << MAX << " " << min << endl;
}

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

int n, m;
int ice[92][92];
int move[92][92];
int solve(int x, int y){
    int M=0;
    move[x][y] = 0;
    if(move[x+1][y]){
        M = max(M, solve(x+1, y));
        move[x+1][y]=1;
    }
    if(move[x][y+1]){
        M = max(M, solve(x, y+1));
        move[x][y+1]=1;
    }
    if(move[x-1][y]){
        M = max(M, solve(x-1, y));
        move[x-1][y]=1;
    }
    if(move[x][y-1]){
        M = max(M, solve(x, y-1));
        move[x][y-1]=1;
    }
    return M+1;
}
int main(){
    int M;
    int a;
    cin >> n >> m;
    while(n || m){
        n++;
        m++;
        M=0;
        for(int i=0;i<92;i++){
            for(int j=0;j<92;j++){
                ice[i][j] = 0;
            }
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<m;j++){
                cin >> ice[i][j];
            }
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<m;j++){
                if(ice[i][j]){
                    memcpy(move, ice, sizeof(ice));
                    M=max(M,solve(i,j));
                }
            }
        }
        cout << M << endl;
        cin >> n >> m;
    }
}

Measured memory_bytes: 1224
import math
N,M = (int(T) for T in input().split())
S = input()
T = input()
Length = N*M//math.gcd(N,M)
Flag   = True
SIndex = [Nk*(Length//N) for Nk in range(0,N)]
SList  = list(S)
    
for Mk in range(0,M):
    if Mk%(Length//N)==0:
        MInd = SIndex.index(Mk*(Length//M))
        if SList[MInd]!=T[Mk]:
            Flag = False
            break
        
if Flag:
    print(Length)
else:
    print(-1)

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


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

int main(){
	string s;
	cin >> s;
	if(s == "RRR"){
		cout << 3 << endl;
	}else if(s == "SRR" || s == "RRS"){
		cout << 2 << endl;
	}else if(s == "SSS"){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
}


Measured memory_bytes: 3188
ABCDE = []
ABCDEamari = []
for i in range(5):
    ABCDE.append(int(input()))
    ABCDEamari.append(ABCDE[i]%10)
answer = 0
for i in range(5):
    if ABCDEamari[i] == 0:
        answer += ABCDE[i]
    else:
        answer += (ABCDE[i]//10)*10 + 10

min = 10

for i in range(5):
    if min > ABCDEamari[i] and ABCDEamari[i] != 0:
        min = ABCDEamari[i]
    

answer -= (10-min)%10

print(answer)

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

int main(){

    int N;
    string A, B, C;
    cin >> N;
    cin >> A;
    cin >> B;
    cin >> C;
    int ans = 0;
    rep(i, N){
        if(A[i]!=B[i] && B[i]!=C[i] && A[i]!=C[i])ans+=2;
        else if(A[i]==B[i] && B[i]==C[i])ans+=0;
        else ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> mon(N+1,0);
  vector<long long> hero(N,0);
  for(int i = 0;i < N + 1;i++){
    cin >> mon.at(i);
  }
  for(int i = 0;i < N;i++){
    cin >> hero.at(i);
  }
  long long count = 0,x = 0,y = 0;
  for(int i = 0;i < N;i++){
    x = min(mon.at(i),hero.at(i));
    count += x;
    hero.at(i) -= x;
    if(hero.at(i) != 0){
      y = min(mon.at(i + 1),hero.at(i));
      count += y;
      mon.at(i + 1) -=y;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 4840
def solve(v)
  d = (v[0].to_f / v[1].to_f).to_s.split(".")[1]
  s = 0
  count = 0
  d.each_byte{|c|
    s += c - 48
    break if (count += 1) == v[2].to_i
  }
  return s
end

while input = $stdin.gets
  v = input.chomp.split(" ")
  p solve(v)
end

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


int main() {
    int N;
    cin >> N;
    vector <int> a(N);
    for (int i=0; i < N; i++){
        cin >> a.at(i);
    }

    sort(a.begin(),a.end());
    for (int i = 0; i<N-1; i++){
        if (a.at(i)==a.at(i+1)){
            cout << "NO" << endl;
            exit(0);
        }
    }

    cout << "YES" << endl;
  }

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, D[105], ans = 1;

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> D[i];
  sort(D, D + N);

  for (int i = 1; i < N; i++){
    if (D[i] == D[i - 1]) continue;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

ll digitcal(ll x){
  ll n=0;
  while(x>0){
    x/=10;
    n++;
  }
  return n;
}

int main() {
  int n;
  cin>>n;
  int a[101][101];
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      a[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    int two=0,five=0;
    if(s.find(".") == string::npos){
      int x=stoi(s);
      //cout<<x<<endl;
      while(x%2==0){
        two++;
        x/=2;
      }
      while(x%5==0){
        five++;
        x/=5;
      }
      a[two+50][five+50]++;
      //cout<<two<<' '<<five<<endl;
      continue;
    }
    int y=s.find(".");
    two=-((int)s.size()-y-1);five=-((int)s.size()-y-1);
    ll now=1;
    ll moto=0;
    for(int j=(int)s.size()-1;j>=0;j--){
      if(s[j]=='.') continue;
      moto+=(int)(s[j]-'0')*now;
      now*=10;
    }
    //cout<<moto<<endl;
    while(moto%2==0){
      moto/=2;
      two++;
    }
    while(moto%5==0){
      moto/=5;
      five++;
    }
    //cout<<two<<' '<<five<<endl;
    a[two+50][five+50]++;
  }
  ll sum[101][101];
  sum[100][100]=a[100][100];
  for(int i=99;i>=0;i--){
    sum[i][100]=sum[i+1][100]+a[i][100];
    sum[100][i]=sum[100][i+1]+a[100][i];
  }
  for(int i=99;i>=0;i--){
    for(int j=99;j>=0;j--){
      sum[i][j]=a[i][j]+sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1];
    }
  }
  ll ans=0;
  for(int i=0;i<=49;i++){
    for(int j=0;j<=49;j++){
      ans+=a[i][j]*sum[100-i][100-j];
    }
  }
  for(int i=50;i<=100;i++){
    for(int j=0;j<=49;j++){
      ans+=a[i][j]*sum[50][100-j];
    }
  }
  for(int i=0;i<=49;i++){
    for(int j=50;j<=100;j++){
      ans+=a[i][j]*sum[100-i][50];
    }
  }
  for(int i=0;i<=49;i++){
  	for(int j=50;j<=100;j++){
    	ans+=a[i][j]*(sum[100-i][100-j]-sum[100-i][50]);
    }
  }
  ans+=sum[50][50]*(sum[50][50]-1)/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3664
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int i = 1, cur = 7;
    for (; i <= k; i++) {
        if (cur % k == 0) {
            cout << i << endl;
            return 0;
        }
        cur = (cur * 10 + 7) % k;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int k, a, b;
	cin >> k >> a >> b;
	if((a + k - 1) / k * k <= b){
		cout << "OK";
	}
	else{
		cout << "NG";
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3640
#include <cstdio>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
int a[2010];
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    int cnt=0;
    for(int i=1;i<=n-2;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(a[i]+a[j]<=a[k]) break;
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
  int roop;
  double a, sum;

  while ( scanf("%lf", &a) != EOF) {
    sum = a;

    for (roop = 2; roop <= 10; roop++) {
      if ((roop % 2) == 0) {
        a *= 2;
        sum += a;
      } else {
        a /=3;
        sum += a;
      }
    }

    printf("%f\n", sum);
    sum = 0;
  }

  return 0;
}

Measured memory_bytes: 648
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

int main() {
string s, tmp;
map<char, int> count, ans;
int n;
cin >> n;
for(char i = 'a'; i<='z'; i++){
  ans[i] = 52;
}
REP(i, n){
  cin >> s;
  int l = s.size();
  char f='a';
  for(char j = 'a'; j<='z'; j++){
  count[j] = 0;
  }
  REP(j, l){
    count[s[j]]++;
    if(f<s[j]) f=s[j];
  }

  for(char j = 'a'; j<='z'; j++){
    ans[j]=min(ans[j], count[j]);
  }
//  cout << f << endl;

}
/*for(char i = 'a'; i<='z'; i++){
  cout << i << ' ' <<  ans[i] << ' ' << count[i] << ' ' << endl;
}*/
for(char i = 'a'; i<='z'; i++){
  REP(j,ans[i]) cout << i;
}
cout << endl;

}

Measured memory_bytes: 888
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static String a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            a=sc.next();
            if(a.equals("0")){
                sc.close();
                return;
            }
            int len=a.length();
            int ans=0;
            for(int i=0;i<len;i++){
                int b=a.charAt(i)-'0';
                ans+=b;
            }
            System.out.printf("%d\n",ans);
        }
    }
    public static long sumDigits(long n) {
        long sum=0;
        while(n!=0){
            sum+=n%10;
            n/=10;
        }
        return sum;
    }
}


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

int main(void)
{
    int N;
    cin >> N;
    int s[N];
    int is10[N] = {};
    int max = 0;
    for( int i = 0; i < N; i++){
        cin >> s[i];
        max += s[i];
    }
    sort(s, s+N);
    for( int i = 0; i < N; i++){
        if( s[i] % 10 == 0) is10[i] = 1;
    }
    if( max % 10 != 0){
        cout << max;
        return 0;
    }
    for( int i = 0; i < N; i++){
        //printf("is10[%d] = %d\n", i, is10[i]);
        if( is10[i] == 0 ){
            cout << max - s[i];
            return 0;
        }
    }
    cout << 0;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=3*10000000000;

int main()
{
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x){
        cin >> a[i];
    }
    rep(i,y){
        cin >> b[i];
    }
    rep(i,z){
        cin >> c[i];
    }
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());
    vector<ll> sum(x*y);
    rep(i,x){
        rep(j,y){
            sum[x*j+i]=a[i]+b[j];
        }
    }
    sort(sum.rbegin(),sum.rend());
    vector<ll> ans;
    rep(i,min(x*y,3000LL)){
        rep(j,z){
            ans.push_back(sum[i]+c[j]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    rep(i,k){
        cout << ans[i] << endl;
    }
    
    return 0;
} 

Measured memory_bytes: 42984