akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, t) cin >> a[i];

  int c = *max_element(a.begin(), a.end()), ans = 0;
  rep(i, c - (k + 1) / 2) {
    if (!i && k % 2 == 0) ans++;
    else ans += 2;
  }
  cout << ans << '\n';



  
  return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int minus = 0;
    bool zero = false;
    ll sum = 0;
    rep(i, N){
        cin >> A[i];
        if(A[i] == 0){
            zero = true;
        } else if (A[i] < 0){
            minus++;
            A[i] *= -1;
        }
        sum += A[i];
    }
    if(minus % 2 == 0 || zero ){
        cout << sum << endl;
    } else {
        sort(all(A));
        sum -= 2 * A[0];
        cout << sum << endl;
    }

}

Measured memory_bytes: 640
#coding: utf-8
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 2):
    for j in range(i+1, N-1):
        idx = bisect_left(L, L[i]+L[j]) - 1 - j
        ans += idx
print(ans)

Measured memory_bytes: 3316
import java.util.*;

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

Measured memory_bytes: 35880
(defmacro inner-input []
  '(->> (clojure.string/split (read-line) #"\s")
     (map #(Integer/parseInt %))))

(defn input []
  (let [[N] (inner-input)
        [D X] (inner-input)]
    (list N D X
      (loop [n N As '()]
        (if (zero? n)
          As
          (recur (dec n) (concat As (inner-input))))))))

(defn Chocolate [[N D X As]]
  (->> As
    (map #(count (range 1 (inc D) %)))
    (apply +)
    (+ X)))

(-> (input)
  Chocolate
  println)

Measured memory_bytes: 67900
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <complex>
using namespace std;

typedef complex<int> P;

namespace std {
	bool operator < (const P &a, const P &b) {
		if (a.real() == b.real()) return a.imag() < b.imag();
		else return a.real() < b.real();
	}
};


int main() {
	P p_dir[12] = {
		P(2, -1),  P(2, 0),  P(2, 1),
		P(-2, -1), P(-2, 0), P(-2, 1),
		P(-1, 2),  P(0, 2),  P(1, 2),
		P(-1, -2), P(0, -2), P(1, -2)
	};

	vector<P> now(1);
	while (cin >> now[0].real() >> now[0].imag(), now[0].real() || now[0].imag()) {
		int n; cin >> n;
		vector<P> sp;
		for (int i = 0; i < n; ++i) {
			int x, y; cin >> x >> y;
			sp.push_back( P(x, y) );
		}
		for (int t = 0; t < n; ++t) {
			vector<P> next;
			for (int i = 0; i < now.size(); ++i) {
				for (int j = 0; j < 12; ++j) {
					P p = now[i] + p_dir[j];
					if ( p.real() >= 0 && p.real() < 10 && p.imag() >= 0 && p.imag() < 10
						&& abs(p.real() - sp[t].real()) <= 1 && abs(p.imag() - sp[t].imag()) <= 1 )
						next.push_back(p);
				}
			}

			sort( next.begin(), next.end() );
			next.erase( unique( next.begin(), next.end() ), next.end() );
			now = next;
		}
		if (now.size()) cout << "OK" << endl;
		else cout << "NA" << endl;

		now.clear();
		now.resize(1);
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	string s;
	cin >> s;
	if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes";
	else cout <<"No";
}

Measured memory_bytes: 3652
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <stdio.h>
#include <string.h>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

char N[20];
uint64_t sum = 0;
void f(int i, uint64_t temp_sum, uint64_t last)
{
	if (N[i] == '\0') { sum += temp_sum + last; return; }
	f(i + 1, temp_sum + last, N[i] - '0');
	f(i + 1, temp_sum, last * 10 + N[i] - '0');
}

int main()
{
	cin >> N;
	f(1, 0, N[0] - '0');
	cout << sum << std::endl;
}


Measured memory_bytes: 3636
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
v = na()
v.sort()

s = 0
for i in range(n):
    s = s * 0.5 + v[i]
    if i == 0:
        s += v[i]
print("{:.14f}".format(s*0.5))


Measured memory_bytes: 3060
n = int(input())
def get_gcd(a, b): #最大公約数を求める関数
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return get_gcd(b, a % b)
def get_lcm(a, b, gcd): #みたまんまそういうやつです
    lcm = a * b // gcd
    return lcm
print(int((2 * n) / get_gcd(2,n)))

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long result = 0;
		for (int i = 1; i <= N; i++) {
			if (i % 5 == 0 || i % 3 == 0) {
				continue;
			} else {
				result += (long)i;
			}
		}
		System.out.println(result);
	}

}


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

void solve() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  while (true) {
    if (A < B) break;
    B *= 2;
    K--;
  }
  while (true) {
    if (B < C) break;
    C *= 2;
    K--;
  }
  cout << ((K >= 0) ? "Yes" : "No") << endl;
}

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

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

int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++)
    cin >> d.at(i);
  for(int i = 0; i < n - 1; i++)
    for(int j = i + 1; j < n; j++)
      sum += d.at(i) * d.at(j);
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int read(){
    char ch=getchar(); int w=1,c=0;
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
    for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);
    return w*c;
}
const int M=2e5+10;
char ch[M];
int n,A,B,C,D;
int L_bl(int l,int r){
	int len=0,mx=0;
	for (int i=l;i<=r;i++){
		if (ch[i]=='#') len++;
		else len=0;
		if (len>mx) mx=len;
	}
	return mx;
}
int L_sp(int l,int r){
	int len=0,mx=0;
	for (int i=l;i<=r;i++){
		if (ch[i]=='.') len++;
		else len=0;
		if (len>mx) mx=len;
	}
	return mx;
}
int main(){
	n=read(); A=read(); B=read(); C=read(); D=read();
	scanf("%s",ch+1);
	if (C>A && C<B){
		if (L_bl(A,C)<2 && L_bl(B,D)<2) printf("Yes\n");
		else printf("No\n");
	}
	if (C>B && C<D){
		if (L_bl(A,C)<2 && L_bl(B,D)<2) printf("Yes\n");
		else printf("No\n");
	}
	if (C>D){
		if (L_bl(A,C)<2 && L_bl(B,D)<2 && L_sp(B-1,D+1)>=3) printf("Yes\n");
		else printf("No\n");
	}
    return 0;
}



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

#define MAX_INT 0x3f3f3f3f 
#define precision(x) setprecision(x)
#define boost ios_base::sync_with_stdio(false); 	cin.tie(NULL);

int main()
{
	boost;
	int n;
	cin >> n;
	vector<vector<int> > v(n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			int p;
			cin >> p;
			v[i].push_back(p);
		}
	}
	vector<vector<int> > dp(n, vector<int> (3, 0));
	for(int i=0;i<n;i++)
	{	
		if(i==0)
		{
			dp[0][0]=v[0][0];
			dp[0][1]=v[0][1];
			dp[0][2]=v[0][2];
		}
		else
		{
			dp[i][0]=max(dp[i-1][1],dp[i-1][2]) + v[i][0];
			dp[i][1]=max(dp[i-1][0],dp[i-1][2]) + v[i][1];
			dp[i][2]=max(dp[i-1][1],dp[i-1][0]) + v[i][2];	
		}
	}
	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << "\n";
}

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

#A
def A():
    a, b = LI()
    ans = ['Odd', 'Even']
    print(ans[(a*b)%2-1])
    return

#B
def B():
    a, b = map(str,input().split())
    a = a + b
    if math.sqrt(int(a)).is_integer():
        print("Yes")
    else:
        print("No")
    return

#C
def C():
    n = II()
    pre = (0, 0, 0)
    for _ in range(n):
        t,x,y = LI()
        dist = abs(pre[0] - x) + abs(pre[1] - y)
        if dist <= t - pre[2] and dist % 2 == (t - pre[2]) % 2:
            pre = (x, y, t)
            continue
        print("No")
        return
    print("Yes")
    return

#D
def D():
    n, k = LI()
    dp = [[0] * (2 * k + 1) for i in range(2 * k + 1)]
    for _ in range(n):
        x, y, c = LS()
        x, y = int(x), int(y)
        if c == "W":
            dp[y % (2 * k) + 1][(x + k) % (2 * k) + 1] += 1
        else:
            dp[y % (2 * k) + 1][x % (2 * k) + 1] += 1
    for y in range(2 * k + 1):
        for x in range(1, 2 * k + 1):
            dp[y][x] += dp[y][x - 1]
    for y in range(1, 2 * k + 1):
        for x in range(2 * k + 1):
            dp[y][x] += dp[y - 1][x]
    
    def count(l, r, d, u):
        return dp[d][l] - dp[d][r] - dp[u][l] + dp[u][r]
    
    ans = 0
    for i in range(k):
        for j in range(k):
            tmp = count(j, j + k, i, i + k) + count(0, j, 0, i) + count(j + k, 2 * k, 0, i) + \
                 count(0, j, i + k, 2 * k) + count(j + k, 2 * k, i + k, 2 * k)
            ans = max(ans, tmp, n - tmp)
    print(ans)
    return

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


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

int main()
{

	int n;
	cin >> n;

	vector<int64_t> fib(n+1);
	fib[0]=1;
	fib[1]=1;

	for (int i=2;i<=n;++i)
	{
		fib[i]=fib[i-1]+fib[i-2];
	}
	cout << fib[n] << endl;
}








Measured memory_bytes: 3100
#include <stdio.h>

int n;
int d[110][2];

int main()
{
    for(int i=0;i<110;i++)
    {
        d[i][0]=-1;
        d[i][0]=-2;
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%d%d",&d[i][0],&d[i][1]);

    for(int i=0;i<n;i++)
    {
        if(d[i][0]==d[i][1])
        {
            if(d[i+1][0]==d[i+1][1]&&d[i+2][0]==d[i+2][1])
            {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <iterator>
using namespace std;
int main(void){
    string a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"EQUAL";
    }else if(a.size()==b.size()){
        for(int i=0;i<a.size();i++){
            if(a[i]<b[i]){
                cout<<"LESS";
                return 0;
            }else{
                cout<<"GREATER";
                return 0;
            }
        }
    }else if(a.size()<b.size()){
        cout<<"LESS";
    }else{
        cout<<"GREATER";
    }
}


Measured memory_bytes: 256
s=input()
n=len(s)
a=[]
for i in range(1<<(n-1)):
 c=""
 for j in range(n-1):
   if i>>j & 1:
     b="+"
   else:
     b=""
   c+=s[j]+b
 c+=s[-1]
 a.append(c)
k=0
for i in a:
  for j in i.split("+"):
    k+=int(j)
print(k)

Measured memory_bytes: 39792
#include <iostream>
#include <string>
#include <iomanip>

int main(int argc, char *argv[])
{
    int k, a, b;
    bool ans = false;

    std::cin >> k >> a >> b;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {ans = true;}
    }

    if (ans) {
        std::cout << "OK" << std::endl;
    } else {
        std::cout << "NG" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mod 1e9+7
int main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);
  string s;
  cin>>s;
  int c=0;
	for(int i=0;i<3;i++)
      if(s[i]=='R')
        c++;
  if(c==2&&s[1]=='S')
    cout<<"1";
  else 
    cout<<c;
    
}

Measured memory_bytes: 3616
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  ll kmax = 61;
  vll c0s(kmax, 0);

  rep(i, n){
    ll a;
    cin >> a;
    rep(j, kmax){
      c0s[j] += a%2;
      a >>= 1;
    }
  }

  ll const mod = 1000000007;
  ll ans = 0;

  ll rui = 1;
  rep(j, kmax){
    ll c0 = c0s[j], c1 = n - c0s[j];
    ll add = ((c0*c1)%mod * rui) % mod;
    ans += add;
    ans %= mod;
    rui <<= 1;
    rui %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3580
def main():
  import itertools
  n,m=map(int,input().split())
  li=[list(map(int,input().split()))[1:] for _ in range(m)]
  p=tuple(map(int,input().split()))
  
  q=set(sum(li,[]))
  r=set(range(1,n+1))
  v=r-q
  
  ans=0
  
  for i in range(0,len(q)+1):
    for s in itertools.combinations(q,i):
      for u,w in zip(li,p):
        s=set(s)
        if len(s&set(u))%2!=w:
          break
      else:
        ans+=2**(len(v))
   
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

pair<double, double> rotate(double alpha, double x, double y, double len){
  double nx = cos(alpha) * x - sin(alpha) * y;
  double ny = sin(alpha) * x + cos(alpha) * y;

  nx *= len;
  ny *= len;

  return make_pair(nx, ny);
}

int main(){
  double A, B, H, M;
  cin >> A >> B >> H >> M;

  double hour_radian = (H/6) * PI + (M/360) * PI;
  pair<double, double> hour_p = rotate(hour_radian, 0.0, 1.0, A);

  double min_radian = (M/30) * PI;
  pair<double, double> min_p = rotate(min_radian, 0.0, 1.0, B);

  double x2 = (hour_p.first - min_p.first)*(hour_p.first - min_p.first);
  double y2 = (hour_p.second - min_p.second)*(hour_p.second - min_p.second);
  double ans = sqrt(x2+y2);

  printf("%.20f\n", ans);

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A[N+2];
    A[0] = 0;
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    A[N+1] = 0;

    int sum = 0;
    for(int i=0;i<=N;i++){
        sum += abs(A[i] - A[i+1]);
    }

    for(int i=1;i<=N;i++){
        cout << sum + abs(A[i-1] - A[i+1]) - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) << endl;
    }

    return 0;
}

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

namespace AC
{
    class Program
    {
        static int R;
        static int S;
        static int P;
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var K = input[1];
            input = ReadArrayInt();
            R = input[0];
            S = input[1];
            P = input[2];
            var T = Read();
            var used = new bool[N];
            var ans = 0L;
            for (int i = 0; i < N; i++)
            {
                if (used[i]) continue;
                for (int j = i; j < N; j += K)
                {
                    if (used[j]) break;
                    used[j] = true;
                    if (j + K >= N) ans += RSP(WinRSP(T[j]));
                    else
                    {
                        if (T[j] == T[j + K])
                        {
                            if (j + 2 * K >= N) continue;
                            ans += RSP(WinRSP(T[j]));
                            used[j + K] = true;
                            j += K;
                        }
                        else ans += RSP(WinRSP(T[j]));
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static char WinRSP(char c)
        {
            char ret = ' ';
            if (c == 'r') ret = 'p';
            else if (c == 's') ret = 'r';
            else if (c == 'p') ret = 's';
            return ret;
        }

        static long RSP(char c)
        {
            long ret = 0;
            if (c == 'r') ret = R;
            else if (c == 's') ret = S;
            else if (c == 'p') ret = P;
            return ret;
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13664
/// NHDanDz
#include <bits/stdc++.h>
#define nmax 3000005
#define MOD 10000000000007
#define F first
#define S second
#define PB push_back
#define reset(a) memset(a,0,sizeof(a))
#define pii pair<int,int>
#define ll long long
#define Task "D"
#define endl '\n'
#define sz() size()
#define forinc(a,b,c) for(int a = b; a <= c; a++)
#define fordec(a,b,c) for(int a = b; a >= c; a--)
using namespace std;
int n , root[nmax];
struct hd
{
    int x,y,id;
}a[nmax];
struct ha
{
    int u,v,w;
}d[nmax];
bool cmp1(hd a, hd b)
{
    if(a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}
bool cmp2(hd a, hd b)
{
    if(a.y==b.y)
        return a.x < b.x;
    return a.y < b.y;
}
int get_root(int u){
    return root[u] ? (root[u] = get_root(root[u])) : u ;
}
void READ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    forinc(i,1,n)
    {
        a[i].id = i;
        cin >> a[i].x >> a[i].y;
    }
    sort(a + 1, a + 1 + n, cmp1);
    forinc(i,1,n - 1)
    {
        d[i].u = a[i].id;
        d[i].v = a[i + 1].id;
        d[i].w = min(abs(a[i + 1].x - a[i].x),abs(a[i + 1].y - a[i].y));;
    }
    sort(a + 1, a + 1 + n, cmp2);
    forinc(i,1,n - 1)
    {
        d[i + n - 1].u = a[i].id;
        d[i + n - 1].v = a[i + 1].id;
        d[i + n - 1].w = min(abs(a[i + 1].x - a[i].x),abs(a[i + 1].y - a[i].y));
    }
}
bool cmp3(ha a,ha b)
{
    return a.w < b.w;
}
void SOLVE()
{
    ll ans(0);
    sort(d + 1, d + 1 + 2*n -2,cmp3);
    forinc(i,1,2*n - 2)
    {
        int p = get_root(d[i].u) , q = get_root(d[i].v);
        //cout << p << " " << q << endl;
        if(p != q)
        {
            root[p] = q;
            ans += d[i].w;
        }
    }
    cout << ans;
}
int main()
{
    READ();
    SOLVE();
    return 0;
}


Measured memory_bytes: 8448
//mo algo (no square root decomposition)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define int long long int
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}

#define int long long int
int32_t main(){
	int n;
  cin>>n;
  n = 1LL*180*(n-2);
  cout<<n;
}

Measured memory_bytes: 256
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/


int main()
{
	long long n, m, s;
	
	scanf("%lld%lld", &n, &m);
	if (n * 2 >= m) {
		s = m / 2;
	} else {
		s = n + (m - n * 2) / 4;
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 256
#include <stdio.h>

int linearSearch(int a[],int n, int key);

int main(void)
{
	int n;
	scanf("%d",&n);
	int i;
	int s[n];
	for( i = 0; i < n; i++)
	{
		scanf("%d",&s[i]);
	}
	int q;
	scanf("%d",&q);
	int t[q];
	int j=0;
	
	for( i = 0; i < q; i++)
	{
		scanf("%d",&t[i]);
	}
	
	for( i = 0; i < q; i++)
	{
		j += linearSearch(s,n,t[i]);
		
	}
	printf("%d\n",j);
	return 0;
}

int linearSearch(int a[] , int n, int key)
{
	int i;
	for( i = 0; i < n; i++)
	{
		if(a[i] == key) return 1;
	}
	return 0;
}


Measured memory_bytes: 2092
N =int(input())
ans = 0
for i in range (1,N+1) :
    if i%3 !=0 and i%5 !=0 : #1~Nまで３の倍数かつ５の倍数でないものを探す
        ans += i     #+=iにすることで、合計が求められる
print(ans)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define fr(i,j,k) for(int i=j;i<k;i++)
//#define f(n) fr(i,0,n)
//#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const int maxn = 2e5+5;
#include<atcoder/all>
using namespace atcoder;
void solve() {
    int n, k;
    cin >> n >> k;
    mcf_graph<int,ll>g(n+n+2);
    int st = n + n;
    int ed = st + 1;
    for(int i = 0 ; i < n ; i++) {
        g.add_edge(st,i,k,0);
        g.add_edge(i,ed,k,mod);
        g.add_edge(n+i,ed,k,0);
    }
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < n ; j++) {
            int x;
            cin >> x;
            g.add_edge(i,n+j,1,mod-x);
        }
    }
    auto res = g.flow(st, ed);
    cout << 1LL * k * n * mod - res.S << '\n';
  vector<string>ans(n,string(n,'.'));
    for (auto &i : g.edges()) {
        if (i.from != st && i.to != ed && i.flow) {
            ans[i.from][i.to-n] = 'X';
        }
    }
    for (auto &i : ans) {
        cout << i << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N;
int A[2][110];

void _main() {
    cin >> N;
    REP (i, 2) REP (j, N) cin >> A[i][j];
    REP (j, N - 1) A[0][j + 1] += A[0][j];
    for (int j = N - 1; j > 0; --j) A[1][j - 1] += A[1][j];
    int ans = 0;
    REP (i, N) ans = max(ans, A[0][i] + A[1][i]);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define FOR(hoge,a) for(hoge=0;hoge<a;hoge++)
#define INTINF 695271612
int i,j;
int dp[1001][7];

int sigma(int u){
	int res=0;
	int piyo;
		FOR(piyo,7){
		res+=dp[u][piyo];
		res=res%10007;
	}
	return res;
}

int main() {
	int n;char a[1001];
	cin>>n;
	FOR(i,n){
		cin>>a[i];
	}
	int ans=0;
	FOR(i,n){
		FOR(j,7){
			dp[i][j]=0;
		}
	}
	dp[0][0]=1;
	FOR(i,n){
		int g=sigma(i);
		dp[i+1][6]=g;
		if(a[i]=='J'){
			dp[i+1][0]=(dp[i][0]+dp[i][3]+dp[i][5]+dp[i][6])%10007;
			dp[i+1][3]=(g-dp[i][2])%10007;
			dp[i+1][5]=(g-dp[i][1])%10007;
		}
		if(a[i]=='O'){
			dp[i+1][1]=(dp[i][1]+dp[i][3]+dp[i][4]+dp[i][6])%10007;
			dp[i+1][3]=(g-dp[i][2])%10007;
			dp[i+1][4]=(g-dp[i][0])%10007;
		}
		if(a[i]=='I'){
			dp[i+1][2]=(dp[i][2]+dp[i][4]+dp[i][5]+dp[i][6])%10007;
			dp[i+1][4]=(g-dp[i][0])%10007;
			dp[i+1][5]=(g-dp[i][1])%10007;
		}
	}
	FOR(i,7){
		ans=(ans+dp[n][i])%10007;
	}
	while(ans<0){ans+=10007;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N;
	scanf("%d", &N);
	
	int i;
	long long power;
	for (i = 1, power = 1; i <= N; power = (power * (i++)) % 1000000007);
	
	printf("%lld\n", power);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t,u;
	ll a,b;
	cin>>s>>t>>a>>b>>u;
	if(s==u)puta(a-1,b);
	else puta(a,b-1);
	return 0;
}

Measured memory_bytes: 256
#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)


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

	ll N;
	cin >> N;
	if (N % 2 == 1)puts(0);
	else {
		ll K = N / 2LL;
		ll temp = 5;
		ll ans = 0;
		while (1) {
			ans += K / temp;
			temp *= 5;
			if (temp > K)break;
		}
		puts(ans);
	}
	
	return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

const int MAXN = 100010;

int n, q;

int freq[MAXN];

int main()
{
	scanf("%d",&n);

	lli ans = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		int v;
		scanf("%d",&v);

		ans += v;
		freq[v]++;
	}

	scanf("%d",&q);

	for(int i = 1 ; i <= q ; i++)
	{
		int b, c;
		scanf("%d %d",&b,&c);

		lli qtd = freq[b];
		ans -= qtd*b;
		ans += qtd*c;

		freq[c] += qtd;
		freq[b] = 0;

		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }
  int ans = 0;
  sort(vec.begin(),vec.end());
  for(int i=0;i<2;i++){
    ans += vec.at(i+1)-vec.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
vvl factorize(ll n) {
  vvl ret;
  for(ll i = 2; i * i <= n; i++) {
    ll c = 0;
    while(n % i == 0) n /= i, c++;
    if(c!=0) ret.push_back(vll{i, c});
  }
  if(n != 1) ret.push_back(vll{n, 1});
  return ret;
}
ll mpow(ll a, ll b, ll p = -1){
  ll ret = 1, num = a;
  if(p==-1){
    while(b>0){
      if(b%2) ret *= num;
      num = num * num;
      b /= 2;
    }
  }else{
    while(b>0){
      if(b%2) ret = (ret*num)%p;
      num = (num*num)%p;
      b /= 2;
    }
  }
  return ret;
}


int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);re(i, n) std::cin >> a[i];
  vll x(1000001, 0);
  init();
  for(int i=0;i<n;i++){
    vvl tmp = factorize(a[i]);
    for(int j=0;j<tmp.size();j++) x[tmp[j][0]] = max(x[tmp[j][0]], tmp[j][1]);
  }
  ll g = 1;
  for(int i=1;i<=1000000;i++) g = (g * mpow(i, x[i], P))%P;
  ll ans = 0;
  re(i, n) ans = (ans + (g*inv[a[i]])%P)%P;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 242560
"""a,bの最大公約数"""
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
for i in range(g):
    if s[n//g*i]!=t[m//g*i]:
        print(-1)
        exit()
print(n*m//g)


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

int main() {
	int N, dist1 = 0, dist2 = 0;
	cin >> N;
	int* a = (int*)malloc(sizeof(int)*N+2);
	a[0] = 0;a[N + 1] = 0;
	for (int i = 1;i <= N;i++) cin >> a[i];
	for (int i = 0;i < N + 1;i++)dist2 += abs(a[i] - a[i + 1]);
	for (int i = 1;i <= N;i++) {
		dist1 = dist2;
		dist1 = dist1 - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
		cout << dist1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int N; cin >> N;
  vector <long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (A.at(i) < 0){
      A.at(i) = - A.at(i);
      cnt++;
    }
  }
  long sum = 0;
  for (int i = 0; i < N; i++){
    sum += A.at(i);
  }
  if(cnt % 2 == 0) cout << sum << endl;

  else{
    long m = (long)*min_element(A.begin(),A.end());
    cout << sum - 2*m << endl;
  }
}



Measured memory_bytes: 1024
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 3e5 + 10;

char s[N];
int pre[N][2], suf[N][2];

int main() {
	int n;
	cin >> n >> (s + 1);
	for (int i = 1; i <= n; ++i) {
		pre[i][0] = pre[i - 1][0] + (s[i] == 'W');
		pre[i][1] = pre[i - 1][1] + (s[i] == 'E');
	}
	for (int i = n; i >= 1; --i) {
		suf[i][0] = suf[i + 1][0] + (s[i] == 'W');
		suf[i][1] = suf[i + 1][1] + (s[i] == 'E');
	}
	int best = n;
	for (int i = 1; i <= n; ++i) {
		best = min(best, pre[i - 1][0] + suf[i + 1][1]);
	}
	cout << best;
}

Measured memory_bytes: 5248
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        int p, y;
        TreeMap<Integer, Integer>[] map1 = new TreeMap[n+1];
        for(int i = 1; i <= n; i++){
            map1[i] = new TreeMap<>();
        }
        for(int i = 1; i <= m; i++){
            p = Integer.parseInt(sc.next());
            y = Integer.parseInt(sc.next());
            map1[p].put(y, i);
        }
        
        TreeMap<Integer, String> map2 = new TreeMap<>();
        for(int i = 1; i <= n; i++){
            if(map1[i].isEmpty()){
                continue;
            }
            Set set = map1[i].keySet();
            List<Integer> list = new ArrayList<>(set);
            for(int j = 1; j <= list.size(); j++){
                String s1 = Integer.toString(i);
                while(s1.length() < 6){
                    s1 = "0" + s1;
                }
                String s2 = Integer.toString(j);
                while(s2.length() < 6){
                    s2 = "0" + s2;
                }
                
                map2.put(map1[i].get(list.get(j-1)), s1 + s2);
            }
        }
        
        StringBuilder sb = new StringBuilder();
        map2.keySet().forEach((key) -> {
            sb.append(map2.get(key)).append(System.lineSeparator());
        });
        System.out.println(sb);
    }
}

Measured memory_bytes: 116328
//
//  ABC104C All Green
//

#include <iostream>
#include <string>
#include <bitset>
#include <sstream>
#include <cmath>
#include <vector>
#include <utility>     // makepair
#include <algorithm>   // sort

using namespace std;

class Problems {
public:
	int point;		//得点
	int num;			//問題数
	int bonus;		//ボーナス得点

	Problems(int p, int c, int b) {
		point= p;
		num = c;
		bonus = b;
	}

	int point_calc(int n) {  // n問解いた時の得点を計算
		if (n == num) {
			return point * n + bonus;
		} else {
			return point * n;
		}
	}

	int num_calc(int p) {  // 得点p以下となる最大の問題数を求める
		int ans = p / point;
		if (ans > num) ans = num;
		return ans;
	}

private:

};

bool pb_compare(const Problems& aa, const Problems& bb) {
	return (aa.point >  bb.point);  			// ポイントの降順
}

// 整数bina のdigit桁2進数文字列を返す
string binary(int bina, int digit){
    int ans = 0;
    string leading_zero(digit,'0');

    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    string str1 = leading_zero + to_string(ans);
    return str1.substr(str1.length()-digit);
}



int main() {
	int D,G;
	cin >> D >> G;

	vector<Problems> pb;  		// 個別配点、問題数,ボーナスを格納する配列
	int N=0;							// 総問題数
	for(int i=0; i<D; i++) {
		int x,y;
		cin >> x >> y ;
		Problems q(100*(i+1),x,y);
		N += x;
		pb.push_back(q);
	}
	sort(pb.begin(), pb.end(), pb_compare);

	int minCount=N+1;		// 解くべき問題数
	int minPoint;       // その時の得点
	string ansstr;			// 回答を得られる問題の組み合わせ
	vector<int> ansTBL(D);

	for(int bit=0; bit < (1<<D); ++bit) {
		string binstr = binary(bit,D);    // binstrの桁数は問題数Nではなく問題G数のD
		vector<int> tbl(D);

		// 素得点の大きい問題から解いて、ゴールにたどり着くか計算する
		int sum=0;
		int pcount=0;
		for(int j=0; j<D; j++) {
			if(binstr.at(j) == '1') {
				// 問題 pb[j]について考える。
				int x = pb[j].num_calc(G - sum);  // ゴールとのギャップを埋める問題数を求める
				sum += pb[j].point_calc(x);
				pcount += x;
				tbl[j] = x;

				if(sum >G) 	break;

			}
		}
		// 回答の判定
		if ( sum >= G ) {
			if ( pcount < minCount ) {
				minCount = pcount;
				minPoint = sum;
				copy(tbl.begin(), tbl.end(), ansTBL.begin());
				ansstr = binstr;
			}
		}
	}
	cout << minCount << "\n";

	return 0;
}


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

using namespace std;

const string mew = "mew";

int main()
{
  string s1, s2;
  int s, t;
  bool f;

  while(cin>>s1){
    s = t = s1.size();
    f = false;
    while(s > 0 && t > 0){
      t = -1;
      if(s1.size() == 3 && s1 == mew){
	f = true;
	break;
      }
      for(int i = 0; i < s1.size()-3; ++i)
	if(s1.substr(i, 3) == mew){
	  t = i;
	  break;
	}

      if(t == -1){
	f = false;
	break;
      }
      s2 = s1.substr(t+3);
      s1 = s1.substr(0, t);
      s = s1.size();
      t = s2.size();
      s1 += s2;
    }

    cout << ((f)? "Cat": "Rabbit") << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

int main()
{
	const ll max = 1000000007;
	long n, m;
	cin >> n >> m;
	vector<ll> a(n + 1, 0);
	for (long i = 0; i < m; i++)
	{
		long in;
		cin >> in;
		a[in] = -1;
	}

	if (a[1] == 0)
		a[1] = 1;
	if (a[2] == 0)
		a[2] = 1;
	for (long i = 0; i < n; i++)
	{
		if (a[i] < 0)
			continue;
		if (a[i + 1] >= 0)
		{
			if (a[i + 1] + a[i] > max)
				a[i + 1] += a[i] - max;
			else
				a[i + 1] += a[i];
		}
		if (i + 2 <= n && a[i + 2] >= 0)
		{
			if (a[i + 2] + a[i] > max)
				a[i + 2] += a[i] - max;
			else
				a[i + 2] += a[i];
		}
	}

	printf("%lld", a[n]);

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main (void){
  int x,a,b;
  

  scanf("%d%d%d",&x,&a,&b);
  if(a>x){
    if(b>x){
      if(a-x<=b-x){
        printf("A");}
        else{
          printf("B");}}
      else  
        if(a-x<=x-b){
        printf("A");}
        else{
          printf("B");}}
   if(a<x){
     if(b>x){
      if(x-a<=b-x){
        printf("A");}
        else{
          printf("B");}}
      else  
        if(x-a<=x-b){
        printf("A");}
        else{
          printf("B");}}
  
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long seven = 7;
    set<long long> seven_set;
    int ans = 1;
    while (seven % n != 0)
    {
        seven = (seven % n) * 10 + 7;
        if(seven_set.count(seven % n))
        {
            ans = -1;
            break;
        }
        else
        {
            seven_set.insert(seven % n);
        }
        
        ans ++;
    }

    cout << ans << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
   ll ans=0;
   ll n;cin >>n;
   ll mint=INF;
    for (int i = 0; i < n; ++i) {
        ll p;cin >>p;
        if(mint>=p){
            ans++;
            mint=p;
        }
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,i;
    ll k,a[2005];
    cin>>n>>k;
    for(i=0;i<n;i++)
        cin>>a[i];
    ll ans=0,mod=1e9+7;
    int c1=0,c2=0;
    for(i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<a[i])
                c1++;
        }
	}
	for(i=0;i<n;++i)
		for(int j=0;j<n;++j)
			c2+=a[i]>a[j];
    ans=(k*(k-1)/2%mod*c2+k*c1)%mod;
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}
int main(){
  ll i,N,ans=0;
  cin>>N;
  vec v(N+1);
  rep(i,N+1){
    cin>>v[i];
  }
  vsort(v);
  rep(i,N){
    ans=gcd(ans,v[i+1]-v[i]);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  string n;
  cin >> n;
  char a,b,c,d;
  int cnt=0;
  
    	a = n.at(0);
    	b = n.at(1);
    	c = n.at(2);
    	d = n.at(3);
    
    if(a == b && b == c){
	  	cout << "Yes" << endl;
    }else if(b == c && c == d){
	  	cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    VEC(int) counts(26, 0);
    string S;
    cin >> S;
    FOR(i, 0, S.size())
        counts[S[i] - 'a'] ^= 1;

    bool good = true;
    FOR(i, 0, 26)
        if (counts[i])
            good = false;
    cout << (good ? "Yes" : "No") << endl;
    return 0;
};


Measured memory_bytes: 256