akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    set<int> in, out;
    pair<int, int> sushi[N];

    for(int i=0; i<N; i++){
        cin >> sushi[i].second >> sushi[i].first;
    }

    sort(sushi, sushi + N, greater<pair<int, int>>());
    
    long ans = 0;
    long x = 0;
    vector<int> minor, subs;

    for(int i=0; i<K; i++){
        ans += sushi[i].first;
        if (in.count(sushi[i].second) == 0) {
            in.insert(sushi[i].second);
            x++;
        }
        else {
            minor.push_back(sushi[i].first);
        }
    }

    long y = 0;

    for(int i=K; i<N; i++){
        if(out.count(sushi[i].second) == 0 && in.count(sushi[i].second) == 0){
            out.insert(sushi[i].second);
            y++;
            subs.push_back(sushi[i].first);
        }
    }

    ans += x * x;
    long cur = ans;
    int n_type = x + y;
    int cnt = 0;

    for(; x <= n_type && cnt < y && K - 1 - x >= 0; x++){
        cur += 2 * x + 1;
        cur -= minor[K - 1 - x] - subs[cnt];
        cnt++;
        ans = max(ans, cur);
    }

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

Measured memory_bytes: 5884
class BIT:
    def __init__(self, n):
        """
            data : BIT木データ
            el : 元配列
        """
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    
    """A1 ~ Aiまでの累積和"""
    def Sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & (-i)   #LSB(Least Significant Bit)の獲得:i&(-i)
        return s
    
    """Ai += x"""
    def Add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    
    """Ai ~ Ajまでの累積和"""
    def Get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.Sum(j) - self.Sum(i)

def ctoi(c):
    return ord(c) - 97

n = int(input())
s = list(input())
q = int(input())

bits = [BIT(n) for _ in range(26)]
ans = []
for i in range(n):
    bits[ctoi(s[i])].Add(i+1, 1)
for _ in range(q):
    line = list(input().split())
    if line[0] == '1':
        idx = int(line[1])
        bits[ctoi(s[idx-1])].Add(idx, -1)
        s[idx-1] = line[2]
        bits[ctoi(line[2])].Add(idx, 1) 
    else:
        l,r = int(line[1]), int(line[2])
        cnt = 0
        for i in range(26):
            if bits[i].Get(l-1,r)!=0:
                cnt += 1
        ans.append(cnt)
for a in ans:
    print(a)

Measured memory_bytes: 270504
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=10000000;

int main()
{
    int d,n;
    scanf("%d%d",&d,&n);
    if(d == 0){
        for(int x=1 ; x<N ; x++){
            if(x%1 == 0){
                int y=x;
                if(y%100 == 0) continue;
                n--;
                if(n == 0){
                    printf("%d",x);
                    return 0;
                }
            }
        }
    }

    if(d == 1){
        for(int x=1 ; x<N ; x++){
            if(x%100 == 0){
                int y=x/100;
                if(y%100 == 0) continue;
                n--;
                if(n == 0){
                    printf("%d",x);
                    return 0;
                }
            }
        }
    }

    if(d == 2){
        for(int x=1 ; x<N ; x++){
            if(x%10000 == 0){
                int y=x/10000;
                if(y%100 == 0) continue;
                n--;
                if(n == 0){
                    printf("%d",x);
                    return 0;
                }
            }
        }
    }

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Greedy algorithms - Activity Selection Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_C&lang=jp

"""
n = int(input())
activities = sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: x[1], reverse=True)

ans, ct = 0, 0
while activities:
    s, t = activities.pop()
    if s > ct:
        ct = t
        ans += 1
print(ans)



Measured memory_bytes: 24372
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<math.h>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e8;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
char b[5];
int main()
{
    ll a, c=0;
    cin >> a;
    for (int i = 0; i <= 3;i++)
    {
        cin >> b[i];
        if(i!=1)
            {
                c *= 10;
                c += b[i] -48;
            }
    }
    a *= c;
    cout << a / 100;
    return 0;
}

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

int dp[100001];
int a[100001];
int main(){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		dp[i]=1e9+7;
	}

	dp[0]=0;
	dp[1] = min(dp[1], dp[0] + abs(a[1]-a[0]));
	for(int i = 2; i < N; i++){
		int v = abs(a[i-1]-a[i]);
		int v2 = abs(a[i-2]-a[i]);
		dp[i] = min(dp[i-1] + v, dp[i-2] + v2);
	}
	cout << dp[N-1] << endl;

}


Measured memory_bytes: 4348
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,k,snake=0;
    cin >> n >> k;
    vector<int>l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end(),greater<int>());
    for(int i=0;i<k;i++){
        snake+=l[i];
    }
    cout << snake;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> aa(b, false);
  for (int i = 0; ; i++) {
    int now = a * i % b;
    if (aa[now]) {
      break;
    }
    aa[now] = true;
  }
  cout << (aa[c] ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
    string w;
    cin >> w;
    int alpha_size = 'z'-'a'+1;
    auto ww = vector<int>(alpha_size,0);
    for(int i=0;i<(int)w.size();i++){
        ww[w[i]-'a']++;
    }
    for(int i=0;i<(int)ww.size();i++){
        if(ww[i]%2!=0){
            cout << "No";
            return 0;
        }
    }
    
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
//E
#include<stdio.h>
main(){
	int a, b, c, d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a*b>c*d){
		printf("%d",a*b);
	}
	else{
		printf("%d",c*d);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;



int main()
{
    ll n,x;
    cin >> n >> x;
    vll s(n);
    rep(i,n)cin>>s[i];
    sort(all(s),greater<ll>());
    vll dp(1e5 + 1, 0);
    dp[x] = 1;
    rep(i,n){
        vll nex(1e5 + 1, 0);
        rep(j, 1e5 + 1){
            if (j<s[i]){
                nex[j] = (nex[j] + dp[j] * (n - i) % mod) % mod;
            }
            else{
                nex[j] = (nex[j] + dp[j] * (n - 1 - i) % mod) % mod;
                nex[j % s[i]] = (nex[j % s[i]] + dp[j]) % mod;
            }
        }
        copy(all(nex), dp.begin());
    }
    ll ans = 0;
    rep(j,1e5+1){
        ans = (ans + dp[j] * j % mod) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1904
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(void) {
	double n,m,k=0.0,sum=0.0,tmp=0.0;
	double ans;
	char str[100],*line;

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		line=strtok(str,",");
		sscanf(line,"%lf",&n);
		line=strtok(NULL,",");
		sscanf(line,"%lf",&m);
		sum+=n*m; tmp+=m; k++;
	}
	ans=tmp/k;
	ans=ceil(ans);
	printf("%d\n%d\n",(int)sum,(int)ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
int main(){
  int h,n;
  std::cin >> h >> n;
  int a[n];
  for(int i = 0; i < n; i++)
    std::cin >> a[i];
  int  i;
  std::sort(a, a + n);
  for(i = n - 1; i > -1; i--) {
    h -= a[i];
    if(h <= 0)
      break;
  }
  if(h > 0)
    std::cout << "No"<< std::endl;
  else
    std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j,cc=0;
    cin>>n;
    ll ara[n],value[n];
    for(i=0;i<n;i++)cin>>ara[i];
    for(j=0;j<n;j++)cin>>value[j];
    for(i=0;i<n;i++){
        if(ara[i]-value[i]>0)cc+=ara[i]-value[i];
    }
    cout<<cc<<endl;
return 0;
}


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

int main(){
    int H, N; cin >> H >> N;
    int A[N], sumA=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sumA += A[i];
    }
    if(sumA >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int t = 1;
  for(int i = 0;i < N;i++){
    if (t * 2 < t + K){
      t *= 2;
    }
    else{
      t += K;
    }
  }
  cout << t <<endl;
}


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

#define ll long long

int main() {
    int R, G, B, N;
    int res = 0;
    scanf("%d%d%d%d", &R, &G, &B, &N);
    for(int r = 0;r <= N/R;r++) {
        for(int g = 0;g <= N/G;g++) {
            res += 0 <= N - r*R - g*G && (N - r*R - g*G)%B == 0 ? 1 : 0;
        }
    }
    printf("%d\n", res);
    return 0;
}

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

int main(){

    int n;
    cin >> n;
    vector<int> vec(n);
    
    iota(vec.begin(), vec.end(), 1);

    do{
        for(auto it = vec.begin(); it != vec.end(); ++it){
            if(it != vec.begin()){
                cout << " ";
            }
            cout << *it;
        }
        cout << endl;
    }while(next_permutation(vec.begin(), vec.end()));

    return 0;
}


Measured memory_bytes: 3096
N = int(input())
a = list(map(int, input().split()))
ans = 'APPROVED'
for i in range(N):
    if a[i]%2 ==0:
        if a[i]%3 ==0 or a[i]%5 ==0:
            continue
        else:
            ans = 'DENIED'
            break
    
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int r;
    cin >> r;
    printf("%.4lf\n",2*r*3.1415);
    return 0;
}





























Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
  lli A,B,C=INF,D=0,E=0,F=0,G=0,H=0,N,M;
  cin >> N;
  vector<lli>P(N);
  rep(i,0,N){
    cin >> P[i];
    D=D+P[i]-1;
  }
  Out(D);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>

int main()
{
long long int n;
long long int a;
long long int count = 0;
std::cin >> n;
for(long long int i = 0; i < n; i++){
    std::cin >> a;
    if(a % 2 != 0){
        count++;
    }
}
if(count % 2 == 0){
    std::cout << "YES" << std::endl;
} else {
    std::cout << "NO" << std::endl;
}

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    int ue,shita,migi,hidari;
    ue = y+r;
    shita = y-r;
    migi = x + r;
    hidari = x - r;
    if(H < ue || shita < 0 || H < migi || hidari < 0 ){
        printf("No\n");
    }else{
        printf("Yes\n");
    }   
}

Measured memory_bytes: 2680
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(input())
    p = [int(input()) for _ in range(N)]
    print(max(p) // 2 + sum(p) - max(p))

main()


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

int main(){

    int a,b,c;
    cin >> a >> b>> c;

    int n=0;
    for (int i = a; i <=b ; i++)
    {
        if (c % i == 0) n++;
    }
    
    cout << n <<endl;
    

}




Measured memory_bytes: 3096
#coding: utf-8
import math

x = int(input())

maxcount = int(math.sqrt(x))

result = 0
for i in range(1,maxcount+ 1):
    j = 0
    while True:
        tmp = i ** (maxcount - j)
        j += 1
        if tmp > x:
            continue
        else:
            break
    if tmp > result and tmp <= x:
        result = tmp

print(result)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<int, int> intP;
typedef std::priority_queue<intP, std::vector<intP>, std::greater<intP> > IntPReversePrioQueue; //A->Z

int dx9[9]={0,0,0,1,1,1,-1,-1,-1};
int dy9[9]={1,0,-1,1,0,-1,1,0,-1};
ll ans[10];

void solve(void){
    ll h, w, n;
    scanf("%lld%lld%lld\n", &h, &w, &n);
    IntPReversePrioQueue que;
    rep(n, i){
        ll a, b;
        scanf("%lld%lld\n", &a, &b);
        rep(9, j) {
            ll x = a+dx9[j], y = b+dy9[j];
            if (2 <= x and x <= (h-1) and 2 <= y and y <= (w-1)) que.push(intP(x, y));
        }
    }
    int mulc = 1;
    intP temp;
    while (que.size()) {
        temp = que.top(); que.pop();
        if (temp != que.top() or que.empty()) {
            ans[mulc]++;
            mulc = 1;
        }
        else mulc++;
        //printf("%d %d\n", temp.first, temp.second);
    }
    ans[0] = (h-2)*(w-2);
    Rep(1, 9, i) ans[0] -= ans[i];
    rep(10, i) printf("%lld\n", ans[i]);
}

int main(void){
  solve();
  return 0;
}


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

int main(){
    int n;  cin>>n;
    double ans=0;
    for(int i=0;i<n;i++){
        double x;   cin>>x;
        string u;   cin>>u;

        if(u=="JPY")ans+=x;
        else ans+=(x*380000.0);
    }

    cout<<ans<<endl;



    return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;i++){
            fac[i]=fac[i-1]*i%mod;
            inv[i]=mod-inv[mod%i]*(mod/i)%mod;
            finv[i]=finv[i-1]*inv[i]%mod;
        }
    }
    ll operator()(int n,int k){
        if(n<k)return 0;
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
    }
};

int main(){
    int n;
    cin>>n;
    int flag=false;
    int a[n+1];
    map<int,int> mp;
    int cnt=0;
    rep(i,n+1){
        cin>>a[i];
        if(flag)++cnt;
        ++mp[a[i]];
        if(mp[a[i]]==2)flag=true;
    }
    rep(i,n+1){
        if(mp[a[i]]==2)break;
        ++cnt;
    }
    Combination comb(n+1);
    for(int k=1;k<=n+1;++k){
        ll ans=comb(n+1,k);
        ans=(ans-comb(cnt,k-1))%mod;
        ans=(ans+mod)%mod;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 8576
class atcorder:
    
    S=list(input())
    inv=list(reversed(S))
    i=0
    j=0
    if S==inv:
        i+=1
        
    N=int((len(S)-1)/2)
    for x in range(N-1):
        if S[x]==S[N-1-x] and inv[x]==inv[N-1-x]:
            pass
        else:
            j+=1
                
    if j==0 and i==1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
N = int(input())
mod = 10**9+7
from collections import defaultdict
dp = defaultdict(lambda:{})
def possible(last4):
    if 'AGC' in last4:
        return False
    for i in range(3):
        s = list(last4)
        s[i],s[i+1] = s[i+1],s[i]
        if 'AGC' in ''.join(s):
            return False
    return True
    
def rec(n,last3):
    if last3 in dp[n]:
        return dp[n][last3]
    if n == 3:
        if last3 not in ['AGC','GAC','ACG']:
            dp[n][last3] = 1
            return 1
        else:
            dp[n][last3] = 0
            return 0
    res = 0
    for s in 'AGCT':
        last4 = last3+s
        if possible(last4):
            res += rec(n-1,last4[1:])
            res %= mod
    dp[n][last3] = res
    return res

print(rec(N+3,'TTT'))

Measured memory_bytes: 4216
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <random>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

constexpr int dy[] = {1,0,-1,0,1,-1,-1,1};
constexpr int dx[] = {0,1,0,-1,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;

inline int gcd(int a, int b){ return b ? gcd(b,a % b) : a;}
inline int lcm(int a, int b){ return a / gcd(a,b) * b;}
inline int updiv(int a, int b){ return (a + b - 1) / b; }

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,y;
    cin >> n >> y;

    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n - i; ++j){
            int tmp = i * 1e4 + j * 5e3;
            if(tmp % 1000 == 0 && (y - tmp) / 1e3 == n - i - j){
                return cout << i << ' ' << j << ' ' << (y - tmp) / 1e3 << '\n',0;
            }
        }
    }

    cout << "-1 -1 -1\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int n;
        int min = 1000000;
        int max = -1000000;
        int temp;
        long sum = 0;
        cin>>n;
        for(int i=0;i<n;i++){
                cin>>temp;
                sum+=temp;
                if(temp>max){
                       max = temp;
                }
                if(temp<min){
                        min = temp;
                }
        }
        cout<<min<<" "<<max<<" "<<sum<<endl;
}




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

int main() {
  int ac=0,wa=0,tle=0,re=0;
  int b;
  string c;
  
  cin >> b;

  for (int i = 0; i < b; i++) {
    cin >> c;
    if(c == "AC"){
      ac = ac+ 1;
    }
    if(c == "WA"){
      wa = wa+ 1;
    }
    if(c == "TLE"){
      tle = tle+ 1;
    }
    if(c == "RE"){
      re = re+ 1;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	int N,T[10001],M,P[10001][2],i,j,sum=0,q,k;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&T[i]);
	scanf("%d",&M);
	for(j=0;j<M;j++)
		scanf("%d %d",&P[j][0],&P[j][1]);
    for(i=0;i<M;i++){
 	  	if(P[i][0]<=N){
 	  		q=T[P[i][0]-1];
   			T[P[i][0]-1]=P[i][1];
  			 for(k=0;k<N;k++){
				sum+=T[k];
			}
			printf("%d\n\n",sum);
			sum=0;
			T[P[i][0]-1]=q;
		}
	}
	return 0;
}

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

struct Fast{Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define SIZE(x) ll((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)

/* REPmacro*/
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (ll i = (a); i >= (ll)(b); --i)
#define RREP(i, n) RFOR(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* alias */
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vs = vector<string>;

/* const */
const int INF = 1001001001;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

/* func */
template <typename T = int> inline T in(){T x; cin >> x; return x;}
template <typename T> inline void print(const T& x){cout << x << "\n";}
inline void printvec(const vi& vec){REP(i, SIZE(vec)) cout << vec.at(i) << ((i == SIZE(vec)) ? "\n" : " ");}
inline int lcm(int a, int b){return a / gcd(a, b) * b;}
bool is_prime(int n){if (n < 2) return false;FOR(i, 2, (int)(sqrt(n) + 1)){if (n % i == 0) return false;}return true;}


int main(){
  int K = in();
  long long num = 0;
  FOR(i, 1, K+1){
    FOR(j, 1, K+1){
      FOR(k, 1, K+1){
        num += gcd(gcd(i, j), k);
      }
    }
  }
  print(num);
}

Measured memory_bytes: 3692
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int c, a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    if (c - (a - b) >= 0)
    {

        cout << c - (a - b) << "\n";
        return 0;
    }
    else
        cout << 0 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, L; cin >> N >> L;
    int sum = 0;
    rep(i, N){
        sum += L + i;
    }
    ll diff = INF;
    int ans = 0;
    rep(i, N){
        int tmp = sum - (L + i);
        if(abs(tmp - sum) < diff){
            ans = tmp;
            diff = tmp - sum;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc146/tasks/abc146_a
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        c: chars
    };
    let wdays = vec!["SUN","MON","TUE","WED","THU","FRI","SAT"];
    let cs = join!(c, "");
    for i in 0..7 {
        if cs == wdays[i] {
            println!("{}", ifv!(i == 0, 7, 7-i));
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[99999999];
ll INF = 1e17;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);

    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }

    dp[0]=0;
    dp[1]=abs(h[1]-h[0])+dp[0];

    

    for(int i = 2; i < n; i++){
        
        for(int j = 0; j <= min(i,k);j++){
            dp[i]=(j==1)?abs(h[i]-h[i-j])+dp[i-j]:min(dp[i],abs(h[i]-h[i-j])+dp[i-j]);
        }
    }

    cout << dp[n-1] << endl;



}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int c1 = 0, c2 = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			c1++;
		} else {
			c2++;
		}
	}
	if (c1 > c2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  ll n; cin >> n;
  ll sum = 0;
  FOR(i,1,n){
    FOR(j,1,n){
      FOR(k,1,n){
        ll tmp = gcd(gcd(i,j),k);
        sum += tmp;
      }
    }
  }
  cout << sum << "\n";

}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
using namespace __gnu_cxx;

using ci = const int;
using ld = long double;
using llint = long long;
using ullint = unsigned long long;
using pii = pair <int,int>;
using pcc = pair <char,char>;
using pll = pair <llint,llint>;
using pss = pair <string,string>;
using vi = vector <int>;
using vb = vector <bool>;
using vll = vector <llint>;
using vii = vi::iterator;

#define INF (1<<30)
#define MOD 1000000007
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define ms(name,val) memset(name, val, sizeof name)
#define np nullptr
// inline functions



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

    int n, a, b, c, prevA, prevB, prevC;
    cin >> n;

    for (int t1 = 0; t1 < n; ++t1)
    {
        cin >> a >> b >> c;

        if (t1)
        {
            a += max(prevB, prevC);
            b += max(prevA, prevC);
            c += max(prevA, prevB);
        }

        prevA = a, prevB = b, prevC = c;
    }

    cout << max({a, b, c}) << '\n';






























    return 0;
}

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

class Field {
  public:
  vector<vector<bool> > field; // [y][x]
  int H, W;
  Field(vector<vector<bool> > _field, int h, int w) {
    H = h;
    W = w;
    field = _field;
  }
  void next() {
    for(int y = 0; y < H; ++y) for(int x = W - 2; x >= 0; --x) {
      field[y][x + 1] = field[y][x];
      field[y][x] = false;
    }
  }
};

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<bool> > field(H, vector<bool>(W, false));
  for(int h = 0; h < H; ++h) {
    for(int w = 0; w < W; ++w) {
      char c;
      cin >> c;
      if(c == 'c') {
        field[h][w] = true;
      } else {
        field[h][w] = false;
      }
    }
  }
  
  Field f(field, H, W);

  vector<vector<int> > rfield(H, vector<int>(W, -1)); // [y][x]
  for(int i = 0; i <= W; ++i) {
    for(int y = 0; y < H; ++y) {
      for(int x = 0; x < W; ++x) {
        if(f.field[y][x] && rfield[y][x] == -1) rfield[y][x] = i;
      }
    }
    f.next();
  }
  for(int y = 0; y < H; ++y) {
    for(int x = 0; x < W; ++x) {
      if(x != 0) cout << ' ';
      cout << rfield[y][x];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1777777777;
// constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i)  cin >> a[i];

    constexpr ll inf = 1e+15;
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -inf));
    auto MemoRec = [&](auto&& self, int l, int r) -> ll {
        if(dp[l][r] != -inf)    return dp[l][r];
        if(r - l <= 0)  return dp[l][r] = 0;
        
        ll res = -inf;
        chmax(res, a[l] - self(self, l + 1, r));
        chmax(res, a[r - 1] - self(self, l, r - 1));

        return dp[l][r] = res;
    };

    cout << MemoRec(MemoRec, 0, N) << endl;
}

Measured memory_bytes: 73936
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem141b(s))
}

fun problem141b(s: String): String {
    for (i in s.indices) {
        if ((i + 1) % 2 == 0) {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {

            } else {
                return "No"
            }
        } else {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {

            } else {
                return "No"
            }
        }
    }
    return "Yes"
}

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

int main() {
	int n; cin >> n;

	int tmp = n;
	int ans = 0;
	while (tmp != 0) {
		ans += tmp % 10;
		tmp /= 10;
	}

	cout << (n % ans == 0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,a,b,c,cnt;
int main(){
  cin>>n;
  while(n--){
    cin>>a>>b>>c;
    cnt=min(a,min(b,c));
    a-=cnt;
    b-=cnt;
    c-=cnt;
    while(a>=2&&b>=1){
      cnt++;
      a-=2;
      b--;
    }
    cnt+=(a/3);
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const int MXN = 1e6 + 1;
const int MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const int INF = 1e9;
const llong LINF = 1e18;
const int MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

int ans = INF;

string s;

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> s;
    for (int i = 1; i < (int)s.size (); ++ i) {
        if (s[i] != s[i - 1]) {
            int k = max (i, (int)s.size () - i);
            ans = min (ans, k);
        }
    }
    cout << (ans == INF ? s.size () : ans);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;

void bfs(int p, int x, vector<vector < int >>& ab, vector<long>& count){
  int a = count[p]+x;
  count[p] = a;
  x = count[p];
  // count[p] += x;
  for (auto next : ab[p]){
      bfs(next, x, ab, count);
    }
}

int main(int argc, const char * argv[]) {

  int n, q;
  cin >> n >> q;
  vector<vector< int > > ab(n+1);
  vector<long> count(n+1,0);

  rep(i, n-1){
    int a, b;
    cin >> a >> b; 
    ab[a].push_back(b);
  }

  rep(i, q){
    int p, x;
    cin >> p >> x;
    count[p] += x;
  }
  bfs(1, 0, ab, count);
  repd(i, 1, n+1){
    cout << count[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 24320
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

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

#define INF 987654321

using namespace std;

class Graph {
public:
    Graph(int v) : graph(v) {}

    void add_edge(int from, int to) {
        graph[from].push_back(to);
        graph[to].push_back(from);
    }

    int shortest_path(int from, int to) {
        queue<int> q;
        vector<int> distance(graph.size(), INF);

        distance[from] = 0;
        q.push(from);

        while (!q.empty()) {
            int p = q.front();
            q.pop();

            for (int v : graph[p]) {
                if (distance[v] == INF) {
                    distance[v] = distance[p] + 1;
                    q.push(v);
                }

                if (v == to) return distance[v];
            }
        }

        return -1;
    }

    vector<vector<int>> graph;
};

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

    Graph graph(H * W);
    char map[50][50];

    REP(i, 50)
    REP(j, 50)
    map[i][j] = '#';

    REP(i, H)
    REP(j, W)
    cin >> map[i][j];

    int white = 0;
    REP(i, H) {
        REP(j, W) {
            int dx[] = {1, 0, -1, 0};
            int dy[] = {0, -1, 0, 1};

            if (map[i][j] == '.') {
                white++;
                REP(k, 4) {
                    int x = j + dx[k];
                    int y = i + dy[k];

                    if (0 <= x && x < W && 0 <= y && y < H) {
                        if (map[y][x] == '.') {
                            graph.add_edge(y * W + x, i * W + j);
                        }
                    }
                }
            }
        }
    }

    int res = graph.shortest_path(0, H * W - 1);

    if (res == -1)
        cout << res << endl;
    else
        cout << white - res - 1 << endl;

    return 0;
}


Measured memory_bytes: 384
n,p=map(int,input().split())
s=input()
total=[0]*p#pで割った余りで分類
total[0]=1#t[0]=0の分をあらかじめカウント
t=[0]*(n+1)#s[i:n]を格納する用の配列
if p==2 or p==5:
    ans=0
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
    print(ans)
else:
    for i in range(n-1,-1,-1):
        t[i]=t[i+1]%p+int(s[i])*pow(10,n-1-i,p)#s[i:n]を漸化式で付け加えていく
        total[t[i]%p]+=1
    ans=0
    for i in range(p):
        ans+=total[i]*(total[i]-1)//2
    print(ans)

Measured memory_bytes: 75400
#include<iostream>
#include<vector>
#include<map>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
const long mod=1e9+7;
int N,M;
string s;
char var[10];
int u[10];
main()
{
	cin>>N>>M;
	cin>>s;
	for(int i=0;i<M;i++)
	{
		cin>>var[i]>>u[i];
	}
	long ans=0;
	for(int i=0;i<1<<M;i++)
	{
		for(int j=i;;j=j-1&i)
		{
			map<char,vector<int> >now;
			vector<int>L,R;
			for(char c='0';c<='9';c++)
			{
				now[c]=(vector<int>){(int)L.size()};
				L.push_back(c-'0');
				R.push_back(c-'0');
			}
			bool ok=true;
			for(int k=0;k<M;k++)
			{
				int id=L.size();
				if(i>>k&1)
				{
					if(j>>k&1)
					{
						if(u[k]<10)
						{
							ok=false;
							break;
						}
						now[var[k]]=(vector<int>){id,id+1};
						L.push_back(u[k]/10);
						R.push_back(u[k]/10);
						L.push_back(0);
						R.push_back(u[k]%10);
					}
					else
					{
						if(u[k]<20)
						{
							ok=false;
							break;
						}
						now[var[k]]=(vector<int>){id,id+1};
						L.push_back(1);
						R.push_back(u[k]/10-1);
						L.push_back(0);
						R.push_back(9);
					}
				}
				else
				{
					now[var[k]]=(vector<int>){id};
					L.push_back(0);
					R.push_back(u[k]<9?u[k]:9);
				}
			}
			if(ok)
			{
				vector<int>S;
				for(char c:s)for(int id:now[c])S.push_back(id);
				UF uf(L.size());
				for(int k=0;k<S.size();k++)
				{
					uf.unite(S[k],S[S.size()-k-1]);
				}
				long ret=1;
				vector<bool>vis(L.size(),false);
				for(int k=0;k<L.size();k++)if(!vis[uf.find(k)])
				{
					vis[uf.find(k)]=true;
					int l=0,r=9;
					for(int m=0;m<L.size();m++)if(uf.find(m)==uf.find(k))
					{
						if(l<L[m])l=L[m];
						if(r>R[m])r=R[m];
					}
					if(l>r)ret=0;
					else ret=ret*(r-l+1)%mod;
				}
				(ans+=ret)%=mod;
			}
			if(j==0)break;
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3220
using System;

namespace beginner753
{
    class Program
    {
        static void Main(string[] args)
        {
            switch(int.Parse(Console.ReadLine().Trim()))
            {
                case 3:
                case 5:
                case 7:
                    Console.WriteLine("YES");
                    break;
                default:
                    Console.WriteLine("NO");
                    break;
            }

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);

    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> c[i];
    }

    int ans = 0;

    for(int i = 0; i < n; ++i){
        if(v[i] > c[i])ans += v[i]-c[i];
    }

    cout << ans << endl;


}

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

using namespace std;
int main(void){
    int N,A;
    int T[3];
    cin>>T[0]>>T[1]>>T[2]>>N;
    A=0;
    sort(T,T+3);
    reverse(T,T+3);
        
    
    for(int i=0;i<=N/T[0];i++){
        for(int j=0;j<=(N-i*T[0])/T[1];j++){
            
            if((N-T[0]*i-T[1]*j)%T[2]==0){
                    A=A+1;
                
            }    
        }
    }
    
    cout<<A<<endl;
    return 0;
    
}

Measured memory_bytes: 256
// Problem : 
// 			D - Connectivity
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 049
// URL : https://atcoder.jp/contests/abc049/tasks/arc065_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, A, B;
int dsu[2][200005];
map<int, int> mp[200005];

int getrt(int t, int n){
	return dsu[t][n] = (dsu[t][n] == n ? n : getrt(t, dsu[t][n]));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> A >> B;
	for(int i = 1; i<=N; i++){
		dsu[0][i] = dsu[1][i] = i;
	}
	for(int i = 1; i<=A; i++){
		int a, b;
		cin >> a >> b;
		if(getrt(0, a) != getrt(0, b)){
			dsu[0][getrt(0, a)] = getrt(0, b);
		}
	}
	for(int i = 1; i<=B; i++){
		int a, b;
		cin >> a >> b;
		if(getrt(1, a) != getrt(1, b)){
			dsu[1][getrt(1, a)] = getrt(1, b);
		}
	}
	for(int i = 1; i<=N; i++){
		mp[getrt(1, i)][getrt(0, i)]++;
	}
	for(int i = 1; i<=N; i++){
		cout << mp[getrt(1, i)][getrt(0, i)] << " ";
	}
}

Measured memory_bytes: 23060
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
#include <cmath>
//#include <iomainp>
using namespace std;

#define DB(x)
#define rep(i, n) for(int i = 0;i < n;i++)
typedef uint64_t LL;

int main()
{
    LL A,B,K;
    cin >> A >> B >> K;
    
    if( A >= K ){
        A -= K;
        cout << A << " " << B << endl;
        return 0;
    }else{
        K -= A;
        A = 0;
    }
    
    if( B >= K ){
        B -= K;
        cout << A << " " << B << endl;
        return 0;
    }else{
        K -= B;
        B = 0;
    }
    
    cout << A << " " << B << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a+b+c >=22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    
    
}

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


int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string	s;
	cin >> s;
	int		result = 0;
	for (char x : s) if (x == '1') result++;
	cout << result << "\n";
}


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

int n;//n週間
double sum;//n週間後の借金

int main(){
  sum = 100000;
  scanf("%d",&n);
  for(int i= 0;i < n;i++){
    sum += 0.05*sum;
    sum = ceil(sum/1000)*1000;
}
  
  int ans =(int)sum;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1188