akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n, p = map(int, input().split())
s = input()

if p == 2 or p == 5:
    ans = 0
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
    print(ans)
    exit()

num = 0
a = [0] * (n+1)
for i in reversed(range(n)):
    j = n-1 - i
    num += int(s[i]) * pow(10, j, p) % p
    num %= p
    a[j+1] = num

ctr = Counter(a)
ans = 0
for v in ctr.values():
    ans += v * (v-1) // 2

print(ans)

Measured memory_bytes: 11964
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

lint make1(int s, int t);
lint make2(int s, int t);

int N, M;
vector<int> S, T;

lint dp1[2020][2020], dp2[2020][2020];

lint make1(int s, int t){
    if(s == N){
        return 1;
    }else if(dp1[s][t] != -1){
        return dp1[s][t];
    }
    return dp1[s][t] = (make1(s + 1, t) + make2(s, t)) % mod;
}

lint make2(int s, int t){
    if(t == M){
        return 0;
    }else if(dp2[s][t] != -1){
        return dp2[s][t];
    }
    lint ans = make2(s, t + 1);
    if(S[s] == T[t]){
        ans += make1(s + 1, t + 1);
    }
    return dp2[s][t] = ans % mod;
}

int main(){
    cin >> N >> M;
    S.resize(N), T.resize(M);
    cins(all(S)), cins(all(T));
    memset(dp1, -1, sizeof(dp1));
    memset(dp2, -1, sizeof(dp2));
    cout << make1(0, 0) << endl;
}

Measured memory_bytes: 64256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, cnt = 0, c = 1;
    cin >> h;
    while(h >= 1) {
    	cnt += c;
    	c *= 2;
    	h /= 2;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3644
import sys
import numpy as np

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]

    dog_ord_num = 1
    mon_ord_num = 1

    if abs(N - M) <= 1:
        for i in range(N):
            dog_ord_num *=  i + 1
            dog_ord_num = dog_ord_num % (int(1e+9) + 7)

        for i in range(M):
            mon_ord_num *= i + 1
            mon_ord_num = mon_ord_num % (int(1e+9) + 7)



        all_ord = (dog_ord_num * mon_ord_num ) % (int(1e+9) + 7)
        if (abs(N - M) == 0):
            all_ord *= 2
            all_ord %= (int(1e+9) + 7)

    else:
        all_ord = 0

    print int(all_ord)


if __name__ == '__main__':
    main()

Measured memory_bytes: 19564
import java.util.*;

class Main{           
  
   public static void main(String[] args){
         Scanner sc = new Scanner(System.in);  
         
         while(true){
             int n = sc.nextInt();
             if(n == 0){
                 break;
             }
             
             int min = Integer.MAX_VALUE;
             
             int a[] = new int[n];
             for(int i = 0;i < n;i++){
                 a[i] = sc.nextInt();
             }
             
             Arrays.sort(a);
             
             int before = a[0];
             for(int i = 1;i < n;i++){
                 int target = a[i];
                 min = Math.min(min,Math.abs(target-before));
                 before = target;
             }
             
             System.out.println(min);             
             
         }
         
         
   }         
         
 }
  

        
        

Measured memory_bytes: 46956
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}



int main() {
	int i, j, k;

	int N, M, K;

	cin >> N;
	map<int, int> A;

	int first=-1;
	int second=1000000000;
	rep(i, 0, N) {
		int a;
		cin >> a;
		A[a] ++;
		first = Max(first, a);
		second = Min(second, a);
	}


	bool isClear = true;
	int left = first;
	int mid = second;
	auto X = A;
	X[left]--;
	X[mid]--;
	for (i = 1; i < N - 1; i++) {
		if (X[left ^ mid] < 1) {
			cout << "No";
			return 0;
		}
		int tmp = left;
		left = mid;
		mid = tmp ^ mid;
		X[mid]--;
	}
	if ((left ^ mid) != first) {
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}

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

int N;
ll D, A;
vector<ll> X, H;

ll solve(){
    vector<int> ids(N);
    for(int i = 0; i < N; i++) ids[i] = i;
    sort(ids.begin(), ids.end(), [&](int i, int j) {return X[i] < X[j]; });
    vector<ll> nX(N), nH(N);
    for(int i = 0; i < N; i++) nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    X = nX, H = nH;

    vector<ll> S(N+1, 0);
    ll res = 0;
    for(int i = 0; i < N; i++){
        if(S[i] < H[i]){
            ll need = (H[i] - S[i] - 1) / A + 1;
            ll right = X[i] + D * 2;
            int id = upper_bound(X.begin(), X.end(), right) - X.begin();

            S[i] += need * A;
            S[id] -= need * A;
            res += need;
        }
        S[i+1] += S[i];
    }
    return res;
}

int main(){
    cin >> N >> D >> A;
    X.resize(N); H.resize(N);
    for(int i = 0; i < N; i++) cin >> X[i] >> H[i];
    cout << solve() << endl;
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc082.contest.atcoder.jp/tasks/arc082_b>
問題文============================================================
 1,2,..,N からなる順列 p1,p2,..,pN が与えられます。 次の操作を何回か (0回でもよい) 行うことが出来ます。
 
 操作: 順列で隣り合う二つの数を選んでスワップする。
 
 何回か操作を行って、任意の 1≤i≤N に対して pi≠i となるようにしたいです。 必要な操作の最小回数を求めてください。
 制約
 2≤N≤105
 p1,p2,..,pN は 1,2,..,N の順列である。
=================================================================

解説=============================================================

 数列を最初から順に見ていく、
 ここでpi = i となっているものがあれば、
 swapで pi+1 の値と交換してやれば良い
 
 最後の i == N だけは、異なれば pi-1と交換する
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> p(N+1);
    for(int i = 1; i <= N;i++) cin >> p[i];
    ll cnt = 0;
    for(int i = 1; i <= N;i++){
        if(p[i] == i){
            if(i == N){
                swap(p[i-1],p[i]); cnt++;
                continue;
            }else{
                swap(p[i],p[i+1]); cnt++;
                continue;
            }
        }
    }
    cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll=long long int;
using namespace std;
typedef pair<int, int>pi;
int main() {
	int n; cin >> n;
	if (n % 1000 == 0)puts("0");
	else if (n < 1000) {
		cout << 1000 - n;
	}
	else {
		int res = n / 1000;
		res++;
		res *= 1000;
		cout << res - n;
	}
	return 0;
}

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

const int DIM = 1e5 + 5;

int arr[DIM], dp[DIM][2];

int main(void)
{
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
        
        if (i == 1)
            dp[i][0] = dp[i][1] = 1;
        else {
            dp[i][0] = min(dp[i - 1][0] + (arr[i] < arr[i - 1]), dp[i - 1][1] + 1);
            dp[i][1] = min(dp[i - 1][1] + (arr[i] > arr[i - 1]), dp[i - 1][0] + 1);
        }
    }
    
    cout << min(dp[n][0], dp[n][1]) << endl;
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct item_t {
  ll w, v;
  item_t(ll w, ll v):w(w),v(v){}
  item_t():w(0),v(0){}
  void operator+=(const item_t &r) {
    w += r.w;
    v += r.v;
  }
  bool operator<(const item_t &r) const { return w < r.w; }
};

vector<item_t> rekkyo(vector<item_t> item) {
  vector<item_t> a(1, item_t(0,0));
  for (auto i : item) {
    vector<item_t> b, c;
    for (auto &e : a) {
      b.emplace_back(e);
      b.back() += i;
    }
    merge(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c));
    swap(a, c);
  }
  return a;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<item_t> item(n+1); //1-indexed
  rep(i,n) cin >> item[i+1].v >> item[i+1].w;
  int q;
  cin >> q;
  while(q--) {
    int v, L;
    cin >> v >> L;
    vector<item_t> A;
    while(v > 0) {  
      A.emplace_back(item[v]);
      v /= 2;
    }
    int m = A.size();
    auto a = rekkyo({A.begin(), A.begin() + m/2});
    auto b = rekkyo({A.begin() + m/2, A.end()});
    ll maxv = 0;
    for (auto&& x : b) {
      chmax(maxv, x.v);
      x.v = maxv;
    }
    reverse(all(a));
    ll ans = 0;
    auto itr = b.begin();
    for (auto&& x : a) {
      while(next(itr) != b.end() && x.w + (*next(itr)).w <= L) {
        itr = next(itr);
      }
      if (x.w + (*itr).w > L) continue;  
      chmax(ans, x.v + (*itr).v);
    }
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 7336
s = input()

ans1 = 0
for i in range(len(s)):
    if i % 2 == 0 and s[i] == '0':
        ans1 += 1
    elif i % 2 == 1 and s[i] == '1':
        ans1 += 1

ans2 = 0
for i in range(len(s)):
    if i % 2 == 0 and s[i] == '1':
        ans2 += 1
    elif i % 2 == 1 and s[i] == '0':
        ans2 += 1
print(min(ans1, ans2))


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int a, b;
   cin >> a >> b;
   int ans = 0;
   for (int i = a; i <= b; i++) {
      string s = to_string(i);
      string t = s;
      reverse(all(t));
      if (s == t) {
         ans++;
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;


int N,A,B;
int X[100010];
int num[100010];
vector<int> V;

int Ceil(int a,int b){return ((a%b==0)?a/b:a/b+1);}

signed main(){
	cin>>N>>A>>B;
	REP(i,N){
		cin>>X[i];
	}
	auto Judge=[](int m){
		int cnt=0;
		REP(i,N){
			if(X[i]>=m*B){
				int e=Ceil(X[i]-m*B,A-B);
				cnt+=e;
			}
		}
		if(cnt>m){
			return false;
		}
		else{
			return true;
		}
	};
	int ok=1e10,ng=-1,mid;
	while(abs(ok-ng)>1){
		mid=(ok+ng)/2;
		if(Judge(mid)){
			ok=mid;
		}
		else{
			ng=mid;
		}
	}
	if(Judge(mid)!=true){
		cout<<mid+1<<endl;
	}
	else{
		cout<<mid<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int col[10];
	for(int x=0; x<10; x++)
		col[x] = 0;
	int N; cin>>N;
	int gt = 0;
	int a;
	for(int n=0; n<N; n++){
		cin>>a;
		if(a>=3200)
			gt++;
		else if(a>=2800)
			col[7]++;
		else if(a>=2400)
			col[6]++;
		else if(a>=2000)
			col[5]++;
		else if(a>=1600)
			col[4]++;
		else if(a>=1200)
			col[3]++;
		else if(a>=800)
			col[2]++;
		else if(a>=400)
			col[1]++;
		else
			col[0]++;
	}
	int diffc = 0;
	for(int x=0; x<8; x++){
		diffc += (col[x]>0);
	}
	if(diffc==0&&gt>0)
		cout << 1;
	else
		cout << diffc;
	cout << " ";
	cout << min((int)1e9, diffc+gt) << endl;
	return 0;
}

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

using ll = unsigned long long;
int main() {
	int n, c[26] = { 0 };
	char s[11];

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		c[s[0] - 'A']++;
	}

	ll comp[5];
	comp[0] = c['M' - 'A'];
	comp[1] = c['A' - 'A'];
	comp[2] = c['R' - 'A'];
	comp[3] = c['C' - 'A'];
	comp[4] = c['H' - 'A'];
	ll total = 0;
	for (int i = 0; i < 3; i++)
		for (int j = i + 1; j < 4; j++)
			for (int k = j + 1; k < 5; k++)
				total += comp[i] * comp[j] * comp[k];
	printf("%llu\n", total);
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int S,M;
  int h, m, s;
  scanf("%d", &S);
  h = S/3600;
  M = S%3600;
  m = M/60;
  s = M%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}


Measured memory_bytes: 2108
class Array
  def gcd
    self.inject{|a,b| a.gcd(b)}
  end
end
n,x = gets.chomp.split(' ').map(&:to_i)
coord_def = gets.chomp.split(' ').map(&:to_i).map do |val|
  (val-x).abs
end
p coord_def.gcd

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

using namespace std;

int main() {
  int a[] = { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
  int x, y;
  cin >> x >> y;
  cout << ( a[x] == a[y] ? "Yes" : "No" ) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-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; }

bool pcom(pair<ll,ll> a,pair<ll,ll> b){
    if(a.second!=b.second) return a.second<b.second;
    else return a.first<b.first;
}

int main(){
    ll N,M,cnt=0,a=0;
    cin>>N>>M;
    vector<pair<ll,ll>> p(M);
    for(ll i=0;i<M;i++) cin>>p[i].first>>p[i].second;
    sort(p.begin(),p.end(),pcom);
    for(ll i=0;i<M;i++){
        if(a<=p[i].first){
            cnt++;
            a=p[i].second;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=10010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	long long int n;
	long long int ans=0;
	//	long long int  a[N];
	cin>>n;
//	nn=n/10000;
//	nm=n%10000;

	for(long long int i=1;i*(i+1)+i<=n;i++){
		if(n%i==0) ans=ans+n/i-1;
	}

	cout<<ans<<endl;
//printf("%d%d%d%d\n",bnuma[0][1],bnuma[1][1],bnuma[1][0],bnuma[0][0]);
//	qsort(b, 5, sizeof(long long int), compare_int);
/*	rep(i, 5){
		if((b[i]-1)%10<k){
			k=b[i]%10;
		}
		ans=ans+(b[i]+9)/10;
	}
	anss=ans*10+k-10;
	if(k==0){
		anss=anss+10;
	}
	cout<<anss<<endl;




/*	qsort(b, 5, sizeof(int), compare_int);
	if(b[4]-b[0]>k){
		printf(":(\n");
	}
	else{
		printf("Yay!\n");
	}
		rep(i, n){
		ans=c;
		rep(j, m){
			cin>>imp;
			ans=ans+imp*b[j];
		}
		if(ans>0){
			anss++;
		}
	}
	cout<<anss<<endl;
}*/
//		memset(b, '\0', sizeof(b));初期化
}

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

using namespace std;

int main() {
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    for (int i = 0; i < M; ++i)cin >> B[i];

    int x, ans = 0;
    for (int j = 0; j < N; ++j) {
        int sum = 0;
        for (int i = 0; i < M; ++i) {
            cin >> x;
            sum += x * B[i];
        }
        if (sum + C > 0) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


ll MOD = 1000000007;


int main()
{
	string S; cin >> S;
	reverse(S.begin(), S.end());
	vec Count(13);
	Count[0] = 1;
	ll ten = 1;


	for (auto & c : S)
	{
		vec tmp(13);

		if (c == '?')
		{
			for (ll i = 0; i <= 9; ++i)
			{
				for (ll k = 0; k < 13; ++k)
				{
					ll a = (i*ten + k) % 13ll;
					tmp[a] += Count[k];
					tmp[a] %= MOD;
				}
			}
		}
		else
		{
			ll v = (ll)(c - '0');
			for (ll k = 0; k < 13; ++k)
			{
				ll a = (v*ten + k) % 13ll;
				tmp[a] += Count[k];
				tmp[a] %= MOD;
				
			}
		}
		ten *= 10ll;
		ten %= 13;
		Count = tmp;

	}

	cout << Count[5] << endl;

	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N = int(input())
    A_lsit = list(map(int, input().split()))

    mount1_min = 0
    mount1_max = min(A_lsit[0], A_lsit[-1])

    mount_list = [0]*N

    while True:
        mount_list[0] = (mount1_min + mount1_max)//2
        for i in range(N-1):
            mount_list[i+1] = A_lsit[i] - mount_list[i]
        #print(mount_list)
        if A_lsit[N-1] - mount_list[N-1] == mount_list[0]:
            break
        elif A_lsit[N-1] - mount_list[N-1] < mount_list[0]:
            mount1_max = mount_list[0]
        else:
            if mount1_min != mount_list[0]:
                mount1_min = mount_list[0]
            else:
                mount1_min = mount_list[0]+1
    print(" ".join([str(m*2) for m in mount_list]))

if __name__ == "__main__":
    main()



Measured memory_bytes: 24952
f q x = x - (x**3.0 - q) / (3.0*x*x)

ans' q x =
  if abs (x*x*x - q) < 0.00001 * q
  then x
  else
    ans' q (f q x)

ans q =
  let xn = q / 2.0
  in
    ans' q xn

main = do
  c <- getContents
  let i = takeWhile (/= -1) $ map read $ lines c :: [Double]
      o = map ans i
  mapM_ print o
 

Measured memory_bytes: 4548
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define ll 				long long
#define int             long long int
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }


void solve()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	reverse(a, a+n);
	int sum = 0;
	int i = 0, cnt;
	n--;
	while(true)
	{
		cnt = min({2LL, i+1, n});
		sum += cnt*a[i];
		i++;
		n = n-cnt;
		if(n <= 0)
			break;
	}
	cout << sum;
}
 
int32_t main()
{
	FIO
    //aks();
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 5176
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int main()
{
	int r, g, b;
	int sum = 0;
	cin >> r >> g >> b;
	sum += r * 100 + g * 10 + b;
	if (sum % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return	0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int N = sc.nextInt();
		int K = sc.nextInt();

		ArrayList<Integer> priceList = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			int num = sc.nextInt();
			priceList.add(num);
		}

		sc.close();

		Collections.sort(priceList);

		int answer = 0;

		for(int i = 0; i < K; i++) {
			answer += priceList.get(i);
		}

		System.out.println(answer);

	}

}


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

int main() {
    int x[20];
    int a, b, k;
    int y = 0;
    cin >> a >> b >> k;
    for (int i = 1; i <= 100; i++) {
        if (a % i == 0 && b % i == 0) {
            x[y] = i;
            y++;
        }
    }
    
    cout << x[y - k] << endl;
    return 0;

}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let a: usize = sc.get();
    let s: String = sc.get();
    if a >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
using namespace std;
typedef long long  ll;
int f(int x){
    int res = 0;
    while(x%2 == 0){
        x /= 2;
        res++;
    }
    return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) a[i] /= 2;
    int t = f(a[0]);
    for(int i=0; i<n; i++){
        if(f(a[i]) != t){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    for(int i=0; i<n; i++){
        l = lcm(l,a[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m+1)/2;
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3760
import math
import itertools
N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]


def distance(R):
	x = []
	y = []
	for i in range(N):
		x.append(int(R[i][0]))
		y.append(int(R[i][1]))
	d = 0
	for i in range(N-1):
		d += math.sqrt((x[i]-x[i+1])**2 + (y[i]-y[i+1])**2)
	return d


		
sum = 0
count = 0
for route in itertools.permutations(xy):
	sum += distance(route)
	distance(route)
	count += 1

print(sum/count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
using namespace std;

int main() {
	int n, x[114514], y[114514], time[114514], flg = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> time[i] >> x[i] >> y[i];
	}
	if (abs((x[0] + y[0] - time[0]) % 2 == 1)||(abs(x[0])+abs(y[0])>time[0])) {
		flg = 1;
	}
	for (int i = 1; i < n; i++) {
		int dx = x[i] - x[i - 1];
		int dy = y[i] - y[i - 1];
		int dt = time[i] - time[i - 1];
		if ((abs(dx)+abs(dy)>dt)||(abs((dx+dy-dt))%2==1)) {
		flg = 1;
		}
	}
	if (flg == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 1408
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

class SegmentTree {
public:
    SegmentTree(ll n, ll value) {
        n_ = (ll)pow(2, ceil(log2(n)));
        nodes_.resize(2 * n_ - 1, value);
    }

    void update(ll x, ll v) {
        nodes_[x + n_ - 1] = v;
        for (ll i = (x + n_ - 2) / 2; i > 0; i = (i - 1) / 2) {
            nodes_[i] = max(nodes_[2 * i + 1], nodes_[2 * i + 2]);
        }
        nodes_[0] = max(nodes_[1], nodes_[2]);
    }

    ll getMaxIndex(ll k = 0) {
        //最も大きいもののindexを返す
        if (k >= n_ - 1) {
            //最下段まで来ていたらindexを返す
            return k - (n_ - 1);
        }
        return (nodes_[2 * k + 1] >= nodes_[2 * k + 2] ? getMaxIndex(2 * k + 1) : getMaxIndex(2 * k + 2));
    }

    ll getMax(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
        if (r < 0) {
            r = n_;
        }
        if (r <= a || b <= l) {
            return INT_MAX;
        }
        if (a <= l && r <= b) {
            return nodes_[k];
        }
        ll lv = getMax(a, b, 2 * k + 1, l, (l + r) / 2);
        ll rv = getMax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(lv, rv);
    }

private:
    //2のべき乗
    ll n_;
    vector<ll> nodes_;
};

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }

    SegmentTree st(N, 0);
    for (ll i = 0; i < N; i++) {
        st.update(i, B[i]);
    }

    ll same_num = 0;
    for (ll i = 0; i < N; i++) {
        if (A[i] == B[i]) {
            same_num++;
            st.update(i, 0);
        }
    }

    ll ans = 0;
    while (same_num < N) {
        ll index = st.getMaxIndex();
        ll left = (index + N - 1) % N;
        ll right = (index + 1) % N;
        ll sub = B[left] + B[right];
        ll lr_max = max(B[left], B[right]);
        
        if (A[index] >= lr_max) {
            //B[index]がA[index]ぴったりになって終了
            if ((B[index] - A[index]) % sub != 0) {
                cout << -1 << endl;
                return 0;
            } else {
                ans += (B[index] - A[index]) / sub;
                B[index] = A[index];

                //もう見ないので0にしておく
                st.update(index, 0);
                same_num++;
            }
        } else {
            //left, rightの大きい方を下回るような操作回数kを求める
            ll k = (B[index] - lr_max + sub - 1) / sub;

            //その操作によってA[index]を下回ってしまってはダメ
            if (B[index] - k * sub < A[index]) {
                cout << -1 << endl;
                return 0;
            } else {
                ans += k;
                B[index] -= k * sub;

                if (B[index] == A[index]) {
                    st.update(index, 0);
                    same_num++;
                } else {
                    st.update(index, B[index]);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 7424
#include<stdio.h>
int main(){
  int N,Y,i,k,p,t=0,a,b,c;
  scanf("%d %d",&N,&Y);
  for(i=0;i<=N;i++){
      for(k=0;k<=N;k++){
        p=N-(i+k);
     if(p>=0&&i+k+p==N&&10000*p+5000*k+1000*i==Y){
       a=p;
         b=k;
         c=i;
          t=1;
          break;
        }
      }
  }
    if(t==1){printf("%d %d %d",a,b,c);}
    else printf("-1 -1 -1");
  return 0;
  }

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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for(int i = 0; i < N; ++i) cin >> S[i];
  for(int j = 0; j < M; ++j) cin >> T[j];
  vector<vector<mint>> dp(N+1,vector<mint>(M+1,mint(0)));
  dp[0][0] = 1;
  // for(int i = 0; i <= N; ++i) dp[i][0] = 1;
  for(int i = 0; i <= N; ++i){
    for(int j = 0; j <= M; ++j){
      if(i < N) dp[i+1][j] += dp[i][j];
      if(j < M) dp[i][j+1] += dp[i][j];
      if(i < N and j < M and S[i] != T[j])
        dp[i+1][j+1] -= dp[i][j];
    }
  }
  // for(int i = 0; i <= N; ++i){
  //   for(int j = 0; j <= M; ++j)
  //     cerr << dp[i][j] << " ";
  //   cerr << endl;
  // }
  cout << dp[N][M] << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define pb push_back
#define x first 
#define y second
#define vec vector
#define ll long long
#define mp make_pair
#define pii pair<ll ,ll >
#define THICC 69420911
#define speedup ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define loop(it) for(auto it = mep.begin();it!=mep.end();++it)
using namespace std;
int main(){
    ll  n,m; cin>>n>>m;
	string grid[n];
	for(ll  i = 0 ; i < n ; i++){
		cin>>grid[i];
	}
	vector<vector<ll>> dp(n , vector<ll>(m)); dp[0][0] = 1;
	for(ll  i = 0 ; i < n ; i++){
		for(ll  j = 0 ; j < m ; j++){
			if(grid[i][j] == '#')dp[i][j] = 0;
			else if(i==0&&j==0)dp[i][j] = 1;
			else if(i==0)dp[i][j] = dp[i][j-1];
			else if(j==0)dp[i][j] = dp[i-1][j];
			else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%((ll)1e9+7);
		}
	}
	cout<<dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 9216
n, m, l = map(int, input().split())
#a = n*m
#b = m*l
#c = n*l
a = []#[[0 for i in range(m)] for j in range(n)]
b = []#[[0 for i in range(l)] for j in range(m)]
c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
    
for i in range(n):
    for j in range(l):
        cnt = 0
        for k in range(m):
            cnt += a[i][k]*b[k][j]
        c[i][j]=cnt

for i in range(n):
    print(*c[i])


Measured memory_bytes: 7068
#include <stdio.h>
char s[2000][2001];
int sumU[2000][2000];
int sumD[2000][2000];
int sumR[2000][2000];
int sumL[2000][2000];
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	int h, w;
	int ans = 0;
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", s[i]);
	}
	for (int i = 0; i < h; i++) {
		for (int j = 1; j < w; j++) {
			sumL[i][j] = sumL[i][j - 1];
			if (s[i][j - 1] == '.') {
				sumL[i][j]++;
			} else {
				sumL[i][j] = 0;
			}
		}
		for (int j = w - 2; j >= 0; j--) {
			sumR[i][j] = sumR[i][j + 1];
			if (s[i][j + 1] == '.') {
				sumR[i][j]++;
			} else {
				sumR[i][j] = 0;
			}
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 1; j < h; j++) {
			sumU[j][i] = sumU[j - 1][i];
			if (s[j - 1][i] == '.') {
				sumU[j][i]++;
			} else {
				sumU[j][i] = 0;
			}
		}
		for (int j = h - 2; j >= 0; j--) {
			sumD[j][i] = sumD[j + 1][i];
			if (s[j + 1][i] == '.') {
				sumD[j][i]++;
			} else {
				sumD[j][i] = 0;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				continue;
			}
			ans =
				max(ans, sumR[i][j] + sumL[i][j] + sumD[i][j] + sumU[i][j] + 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  if(N%(A+B)>=A){
    cout << (N/(A+B))*A+A << endl;
  }else{
    cout << (N/(A+B))*A+N%(A+B)<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int m,a[N];
ll ans=0;
int top,s[N];
int solve()
{
    while(top>1)
    {
        ans++;
        s[top-1]+=s[top];
        if(s[top-1]<10) top--;
        else
        {
            s[top]=s[top-1]%10;
            s[top-1]=1;
        }
    }
    return s[1];
}
int main()
{
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        int d;
        ll c;
        scanf("%d%lld",&d,&c);
        while(c>1)
        {
            if(c&1) s[++top]=d,c--;
            if(d==9)
            {
                ans+=c;
                c/=2;
            }
            else if(d==8)
            {
                ans+=c;
                c/=2;
                d=7;
            }
            else if(d==7)
            {
                ans+=c;
                c/=2;
                d=5;
            }
            else if(d==6)
            {
                ans+=c;
                c/=2;
                d=3;
            }
            else if(d==5)
            {
                ans+=c;
                c/=2;
                d=1;
            }
            else if(d==4)
            {
                ans+=c/2;
                c/=2;
                d=8;
            }
            else if(d==3)
            {
                ans+=c/2;
                c/=2;
                d=6;
            }
            else if(d==2)
            {
                ans+=c/2;
                c/=2;
                d=4;
            }
            else if(d==1)
            {
                ans+=c/2;
                c/=2;
                d=2;
            }
            else if(d==0)
            {
                ans+=c/2;
                c/=2;
                d=0;
            }
        }
        if(c==1) s[++top]=d;
        a[i]=solve();
        top=0;
    }
    while(m>1)
    {
        ans++;
        a[m-1]+=a[m];
        if(a[m-1]<10) m--;
        else
        {
            a[m]=a[m-1]%10;
            a[m-1]=1;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
		return 0;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
		return 0;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int ans=N%10;
  if(ans==2||ans==4||ans==5||ans==7||ans==9)
  { 
    cout<<"hon"<<endl;
  }
  else if(ans==0||ans==1||ans==6||ans==8)
  {
    cout<<"pon"<<endl;
  }
  else if (ans==3)
  {
  cout<<"bon"<<endl;
}
  return 0;
}


Measured memory_bytes: 3612
import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main{
    static int n;
    static int val[];
    static int weights[];
    static long memo[][];
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();
        int w = sc.nextInt();
        val = new int[n];
        weights = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            weights[i] = sc.nextInt();
            val[i] = sc.nextInt();
            sum+= val[i];
        }

        memo = new long[n][sum+1];

        for (int i = 0; i < n; i++)
            Arrays.fill(memo[i],-1);

        int max = 0;

        for (int i = 1; i <= sum; i++) {
            if (dp(0,i) <= w)
                max = i;
        }

        out.println(max);
        out.flush();

    }

    static long dp(int i,int v){

        if (v == 0)
            return 0;

        if (i == n)
            return  (long) (1e9 +10);

        if (memo[i][v] != -1)
            return  memo[i][v];
        long take = (long) (1e9 +10);
        if (v-val[i] >= 0)
            take = dp(i+1,v-val[i]) + weights[i];

        long leave = dp(i+1,v);

        return memo[i][v] = Math.min(take,leave);
    }

}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return  Long.parseLong(next());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public boolean ready() throws IOException {
        return br.ready();
    }
}

Measured memory_bytes: 125264
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N, count5, count7;
        count5 = count7 = 0;

        for (int i = 0; i < 3; i++) {
            N = sc.nextInt();
            if (N == 5) {
                ++count5;
            }else if (N == 7){
                ++count7;
            }
        }

        if(count5 == 2 && count7 == 1) {
            System.out.print("YES");
        }else{
            System.out.print("NO");
        }

        sc.close();
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;


int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-k){
        if(a[i]<a[i+k]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4764
import math, string, itertools, fractions, heapq, collections, re, \
array, bisect, sys, random, time, copy, functools, os, queue, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K = LI()
A = LI()

"""
2 1なら
2 1 2 1
点灯数は、左の数のほうが多いもの
2 1
2 1
2 1
の3種類
2回つなげてみたら決まる
2 1 2 1なら
K = 2で3
K=3 で 2 1 2 1 2 1で6
K=4 で2 1 2 1 2 1 2 1で10通り 4+3+2+1=
K=6なら 2 1 2 1 2 1 2 1 2 1 2 1で6+5+4+3+2+1 = 

偶奇でわける
modで割る

1 2なら
1 2 1 2で1しかない1
1 2 1 2 1 2なら3で2 + 1
1 2 1 2 1 2 1 2 なら6で3+2+1
"""
if len(set(A)) == 1:
    print(0)
    exit()

"""
各数字ごとに数える
"""
K %= mod
in_count = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            #  print('i, j', i,j, A[i], A[j])
            in_count += 1
#  print(in_count)
in_count %= mod
in_ans = in_count * K
in_ans %= mod

out_count = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            out_count += 1
#  print(out_count)

out_count %= mod
out_ans = (out_count * K * (K-1))//2
out_ans %= mod
#  print(in_ans, out_ans)
print(int((in_ans + out_ans)%mod))


Measured memory_bytes: 7868
#include<bits/stdc++.h>
#define H 255
using namespace std;

int main(){
  int h,A[H];
  cin>>h;
  for(int i=1;i<=h;i++)
    cin>>A[i];
  for(int i=1;i<=h;i++){
    cout<<"node "<<i<<": key = ";
    cout<<A[i]<<", ";
    if(i!=1)cout<<"parent key = "<<A[i/2]<<", ";
    if(i*2<=h)cout<<"left key = "<<A[i*2]<<", ";
    if(i*2+1<=h)cout<<"right key = "<<A[i*2+1]<<", ";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
/**
 🍪 the_hyp0cr1t3
 🍪 31.08.2020 18:14:01
**/
#ifdef W
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define aylmao cin.tie(nullptr)->sync_with_stdio(false);
#endif
#define endl '\n'
#define pb emplace_back
// #define int int64_t
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define Luv(...) [&](auto&& u, auto&& v) { return __VA_ARGS__; }
auto chmax = [](auto& A, auto&& B) { return B > A? A = B, true : false; };
auto chmin = [](auto& A, auto&& B) { return B < A? A = B, true : false; };

using ll = int64_t;
using pii = pair<int,int>;
const ll DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;

const int N = 2e5 + 5;

int32_t main() {
    aylmao
    int i, j, n;
    cin >> n;
    vector<int> masks(n), dp(1<<n);
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            int x; cin >> x;
            masks[i] += x << j;
        }
    }
    auto get = [](string t) {
        int msk = 0;
        for(int z = 0; z < sz(t); z++) 
            msk += (t[z] == '1') << z;
        return msk;
    };
    string s(n, '0');
    dp[0] = 1;
    for(i = 0; i < n; i++) {
        do {
            int msk = get(s);
            for(j = 0; j < n; j++) {
                if(!(masks[i]>>j&1 and !(msk>>j&1))) continue;
                dp[msk|1<<j] += dp[msk];
                if(dp[msk|1<<j] >= MOD) dp[msk|1<<j] -= MOD;
            }
        } while(next_permutation(all(s)));
        s[n-1-i] = '1';
    }
    cout << dp[(1<<n)-1];
    return 0;
}

Measured memory_bytes: 11316