akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            char a;
            std::vector<vector<char>> vec(n,vector<char>(n));
            for (int i=0;i<n;i++) {
                for (int j=0;j<n;j++) {
                    cin>>a;
                    vec.at(i).at(j)=a;
                }
            }
            int countVer=0,countSide=0,countDiaLeft=0,countDiaRight=0,maxCount=0;
            for (int l=0;l<n;l++) {
                for (int m=0;m<n;m++) {
                    if (vec.at(l).at(m)=='1') {
                        int tmp1=l;
                        int tmp2=m;
                        //横探索
                        while (tmp2!=n&&vec.at(tmp1).at(tmp2)=='1') {
                            countSide++;
                            tmp2++;
                        }
                        tmp1=l;
                        tmp2=m;
                        //縦探索
                        while (tmp1!=n&&vec.at(tmp1).at(tmp2)=='1') {
                        countVer++;
                        tmp1++;
                        }
                        tmp1=l;
                        tmp2=m;
                        //左斜め探索
                        while (tmp1!=n&&tmp2!=-1&&vec.at(tmp1).at(tmp2)=='1') {
                            countDiaLeft++;
                            tmp1++;
                            tmp2--;
                        }
                        //右斜め探索
                        tmp1=l;
                        tmp2=m;
                        while (tmp1!=n&&tmp2!=n&&vec.at(tmp1).at(tmp2)=='1') {
                            countDiaRight++;
                            tmp1++;
                            tmp2++;
                        }
                        int ans=max(countVer,max(countSide,max(countDiaLeft,countDiaRight)));
                        if (ans>maxCount) {
                            maxCount=ans;
                        }
                        countVer=0,countSide=0,countDiaLeft=0,countDiaRight=0;
                    }
                }
            }
            cout<<maxCount<<endl;
        }
    }
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	vector<ll>W(N, 0), E(N, 0);
	rep(i, 0, s.size()) {
		if (s[i] == 'W')W[i]++;
		else E[i]++;
	}
	rep(i, 1, N) {
		W[i] += W[i - 1];
		E[i] += E[i - 1];
	}
	ll ans = INF;
	rep(i, 0, N) {
		if (i == 0) {
			chmin(ans, E[N - 1] - E[0]);
		}
		else if (i == N - 1) {
			chmin(ans, W[i - 1]);
		}
		else chmin(ans, W[i - 1] + E[N - 1] - E[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 5396
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
check_box = [[0, 0, 0, a[0] + b[0] + c[0]]]
for i in range(k):
    check = check_box.pop(0)
    print(check[3])
    if check[0] < x - 1 and [check[0] + 1, check[1], check[2], a[check[0] + 1] + b[check[1]] + c[check[2]]] not in check_box:
        check_box.append([check[0] + 1, check[1], check[2], a[check[0] + 1] + b[check[1]] + c[check[2]]])
    if check[1] < y - 1 and [check[0], check[1] + 1, check[2], a[check[0]] + b[check[1] + 1] + c[check[2]]] not in check_box:
        check_box.append([check[0], check[1] + 1, check[2], a[check[0]] + b[check[1] + 1] + c[check[2]]])
    if check[2] < z - 1 and [check[0], check[1], check[2] + 1, a[check[0]] + b[check[1]] + c[check[2] + 1]] not in check_box:
        check_box.append([check[0], check[1], check[2] + 1, a[check[0]] + b[check[1]] + c[check[2] + 1]])
    check_box.sort(key = lambda x: x[3], reverse = True)

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

int main() {
	int N, K;
	cin >> N;
	cin >> K;
	int B = 1;
	for (int i = 0; i < N; i++) {
		if (B + K >= B * 2){
        	B *= 2;
        }else{
			B += K;
    	}
    }cout << B << endl;
}

Measured memory_bytes: 256
H, W  = map(int, input().split())

A = [[x for x in str(input())] for _ in range(H)]

x = 0
for h in range(H-1, -1, -1):
    if A[h].count('.') == W:
        del A[h]
        x += 1

for w in range(W-1, -1, -1):
    count = 0
    for h in range(H-x):
        if A[h][w] == '.':
            count += 1
    if count == H-x:
        for h in range(H-x-1, -1, -1):
            del A[h][w]

for h in range(H-x):
    print(''.join(A[h]))

Measured memory_bytes: 3188
// Libra

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;

	if (A+B > C+D)
		cout << "Left" << endl;
	else if (A+B == C+D)
		cout << "Balanced" << endl;
	else
		cout << "Right" << endl;

	return 0;
}


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


int main() {

	int n;	// さいころ数
	int k;	// 隣接するさいころの数

	int i;
	scanf("%d %d", &n, &k);

	double ex_value[n];

	int p[n];
	double cum_sum[n - k + 1];
	double tmp = 0;
	double index = 0;

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

	for (i = 0; i < n; i++) {
		ex_value[i] = (double)(1 + p[i]) / 2;
	}

	// 累積和
	for (i = 0; i < n; i++) {
		cum_sum[i] += ex_value[i];
		tmp += ex_value[i];
		if (i >= k) {
			tmp -= ex_value[i - k];
		}
		if (index < tmp) {
			index = tmp;
		}
	}

	printf("%.12f", index);

	return 0;


}


Measured memory_bytes: 4096
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll b = n/500 ;
	n %= 500 ;
	cout << b*1000+n/5*5 << endl ;
}


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

int n;

int main(){
	std::string s;
	std::cin >> s;
	std::cin >> n;
	int ans = 0;
	for (int i = 0; i < n; ++i){
		std::string h;
		std::cin >> h;
		h += h;
		if (h.find(s) != std::string::npos){
			ans++;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1212
N, Y = map(int, input().split())
Y = Y//1000
for i in range(N+1):
  for j in range(N+1): 
    k = N-i-j
    if 10*i+5*j+k == Y and 0 <= k <= N:
      print(i, j, k)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int N = 1e2 + 10;



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

    ll n, k;
    cin >> n >> k;
    cout << n % k;
    
    return 0;
}


Measured memory_bytes: 764
n=int(input())
A=[int(i) for i in input().split()]
A.append(0)
D=[abs(A[0])]
for i in range(n-1):
  D+=[abs(A[i]-A[i+1])]
D.append(abs(A[n-1]))
d=sum(D)
for i in range(n):
  print(d+abs(A[i-1]-A[i+1])-D[i]-D[i+1])

Measured memory_bytes: 14048
#include <iostream>

int main(int argc, char *argv[]) {
	int S, h, m, s;
	std::cin >> S;
	s = S % 60;
	S /= 60;
	m = S % 60;
	h = S / 60;
	std::cout << h << ":" << m << ":" << s << std::endl;
	return 0;
}

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

constexpr int ArgNum = 3;

int main()
{
	int n;
	int count5 = 0;
	int count7 = 0;

	for (int i = 0; i < ArgNum; ++i)
	{
		cin >> n;
		if (n == 5) ++count5;
		if (n == 7) ++count7;
	}

	if (count5 == 2 && count7 == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

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

namespace ABC118A
{
    class Program
    {
        static void Main(string[] args)
        {


                    var word = Console.ReadLine().Split();
                    int a = int.Parse(word[0]);
                    int b = int.Parse(word[1]);
                    int max = 0;

            if (b % a == 0)
            {
                max = a + b;
               

            }
            else
                max = b - a;
                    Console.WriteLine(max);
                    Console.ReadKey();



                }
            }
        }



Measured memory_bytes: 11092
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL n,k,a[200005];
LL pre[200005] = {0};
map <LL,LL> mp;
LL tot = 0;

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i]; a[i] --; a[i] %= k;
		pre[i] = pre[i - 1] + a[i]; pre[i] %= k;
	}
	mp[pre[0]] = 1;
	for(LL i = 1;i <= n;i ++){
		if(i >= k) mp[pre[i - k]] --;
		tot += mp[pre[i]];
		mp[pre[i]] ++;
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <cassert>
#include <iostream>
#include <vector>

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

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  // Input
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (auto &a : A)
    std::cin >> a;

  // Main
  std::vector<int> left(N + 1, 0);
  std::vector<int> right(N + 1, 0);
  for (int i = 1; i <= N; ++i)
    left[i] = gcd(A[i - 1], left[i - 1]);
  for (int i = N - 1; i >= 0; --i)
    right[i] = gcd(A[i], right[i + 1]);

  // Output
  int res = 0;
  for (int i = 0; i < N; ++i)
    chmax(res, gcd(left[i], right[i + 1]));
  std::cout << res << std::endl;

  return 0;
}


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

enum color {red, blue};

vector<vector<int>> to(200000);
vector<int> v_red;
vector<int> v_blue;

void dfs(int v, color c, int prev)
{
  if (c == red) {
    v_red.push_back(v);
  } else {
    v_blue.push_back(v);
  }
  for (auto next : to.at(v)) {
    if (next == prev) continue;
    dfs(next, c == red ? blue : red, v);
  }
}

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

  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }

  dfs(0, red, -1);

  vector<int> v = {1, 3, 2};
  if (v_red.size() > v_blue.size()) swap(v_red, v_blue);
  if (v_red.size() <= size_t(n / 3)) swap(v[0], v[1]);
  v_red.insert(end(v_red), begin(v_blue), end(v_blue));

  vector<int> v123;
  for (const auto& i : v) {
    for (int j = i; j <= n; j += 3) {
      v123.push_back(j);
    }
  }

  vector<int> ans(n);

  for (int i = 0; i < n; i++) {
    ans.at(v_red.at(i)) = v123.at(i);
  }

  for (int i = 0; i < n; i++) {
    cout << ans.at(i) << (i == n - 1 ? '\n' : ' ');
  }
}


Measured memory_bytes: 22472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;
	cin>>n;
	vector<int>v;
	for(int i=0;i<n;i++){
		int a;cin>>a;
		v.push_back(a);
	}
	int now=1;
	for(int i=0;i<v.size();i++){
		if(v[i]==now){
			now++;
		}
	}
	if(now==1){cout<<-1<<endl;}
	else{
		cout<<n-(now-1)<<endl;
	}
	return 0;
}


Measured memory_bytes: 4336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        String str;
        BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
        while ((str = bReader.readLine()) != null) {
            String[] editedStr = str.split(" ");
            Arrays.sort(editedStr);
            System.out.println(FindGCD(Long.parseLong(editedStr[0]), Long.parseLong(editedStr[1])) + " " + FindLCM(Long.parseLong(editedStr[0]), Long.parseLong(editedStr[1])));
        }
    }

    public static long FindGCD(long a, long b){
        long r = a % b;
        while (r > 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }

    public static long FindLCM(long a, long b) {
        return (a * b) / FindGCD(a, b);
    }
}

Measured memory_bytes: 9164
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<string>a(n), b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int tmp = -5;
	int count = 0;
	for (int k = 0; k <= n - m; k++) {
		tmp = -5;
		for (int i = 0; i < m; i++) {
			if (count == m) {
				break;
			}
			int s = a[i + k].find(b[i]);
			int s1 = a[i + k].find(b[i], s + 1);
			int s2 = a[i + k].find(b[i], s1 + 1);
			int s3 = a[i + k].find(b[i], s2 + 1);

			if (s == tmp || (s != -1 && tmp == -5)) {
				tmp = s;
				count++;
			}
			else if (s1 == tmp || (s1 != -1 && tmp == -5)) {
				tmp = s1;
				count++;
			}
			else if (s2 == tmp || (s2 != -1 && tmp == -5)) {
				tmp = s2;
				count++;
			}
			else if (s3 == tmp || (s3 != -1 && tmp == -5)) {
				tmp = s3;
				count++;
			}
			else {
				if (count == m) {
					break;
				}
				count = 0;
				i = m;
			}
		}
	}
	if (count == m) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}







Measured memory_bytes: 256
#include<map>
#include<cstdio>

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		int ans=-1;
		map<int,int> num;
		for(int i=0;i<n;i++){
			int c;	scanf("%d",&c);
			num[c]++;
			if(2*num[c]>n)	ans=c;
		}

		if(~ans)	printf("%d\n",ans);
		else		puts("NO COLOR");
	}

	return 0;
}

Measured memory_bytes: 1852
#include<bits/stdc++.h>
using namespace std;
int a[45];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int sum=0;
  int ans=0;
  for(int i=0;i<n;i++){
    sum=0;
    for(int j=0;j<i;j++){
      if(a[i]<a[j]){
        sum++;
      }
    }
    if(sum==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools
import math

def main():

    K = int(input())
    K_list = list(range(1, K+1))
    sum = 0

    combi=  list(itertools.combinations_with_replacement(K_list, 3))

    for tup_ in combi:
        
        dup = len(set(tup_))
        if dup == 3:
            coef = 6
        elif dup == 2:
            coef = 3
        else:
            coef = 1
        i, j, k = tup_
        sum += coef * math.gcd(math.gcd(i,j), k)

    print(sum)
if __name__ == "__main__":
    main()

Measured memory_bytes: 105692
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b; cin>>a>>b;
	ote(max(0, a-(b*2)));
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
        public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            while (true) {
                int H = sc.nextInt();
                int W= sc.nextInt();
                if (H == 0 && W == 0) {
                    break;
                }else{
                    for(int i=0;i<H;i++){
                        for(int j=0;j<W;j++){
                            System.out.print("#");


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

                }

            }
        }
    }


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++){
      cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    int64_t ans = A[0];
    for (int i = 1; i < N - 1; i++){
      ans += A[(i + 1) / 2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  ll a;
  map<ll, ll> cnt;
  rep(i, N){
    cin >> a;
    cnt[a]++;
  }

  ll ans = 0;

  for(auto it = cnt.begin(); it != cnt.end(); it++){
    if(it->first != it->second){
      if(it->first > it->second) ans += it->second;
      else ans += it->second - it->first;
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 6272
n=int(input())
cardpoints=list(map(int,input().split()))

alicep=0
bobp=0

for i in range(n):
	if i%2 == 0:
		alicep += max(cardpoints)
		cardpoints.remove(max(cardpoints))
	else:
		bobp += max(cardpoints)
		cardpoints.remove(max(cardpoints))

print(alicep-bobp)

Measured memory_bytes: 3060
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
    int a, b, c ;
    cin >>a>>b>>c;
    if (b > c)
        swap(b, c);
    if (a > b)
        swap(a, b);
    if (b > c)
        swap(b, c);
    cout << a << " " << b <<" " << c << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
 
using namespace std;
 
#define MAX_LETTERS  12
 
const char Alphabet[5] = "ACGT";

const int power[MAX_LETTERS + 1] = { 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216 };
 
int cipher(string S)
{
    int Ans = 0;
    
    unsigned size_ = S.size();
 
    for (unsigned i = 0; i < size_; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (Alphabet[j] == S[i])
            {
                Ans += power[size_ - i - 1] * j;
            }
        }
    }
 
    return Ans;
}
 
int main()
{
    vector<vector<bool> > D;
 
    unsigned n;
 
    for (int i = 0; i <= MAX_LETTERS; i++)
    {
        D.push_back(vector<bool>(power[i], false));
    }
 
    scanf("%d", &n);
 
    vector<string> W;
 
    vector<bool> F(n);
 
    for (unsigned i = 0; i < n; i++)
    {
        char S1[20], S2[20];
 
        scanf("%s%s", &S1, &S2);
 
        if (S1[0] == 'f')
        {
            F[i] = true;
        }
 
        W.push_back(S2);
    }
 
    for (unsigned i = 0; i < n; i++)
    {
        if (F[i] == false)
        {
            D[W[i].size()][cipher(W[i])] = true;
        }
        else
        {
            printf("%s\n", (D[W[i].size()][cipher(W[i])] ? "yes" : "no"));
        }
    }
 
    return 0;
}

Measured memory_bytes: 59980
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, K := getInt(), getInt()
	p := make([]int, N)
	for i := 0; i < N; i++ {
		p[i] = getInt()
	}
	sort.Ints(p)
	ans := 0
	for i := 0; i < K; i++ {
		ans += p[i]
	}
	out(ans)
}


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

int main () {
    
    int n = 0, a = 0, w = 0;
    std::map < int, bool > is;
    std::map < int, bool >::iterator it;

    scanf ("%d", &n);
    while (n--) {
        scanf ("%d", &a);
        if (is [a]) {
            is [a] = 0;
        } else {
            is [a] = 1;
        }
    }
    
    for (it = is.begin(); it != is.end(); ++it) {
        if (it->second == 1) ++w;
    }
    printf ("%d\n", w);
    return 0;
}

Measured memory_bytes: 4992
ab = []

ab.append(int(input()))
ab.append(int(input()))

def solve():
  if 1 not in ab:
    print(1)
  elif 2 not in ab:
    print(2)
  
  elif 3 not in ab:
    print(3)

def main():
  solve()

if __name__ == "__main__":
  main()

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    S=input()
    a,b=0,0
    for i in range(N):
        if S[i]=='(':
            b+=1
        else:
            if b==0:
                a+=1
            else:
                b-=1
    print('('*a+S+')'*b)
            

if __name__ == '__main__':
    main()


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;

ll solve(ll h, ll w){
    ll s = h*w;
    for(ll wx = 1; wx <= w; wx++){
        vector<ll> v;
        v.push_back(h*wx);
        if(h%2 == 0 || (w-wx)%2 == 0){
            v.push_back(h*(w-wx)/2);
            v.push_back(h*(w-wx)/2);
        }
        else if(h < w-wx){
            v.push_back(h*(w-wx-1)/2+h);
            v.push_back(h*(w-wx-1)/2);
        }
        else{
            v.push_back((h-1)*(w-wx)/2+(w-wx));
            v.push_back((h-1)*(w-wx)/2);
        }
        sort(v.begin(), v.end());
        s = min(s, (v[2]-v[0]));
    }
    return s;
}

int main(){
    ll h, w;
    cin >> h >> w;

    ll s = solve(h, w);
    s = min(s, solve(w, h));

    cout << s << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int mx = max({a, b, c});
    if(mx == a){
        cout << "A\n";
    }else if(mx == b){
        cout << "B\n";
    }else{
        cout << "C\n";
    }
    return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll l,r,d;
    cin>>l>>r>>d;
    ll ans=r/d;
    if(l%d==0) ans-=(l/d-1);
    else ans-=l/d;
    cout<<ans<<endl;



}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve(); 


    return 0;
}


Measured memory_bytes: 3648
import numpy as np
from functools import reduce

N, M, K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))


def get_cum(arr):
    cum_arr = [0]
    for e in arr:
        tot = cum_arr[-1] + e
        if tot > K:
            return cum_arr
        cum_arr.append(tot)
    return cum_arr


cumA = get_cum(As)
cumB = get_cum(Bs)

max_count = 0
a_thresh = len(cumA) - 1
a_count = a_thresh
b_count = 0
b_thresh = len(cumB) - 1
while a_count >= 0 and b_count <= b_thresh:
    while b_count <= b_thresh and cumA[a_count] + cumB[b_count] <= K:
        b_count += 1
    b_count = max(0, b_count - 1)
    if cumA[a_count] + cumB[b_count] <= K:
        max_count = max(max_count, a_count + b_count)
    a_count -= 1

print(max_count)


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

using namespace std;

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  int ans = 1e9;
  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
  }
  for (unsigned i = 0; i < 1 << D; ++i) {
    int cnt = 0, sum = 0;    
    for (int j = 0; j < D; ++j) {
      if (i >> j & 1) {
	cnt += p[j] ;
	sum += p[j] * (j + 1) * 100 + c[j];
      }
    }
    for (int j = D - 1;; --j) {
      if (G <= sum) {
	ans = min(ans, cnt);
	break;
      }
      if (j < 0) break;
      if (!(i >> j & 1)) {
	int tmp = (G - sum - 1) / ((j + 1) * 100) + 1;
	if (tmp >= p[j]) tmp = p[j] - 1;
	cnt += tmp;
	sum += tmp * (j + 1) * 100;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

#define LL long long

LL N, M;
LL MAX_L = 1234567812345678;
vector<vector<pair<LL, LL> > > G;
 
LL maxFlow(LL a, LL b){
    LL F = 0;
    while(true){
        queue<LL> Q;
        vector<LL> used(N, -1), pred(N, -1), cap(N);
        Q.push(a);
        used[a] = 0;
        cap[a] = MAX_L;
        while(Q.size() != 0){
            LL v = Q.front();
            Q.pop();
            for(LL w = 0; w < N; w++){
                LL f1 = G[v][w].first, f2 = G[w][v].first, c = G[v][w].second, r = c - f1 + f2;
                if(r > 0 && used[w] == -1){
                    used[w] = used[v]++;
                    pred[w] = v;
                    cap[w] = min(cap[v], r);
                    Q.push(w);
                }
            }
        }
        if(used[b] == -1) break;
        F += cap[b];
        LL v = b;
        while(v != a){
            LL w = pred[v], f1 = G[w][v].first, f2 = G[v][w].first, c = G[w][v].second, o = min(f2, cap[b]);
            G[v][w].first -= o;
            G[w][v].first += cap[b] - o;
            v = w;
        }
    }
    return F;
}
 
 
int main(){

    // 1. 入力情報.
    scanf("%d %d", &N, &M);
    
    // 2. グラフ.
    G.resize(N, vector<pair<LL, LL> >(N, {0, 0}));
    for(LL m = 0; m < M; m++){
        LL A, B, C;
        scanf("%d %d %d", &A, &B, &C);
        G[A][B].second = C;
    }
    
    // 3. 出力.
    cout << maxFlow(0, N - 1) << endl;
    return 0;

}



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

namespace ABC124 {
	class ABC124_A {
		static void Main(string[] args) {
			// ABの入力を受け付け、intでパースする
			// 合計を保存するための変数を用意する
			// ABの数字を比較して、大きい方の値を合計の変数に加算する
			// その処理を2回繰り返す

			var AB = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			var A = AB[0];
			var B = AB[1];

			var total = 0;
			for (int i = 0; i < 2; i++) {
				if (A > B) {
					total += A--;
				} else {
					total += B--;
				}
			}

			Console.WriteLine(total.ToString());
		}
	}
}


Measured memory_bytes: 13268
#include<cstdio>
#include<cstring>
int n, m, field[11][11], si, sj, num;

int dfs(int x, int y){
  int ans = 0;
  if(num == 0){
    if(x == si || y == sj)return 1;
    else return 0;
  }
  field[x][y] = 0;
  for(int i = x + 1;i < m;i++){
    if(field[i][y] == 1){
      num--;
      ans += dfs(i, y);
      num++;
      break;
    }
  } 
  for(int i = x - 1;i >= 0;i--){
    if(field[i][y] == 1){
      num--;
      ans += dfs(i, y);
      num++;
      break;
    }
  } 
  for(int i = y + 1;i < n;i++){
    if(field[x][i] == 1){
      num--;
      ans += dfs(x, i);
      num++;
      break;
    }
  } 
  for(int i = y - 1;i >= 0;i--){
    if(field[x][i] == 1){
      num--;
      ans += dfs(x, i);
      num++;
      break;
    }
  }  
  field[x][y] = 1;
  return ans;
}

int main(){
  while(1){
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0)return 0;
    memset(field, 0, sizeof(field));
    num = 0;
    for(int i = 0;i < m;i++){
      for(int j = 0;j < n;j++){
	scanf("%d", &field[i][j]);
	if(field[i][j] == 2){
	  si = i;
	  sj = j;
	}
	else num += field[i][j];
      }
    }
    printf("%d\n", dfs(si, sj));
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, K;
  cin >> N >> K;
  N -= N/K * K;
  cout << min(N, abs(N-K)) << endl;
}

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

int n, a, b;
string sa, sb;

int main() {
  cin>>n;
  for(int i=0;i<n;++i) {
    cin>>sa>>sb;
    if(sa>sb)a+=3;
    else if(sb>sa)b+=3;
    else {
      a+=1;
      b+=1;
    }
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 1208
N = int(input())
A = list(map(int, input().split()))

l = r = 0
now = 0
ans = 0
temp = 0
while r < N:
  if now ^ A[r] == now + A[r]:
    ans += temp + 1
    temp += 1
    now += A[r]
    r += 1
  else:
    temp = max(temp - 1, 0)
    now -= A[l]
    l += 1

print(ans)

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

#define ll long long

#define rep(i, a, b) for (int i = a; i < b; i++)
#define For(i, a, b) for (int i = a; i <= b; i++)

using namespace std;

const int mod = 1000000000 + 7;
const int MAXN = 300000 + 5;

char s[MAXN];
int countE[MAXN], countW[MAXN];
int n;

int main() {
    scanf("%d%s", &n, &s);
    int ans = INT32_MAX;
    for (int i = 0; i < n; i++) {
        countW[i + 1] += countW[i];
        countE[i + 1] += countE[i];
        if (s[i] == 'W')
            countW[i + 1]++;
        else
            countE[i + 1]++;
    }
    for (int i = 1; i <= n; i++) {
        ans = min(ans, countW[i - 1] + countE[n] - countE[i]);
    }
    printf("%d", ans);
};

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll N, sum = 0; cin >> N;
  rep(i, 1, N + 1) {
  	if ((i % 3 != 0) && (i % 5 != 0)) {
  		sum += i;
  	}
  }
  cout << sum << endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

struct s{
  int a;
  int b;
  double c;
};

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n,k;

  cin >> n >> k;

  vector<int> p(n);
  REP(i,n) cin >> p[i];
  
  vector<double> l(n,0);

  REP(i,n){
    REP(j,p[i]){
      l[i] += (1.0 / p[i]) * (j + 1);
    }
  }

  vector<double> sum(n - k + 1,0);
  REP(i,k) sum[0] += l[i];
  FOR(i,1,n - k + 1){
    sum[i] = sum[i - 1] + l[i + k - 1] - l[i - 1];
  }

  auto it = max_element(sum.begin(), sum.end());
  int index = distance(sum.begin(), it);
  cout << fixed;
  cout << sum[index] << endl;
  return 0;
}

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

int main()
{
	int mc=0;
	string str,mlstr="";
	map<string,int> m;
	while(cin >> str)
	{
		if(!(m.insert(pair<string,int>(str,1)).second))
		{
			m[str]++;
		}
		mc = (m[str]>mc ? m[str] : mc);
		mlstr = (str.length()>mlstr.length() ? str : mlstr); 
	}
	
	map<string,int>::iterator it;
	for(it=m.begin(); it!=m.end(); it++)
	{
		if(mc==it->second)
		{
			cout << it->first;
		}
	}
	cout << " " << mlstr << endl;
}

Measured memory_bytes: 0
#include <cstdio>

using namespace std;
int h,w,i,j;
char a[504][504],b[504][504],x;
int main()
{
    scanf ("%d %d\n", &h, &w);
    for (i=1;i<=h;i++)
        for (j=1;j<=w;j++)
        {
            a[i][j]='.';
            b[i][j]='.';
        }
    for (i=1;i<=w;i++)
    {
        if (i%2==1)
        {
            for (j=1;j<h;j++)
                a[j][i]='#';
        }
        else
            a[1][i]='#';
    }
    for (i=1;i<=w;i++)
    {
        if (i%2==0)
        {
            for (j=h;j>1;j--)
                b[j][i]='#';
        }
        else
            b[h][i]='#';
    }
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
        {
            scanf ("%c", &x);
            if (x=='#')
            {
                a[i][j]='#';
                b[i][j]='#';
            }
        }
        scanf ("%c", &x);
    }
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
            printf ("%c", a[i][j]);
        printf ("\n");
    }
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
            printf ("%c", b[i][j]);
        printf ("\n");
    }
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] maze = new char[h][w];
        int[][] distance = new int[h][w];
        int countBlack = 0;
        for(int row = 0; row < h; row++) {
            String str = sc.next();
            for(int col = 0; col < w; col++) {
                char c = str.charAt(col);
                maze[row][col] = c;
                distance[row][col] = -1;
                if(c == '#') countBlack++;
            }
        }
        ArrayDeque<Pair> queue = new ArrayDeque<>();
        queue.addLast(new Pair(0, 0));
        maze[0][0] = '#';
        int counter = 1;
        int[] dy = {1, 0, -1, 0};
        int[] dx = {0, 1, 0, -1};
        while(!queue.isEmpty()) {
            int size = queue.size();
            while(size != 0) {
                Pair p = queue.removeFirst();
                distance[p.y][p.x] = counter;
                for(int i = 0; i < 4; i++) {
                    int newRow = p.y + dy[i];
                    int newCol = p.x + dx[i];
                    if(newRow >= 0 && newCol >= 0 && newRow < h && newCol < w && maze[newRow][newCol] == '.') {
                        queue.addLast(new Pair(newCol, newRow));
                        maze[newRow][newCol] = '#';
                    }
                }
                size--;
            }
            counter++;
        }
        if (distance[h-1][w-1] == -1) {
            System.out.println(-1);
        } else {
            System.out.println((h * w) - countBlack - distance[h-1][w-1]);
        }
    }

    private static class Pair{
        int x;
        int y;
        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 22740
def main():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]

    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]

    mod = 10**9+7
    fact = [1, 1]
    inv = [pow(i, mod-2, mod) for i in range(n+1)]
    for i in range(2, n+1):
        fact.append(fact[-1]*i % mod)

    class Rerooting():
        def __init__(self):
            # merge:頂点aにbをマージするときのモノイド
            # adj_bu:ボトムアップ時の調整（a:値,i:頂点）
            # adj_td:トップダウン時の調整（a:値,i:頂点,p:親）
            # （根方向への調整と考えるとわかりやすい）
            # adj_fin:最終調整（a:値,i:頂点）
            def merge(a, b): return a * b % mod
            def adj_bu(a, i): return a * inv[size[i]] % mod
            def adj_td(a, i, p): return a * inv[n-size[i]] % mod
            def adj_fin(a, i): return a * fact[n-1] % mod

            # トポロジカルソートをする
            # T:木の隣接グラフ表現をset化
            # P:親
            # q:キュー
            # order:トポソしたもの
            T = g
            P = [-1]*n
            q = [0]
            ini = 1
            order = []
            while q:
                i = q.pop()
                order.append(i)
                for a in T[i]:
                    if a != P[i]:
                        P[a] = i
                        T[a].remove(i)
                        q.append(a)

            T = [list(i) for i in T]

            # サイズの処理を先に行う
            # size[i]:0を根とする根付き木における、iを根とする部分木の大きさ
            size = [1]*n
            for i in order[1:][::-1]:
                size[P[i]] += size[i]

            # ボトムアップ処理をする
            # ME:マージした値を一時保存
            # DP:DP値、MEを調整したもの
            ME = [ini]*n
            DP = [0]*n
            for i in order[1:][::-1]:
                DP[i] = adj_bu(ME[i], i)
                p = P[i]
                ME[p] = merge(ME[p], DP[i])
            DP[order[0]] = adj_fin(ME[order[0]], order[0])
            TD = [ini]*n

            # トップダウン処理をする
            for i in order:
                # 左からDP（結果はTDに入れている）
                ac = TD[i]
                for j in T[i]:
                    TD[j] = ac
                    ac = merge(ac, DP[j])
                # 右からDP（結果はacに入れている、一度しか使わないのでacで問題ない）
                # 例えばjが1から4だったとすると、TD[j]にはそれぞれ
                # TD[1] = 無、TD[2] = DP[1]、TD[3] = DP[1]*DP[2]、TD[4] = DP[1]*DP[2]*DP[3]
                # が入っている。
                # ここでacにそれぞれ無、DP[4]、DP[3]*DP[4]、DP[2]*DP[3]*DP[4]を
                # 順に入れていくといい感じになることがわかる。
                # 最後にTDに欠けているのは本来の根方向への補正なので、
                # jの部分木以外のサイズの逆数を掛けてやる必要がある。
                # これで、TDには根方向、MEにはそれ以外の方向のDP値が入っている状態になっているので
                # あとは掛けてやるだけでよい。
                ac = ini
                for j in T[i][::-1]:
                    TD[j] = adj_td(merge(TD[j], ac), j, i)
                    ac = merge(ac, DP[j])
                    DP[j] = adj_fin(merge(ME[j], TD[j]), j)
            for i in DP:
                print(i)
    Rerooting()


main()


Measured memory_bytes: 144868
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int Maxn = 110;
const int Maxv = 100010;
const ll INF = (ll) 1e10;

ll dp[Maxn][Maxv], w[Maxn], v[Maxn];

int main() {
    int n, x;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    fill(dp[0], dp[0] + Maxv, INF);
    dp[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < Maxv; ++j) {
            dp[i + 1][j] = dp[i][j];
            if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }

    for (int i = Maxv - 1; i >= 0; --i) {
        if (dp[n][i] <= x) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 80256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l, r;
    cin >> l >> r;
    int d;
    cin >> d;
    int res = 0;
    for(int i = l; i <= r; i++) {
        if(i%d == 0) res++;
    }
    cout << res << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	ll n, p;
	cin >> n >> p;
	vector<int> dcnt(1e6 + 1);
	FOR(i, 2, 1e6) {
		while (p%i == 0) {
			dcnt[i]++;
			p /= i;
		}
	}
	ll res = 1;
	FOR(i, 2, 1e6) {
		while (dcnt[i] >= n) {
			res *= i;
			dcnt[i] -= n;
		}
	}
	if (n == 1) {
		res *= p;
	}
	pv(res)
	return 0;
}

Measured memory_bytes: 7196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		String answer = "";

		while (N > 0) {
			N--;
			answer = (char) ('a' + (N % 26)) + answer;
			N = N / 26;
		}

		System.out.println(answer);
	}

}

Measured memory_bytes: 39256
#include<cstdio>
#define je 1000000007
char str[2][60];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",str[0]);
	scanf("%s",str[1]);
	//printf("%s\n%s\n",str[0], str[1]);
	int lft = 0;
	long long ans = 1;
	for(int i=0;i<n;i++){
		if(str[0][i] == str[0][i+1]){
			if(lft == 0) ans = (ans * 6) % je;
			if(lft == 1) ans = (ans * 2) % je;
			if(lft == 2) ans = (ans * 3) % je;
			lft = 2;
			i++;
		}else{
			if(lft == 0) ans = (ans * 3) % je;
			if(lft == 1) ans = (ans * 2) % je;
			if(lft == 2) ans = ans;
			lft = 1;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128