akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
vector<int> g[100000];
int used[100000];
vector<int> path, path2;

int main() {
    scanf("%d%d", &n, &m);
    forn(i, m) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        g[from].pb(to);
        g[to].pb(from);
    }
    for (int v = 0; ; ) {
        path.pb(v);
        used[v] = 1;
        bool done = true;
        for (int to : g[v]) if (!used[to]) {
            v = to;
            done = false;
            break;
        }
        if (done) {
            break;
        }
    }
    for (int v = 0; ; ) {
        path2.pb(v);
        used[v] = 1;
        bool done = true;
        for (int to : g[v]) if (!used[to]) {
            v = to;
            done = false;
            break;
        }
        if (done) {
            break;
        }
    }
    reverse(path2.begin(), path2.end());
    path2.pop_back();
    printf("%d\n", (int)(path.size() + path2.size()));
    for (int x : path2) printf("%d ", x + 1);
    for (int x : path) printf("%d ", x + 1);
    puts("");
    return 0;
}


Measured memory_bytes: 7160
n = int(input())
x = list(map(int, input().split()))
a=0
b=0
def max():
    m = 0
    j = 0
    for i in range(len(x)):
        if x[i]>m:
            m=x[i]
            j=i
    x.pop(j)
    return m
if n%2 == 0:
    i=0
    while i<n:
        a += max()
        b += max()
        i += 2
else:
    i=0
    while i<n-1:
        a += max()
        b += max()
        i += 2
    a+=max()
print(a-b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N;
int c[2000][2000];

void pnt(int s, int d, int l)
{
    for (int i = s; i < N; i += d) {
        for (int j = s; j < N; j += d) {
            if (((i - j) / d % 2 + 2) % 2 == 1) {
                c[i][j] = l;
            }
        }
    }
}

void solve()
{
    int t = 1;
    int l = 1;
    FOR(i, 0, N)
    {
        FOR(j, 0, N)
        {
            c[i][j] = -1;
        }
    }
    bool flag = true;
    while (true) {
        for (int i = 0; i < t; i++) {
            pnt(i, t, l);
        }
        if (t >= N) {
            break;
        }
        t *= 2;
        l++;
    }
    FOR(i, 0, N - 1)
    {
        FOR(j, i + 1, N)
        {
            cout << c[i][j] << " ";
        }
        cout << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    solve();
    return 0;
}


Measured memory_bytes: 7680
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
bool check(int n)
{
	for (int i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 6; i < N; i += 5)
	{
		if (!check(i)) continue;
		n--;
		printf("%d%c", i, " \n"[n == 0]);
		if (n == 0) break;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		while(scan.hasNext()){
			int d = Integer.parseInt(scan.next());
			int n = 600;
			int m = 0;
			for(int i = d;i < n;i += d){
				m += d*Math.pow(i,2);
			}
			System.out.println(m);
		}
		System.exit(0);
	}

}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
int n[10000000],s1,s2;
int main(){
int p,a,b;
while(true){
s1=0;s2=0;
cin>>p;
if(p==0){
break;
}
for(int i=0;i<p;i++){
cin>>a>>b;
if(a>b){s1+=a+b;}
else if(b>a){s2+=a+b;}
else{s1+=a;s2+=b;}
}
cout<<s1<<' '<<s2<<endl;
}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(void){

    string s;
    cin>>s;

    if(s=="SAT") cout<<"1"<<endl;
     if(s=="SUN") cout<<"7"<<endl;
     if(s=="MON") cout<<"6"<<endl;
      if(s=="TUE") cout<<"5"<<endl;
       if(s=="WED") cout<<"4"<<endl;
        if(s=="THU") cout<<"3"<<endl;
         if(s=="FRI") cout<<"2"<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
    int a, b;
    cin >> a >> b;
    cout << a + b/2 << endl;
    return 0;
}

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

int main() {

	string s; cin >> s;
	int t = s.size() - 2;
	string ans = "";
	ans += s[0];
	ans += to_string(t);
	ans += s[s.size() - 1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3688
#include <cstdio>

int main()
{
        const int MAX = 10;
        int l[MAX];
        int v1, v2;
        int sumL;

        while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
                                 &l[0], &l[1], &l[2], &l[3],
                                 &l[4], &l[5], &l[6], &l[7],
                                 &l[8], &l[9], &v1, &v2) != EOF) {
                sumL = 0;
                for (int i = 0; i < MAX; i++) {
                        sumL += l[i];
                }
                float l1 = v1 * ((float)sumL / (v1 + v2));
                int i = 0;
                while (l1 > 0) {
                        l1 -= l[i++];
                }
                printf("%d\n", i);
        }

        return 0;
}

Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;
int calc(string);

stack<int> st;

int main() {
	string str;
	while(cin >> str) {
		if(str == "+" || str == "-" || str == "*") {
			st.push(calc(str));
		}
		else {
			st.push(stoi(str));
			//st.push(atoi(str.c_str()));
		}
		
		if(getchar() == '\n'){
			break;
		}
	}

	
	cout << st.top() << endl;
}

int calc(string str) {
	int first, second;
	second = st.top(); st.pop();
	first = st.top(); st.pop();
	int result;
	if(str == "+") {
		result = first + second;
	}
	else if(str == "-") {
		result = first - second;
	}
	else {
		result = first * second;
	}

	return result;
}




Measured memory_bytes: 3164
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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


fn main() {
    input!{
        n: usize,
        v: [[i64; 3]; n]
    }
    for i in 0..101 {
        'next: for j in 0..101 {
            let mut h: i64 = 0;
            for k in 0..n {
                if v[k][2] == 0 {
                    continue;
                }
                h = v[k][2] + (i - v[k][0]).abs() + (j - v[k][1]).abs();
                break;
            }
            for k in 0..n {
                let dh = v[k][2] - std::cmp::max(h - (i - v[k][0]).abs() - (j - v[k][1]).abs(), 0);
                if dh != 0 {
                    continue 'next;
                }
            }
            println!("{} {} {}", i, j, h);
            return;
        }
    }
}


Measured memory_bytes: 4352
from collections import deque

def main():
    h, w = map(int, input().split())
    start_h, start_w = map(lambda x: int(x)+1, input().split())
    goal_h, goal_w = map(lambda x: int(x)+1, input().split())

    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for _ in range(h):
        s.append("##" + input() + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))

    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[start_h][start_w] = 0

    move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),(-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),(0, -2), (0, -1), (0, 0), (0, 1), (0, 2),(1, -2), (1, -1), (1, 0), (1, 1), (1, 2),(2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]

    yet = deque([(start_h, start_w)])
    done = deque()

    while yet:
        x1, y1 = yet.popleft()
        done.append((x1, y1))
        for (p, q) in move1:
            v1, v2 = x1+p, y1+q
            if ans[v1][v2] == -1: #"."でまだ辿り着いていないマス
                yet.append((v1, v2))
                ans[v1][v2] = ans[x1][y1]

        if len(yet) == 0:
            while done:
                x2, y2 = done.popleft()
                for (p, q) in move2:
                    i, j = x2+p, y2+q
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        yet.append((i, j))

    print(ans[goal_h][goal_w])

if __name__ == "__main__":
    main()


Measured memory_bytes: 23588
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    string s,t;
    cin>>s>>t;
    int l=t.size();
    int mn=1123456789;
    for(int i=0;i<s.length()-t.length()+1;i++){
        int c=0;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!=t[j]){
                c++;
            }

        }
        mn=min(c,mn);
    }
    cout<<mn;



    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
    while(true) {
        ll e; cin >> e;
        if(e == 0) break;
        ll ans = e;
        for(ll z = 0; z*z*z <= e; z++) {
            for(ll y = 0; y*y <= e - z*z*z; y++) {
                int x = e - z*z*z - y*y;
                ans = min(ans, x + y + z);
            }
        }
        cout << ans << endl;
    }
}



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

int main(){
    int N,L ;
    cin >> N >> L ;
    //最後のリンゴの味
    int LN = N+L-1 ;
    if(L*LN <= 0){
        cout << (L + LN) * N / 2 << endl ;
    }
    else
    {
        if (L > 0)
        {
            cout << (L + LN) * N / 2 - L << endl ;
        }else
        {
            cout << (L + LN) * N / 2 - LN << endl ;
        }
        
        
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int counter = 0;
	
void isPrime(int num)
{
	int i=2, limit=sqrt(num);
	while(i<=limit){
		if(num%i == 0) return;
		i++;
	}

	counter++;
	return;
}

int main()
{
	int N;
	cin >> N;
	int num;
	for(int i=0; i<N; i++){
		scanf("%d", &num);
		isPrime(num);
	}
	cout << counter << endl;
}



Measured memory_bytes: 3160
s = input()
k = int(input())

num = 0
for i in s:
    if i == "1":
        num += 1
    else:
        break

first = 0
for i in s:
    if i == "1":
        first = 1
    else:
        first = i
        break

if num == 0:
    print(first)
elif k <= num:
    print(1)
else:
    print(first)

Measured memory_bytes: 3060
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,z;
    cin>>a>>b>>c;
    if(b*c>=a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return EXIT_SUCCESS;
}



Measured memory_bytes: 3636
/// 3:03 PM 11/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, w;
    cin >> n >> w;
    vector<ll> W(n);
    vector<ll> V(n);
    ll sv = 0;
    for (ll i = 0; i < n; i++) {
        cin >> W[i] >> V[i];
        sv += V[i];
    }
    vector<vector<ll> > dp(n + 1, vector<ll>(sv + 1, INF));
    dp[0][0] = 0;
    for (ll i = 1; i <= n; i++) {
        for(ll price = 0;price <= sv;price++) {
            ll cw = W[i-1];
            ll cp = V[i-1];
            if(cp <= price) {
                dp[i][price] = min(dp[i-1][price], cw + dp[i-1][price - cp]);
            } else {
                dp[i][price] = dp[i-1][price];
            }
        }
    }
    ll ans = 0;
    for(ll i=0;i<=sv;i++) {
        if(dp[n][i] <= w) {
            ans = i;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 80256
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """dict() -> new empty dictionary"""

    def items(self):
        """D.items() -> a set-like object providing a view on D's items"""
        return dict.iteritems(self)

    def keys(self):
        """D.keys() -> a set-like object providing a view on D's keys"""
        return dict.iterkeys(self)

    def values(self):
        """D.values() -> an object providing a view on D's values"""
        return dict.itervalues(self)


def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


def main():
    s = input().split('/')
    if int(s[1]) <= 4:
        print('Heisei')
    else:
        print('TBD')


if __name__ == '__main__':
    main()


Measured memory_bytes: 28780
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		int n,m;
		int p[1002];
		
		scanf("%d%d",&n,&m); if(n == 0 && m == 0)break;
		rep(i,n){
			scanf("%d",&p[i]);
		}
		
		vector<int> p1;
		rep(i,n){
			p1.pb(p[i]);
		}
		p1.pb(0);
		
		vector<int> p2;
		rep(i,n+1){
			rep(j,n+1){
				p2.pb(p1[i]+p1[j]);
			}
		}
		sor(p2);
		uniq(p2);
		
		int ret = 0;
		rep(i,p2.size()){
			if(p2[i] <= m){
				ret = max ( ret , p2[i] + *--ub(p2,m-p2[i]) );
			}
		}
		
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	string s;
	cin >> s;
	for(int i=0; i<s.size()-1; i++){
		if(s[i]==s[i+1]){
			cout << "Bad"<< endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
L = list(map(int, input().split()))

counter = 0

for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if len(set([L[i], L[j], L[k]]))==3 and L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[i]+L[k]>L[j]:
        counter+=1
      
print(counter)

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

int main(void){

    char s[16] = "", *p = s;
    int length = 0, i = 0, flg = 0, flg2 = 0;
    char result[3] = "AC";

    scanf("%s", &s);

    while(1){
        if(*p++ != '\0')
            length++;
        else
            break;
    }

    for(i = 0; i < length; i++){
        flg2 = 0;
        if(i == 0){
            if(s[0] != 'A'){
                strcpy(result,"WA");
                break;
            }
            flg2 = 1;
        }
        else if( i >= 2 && i <= (length - 2)){
            if(s[i] == 'C'){
                if(flg != 0){
                    strcpy(result,"WA");
                    break;
                }
                flg = 1;
                flg2 = 1;
            }
        }
        if(!('a' <= s[i] && s[i] <= 'z') && flg2 == 0){
            strcpy(result,"WA");
            break;
        }
    }

    if(flg != 1)
        strcpy(result,"WA");


    printf("%s\n",result);
    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main ()
{
    int x ;
    cin >> x ;
    if (x < 1200)
        cout << "ABC" ;
    else    
        cout << "ARC" ;

    return 0 ;
}


Measured memory_bytes: 256
// 27/07/19 // 16:32 PM //
// O(n)

#include <iostream>
#include <cstring>

using namespace std;

#define MAXN 100010

int n;
int value[MAXN][10];
int memo[MAXN][10];

int funcao(int i, int ant){  // ant = 0, 1, 2
    if(memo[i][ant]>=0) return memo[i][ant];

    if(i>n) return 0;

    for(int k=0; k<3; k++)
        if(k!=ant)
            memo[i][ant] = max(memo[i][ant], value[i][k] + funcao(i+1, k));

    return memo[i][ant];
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    memset(memo, -1, sizeof(memo));

    cin >> n;

    for(int i=1; i<=n; i++)
        cin >> value[i][0] >> value[i][1] >> value[i][2];

    cout << funcao(1, 4) << "\n";

    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vso(x) sort( x.begin() , x.end() )
#define vre(x) reverse( x.begin() , x.end() ) ;
#define aso(x) sort( x , x + x.size() )
#define are(x) reverse( x , x + x.size() )
#define print(x) cout << x << endl 
#define no cout << "NO\n" 
#define yes cout << "YES\n"
typedef long long ll ; 
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    //ull h = 798568968205 ; srand(h) ;
    //int t ; cin >> t ; while(t--){}
    ll x , n ; cin >> x >> n ;
    set <ll> s ;
    for ( int i = 0 ; i < n ; i++ )
    {
        ll p ; cin >> p ;
        s.insert(p) ;
    }
    ll l = x , r = x ;
    while(true)
    {
        if( s.count(l) == 0 ) { print(l) ; break ; }
        if( s.count(r) == 0 ) { print(r) ; break ; }
        l-- ; r++ ;
    }
    
}

Measured memory_bytes: 3656
object Main {
  def main(args: Array[String]): Unit = {
    val numbers = io.StdIn.readLine().split(" ")
    val q = io.StdIn.readInt()
    (0 until q)
      .map(_ => io.StdIn.readLine().split(" "))
      .foreach { case Array(u, s) =>
        val iu = numbers.indexWhere(_ == u)
        val is = numbers.indexWhere(_ == s)
        val ie = Dice(Sides(iu), !Sides(is)).eastSide.index
        println(numbers(ie))
      }
  }

  sealed trait Sides {
    def index: Int = Sides.values.indexWhere(_ == this)

    def unary_! : Sides = this match {
      case Sides.One   => Sides.Six
      case Sides.Two   => Sides.Five
      case Sides.Three => Sides.Four
      case Sides.Four  => Sides.Three
      case Sides.Five  => Sides.Two
      case Sides.Six   => Sides.One
    }
  }
  object Sides {
    case object One extends Sides
    case object Two extends Sides
    case object Three extends Sides
    case object Four extends Sides
    case object Five extends Sides
    case object Six extends Sides

    val values: Array[Sides] = Array(One, Two, Three, Four, Five, Six)
    def apply(index: Int): Sides = values(index)
  }

  case class Dice(upSide: Sides, northSide: Sides) {
    val eastSide: Sides = Dice.eastSides(upSide, northSide)
    def downSide: Sides = !upSide
    def southSide: Sides = !northSide
    def westSide: Sides = !eastSide

    def rotate(direction: Direction): Dice = direction match {
      case Direction.North => Dice(southSide, upSide)
      case Direction.South => Dice(northSide, downSide)
      case Direction.East => Dice(westSide, northSide)
      case Direction.West => Dice(eastSide, northSide)
    }
  }
  object Dice {
    import Sides._
    def apply(): Dice = Dice(One, Five)

    private[this] val eastSidesMap: Map[(Sides, Sides), Sides] = {
      def toMap(roll: Array[Sides], sides: Sides): Map[(Sides, Sides), Sides] = {
        roll.zip(roll.tail).map(_ -> sides).toMap
      }

      val _4 = Array[Sides](One, Two, Six, Five, One)
      val _2 = Array[Sides](One, Three, Six, Four, One)
      val _6 = Array[Sides](Two, Three, Five, Four, Two)

      toMap(_4, Four) ++ toMap(_4.reverse, Three) ++
      toMap(_2, Two)  ++ toMap(_2.reverse, Five) ++
      toMap(_6, Six)  ++ toMap(_6.reverse, One)
    }

    def eastSides(upSide: Sides, northSide: Sides): Sides = eastSidesMap((upSide, northSide))
  }

  sealed trait Direction
  object Direction {
    case object North extends Direction
    case object South extends Direction
    case object East extends Direction
    case object West extends Direction

    def apply(c: Char): Direction = c match {
      case 'N' => North
      case 'S' => South
      case 'E' => East
      case 'W' => West
      case _ => throw new Exception
    }
  }
}

Measured memory_bytes: 44128
using System;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);

            
            string[] input_b = Console.ReadLine().Split(' ');
            long[] b = new long[n];
            long[] c = new long[n];
            for(int i = 0;i < n;i++)
                b[i] = long.Parse(input_b[i]);
            
            
            for(int i = 1;i < n + 1;i++)
                c[b[i-1] - 1]= i; 

            for(int i = 0;i < n;i++)
                Console.Write(c[i] + " ");
        }
    }

Measured memory_bytes: 25940
a = int(input())
b = int(input())
if a == 1 and b == 2:
  print('3')
  
elif a == 2 and b == 3:
  print('1')
elif a == 1 and b == 3:
  print('2')
elif a == 2 and b == 1:
  print('3')
elif a == 3 and b == 1:
  print('2')
else:
  print('1')

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
ll n,m;
  ci(n)
  ci(m)
  vpll AB(n);
  FOR(i,0,n){
    ci(AB[i].fi);
    ci(AB[i].se);
  }
  SORT(AB);
  
  ll sum = 0;
  FOR(i,0,n){
    if(m > AB[i].se){
      m -= AB[i].se;
      sum += AB[i].fi * AB[i].se;
    }else{
      sum += AB[i].fi * m;
      break;
    }
  }
  co(sum);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll minAns = N;
    set<ll> ans;
    do {
        ans.insert(N);        
        ll newAns; 
        if (N > K) {
            newAns = N % K;
        } else {
            newAns = abs(N - K);
        }     
        minAns = min(newAns, minAns);
        N = newAns;
    } while (ans.count(N) == 0);
    cout << minAns << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE c(n - 1), s(n - 1), f(n - 1);
	rep(i, n - 1)cin >> c[i] >> s[i] >> f[i];
	rep(i, n) {
		int now = 0;
		FOR(j, i, n - 1) {
			if (now < s[j]) {
				now += s[j] - now;
			}
			else if(now % f[j] != 0){
				now += f[j]- now % f[j];
			}
			now += c[j];
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
inline ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

struct El{int left; int right;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    
    int left = 0;
    int right = INT_MAX;
    vector<El> vec;
    
    int ret = 0;
    
    while(M--)
    {
        int l, r; cin >> l >> r;
        vec.push_back(El{l, r});
        left = max(left, l);
        right = min(right, r);
    }
    
    cout << max(0, right - left + 1) << endl;
    return 0;
}


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

int main(void)
{
    int time;
    cin >> time;

    int hour, minute, second;

    hour = time / 3600;
    time -= hour * 3600;
    minute = time / 60;
    time -= minute * 60;
    second = time;

    cout << hour << ":"<< minute << ":" << second << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 


int main() {
    int n;
    vector<set<int>> idxs(26);
    cin >> n;
    rep(i, n) {
        char c;
        cin >> c;
        idxs[c-'a'].insert(i);
    }
    int q;
    vector<int> ans;
    cin >> q;
    rep(i, q) {
        int s;
        cin >> s;
        if (s == 1) {
            int iq;
            char cq;
            cin >> iq >> cq;
            --iq;
            rep(j, 26) {
                if (idxs[j].count(iq)) {
                    idxs[j].erase(iq);
                    idxs[cq-'a'].insert(iq);
                }
            }
        } else {
            int lq, rq;
            cin >> lq >> rq;
            --lq; rq;
            int c = 0;
            rep(j, 26) {
                if (idxs[j].size()) {
                    char cc = j + 'a';
                    auto lit = idxs[j].lower_bound(lq);
                    if (lit != idxs[j].end() && *lit < rq) ++c;
                }
            }
            ans.push_back(c);
        }
    }
    for (int a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 23936
def sqrt(n):
    i=0
    while n>=(i+1)**2:
        i=i+1
    return i

def digit(n):
    if n<10:
        return 1
    else:
        return 1+digit(n//10)

N=int(input())
i=sqrt(N)
while i>0:
    if N%i==0:
        print(digit(N//i))
        break
    else:
        i=i-1

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using ll = long long;
using ld = long double;
using Pa = std::pair<ll, ll>;
using vecin = std::vector<int>;
using vecll = std::vector<ll>;
using vecchar = std::vector<char>;
using vecvecll = std::vector<std::vector<ll>>;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n,ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow(((x * x)%mod), n / 2,mod));
	else
		return ((x%mod) * pow(x, n - 1,mod));
}
bool prime(int n) {
	int i = 2;
	if (n == 2)return true;
	else if(n <= 1)return false;
	if (n % i == 0)return false;
	i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0)return false;
		i += 2;
	}
	return true;
}
ll mod = 998244353;
int main() {
	int d, t, s; cin >> d >> t >> s;
	if (t * s < d)cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 3620
import math

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

fo = [a[0]]
re = [a[-1]]

x,y = a[0] , a[-1]
for i in range(n-1):
    x = math.gcd(x,a[i+1])
    y = math.gcd(y,a[n-2-i])
    fo.append(x)
    re.append(y)
    
ans = re[n-2]
for i in range(1,n-1):
    ans = max(ans , math.gcd(fo[i-1],re[n-2-i]))
ans = max(ans , fo[n-2])

print(ans)

Measured memory_bytes: 97268
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

ll pow_mod(ll base, ll exp, ll q) {
	base %= q;
	ll ans = 1;
	while (exp) {
		if (exp & 1) ans = (ans * base) % q;	
		base = (base * base) % q;
		exp /= 2;
	}
	return ans;
}

struct Binoms {
	ll n, q;
	vll fact, inv;

	Binoms(int max_objects, int modulo):n(max_objects),q(modulo) {
		fact.pb(1);
		inv.pb(1);
		for (int i = 1; i <= n; i++) {
			fact.pb( (fact[i-1]*i) % q);
			inv.pb(pow_mod(fact[i], q-2, q)); 
		}
	}

	ll binom(ll n, ll r) {
		return (fact[n] * ((inv[r]*inv[n-r]) % q)) % q;
	}
};

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int s; cin >> s;
	Binoms B = Binoms(s + 700, MOD);
	ll ans = 0;
	for (int num_vars = 1; num_vars <= 700; num_vars++) {
		int objects = s - (3*num_vars);
		if (objects < 0) break;
		ans += B.binom(objects + num_vars - 1, objects);
		ans %= MOD;
	}
	cout << ans;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=2e5+20;
const int M=5e2+20;
const ll inf=2e15;
ll n,x[N],L,Q;
ll d[30][N];
void init()
{
	for(ll i=1;i<=20;i++)
	{
		for(int j=1;j<=N;j++)
		{
			d[i][j]=d[i-1][d[i-1][j]];
		}
	}
}
int main()
{
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)
			scanf("%I64d",&x[i]);
		cin>>L>>Q;
		for(int i=1;i<=n;i++)
		{
			int l=i+1,r=n;
			while(l<=r)
			{
				int mid=(l+r)>>1;
				if(x[mid]-x[i]<=L)
					l=mid+1;
				else
					r=mid-1;
			}
			d[0][i]=l-1;
		}
		init();
		ll u,v;
		while(Q--)
		{
			scanf("%I64d%I64d",&u,&v);
			if(u>v)
				swap(u,v);	
			ll ans=0;
			for(ll i=20;i>=0;i--)
			{
				if(d[i][u]<v)
					ans+=(1ll<<i),u=d[i][u];
			}
			ans++;
			cout<<ans<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 37504
import math

def main():
    n,m = map(int,input().split())

    if abs(n-m) > 1:
        print(0)

    elif n == m:
        ans = math.factorial(n) * math.factorial(m) * 2
        print(ans%1000000007)

    else:
        ans = math.factorial(n) * math.factorial(m)
        print(ans%1000000007)



if __name__ == "__main__":
        main()


Measured memory_bytes: 5196
#include <iostream>

using namespace std;

int main(){
  string  s;
  cin >> s;
  int ans=0;
  for(int i=0; i<s.size()/2; i++){
      if(s[i] != s[s.size()-1-i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=2e5+10;

int p,n,m;
char str[N];

namespace Solve1 { //O(n^1.5)
    int bel[N],cnt[N],t[N],d[N],siz;
    ll ans[N],now;
    struct Query{
        int l,r,id;
        bool operator<(const Query&d) const{
            return bel[l]!=bel[d.l]?l<d.l:r<d.r;
        }
    } q[N];
    void add(int x) {
        now-=1ll*cnt[x]*(cnt[x]-1)/2; cnt[x]++;
        now+=1ll*cnt[x]*(cnt[x]-1)/2; 
    }
    void del(int x) {
        now-=1ll*cnt[x]*(cnt[x]-1)/2; cnt[x]--;
        now+=1ll*cnt[x]*(cnt[x]-1)/2; 
    }
    void main() {
        siz=sqrt(n);
        bel[n+1]=n/siz+1;
        int c=1;
        for(int i=n; i; --i,c=1LL*c*10%p) {
            t[i]=(1LL*c*(str[i]-'0')%p+t[i+1])%p;
            d[i]=t[i];
            bel[i]=(i-1)/siz+1;
        }
        sort(d+1,d+n+2);
        c=unique(d+1,d+n+2)-d-1;
        for(int i=1; i<=n+1; ++i) {
            t[i]=lower_bound(d+1,d+c+1,t[i])-d;
        }
        m=1;
        for(int i=1; i<=m; ++i) {
        	q[i].l=1;q[i].r=n;
            q[i].id=i; q[i].r++;
        }
        sort(q+1,q+m+1);
        for(int i=1,l=1,r=0; i<=m; ++i) {
            while(l<q[i].l) del(t[l++]);
            while(q[i].l<l) add(t[--l]);
            while(r<q[i].r) add(t[++r]);
            while(q[i].r<r) del(t[r--]);
            ans[q[i].id]=now;
        }
        for(int i=1; i<=m; ++i) {
            printf("%lld\n",ans[i]);
        }
    }
}
namespace Solve2 { //O(n)
    bool lgl[10];
    ll snum[N],spos[N];
    void main() {
        if(p==2) lgl[0]=lgl[2]=lgl[4]=lgl[6]=lgl[8]=1;
        if(p==5) lgl[0]=lgl[5]=1;
        for(int i=1; i<=n; ++i) {
            snum[i]=snum[i-1]+lgl[str[i]-'0'];
            spos[i]=spos[i-1]+lgl[str[i]-'0']*i;
        }
        m=1;
        for(int l,r; m--; ) {
            l=1;r=n;
            printf("%lld\n",spos[r]-spos[l-1]-(snum[r]-snum[l-1])*(l-1));
        }
    }
}

int main() {
	cin>>n>>p>>str+1;
    if(p==2||p==5) Solve2::main();
    else Solve1::main();
    return 0;
}

Measured memory_bytes: 8576
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

dsum1 = 0
dsum2 = 0
dsum3 = 0
dmax = 0
for i in range(len(x)):
	d = abs(x[i]-y[i])
	dsum1 += d
	dmax = max(dmax, d)
	dsum2 += d**2
	dsum3 += d**3
print('{0:.6f}'.format(dsum1))
print('{0:.6f}'.format(dsum2**(1/2)))
print('{0:.6f}'.format(dsum3**(1/3)))
print('{0:.6f}'.format(dmax))


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


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


	for(int i=1;i <= 3; i++){
		int tmp = i * a * b;
		if(tmp % 2 == 1){
			cout <<  "Yes" << endl;
			exit(0);
		}
	}
	cout <<  "No" << endl;


}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i, n) for(int i = 0; i < (n); ++i)
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.second < secondElof.second;
}

int main() {
    ll n, d, x, y, ans = 0;
    cin >> n >> d;
    rep(t, n) {
        cin >> x >> y;
        if(x * x + y * y <= d * d) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <limits.h>

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

    int ma,mi,maxdis;
    maxdis=(-1)*INT_MAX;
    int r;
    int i;
    for(i=0;i<n;i++) {
        scanf("%d",&r);
        if(!i)mi=r;
        if(i==1)ma=r;
        if(ma<r)ma=r;
        if(i&&maxdis<r-mi) {
            maxdis=r-mi;
        }
        if(mi>r)mi=r;
    }
    printf("%d\n",maxdis);
    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdint>
#include <limits>
using namespace std;

int A,B,C,N;
int ary[8];


int dfs(int i, int a, int b, int c) {
    if (i == N) {
        if (min(a, min(b,c)) > 0) {
            return abs(A-a) + abs(B-b) + abs(C-c) - 30;
        }
        else
        {
            return inf;
        }
    }


    int w = dfs(i+1, a, b, c);
    int x = dfs(i+1, a+ary[i], b, c) + 10;
    int y = dfs(i+1, a, b+ary[i], c) + 10;
    int z = dfs(i+1, a, b, c+ary[i]) + 10;

    return min(w,min(x,min(y,z)));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> A >> B >> C;
    rep(i,N)
    {
        cin >> ary[i];
    }

    cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256