akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> as(N + 1), bs(N);
  F0R(i, N + 1) {
    cin >> as[i];
  }
  i64 result = 0;
  F0R(i, N) {
    int b, c = 0;
    cin >> b;
    c = min(b, as[i]);
    as[i] -= c;
    b -= c;
    result += c;
    c = min(b, as[i + 1]);
    as[i + 1] -= c;
    result += c;

  }
  cout << result;
}
#endif


Measured memory_bytes: 3888
program gluttony
    implicit none
    integer(8):: n,i
    integer(8), allocatable:: a(:), f(:)
    integer(8):: k, ans

    read*, n, k
    allocate(a(n), f(n))
    read*, a(:)
    read*, f(:)
    call merge_sort(a(:), 1_8, n)
    call merge_sort(f(:), 1_8, n)
    f(:) = [(f(i), i=n,1_8,-1_8)]

    ! if (sum(a(:)) <= k)then
    !     print*, 0
    !     stop
    ! end if
    ! print*, a(:)
    ! print*, f(:)
    block
        integer(8):: l=-1, r=1000000000000_8, c
        do while(l+1_8 < r)
            ans = 0_8
            c = (l+r)/2_8
            do i=1_8, n
                ans = ans + max(0_8, a(i) - c/f(i))
            end do
            if (ans <= k) then
                r = c
            else
                l = c
            end if
        end do
        print*, r
    end block

    contains
    recursive subroutine merge_sort(ar,start,end)
        integer(8):: ar(:), start, end

        if (end-start < 2_8) then
            if (ar(start) > ar(end)) then
            block; integer(8):: tmp
                tmp = ar(start)
                ar(start) = ar(end)
                ar(end) = tmp
            end block; end if
            return
        end if

        block
            integer(8):: c
            c = (start+end)/2_8
            call merge_sort(ar(:), start, c)
            call merge_sort(ar(:), c+1_8, end)
            call merge(ar(:), start, c, end)
        end block
    end subroutine

    subroutine merge(ar, start, c, end)
        integer(8):: ar(:), start, c, end
        integer(8),pointer:: tmp(:)
        allocate(tmp(end-start+1))

        block
            integer(8):: l,r,ti
            l=start
            r=c+1_8
            ti=1_8
            do while(l <= c .and. r <= end)
                if (ar(l) <= ar(r)) then
                    tmp(ti) = ar(l)
                    l=l+1_8
                else
                    tmp(ti) = ar(r)
                    r=r+1_8
                end if
                ti=ti+1_8
            end do

            if (r > end) then
                tmp(ti:) = ar(l:c)
            else
                tmp(ti:) = ar(r:end)
            end if
        end block

        ar(start:end) = tmp(:)
        deallocate(tmp)
    end subroutine
end program gluttony

Measured memory_bytes: 6180
#include <iostream>
using namespace std;
int calc(int);

int main(){
    int a;
    int b;
    while(cin>>a>>b){
        cout << calc(a+b) <<"\n";
    }
	
    return 0;
}

int calc(int value){
    int count = 1;
    while((value /= 10) != 0){
        count++;
    }
    return count;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
	int c, r, x[101][101] = {}, i, j;
	scanf("%d %d", &c, &r);
	for(i=0; i<c; i++){
		for(j=0; j<r; j++){
			scanf("%d", &x[i][j]);
			x[i][r] += x[i][j];
		}
	}
	for(i=0;i<=r;i++){
		for(j=0;j<c;j++){
			x[c][i] += x[j][i];
		}
	}
	for(i=0;i<=c;i++){
		for(j=0;j<=r;j++){
			printf("%d", x[i][j]);
			if(j != r){
				printf(" ");
			}
		}
		printf("\n");
	}
}


Measured memory_bytes: 2144
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()

print("ABC{}".format(N))

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

int absolute_value(int n){
  if(n >= 0) return n;
  if(n < 0) return -n;
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> student(N, vector<int>(2));
  vector<vector<int>> check_point(M, vector<int>(2));
  rep(i, N){
    cin >> student[i][0] >> student[i][1];
  }
  rep(i, M){
    cin >> check_point[i][0] >>check_point[i][1];
  }
  
  rep(i, N){       
    int P = 1;
    int min_d = absolute_value(student[i][0]-check_point[0][0]) + absolute_value(student[i][1]-check_point[0][1]);
    rep(j, M){          
      int d;
      d = absolute_value(student[i][0]-check_point[j][0]) + absolute_value(student[i][1]-check_point[j][1]);
      if(d < min_d){
        min_d = d;
        P = j+1;
      }
    }
    cout << P << endl;
  }
}
      
  

Measured memory_bytes: 256
antenna = [int(input()) for _ in range(5)]
k = int(input())

#%%
import itertools

flag = True
for v1, v2 in itertools.combinations(antenna, 2):
    if abs(v1 - v2) > k:
        flag = False
        break

if flag:
    print('Yay!')
else:
    print(':(')




Measured memory_bytes: 38512
r,c=map(int,input().split())
N=[list(map(int,input().split())) for i in range(r)]
retu=[[0 for i in range(1)] for j in range(1)] 
for j in range(c):
  ret=0
  for i in range(r):
    ret+=N[i][j]
  if j==0:
    retu[0][0]+=ret
  else:
    retu[0].append(ret)
N.extend(retu)
for i in range(r+1):
  tuika=0
  for j in range(c):
    tuika+=N[i][j]
  N[i].append(tuika)
  
for i in range(r+1):
  for j in range(c+1):
    if j==0:
      print(N[i][j],end="")
    else:
      print("",N[i][j],end="")
  print("")


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> color(9,0);
    rep(i, n) {
        cin >> a[i];
        if(a[i]/400 > 7) {
            color[8]++;
        } else {
            color[a[i]/400]++;
        }
    }
    int ans = 0;
    rep(i, 8) if(color[i] > 0) ans++;
    int minans = max(ans, 1);
    int maxans = ans + color[8];

    cout << minans << endl;
    cout << maxans << endl;

    return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)

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

    string s;
    cin >> s;
    //cout << s <<"\n";
    
    int num0 = count(s.begin(), s.end(), '0');
    int num1 = count(s.begin(), s.end(), '1');
    
    int ans = 2 * min(num0, num1);
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}

signed main() {
	int n;
	cin >> n;
	P a[200005];
	rep(i, n) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a, a + n);
	int now = 0;
	rep(i, n) {
		now += a[i].second;
		if (now > a[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 3328
S = str(input())

if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
    print(3)
elif S[0] == 'R' and S[1] == 'R' and S[2] == 'S':
    print(2)
elif S[0] == 'R' and S[1] == 'S' and S[2] == 'R':
    print(1)
elif S[0] == 'R' and S[1] == 'S' and S[2] == 'S':
    print(1)
elif S[0] == 'S' and S[1] == 'R' and S[2] == 'R':
    print(2)
elif S[0] == 'S' and S[1] == 'R' and S[2] == 'S':
    print(1)
elif S[0] == 'S' and S[1] == 'S' and S[2] == 'R':
    print(1)
elif S[0] == 'S' and S[1] == 'S' and S[2] == 'S':
    print(0)

Measured memory_bytes: 61784
program main
  implicit none
  integer :: a, b, k, i, j = 0
  
  read *, a, b, k

  do i = min(a, b), 1, -1
    j = j + 1
    if (mod(a, i) + mod(b, i) > 0) then
      j = j - 1
    end if
    if (j == k) then
      print '(i0)', i
      exit
    end if
  end do

end

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

int h, w, m, x, y, rcnt[300005], ccnt[300005];
vector<int> rmax, cmax, targets[300005];
typedef pair<int, int> ii;
vector<ii> rpr, cpr;

int main(){
    scanf("%d%d%d", &h, &w, &m);
    for (int i = 0; i < m; ++i){
        scanf("%d%d", &x, &y);
        ++rcnt[x]; ++ccnt[y];
        targets[x].push_back(y);
    }
    for (int i = 1; i <= h; ++i){
        rpr.push_back(ii(rcnt[i], i));
    }
    for (int i = 1; i <= w; ++i){
        cpr.push_back(ii(ccnt[i], i));
    }
    sort(rpr.begin(), rpr.end(), greater<ii>());
    sort(cpr.begin(), cpr.end(), greater<ii>());
    int maxr = rpr[0].first, maxc = cpr[0].first;
    for (int i = 0; i < h; ++i){
        if (rpr[i].first == maxr){
            rmax.push_back(rpr[i].second);
        }
        else break;
    }
    for (int i = 0; i < w; ++i){
        if (cpr[i].first == maxc){
            cmax.push_back(cpr[i].second);
        }
        else break;
    }
    for (int i = 0; i < rmax.size(); ++i){
        int _r = rmax[i];
        sort(targets[_r].begin(), targets[_r].end());
        for (int j = 0; j < cmax.size(); ++j){
            int _c = cmax[j];
            //printf("%d\n", _c);
            int pos = lower_bound(targets[_r].begin(), targets[_r].end(), _c) - targets[_r].begin();
            //printf("%d %d %d\n", pos, targets[_r][pos], _c);
            if (pos >= targets[_r].size() || _c != targets[_r][pos]){
                printf("%d", maxr + maxc);
                return 0;
            }
        }
    }
    printf("%d", maxr + maxc - 1);
    return 0;
}


Measured memory_bytes: 31116
def ifTriangle(v):
    largest = max(v)
    smallers_sum = 0
    for x in v:
        if not x == largest:
            smallers_sum += x
    if smallers_sum > largest:
        return True
    return False


N = int(input())
L = [int(x) for x in input().split()]
L.sort()
L.reverse()

count = 0
before_i = -1
before_j = -1
before_k = -1
for i in range(N-2):
    for j in range(i+1, N-1):
        if L[j] == L[i]:
            continue
        if L[i]/2 >= L[j]:
            break
        for k in range(j+1, N):
            if L[k] == L[j]:
                continue
            if ifTriangle([L[i], L[j], L[k]]):
                count += 1
print(count)


Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b)/2<<endl;
}

Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
rows = [input() for _ in range(N)]

sets = set(rows)

print(len(sets))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 35632
n,m,c = map(int,input().split())
seisu = list(map(int,input().split()))
count = 0
for i in range(n):
  source = list(map(int,input().split()))
  a = 0
  for j in range(m):
    a = a + source[j]*seisu[j]
  if a+c >= 1:
    count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
	char ch = getchar(); int f = 0; x = 0;
	while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 +10;
int n, k, a[N], lg[N], c[N];
signed main() {
    read (n), read (k);
    for (int i = 1; i <= n; ++i) read (a[i]);
    for (int i = 1; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
    int mx = lg[n] * 3;
    if (k >= mx) {
        for (int i = 1; i <= n; ++i) printf ("%d ", n); puts ("");
        return 0;
    }
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= n; ++j) c[j] = 0;
        for (int j = 1; j <= n; ++j) {
            ++c[max (j - a[j], 1)], --c[j + a[j] + 1];
        } int s = 0;
        for (int j = 1; j <= n; ++j) {
            s += c[j]; a[j] = s;
        }
    } for (int i = 1; i <= n; ++i) printf ("%d ", a[i]); puts ("");
    return 0;
}


Measured memory_bytes: 6000
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int x;

    cin >> x;

    if (x < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }

    return 0;
}

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

int main(){

  int n;
  int v[22], c[22];
  int x = 0, y = 0;

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

  for(int i=0;i<n;i++){
    if(v[i] > c[i]){
      x += v[i];
      y += c[i];
    }
  }

  cout << x - y << endl;
}


Measured memory_bytes: 256
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c+1]) or int(lista[c-1]) < int(lista[c]) < int(lista[c+1]):
        k += 1

print(k)

Measured memory_bytes: 2940
from collections import Counter


MOD = 10 ** 9 + 7
S = input()
N = len(S)

cnt = Counter()

for s in S:
    if s == 'B':
        cnt['?B'] += cnt['?']
        cnt['AB'] += cnt['A']
    elif s == 'C':
        cnt['ABC'] += cnt['AB']
        cnt['A?C'] += cnt['A?']
        cnt['?BC'] += cnt['?B']
        cnt['??C'] += cnt['??']
    elif s == '?':
        for t in ['??', 'A?', '?B', 'AB']:
            cnt[t + '?'] += cnt[t]
        for t in ['A', '?']:
            cnt[t + '?'] += cnt[t]
    cnt[s] += 1

q = cnt['?']
ans = 0
for key in [x for x in list(cnt.keys()) if len(x) == 3]:
    if cnt[key]:
        ans += cnt[key] * pow(3, q - key.count('?'), MOD)
        ans %= MOD

print(ans)


Measured memory_bytes: 42732
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define pi acos(-1)
#define pb push_back
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
 
int water[3010],sugar[3010];
 
int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    int A,B,C,D,E,F;
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    for(int i=0; i<=300; i++)
        for(int j=0; j<=300; j++) {
            if(100*i*A+100*j*B>F) continue;
            water[100*i*A+100*j*B]=1;
//            printf("%d\n",100*i*A+100*j*B);
        }
 
    for(int i=0; i<=3000; i++)
        for(int j=0; j<=3000; j++) {
            if(i*C+j*D>F) continue;
            sugar[i*C+j*D]=1;
//            printf("%d\n",i*C+j*D);
        }
    double ans=0;
    int sum1=0,sum2=0;
    for(int i=0; i<=3000; i++) {
        if(water[i]) {
            for(int j=0; j<=3000; j++) {
                if(i+j>F) break;
                if(!sugar[j]) continue;
                if(((double)(j)/(double)(i))>((double)(E)/(double)(100))) break;
                double sum=(100.0*j)/(double)(i+j);
//                printf("%d %d \n",i,j);
                if(sum>=ans) {
                    ans=sum;
                    sum1=i;
                    sum2=j;
                }
            }
        }
    }
    printf("%d %d\n",sum1+sum2,sum2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ld long double
using namespace std;
int32_t main()
{
    IOS;
    string s,t;
    cin>>s>>t;
    int l=s.length(),c=0;
    for(int i=0;i<l;i++)
    {
    	if(s[i]!=t[i])
    		c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 3848
#include <stdio.h>
int main(void)
{
  int i=0;
  int a[100000]={0};
  int f;

  while(1) {
	scanf("%d",&a[i]);

	if (a[i]==0)
	  break;
	i++;
  }

  f=i;

  for (i=0; i<f; i++) {
	printf("Case %d: %d\n",i+1,a[i]);
  }

  return 0;
}

Measured memory_bytes: 996
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
ans=[]
for i,a in enumerate(A):
    ans+=[str(i+1)]*a
for h in range(H):
    if h%2==0:
        print(" ".join(ans[h*W:(h+1)*W]))
    else:
        print(" ".join(ans[h*W:(h+1)*W][::-1]))

Measured memory_bytes: 3700
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    A = {}
    for i in range(n):
        k = II()
        if not k in A:
            A[k] = 1
        else:
            A[k] += 1
    ans = 0
    #print(A)
    for item in A.values():
        ans += item % 2
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


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

int main() {
  string s;
  int c = 0;
  cin >> s;
  for(int i = 0;i < s.size()/2;i++){
    char t = s.at(i);
    char e = s.at(s.size()-1-i);
    if(t != e){
      c++;
    }
  }
  cout << c << endl;
}


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

using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> mp(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int k = 0; k < n; k++) {
            if (s[k] == '1') {
                mp[i].emplace_back(k);
            }
        }
    }
    int ans = -1;
    for (int i = 0; i < n; i++) {
        int mx = 1;
        vector<int> num(n, -1);
        num[i] = 1;
        queue<int> q;
        q.emplace(i);
        while (!q.empty()) {
            int front = q.front();
            q.pop();
            int new_val = num[front] + 1;
            for (auto e: mp[front]) {
                int diff = new_val - num[e];
                if (num[e] < 0) {
                    num[e] = new_val;
                    q.emplace(e);
                    mx = max(mx, new_val);
                } else if (num[e] > 0 && diff != 0 && diff != 2) {
                    mx = -1;
                    queue<int>().swap(q);
                    break;
                }
            }
        }
        ans = max(ans, mx);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.math.*;

class Main {
  public static void main (String[] args) {
    Scanner scan_ = new Scanner(System.in);
   int h_ = 0;
   int w_ = 0;

   while(scan_.hasNext()) {
      h_ = scan_.nextInt();
      w_ = scan_.nextInt();

      if(h_ != 0 | w_!=0) {
        for( int i = 0; i < h_ ; i++) {
          if(i== 0 | i== h_-1){
            for(int n = 0; n < w_ ; n++) {
              System.out.print("#");
            }
           System.out.println();
          }else{
           for(int n = 0; n < w_ ; n++) {
             if(n == 0 | n == w_ -1){
               System.out.print("#");
             }else{
              System.out.print(".");
             }
           }
            System.out.println();
          }
       
       }
       
       System.out.println();
      }
   }
  }
}


Measured memory_bytes: 35176
use std::io::*;
use std::str::*;

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

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    if (a * b) % 2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}

Measured memory_bytes: 4352
// ABC 81 B

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

typedef long long ll;

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; }
const long long INF = 1LL<<60;

int main()
{
  int n;
  cin >> n;
  int ans = 999;
  rep(i, n) {
    int count = 0;
    int a;
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      count++;
    }
    chmin(ans, count);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, queue
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None
N, M =LI()
AB = []
for i in range(N):
    AB.append(LI())
#  AB.sort(key=lambda x: x[0])
#  perr(AB)
AB_dict = {}
for ab in AB:
    if ab[0] not in AB_dict.keys():
        AB_dict[ab[0]] = [ab[1]]
    else:
        AB_dict[ab[0]].append(ab[1])
#  for k in AB_dict.keys():
#      AB_dict[k] = collections.Counter(AB_dict[k])
#  for k in AB_dict.keys():
#      AB_dict[k].sort()
perr(AB_dict)

#  tmp = []
#  day = 1
#  ans = 0
#  crr = 0
#  while True:
#      if day == M + 1:
#          break

#      if crr < N:
#          if AB[crr][0] > day:
#              perr('nextday')
#              perr(tmp)
#              day += 1
#              if len(tmp) == 0:
#                  continue
#              tmp.sort()
#              ans += tmp.pop()
#          else:
#              perr('add')
#              tmp.append(AB[crr][1])
#              crr += 1
#      else:
#          if len(tmp) == 0:
#              break
#          tmp.sort()
#          for time in range(M-day+1):
#              ans += tmp.pop()
#              day += 1
        
#  print(ans)
#  ans = 0
#  tmp = []
#  crr = 0
#  for i in range(1, M+1):
#      if crr < N:
#          if AB[crr][0] == i:
#              while True:
#                  if crr == N:
#                      break
#                  if AB[crr][0] != i:
#                      break
#                  tmp.append(AB[crr][1])
#                  crr += 1

#      perr('tmp')
#      perr(tmp)
#      if len(tmp) == 0:
#          continue

#      max_v = max(tmp)
#      ans += max_v
#      tmp.remove(max_v)
#      #  tmp.sort()
#      #  ans+=tmp.pop()

#  """
#  貪欲か？
#  日が長くて報酬の高いものから選んでいく
#  そうすると
#  10 1
#  9 10
#  みたいなときに10 1のほうから選んでしまうからだめ
#  残り日数を意識
#  残ってる中で最も報酬の高いものから？
#  2 10
#  1 11
#  のパターンで、先に1をやってしまうためだめ
#  2 10
#  1 11
#  1 15
#  のパターンで、1 1をやるのが正解
#  """

ans = 0
tmp = queue.PriorityQueue()
keys = AB_dict.keys()
for i in range(1, M+1):
    # 残りi日
    if i in keys:
        for ab in AB_dict[i]:
            tmp.put((-ab, ab))
        #  tmp[len(tmp):] = AB_dict[i]
    perr('tmp')
    perr(tmp)
    if tmp.empty():
        continue
    #  tmp.sort()
    #  max_v = max(tmp)
    #  ans += max_v
    ans += tmp.get()[1]
print(ans)


Measured memory_bytes: 42176
n = int(input())

l = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
    if i == 0:
        continue
    u = list(map(int, input().split()))
    for x in u[2:]:
        l[i][x] = 1

for i in range(n + 1):
    if i == 0:
        continue
    print(*l[i][1:])

Measured memory_bytes: 8480
N = int(input())
line = input().split()
H = [0]*N
for i in range(N):
    H[i] = int(line[i])

maxCount = 0
count = 0
before = 0
for i in range(N):
    if before >= H[i]:
        count += 1
        if maxCount < count:
            maxCount = count
    else:
        count = 0
    before = H[i]

print(maxCount)

Measured memory_bytes: 14096
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = sr()
    N = len(S)
    a = [0]*2019
    a[0] += 1
    t = 0
    r = 1
    for s in reversed(S):
        t += int(s)*r
        t %= 2019
        r *= 10
        r %= 2019
        a[t] += 1
    ans = 0
    for i in range(2019):
        ans += a[i]*(a[i]-1)//2
    print(ans)
resolve()

Measured memory_bytes: 68276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<ll> ans;
    for(int i=n-1;i>=0;i--){
        if(a[i]==a[i-1]){
            ans.push_back(a[i]);
            i--;
        }
        if(ans.size()==2){
            break;
        }
    }
    if(ans.size()==0||ans.size()==1){
        cout<<"0"<<endl;
        return 0;
    }
    if(ans.size()==2){
        cout<<ans[0]*ans[1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<set>
#include<fstream>
#include<map>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
int a[214514];
int n;
int solve(int mi) {
	int ans = 0;
	rep(i, n)ans += abs(a[i] - mi);
	return ans;
}

signed main() {
	 cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)a[i] -= i + 1;
	sort(a, a + n);
	int mi, ans;
	if (n & 1) {
		cout << solve(a[n / 2]) << endl;
	}
	else {
		cout << max(solve(a[n / 2]), solve(a[n / 2 - 1])) << endl;
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
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;
}

const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
const ll HMOD = (ll)4222234727;
const ll hashprime = (ll)31;
 
const int maxn = 200005;


int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll k,x; cin >> k >> x;
    if(1LL * 500 * k >= x){
        cout << "Yes" << '\n';
    }else cout << "No" << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

ll dp[100001][13];

void solve(string S){
	rep(i, 13) {
		dp[0][i] = 0;
	}
	dp[0][0] = 1;
	rep(i, S.length()) {
		rep(j, 13) {
			if (S[i] == '?') {
				rep(e, 10) {
					dp[i+1][(j*10+e)%13] = (dp[i+1][(j*10+e)%13]+dp[i][j])%mod;
				}
			} else {
				ll d = S[i] - '0';
				dp[i+1][(j*10+d)%13] = dp[i][j]%mod;
			}
		}
	}
	cout << dp[S.length()][5] << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



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

const int N=1000005;
int a[N],b[3],c[3],p[3],q[3],n,x,y;
char s[N];

int main(){
	scanf("%s",s+1);
	for(int i=1;s[i];i++)
		if(s[i]!=s[i-1])a[++n]=s[i]-'A',b[a[n]]++;
	rep(i,0,2)p[i]=i;
	sort(p,p+3,[&](int x,int y){return b[x]<b[y];});
	if(!b[p[0]])return 0;
	rep(i,0,2)q[p[i]]=i;
	rep(i,1,n)a[i]=q[a[i]],c[a[i]]++;
	for(int l=1,r;l<=n;l++)
		if(a[l]){
			r=l;
			while(r<n&&a[r+1])r++;
			if(1<l&&r<n&&l==r&&a[l]==2)y++;
			else{
				if(l<r||l==r&&a[l]==1)x++;
				if(a[l]==2&&c[2]>c[1])a[l]=-1,c[2]--;
				if(a[r]==2&&c[2]>c[1])a[r]=-1,c[2]--;
			}
			l=r;
		}
	int t=max(0,y-x);
	for(int i=2;i<=n-1&&t;i++)
		if(!a[i-1]&&!a[i+1]&&a[i]==2)
			a[i]=a[i-1]=-1,c[0]--,c[2]--,t--;
	int nn=0;
	rep(i,1,n)
		if(a[i]>=0)a[++nn]=a[i];
	n=nn;
	assert(c[1]==c[2]);
	for(int l=1,r;l<=n;l++)
		if(a[l]){
			r=l;
			while(r<n&&a[r+1])r++;
			int t=min((l==1||r==n?(r-l+1)/2:(r-l)/2),c[1]-c[0]);
			for(int i=l;t;i+=2)
				a[i]=a[i+1]=-1,c[1]--,t--;
			l=r;
		}
	rep(i,1,n)if(a[i]!=-1)putchar('A'+p[a[i]]);
	puts("");
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define MAX 200010
using namespace std;

int arr[MAX];

int main(void)
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> arr[i];
	sort(arr, arr + N);
	for (int i = 1; i < N; i++)
	{
		if (arr[i - 1] == arr[i])
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, '%d', $N);

$nums = array();
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%d', $n);
    $nums[] = $n;
}

list($m, $G, $cnt, $nums) = shellSort($nums, $N);

echo "$m\n";
echo join(' ', $G)."\n";
echo "$cnt\n";
foreach ($nums as $num) {
    echo "$num\n";
}

function insertionSort($A, $n, $g, &$cnt)
{
    for ($i = $g; $i < $n; $i++) {
        $val = $A[$i];
        $j = $i - $g;

        while ($j >= 0 && $A[$j] > $val) {
            $A[$j+$g] = $A[$j];
            $j -= $g;
            $cnt++;
        }
        $A[$j+$g] = $val;
    }

    return $A;
}


function shellSort($A, $n)
{
    // h_{i+1} = 3 h_{i} + 1 ( 1 <= $h <= $n )
    $G = array();
    for ($h = 1; $h <= $n; $h = 3*$h+1) {
        $G[] = $h;
    }
    $G = array_reverse($G);

    $cnt = 0;
    foreach ($G as $g) {
        $A = insertionSort($A, $n, $g, $cnt);
    }

    return array(count($G), $G, $cnt, $A);
}

Measured memory_bytes: 336644
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const ll MAX = 1e5 + 5;

int main(void)
{
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	ll p[a], q[b], r[c];
	for(int i = 0; i < a; i++)
		cin >> p[i];

	for(int i = 0; i < b; i++)
		cin >> q[i];

	for(int i = 0; i < c; i++)
		cin >> r[i];

	sort(p, p + a);
	sort(q, q + b);
	sort(r, r + c);

	stack <ll> s1, s2, s3;
	for(int i = 0; i < c; i++)
		s3.push(r[i]);

	ll sum = 0;
	for(int i = a - 1; i > a - 1 - x; i--)
	{
		sum += p[i];
		s1.push(p[i]);
	}

	for(int i = b - 1; i > b - 1 - y; i--)
	{
		sum += q[i];
		s2.push(q[i]);
	}

	while(!s3.empty())
	{
		if(!s1.empty() && !s2.empty())
		{
			if(s1.top() < s3.top() && s2.top() < s3.top())
			{
				ll mn = min(s1.top(), s2.top());
				if(mn == s1.top())
				{
					sum -= s1.top();
					sum += s3.top();
					s1.pop();	s3.pop();
				}
				else 
				{
					sum -= s2.top();
					sum += s3.top();
					s2.pop();	s3.pop();
				}
			}
			else if(s1.top() < s3.top())
			{
				sum -= s1.top();
				sum += s3.top();
				s1.pop();	s3.pop();
			}
			else if(s2.top() < s3.top())
			{
				sum -= s2.top();
				sum += s3.top();
				s2.pop();	s3.pop();
			}
			else
				s3.pop();
		}
		else if(!s1.empty() && s1.top() < s3.top())
		{
				sum -= s1.top();
				sum += s3.top();
				s1.pop();	s3.pop();
		}
		else if(!s2.empty() && s2.top() < s3.top())
		{
				sum -= s2.top();
				sum += s3.top();
				s2.pop();	s3.pop();
		}
		else
			s3.pop();
	}

	cout << sum << endl;





	return 0;
}

Measured memory_bytes: 4864
/*input
6 727202214173249351
6 5 2 5 3 2
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  200005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
lld v[N];
bool vis[N];
void solve()
{
	lld n,k;
	cin >> n >> k;
	rep(i,1,n+1){
		lld x;
		cin >> x;
		v[i]=x;
	}	 
	lld st=1;
	lld c=0;
	lld cycbeg;
	while(!vis[st]){
		vis[st]=1;
		st=v[st];
		c++;
	}
	cycbeg=st;
	st=1;
	lld c2=0;
	while(st!=cycbeg){
		c2++;
		st=v[st];
	}
	if(k<c2){
		lld ans=1;
		st=1;
		while(k>0){
			st=v[st];
			ans=st;
			k--;
		}
		cout << ans << endl;
	}
	else{
		k-=c2;
		c-=c2;
		k%=c;
		st=cycbeg;
		lld ans=st;
		while(k>0){
			st=v[st];
			ans=st;
			k--;
		}
		cout << ans << endl;
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

int main(void){
  string s; cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3552
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e3 + 7;
const ld pi = 3.14159265359;
const int INF = 1e20 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

string s;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> s;

  for(int i = 0; i < s.size() - 1; i++){
    if(s[i] == s[i + 1]){
      cout << i + 1 << ' ' << i + 2;
      return 0;
    }
  }

  for(int i = 0; i < s.size() - 1; i++){
    if(s[i] == s[i + 2]){
      cout << i + 1 << ' ' << i + 3;
      return 0;
    }
  }

  cout << -1 << ' ' << -1;
}


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

long gcd(long x, long y) {
    return y ? gcd(y, x % y) : x;
}

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() {
    
    long A, B;
    cin >> A >> B;
    
    map< int64_t, int > MA = prime_factor(gcd(A, B));
    
    cout << MA.size() + 1 << endl;
}

Measured memory_bytes: 256
let lcs (x, y) =
  let m = String.length x in
  let n = String.length y in
  let s = Array.make (n + 1) 0 in
  let t = Array.copy s in
  for i = 1 to m do
    for j = 1 to n do
      t.(j) <-
        if x.[i-1] = y.[j-1] then s.(j-1) + 1
        else if s.(j) > t.(j-1) then s.(j)
        else t.(j-1);
    done;
    Array.iteri (fun i e -> s.(i) <- e) t;
  done;
  t.(n)

let () =
  let q = Scanf.scanf "%d " (fun q -> q) in
  for _ = 0 to q - 1 do
    Scanf.scanf "%s %s " (fun x y -> x, y)
    |> lcs
    |> Printf.printf "%d\n"
  done

Measured memory_bytes: 3460
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N, A[SIZE], B[SIZE], C[SIZE];

  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-1; i++) cin >> C[i];

  ll ans = 0;

  for(int i=0; i<N-1; i++)
    if (A[i]+1 == A[i+1]) ans += C[A[i]-1];

  debug(ans);

  for(int i=0; i<N; i++)
    ans += B[A[i]-1];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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字くらい使った方がいいかも
*/

int main(){
    vector<int> a(5);
    int ans = 0;

    int minv = 100;
    for(int i=0; i<5; i++){
        int v; cin >> v;
        int ret = (v%10 == 0)? 10:v%10;
        minv = min(minv, ret);
        ans += (v-1)/10*10 + 10;
    }

    cout << ans - 10 + minv << endl;
}

Measured memory_bytes: 256
import math

S = str(input())
T = str(input())

ans = len(T)

for i in range(0,len(S) - len(T)+1):
    diff = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            diff += 1
    ans = min(ans,diff)

print(ans)

Measured memory_bytes: 9028
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!(
        x: i64,
        k: i64,
        d: i64,
    );
    let x = x.abs();
    let (q, r) = (x / d, x % d);
    if k <= q { println!("{}", x - k*d); }
    else {
        if (k - q) % 2 == 0 { println!("{}", r); }
        else { println!("{}", d - r); }
    }
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main()
{
 
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n; cin >> n;
    
    string ans="";

    while (n) {
        ans = char ((n - 1) % 26 + 'a') + ans;
        n = (n - 1) / 26;
    }

    cout << ans;
    return 0;
}

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

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

string S;
int K;

int main()
{
  cin >> S >> K;
  // cout << S << endl;
  // cout << K << endl;

  REP(i, S.size()) {
    if (S[i] == 'a') continue;

    int k = ('z'+1) - S[i];

    if (k <= K) {
      S[i] = 'a';
      K -= k;
    }
  }


  for (int i = S.size()-1; i >= 0; i--) {
    if (S[i] == 'a') continue;
    if (K > 0) {
      S[i] += K;
      K = 0;
      break;
    }
  }

  K %= 26;

  for (int i = S.size()-1; i >= 0; i--) {
    if (K <= 0) break;
    S[i] += K;
    K=0;
  }

  cout << S << endl;;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <vector>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <map>
#include <stack>
#include <cmath>
#define LL long long 
using namespace std; 
 
char c[1000005]; 
 
int main()
{
	int k,n,q;
	long long numm,numd,numc,numdm,nummc,ans;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		cin>>c[i];
	scanf("%d",&q);
	while(q--)
	{
		numm=0,numd=0,numc==0,numdm=0,nummc=0,ans=0;
		scanf("%d",&k);
		for(int i=1;i<=n;i++)
		{
			if(i<=k)
			{
				if(c[i]=='D')
					numd++;
				if(c[i]=='M')
					numm++,numdm+=numd;
				if(c[i]=='C')
					numc++,nummc+=numm,ans+=numdm;
			}
			else
			{
//				cout<<i<<" "<<numd<<" "<<numm<<" "<<numdm<<endl;
				int x=i-k;
				if(c[x]=='D')
					numd--,numdm-=numm;
				if(c[x]=='M')
					numm--,nummc-=numc;
				if(c[x]=='C')
					numc--;
				if(c[i]=='D')
					numd++;
				if(c[i]=='M')
					numm++,numdm+=numd;
				if(c[i]=='C')
					numc++,nummc+=numm,ans+=numdm;
//				cout<<i<<" "<<numd<<" "<<numm<<" "<<numdm<<endl;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1280