akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	long long x;
	cin >> x;

	long long patties = (1LL << (n + 1)) - 1;
	long long burger_size = 2 * patties - 1;
	long long ans = 0;
	long long low = 1, high = burger_size;
	while (low <= high) {
		long long mid = (low + high) / 2;
		if (mid == x) {
			ans += patties / 2 + 1;
			break;
		}
		else if (mid < x) {
			ans += patties / 2 + 1;
			low = mid + 1;
			--high;
		} else {
			high = mid - 1;
			++low;
		}

		--n;
		patties = (1LL << (n + 1)) - 1;
	}

	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 3644
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

#define NUM 100000
#define NIL -1
#define INF 1000000000
#define BLACK 0
#define WHITE 1
int node_num;
vector<pair<int, int>> V[NUM];
int d[NUM];
int color[NUM];

pair<int, int> get_most_distant(int n){
    for(int i = 0; i < node_num; i++){
        color[i] = WHITE;
    }

    queue<int> Q;
    Q.push(n);
    d[n] = 0;
    color[n] = BLACK;

    while(!Q.empty()){
        int target = Q.front(); Q.pop();
        for(int i = 0; i < V[target].size(); i++){
            pair<int, int> next_node = V[target][i];
            if(color[next_node.first] == BLACK)
                continue;
            d[next_node.first] = d[target] + next_node.second;
            Q.push(next_node.first);
            color[target] = BLACK;
        }
    }

    int max_index = NIL;
    int max_value = -INF;
    for(int i = 0; i < node_num; i++){
        if(d[i] > max_value){
            max_index = i;
            max_value = d[i];
        }
    }


    return make_pair(max_index, max_value);
}

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

    for(int i = 0; i < node_num - 1; i++){
        int s, t, w;
        scanf("%d", &s);
        scanf("%d", &t);
        scanf("%d", &w);
        V[s].push_back(make_pair(t, w));
        V[t].push_back(make_pair(s, w));
    }

    pair<int, int> dist_node = get_most_distant(0);
    //printf("%d %d\n",dist_node.first, dist_node.second);
    printf("%d\n", get_most_distant(dist_node.first).second);

    return 0;
}



Measured memory_bytes: 9780
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, k;
	scanf("%ld %ld", &n, &k);
	V a(n+1, 0);
	rep(i, 1, n+1){
		scanf("%ld", &a[i]);
		a[i] += a[i-1] - 1;
		a[i] %= k;
	}

	ll ans = 0;
	std::map<ll, ll> mp;
	rep(i, 0, n+k-1){
		if(i<=n) mp[a[i]]++;
		if(i>=k-1) {
			mp[a[i-k+1]]--;
			ans += mp[a[i-k+1]];
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 16384
N = int(input())
S = [int(input()) for _ in range(N)]

mn = 200
for i in range(N):
    if S[i] % 10 != 0:
        if S[i] <= mn:
            mn = S[i]
total = sum(S)
if total % 10 != 0:
    print(total)
elif mn == 200:
    print(0) 
else:
    print(total - mn)

Measured memory_bytes: 9128
local n = io.read("*n")
local t = {}
for i = 1, n do t[i] = io.read("*n") end
local cnt = 0
for i = 1, n - 1 do
  if(t[i] == i) then
    t[i], t[i + 1], cnt = t[i + 1], t[i], cnt + 1
  end
end
if(t[n] == n) then cnt = cnt + 1 end
print(cnt)


Measured memory_bytes: 1280
number = int(input())
answer = 0

for i in range(3):
    divider = 10 ** (2-i)
    target_org = int(number / divider)
    target = 0

    if target_org == 1:
        target = 9
    elif target_org == 9:
        target = 1
    else:
        target = target_org

    answer += target * 10 ** (2-i)

    number -= target_org * 10 ** (2-i)



print(answer)

Measured memory_bytes: 3064
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;cin>>n;
	map<int,int>ma;
	rep(i,n){
		int a;cin>>a;
		ma[a]++;
	}
	int out=0;
	for(auto it=ma.begin();it!=ma.end();it++){
		int s=it->first,t=it->second;
		if(s<=t)out+=t-s;
		else out+=t;
	}
	cout<<out<<endl;
}




Measured memory_bytes: 4736
n = int(input())
h = list(map(int,input().split()))	

count = 1
max = h[0]
f = 0
if n == 1:
    print(count)
    f = 1
else:
    for i in range(1,n):
        if h[i] >= max:
            count += 1
            max = h[i]
        
if f == 0:
    print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
bool f(string& S, int l, int r) {
  while (l < r) {
    if (S[l] != S[r]) return false;
    l++;
    r--;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  bool ret = true;
  if (!f(S, 0, N-1)) ret = false;
  if (!f(S, 0, (N-1)/2-1)) ret = false;
  if (!f(S, (N+3)/2-1, N-1)) ret = false;
  if (ret) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
main :: IO ()                                                                                                              
main = getLine >>= putStrLn . f                                                                                            
                                                                                                                           
f :: [a] -> [a]                                                                                                            
f [] = []                                                                                                                  
f [x] = [x]                                                                                                                
f (x:_:xs) = x:f xs

Measured memory_bytes: 4988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		Long sum = stdIn.nextLong();
		Long min = sum;
		Long max = sum;
		Long j;

		for (int i = 0; i < x-1; i++) {
			 j = stdIn.nextLong();
			sum += j;
			min = Math.min(min, j);
			max = Math.max(max, j);
    	}
		stdIn.close();

		System.out.printf("%d %d %d%n",min,max,sum);


	}
}



Measured memory_bytes: 43264
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> B = A;
  std::sort(B.begin(), B.end());

  std::map<ll, ll> answer_map;
  for (auto i = 0;i < N;++i) {
    ++answer_map[A[i]];
  }
  ll sum_cnt {};
  auto answer_map_end = answer_map.end();
  for (auto it = answer_map.begin(); it != answer_map_end;++it) {
    ll tmp = it->second;
    sum_cnt += tmp*(tmp - 1)/2;
  }
  for (auto e : A) {
    if (answer_map[e] != 1) {
      ll tmp = answer_map[e]*(answer_map[e]-1) - (answer_map[e]-1)*(answer_map[e]-2);
      cout << sum_cnt - tmp/2 << '\n';
    } else {
      cout << sum_cnt << '\n';
    }
  }
}


Measured memory_bytes: 12672
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;
int n, m;
const int maxN = 1e5 + 5;
vector<int> edges[maxN];
int in_degree[maxN];
int dist[maxN];
bool visited[maxN];

void dfs(int a) {
    visited[a] = true;
    for (int b: edges[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if (in_degree[b] == 0)
            dfs(b);
    }
}

int main(int argc, char *argv[]) {
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        in_degree[b]++;
    }
    for (int i = 1; i <= n; ++i) {
        if (!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, dist[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=1e9+7;
vector<vector<ll> >G(100010);
ll dfs(ll i,ll p){
    ll res=0;
    for(auto e:G[i]){
        if(e==p)continue;
        res^=(dfs(e,i)+1);
    }
    return res;
}
signed main(){
    ll n;cin>>n;
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll ans=dfs(0,-1);
    if(ans)cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}

Measured memory_bytes: 13532
n,p = map(int,input().split())
s = list(map(int, list(input()))) # 数値のリストにしておく

def solve():
    if p in [2,5]: # 例外的な処理
        ret = 0
        for i in range(n): # 文字位置: i: 左から, n-1-i:右から (0 基準)
            lsd = s[n-1-i] # 最下位桁
            if lsd % p == 0: ret += n - i # LSD が割り切れたら LSD から右の桁数分加算
        return ret

    ten = 1 # S[l,r) のときの 10^r, init r=0 -> 10^0 = 1
    cnt = [0]*p # 余りで仕分けして個数を集計
    r = 0 # 左からの文字数 0 のときの余り
    cnt[r] += 1 # 余りが同じものをカウント
    for i in range(n): # 文字位置: i: 左から, n-1-i:右から (0 基準)
        msd = s[n-1-i] # 最上位桁
        r = (msd * ten + r) % p # r: 今回の余り
        ten = ten * 10 % p # N≦2*10^5 桁 なので剰余計算忘れずに！
        cnt[r] += 1 # 余りが同じものをカウント

    ret = 0
    for r in range(p): # 余り r の個数から組み合わせを計算
        ret += cnt[r] * (cnt[r] - 1) // 2 # nCr(n=i,r=2)= n(n-1)/2
    return ret

print(solve())


Measured memory_bytes: 6560
#include<cstdio>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 100
int N,B[MAXN+5];

int main(){
    N=read();
    for(int i=1;i<=N-1;i++)
        B[i]=read();
    int Ans=B[1]+B[N-1];
    for(int i=2;i<=N-1;i++)
        Ans+=min(B[i-1],B[i]);
    printf("%d",Ans);
}


Measured memory_bytes: 128
from math import cos, sin, pi

x1,y1,x2,y2 = map(int,input().split())

x3 = cos(-0.5*pi)*(x1-x2)-sin(-0.5*pi)*(y1-y2)+x2
y3 = sin(-0.5*pi)*(x1-x2)+cos(-0.5*pi)*(y1-y2)+y2

x4 = cos(0.5*pi)*(x2-x1)-sin(0.5*pi)*(y2-y1)+x1
y4 = sin(0.5*pi)*(x2-x1)+cos(0.5*pi)*(y2-y1)+y1
print(round(x3), round(y3), round(x4),round(y4))

Measured memory_bytes: 3444
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    int a[n][m];
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
        
    }
    int ans =0;
    int res[n]= {0};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            res[i] += b[j] * a[i][j];
        }
        res[i] +=c;
        if(res[i] >0)ans++;
    }
    cout << ans <<endl;
    return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		unsigned int count = 0;
		if(n == 0) break;
		vector<unsigned int> nums;
		for(int i = 0; i < n; i++){
			unsigned int t;
			cin >> t;
			nums.push_back(t);
		}
		sort(nums.begin(), nums.end());
		for(unsigned int i = 1; i < nums.size(); i++){
			count += nums[nums.size() - 1 - i] * i;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

typedef vector<int> cups;

int pos(char c) {
	return c - 'A';
}

int main() {
	cups c = {1, 0, 0};
	char a, b;
	while (scan(a)) {
		scan(b);
		swap(c[pos(a)], c[pos(b)]);
	}
	out((char)(find(c.begin(), c.end(), 1) - c.begin() + 'A'), '\n');
}


Measured memory_bytes: 2460
import itertools, math
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ans = float('inf')
comb = list(itertools.product([0, 1], repeat=d))
for i in range(len(comb)):
    s = 0
    c = 0
    for j in range(d):
        if comb[i][j] == 1:
            s += pc[j][0] * (j + 1) * 100 + pc[j][1]
            c += pc[j][0]
    div = g - s
    if div <= 0:
        ans = min(ans, c)
        continue
    for j in range(d):
        tmpdiv = div
        tmpc = c
        if comb[i][j] == 0:
            cut = min(tmpdiv // math.ceil((j + 1) * 100), pc[j][0] - 1)
            tmpc += cut
            tmpdiv -= cut * (j + 1) * 100
            if tmpdiv <= 0:
                ans = min(ans, tmpc)
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>

#define M 1000033
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return key%(M-1)+1; }
int h(int key,int i){return (h1(key)+i*h2(key))%M;}
int find(char str[]){
  int i=0;
  int x=getKey(str);
  int num = h(x,i);
  while(H[num][0]!='\0')
    {
      if(strcmp(H[num],str)==0)
	{
	  return 1;
	}
      i++;
      num=h(x,i);
    }
  return 0;

}

int insert(char str[]){
  int i=0,x=getKey(str),num=h(x,i);
  while(1)
    {
      num=h(x,i);
      if( H[num][0] == '\0' )
	{
	  strcpy(H[num],str);
	  return 1;
	}
      i++;  
    }
  
}
 

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cstdio>
#include <cinttypes>


int main()
{
	int N, K;
	//std::map<std::string, int> m;
	cin >> N;

	int n = N / 2;
	if (N & 1) {
		n += 1;
	}

	printf("%d\n", n);


	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll L,R,d,ans=0;
  cin>>L>>R>>d;
  for(int i=1;i<110;i++){
    if(L<=d*i && d*i<=R) ans++;
  }
  cout<<ans<<endl;
return 0;}

Measured memory_bytes: 3560
S = input()
Q= int(input())
r = False
h = []
t = []
for i in range(Q):
    Query = input().split()
    if int(Query[0]) == 1:
        r = not r
    else:
        if int(Query[1]) == 1 and not r or int(Query[1]) == 2 and r:
            h.append(Query[2])
        else:
            t.append(Query[2])
if not r:
    print(''.join(reversed(h))+S+''.join(t))
else:
    print(''.join(reversed(t))+S[::-1]+''.join(h))


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

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

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

  sort(v.begin(), v.end());

  for (int i = 0; i < n; i++) {
    v[i] = abs(v[i] - x);
  }

  while (v[0] == 0) v.erase(v.begin());  // 0を消す

  ll ans = v[0];
  for (int i = 0; i < v.size(); i++) {
    ans = gcd(ans, v[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, *owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3) + 1;
	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

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


	fread(ci, 1, CM, stdin);
	int K = getint();
	int N = getint();
	int A0 = getint();
	int mae = A0;
	int kotae = 0;
	rep(i, N - 1) {
		int a = getint();
		chmax(kotae, a - mae);
		mae = a;
	}

	chmax(kotae, A0 + K - mae);

	printf("%d", K - kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.141592653589793238
using namespace std;
double a,b,x,as;
int main(){
	cin>>a>>b>>x;
	if(x==a*a*b)
	{
		cout<<0<<endl;
		return 0; 
	}
	if(x<=a*a*b/2)
	{
		as=x*2/b/a;
		as=sqrt(as*as+b*b);
		printf("%.10lf\n",asin(b/as)*180/pi);
	}
	else
	{
		x=a*a*b-x;
		as=x*2/a/a;
		as=sqrt(as*as+a*a);
		printf("%.10lf\n",90-asin(a/as)*180/pi);
	}
	return 0;
}

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

#define endl '\n'

vector<vector<int>> adj;
vector<int> vis, ans;

void solve(){
    int n,m; cin >> n >> m;
    vis = ans = vector<int>(n+1);
    adj = vector<vector<int>>(n+1);
    for (int i=0; i<m; i++){
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int top = q.front(); q.pop();
        for (int c : adj[top]){
            if (!ans[c]){
                ans[c] = top;
                q.push(c);
            }
        }
    }
    cout << "Yes\n";
    for (int i=2; i<=n; i++) cout << ans[i] << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solve();
}

Measured memory_bytes: 10572
open Printf
open Scanf

let solve k a b =
  if a <= b && a >= k then 1
  else if a <= b then -1
  else let i = (k - b + a - b - 1) / (a - b) in max 1 (2 * i - 1)

let () =
  scanf "%d %d %d " solve |> printf "%d\n"


Measured memory_bytes: 3788
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int t=0,T[N],M,i,P,X;

	for(i=0;i<N;i++){
		scanf("%d",&T[i]);
		t+=T[i];
	}
	scanf("%d",&M);
	int total[M];

	for(i=0;i<M;i++){
		scanf("%d %d",&P,&X);
		total[i]=t-T[P-1]+X;
	}
	for(i=0;i<M;i++)
		printf("%d\n",total[i]);
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int mx = 0, mn = 1e9;
  FOR(i,0,n) {
    int a;
    cin >> a;
    mx = max(a, mx);
    mn = min(a, mn);
  }
  cout << mx - mn << endl;
}

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

using namespace std;
int n;

long long res;
int a[10000];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        res += a[i];
    }

    sort(a, a+n);

    if (res % 10 > 0) {
        cout << res << "\n";
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] % 10 > 0) {
            cout << res - a[i] << "\n";
            return 0;
        }
    }

    cout << 0 << "\n";



    return 0;
}


Measured memory_bytes: 256
N_K_var = input().split()
price_list_var = input().split()

N_K = [int(s) for s in N_K_var]
price_list = [int(s) for s in price_list_var]

price_sorted = sorted(price_list)
price = 0
for i in range(N_K[1]):
    price += price_sorted[i]

print(price)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] weight = new int[n];
        for (int i=0; i<n; i++){
            weight[i] = sc.nextInt();
        }

        // ?????¨??????????´¢???????????§????????????solve???
        // n????????¶?????´???100,000???????????????????????´?????¶???100,000????????\???????????´???1~10^10
        System.out.println(solve(n, k, weight));

    }

    private static long solve(int n, int k, int[] weight) {
        long left = 0;
        long rihgt = 100000 * 100000;

        while(rihgt-left > 1){
            long mid = (left+rihgt)/2;
            int temp = check(mid, n, k, weight);
            if (temp >= n){
                rihgt = mid;
            }
            else {
                left = mid;
            }
        }

        return rihgt;
    }

    private static int check(long p, int n, int k, int[] weight) {

        int i = 0;

        for (int j=0; j<k; j++){
            long s = 0;
            while (s+weight[i] <= p){
                s += weight[i];
                i++;
                if (i == n){
                    return n;
                }
            }
        }

        return i;
    }
}

Measured memory_bytes: 70796
# coding: utf-8
S = input()
def check(S):
    ret = True
    for i in range(len(S)//2):
        if S[i] != S[-i-1]:
            ret = False
    return ret
if len(S) == 3:
    if S[0] != S[-1]:
        print("No")
    else:
        print("Yes")
    exit()
flag = True
if not check(S):
    flag = False
if not check(S[:(len(S))//2]):
    flag = False
if not check(S[(len(S)+3)//2-1:]):
    flag = False
print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, k;
	while (scanf("%d%d", &n, &k), n | k)
	{
		int c[10];
		for (int i = 0; i < n; ++i)
			scanf("%d", c + i);

		set<int> combi;
		sort(c, c + n);
		do
		{
			int seq = 0;
			for (int i = 0; i < k; ++i)
			{
				if (c[i] < 10)
					seq = seq*10 + c[i];
				else
					seq = seq*100 + c[i];
			}
			combi.insert(seq);
		} while (next_permutation(c, c + n));
		printf("%d\n", combi.size());
	}
}

Measured memory_bytes: 976
package main

import (
        "fmt"
)

func main() {
        var s, b, w []int
        var n int

        fmt.Scanf("%d", &n)
        var nb, nw int
        for i := 0; i < n; i++ {
                var c rune
                fmt.Scanf("%c", &c)
                if c == '.' {
                        s = append(s, 0)
                        nw++
                } else {
                        s = append(s, 1)
                        nb++
                }
                b = append(b, nb)
                w = append(w, nw)
        }
/*
        var idx, last int
        last = s[0]

        for i := 1; i < n; i++ {
                if last == 1 && s[i] == 0 {
                        idx = i
                        break
                }
                last = s[i]
        }
        lb := b[idx]
        rw := w[n-1] - w[idx]
*/
        var m int
        m = n
        for i := 0; i < n; i++ {
                lb := b[i]
                rw := w[n-1] - w[i]
                if m > lb + rw {
                        m = lb + rw
                }
        }
        //m = lb + rw
        if m > b[n-1] {
                m = b[n-1]
        }
        if m > w[n-1] {
                m = w[n-1]
        }

        fmt.Println(m)
        /**
        fmt.Println(s)
        fmt.Println(b)
        fmt.Println(w)
  **/
}


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


int main(){
    int n,k;
    cin  >> n >> k;
    vector<int> a(n);
    int amin = 1;
    int amax = 1;
    rep(i,n) {
        cin >> a[i];
        amax = max(amax,a[i]);
    }
    ll sum =0;
    rep(i,n){
        sum += a[i];
    }

    if(sum <= k){
        cout << 1 << endl;
        return 0;
    }
    int x = 1;
    while(amax-amin>1){
        //cout << amax << " " <<amin << endl;
        sum = 0;
        x = (amax+amin)/2;
        rep(i,n){
            sum += a[i]/x;
            if(a[i]%x==0) sum--;
        }
        //cout << " " << sum << endl;
        if(sum<=k) amax = x;
        else amin = x;
    }

    cout << amax << endl;



 }

Measured memory_bytes: 3992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),x=sc.nextInt();
		double ans;
		if(x>=(double)a*a*b/2) ans = (double)2*(a*a*b-x)/(a*a*a);
		else ans = (double)a*b*b/(2*x);
		System.out.printf("%.10f\n",(double)180*Math.atan(ans)/Math.PI);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll k, a, b;
int main(){
    cin>>k>>a>>b;
    
    if(b-a > 2){
        ll ans=0;
        if(a+1<=k){
            ans+=b;
            k-=a+1;
            ans+=(k/2*(b-a))+(k%2);
            cout<<ans<<endl;
        }
        else{
            cout<<1+k<<endl;
        }
    }
    else{
        cout<<1+k<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)

{

 int a[3000];
 int b[3000];
 int c = 0;
 int i = 0;

 while (i == 0)
{

 scanf("%d", &a[c]);
 scanf("%d", &b[c]);

 if (a[c] != 0 || b[c] != 0)
{
  if (a[c] >= b[c])
    printf("%d %d\n", b[c], a[c]);

  else 
    printf("%d %d\n", a[c], b[c]);

 }

  if (a[c] == 0 && b[c] == 0)
   i = 1;

 c++;

}

 return 0;

}






Measured memory_bytes: 2064
num_tower, num_path = [int(ipt) for ipt in input().split(' ')]

heights = [0] + [int(h) for h in input().split(' ')]

bad_towers = set()

for p in range(num_path):
  tower_1, tower_2 = [int(t) for t in input().split(' ')]
  # either one is lower
  if heights[tower_1] < heights[tower_2]:
    bad_towers.add(tower_1)
  elif heights[tower_1] > heights[tower_2]:
  	bad_towers.add(tower_2)    
  # same height
  else:
    bad_towers.add(tower_1)
    bad_towers.add(tower_2)
    
print(num_tower - len(bad_towers))


Measured memory_bytes: 19988
#include<bits/stdc++.h>
using namespace std;
long long n,a,cnt[55][2525];
int main()
{
	cin>>n>>a;
	cnt[0][0]=1;
	for(long long i=1;i<=n;i++)
	{
		long long x;
		cin>>x;
		for(long long j=i;j>0;j--)
		{
			for(long long k=x;k<=2500;k++)
			{
				cnt[j][k]+=cnt[j-1][k-x];
			}
		}
	}
	long long ans=0;
	for(long long i=1;i<=n;i++)
	{
		ans+=cnt[i][a*i];
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

bool dp_x[5001][2 * 8000 + 1], dp_y[5001][2 * 8001 + 1]; //1-indexed

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    s += 'T'; // sentinell
    int cnt_F = 0, cnt_T = 0, cnt_X = 0, cnt_Y = 1;
    dp_y[0][8000] = true;
    rep(i, s.size()) {
        if (s[i] == 'F') {
            ++cnt_F;
        } else {
            ++cnt_T;
            if (cnt_T % 2) {
                if (cnt_T == 1) {
                    dp_x[cnt_X][8000 + cnt_F] = true;
                    ++cnt_X;
                } else {
                    for (int j = 0; j < 16001; ++j) {
                        if (! dp_x[cnt_X - 1][j]) continue;
                        if (j - cnt_F >= 0) dp_x[cnt_X][j - cnt_F] |= dp_x[cnt_X - 1][j];
                        if (j + cnt_F < 16001) dp_x[cnt_X][j + cnt_F] |= dp_x[cnt_X - 1][j];
                    }

                    ++cnt_X;
                }
            } else {
                for (int j = 0; j < 16001; ++j) {
                    if (! dp_y[cnt_Y - 1][j]) continue;
                    if (j - cnt_F >= 0) dp_y[cnt_Y][j - cnt_F] |= dp_y[cnt_Y - 1][j];
                    if (j + cnt_F < 16001) dp_y[cnt_Y][j + cnt_F] |= dp_y[cnt_Y - 1][j];
                }

                ++cnt_Y;
            }

            cnt_F = 0;
        }
    }

    if (dp_x[cnt_X - 1][8000 + x] && dp_y[cnt_Y - 1][8000 + y]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 125696
require 'set'

loop {
	n, h = gets.split.map &:to_i
	break if n == 0

	used_x = {}
	used_y = {}
	z_lines = Set.new

	h.times {
		face, u, v = gets.split
		u = u.to_i
		v = v.to_i
		case face
		when 'xy'
			z_lines << [u, v]
		when 'xz'
			(used_x[v] ||= Set.new) << u
		when 'yz'
			(used_y[v] ||= Set.new) << u
		end
	}

	count = 0
	(1..n).each{|z|
		a = used_x[z] || []
		b = used_y[z] || []
		count += n * (a.size + b.size) - a.size * b.size
		z_lines.each{|x, y|
			count += 1 unless a.include?(x) || b.include?(y)
		}
	}
	p n**3 - count
}

Measured memory_bytes: 6392
H, W, M = map(int, input().split())
test = [[i, i] for i in range(1, M+1)]
tH, tW, tag = [0]*H, [0]*W, set()
Hmax, Wmax = 0, 0

for _ in range(M):
    h, w = map(int, input().split())
    tH[h-1] += 1
    tW[w-1] += 1
    tag.add(W*(h-1) + (w-1))
    Hmax = max(Hmax, tH[h-1])
    Wmax = max(Wmax, tW[w-1])

Hind = [i for i, x in enumerate(tH) if x == Hmax]
Wind = [i for i, x in enumerate(tW) if x == Wmax]
if len(Hind) * len(Wind) > M:
    print(Hmax + Wmax)
    exit()
else:
    for h in Hind:
        for w in Wind:
            if W*h + w not in tag:
                print(Hmax + Wmax)
                exit()
print(Hmax + Wmax - 1)

Measured memory_bytes: 97216
from itertools import combinations
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
ans=0
for i in range(N):
    B[A[i]]+=1
for i in range(1,N+1):
    ans+=B[i]*(B[i]-1)//2
for k in range(0,N):
    print(ans-B[A[k]]+1)


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

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

  char a;

  for(int i=0; i<n; i++){
    scanf("%c",&a);
    if(a == 'Y'){
      puts("Four");
      return 0;
    }
  }

    puts("Three");
    return 0;

}



Measured memory_bytes: 128
#include <stdio.h>
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    do{
        c=c-b;
        a=a-d;
        if(c<=0){
            printf("Yes");
            return 0;
        }

        if(a<=0){
            printf("No");
            return 0;
        }
    }while(1);
}


Measured memory_bytes: 1732
#include <stdio.h>

int main(void) {
  int N;
  int R;

  scanf("%d", &N);
  scanf("%d", &R);
  if (N >= 10) {
    printf("%d\n", R);
  } else {
    printf("%d\n", R + 100 * (10 - N));
  }
  return 0;
}

Measured memory_bytes: 1724
n=input()
s=raw_input().split()
a=[0 for i in range(n)]
b=[0 for i in range(100005)]
mini=1000005
maxi=-1
for i in range(n):
    a[i]=int(s[i])
    b[a[i]]+=1
maxi=-1
for i in range(100001):
    maxi=max(maxi,b[i]+b[i+1]+b[i+2])
print maxi


Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;


string f(string a, string b) {
    int dp[8][10];
    memset(dp, 0, sizeof dp);
    for (int i = a.size() - 1; i >= 0; i--) {
        if (b[i] == '?') {

            for (int j = a[i] - '0' + 1; j < 10; j++) {
                dp[i][j] = 1;
            }
        }
    }
}



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t1 = a / d + (a % d ? 1 : 0);
    int t2 = c / b + (c % b ? 1 : 0);
    cout << (t1 < t2 ? "No" : "Yes");


}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int k;
vi a;

int I_Love_Hashimoto_Kanna() {
	fastio;
	cin>>k;
	int n,m=0;
	FOR(i,0,21){
		if(k&(1<<i)){
			k-=(1<<i);
			a.push_back(1);
			m++;
		}
		else a.push_back(0);
		if(!k)break;
	}
	n=a.size();
	m+=(a.size()-1)*2-1;
	cout<<n<<" "<<m<<endl; 
	int mx=0;
	FOR(i,0,a.size()-1){
		cout<<i+1<<" "<<i+2<<" "<<0<<endl;
		cout<<i+1<<" "<<i+2<<" "<<(1<<i)<<endl;
		mx+=(1<<i);
	}
	for(int i=a.size()-2;i>=0;i--){
		if(!a[i])continue;
		cout<<i+1<<" "<<n<<" "<<++mx<<endl;
		FOR(j,0,i)mx+=(1<<j);
	}
	
	
	return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    a, b = map(int, input().split())
    ans = 0
    for n in range(a, b + 1):
        c = str(n)
        l = len(c)
        circle = True
        for i in range(l // 2):
            if c[i] != c[-i-1]:
                circle = False
                break
        if circle: ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 73304
n_ = int(input())
a = [int(i) for i in input().split()]

n = max(a)
r = n

if n_ == 2:
    print(max(a), min(a))

else:
    for i in a:
        if abs(r-int(n/2)) > abs(i-int(n/2)):
            r = i

    print(n, r)

Measured memory_bytes: 14052
#include<stdio.h>

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




Measured memory_bytes: 2096
n=int(input())
s=input()
ans=0
for aim in range(100):
  sa=str(aim)
  if aim<=9:sa="0"+sa
  cnt=0;k=-1
  for i in range(n):
    if sa[cnt]==s[i]:cnt+=1
    if cnt==2:k=i;break
  else:continue
  ans+=len(set(list(s[k+1:])))
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define inf 0x3f3f3f3f
#define maxn 15
using namespace std;
typedef long long ll;
int d,g,p[maxn],c[maxn];
vector <int> rest;
int main(){
	scanf("%d%d",&d,&g);
	for(int i=1;i<=d;i++){
		scanf("%d%d",&p[i],&c[i]);
	}
	int ans = inf;
	for(int i=0;i<(1 << d);i++){
		int res = 0,scr = 0;
		rest.clear();
		for(int j=1;j<=d;j++){
			if(i & (1 << (j-1))){
				res += p[j];
				scr += p[j] * j * 100 + c[j];
			}else{
				rest.push_back(j);
			}
		}
		if(scr >= g){
			ans = min(ans,res);
			continue;
		}
		for(int j=rest.size()-1;j>=0;j--){
			for(int k=1;k<=p[rest[j]];k++){
				scr += rest[j] * 100;
				res++;
				if(scr >= g){
					ans = min(ans,res);
					break;
				}
			}
			if(scr >= g){
				break;
			}
		}
		ans = min(ans,res);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:1710886400")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	int n, p;
	long long dp[60][2];
	cin >> n >> p;
	dp[0][0] = 1;
	dp[0][1] = 0;
	for (int i = 1; i <= n; ++i) {
		int a;
		cin >> a;
		if (a % 2 == 0) {
			dp[i][0] = 2 * dp[i - 1][0];
			dp[i][1] = 2 * dp[i - 1][1];
		}
		else {
			dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
			dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
		}
	}
	cout << dp[n][p] << endl;

	my_return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  int out[256]={0};
  while(getline(cin,s)){
    rep(i,s.size()){s[i]=tolower(s[i]);out[s[i]]++;}
  }
    for(char i='a';i!='z'+1;i++)cout<<i<<" : "<<out[i]<<endl;
}

Measured memory_bytes: 1176
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

s = S()
if s == "ABC":
    print("ARC")
else:
    print("ABC")

Measured memory_bytes: 77088
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n,sum;
    while(~scanf("%d",&n))
    {
      sum=0;
      for(int i=1;i<=n;i++)
        sum+=i;
      printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])
    B = input([int, N])
    C = input([int, N - 1])

    ans = 0    
    for n in range(N):
        ans += B[A[n] - 1]
        if 0 < n:
            if A[n - 1] + 1 == A[n]:
                ans += C[A[n - 1] - 1]
    print(ans)

    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3444