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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<int> count(26);
    for (int h=0;h<H;h++){
        for (int w=0;w<W;w++){
            char a;
            cin >> a;
            count[a-'a']++;
        }
    }
    int four = (H/2)*(W/2);
    while (four >0){
        bool ok = false;
        for (int i=0;i<26;i++){
            if (count[i] >= 4) {
                four--;
                count[i]-=4;
                ok = true;
            }
        }
        if (!ok) {
            cout << "No" << "\n";
            return 0;
        }
    }
    int two = (H/2)*(W - (W/2)*2) + (W/2)*(H - (H/2)*2);
    while (two > 0){
        bool ok = false;
        for (int i=0;i<26;i++){
            if (count[i] >= 2) {
                two--;
                count[i]-=2;
                ok = true;
            }
        }
        if (!ok) {
            cout << "No" << "\n";
            return 0;
        }
    }
    int one = (H - (H/2)*2)*(W - (W/2)*2);
    while (one > 0){
        bool ok = false;
        for (int i=0;i<26;i++){
            if (count[i] >= 1) {
                one--;
                count[i]-=1;
                ok = true;
            }
        }
        if (!ok) {
            cout << "No" << "\n";
            return 0;
        }
    }
    bool yes = true;
    for (int i=0;i<26;i++){
        if (count[i] != 0) yes = false;
    }
    if (yes) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 3612
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int K = sc.nextInt();
      int[] array = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      
      // K項目取得
      int result = array[K -1];
      
      // 出力
      System.out.println(result);
    }
    

}

Measured memory_bytes: 22228
# -*- coding: utf-8 -*-

def main(S):
    while(True):
        S.pop()
        if(len(S)%2==1):
            continue
        elif(S[0:int(len(S)/2)]==S[int(len(S)/2):len(S)+1]):
            print(len(S))
            break       
        
if __name__ == '__main__':
    S = input()
    main(list(S))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> d(n);
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mp[d[i]]++;
  }

  ll m;
  cin >> m;
  vector<ll> t(m);
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }

  string ans = "YES";
  for (int i = 0; i < m; i++) {
    if (mp[t[i]] > 0) {
      mp[t[i]]--;
    } else {
      ans = "NO";
      break;
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <stdlib.h>
int main()
{
  long long int n, k;
  scanf("%lld %lld", &n, &k);
  
  long long int mo, kk;
  mo = n%k;
  kk = fabs(mo-k);
  if(mo > kk) printf("%lld", kk);
  else printf("%lld", mo);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x,t;
    cin>>n>>x>>t;
    int g=ceil(n/(double)x);
    cout<<g*t<<'\n';


}

Measured memory_bytes: 3636
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        exec();
    }

    private static void exec() {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        // 借金額
        double debt = 100000;

        // n週間後の借金残高計算
        for (int i = 0; i < n; i++) {

            // 利子5%を追加
            debt = debt + (debt / 20);

            // 借金の1000円未満切り上げ
            BigDecimal bd1 = new BigDecimal(debt / 1000);
            BigDecimal bd2 = bd1.setScale(0, BigDecimal.ROUND_UP);
            debt = bd2.intValue() * 1000;
        }

        System.out.println((int) debt);
    }
}

Measured memory_bytes: 17308
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        ll n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;
        map<ll, ll> mp;
        mp[1] = d;
        int mx = 1000;
        vector<vector<pair<ll, int>>> g(mx);
        vector<ll> dis(mx, 1e18);
        for (int i = 0; i < mx; i++) {
            if (i != mx - 1) {
                g[i].emplace_back(d, i + 1);
                g[i + 1].emplace_back(d, i);
            }
            if (i * 2 < mx) {
                g[i].emplace_back(a, i * 2);
                g[i * 2].emplace_back(a, i);
            }
            if (i * 3 < mx) {
                g[i].emplace_back(b, i * 3);
                g[i * 3].emplace_back(b, i);
            }
            if (i * 5 < mx) {
                g[i].emplace_back(c, i * 5);
                g[i * 5].emplace_back(c, i);
            }
        }
        using P = pair<ll, int>;
        dis[0] = 0;
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.push(P(0, 0));
        while (!pq.empty()) {
            P p = pq.top();
            pq.pop();
            int v = p.second;
            if (dis[v] < p.first) {
                continue;
            }
            for (auto e : g[v]) {
                if (dis[e.second] > dis[v] + e.first) {
                    dis[e.second] = dis[v] + e.first;
                    pq.push(P(dis[e.second], e.second));
                }
            }
        }
        for (int i = 0; i < mx; i++) {
            mp[i] = dis[i];
        }
        function<ll(ll)> solve = [&](ll x) {
            if (x == 0) {
                return 0LL;
            }
            if (mp[x] != 0LL) {
                return mp[x];
            }
            ll res = 9e18;
            if (1.0 * x * d < 9e18) {
                res = x * d;
            }
            if (x % 2 == 0) {
                res = min(res, solve(x / 2) + a);
            } else {
                res = min(res, solve(x / 2) + a + d);
                res = min(res, solve(x / 2 + 1) + a + d);
            }
            if (x % 3 == 0) {
                res = min(res, solve(x / 3) + b);
            } else if (x % 3 == 1) {
                res = min(res, solve(x / 3) + b + d);
                res = min(res, solve(x / 3 + 1) + b + d + d);
            } else {
                res = min(res, solve(x / 3) + b + d + d);
                res = min(res, solve(x / 3 + 1) + b + d);
            }
            ll q = x % 5;
            res = min(res, solve(x / 5) + c + d * q);
            res = min(res, solve(x / 5 + 1) + c + d * (5 - q));
            return mp[x] = res;
        };
        cout << solve(n) << '\n';
    }
    return 0;
}


Measured memory_bytes: 4652
n, a, b = map(int , raw_input().split())
def dfs(u, q, n, a, b):
	c = 0
	if u > n:return 0

	if a <= q <= b: 
		c += u

	for d in range(0 if u else 1,10): 
		c += dfs(u * 10 + d,q + d, n, a, b)
	return c


print dfs(0, 0,n, a, b )

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


int main(){
  string s;
  cin >> s;
  deque<char> dq;

  int q,i;
  for(i=0;i<s.length();++i) dq.push_back(s[i]);
  cin >> q;
  int ti=0;
  int t,f;
  char c;
  for(i=0;i<q;++i){
    cin >> t;
    if(t==1){
      ti++;
    }else{
      cin >> f >> c;
      if(f==1){
        if(ti%2==0){
          //s=c+s;
          dq.push_front(c);

        }else{
          //s=s+c;
          dq.push_back(c);

        }
      }else{
        if(ti%2==0){
          //s=s+c;
          dq.push_back(c);
        }else{
          //s=c+s;
          dq.push_front(c);

        }
      }
    }
  }
  if(ti%2==1){
    /*while(!dq.empty()){
      cout << dq.back() ;
      dq.pop_back();
    }
    cout << endl;*/
    reverse(dq.begin(),dq.end());
    for(auto d : dq)cout << d;
    cout << endl;
  }else{
    while(!dq.empty()){
      cout << dq.front();
      dq.pop_front();
    }
    cout << endl;
  }
  return 0;
}


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

int main(){
    unsigned long N;
    cin >> N;
    unsigned long ans{11};
    for(unsigned long i = 1; i * i <= N; ++i)if(!(N % i))ans = min(ans, to_string(N / i).size());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

res = n
for i in range(n+1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t //= 6
    t = n - i
    while t > 0:
        cc += t % 9
        t //= 9
    if res > cc:
        res = cc

print(res)

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

int A[3];

signed main()
{
	cin >> A[0] >> A[1] >> A[2];
	if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) {
		cout << 0 << endl;
		return 0;
	}
	sort(A, A + 3);
	cout << A[0] * A[1] << endl;
}


Measured memory_bytes: 256
from collections import deque
a = deque(input())
a.append("a")
b = deque(input())
b.append("b")
c = deque(input())
c.append("c")
 
start = a.popleft()
while a and b and c:
    if start == "a":
        start = a.popleft()
    elif start == "b":
        start = b.popleft()
    else:
        start = c.popleft()
 
print(str(start).upper())

Measured memory_bytes: 64804
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

const ll INF = 1E18+5;
const ll mod = 1E9+7;
ll n,k;
vector<ll> a(200001);
bool check(ll mid){
    ll i,ans = 0;
    for(i=0;i<n;i++)
    {
        ans = ans + (ll)((a[i]-1)/mid);
    }
    if(ans<=k)
        return true;
    return false;
}

int main(){
    cin>>n>>k;
    ll i;
    for(i=0;i<n;i++)
        cin>>a[i];
    ll start = 0, end = 2000000000, ans;
    while(start<=end)
    {
        ll mid = start + (end-start)/2;
        if(mid==0)
        {
            ans = 1;
            break;
        }
        if(check(mid))
        {
            end = mid-1;
            ans = mid;
        }
        else start = mid+1;
    }
    cout<<ans;
}




Measured memory_bytes: 4672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Hs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var ret = 0;
            var temp = 0;
            var isLow = false;
            for (int i = 0; i < N - 1; i++)
            {
                if(Hs[i] >= Hs[i + 1])
                {
                    isLow = true;
                    temp++;
                }
                else if(isLow && Hs[i] < Hs[i + 1])
                {
                    isLow = false;
                    ret = Math.Max(ret, temp);
                    temp = 0;
                }
            }
            ret = Math.Max(ret, temp);
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 26204
n=int(input())
d=[[0]*10 for i in range(10)]
ans=0
for i in range(1,n+1):
    a=i%10
    if a!=0:
        t=i
        while t>9:
            t//=10
        b=t
        d[b][a]+=1
for i in range(10):
    for j in range(10):
        ans+=d[i][j]*d[j][i]
print(ans)


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

using namespace std;

int main ()

{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << ((a*(a-1))/2)+((b*(b-1))/2) << endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    vector<int> ban(n + 1, false);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        ban[a] = true;
    }

    vector<ll> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (ban[i]) continue;
        dp[i] = dp[i - 1];
        if (i > 1) (dp[i] += dp[i - 2]) %= MOD; 
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int a, b,h;
	cin >> a >> b >>h;
	cout << (a + b) * h /2 << endl;
}


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

#define MAX_N (1000L)
#define NUM_MOD (1000000007L)

using namespace std;

long mod_pow(long n, long k, long mod) {
  long res = 1, num = n;
  while (k > 0) {
    if (k % 2 == 1) {
      res = res * num % mod;
    }
    k /= 2;
    num = num * num % mod;
  }
  return res;
}

long fs[MAX_N + 1], finvs[MAX_N + 1], invs[MAX_N + 1];

void fact_init(long N) {
  fs[0] = fs[1] = 1;
  finvs[0] = finvs[1] = 1;
  invs[1] = 1;
  for (int i = 2; i <= N; i++) {
    fs[i] = fs[i - 1] * i % NUM_MOD;
    invs[i] = NUM_MOD - invs[NUM_MOD % i] * (NUM_MOD / i) % NUM_MOD;
    finvs[i] = finvs[i - 1] * invs[i] % NUM_MOD;
  }
}

long num_comb(long i, long j, long k) {
  long res = 1;
  res = res * fs[i] % NUM_MOD;
  res = res * finvs[i - k * j] % NUM_MOD;
  res = res * finvs[k] % NUM_MOD;
  res = res * mod_pow(finvs[j], k, NUM_MOD) % NUM_MOD;
  return res;
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, A, B, C, D;
  scanf("%ld %ld %ld %ld %ld", &N, &A, &B, &C, &D);

  // init
  fact_init(N);

  // solve dp
  long dpss[MAX_N + 1][MAX_N + 1];
  // initialize
  for (long j = 0; j <= N; j++) {
    dpss[0][j] = 1;
  }
  for (long i = 1; i <= N; i++) {
    // B is the maximum number of people per group
    if (i % B == 0 && i / B >= C && i / B <= D) {
      dpss[i][B] = num_comb(i, B, i / B);
    } else {
      dpss[i][B] = 0;
    }
  }
  // update
  for (long i = 1; i <= N; i++) {
    for (long j = B - 1; j >= A; j--) {
      long dp = 0;
      // dp = max(dp, dpss[i][j + 1]);
      dp = (dp + dpss[i][j + 1]) % NUM_MOD;
      for (long k = C, k_last = min(D, i / j); k <= k_last; k++) {
        dp = (dp + dpss[i - k * j][j + 1] * num_comb(i, j, k) % NUM_MOD) % NUM_MOD;
        // printf("i = %ld, j = %ld, k = %ld, dpss[i - k * j] = %ld, num_comb = %ld\n", i, j, k,
        //        dpss[i - k * j][j + 1], num_comb(i, j, k));
      }
      dpss[i][j] = dp;
    }
  }
  // for (long i = 0; i <= N; i++) {
  //   printf("i = %ld:", i);
  //   for (long j = A; j <= B; j++) {
  //     printf(" %ld", dpss[i][j]);
  //   }
  //   printf("\n");
  // }
  printf("%ld\n", dpss[N][A]);

  return 0;
}


Measured memory_bytes: 8064
h, w = list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))

mat = [[0]*w for _ in range(h)]

seq = 0
for color, i  in enumerate(a):
    i0 = i
    while i0>0:
        r = seq//w
        if r%2 == 0:
            c = seq%w
        else:
            c = w-seq%w-1
        mat[r][c] = color+1
        i0 -=1
        seq += 1
for l in mat:
    print(*l, sep=' ')
    


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

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

    int a[100010];
    set<int> st;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        st.insert(a[i]);
    }

    if(st.size() >= 3){
        cout << "No" << endl;
        return 0;
    }

    if(st.size() == 1){
        if(a[0] == 1 || a[0] == n-1 || n / a[0] > 1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }

    sort(a, a+n);
    int mi = a[0];
    int ma = a[n-1];

    if(ma != mi+1){
        cout << "No" << endl;
        return 0;
    }

    int macnt = 0;
    int micnt = 0;
    for(int i = 0;i < n;i++){
        if(a[i] == mi){
            micnt++;
        }else{
            macnt++;
        }
    }

    if(mi >= micnt && (macnt / (ma-micnt)) > 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 5376
# # -*- coding: utf-8 -*-
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
    exit()

P = set((map(int, input().split(' '))))

ans, min_diff = None, float('inf')
for n in range(102):
    if n in P:
        continue

    diff = abs(X - n)
    if diff < min_diff:
        min_diff = diff
        ans = n

print(ans)








Measured memory_bytes: 61800
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int>vec[100001];
int n,memo[100001][4];
int solve(int idx,int prev=0){
    if(idx==n)
        return 0;
    int &cur=memo[idx][prev];
    if(cur!=-1)
        return cur;
    cur=0;
    for(int i=0;i<3;i++){
        if((i+1)!=prev){
            cur=max(cur,vec[idx][i]+solve(idx+1,i+1));
        }
    }
    return cur;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1,sizeof(memo));
    cin>>n;
    for(int i=0;i<n;i++){
        for(int c=0;c<3;c++){
            int x;
            cin>>x;
            vec[i].push_back(x);
        }
    }
    cout<<solve(0);
}

Measured memory_bytes: 15104
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[105];
	int flag=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]%2==0)
		{
			if(a[i]%3!=0&&a[i]%5!=0)flag=0;
		}
	}
	if(flag==1)cout<<"APPROVED";
	else cout<<"DENIED";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p){return fpow(n,p-2,p);}
ll modmul(ll x,ll y){return (x*y)%hell;}
ll modadd(ll x,ll y){if(x>=hell)x-=hell;if(y>=hell)y-=hell;ll temp=x+y;if(temp>=hell)temp-=hell;if(temp<0)temp = temp+hell;return temp;}
/*void sieve(){
	prime[1] = 1;
	for(ll i=2;i<=15000000;i++)
		if(!prime[i])
			for(ll j=i;j<=15000000;j+=i)
				if(!prime[j])
					prime[j] = i;
}*/
int main(){
	ios
	ll t = 1;
	//cin >> t;
	//sieve();
	while(t--)
	{
		ll n;
		cin >> n;
		vector<ll>a(n),dp(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		dp[0] = 0;
		dp[1] = abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
			dp[i] = min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));
		cout << dp[n-1] << "\n";
	}
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
int main(){
  int n, k;
  cin >> n >> k;
  
  for(int i = 0; i < n; ++i){
    char c;
    cin >> c;
    if(i == k - 1){
      c += 32;
    }
    
    cout << c;
  }
  
  cout << endl;
}

Measured memory_bytes: 256
# 整数の入力
N, M, X, Y = map(int, input().split())
x = map(int, input().split())
y = map(int, input().split())

x_max = max(x)
y_min = min(y)

flag_war = True

for z in range(X+1, Y+1):
    if x_max < z:
        if y_min >= z:
            print('No War')
            flag_war = False
            break
        else:
            continue
    else:
        continue
if flag_war == True:
    print('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
 
ll euclid(ll a, ll b ){
ll temp;
if( a < b ) { temp = a; a = b; b = temp; }
if( b < 1 ) return -1;
if( a % b == 0 ) return b;
return euclid( b, a % b );
}

int main(){
    ll K; cin >> K;
    ll sum = 0;
    for(int i=1; i<K+1; i++){
        for(int j=1; j<K+1; j++){
            for(int k=1; k<K+1; k++){
                int m = euclid(i, j);
                sum += euclid(m,k);
            }
        }
    }
    cout << sum;
}

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

int n, x, t;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> x >> t;
    int add = x, ans = t;
    while (n > x) {
        x += add;
        ans += t;
    }
    cout << ans << "\n";
    return 0;
}


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

namespace ABC124D
{
    class MainClass
    {

        static int[] n;

        public static void Main(string[] args)
        {

            n = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            string s = Console.ReadLine();
            int nowl = 0;
            var lrlst = new List<int[]>();
            var lrfst = new int[2] { 0, 0 };
            lrlst.Add(lrfst);
            for (int i = 0; i < s.Length - 1; i++)
            {
                if (s[i] == '0' && s[i + 1] == '1')
                {
                    int[] lr = new int[] { nowl, i + 1 };
                    lrlst.Add(lr);
                }else if (s[i] == '0' && s[i + 1] == '0' && i == s.Length - 2)
                {
                    int[] lr = new int[] { nowl, i + 2 };
                    lrlst.Add(lr);
                }
                else if (s[i] == '1' && s[i + 1] == '0')
                {
                    nowl = i + 1;
                    if (i == s.Length - 2)
                    {
                        int[] lr = new int[] { nowl, i + 2 };
                        lrlst.Add(lr);
                    }

                }
            }
                var lrlast = new int[2] { n[0], 0 };
                lrlst.Add(lrlast);


                /*foreach (int[] lr in lrlst)
                {
                    Console.WriteLine(lr[0] + " " + lr[1]);
                }*/



                int lrcnt = lrlst.Count;
                if (lrcnt - 2 <= n[1])
                {
                    Console.WriteLine(n[0]);
                }
                else
                {
                    int ans = 0;
                    for (int i = 0; i < lrcnt - n[1] - 1; i++)
                    {
                        ans = Math.Max(lrlst[i + n[1] + 1][0] - lrlst[i][1], ans);
                    }
                    Console.WriteLine(ans);
                }
            }
        }
    }



Measured memory_bytes: 14560
#include<bits/stdc++.h>
using namespace std;
int n,t=0,x=0;string a;
int main()
{
	cin>>n>>a;
	for(int i=0; i<n; i++)
	{
		if(a[i]=='I')t++;
		else if(a[i]=='D')t--;
		if(t>=x)x=t;
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n, m = map( int, input().split() )

An = list(map(int, input().split()))

Bn = [0]+An



for i in range(n):
    Bn[i+1] = An[i] + Bn[i] 

#print(Bn)



mp = []

for i in range(n+1):
    r = Bn[i] % m
    mp.append(r)

nlist = Counter(mp).most_common()

ans = 0
for i in range(len(nlist)):
    t = nlist[i][1]
    if t <= 1:
        break

    ans += t*(t-1)//2

print(ans)


Measured memory_bytes: 21784
//include---------------------------------------------------------------------------
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cctype>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<algorithm>
#include<memory>

//using namespace-------------------------------------------------------------------
using namespace std;

//define,const----------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1 << 25;
#define MAX_N 100

//global----------------------------------------------------------------------------
int numbar[MAX_N], n;

//function--------------------------------------------------------------------------
int main(){
	scanf("%d", &n);
	const int N = n;
	int num;
	rep(i, N)
		scanf("%d", &numbar[i]);
	rep(i, N - 1)
		printf("%d ", numbar[i]);
	printf("%d\n", numbar[N - 1]);
	for(int i = 1; i < N; i++){
		num = i;
		for(int j = 0; j < i; j++){
			if(numbar[i] < numbar[j]){
				num = j;
				break;
			}
		}
		if(num != i){
			for(int j = num; j < i; j++){
				swap(numbar[j], numbar[i]);
			}
		}
		for(int j = 0; j < N - 1; j++)
			printf("%d ", numbar[j]);
		printf("%d\n", numbar[N - 1]);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#define maxn 200005
using namespace std;
int r[maxn],n;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&r[i]);
    }
    int maxv=-1e9,minv=r[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,r[i]-minv);
        minv=min(minv,r[i]);
    }
    printf("%d\n",maxv);
    return 0;
}



Measured memory_bytes: 3968
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;



int main()
{
    SRK;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans1 = (ll)a * c;
    ll ans2 = (ll)b * d;
    ll ans3 = (ll)a * d;
    ll ans4 = (ll)b * c;
    cout << max(max(ans1,ans2),max(ans3,ans4)) << endl;
}


Measured memory_bytes: 3648
N,K=[int(s) for s in input().split()]
if K%2==1:
  ###N以下のKの正の倍数を並べれば良い
  a=N//K
  print(a**3)
else:
  ans=0
  ###全てがKの倍数の場合
  a=N//K
  ans+=a**3
  ###全てがK/2の倍数かつKの倍数でない場合
  b=N//(K//2)
  ans+=(b-a)**3
  print(ans)



Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int x = 0;
            int xmax = 0;
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'I')
                {
                    x++;
                }
                else 
                {
                    x--;
                }

                xmax = Math.Max(x, xmax);

            }
            Console.WriteLine(xmax);
            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 2776
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


ll N, X, D;
map<ll,vector<pair<ll,ll>>>mp;

ll sum(ll from,ll to) {
	if (from > to)return 0;
	ll sum1 = to * (to + 1LL) / 2LL;
	ll sum2 = from * (from - 1LL) / 2LL;
	return sum1 - sum2;
}

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


	cin >> N >> X >> D;
	if (D == 0) { 
		if (X != 0) { puts(N + 1); }
		else puts(1);
		return 0;
	}
	if (D < 0) { X = X + (N - 1LL)*D; D = -D; }

	for (ll i = 0; i <= N; i++) {
		ll m = (i*X + ((X < 0LL)?(-i*X+D-1LL)/D:0LL)*D)%D;
		mp[m].pb({i*X + D*sum(0,i-1),1});
		mp[m].pb({i*X + D*sum(N-i,N-1)+1,-1});
	}

	ll ans = 0;
	fore(x, mp) {
		auto v = x.second;
		sort(all(v));
		ll cur = 0;
		ll curr;
		fore(y, v) {
			if (cur == 0) { curr = y.first; }
			cur += y.second;
			if (cur == 0) { ans += (y.first-1-curr) / D + 1LL; }
		}
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 25216
H, W, K = map(int, input().split())
S = []
for _ in range(H):
  S.append(input())
hsummation = [[int(S[0][k])]for k in range(W)]
for k in range(W):
  for j in range(1, H):
    hsummation[k].append(hsummation[k][j-1] + int(S[j][k]))

ans = float('inf')
anskouho = 0
h = -1
binhh = []
for j in range(2**(H-1)):
  h += 1
  binh = "0"*(H-len(str(bin(h)))+1)+str(bin(h))[2:]
  c = 0
  for k in range(len(binh)):
    if binh[k] == '1':
      c += 1
  binhh.append([binh, c])
binhh.sort(key = lambda x:x[1] , reverse= True)
#print(binhh)
#h = 2**(H-1)
for j in range(2**(H-1)):
  #h -= 1
  #binh = "0"*(H-len(str(bin(h)))+1)+str(bin(h))[2:]
  hlist=[]
  for k in range(H-1):
    if binhh[j][0][k] == '1':
      hlist.append(k)
  hlist.append(-1)
  anskouho = len(hlist)-1
  now = 0
  while now < W:
    counter = [0 for _ in range(len(hlist))]
    while now < W:
      counter[0] += hsummation[now][int(hlist[0])]
      for l in range(1, len(hlist)):
        #if l == 0:
          #counter[l] += hsummation[now][int(hlist[l])]
          #continue
        #else:
        counter[l] += - hsummation[now][hlist[l-1]] + hsummation[now][hlist[l]]
      if max(counter) > K:
        anskouho += 1
        break
      else:
        now += 1
    if anskouho > ans:
      break
  else:
    ans = min(ans, anskouho)
print(ans)

Measured memory_bytes: 75448
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	map<string, int> m;
	int maxcnt = 0;
	for( int i = 0; i < N; ++i ) {
		string s;
		cin >> s;
		m[s] += 1;
		maxcnt = max( maxcnt, m[s] );
	}

	for( auto& v: m ) {
		if( v.second == maxcnt ) {
			cout << v.first << '\n';
		}
	}

	return 0;
}


Measured memory_bytes: 23808
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

std::string A, B, t;

int main()
{
  std::cin >> A >> B;

  if( A.size() < B.size() )
  {
    rep( i, B.size()-A.size() )
      t += "0";

    t += A;

    A = t;
  }
  if( B.size() < A.size() )
  {
    rep( i, A.size()-B.size() )
      t += "0";

    t += B;

    B = t;
  }

  if( A > B )
    std::cout << "GREATER" << std::endl;
  else if( A < B )
    std::cout << "LESS" << std::endl;
  else
    std::cout << "EQUAL" << std::endl;

  return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<string> S;
    while (N--) {
        string s;
        vector<char> s_vec;
        cin >> s;
        for (int i=0; i<s.size(); i++) {
            s_vec.push_back(s[i]);
        }
        sort(s_vec.begin(), s_vec.end());
        s = "";
        for (int i=0; i<s_vec.size(); i++) {
            s += s_vec[i];
        }
        S.push_back(s);
    }

    sort(S.begin(), S.end());
    // for (int i=0; i<S.size(); i++) {
    //     cout << S[i] << endl;
    // }
    long int count = 0;
    long int groupCount = 1;
    string tmp = S[0];
    for (int i=1; i<S.size(); i++) {
        if (tmp == S[i]) {
            groupCount++;
        } else {
            count += groupCount * (groupCount-1) / 2;
            groupCount = 1;
        }
        tmp = S[i];
    }
    count += groupCount * (groupCount-1) / 2;

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 4980
import math as m

x = int(input()) - 1
flg = 1
while flg == 1:
    flg = 0
    x += 1
    a = int(m.sqrt(x)//1 + 1)
    for i in range(2, a):
        if x % i == 0:
            flg = 1
            break

print(x)


Measured memory_bytes: 2940
def bubbleSort(matrix, N):
  for i in range(N):
    for j in reversed(range(i+1, N)):
      if matrix[j][1] < matrix[j-1][1]:
        matrix[j], matrix[j-1] = matrix[j-1], matrix[j]

def selectionSort(matrix, N):
  for i in range(N):
    minj = i
    for j in range(i, N):
      if matrix[j][1] < matrix[minj][1]:
        minj = j
    if matrix[i][1] != matrix[minj][1]:
      matrix[i], matrix[minj] = matrix[minj], matrix[i]

def printList(matrix, N):
  matrix_cards = []
  for i in range(N):
    matrix_cards.append(matrix[i][0])
  print(" ".join(map(str, matrix_cards)))

n = int(input())
A = list(input().split())
B = [[] for i in range(n)]
C = [[] for i in range(n)]

for i in range(n):
  A[i] = [A[i], int(A[i][1:])]
  B[i] = A[i]
  C[i] = A[i]

bubbleSort(B, n)
selectionSort(C, n)

printList(B,n)
print("Stable")

printList(C,n)
if B == C:
  print("Stable")
else:
  print("Not stable")



Measured memory_bytes: 5608
#include <stdio.h>
#define N 100

int main(){
  int temp,i,j,n,A[N],count=0;

  scanf("%d",&n);

  for(i=0;i < n;i++)
    scanf("%d",&A[i]);

  for(i=0;i< n;i++){
    for(j = n-1;j > i;j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	count++;
      }
    }
  }

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

  return 0;
}



Measured memory_bytes: 2068
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  long long A[100000];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  if(N<=2){
    cout<<1<<endl;
  }
  else{
  int answer=1;
  int judge=0;
    for(int i=1;i<N;i++){
      if(judge==0){
        if(A[i-1]<A[i]) judge=1;
        if(A[i-1]>A[i]) judge=-1;
      }
      if(judge==1&&A[i-1]>A[i]){
       judge=0;
        answer++;
      }
      if(judge==-1&&A[i-1]<A[i]){
        judge=0;
        answer++;
      }
    }
    cout<<answer<<endl;
  }
  return 0;
}

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

#define int long long

signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);

    int n = 0;
    while(true) {
        sort(v.begin(), v.end());
        if(v[0]==v[1] && v[0]==v[2]) {
            cout << n << endl;
            return 0;
        }
        if(v[0]+2 <= v[2]) {
            n++;
            v[0] += 2;
            continue;
        } else {
            v[0]++;
            v[1]++;
            n++;
        }
    }
    return 0;
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
//Cancel in interactive questions
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define got(container,num) get<num-1>(container)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;

main()
{
    IOS
    cin>>n>>m;
    fun(i)
    {
        cin>>a[i];
    }
    sort(in(a));
    fum(i)ans+=a[i];
    out(ans)
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>

using namespace std;

inline int abs(int x)       { return x>0 ? x : -x ; }
inline int max(int x, int y){ return x>y ? x : y ; }
inline int min(int x, int y){ return x>y ? y : x ; }


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

        int h[100010] ={};
        for(int i=0; i<N; i++)
                cin >> h[i];

        int dp[100010];
        dp[0] = 0;
        dp[1] = abs(h[1] - h[0]);
        for(int i=2; i<N; i++){
                dp[i] = min( dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) ;
        }
        cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int v,h;
	int matrixA[1000][1000];
	int matrixB[1000];
	int matrixC[1000] = {};
	scanf("%d%d",&v,&h);
	for(int i = 0; i < v; i++)for(int j = 0; j < h; j++)scanf("%d",&matrixA[i][j]);
	for(int i = 0; i < h; i++)scanf("%d",&matrixB[i]);
	for(int i = 0; i < v; i++){
		for(int j = 0; j < h; j++){
			matrixC[i] += matrixA[i][j] * matrixB[j];
		}
	}
	for(int i = 0; i < v; i++)printf("%d\n",matrixC[i]);
	return 0;
}



Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

constexpr int mod = 1000000007;
struct mint {
  long long x;
  constexpr mint(long long x = 0) : x((x % mod + mod) % mod) {}
  constexpr mint operator-() const { return mint(-x); }
  constexpr mint &operator+=(const mint &a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint operator+(const mint &a) const {
    mint res(*this);
    return res += a;
  }
  constexpr mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  constexpr mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  constexpr mint pow(long long t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  constexpr mint inv() const { return pow(mod - 2); }
  constexpr mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
  constexpr mint operator/(const mint &a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream &operator<<(ostream &os, const mint &m) {
  os << m.x;
  return os;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n + 5);

  mint ans = 0;
  rep(ri, 0, 2) {
    rep(i, 0, n) {
      mint now = c(i, k - 1);
      if (ri == 1)
        now = -now;
      ans += a[i] * now.x;
    }
    reverse(a.begin(), a.end());
  }

  cout << ans.x << endl;
}


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

const ll MOD = 1e9 + 7;
const int N = (60);
int memo[N][2][2][2];
string L, R;

int dpOverDig(int pos, int highL, int lowR, int MSB) {
  if (pos == (int) R.size()) return 1;
  int &ret = memo[pos][highL][lowR][MSB];
  if (ret != -1) return ret;
  ret = 0;
  if (lowR) {
    if (highL) {
      for (int i = 0; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
          if (i == 1 and j == 0) continue;
          if (!MSB and i == 0 and j == 1) continue;
          ret += dpOverDig(pos + 1, 1, 1, MSB or (i and j));
          ret %= MOD;
        }
      }
    } else {
      int d = L[pos] - '0';
      for (int i = d; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
          if (i == 1 and j == 0) continue;
          if (!MSB and i == 0 and j == 1) continue;
          ret += dpOverDig(pos + 1, d < i? 1 : 0, 1, MSB or (i and j));
          ret %= MOD;
        }
      }
    }
  } else {
    if (highL) {
      for (int i = 0; i <= 1; ++i) {
        int d = R[pos] - '0';
        for (int j = 0; j <= d; ++j) {
          if (i == 1 and j == 0) continue;
          if (!MSB and i == 0 and j == 1) continue;
          ret += dpOverDig(pos + 1, 1, j < d? 1 : 0, MSB or (i and j));
          ret %= MOD;
        }
      }
    } else {
      int dL = L[pos] - '0';
      for (int i = dL; i <= 1; ++i) {
        int dR = R[pos] - '0';
        for (int j = 0; j <= dR; ++j) {
          if (i == 1 and j == 0) continue;
          if (!MSB and i == 0 and j == 1) continue;
          ret += dpOverDig(pos + 1, dL < i? 1 : 0, j < dR? 1 : 0, MSB or (i and j));
          ret %= MOD;
        }
      }
    }
  }
  return ret;
}

int main() { // claudio van
  ll l, r; scanf("%lld %lld", &l, &r);
  for (int i = N - 1; i >= 0; --i) {
    L += '0' + ((l >> i) & 1);
    R += '0' + ((r >> i) & 1);
  }
  memset(memo, -1, sizeof memo);
  printf("%d\n", dpOverDig(0, 0, 0, 0));
  return 0;
}

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

int n, m;
long long d[1001];
vector<tuple<int,int,int> > edges;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0, u, v, w; i < m; i++) {
		cin >> u >> v >> w;
		edges.emplace_back(u, v, -w);
	}
	if(n > 1) fill(d+2, d+n+1, 1e18);
	for(int t = 1; t < n; t++) for(auto p: edges) {
		int u, v, w;
		tie(u, v, w) = p;
		if(d[u]+w < d[v]) d[v] = d[u]+w;
	}
	long long d1 = d[n];
	for(int t = 1; t < n; t++) for(auto p: edges) {
		int u, v, w;
		tie(u, v, w) = p;
		if(d[u]+w < d[v]) d[v] = d[u]+w;
	}
	if(d1 == d[n]) cout << -d[n];
	else cout << "inf";
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var N, K, Q int
	fmt.Scan(&N)
	fmt.Scan(&K)
	fmt.Scan(&Q)
	app := make([]int, N)
	for i := 0; i < Q; i++ {
		var a int
		fmt.Scan(&a)
		app[a-1]++
	}

	for i := 0; i < N; i++ {
		if K+app[i]-Q <= 0 {
			fmt.Println("No")
		} else {
			fmt.Println("Yes")
		}
	}
}


Measured memory_bytes: 7424
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ar[]= new int[n];
        for (int i=0;i<n;i++){
            ar[i]=sc.nextInt();
        }
        int sum=0;
        Arrays.sort(ar);
        for (int i=0;i<k;i++){
            sum+=ar[i];
 
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 38836
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
 
typedef long long int64;
const int INF = 1 << 28;

int N, M;
char mas[500][500];
int countx[500], county[500];


bool counter(int x, int y){
  vector< Pi > points;
  if(countx[x] != 0){
    for(int i = y - 1; i >= 0; i--){
      if(mas[i][x] != '.'){
        points.push_back( Pi( x, i));
        break;
      }
    }
    for(int i = y + 1; i < M; i++){
      if(mas[i][x] != '.'){
        points.push_back( Pi( x, i));
        break;
      }
    }
  }
  if(county[y] != 0){
    for(int i = x - 1; i >= 0; i--){
      if(mas[y][i] != '.'){
        points.push_back( Pi( i, y));
        break;
      }
    }
    
    for(int i = x + 1; i < N; i++){
      if(mas[y][i] != '.'){
        points.push_back( Pi( i, y));
        break;
      }
    }
  }

  for(int i = 0; i < points.size(); i++){
    for(int j = i + 1; j < points.size(); j++){
      Pi& p1 = points[i], p2 = points[j];
      if(mas[p1.second][p1.first] == mas[p2.second][p2.first]){
        mas[p1.second][p1.first] = mas[p2.second][p2.first] = '.';
        county[p1.second]--, county[p2.second]--;
        countx[p1.first]--, countx[p2.first]--;
        return(true);
      }
    }
  }
  return(false);
}

int solve(){
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      if(county[i] + countx[j] < 2) continue;
      if(mas[i][j] == '.' && counter( j, i)) return(2 + solve());
    }
  }
  return(0);
}

int main(){

  cin >> M >> N;
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      cin >> mas[i][j];
    }
  }
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      county[i] += mas[i][j] != '.';
      countx[j] += mas[i][j] != '.';
    }
  }
  cout << solve() << endl;
}

Measured memory_bytes: 1448
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (10**6+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)
    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> cnt(m);
  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    vector<int> a(k);
    for(int j=0;j<k;j++){
      cin >> a[j];
      cnt[a[j]-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<m;i++){
    if(cnt[i]==n){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256