akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
constexpr long long mod = 998244353;
typedef pair<int, int> P;
string a, b;
int n;
int mincost(vector<P>V) {
	if (V.empty())return 0;
	sort(V.begin(), V.end());
	vector<int>G[2005];
	vector<int>mx(2005);
	rep(i, V.size()) {
		G[V[i].first].push_back(V[i].second);
		mx[V[i].first] = max(mx[V[i].first], V[i].second);
	}
	int res = 1e9;
	int r = 0;
	for(int i=2000;i>=0;i--) {
		res = min(res, i + r);
		r = max(r, mx[i]);
	}
	return res;
}

int ok() {
	int ca = 0, cb = 0;
	rep(i, n)ca += a[i] - '0';
	rep(i, n)cb += b[i] - '0';
	if (!cb) {
		if (!ca)return 1;
		return 0;
	}
	return 2;
}

int solve() {
	vector<int>V1;
		rep(i, n) {
			if (b[i] == '1') {
				V1.push_back(i);
				V1.push_back(i + n);
			}
		}
		sort(V1.begin(), V1.end());;

		int ans = 1e9;

		string K(n, '0');
		rep(i, n) {
			vector<int>V2;
			rep(j, n) {
				if (b[i + j] == '1') {
					K[j] = b[i + j];
					V2.push_back(j);
					V2.push_back(j + n);
				}
			}
			sort(V2.begin(), V2.end());

			int cost2 = 0;
			vector<int>pena;
			rep(j, n) {
				if (a[j] != b[i + j]) {
					cost2++;
					if (K[j] == '0') {
						pena.push_back(j);
					}
				}
			}
			vector<P>cost;
			rep(j, pena.size()) {
				int l = *(upper_bound(V1.begin(), V1.end(), pena[j]+n)-1);
				int r = *lower_bound(V2.begin(), V2.end(), pena[j]);
			
				l = pena[j] + n - l;
				l %= n;
				r -= pena[j];
				cost.push_back(P(l, r));
			}
			ans = min(ans, mincost(cost) * 2 + cost2 + i);
		}
		return ans;
}

int main() {
	cin >> a >> b;
	n = a.size();
	b += b;

	if (ok() == 0)cout << -1 << endl;
	else if (ok() == 1)cout << 0 << endl;
	else {
		int ans = solve();
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		ans = min(ans, solve());
		cout << ans << endl;
	}
}

Measured memory_bytes: 384
import math
x = y = 0
h = math.radians(90)
while True:
    d, t = map(int, input().split(","))
    if d == t == 0:
        break
    x += d * math.cos(h)
    y += d * math.sin(h)
    h -= math.radians(t)
print(int(x))
print(int(y))


Measured memory_bytes: 5712
fn main() {
    let scan = std::io::stdin();
    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();

    let n: u32 = vec[0].parse().unwrap_or(0);
    let m: u32 = vec[1].parse().unwrap_or(0);
    println!("{}", n+m/2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct RollingHash{
  static const int base1 = 1007, base2 = 2009;
  static const int mod1 = 1000000007, mod2 = 1000000009;
  vector<ll> hash1, hash2, power1, power2;

  RollingHash(const string &s){
    int n = (int)s.size();
    hash1.assign(n+1,0);
    hash2.assign(n+1,0);
    power1.assign(n+1,1);
    power2.assign(n+1,1);
    rep(i,n){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      power1[i+1] = (power1[i]*base1)%mod1;
      power2[i+1] = (power2[i]*base2)%mod2;
    }
  }
  pair<ll, ll> get(int l, int r){
    ll res1 = hash1[r]-hash1[l]*power1[r-l]%mod1;
    if(res1<0) res1+=mod1;
    ll res2 = hash2[r]-hash2[l]*power2[r-l]%mod2;
    if(res2<0) res2+=mod2;
    return {res1, res2};
  }
  int getLCP(int a, int b){
    int len = min((int)hash1.size()-a, (int)hash1.size()-b);
    int low = 0, high = len;
    while(high-low>1){
      int mid = (low+high)>>1;
      if(get(a,a+mid)!=get(b,b+mid)) high=mid;
      else low = mid;
    }
    return low;
  }
};

signed main(){
  int n; cin>>n;
  string s; cin>>s;
  RollingHash rh(s);

  int res = 0;
  rep(i,n){
    for(int j=i+1; j<n; j++){
      int lcp = rh.getLCP(i,j);
      lcp = min(lcp,j-i);
      res = max(res, lcp);
    }
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long lli;

lli res, L;

class p {
public:
	p* nxt[2];
	lli h;
	p() {
		nxt[0] = nxt[1] = NULL;
	}
	void ins(string& s, int k) {
		h = k;
		if (k == s.size()) return;
		if (nxt[s[k] - '0'] == NULL) nxt[s[k] - '0'] = new p();
		nxt[s[k] - '0']->ins(s, k + 1);
	}
	void dfs() {
		int cnt = 0;
		if (nxt[0] != NULL) {
			cnt++; nxt[0]->dfs();
		}
		if (nxt[1] != NULL) {
			cnt++; nxt[1]->dfs();
		}
		if (cnt == 1) {
			lli add = 1;
			lli w = L - h;
			while (w % 2 == 0) {
				w /= 2; add *= 2;
			}
			res ^= add;
		}
	}
};

p* root;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> L;
	root = new p();
	while (n--) {
		cin >> s;
		root->ins(s, 0);
	}
	root->dfs();
	if (res) cout << "Alice\n";
	else cout << "Bob\n";
	return 0;
}

Measured memory_bytes: 5584
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vii vector<int>
#define vcc vector<char>
#define pll pair<long long, long long>
#define mem memset
#define sof sizeof
#define co1 __builtin_popcountll
#define PB push_back
#define UB upper_bound
#define LB lower_bound
#define MP make_pair
#define TS to_string
#define F first
#define S second
#define endl '\n'
using namespace std;
 
long long __lcm(long long a, long long b){
    ll gd = __gcd(a,b);
    ll xx = (a*b)/gd;
    return xx;
}
 
long long bigmod(long long a, long long b, long long M){
    if(b==0) return 1%M;
    ll x = bigmod(a,b/2,M);
    x=(x*x)%M;
    if(b%2==1) x=(x*a)%M;
    return x;
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    cin>>n;
    if(n%1000==0) cout<<0;
    else cout<<1000-(n%1000);
}

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	int n; cin>>n;
	vl a(n); forn(i, n) cin>>a[i];
	int ans = 0;
	forn(i, n) ans += (a[i]%2==1)&&(i%2==0);
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen(".inp.txt", "r", stdin);
    	freopen(".out.txt", "w", stdout);
    	freopen(".err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3652
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

#print(N,M)
comb_N=0
comb_M=0
if N>=2:
  comb_N = (N*(N-1))/2
if M>=2:
  comb_M = (M*(M-1))/2

print(int(comb_N+comb_M))

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

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

int main(){
    int n; cin >> n;
    vector <pair<ll, ll>> Q(n);
    rep(i, n)cin >> Q.at(i).first >> Q.at(i).second;
    pair <ll, ll> now_t_a = make_pair(1, 1);

    for(auto q: Q){
        ll F = q.first;
        ll S = q.second;

        ll max_div = (now_t_a.first + (F - 1)) / F;
        max_div = max(max_div, (now_t_a.second + (S - 1)) / S);

        F *= max_div;
        S *= max_div;

        //cout << F << " " << S << endl;

        now_t_a = make_pair(F, S);
        
    }

    cout << now_t_a.first + now_t_a.second << endl;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>

using namespace std;
typedef long long ll; //64bit型

const int INF = 1050000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int N_MAX = 2010;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() //input->compute->output
{
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=a;i<b+1;i++){
        if(c%i==0) ans++;
        
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <set>

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(void) {
	// cin, coutの結びつきを解除し、速くする
	cin.tie(0);
   	ios::sync_with_stdio(false);

	string S; cin >> S;
	long long int count = 0;
	long long int w_sum = 0;
	REP(i, S.size()) {
		if (S.at(i) == 'W') {
			w_sum += i;
			count++;
		}
	}
	long long int w_base;
	if (count == 0)
		w_base = 0;
	else
		w_base = count * (count - 1) / 2;

	long long int ans = w_sum - w_base;

	cout << ans << endl;


}


Measured memory_bytes: 720
n = int(input())

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

mod = 10**9 + 7

from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

x = lcm_list(a)
# print(x)

ans = 0
for i in range(n):
    ans += int(x//a[i])

print(int(ans)%mod)

Measured memory_bytes: 5576
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

	int n = s.length();
	long long ans = 0;
	for(int i = 0; i < (1 << (n-1)); i++){
		string formula = "";
		formula += s[0];

		for(int j =0; j < n-1; j++){
			if(i & (1 << j)) formula += '+';
			formula += s[j+1];
		}

		int k = 0;
		ll num = 0;
		while(k < formula.size()){
			if(formula[k] == '+'){
				ans += num;
				num = 0;
			}
			else num = num*10 + (formula[k] - '0');
			k++;
		}
		ans += num;
	}

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


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

using namespace std;
int a, b, c, d;
int main() {
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    
    if ((a + b) > (c + d))
        cout << "Left\n";
    else if ((a + b) < (c + d))
        cout << "Right\n";
    else
        cout << "Balanced\n";
}


Measured memory_bytes: 256
fn main() {
    let n: i32 = read();
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for _ in 0..n {
        let s: String = read();
        match s.as_ref() {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            _ => re += 1,
        }
    }

    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2092
#include <stdio.h>
int main(void){
	int i,seisu[10000];//????????°?????????
	for(i=1;i<=10000;i++){//??\????????????
		scanf("%d",&seisu[i-1]);
		if (seisu[i-1]==0){//0?????\?????????????????????
			break;
		}
		printf("Case %d: %d\n",i,seisu[i-1]);
	}
	return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  
  // hill climbing
  int lm = 0;
  int sc[26];
  for(;;) {
    if((xor64()>>25)&1) {
      int d = xor64()%D;
      int pi = t[d];
      last[pi].erase(d);
      for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
      int mi = std::max_element(sc, sc+26) - sc;
      t[d] = mi;
      last[mi].insert(d);
      if(mi != pi) lm = 0; else ++lm;
    } else {
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-16 || d2 < d1-16 || t[d1] == t[d2]) {
        d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
        ++lm;
      }
    }
    if(lm >= 100000) break;
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>

int main() {
	int m, n;
	int x, y;

	int i, j, k;
	int ans[128];
	int order[128][2];

	int flag;

	scanf("%d%d", &m, &n);

	for(i = 0; i < m; i++)
		ans[i] = i + 1;

	for(i = 0; i < n; i++) {
		scanf("%d%d", &order[i][0], &order[i][1]);
		//		printf("%d %d\n", order[i][0], order[i][1]);
	}

	while(1) {
		flag = 1;
		for(i = 0; i < n; i++) {
			for(x = 0; ans[x] != order[i][0]; x++);
			for(y = 0; ans[y] != order[i][1]; y++);

			if(y < x) {
				flag = 0;
				for(k = y; k < x; k++) {
					int temp = ans[k];
					ans[k] = ans[k + 1];
					ans[k + 1] = temp;
				}
			}
		}
		if(flag)
			break;
	}

	for(i = 0; i < m; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='0'&&s[i+1]=='0'){
			if(s[i+2]=='1'){
				s[i+2]='0';
				s[i+1]='1';
				ans+=2;
			} else {
				s[i+1]='1';
				ans++;
			}
		}
		else if(s[i]=='1'&&s[i+1]=='1'){
			if(s[i+2]=='0'){
				s[i+2]='1';
				s[i+1]='0';
				ans+=2;
			} else {
				s[i+1]='0';
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 512
using System;

namespace tes
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split();
            int a = int.Parse(line1[0]);
            int b = int.Parse(line1[1]);
            int c = int.Parse(line1[2]);

            if ((a < b)&&(b < c))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

Measured memory_bytes: 8944
using System;

namespace Atc_0019
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int N = int.Parse(str.Split(' ')[0]);
            int X = int.Parse(str.Split(' ')[1]);
            int T = int.Parse(str.Split(' ')[2]);
            int count = 0;
            while (true)
            {
                count++;
                N = N - X;
                if (N <= 0)
                {
                    break;
                }
                
            }

            Console.WriteLine(count * T);
        }
    }
}


Measured memory_bytes: 27300
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder text = new StringBuilder();
		while (true) {
			String line = scan.nextLine();
			String[] elems = line.split(" ");
			int a = Integer.parseInt(elems[0]);
			String op  = elems[1];
			int b = Integer.parseInt(elems[2]);
			if (op.equals("?")) {
				scan.close();
				text.deleteCharAt(text.lastIndexOf("\n"));
				System.out.println(text.toString());
				break;
			} else {
				if(op.equals("+")){
					text.append(a + b).append("\n");
				}else if(op.equals("-")){
					text.append(a - b).append("\n");
				}else if(op.equals("*")){
					text.append(a * b).append("\n");
				}else if(op.equals("/")){
					text.append(a / b).append("\n");
				}
			}
		}
	}
}

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

int main(void){
  int K,N,a;
  scanf("%d %d",&N,&K);
  if(K==1 || K>10){
    printf("Kの値は１＜K＜１１です。\n");
    exit(1);
  }
  a=N;
  for(int i=0;i<N;i++){
    if(a<K){
      printf("%d\n",i+1);
    break;
    }
    a=a/K;
  }
  
  return 0;
}
    
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<char> t[100100];
int main(){
    char a;
    int n, k, r, s, p, ans = 0;
    scanf("%d %d %d %d %d", &n, &k, &s, &p, &r);
    for(int i = 0; i < n; i++){
        scanf(" %c", &a);
        t[i%k].push_back(a);
    }
    for(int i = 0; i < k; i++){
        a = 'o';
        for(auto x : t[i]){
            if(x == a){
                a = 'o';
            }
            else{
                a = x;
                if(x == 's'){
                    ans += s;
                }
                else if(x == 'p'){
                    ans += p;
                }
                else if(x == 'r'){
                    ans += r;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int H, W, D; cin >> H >> W >> D;
  map<int, P> A;
  rep(i, H) {
    rep(j, W) {
      int a; cin >> a;
      A[a] = make_pair(i, j);
    }
  }
  int power[90090];
  rep1(i, D) {
    power[i] = 0;
  }
  Rep1(i, D + 1, H * W) {
    power[i] = power[i - D] + abs(A[i].fr - A[i - D].fr) + abs(A[i].sc - A[i - D].sc);
  }
  int Q; cin >> Q;
  rep(i, Q) {
    int L, R; cin >> L >> R;
    cout << power[R] - power[L] << "\n";
  }
  return 0;
}

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

#define N 1005

using namespace std;

long long a,b,c,ans,k;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

long long max(long long cmp1,long long cmp2){
	if(cmp1>cmp2)
	return cmp1;
	else return cmp2; 
}

void init(){
	cin>>a>>b>>c;
	cin>>k;
}	

int main(){
	init();
	long long Max=max(a,max(b,c)),mul=1;
	for(int i=1;i<=k;i++)
	mul*=2;
	ans=a+b+c-Max+Max*mul;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

x.sort()
y.sort()

for i in range(x[-1]+1, y[0]+1):
    if X < i <= Y:
        print('No War')
        break
else:
    print('War')


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

using namespace std;

int main() {
    int n;
    cin >> n;
    int now = n;
    int count = 0;
    while (now > 0) {
        count += now % 10;
        now /= 10;
    }
    if (n % count == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	int n; cin >> n;
	set<string>sts;
	for (int i = 0; i < n; ++i) {
		string st; cin >> st;
		sts.emplace(st);
	}
	int m; cin >> m;
	bool close = true;
	for (int i = 0; i < m; ++i) {
		string st; cin >> st;
		if (sts.find(st) != sts.end()) {
			if (close) {
				cout << "Opened by " << st << endl;
			}
			else {
				cout << "Closed by " << st << endl;
			}
			close = !close;
		}
		else {
			cout << "Unknown " << st << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3240
//答え見ました。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
 
int main() {
  ll n;
  cin >> n;
  
  int ans = 10e6;
  for(int i=0; i<=n; i++){
    int res;
    int t = i;
    while(t>0) res+=t%6,t/=6;
    t=n-i;
    while(t>0) res+=t%9,t/=9;
    ans=min(ans,res);
  }
  
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head = 1, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail++;
}

P dequeue(void){
  head++;
  return Q[head - 1];
}


int main(){
  int elaps = 0;
  int i, q;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  tail = i;
  while(head != tail){
    Q[head].t -= q;
    if(Q[head].t > 0){
      elaps += q;
      enqueue(Q[head]);
    } else { elaps += q + Q[head].t;
      printf("%s %d\n", Q[head].name, elaps);
    }
    dequeue();
    if(tail == 100005) tail = 1;
    if(head == 100005) head = 1;
  }
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 512
int a[N][N]={};

int main(){
	int n; scanf("%d", &n);
	REP(i, 9){
		REP(j, N){
			REP(k, N){
				if(a[j][k]) continue;
				if((j&(1<<i)) != (k&(1<<i))) a[j][k]=i+1;
			}
		}
	}
	REP(i, n){
		FOR(j, i+1, n){
			printf("%d ", a[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 1536
<?php
while(1){
  $L=trim(fgets(STDIN));
  if($L=='-') break;
  $Ll=strlen($L);

  $m=trim(fgets(STDIN));
  for($i=0;$i<$m;$i++){
    $h=trim(fgets(STDIN));
    $l='';
    for($j=$h;$j<$Ll;$j++) $l.=$L[$j];
    for($j=0;$j<$h;$j++) $l.=$L[$j];
    $L=$l;
  }

  echo $L,PHP_EOL;
}

Measured memory_bytes: 15412
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  int a,b;
  cin>>a>>b;
  int ans;
  if(b==1){
    cout<<0<<endl;
    return 0;
  }
  REPP(k,30){
    if(1+(a-1)*k>=b){
      ans = k;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
int n, k;
int cp, cn;
typedef pair<ll, int>pii;
vector<pii>vc, vv;
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		ll x;
		scanf("%lld", &x);
		if (x < 0)vc.push_back(pii(-x, 1)), cn++;
		else vc.push_back(pii(x, 0)), cp++;
	}
	if (k == n && (k & 1) != (cp & 1) || cp == 0 && (k & 1)) {
		ll ans = 1ll;
		sort(vc.begin(), vc.end());
		for (int i = 0; i < k; i++)ans = ans * vc[i].first % mod;
		ans = (mod - ans) % mod;
		printf("%lld\n", ans);
	}
	else {
		ll ans = 1ll;
		int cnt = 0;
		sort(vc.begin(), vc.end(), greater<pii>());
		for (int i = 0; i < k; i++) {
			vv.push_back(vc[i]);
			cnt += vc[i].second;
		}
		if (cnt & 1) {
			ll tmp1 = vv.back().first, tmp2;
			int p1 = -1, p2 = -1, q = -1;
			int t = vv.back().second;
			for (int i = (int)vv.size() - 2; i >= 0; i--) {
				if (vv[i].second != t) {
					tmp2 = vv[i].first;
					q = i;
					break;
				}
			}
			if (q == -1) {
				for (int i = k; i < (int)vc.size(); i++) {
					if (vc[i].second != t) {
						vv.pop_back();
						vv.push_back(vc[i]);
						break;
					}
				}
			}
			else {
				for (int i = k; i < (int)vc.size() && (p1 == -1 || p2 == -1); i++) {
					if (vc[i].second != t) {
						if (p1 == -1) {
							p1 = i;
							tmp2 *= vc[i].first;
						}
					}
					else {
						if (p2 == -1) {
							p2 = i;
							tmp1 *= vc[i].first;
						}
					}
				}
				if (p2 == -1 || p1 != -1 && tmp1 < tmp2) {
					vv.pop_back();
					vv.push_back(vc[p1]);
				}
				else {
					vv.erase(vv.begin() + q);
					vv.push_back(vc[p2]);
				}
			}
		}
		for (pii p : vv)ans = ans * p.first%mod;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 12492
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N;
  cin >> N;
  VI a(N);
  set<int> s;
  REP(i, N) {
    cin >> a[i];
    s.insert(a[i]);
  }
  VI elms(s.begin(), s.end());
  if (elms.size() == 1 && elms[0] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if (N % 3 != 0) {
    cout << "No" << endl;
    return 0;
  }
  if (elms.size() == 2) {
    if (elms[0] == 0 || elms[1] == 0) {
      int cnt = count(a.begin(), a.end(), elms[0]);
      if (cnt == N/3 || cnt == 2*N/3) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  } else if (s.size() == 3) {
    int v = elms[0] ^ elms[1] ^ elms[2];
    if (v == 0 && count(a.begin(), a.end(), elms[0]) == N/3 && count(a.begin(), a.end(), elms[1]) == N/3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 4480
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=v()
if n == "Sunny":
    print("Cloudy")
elif n=="Cloudy":
    print("Rainy")
else:
    print("Sunny")


Measured memory_bytes: 10256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, x, hash, total;
	unordered_map<int, long double> dp;

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

	for (total = 0; total <= n; total++) {
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= n; j++) {
				k = total - i - j;
				if (k < 0) continue;
				hash = i * 1000000 + j * 1000 + k;

				if (i + j + k == 0) dp[hash] = 0;
				else {
					long double ans = 0, r = (n - i - j - k) * 1.0 / n;
					if (i > 0) ans += i * 1.0 / n * (1 + dp[hash - 1000000 + 1000]);
					if (j > 0) ans += j * 1.0 / n * (1 + dp[hash - 1000 + 1]);
					if (k > 0) ans += k * 1.0 / n * (1 + dp[hash - 1]);

					ans = (r + ans) / (1 - r);
					dp[hash] = ans;
				}
			}
		}
	}

	x = ct[3] * 1000000 + ct[2] * 1000 + ct[1];
	long double ans = dp[x];
	cout << setprecision(10) << fixed << ans << "\n";

	return 0;
}




Measured memory_bytes: 338632
X, K, D = map(int, input().split())
K2 = K
#X=１に近いものにおきかえる
if X >= 0:
  a= 1
else:
  a = -1
#何回引けるか
h = min(K, int(a*X/D))
K = K-h
X = X - a*D*h

#print(X, K, D)
      


flg = 0
minx = abs(X)
Xnow = X
Xprepre = 0
for i in range(K):
  if i != 0:
    Xprepre = Xpre
  Xpre = Xnow #前回
  X1 = Xnow -D
  X2 = Xnow +D
  if abs(X1) < abs(X2):
    Xnow = X1
  else:
    Xnow = X2
  #繰り返したらおわり
  if Xprepre == Xnow:
    flg = 1
    if (K-i+1)%2 == 0:
      print(abs(Xnow))
    else:
      print(abs(Xpre))
    break
if flg == 0:
  print(abs(Xnow))


Measured memory_bytes: 9040
sec = int(input())

hh = 0 
mm = 0
ss = 0
while sec >= 3600:
     hh += 1
     sec -= 3600
     
while sec >= 60:
    mm += 1
    sec -= 60
    
ss = sec 

print(hh, ':', mm, ':' , ss, sep= '')
    


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
main(){
  string s[3];
  int n;
  double a[16][3][3];
  while(cin>>n,n){
    memset(a,0,sizeof(a));
    r(i,3)cin>>s[i];
    r(i,15)a[i][(s[2][0]-'A')/3][(s[2][0]-'A')%3]=-1;
    a[0][(s[0][0]-'A')/3][(s[0][0]-'A')%3]=1;
    r(k,n)r(i,3)r(j,3)if(a[k][i][j]>0)r(l,4){
      int y=i+dy[l],x=j+dx[l];
      if(y<0||y>=3||x<0||x>=3)a[k+1][i][j]+=a[k][i][j]/4;
      else if(a[k][y][x]==-1)a[k+1][i][j]+=a[k][i][j]/4;
      else a[k+1][y][x]+=a[k][i][j]/4;
    }
    printf("%.9f\n",a[n][(s[1][0]-'A')/3][(s[1][0]-'A')%3]);
  }
}

Measured memory_bytes: 3216
#include<iostream>
using namespace std;
struct song{
  string s;
  int x;
};
int main()
{
  int n;
  cin>>n;
  struct song songs[n];
  for(int i=0;i<n;i++)
  {
    cin>>songs[i].s;
    cin>>songs[i].x;
  }
  int sum=0;
  string s1;
  cin>>s1;
  int q;
  for(int i=0;i<n;i++)
  {
    if(songs[i].s==s1)
    {
      q=i;
      break;
    }
  }
  for(int i=q+1;i<n;i++)
  {
    sum=sum+songs[i].x;
  }
  cout<<sum;
}
  

Measured memory_bytes: 256
#include <stdio.h>
int Lsearch(int[],int,int);
int main(){
  int x,y,i,j,k,key,res=0,same[500],A[10000+1];

  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf("%d",&key);
    if(Lsearch(A,x,key)==1)res++;
  }


  printf("%d\n",res);
  return 0;
}

int Lsearch(int B[],int n,int kkey){
  int i=0;
  B[n]=kkey;
  while(B[i]!=kkey) i++;
  if(i==n)return 0;
  else return 1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c=1;
  cin>>a>>b;
  rep(i,a-1){
    c*=b-1;
  }
  cout<<c*b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

bool a(char c){
  if(c == 'A' || c == 'T' || c == 'G' || c == 'C') return true;
  return false;
}

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

  vector<int> K(N);
  vector<vector<int>> A(N, vector<int>(0));
  for(int i = 0; i < N; i++){
    cin >> K.at(i);
    for(int j = 0; j < K.at(i); j++){
      int a;
      cin >> a;
      a--;
      A.at(i).push_back(a);
    }
  }

  int result = 0;
  for(int i = 0; i < M; i++){
    int counter = 0;
    for(int j = 0; j < N; j++){
      bool flag = false;
      for(int k = 0; k < K.at(j); k++){
        if(A.at(j).at(k) == i){
          flag= true;
          break;
        }
      }
      if(flag) counter++;
    }
    if(counter == N) result++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


long long MOD = 1000000007;

struct mint{

    long long v;

    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}


ll solve25(ll p, const string& s){
    ll ret = 0;
    REP(i, s.size()){
        const ll d = s.at(i) - '0';
        if(d % p == 0){
            ret += i + 1;
        }
    }
    return ret;
}

ll solve(ll p, const string& s){
     vector<ll> count(p, 0);
     count.at(0) = 1;
     ll ret = 0;
     mint p10 = 1;
     mint sum = 0;
     for(ll i = static_cast<ll>(s.size()) - 1; i >= 0; --i){
        const ll d = s.at(i) - '0';
        sum += d * p10;
        p10 *= 10;
        ret += count.at(sum.v);
        count.at(sum.v)++;
     }
     return ret;
}

int main(){
    ll n, p;
    string s;

    cin >> n >> p;
    cin >> s;

    MOD = p;

    if(10 % p == 0){
        cout << solve25(p, s) << endl;
    }else{
        cout << solve(p, s) << endl;
    }
    return 0;
}


Measured memory_bytes: 640
/**
 * author: stein
 * created: 2020.08.23 20:03:48
**/
#include <bits/stdc++.h>
using namespace std;

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

  long long n, mx = -1, res = 0;
  
  cin >> n;
  vector<int> f (n);
  for (auto &it : f) cin >> it;
  mx = f[0];
  for (int i = 1; i < n; i++) {
    if (f[i] > mx) mx = f[i];
    else res += mx - f[i];
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3924
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for (; ; ) {
      int H = ni();

      if ( H == 0 ) {
        break;
      }

      int[][] field = new int[ H ][ 5 ];
      for ( int i = 0; i < H; ++i ) {
        for ( int j = 0; j < 5; ++j ) {
          field[ i ][ j ] = ni();
        }
      }

      int ans = 0;
      for (; ; ) {
        int sum = 0;
        for ( int i = 0; i < H; ++i ) {
          for ( int j = 0; j < 3; ++j ) {
            int v = field[ i ][ j ];
            boolean del = true;
            for ( int k = 1; k < 3; ++k ) {
              del &= field[ i ][ j + k ] == v;
            }
            if ( del ) {
              for ( int k = 0; j + k < 5; ++k ) {
                if ( field[ i ][ j + k ] != v ) {
                  //debug("here", i, j + k, v, field[i][j+k]);
                  break;
                }
                sum += v;
                field[ i ][ j + k ] = 0;
                for ( int l = i; 0 < l; --l ) {
                  field[ l ][ j + k ] = field[ l - 1 ][ j + k ];
                }
                field[ 0 ][ j + k ] = 0;
              }
              break;
            }
          }
        }


        //for ( int[] v : field ) debug(v);
        //debug();


        if ( sum == 0 ) {
          break;
        }

        ans += sum;
        // debug(sum);
      }

      System.out.println(ans);
    }
  }

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 48692
n,k,c = map(int,input().split())
S = input()
mae = []
ushiro = []
cur_1 = 0
temp_1 = 0
cur_2 = 0
temp_2 = 0
ans = []
for i in range(n):
    if S[i] == 'o' and temp_1 == 0:
        mae.append(i)
        cur_1 += 1
        temp_1 = c
    else:
        temp_1 = max(temp_1-1,0)
    if cur_1 == k:
        break
for i in range(n):
    if S[n-i-1] == 'o' and temp_2 == 0:
        ushiro.append(n-i-1)
        cur_2 += 1
        temp_2 = c
    else:
        temp_2 = max(temp_2-1,0)
    if cur_2 == k:
        break
for i in range(k):
    if mae[len(mae)-1-i] == ushiro[i]:
        ans.append(ushiro[i]+1)
if len(ans) == 0:
    None
else:
    ans.reverse()
    for i in range(len(ans)):
        print(ans[i])


Measured memory_bytes: 28664
#include<iostream>
using namespace std;
int n,k,data[100000];
int solve(int x){
  int pos=0,sum;
  for(int i=0;i<k;++i){
    sum=0;
    while(sum+data[pos]<=x){
      sum+=data[pos];
      if(++pos==n) return 1;
    }
  }
  return 0;
}
int main(){
  cin>>n>>k;
  for(int i=0;i<n;++i) cin>>data[i];
  int left=0,right=n*10000,mid;
  while(left+1<right){
    mid=(left+right)/2;
    if(solve(mid)) right=mid;
    else left=mid;
  }
  cout<<right<<endl;
  return 0;
}



Measured memory_bytes: 3488
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

int main() {
    int K, S;
    cin >> K >> S;
    int ans = 0;

    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (z >= 0 && z <= K) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define MAX 1000005
#define NIL -1

struct Node{
  int p,l,r;
};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
  if(T[u].p == NIL)
    cout << "root, ";
  else if(T[u].l == NIL)
    cout << "leaf, ";
  else
    cout << "internal node, ";
  cout << "[";
  for(i = 0, c = T[u].l; c!= NIL; i++, c=T[c].r){
    if(i)
      cout << ", ";
    cout << c;
  }
  cout << "]" << endl;

}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL)
    rec(T[u].r,p);
  if(T[u].l!=NIL)
    rec(T[u].l, p+1);
}
int main(){

  int i, j, d, v, c, l, r;
  cin >> n;
  for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i = 0; i < n; i++){
    cin >> v >> d;
    for(j = 0; j < d; j++){
      cin >> c;
      if(j == 0)
	T[v].l = c;
      else
	T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == NIL)
      r = i;
  }
  rec(r,0);
  for(i = 0; i < n; i++) print(i);
  return 0;
}

Measured memory_bytes: 7684
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a, b int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &a, &b)

	ans := a
	if a > b {
		ans--
	}
	fmt.Println(ans)
}


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

using namespace std;

int main() {
    int n; cin>>n;
    vector<pair<int, int>> tasks;
    for (int i=0;i<n;i++) {
        int a,b; cin>>a>>b;
        tasks.emplace_back(b, a);
    }

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

    int sum=0;
    bool isyes=true;

    for (auto v : tasks) {
        sum += v.second;

        if (sum > v.first) {
            isyes = false;
            break;
        }
    }

    cout << (isyes ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>

using namespace std;
int main(){
	int max=0,a,b;
	char ch='A';
	while(1){
		cin>>a>>b;
		max=a+b;ch='A';
		if(a==0&&b==0)break;
		for(int i=0;i<4;i++)
		{
			cin>>a>>b;
			if(max<a+b){
				max=a+b;
				if(i==0)ch='B';
				if(i==1)ch='C';
				if(i==2)ch='D';
				if(i==3)ch='E';
			}
			
		}cout<<ch<<" "<<max<<endl;
	}
		return 0;
	}
			

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	int c=scan.nextInt();
	int ISU=c;
	for(int i=0;;i++) {
	if(ISU>=a) {
		if((a-c)%(b+c)==0) {
		System.out.println(i);
		}
		else {
			System.out.println(i-1);
		}
		break;
	}
	ISU+=b+c;
	}
	scan.close();
}
}

Measured memory_bytes: 21844
n=int(input())
s=input().split(' ')
h=[]
for i in range(0,n):
	h.append(int(s[i]))
count=1
for i in range(1,n):
	my=h[i]
	highest=max(h[0:i])
	if my >= highest:
		count=count+1

print(count)

Measured memory_bytes: 3064
import java.util.*;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a[] = new int[n];
        int res = 0;
        
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }
        
        Arrays.sort(a);
        
        if(a[n/2-1] != a[n/2]){
            res = a[n/2]-a[n/2-1];
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 50764
#include<stdio.h>

int main(){
	int n,i,j,max,t;
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		
		max=0;
		for(i=0;i<54;i++){
			for(j=0;j<96;j++){
				t=i*i*i+(j*(j+1)*(j+2))/6;
				if(n<t)break;
				if(max<t)max=t;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b,c;
	cin>>a>>b>>c;
	bool f[100]={};
	f[a-96]=1;
	f[b-96]=1;
	f[c-96]=1;
	if(f[1]&&f[2]&&f[3]) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max 4000
#define score 1000000

long long int id[max],raw[max];

int main(){
  long long int num,sale,deal;
  long long int n,i,j,count,k,l,m;
  
  while(1)
    {
      scanf("%lld",&n);

      for (k=0;k<=max;k++)
      {
	id[k] = 0;
      }

      if(n==0)
	{
	  break;
	}

      else
	{
	  count = 0;
	  for(i=1;i<=n;i++)
	{
	  scanf("%lld %lld %lld",&num,&sale,&deal);
	  id[num] = id[num] + (sale * deal);
	  raw[i] = num;
	}
	  for(l=0;l<max;l++)
	    {
		  for(m=l+1;m<=max;m++)
		    {
		      if(raw[l]==raw[m])
			{
			  raw[m]=0;
			}
		    }
	    }
	  for(j=1;j < max;j++)
	{
       	  if(id[raw[j]] >=  score)
	  {
	      printf("%lld\n",raw[j]);
	      count++;
	  }
	}
	  if(count==0)
	    {
	 printf("NA\n");
	    }
	  
	}
    }
  return 0;
}

Measured memory_bytes: 668