akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

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

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

fn main() {
    let a = parse_line::<u32>();

    println!("{}", (a - 2) * 180);
}


Measured memory_bytes: 4352
s = input()
if s[0] == "1":
  res = "9" 
else:
  res = "1"
if s[1] == "1":
  res += "9"
else:
  res += "1"
if s[2] == "1":
  res += "9"
else:
  res += "1"
print(res)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  char s;
  map<string, int> cnt;
  string ans = "Yes";
  for (int i = 0; i < n; i++){
    string w;
    cin >> w;
    if (i > 0 && (s != w[0] || cnt[w] != 0)){
      ans = "No";
      break;
    }
    cnt[w]++;
    s = w[w.size()-1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque

S = deque(input())
Q = int(input())
Flag = 1

for _ in range(Q):
  q = input()
  
  if q[0] == "1":
    Flag *= -1
  
  if q[0] == "2":
    if Flag > 0:
      if q[2] == "1":
        S.appendleft(q[4])
      else:
        S.append(q[4])
    else:
      if q[2] == "1":
        S.append(q[4])
      else:
        S.appendleft(q[4])
  
if Flag < 0:
  S.reverse()

print("".join(S))

Measured memory_bytes: 8436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,sum=0;
	string s;
	stringstream ss;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ss<<i;
		ss>>s;
		if(s.length()%2)sum++;
		ss.clear();
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		
		if(N * A < B) {
			System.out.println(N * A);
		}else {
			System.out.println(B);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
int main(){
  int i,j,k,n,m,l,A[100][100],B[100][100];
  long long sum;
  scanf("%d%d%d",&n,&m,&l);
 
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i=0;i<m;i++){
    for(j=0;j<l;j++){
      scanf("%d",&B[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      sum=0;
      for(k=0;k<m;k++){
	sum += A[i][k]*B[k][j];
      }
      printf("%lld",sum);
      if(j+1!=l)printf(" ");
    }
    printf("\n");
  }
  return 0;
}
      

Measured memory_bytes: 680
import decimal
decimal.getcontext().prec = 100
def sum1(pre,l,r):
    l=max(l,0)
    if(l==0):
        return pre[r]
    return pre[r] - pre[l - 1]

# n=int(raw_input())
a,b,c=map(int,raw_input().split())
if(b+c<=a):
    print 0
    exit()
print c-(a-b)
# t=1
# while(t!=0):
#     t=t-1

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

int main() {
    ll x;
    cin >> x;
    ll a = (x + 10) / 11;
  	ll ans = 2 * a;
    if (11 * a - 5 >= x) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[100010], num;
ll n, par[100010], k, kai[2010];

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	string s;
	cin >> s;
	map<char, ll> mp;
	for (int i = 0; i < s.length(); i++)
	{
		mp[s[i]]++;
	}
	bool jud = true;
	for (auto itr = mp.begin(); itr != mp.end(); ++itr)
	{
		if (itr->second != 2)
		{
			jud = false;
		}
	}
	if (jud && mp.size() == 2)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,d;
	cin>>n>>d;
	cout<<(2*d+n)/(2*d+1)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  cout << 48 - n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, c, k; cin >> n >> c >> k;
    VL t(n); cin >> t;
    SORT(t);
    ll ans = 0;
    FOR(i, 0, n) {
        ll lim = t[i] + k, j = i, cnt = 1;
        while (cnt < c && j + 1 < n && t[j + 1] <= lim) {
            ++cnt, ++j;
        }
        ++ans;
        i = j;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
ll  LINF = 1e18;

struct Linear_Sieve{
int n;
vector<int> lp,primes;
//lp[i]...the least prime of i. primes...prime numbers
Linear_Sieve(int n = 1):n(n),lp(n+1){
	for(int i = 2;i < n+1;i++){
		if(lp[i] == 0) {
			primes.push_back(i);
			lp[i] = i;
		}
		for(int j = 0;j<primes.size() && primes[j] <= lp[i] && i*primes[j] < n+1; ++j) lp[i*primes[j]] = primes[j];
	}
}
bool isPrime(int x) {return lp[x] == x;}

vector<int> factorList(int x){
	//make list which contains prime factors of x. Ans it toralates multipled components.
	vector<int> res;
	while(x != 1){
		res.push_back(lp[x]);
		x /= lp[x];
	}
	return res;
}

vector<pair<int,int>> factor(int x){
		//make list of pairs which couple prime factor and multiplicity.
	vector<int> fl = factorList(x);
	if(fl.size() == 0) return{};
	vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
	for(int p : fl){
		if(res.back().first == p){
			res.back().second++;
		}else{
			res.emplace_back(p,1);
		}
	}
	return res;
}
};

int main(){
	int n;cin >> n;
	Linear_Sieve s(1000100);
	ll ans = 0;
	for(int i = 1;i < n;i++){
		int temp = n-i;
		ll nmul = 1;
		for(P p:s.factor(temp)){
			nmul *= (p.second+1);
		}
		//printf("%d %lld\n",temp,nmul);
		ans+=nmul;
	}
	cout << ans << endl;

}


Measured memory_bytes: 7832
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 2005;
char a[2005][2005];
int up[2005][2005];
int down[N][N];
int lefts[N][N];
int rights[N][N];

int32_t main(){
	fastio();
	int h,w;
	cin >> h >> w;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(a[i][j] == '#') rights[i][j] = 0;
			else rights[i][j] = 1 + rights[i][j - 1];
		}
	}
	for(int i = 1; i <= h; i++){
		for(int j = w; j >= 1; j--){
			if(a[i][j] == '#') lefts[i][j] = 0;
			else lefts[i][j] = 1 + lefts[i][j + 1];
		}
	}
	for(int j = 1; j <= w; j++){
		for(int i = 1; i <= h; i++){
			if(a[i][j] == '#') down[i][j] = 0;
			else down[i][j] = 1 + down[i - 1][j];
		}
	}
	for(int j = 1; j <= w; j++){
		for(int i = h; i >= 1; i--){
			if(a[i][j] == '#') up[i][j] = 0;
			else up[i][j] = 1 + up[i + 1][j];
		}
	}
	int ans = 0;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(a[i][j] != '#'){
				ans = max(ans,up[i][j] + down[i][j] + rights[i][j] + lefts[i][j] - 3);
			}
		}
	}
	cout << ans;

}

Measured memory_bytes: 132836
#include<bits/stdc++.h>
using namespace std;
const int N=2e7+5,mo=1e9+7;
int fac[N],vf[N],inv[N];
inline int C(int x,int y){return x<y || y<0?0:1ll*vf[y]*vf[x-y]%mo*fac[x]%mo;}
inline int P(int x,int y){return 1ll*vf[x-y]*fac[x]%mo;}
int hh,ww,H,W,K,i,j,ans,zz,v1,v2;
int main(){
	for(i=*fac=*vf=1;i<N;++i)
		fac[i]=1ll*fac[i-1]*i%mo,
		inv[i]=i==1?1:1ll*(mo-mo/i)*inv[mo%i]%mo,
		vf[i]=1ll*vf[i-1]*inv[i]%mo;
	scanf("%d%d%d",&hh,&ww,&K);
	for(i=2;i<=K;++i)v1=(v1+1ll*(i-1)*(K-i+1))%mo,v2=(v2+K-i+1)%mo;
	for(zz=max(0,K-ww);zz<=hh;++zz){
		int su=0;
		H=zz;W=K-zz;
		su+=1ll*K*C(K,zz)%mo;
		if(W)su=(su+1ll*K*C(K-1,W-1))%mo;
		if(H)su=(su+1ll*K*C(K-1,H-1))%mo;
		su=(su+1ll*v1*(C(K-2,H-1)+C(K-2,W-1))+1ll*v2*(C(K-1,H)+C(K-1,W)))%mo;
		ans=(ans+1ll*P(hh,zz)*P(ww,K-zz)%mo*su)%mo;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 234624
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
int D[100][2];
int ok[100];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    int KL2GvlyY;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      for(KL2GvlyY=(0);KL2GvlyY<(2);KL2GvlyY++){
        rd(D[Lj4PdHRW][KL2GvlyY]);
      }
    }
  }
  for(i=(0);i<(N);i++){
    if(D[i][0]==D[i][1]){
      ok[i] =1;
    }
    else{
      ok[i] =0;
    }
  }
  for(i=(2);i<(N);i++){
    if(ok[i-2] && ok[i-1] && ok[i]){
      wt_L("Yes");
      wt_L('\n');
      return 0;
    }
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay varsion 20200916-1

// --- original code ---
// int N, D[100][2];
// int ok[100];
// {
//   rd(N,D(N,2));
//   rep(i,N) ok[i] = if[D[i][0]==D[i][1], 1, 0];
//   rep(i,2,N) if(ok[i-2] && ok[i-1] && ok[i]) wt("Yes"), return 0;
//   wt("No");
// }


Measured memory_bytes: 3628
#!/usr/bin/env python3
def main():
    import sys

    input = sys.stdin.readline

    X = int(input())

    for a in range(-150, 151):
        for b in range(-150, 151):
            if a ** 5 - b ** 5 == X:
                print(a, b, sep=' ')
                return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9072
import sys
N = int(input())
array = list(map(int,input().split()))

if not ( 1 <= N <= 100 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 1000 ): sys.exit()

for I in array:
    if I % 2 == 0 and not ( I % 3 == 0 or I % 5 == 0 ):
        print('DENIED')
        sys.exit()
print('APPROVED')

Measured memory_bytes: 8964
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n, T; cin >> n >> T;
  int cost = 1e9;
  for(int i=0; i<n; i++){
    int c, t;
    cin >> c >> t;
    if(t > T) continue;
    cost = min(cost, c);
  }
  if(cost == 1e9) cout << "TLE" << endl;
  else cout << cost << endl;


  return 0;
}



//


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
int h,w,ch[50][50],dx[]={1,-1,0,0},dy[]={0,0,1,-1},nx,ny,tot;
string s[50];
queue<P> que;
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
        for(int j=0;j<w;j++){
            if(s[i][j]=='.')tot++;
            ch[i][j]=0;
        }
    }
    que.push({0,0});
    ch[0][0]=1;
    while(que.size()){
        P p=que.front();
        //cout<<p.F<<" "<<p.S<<endl;
        que.pop();
        for(int i=0;i<4;i++){
            nx=p.F+dx[i],ny=p.S+dy[i];
            //cout<<nx<<" "<<ny<<" "<<s[nx][ny]<<endl;
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]!='#'&&ch[nx][ny]==0){
                //cout<<ch[p.F][p.S]<<" "<<p.F<<" "<<p.S<<endl;
                ch[nx][ny]=ch[p.F][p.S]+1;
                //cout<<nx<<" "<<ny<<endl;
                que.push({nx,ny});
            }
            else continue;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //cout<<ch[i][j]<<" ";
        }
        //cout<<endl;
    }
    if(-ch[h-1][w-1]==0)cout<<-1<<endl;
    else cout<<tot-ch[h-1][w-1]<<endl;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)

n = int(input())
cnt = 0
for i in range(1, n + 1):
    if i % 2 != 0:
        res = make_divisors(i)
        if res == 8:
            cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int n, W;
const int MAX_N = 100;
const int MAX_V = 10000;
vector<int> w(MAX_N);
vector<int> v(MAX_N);

vector<vector<int> > dp(MAX_N+1, vector<int>(MAX_V+1));

int rec(int i, int j){
    if(dp.at(i).at(j) >= 0) {
        return dp.at(i).at(j);
    }
    int res;
    if(i == n){
        res = 0;
    }
    else if(j < w.at(i)){
        res = rec(i+1, j);
    }
    else {
        res = max(rec(i+1, j), rec(i+1, j-w.at(i)) + v.at(i));
    }
    return dp[i][j] = res;
}

int main(){
    
    cin >> n >> W;
    
    rep(i, n) cin >> v.at(i) >> w.at(i);

    rep(i, MAX_N+1) rep(j, MAX_V+1) dp.at(i).at(j) = -1;

    cout << rec(0, W) << endl;

}


Measured memory_bytes: 6696
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    long long c=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            c++;
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3832
a = [int(i) for i in input().split()]
# N:参加回数　R:表示レーティング
N = a[0]
R = a[1]

# X:内部レーティング
#R = X - 100 * (10 - N)
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))

Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Q;
	scanf("%d%d", &N, &Q);

	struct rw { 
		int s, t, x; 
		rw(int s = 0, int t = 0, int x = 0) :s(s), t(t), x(x) {}
	};
	vector<rw> RW(N);
	for (int i = 0; i < N; i++) {
		int s, t, x;
		scanf("%d%d%d", &s, &t, &x);
		RW[i] = { s, t, x };
	}
	sort(RW.begin(), RW.end(), [](auto &l, auto &r) { return (l.s - l.x) < (r.s - r.x); });

	int idx = 0;
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
	for (int i = 0; i < Q; i++) {

		int d;
		scanf("%d", &d);

		while (idx < N && RW[idx].s - RW[idx].x <= d) {
			pq.emplace(RW[idx].x, RW[idx].t - RW[idx].x);
			idx++;
		}
		while (!pq.empty() && pq.top().second <= d) pq.pop();

		printf("%d\n", (pq.empty() ? -1 : pq.top().first));

	}

	return 0;
}


Measured memory_bytes: 5360
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

using namespace std;

int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  ll x;
  cin >> x;
  ll ans = (x / 11) * 2;
  if(x % 11 != 0) {
    ans += (x % 11) > 6 ? 2 : 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int l1, l2, l3;
	int i;
	
	scanf("%d", &n);
	while (n--){
		scanf("%d %d %d", &l1, &l2, &l3);
		
		if (l1 * l1 == l2 * l2 + l3 * l3 ||
			l2 * l2 == l1 * l1 + l3 * l3 ||
			l3 * l3 == l1 * l1 + l2 * l2){
			
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int sx = as.nextInt();
		int sy = as.nextInt();
		int tx = as.nextInt();
		int ty = as.nextInt();
		String l ="";
		for(int i=sy;i<ty;i++){
			l+="U";
		}
		for(int i=sx;i<tx;i++){
			l+="R";
		}
		for(int i=sy;i<ty;i++){
			l+="D";
		}
		for(int i=sx;i<=tx;i++){
			l+="L";
		}
		for(int i=sy;i<=ty;i++){
			l+="U";
		}
		for(int i=sx;i<=tx;i++){
			l+="R";
		}
		l+="DR";
		for(int i=sy;i<=ty;i++){
			l+="D";
		}
		for(int i=sx;i<=tx;i++){
			l+="L";
		}
		l+="U";
		System.out.println(l);
	}
}

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

// 素数5つの和が合成数になっているかを真面目に確かめる方針で実装して、初めの4項を試行錯誤した結果、
// 5n+k 型の素数について考えれば楽だということにあとから気付いて実装を流用したver.
int main(){ 
  const int Nmax= 55555;
  const int Nbits= 5* Nmax;
  int N;
  cin >> N;

  bitset<Nbits> primes; // primes.test(i): iが素数かどうか
  primes.set(); primes.reset(0); primes.reset(1);
  int div= 2;
  while(div*div < Nbits){
    if(primes.test(div)){
      for(int i=2*div; i< Nbits; i+= div){
        primes.reset(i);
      }
    }
    div++;
  }

  bitset<Nbits> ans;  // 出力すべき配列
  bitset<Nbits> sum4; // 出力すべき配列の4要素の和を管理 
  bitset<Nbits> sum3; // 出力すべき配列の3要素の和を管理
  bitset<Nbits> sum2; // 出力すべき配列の2要素の和を管理 

  int p= 2; ans.set(p);
  p=  3; sum2 |= (ans << p); ans.set(p); 
  p= 13; sum3 |= (sum2<< p); sum2 |= (ans << p); ans.set(p); 
  p= 23; sum4 |= (sum3<< p); sum3 |= (sum2<< p); sum2 |= (ans << p);  ans.set(p); 
  p= 33; int cnt= 4; // なんでや！阪神関係ないやろ！
  bitset<Nbits> buf;
  while(cnt < N){
    if(primes.test(p)){
      buf= primes & (sum4 << p);
      if(buf.none()){ /* 重複しない要素の和を考えるので、各bitsetの更新順に注意(重複を許す場合、逆順になる) */
        cnt++;
        sum4 |= (sum3<< p);
        sum3 |= (sum2<< p);
        sum2 |= (ans << p);
        ans.set(p);
      }
    }
    p+= 10;
  }

  cout << 2;
  p= 3; int cnt_out= 1;
  while(cnt_out < N){
    if(ans.test(p)){
      cout <<" "<< p;
      cnt_out++;
    }
    p+= 2;
  }
  cout << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(1)
  {
    c -= b;
    if (c <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if (a <= 0)
    {
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int [n+1];
        int[] bit = new int [m+2];
        int cost1 = 0;
        int cost2 = 0;
        for(int i = 1;i <= m;i++){
            bit[i] = sc.nextInt();
        }

        for(int i = 0;i < n+1;i++){
            a[i] = 0;
        }
        int j = 1;
        for(int i = 0;i < n+1;i++){
            if(j == m+1){
                break;
            }
            if(i == bit[j]){
                a[i] = 1;
                j++;
            }
        }
        for(int i = 0;i < x;i++){
            cost1 = cost1 + a[i];
        }
        for(int i = x+1;i < n+1;i++){
            cost2 = cost2 + a[i];
        }
        if(cost1 <= cost2){
            System.out.println(cost1);
        }
        else{
            System.out.println(cost2);
        }
    }
}

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

void swap(char *i, char *j)
{
	char tmp;
	
	tmp = *j;
	*j = *i;
	*i = tmp;
}

int main(void)
{
	int i, j;
	char str[1000];
	int len;
	
	scanf("%s", str);
	
	len = strlen(str) - 1;
	for (i = 0; i < len; i++, len--){
		swap(&str[i], &str[len]);
	}
	
	printf("%s\n", str);
	
	return (0);
}

Measured memory_bytes: 524
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

int main() {
    ll a;
    cin >> a;
    string s;
    cin >> s;
    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
}


Measured memory_bytes: 888
import numpy as np
N, W = map(int, input().split())

dp = np.full(N * 1001, W + 10000)
dp[0] = 0

for i in range(N):
    w, v = map(int, input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])

ans = np.max(np.where(dp <= W))
print(ans)


Measured memory_bytes: 14912
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
typedef struct {
	double x, y;
}POINT;
int main() {
	POINT a, b, c, d;
	while (~fscanf(stdin,"%lf%lf%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y, &d.x, &d.y)) {
		b.x -= a.x, b.y -= a.y, d.x -= c.x, d.y -= c.y;
		if (fabs(b.x*d.x + b.y*d.y) < 1e-10) fprintf(stdout, "YES\n");
		else fprintf(stdout, "NO\n");
	}
	return 0;
}

Measured memory_bytes: 616
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    string s;
    cin >> s;
    if((s[0] == s[s.size() - 1]) ^ (s.size() % 2)){
        cout << "First" << endl;
    }
    else{
        cout << "Second" << endl;
    }
}



Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {

    int n;
    string s;
    cin >> n >> s;

    int el = 0, wl = 0;

    int er = 0, wr = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == 'E')
            er++;
        else
            wr++;
    }

    int minimum = wl + er;

    char previous = s[0];
    for (int i = 1; i < n; i++) {
        if (previous == 'E') {
            el++;
        } else {
            wl++;
        }

        if (s[i] == 'E') {
            er--;
        } else {
            wr--;
        }

        minimum = min(minimum, wl + er);
        previous = s[i];
    }

    cout << minimum << endl;

    return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N;
  int k,m;
  int L[10000];
  int i;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> L[i];
  sort(L,L+N);
  int count = 0;
  for(i=0;i<=N-3;i++)
    for(k=i+1;k<=N-2;k++)
      for(m=k+1;m<=N-1;m++)
        if(L[i]+L[k]>L[m]) count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define N 100003
int bas,son;
#define orta (bas+son)/2

int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	cout<<(n/(a+b))*a + (n%(a+b) > a)*a + (n%(a+b) <=a)*(n%(a+b));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+2;
int ar[N],ans[N];
pair<int,int> lis[N];
set<int> idx;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,cnt=0,now;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		lis[i]={ar[i],i};
	}
	sort(lis+1,lis+1+n);
	now=lis[n].first;
	i=j=n;
	while(j&&lis[i].first==lis[j].first){
		cnt++;
		idx.insert(lis[j].second);
		j--;
	}
	set<int>::iterator ite;
	i=j;
	while(i){
		ite=idx.begin();
		ans[*ite]+=(now-lis[i].first)*cnt;
		while(j&&lis[i].first==lis[j].first){
			idx.insert(lis[j].second);
			cnt++;
			j--;
		}
		now=lis[i].first;
		i=j;
	}
	ite=idx.begin();
	ans[*ite]+=(now-lis[i].first)*cnt;
	for(i=1;i<=n;i++){
		cout<<ans[i]<<'\n';
	}
}

Measured memory_bytes: 8960
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int i, j;


	while (true)
	{

		cin >> i >> j;

		if (i == 0 && j == 0)
			break;

		if (i > j)
			i ^= j ^= i ^= j;
		cout << i<< " " << j << endl;


	}


	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
using namespace std;

#define N 200000
#define WHITE 0  // 未訪問
#define BLACK 1  // 訪問ずみ

// 連結成分の番号を振る関数
void dfs(int n, int comp[], vector<int> G[])
{
    int i, j, vertex, neighbor, color[N];
    stack<int> S;
    int ans[N] = {};
    // 初期状態
    for (i = 0; i < n; i++)
        color[i] = WHITE;

    for (i = 0; i < n; i++) {
        if (color[i] == WHITE) {
            // dfs
            S.push(i);
            while (!S.empty()) {
                vertex = S.top();
                S.pop();
                color[vertex] = BLACK;  // 訪問済みにする
                comp[vertex] = i;       // 連結成分の番号を振る

                for (j = 0; j < (int)G[vertex].size(); j++) {
                    neighbor = G[vertex][j];  // 隣接している頂点：友人
                    if (color[neighbor] == WHITE)
                        S.push(neighbor);
                }
            }
        }
    }
}

int main()
{
    int i, n, m, s, t;
    int comp[N];       // 連結成分の番号
    vector<int> G[N];  // グラフを表現する隣接リスト

    cin >> n >> m;
    // 隣接リストを作成
    for (i = 0; i < m; i++) {
        cin >> s >> t;
        --s;
        --t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    // グラフを連結成分に分ける
    dfs(n, comp, G);

    int ans[N] = {};
    int temp = 0;
    for (int j = 0; j < n; j++) {
        //std::cout << j << " " << comp[j] << std::endl;
        ++ans[comp[j]];
    }
    for (auto v : ans) {
        temp = std::max(v, temp);
    }
    std::cout << temp << std::endl;
    return 0;
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i;
  cin >> N >> K;
  int sum=0;
  
  for (i=0; i<N; i++){
    int x;
    cin >> x;
    
    if (x >= abs(x-K))
      sum += 2*abs(x-K);
    else sum +=2*x;
    
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
from math import ceil

D,G = map(int,input().split())

pc_list = [[i]+list(map(int,input().split())) for i in range(D)]
def rindex_zero(l):
    return len(l) - l[::-1].index(0)-1

def func(g,cnt,l):
    if len(l) == D:
        if g <= 0:
            return cnt
        idx = rindex_zero(l)
        i,p,c = pc_list[idx]
        if g <= 100*(i+1)*(p-1):
            cnt += ceil(g/(100*(i+1)))
            return cnt
        return 10**9
    length = len(l)
    i,p,c = pc_list[length]
#     print(i,p,c,l)
    a = func(g-(100*(i+1)*p+c), cnt+p,l+[1])
    b = func(g, cnt,l +[0])
    return min(a,b)
        
print(func(G,0,[]))


Measured memory_bytes: 41328
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;



int main() {
  ll k, a, b; cin >> k >> a >> b;
  if(b <= a+1){
    cout << 1+k << endl;
    return 0;
  }

  if(k < a+1){
    cout << 1+k << endl;
    return 0;
  }

  ll ans = a;
  k -= a-1;
  ll n = k/2;
  rep(i, 0, n) ans += b-a;
  if(k%2 != 0) ans += 1;

  cout << ans << endl;

  return 0;
}


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

int main()
{
	int N;
	int sum = 0;
	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		int A;
		cin >> A;
		sum += A - 1;
	}

	cout << sum << endl;
	return ( 0 );
}


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

main(){
  int H, W;
  char c;
  cin >> W >> H >> c;

  assert(3 <= W && W <= 21);
  assert(3 <= H && H <= 21);
  assert( W%2 && H%2 && 'A' <= c && c <= 'Z' );

  for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
      if ( i == 0 && j == 0 ||
           i == 0 && j == W-1 ||
           i == H-1 && j == 0 ||
           i == H-1 && j == W-1 ){
        cout << '+';
      } else if ( i == 0 || i == H-1 ){
        cout << '-';
      } else if ( j == 0 || j == W-1 ){
        cout << '|';
      } else if ( i == H/2 && j == W/2 ){
        cout << c;
      } else {
        cout << '.';
      }
    }
    cout << endl;
  }
}




Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))

int main()
{
	int n,m;
	char* str;
	int i,j;
	while(scanf("%d",&n),n)
	{
		scanf("%d",&m);
		str = mem(char,m+1);
		scanf("%s",str);
		int count = 0;
		i = 0;
		while(1)
		{
			if(i >= (m-2*n-1))
			{
				break;
			}
			else if(str[i] == 'I')
			{
				for (j = 0; j < n; j += 1)
				{
					if(str[++i] != 'O')
						break;
					if(str[++i] != 'I')
					{
						i--;
						break;
					}
				}
				if(j == n)
				{
					while(1)
					{
						if(i >= m-2)
						{
							break;
						}
						if(str[++i] == 'O' && str[++i] == 'I')
						{
							count++;
						}
						else
						{
							i--;
							break;
						}
					}
					count++;
				}
			}
			else
			{
				i++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	int leave = a-b;
	cout << max(c-leave, 0) << endl;

	return 0;
}

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

using namespace std;
using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int64 N, P;
  string S;
  cin >> N >> P >> S;
  if(P < 100) {
    auto nxt = make_v< int >(P, 10);
    for(int i = 0; i < P; i++) {
      for(int j = 0; j < 10; j++);
    }


    int64 ret = 0;

    int64 dp[10000] = {};
    int64 dp2[10000] = {};

    for(auto &c : S) {
      int cur = (c - '0') % P;

      memset(dp2, 0, sizeof(dp));
      for(int k = 0; k < P; k++) dp2[(k * 10 + cur) % P] += dp[k];
      dp2[cur]++;
      memcpy(dp, dp2, sizeof(dp2));

      ret += dp[0];
    }
    cout << ret << endl;
    return 0;
  }
  vector< int64 > tap(N);
  tap[N - 1] = 1;
  for(int i = N - 2; i >= 0; i--) {
    tap[i] = tap[i + 1] * 10;
    tap[i] %= P;
  }

  map< int64, int64 > mp;
  mp[0] = 1;
  int64 now = 0;
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    int64 mul = tap[i];
    mul *= S[i] - '0';
    mul %= P;
    now += mul;
    now %= P;
    ret += mp[now];
    mp[now]++;
  }
  cout << ret << endl;
}


Measured memory_bytes: 2580
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll x) {
  ll res = x / 11 * 2;
  if (x % 11 > 0) ++res;
  if (x % 11 > 6) ++res;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll x;
	scanf("%lld", &x);
	solve(x);
	return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;

struct Tree {
  int node_num;
  int edge_num;
  int diameter = -1;
  int leaf_node;
  int far_index = -1;
  vector<vector<int>> cost;
  vector<bool> visited;

  Tree(int nn) : node_num(nn){
    edge_num = node_num - 1;
    cost = vector<vector<int>> (node_num);
    visited = vector<bool> (node_num, false);
  }


  pair<int, int> get_far(int from, int d){
    visited[from] = true;
    for(auto a : cost[from]){
      if(!visited[a]){
        get_far(a, d+1);
      }
    }
    if(diameter < d){
      diameter = d;
      far_index = from;
    }
    return {far_index, diameter};
  }

  int get_diameter(int from){
    pair<int, int> i_and_d = get_far(0, 0);
    init();
    return diameter = get_far(i_and_d.first, 0).second;
  }

  void init(){
    visited = vector<bool> (node_num, false);
  }

};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  Tree t(n);
  for (int i = 0; i < n-1; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;
    t.cost[from].push_back(to);
    t.cost[to].push_back(from);
  }
  t.get_diameter(0);
  if(t.diameter % 3 == 1) {
    cout << "Second" << endl;
  }else{
    cout << "First" << endl;
  }
}


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

int main() {

    int x, t;
    int sum = 0;
    cin >> x;

    for ( int t = 1;; t++) {
        sum = sum + t;
        if (sum >= x)  {
            cout << t << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        
        int ret = 0;
        for(int i = a; i <= b; i++) {
            ret += (c % i == 0) ? 1 : 0;
        }
        
        System.out.println(ret);
    }
}


Measured memory_bytes: 26364
import itertools

# load
N = int(input())
a = []
x = []
y = []
for i in range(N):
  a.append(int(input()))
  xtmp = []
  ytmp = []
  for j in range(a[i]):
    xtmp2, ytmp2 = map(int, input().split())
    xtmp.append(xtmp2)
    ytmp.append(ytmp2)
  x.append(xtmp)
  y.append(ytmp)

#print('x:%s' % x)
#print('y:%s' % y)
#print(x[0][0])

# honest?

contra = False
stop = False
for r in range(N+1):
  for v in itertools.combinations(range(N), r):
    h = [1] * N
    for t in range(len(v)):
      h[v[t]] = 0

    for i in range(N):
      for j in range(a[i]):
      	if h[i] == 1 and (h[x[i][j]-1] != y[i][j]): # contradiction
          contra = True
          #print('contra: h:%s, i:%d, j:%d, h[x[i][j]-1]:%d, y[i][j]:%d' % (h, i, j, h[x[i][j]-1], y[i][j]))
          break
      if contra:
        contra = False
        break
    else:
      stop = True
      #print('answer? h: %s' % h)
      break
  if stop:
    break
    
print(sum(h))

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var W, H, x, y float64
	fmt.Scan(&W, &H, &x, &y)

	a1 := W * H / 2.0
	a2 := x == W/2.0 && y == H/2.0
	fmt.Printf("%f %d\n", a1, toInt(a2))
}

func toInt(b bool) int {
	if b {
		return 1
	}
	return 0
}

Measured memory_bytes: 512
# import math
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque
# from collections import Counter

import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
s = input()

arrS = list(s)

ans = 1
for i in range(1,len(arrS)):
    if arrS[i-1] != arrS[i]:
        ans += 1
    else:
        continue

print(ans)

Measured memory_bytes: 13388
#!/usr/bin/env python3
import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(H: int, W: int, h: int, w: int):
    return (H - h ) * (W - w)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    h = int(next(tokens))  # type: int
    w = int(next(tokens))  # type: int
    result = solve(H, W, h, w)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 10000
typedef pair<int,int> pii;
int a,b,c;
 
bool input(){
    cin >> a >> b >> c;
    return a;
}
 
int main(){
    while(input()){
	bool found = false;
	vector<pii> pr,qs;
	for(int p = 1 ; p <= a ; p++){
	    int r = a/p;
	    if(a % p != 0 || p < r) continue;
	    pr.push_back(pii(p,r));
	}
	int cc = c < 0 ? -c : c;
	for(int q = -cc ; q <= cc ; q++){
	    if(q == 0) continue;
	    int s = 0;
	    if(c < 0){
		if(q < 0 && abs(c) % abs(q) == 0){
		    if(abs(c) % abs(q) == 0){
			s = abs(c)/abs(q);
		    }
		}else{
		    if(abs(c) % q == 0){
			s = abs(c)/q;
			s = -s;
		    }
		}
	    }else{
		if(q < 0){
		    if(c % abs(q) == 0){
			s = c/abs(q);
			s = -s;
		    }
		}else{
		    if(c % q == 0){
			s = c/q;
		    }
		}
	    }
	    if(s == 0) continue;
	    qs.push_back(pii(q,s));
	}
	if(c == 0){
	    for(int i = -MAX ; i <= MAX ; i++){
		qs.push_back(pii(0,i));
		qs.push_back(pii(i,0));
	    }
	}
	for(int i = 0 ; i < (int)pr.size() ; i++){
	    for(int j = 0 ; j < (int)qs.size() ; j++){
		int p = pr[i].first,r = pr[i].second;
		int q = qs[j].first,s = qs[j].second;
		if(p == r && q < s) continue;
		if(p*s+q*r == b){
		    cout << p << " " << q << " " << r << " " << s << endl;
		    found = true;
		    goto END;
		}
	    }
	}
	if(!found){
	    cout << "Impossible" << endl;
	}
    END:;
    }
    return 0;
}

Measured memory_bytes: 3536