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

typedef long long ll;

const ll mod = 1e9 + 7;

#define ff(i,n) for(int i=1;i<=n;i++)

ll C[4005][4005], n, k;

ll solve(int i, int total)
{
	if(total < i) return 0;
	if(i==0 && total > 0) return 0;
	if(i==0 && total == 0) return 1;
	if(i<0) return 0;
	total -= i;
	return C[i-1][total+i-1];
}

int main() {
	C[0][0] = 1;
	for(int i = 1; i <= 4000; i++)
	{
		C[0][i] = C[i][i] = 1;
		for(int j = 1; j < i; j++) 
		{
			C[j][i] = (C[j][i-1] + C[j-1][i-1])%mod;
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) cout <<  (solve(i,k) * (solve(i-1,n-k) + 2*solve(i,n-k) + solve(i+1,n-k))%mod)%mod << endl;
}
//hahahahahahahahahhahahahahahaahahahahhahahahahahahah


Measured memory_bytes: 125184
#include <iostream>

using namespace std;

void insertionSort(int *A, int n)
{
    for(int i = 0; i < n; ++i)
    {
        int v = A[i];
        int j = i - 1;
        
        while( j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
          --j;
        }
        A[j + 1] = v;
        
        for(int k = 0; k < n - 1; ++k)
        { cout << A[k] << " "; }
        cout << A[n - 1] << endl;
    }
    return;
}

int main()
{
    int n;
    cin >> n;
    
    int A[n];
    
    for(int i = 0; i < n; ++i)
    { cin >> A[i]; }
    
    insertionSort(A, n);
    
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>

using namespace std;

int main() {
	int N;
	int X[105] = {};

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	
	int result = 100000000;
	for (int P = 1; P <= 100; P++) {
		int r = 0;
		for (int i = 0; i < N; i++) {
			r += (X[i] - P) * (X[i] - P);
		}
		if (r < result) {
			result = r;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t x,int64_t y){
if(y==0)
  return x;
  else
    return gcd(y,x%y);
}
int main(){
int N; int64_t K;
  cin>>N>>K;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  sort(A.begin(),A.end());
  int64_t g=A.at(0);
  for(int i=1;i<N;i++)
    g=gcd(g,A.at(i));
  if(K%g!=0)
    cout<<"IMPOSSIBLE"<<endl;
  else{
  if(K<=A.at(N-1))
    cout<<"POSSIBLE"<<endl;
    else
      cout<<"IMPOSSIBLE"<<endl;
  
  }
  
   return 0;
}


Measured memory_bytes: 1024
def calc(a, op, b)
  case op
  when '+'
    puts "#{a + b}"
  when '-'
    puts "#{a - b}"
  when '*'
    puts "#{a * b}"
  when '/'
    puts "#{a / b}"
  else
  end
end

loop do
    a, op, b = gets.split
    break if op == '?'

    calc(a.to_i, op, b.to_i)
end



Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 505;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int> > a(MAX, vector<int>(MAX));
    int l, r;
    for (int i = 0; i < M; i++) {
        cin >> l >> r;
        a[l][r]++;
    }
    vector<vector<int> > sum(MAX + 1, vector<int>(MAX + 1));
    for (int i = 0; i < MAX; i++) {
        for (int j = 0; j < MAX; j++) {
            sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + a[i][j];
        }
    }

    for (int i = 0; i < Q; i++) {
        cin >> l >> r;
        cout << sum[r+1][r+1] - sum[r+1][l] - sum[l][r+1] + sum[l][l] << '\n';
    }

}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (1) {
		int x, y, s;
		cin >> x >> y >> s;
		if (x == 0)break;
		int cmax = -INF;
		FOR(i, 1, s - 1) {
			FOR(j, 1, s - 1) {
				if (i*(100 + x) / 100 + j*(100 + x) / 100 == s)cmax = max(cmax, i*(100 + y) / 100 + j*(100 + y) / 100);
			}
		}
		cout << cmax << endl;

	}
	return 0;
}

Measured memory_bytes: 3184
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();

                int n = 0;
                if (x > (y + z)) {
                   n = (x - z) / ( y + z);
                }
                
		// 出力
		System.out.println(String.valueOf(n));
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

struct unionfind{
    vector<int> par;
    vector<int> size;
    vector<int> si;
    int num;
    unionfind(int n):num(n), par(n,-1), size(n,1),si(n,1){}
    int find(int x){
        if(par[x]==-1)return x;
        return par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(size[x]>size[y])swap(x,y);
        if(size[x]==size[y])size[y]++;
        par[x]=y;
        si[y]+=si[x];
        num--;
        return;
    }
    void get(const int m){
        rep(i,m){
            int a,b;cin >> a >> b;
            a--;b--;
            unite(a,b);
        }
        return;
    }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n,m;cin >> n >> m;
    unionfind uf(n);
    rep(i,m){
        int a,b;cin >> a >> b;
        uf.unite(a-1,b-1);
    }
    int ans=0;
    rep(i,n){
        ans=max(ans,uf.si[uf.find(i)]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int64_t N, K;
	cin >> N >> K;

	int64_t ans = 0;
	for (int64_t i = K + 1; i <= N; i++) {
		ans += (i - K) * (N / i);
		int64_t n = N % i;
		if (n >= K) ans += n - K + 1;
	}

	if (!K) ans = N * N;

	cout << ans << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define fi first
#define se second
const int N = 1e5 + 5;

int n, k;
vector <pair<int, int>> v[N];
ll dp[N];

struct BIT {
    ll c[N];
    void init() {
        for (int i = 1; i <= n; i++) {
            c[i] = 1e18;
        }
    }
    int lowbit(int x) {
        return x & (-x);
    }
    void update(int x, ll v) {
        x = n - x + 1;
        for (; x <= n; x += lowbit(x)) {
            c[x] = min(c[x], v);
        }
    }
    ll query(int x) {
        x = n - x + 1;
        ll res = 1e18;
        for (; x; x -= lowbit(x)) {
            res = min(res, c[x]);
        }
        return res;
    }
}bit;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  ll a,b,c;
  cin>>a;
  ll ans=0;
  for(ll i=1;i<=a;i++)
  {
      cin>>b;
      if(b%2==1&&i%2==1)
        ans++;
  }
  cout<<ans;

    return 0;
}
/*
4 6
3 3 -10
4 4 8
2 3 -2
4 4 -10
4 4 5
1 4 2
*/


Measured memory_bytes: 5992
#include <stdio.h>


int  selectionSort(int A[], int N) {
	int i, j,minj, tmp, count = 0;
	
	for (i = 0; i < N ; i++) {
		minj = i;
		for (j = i; j < N ; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;;
		if (i != minj) count++;
	}
	return count;
}

int main(void) {
	int N;
	int A[100];
	int i;
	int kai;

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

	for (i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");

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

	return 0;
}

Measured memory_bytes: 604
import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,input().split())
def i() : return int(input())
a,b=mi()
ans=0
l=[[] for _ in range(a)]
for i in range(b):
  u,v=mi()
  l[u-1].append(v-1)
  l[v-1].append(u-1)
S=[]
for i in range(1,a):
  S.append(i)
lst=list(permutations(S))
for i in lst:
  x=0
  t=True
  for w in range(len(i)):
    if not i[w] in l[x]:
      t=False
      break
    x=i[w]
  if t:
    ans+=1
print(ans)

Measured memory_bytes: 4084
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
    int ans =0;
    string str = "1";
    
    while(str[0] != '0'){
        getline(cin,str);
        for(int i=0;i<str.size();i++){
            if(str[i] == '1'){
                ans += 1;
            }else if(str[i] == '2'){
                ans += 2;
            }else if(str[i] == '3'){
                ans += 3;
            }else if(str[i] == '4'){
                ans += 4;
            }else if(str[i] == '5'){
                ans += 5;
            }else if(str[i] == '6'){
                ans += 6;
            }else if(str[i] == '7'){
                ans += 7;
            }else if(str[i] == '8'){
                ans += 8;
            }else if(str[i] == '9'){
                ans += 9;
            }else if(str[i] == '0'){
                ans += 0;
            }
        }
        if(str[0] !='0')printf("%d\n",ans);
        ans =0;
    }
    return 0;
}


Measured memory_bytes: 3192
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := nextLine()
	inputs := strings.Split(input, " ")
	n, _ := strconv.Atoi(inputs[0])
	k, _ := strconv.Atoi(inputs[1])
	input = nextLine()

	answer := ((n - 1) / (k - 1))

	if (n-1)%(k-1) != 0 {
		answer++
	}
	fmt.Println(answer)
}


Measured memory_bytes: 768
#include <iostream>

int main()
{
    int n, m, l;
    std::cin >> n >> m >> l;

    int a[n][m] = {};
    int b[m][l] = {};
    long int c[n][l] = {};

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j];
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            std::cin >> b[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int f = 0; f < m; f++) {
                c[i][j] += a[i][f] * b[f][j];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            std::cout << c[i][j];
            if (j == l - 1) {
                std::cout << std::endl;
            } else {
                std::cout << " ";
            }

        }
    }

    return 0;
}

Measured memory_bytes: 3220
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

K,T=mint()
A=lint()
print(max(0,max(A)-(K-max(A))-1))

Measured memory_bytes: 69276
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    ll n,k;
    cin>>n>>k;
    cin>>s;
    if(s[k-1]=='A')
    {
    	s[k-1]='a';
    }
    if(s[k-1]=='B')
    {
    	s[k-1]='b';
    }
    if(s[k-1]=='C')
    {
    	s[k-1]='c';
    }
    cout<<s<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 h, w, n, sr, sc;
string s, t;
i64 vr[] = {0, 0, -1, 1},
    vc[] = {-1, 1, 0, 0};
const char* pt = "LRUD";
const char* ipt = "RLDU";
int main() {
  cin >> h >> w >> n >> sr >> sc >> s >> t;
  for (i64 k = 0; k < 4; ++k) {
    i64 r = sr, c = sc;
    for (i64 i = 0; i < n; ++i) {
      if (s[i] == pt[k]) { r += vr[k]; c += vc[k]; }
      if (r <= 0 || h < r || c <= 0 || w < c) {
        cout << "NO\n"; return 0;
      }
      if (t[i] == ipt[k]) { r -= vr[k]; c -= vc[k]; }
      if (r <= 0) r = 1;
      if (h < r) r = h;
      if (c <= 0) c = 1;
      if (w < c) c = w;
    }
  }
  cout << "YES\n";
  return 0;
}


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

int main(){
    int n, h, w;
    cin >> n >> h >> w;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= h && b[i] >= w) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int main() {
    int H,W; cin >> H >> W;
    int Ch, Dh,Cw,Dw;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    Ch--;Cw--; Dh--; Dw--;
    vector<string> S(H);
    REP(i,H) cin >> S[i];

    vecveci dist(H,veci(W,1e9));
    dist[Ch][Cw] = 0;

    deque<pair<int, int>> que;
    que.push_back({Ch, Cw});

    while(que.size()){
        // 先頭を取る
        auto p = que.front(); que.pop_front();
        int i = p.first, j = p.second;
 
        // 方向の遷移
        for(int dy = -2; dy<=2; dy++){
            for(int dx = -2; dx <= 2; dx++) {
                if(dy == 0 && dx == 0) continue;
                int i2 = i + dy, j2 = j + dx;
                if(i2 < 0 || i2 >= H || j2 < 0 || j2 >= W) continue;
                if(S[i2][j2] == '#') continue;
                
                bool wall = (abs(dy) == 2 || abs(dx) == 2 || (abs(dy) == 1 && abs(dx) == 1));
                int d2 = dist[i][j] + wall;

                if(dist[i2][j2] > d2){
                    dist[i2][j2] = d2;
                    if(wall){
                        que.push_back({i2, j2});
                    }else{
                        que.push_front({i2, j2});
                    }
                }
            }
        }
    }
    if(dist[Dh][Dw] == 1e9) cout << -1 << endl;
    else cout << dist[Dh][Dw]  << endl;
}

Measured memory_bytes: 9496
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Perform BFS from 2...N then use those values to print

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		x%=10;
		String ans = "";
		if (x==3) ans = "bon";
		else if (x==0||x==1||x==6||x==8) ans = "pon";
		else ans = "hon";
		System.out.println(ans);
	}	
}


Measured memory_bytes: 27052
n = int(input())
a = []
b = []
for i in range(n):
 s,t = input().split()
 a.append(s)
 b.append(t)

x = input()
sum = 0
flg = 0
for i in range(n):
 if flg == 1:
  sum += int(b[i])
 if x == a[i]:
  flg = 1

print(sum)








Measured memory_bytes: 3060
from fractions import gcd

N, M = map(int, input().split())
s = input()
t = input()
g = gcd(N, M)
n, m = N//g, M//g

for i in range(g):
    if s[n*i] != t[m*i]:
        print(-1)
        exit()
print(N*M//g)

Measured memory_bytes: 5436
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=pow(2,31)-1;

std::vector<int> v(1e6,0);
int N=1;
int sum(int i){
  int s=0;
  while(i){
    s+=v[i];
    i-=i&-i;
  }
  return s;
}
void add(int i,int a){
  while(i<=N){
    v[i]+=a;
    i+=i&-i;
  }
}

signed main(){
  int n,M;
  cin>>n>>M;
  while(n>N)N*=2;
  std::vector<int> ans;

  for(int i=0;i<M;i++){
    int t,l,r;cin>>t>>l>>r;
    if(t)ans.push_back(sum(r)-sum(l-1));
    else add(l,r);
  }
  for(int p:ans)cout<<p<<endl;
}



Measured memory_bytes: 11300
#include<bits/stdc++.h>
#define ll 				int
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define mod 			1000000007
#define siz 			105
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
  fastio;
	ll n,i,j;
	cin>>n;
	ll a[2],b[2],c[2],flag = 0;
	
	for(i = 0;i<n;i++)
	{
		cin>>a[flag]>>b[flag]>>c[flag];
		
		if(!i)
		{
			flag ^= 1;
			continue;
		}
		
		a[flag] += max(b[flag^1],c[flag^1]);
		
		b[flag] += max(a[flag^1],c[flag^1]);
		
		c[flag] += max(a[flag^1],b[flag^1]);
		
		flag ^= 1;
	}
	
	cout<<max(a[flag^1],max(b[flag^1],c[flag^1]))<<endl;
	
	
	
	
}

Measured memory_bytes: 256
KN = list(map(int, input().split()))
dis = list(map(int, input().split()))
lists = []
for i in range(KN[1]-1):
    lists.append(dis[i+1]-dis[i])

lists.append(KN[0]+dis[0]-dis[KN[1]-1])
print(KN[0]-max(lists))

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

#if 1
char query(string s) {
    cout << "? " << s << endl;
    char c;
    cin >> c;
    return c;
}

void answer(string s) {
    cout << "! " << s << endl;
}
#else
int ans = -1;
string ans_str;
char query(string s) {
    if (ans == -1) cin >> ans;
    // cerr << "query " << s << " " << atol(s.c_str()) << endl;
    ans_str = to_string(ans);
    bool b1 = atol(s.c_str()) <= ans,
        b2 = s <= ans_str;
    char ret = (b1 == b2 ? 'Y' : 'N');
    // cerr << "response " << ret << endl;
    return ret;
}

void answer(string s) {
    cerr << (s == ans_str ? "AC" : "WA")
         << " received answer " << s << ", expect " << ans_str << endl;
}
#endif

char binsearch(string &prefix, char min, char max, string &suffix) {
    char lb = min-1, ub = max;
    while (ub - lb > 1) {
        char c = (lb + ub) / 2;
        char ret = query(prefix + string(1, c) + suffix);
        if (ret == 'N') lb = c;
        else ub = c;
    }
    return ub;
}

int main() {
    string prefix(0, '0'), suffix(10, '9');
    for (int i = 0; i < 10; i++) {
        char c = binsearch(prefix, (i == 0 ? '1' : '0'), '9', suffix);
        prefix += c;
        suffix = suffix.substr(1);
    }
    prefix = prefix.substr(0, 10);
    int i = 9;
    for (;;) {
        if (prefix[i] != '0') { prefix[i]--; break; }
        else i--;
    }
    if (i > 0 || prefix[i] != '0') {
        while (query(prefix) == 'N') prefix.pop_back();
        prefix[i]++;
        answer(prefix);
    } else {
        // 100...0
        prefix[0] = '2';
        while (!prefix.empty() && query(prefix) == 'Y') prefix.pop_back();
        if (prefix.empty()) answer("1");
        else {
            prefix[0] = '1';
            answer(prefix + "0");
        }
    }
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int ketawa(int n){
  int sum = 0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  return sum;
}

int main() {
  int n;
  cin>>n;
  if(n%ketawa(n)==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


  return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N, M;
pair <int, int> arr[MAXN];
set <int> rem;
vector <int> v[MAXN];

multiset <int> rr;

void gogo (int x)
{
    if (rem.lower_bound(x) == rem.end()) return;
    rem.erase(rem.lower_bound(x));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i].first >> arr[i].second;
        v[arr[i].first].push_back(arr[i].second);
    }

    for (int i = 1; i <= M; i++)
    {
        rem.insert(i);
    }
    for (int i = 0; i <= M; i++)
    {
        for (int j : v[i])
        {
            rr.insert(j);
        }
        while ((int) rr.size() > i)
        {
            auto it = rr.begin();
            int x = *it;
            gogo (x);
            rr.erase(it);
        }
    }

    int ans = 0;
    for (int i = M; i >= 0; i--)
    {
        if ((int) rr.size() > i)
        {
            auto it = rr.begin();
            int x = *it;
            gogo (x);
            rr.erase(it);
        }

        ans = max (ans, (int) rr.size() + min (M - i, M - (int) rem.size()));
    }
    cout << N - ans << "\n";
}

Measured memory_bytes: 26100
a=int(input())
b=int(input())
c=int(input())
x=int(input())
num=0
for aa in range(a+1):
  for bb in range(b+1):
    for cc in range(c+1):
      total = 500*aa+ 100*bb+50*cc
#      print(aa,bb,cc,"total",total,"x",x)
      if total == x:
        num += 1
print(num)

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

public class Program
{
    class Node
    {
        public List<int> adjacents;
        public int inTime;
        public int outTime;
        public bool isVisited;
    }

    Node[] _graph;
    int _time;

    public static void Main()
    {
        new Program().Solve();
    }

    void Solve()
    {
        int n = int.Parse(Console.ReadLine());
        _graph = new Node[n];
        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int id = line[0] - 1;
            _graph[id] = new Node();
            _graph[id].adjacents = line.Skip(2).Select(x => x - 1).ToList();
        }
        _time = 1;
        for (int i = 0; i < n; i++)
        {
            if (!_graph[i].isVisited)
            {
                Dfs(i);
            }
        }
        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(string.Format("{0} {1} {2}", i + 1, _graph[i].inTime, _graph[i].outTime));
        }
    }

    void Dfs(int v)
    {
        var node = _graph[v];
        node.isVisited = true;
        node.inTime = _time++;
        foreach (int u in _graph[v].adjacents)
        {
            if (!_graph[u].isVisited)
            {
                Dfs(u);
            }
        }
        node.outTime = _time++;
    }
}



Measured memory_bytes: 9668
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long l,r;
    cin>>l>>r;
    r=min(r,l+2019);
    int ans=2018;
    for(long long i=l;i<=r;i++){
        for(long long j=i+1;j<=r;j++){
            int x = i*j%2019;
            ans=min(x,ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;

int main()
{
	long N,ma=0;
	vector<long> A,B;
	cin >> N;
	
	for (int i = 0; i < N; i++)
	{
		long T;
		cin >> T;
		A.push_back(T);
		B.push_back(T);
	}
	sort(B.begin(), B.end());
	for (int i = 0; i < N; i++)
	{
		if (A[i] == B.back()) { cout << B[N - 2] << endl; }
		else { cout << B.back() << endl; }
	}

}

Measured memory_bytes: 4964
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, m, s, c, ans = 0, memo[3] = {};
bool flag = false;

int main() {
	cin >> n >> m;
	ans = pow(10, n - 1);
	rep(i, 3)memo[i] = -1;
	rep(i, m) {
		cin >> s >> c;
		if ((memo[s - 1] != -1 && memo[s - 1] != c) || (s == 1 && c == 0 && n != 1)) {
			cout << -1 << endl;
			return 0;
		}
		if (!flag && memo[s - 1] == -1) {
			if (s == 1) {
				ans += (c - 1) * pow(10, n - 1);
				memo[0] = c;
			}
			else {
				ans += c * pow(10, n - s);
				memo[s - 1] = c;
			}
		}
		if (n == 1 && s == 1 && c == 0) {
			flag = true;
			ans = 0;
		}
	}
	if (m == 0 && n == 1) {
		cout << 0 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (c-b >= 0 || a-d >= 0) cout << 0 << endl;
    else {
        int mini = max(a, c);
        int maxi = min(b, d);
        cout << maxi-mini << endl;
    }
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;

int main()
{
	ll n,x,c=0;
	cin>>x;
	n = 100;
	while(1){
		if(n>=x) break;
		n = n + (n*1)/100;
		c++;
		}
	cout<<c<<nw;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n;
	cin >> n;
	vector<long long int>a(n+1);
	vector<long long int>b(n);
	for(int i = 0; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	long long int ans = 0;
	for(int i = n-1; i >= 0; --i){
		ans += min(a[i + 1], b[i]);
		b[i] -= min(a[i + 1], b[i]);
		ans += min(a[i], b[i]);
		a[i] -= min(a[i], b[i]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10;
set<int> s;
int a[N],n,k;
int vis[N];
int main() {
	rd(n),rd(k);
	for(int i=1;i<=n;++i) rd(a[i]);
	int ans=n-k+1,flg=0;
	int cnt=0;
	for(int i=1;i<k;++i) cnt+=a[i+1]>a[i];
	for(int i=1;i<=n-k+1;++i) {
		if(cnt==k-1) vis[i]=1,ans--,flg=1;
		cnt-=a[i+1]>a[i];
		cnt+=a[i+k]>a[i+k-1];
	}
	for(int i=1;i<=k;++i) s.insert(a[i]);
	for(int i=1;i<n-k+1;++i) {
		s.insert(a[i+k]);
		if(!vis[i]&&!vis[i+1]) {
			if((*s.begin())==a[i]&&(*s.rbegin())==a[i+k]) ans--;
		}
		s.erase(a[i]);
	}
	printf("%d",ans+flg);
	return 0;
}

Measured memory_bytes: 10368
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n = int(readline())
    memo = [1] * (n + 1)
    ans = 1
    for i in range(2, n + 1):
        memo[i] += 1
        for j in range(i * 2, n + 1, i):
            memo[j] += 1
        ans += memo[i] * i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 151536
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <tuple>

template <typename Weight>
struct edge {
  using value_type = Weight;
  size_t src, dst;
  value_type cost;

  edge(size_t src, size_t dst, value_type cost = 1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(edge<value_type> const& rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <typename Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  using value_type = Weight;
  graph(size_t n): std::vector<std::vector<edge<value_type>>>(n) {}

  void connect_to(size_t src, size_t dst, value_type cost = 1) {
    (*this)[src].emplace_back(src, dst, cost);
  }

  void connect_with(size_t src, size_t dst, value_type cost = 1) {
    connect_to(src, dst, cost);
    connect_to(dst, src, cost);
  }
};

template <class Tp>
std::array<std::vector<size_t>, 2> euler_tour(const graph<Tp>& g, size_t s = 0) {
  std::array<std::vector<size_t>, 2> res;
  res[0] = res[1] = std::vector<size_t>(g.size());
  size_t j = 0;
  std::function<void (size_t, size_t)> dfs = [&](size_t i, size_t pi) {
    res[0][i] = j++;
    for (const auto& e: g[i]) {
      if (e.dst == pi) continue;
      dfs(e.dst, i);
    }
    res[1][i] = j++;
  };
  dfs(s, -1);
  return res;
}

int main() {
  size_t N, Q;
  scanf("%zu %zu", &N, &Q);

  graph<int> g(N);
  for (size_t i = 1; i < N; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.connect_with(a, b);
  }

  auto et = euler_tour(g);

  std::vector<intmax_t> a(N+N+1);
  for (size_t i = 0; i < Q; ++i) {
    size_t p;
    intmax_t x;
    scanf("%zu %jd", &p, &x);
    --p;
    a[et[0][p]] += x;
    a[et[1][p]+1] -= x;
  }
  for (size_t i = 1; i <= N+N; ++i)
    a[i] += a[i-1];

  for (size_t i = 0; i < N; ++i)
    printf("%jd%c", a[et[0][i]], i+1<N? ' ': '\n');
}


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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  vector<char> data(s.size());
  for (int i=0; i<s.size(); i++) {
    data.at(i) = s.at(i);
  }

  for (int i=0; i<a; i++) {
    if(isdigit(data.at(i)) != true) {
      cout << "No" << endl;
      goto SKIP;
    }
  }

  if(data.at(a) != '-') {
    cout << "No" << endl;
    goto SKIP;
  }

  for (int i=0; i<b; i++) {
    if(isdigit(data.at(i+a+1)) != true) {
      cout << "No" << endl;
      goto SKIP;
    }
  }

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

Measured memory_bytes: 3580
def comb(n, k):
    x = y = 1
    for i in range(k):
        x *= n-i
        y *= i+1
    return x//y

N, A, B = list(map(int, input().split()))
V = sorted(list(map(int, input().split())), reverse=True)

if V[0]==V[A-1]:
    n = 0
    for v in V:
        if v!=V[0]: break
        n += 1

    ans = 0
    for k in range(A, min(B,n)+1):
        ans += comb(n, k)

else:
    n = k = 0
    for i,v in enumerate(V):
        if v==V[A-1]:
            if i<A: k += 1
            n += 1
    ans = comb(n,k)

print(sum(V[:A])/A)
print(ans)

Measured memory_bytes: 3064
#include <iostream>

#define N_MAX 100000
#define M_MAX 100000

int main() {
    int n, m, N, M;
    int A, B, better, worse, counter = 0;
    long H[N_MAX], H_best[N_MAX] = {0}, H_better;
    
    std::cin >> N >> M;
    
    for(n = 0; n < N; n++) {
        std::cin >> H[n];
    }
    
    for(m = 0; m < M; m++) {
        std::cin >> A >> B;
        
        if(H[A - 1] == H[B - 1]) {
            H_best[A - 1] = H[B - 1];
            H_best[B - 1] = H[A - 1];
        } else {
            if(H[A - 1] > H[B - 1]) {
                better = A - 1;
                worse = B - 1;
            } else {
                better = B - 1;
                worse = A - 1;
            }
            H_better = H[better];
            
            if(H_better > H_best[worse]) {
                H_best[worse] = H_better;
            }
        }
        
    }
    
    for(n = 0; n < N; n++) {
        if(H[n] > H_best[n]) {
            counter += 1;
        }
    }
    
    std::cout << counter << std::endl;
    
    return 0;
}


Measured memory_bytes: 5148
#include <iostream>

using namespace std;

int main(int argc, char** argv){
  int X;
  cin >> X;
  
  if( X == 3 || X == 5 || X == 7 ){
    cout << "YES" <<endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
ans=0
for i in range(n-2):
  if arr[i]==i+1:
    arr[i],arr[i+1]=arr[i+1],arr[i]
    ans+=1
  elif arr[i+1]==i+1:
    arr[i+1],arr[i+2]=arr[i+2],arr[i+1]
if arr[-1]==n or arr[-2]==n-1:
  ans+=1
print(ans)


Measured memory_bytes: 14008
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int a, b;
	char s[12];
	bool isok = true;
	scanf("%d%d%s", &a, &b, s);
	if (strlen(s) != a + b + 1)isok = false;
	else rep(i, a + b + 1) {
		if (i == a) {
			if (s[i] != '-')isok = false;
		}
		else {
			if (!(s[i] >= '0' && s[i] <= '9'))isok = false;
		}
	}
	printyn(isok);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>

int check_intersection(const double xa, const double ya, const double ra,
                       const double xb, const double yb, const double rb)
{
    double distance = (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb);
    if(distance < (ra - rb) * (ra - rb)){
        if(ra > rb){
            return 2;
        }
        else{
            return -2;
        }
    }
    else if(distance > (ra + rb) * (ra + rb)){
        return 0;
    }
    else{
        return 1;
    }
}

int main ()
{
    double xa, ya, ra, xb, yb, rb;
    u_int N;
    
    std::cin >> N;
    for(u_int i = 0; i < N; ++i){
        std::cin >> xa >> ya >> ra >> xb >> yb >> rb;
        std::cout << check_intersection(xa, ya, ra, xb, yb, rb) << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K,S;
  cin >> K>>S;
  int c=0;
  for (int i=0;i<K+1;i++){
    for(int j=0;j<K+1;j++){
      if(S-i-j<K+1 && S-j-i>-1)c++;
    }
  }
  cout <<c<<endl;
  

}  


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

C = [0]*N
for i in range(1, N):
    C[i] += C[i-1]
    if(S[i-1:i+1] == 'AC'):
        C[i] += 1

for i in range(Q):
    l, r = map(int, input().split())
    print(C[r-1]-C[l-1])


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

int main(){
    int n;
    cin >> n;
    while( n-- > 0 ){
        int out = 0, score = 0, base = 0;
        string event;
        while( out < 3 ){
            cin >> event;
            if( event == "OUT" ) out++;
            else if( event == "HIT" ){
                score += base/3;
                if( !(base/3) ) base++;
            }else if( event == "HOMERUN" ){
                score += base+1;
                base = 0;
            }
        }
        cout << score << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

int main(void)
{
    int a,i,count = 0;
    scanf("%d",&a);
    int c[a],d[a];
    for (i = 0; i < a; i++) {
        scanf("%d%d",&c[i],&d[i]);
    }
    for (i = 0; i < a; i++) {
        count = d[i] - c[i] + 1 + count;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<cstdio>
#include<set>
using namespace std;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  set<int> s1;
  set<int> s2;
  for (int i=0 ; i<M ; i++) {
    int start, end;
    scanf("%d%d", &start, &end);
    if (start == 1) s1.insert(end);
    if (end == N) s2.insert(start);
  }
  for(auto itr = s1.begin(); itr != s1.end(); ++itr) {
    if (s2.find(*itr) != s2.end()) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 9600
#include <cstdio>
#include <cstdint>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <utility>
#include <math.h>
#include <stack>

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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const long long mod = 1e9+7;

void chmod(long long &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

long long modpow(long long x, long long n){
    if(n==0) return 1;
    long long res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };



/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int main() {
    char str[20200];
    scanf("%s", str);
    
    std::stack<int> st1;
    std::stack<std::pair<int, int>> st2;

    int sum = 0;
    
    int i=0;
    while(true) {
        if(str[i] == '\0') { break; }
        char ch = str[i];

        if(ch == '\\') {
            st1.push(i);
        }
        else if(ch == '/' && st1.size()>0) {
            int j = st1.top();
            st1.pop();
            sum += i-j;
            int a = i-j;
            while(st2.size()>0 && st2.top().first > j){
                a += st2.top().second;
                st2.pop();
            }
            st2.push(std::make_pair(j, a));
        }

        i++;
    }

    std::vector<int> ans;
    while(st2.size()>0) { ans.push_back(st2.top().second); st2.pop(); }
    std::reverse(ans.begin(), ans.end());
    printf("%d\n", sum);
    printf("%d", (int)ans.size());
    for(int i=0; i<ans.size(); ++i){
        printf(" %d", ans.at(i));
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 3360
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d,k,ans;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
    if((a*60+b)<(c*60+d)){
        ans=((c*60+d)-(a*60+b));
    }
    else{
        ans=24*60-((a*60+b)-(c*60+d));
    }
    printf("%d\n",ans-k);
}


Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include<queue>
#define INF 1000000009;
#define inl long long
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}
int main() {
	int a = 0, b = 0;
	cin >> a >> b;
	for (int i = b-a+1; i < b+a; i++) {
		if (i != b + a - 1) {
			cout << i << ' ';
		}
		else {
			cout << i;
		}
	}
	cout << endl;
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <bits/stl_numeric.h>
#include <queue>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

static const int MAX = 510000;

int main() {
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;

    vector <int> p(a);
    vector <int> q(b);
    vector <int> r(c);

    REP(i,a)cin >> p[i];
    REP(i,b)cin >> q[i];
    REP(i,c)cin >> r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());

    //x個の赤いリンゴ y個の緑のリンゴ
    //x+yの総和
    //無色がc個あるから上手に振り分ける

    priority_queue<int, vector<int>, greater<int> > red;
    priority_queue<int, vector<int>, greater<int> > blue;
    REP(i,x)
    {
        red.push(p[i]);
    }
    REP(i,y)
    {
        blue.push(q[i]);
    }

    REP(i, c)
    {
        int red_t,blue_t;
        red_t = red.top();
        blue_t = blue.top();

        if(red_t <= blue_t && red_t < r[i])
        {
            red.pop();
            red.push(r[i]);
        }
        else if(blue_t < red_t && blue_t < r[i])
        {
            blue.pop();
            blue.push(r[i]);
        }
        else
        {
            break;
        }
    }

    ll res = 0;
    while(!red.empty())
    {
        int tmp = red.top();
        //cout << tmp << endl;
        res += tmp;
        red.pop();
    }

    while(!blue.empty())
    {
        int tmp = blue.top();
        //cout << tmp << endl;
        res += tmp;
        blue.pop();
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2552
#include <stdio.h>

#define STRING_LENGTH 10
#define ARRAY_SIZE (STRING_LENGTH + 1)

void solve(char s[ARRAY_SIZE]);


int main()
{
  char s[ARRAY_SIZE];

  scanf("%s", &s);
  solve(s);

  return 0;
}

void solve(char s[ARRAY_SIZE])
{
  s[0] = '2';
  s[1] = '0';
  s[2] = '1';
  s[3] = '8';

  printf("%s\n", s);
}


Measured memory_bytes: 128