akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    string head;
    string tail;
    bool flip = false;
    REP(q, Q) {
        int type;
        cin >> type;
        if (type == 1) flip = !flip;
        else {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (flip) tail += c;
                else head += c;
            } else {
                if (flip) head += c;
                else tail += c;
            }
        }
    }

    reverse(ALL(head));
    string ans = head + S + tail;
    if (flip) {
        reverse(ALL(ans));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto x:v) cout<<" "<<x; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int gcd(int a,int b){
	if(!a)
		return b;
	return gcd(b%a,a);
}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	ll n;
	cin>>n;
	ll k=n;
	vector<int>a;
	ll sum[1000001];
	sum[0]=0;
	sum[1]=1;
	for(int i=2;i<1000001;i++)
		sum[i]=sum[i-1]+i;
	for(ll i=2;i*i<=n;i++){
		int ct=0;
		while(k%i==0){
			k/=i;
			ct++;
		}
		if(ct){
		a.pb(ct);
		}
	}
	if(k>1)
		a.pb(1);
	ll ans=0;
	for(int i=0;i<(int)a.size();i++){
		auto l=lower_bound(sum,sum+a[i],a[i]);
		if(sum[l-sum]>a[i])
			ans+=(ll)(l-sum)-1;
		else
			ans+=(ll)(l-sum);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11464
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] nCharArray = String.valueOf(n).toCharArray();
        int nSum = 0;
        for(char c: nCharArray){
            int i = Integer.parseInt(String.valueOf(c));
            nSum += i;
        }
        if(n % nSum == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }

    public static int gcd(int a, int b){
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static int lcm(int a, int b){
        return a * b / gcd(a, b);
    }
}


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

int main() {
    string s;
    cin >> s;
    bool flg = true;
    for (int i = 0; i < s.size(); i++) {
        if (flg) {
            if (i%2 == 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) continue;
            else if (i%2 != 0 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) continue;
            else {
                flg = false;
                break;
            }
        }
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > g(n,std::vector<int>());
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	std::vector<std::vector<mint> > dp(n,std::vector<mint>(2,1));
	auto dfs = [&] (auto f, int i, int par) -> void {
		for(int to:g[i]) {
			if(to==par) continue;
			f(f,to,i);
			dp[i][0] *= dp[to][0] + dp[to][1];
			dp[i][1] *= dp[to][0];
		}
	};

	dfs(dfs,0,-1);
	debug(dp);
	print(dp[0][0]+dp[0][1]);

	return 0;
}


Measured memory_bytes: 15488
import sys
from math import ceil
from operator import itemgetter as get

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nod(a, b):
    while b: 
        a, b = b, a % b
    return a
 
def calc(n, c, d):
    return n - n // c - n // d + n // (c * d // nod(c, d))   


def main():
    n = iinput()
    q = rlinput()
    res = [0] * n
    res[0] = sum(q) - 2 * sum(q[1::2])
    for i in range(1, n):
        res[i] = 2 * q[i - 1] - res[i - 1]
    res = map(str, res)
    print(*res)
main() 

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

long long n;

int main(){
	map<long long, long long> odd;
	map<long long, long long> even;
	cin >> n;
	for(long long i = 0; i < n; i++){
		long long v;
		cin >> v;
		if(i%2 == 0){
			even[v]++;
		}else{
			odd[v]++;
		}
	}

	long long odd_max1 = 0;
	long long odd_num1 = 0;
	long long odd_max2 = 0;
	long long odd_num2 = 0;
	long long even_max1 = 0;
	long long even_num1 = 0;
	long long even_max2 = 0;
	long long even_num2 = 0;

	for(auto o: odd){
		if(odd_max1 < o.second){
			odd_max2 = odd_max1;
			odd_num2 = odd_num1;
			odd_max1 = o.second;
			odd_num1 = o.first;
		}else if(odd_max2 < o.second){
			odd_max2 = o.second;;
			odd_num2 = o.first;
		}
	}
	for(auto e: even){
		if(even_max1 < e.second){
			even_max2 = even_max1;
			even_num2 = even_num1;
			even_max1 = e.second;
			even_num1 = e.first;
		}else if(even_max2 < e.second){
			even_max2 = e.second;;
			even_num2 = e.first;
		}
	}

	if(odd_num1 != even_num1){
		cout << n - (odd_max1 + even_max1) << endl;
		return 0;
	} 
	cout << min(n - (odd_max1 + even_max2), n - (odd_max2 + even_max1) ) << endl;

}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, p;
    cin >> a >> p;
    p = p + 3 * a;
    cout << p / 2;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n=s.size();

  int cost=0;
  if(s[0]!=s.back()) cost++;

  if((n+cost)%2==0) cout<<"First"<<endl;
  else cout<<"Second"<<endl;

  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<map>
using namespace std;

int prob[100+ 5];
int  main()
{
	int  n;
	scanf("%d", &n);
	int ans = 0;
	for(int i =1; i<= n; i++)
		{
			scanf("%d", &prob[i]);
			ans += prob[i];
		}
	int m;
	scanf("%d",&m);
	while(m--)
	{
		int k,v;
		scanf("%d %d",&k, &v);
		printf("%d\n",ans - prob[k] + v);
		
		
	}
	
	return 0;
}

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

int main(){
int N,K;
  string S;
  cin>>N;
  for(int i=0; i<N; i++){
   cin>>S[i];}
  cin>>K;

  for(int i=0; i<N; i++){
    if(S[i]!=S[K-1]){S[i]='*';}
  }
  
  for(int i=0; i<N; i++){
    cout<<S[i];}
  }

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

int gcd(int a, int b){
    if(b==0) return a;
    else return gcd(b, a%b);
}

int gcds(vector<int> x){
    int ans = x[0];
    for(int i = 1; i < (int)x.size(); i++)
    {
        ans = gcd(ans, x[i]);
    }
    return ans;
}

int main(){
    int N, X;
    cin >> N >> X;
    int x[N+1];
    x[0]=X;
    for(int i = 1; i < N+1; i++)
    {
        cin >> x[i];
    }
    sort(x, x+N+1);
    vector<int> diff(N);
    for(int i = 0; i < N; i++)
    {
        diff[i]=x[i+1]-x[i];
    }

    int ans=gcds(diff);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(){
    int a, b, c;
    while(cin >> a >> b >> c){
        if(a > b) swap(&a,&b);
        if(b > c) swap(&b,&c);
        if(a > b) swap(&a,&b);
        printf("%d %d %d\n", a, b, c);
    }
}

Measured memory_bytes: 1144
fun main(args: Array<String>) {
    readLine()!!
    val xs = readLine()!!.split(" ").map(String::toInt)
    println(xs.map { div2Count(it, 0) }.min())
}


fun div2Count(n: Int, count: Int): Int {
    return if (n % 2 == 0) div2Count(n / 2, count + 1)
    else return count
}

Measured memory_bytes: 38000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;

int main() {
	int a, b; cin >> a >> b;
	
	if ((a == 1 && b == 2) || (a == 2 && b == 1)) cout << 3 << endl;
	else if ((a == 2 && b == 3) || (a == 3 && b == 2)) cout << 1 << endl;
	else cout << 2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	string S;
	cin >> S;

	for(int i=0; i<S.length(); i++){
		if(i%2==0){//奇数文字
			if(S[i]=='L'){
				cout << "No" << endl;
				return 0;
			}
		}else{
			if(S[i]=='R'){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
	int  n;
  	cin >> n;
  cout << n*n*n << endl;
}

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

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> tiii;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct edge
{
	int s, e, t,c;
	edge(int s, int e, int t,int c) :s(s), e(e), t(t),c(c) {}
	edge():edge(-1,-1,-1,-1){}
	bool operator==(const edge& ed)const
	{
		return s == ed.s&&e == ed.e;
	}
};

int D[10003];
int C[10003];
vector<edge> G[10003];

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

	int N, M, u, v, d, c;
	while (true)
	{
		cin >> N >> M;
		if (N + M == 0)
		{
			break;
		}

		rep(i, 0, N)
		{
			G[i].clear();
		}
		rep(i, 0, M)
		{
			cin >> u >> v >> d >> c;
			G[u - 1].push_back(edge(u - 1, v - 1, d, c));
			G[v - 1].push_back(edge(v - 1, u - 1, d, c));
		}

		rep(i, 0, N)D[i] = INF, C[i] = INF;
		D[0] = 0;
		C[0] = 0;

		priority_queue<pii,vector<pii>,greater<pii>> pq;
		pq.push(mp(0, 0));

		while (!pq.empty())
		{
			pii tp = pq.top(); pq.pop();
			if (tp.first > D[tp.second])
			{
				continue;
			}
			for (auto& e : G[tp.second])
			{
				if (D[e.e] > tp.first + e.t)
				{
					D[e.e] = tp.first + e.t;
					C[e.e] = e.c;
					pq.push(mp(D[e.e], e.e));
				}
				else if (D[e.e] == get<0>(tp) + e.t)
				{
					chmin(C[e.e], e.c);
				}
			}
		}

		int ans = 0;
		rep(i, 1, N)
		{
			ans += C[i];
		}

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    REP(i,999){
        if(N%111==0){
            cout<<N<<endl;
            return 0;
        }else{
            N++;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int n;
  cin >>n;
  int a[n]={0};
  int x;
  for(int i=0; i<n-1; i++){
    cin>>x;
    a[x-1]+=1;
  }
  for(int j=0; j<n; j++){
    cout << a[j] <<endl;
  }
  return 0;
}

Measured memory_bytes: 4380
import java.io.PrintWriter
import java.util.ArrayDeque

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

/** edge info */
data class Edge(val from: Int, val to: Int, val cost: Long)

fun solve(out: PrintWriter) {
    val (n, m) = readIntegerList()

    /** graph[fromNodeIndex]: edges to other node */
    val graph = Array(n) { mutableListOf<Edge>() }
    repeat(m) {
        val (a, b) = readIntegerList().map { it - 1}
        graph[a].add(Edge(a, b, 0))
        graph[b].add(Edge(b, a, 0))
    }

    val fromArray = IntArray(graph.size)
    val isUnchecked = BooleanArray(graph.size) { true }
    val nodeQueue = ArrayDeque<Int>()
    nodeQueue.addLast(0)
    isUnchecked[0] = false
    while (nodeQueue.isNotEmpty()) {
        val node = nodeQueue.removeFirst()
        for (edge in graph[node]) {
            if (isUnchecked[edge.to]) {
                fromArray[edge.to] = node
                isUnchecked[edge.to] = false
                nodeQueue.addLast(edge.to)
            }
        }
    }

    println("Yes")
    println(fromArray.drop(1).map{ it + 1}.joinToString("\n"))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 88792
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
vector<string> m;
void three1(int a,int b){
        m[a][b]='a';
        m[a+1][b]='a';
        m[a+2][b+1]='a';
        m[a+2][b+2]='a';
}
void three2(int a,int b){
        m[a][b]='c';
        m[a+1][b]='c';
        m[a+2][b+1]='d';
        m[a+2][b]='d';
        m[a+2][b+2]='c';
        m[a+1][b+2]='c';
        m[a][b+2]='d';
        m[a][b+1]='d';
}
void four(int a,int b){
        m[a][b]='a';
        m[a+1][b]='a';
        m[a][b+1]='b';
        m[a+1][b+1]='b';
        m[a][b+2]='c';
        m[a][b+3]='c';
        m[a+1][b+2]='d';
        m[a+1][b+3]='d';
        m[a+2][b]='c';
        m[a+2][b+1]='c';
        m[a+3][b]='d';
        m[a+3][b+1]='d';
        m[a+2][b+2]='a';
         m[a+3][b+2]='a';
          m[a+2][b+3]='b';
         m[a+3][b+3]='b';

}
void five(int a,int b){
        m[a][b]='c';
        m[a][b+1]='c';
        m[a][b+2]='d';
        m[a][b+3]='d';
        m[a][b+4]='c';
        m[a+1][b+4]='c';
        m[a+2][b+4]='d';
        m[a+3][b+4]='d';
        m[a+4][b+4]='c';
        m[a+4][b+3]='c';
        m[a+4][b+2]='d';
        m[a+4][b+1]='d';
        m[a+4][b]='c';
        m[a+3][b]='c';
        m[a+2][b]='d';
        m[a+1][b]='d';
        three1(a+1,b+1);

}
     signed main(){
           int n;
           cin>>n;
           if(n==2){
                   cout<<-1;
                   return 0;

           }
           string s(n,'.');
           for(int i=0;i<n;i++)m.push_back(s);
           switch(n){
                   case 7:
                   m[0][1]='a';
                   m[0][2]='a';
                   m[0][3]='b';
                   m[0][4]='b';
                   m[0][5]='a';
                   m[0][6]='a';
                   m[1][0]='b';
                   m[2][0]='b';
                   m[3][0]='a';
                   m[4][0]='a';
                   m[5][0]='b';
                   m[6][0]='b';
                   three2(1,1);
                   three2(4,4);
                   break;
                   case 8:
                   four(0,0);
                   four(4,4);
                   break;
                   case 3:
                   three1(0,0);
                   break;
                   default:
                   int k,g;
                   if(n%3==0){k=n/3;g=0;}
                   else {k=n/3 -1;g=3+n%3;}
                   if(g==4)four(0,0);
                   if(g==5)five(0,0);
                   for(int i=0;i<k;i++){
                           three1(g+3*i,g+3*i);
                           three2(g+3*i,g+3*((i+1)%k));
                           
                   }
                   break;


           }
           for(int i=0;i<n;i++)cout<<m[i]<<endl;
        
}

        


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  char a, b;
  cin >> a >> b;
  if(a>b)cout << ">" << endl;
  else if(a<b)cout << "<" << endl;
  else cout << "=" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <utility>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<"+"<<endl;
        return 0;
    }else if(a*b==15){
        cout<<"*"<<endl;
        return 0;
    }else{
        cout<<"x"<<endl;
        return 0;
    }
}


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

int main()
{
  char c[3][3];

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

  for(int i = 0; i < 3; i++)
    cout << c[i][i];



  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 2010
#define INF 1073741824
using namespace std;
typedef long long ll;
int n;
ll a[MAXN],x,ans;
ll tree[MAXN*4];
ll minv[MAXN][MAXN];
int main(){
	SF("%d%lld",&n,&x);
	for(int i=1;i<=n;i++)
		SF("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		minv[i][i]=a[i];
		for(int j=i+1;j<=n;j++)
			minv[i][j]=min(minv[i][j-1],a[j]);
	}
	ll ans=-1;
	for(int k=0;k<n;k++){
		ll sum=0;
		for(int l=1;l<=k;l++)
			sum+=min(minv[1][l],minv[(l-k+n-1)%n+1][n]);
		for(int l=k+1;l<=n;l++)	
			sum+=minv[l-k][l];
		if(ans==-1)
			ans=sum+x*k;
		else
			ans=min(ans,sum+x*k);
	}
	PF("%lld",ans);
}

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

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

    vector<vector<int>> v(m);
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
      
      	if (a > m)
        {
        	continue;
        }

        v[m - a].push_back(b);
    }
    
    long long ans = 0;

    priority_queue<int> q;
    for (int i = m - 1; i >= 0; i--)
    {
        for (auto &&j : v[i])
        {
            q.push(j);
        }
        
        if (!q.empty())
        {
            ans += (long long)q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>cnt(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        cnt[a-1]++;
        cnt[b-1]++;
    }
    bool ans=true;
    rep(i,n){
        if(cnt[i]!=0){
            if(cnt[i]%2!=0)ans=false;
        }
    }
    cout<<(ans==true? "YES" : "NO")<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define endl "\n"
#define ar array
#define deb(x) cout << #x << " = " << x << endl
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

template <class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
struct comp
{
    bool operator()(const pair<ll, ll> &x, const pair<ll, ll> &y) const
    {
        return x.first < y.first;
    }
};
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwr(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n & 1)
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    else
        return pwr(mul(x, x), n / 2);
}
ll modInv(ll n)
{
    return pwr(n, mod - 2);
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}
unordered_map<ll, ll> m[1000005];
int main()
{
    int t = 1;
    IOS;
    //cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n + 1];
        for (int i = 0; i < n; i++)
            cin >> a[i];
        ll set = 0;
        bool pairwise = true;
        for (int i = 0; i < n; i++)
        {
           // cout << a[i] << endl;
            for (int j = 1; j * j <= a[i]; j++)
            {
                if (a[i] % j == 0)
                {

                    if (j != 1)
                        m[j][i]++;
                    if (i != a[i] / j && a[i] / j != 1)
                        m[a[i] / j][i]++;
                  //  cout << "j " << j << " a[i]/j " << a[i] / j << endl;
                  //  cout << m[j].size() << " " << m[a[i] / j].size() << endl;
                    if (m[j].size() > 1)
                        pairwise = false;
                    if (m[a[i] / j].size() > 1)
                    {
                        pairwise = false;
                      //  cout << "inside " << endl;
                    }
                }
            }
            if (!pairwise)
                break;
        }
        for (int i = 0; i < n; i++)
        {
            set = gcd(set, a[i]);
            if (set == 1)
                break;
        }
        if (pairwise)
            cout << "pairwise coprime" << endl;
        else if (set == 1)
            cout << "setwise coprime" << endl;
        else
            cout << "not coprime" << endl;
    }
}

Measured memory_bytes: 66124
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int n,k;
	int l[100005] = {};

	cin >> n  >> k;

	rep(i,0,n)cin >> l[i];
	rsort(l,l+n,int);
	int s = 0;
	rep(i,0,k)s += l[i];
	P(s);
	return  0;
}

Measured memory_bytes: 640
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))

k = []
for h in H:
    temp = T - h * 0.006
    sa = abs(A - temp)
    k.append(sa)

min_k = min(k)
print(k.index(min_k)+1)

Measured memory_bytes: 3060
import math
x, n = map(int, input().split(' '))
if n == 0:
    input()
    p = []
else:
    p = map(int, input().split(' '))
    p = list(p)

if x not in p:
    print(x)
    exit()

# p.sort()
min_dist = 103
min = 0
for i in range(102):
    if i not in p:
        if min_dist > abs(x-i):
            min_dist = abs(x-i)
            min = i

print(min)

Measured memory_bytes: 62028
n=int(input())
a=list(int(input()) for _ in range(n))

b=sorted(a)
for i in range(n):
    if a[i]==b[n-1]:
        ama=i

for i in range(n):
    if i==ama:
        print(b[n-2])
    else :
        print(b[n-1])

Measured memory_bytes: 14120
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using Pii = pair<int, int>;

int N;
vector<vector<int> > G;
int K;
vector<int> P;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  G.resize(N);
  for ( int i = 0; i < N-1; i++ ) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int INF = 1e9;

  cin >> K;
  P.resize(N, INF);
  int cnt = K;  
  priority_queue<Pii> Q;  
  for ( int i = 0; i < K; i++ ) {
    int v, p;
    cin >> v >> p;
    v--;
    P[v] = p;
    Q.push(Pii(p, v));    
  }

  bool flag = true;
  while ( cnt < N && Q.size() ) {
    Pii q = Q.top(); Q.pop();
    int v = q.second, p = q.first;
    // cout << v << " " << p << endl;    
    for ( int u: G[v] ) {
      if ( P[u] == INF ) {
	P[u] = p-1;
	cnt++;
	Q.push(Pii(P[u], u));	
      } else {
	if ( abs(P[u]-p) != 1 ) {
	  flag = false;
	  break;
	}	
      }
    }
  }

  for ( int i = 0; i < N; i++ ) {
    for ( int j: G[i] ) {
      if ( abs(P[j]-P[i]) != 1 ) {
	flag = false;
	break;
      }
    }
  }

  if ( cnt < N || !flag ) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for ( int i = 0; i < N; i++ ) cout << P[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 9460
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
#include<algorithm>
#define uLL unsigned long long
#define fio ios::sync_with_stdio(false); cin.tie(0);
#define fix fixed << setprecision(2)
int max(int x, int y) {if(x > y) return x; return y;}
int min(int x, int y) {if(x > y) return y; return x;}
using namespace std;
typedef pair<int, int> P;
typedef long long LL;
LL mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 3.1415927;
const int MX = 1e5 + 5;
int Month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isYear(int y) {
  return y % 400 == 0 || (y % 4 == 0 && y % 100);
}
const int N = 1000010;
int gcd(int a, int b, int ans) {
  if(b == 0) return ans;
  return gcd(b, a % b, ans + 1);
} 
int a[100005];
int d[100005];
void init() {
  a[1] = 1;
  for(int i = 2; i <= 100000; ++i) {
    for(int j = i + i; j <= 100000; j += i)
      a[j] = 1;
  }
  a[2] = 0;
  for(int i = 1; i <= 100000; ++i) {
    if(!a[i] && !a[(i + 1) / 2]) {
      d[i] = d[i - 1] + 1;
    } else {
      d[i] = d[i - 1];
    }
  }
}
int main() {
  init();
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << d[r] - d[l - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
char s[5];
int main()
{
   while(~scanf("%s",s))
   {
       int len = strlen(s);
       if(len == 2)
        printf("%s\n",s);
       else
       {
           swap(s[0],s[2]);
           printf("%s\n",s);
       }
   }
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=200005;
 
int state[N];
int dp[5000][1005];
 
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif*/
    
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9) {
        cout<<a*b;
    }
    else {
        cout<<"-1";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    vector<ll> X(N);
    rep(i, N) cin >> X[i];

    ll ans = 0;
    rep(i, N - 1) { ans += min(A * (X[i + 1] - X[i]), B); }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3980
#include<map>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 105
const int mod=998244353;

int n;
char s[maxn];
bitset<100> pps,all;
map<pair<int,string>,int> h;

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int dp(bitset<100> pps,int len){
	if (!len) return 1;
	pair<int,string> pp=make_pair(len,pps.to_string());
	if (h.find(pp)!=h.end()) return h[pp];
	int ret=dp(pps>>1,len-1)*(pps[0]+1); ret>=mod?ret-=mod:0;
    for (int i=1;i<=(len>>1);i++){
		bitset<100> x=pps,y,all; all.reset();
		for (int j=0;j<i;j++) all[j]=1;
		y=x&all,x>>=i;
		for (int j=2;i*j<=len;j++)
			y&=x&all,x>>=i,ret=(ret+1ll*dp(y,i)*dp(x,len-i*j))%mod;
	}
	return h[pp]=ret;
}

int main(){
    scanf("%s",s),n=strlen(s);
	for (int i=0;i<n;i++) pps[i]=s[i]-'0';
	cout<<dp(pps,n)<<endl;
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string S, T;
    cin >> S >> T;
 
    //答えansを仮置きする。
    //これが十分に大きくないと不正解となるので、
    //この値なら絶対に正しい答えが出る、という値を仮置きすること
    int ans = T.size();
 
    //Sの何文字目から調べるかを全探索する
    for (int start = 0; start <= S.size() - T.size(); start++)
    {
        int diff = 0;
        for (int i = 0; i < T.size(); i++)
        {
            if (T[i] != S[start + i]) {
                diff++;
            }
        }
        ans = min(ans, diff);
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

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

	vector<ll> A(N);

	for (int i = 0; i < N; i++)cin >> A[i];
	
	auto FindZero = find(A.begin(), A.end(), 0);
	if (FindZero != A.end()) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] <= 1000000000000000000 / ans) {
			ans *= A[i];
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 4028
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N=100005;

int n,T,l,s,t,r,mid;
int f[N][18],x[N];

void init(){
	int i,j;
	for (i=1;i<=n;i++)
		for (j=0;j<=17;j++) f[i][j]=n;
	for (i=1;i<n;i++) f[i][0]=lower_bound(x+1,x+1+n,x[i]+l+1)-x-1;
	for (j=1;j<=17;j++)
		for (i=1;i<=n;i++) f[i][j]=f[f[i][j-1]][j-1];
}

int go(int st,int d){
	int i;
	for (i=17;i>=0;i--)
		if (d>=(1<<i)){
			st=f[st][i];
			d-=(1<<i);
		}
	return st;
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&x[i]);
	scanf("%d",&l);
	init();
	scanf("%d",&T);
	while (T--){
		scanf("%d%d",&s,&t); if (s>t) swap(s,t);
		l=1; r=n;
		while (l<r){
			mid=l+(r-l)/2;
			if (go(s,mid)>=t) r=mid;
			else l=mid+1;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 8192
N = int(input())

if N <= 111:
    print(111)
elif N <= 222:
    print(222)
elif N <= 333:
    print(333)
elif N <= 444:
    print(444)
elif N <= 555:
    print(555)
elif N <= 666:
    print(666)
elif N <= 777:
    print(777)
elif N <= 888:
    print(888)
elif N <= 999:
    print(999)



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

using namespace std;


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

    long long n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    long long ans=0;
    if(p==2){
        long long cnt=0;
        for(int i=0;i<n;i++){
            int cur=s[i]-'0';
            cnt++;
            if(cur%2==0){
                ans+=cnt;
            }
        }
    } else if(p==5){
        long long cnt=0;
        for(int i=0;i<n;i++){
            int cur=s[i]-'0';
            cnt++;
            if(cur%5==0){
                ans+=cnt;
            }
        }
    } else {
        map<long long,long long>mp;
        mp[0]++;
        long long prev=1,now=0;
        for(int i=n-1;i>=0;i--){
            long long cur=s[i]-'0';
            now=(now+(cur*prev))%p;
            ans+=mp[now];
            mp[now]++;
            prev=(prev*10)%p;
        }
    }
    cout<<ans<<endl;

    return 0;
}






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

class Kake:
    def __init__(self, n):
        self.n = n

    def div(self):
        div_dict = {}
        
        for i in range(1, int(self.n**0.5)+1):
            if self.n % i == 0 and i <= (self.n/i):
                div_dict[i] = int(self.n / i)     
    
        sa_list = list()
        for i in div_dict:
            sa_list.append((i-1)+(div_dict[i]-1))
        print(min(sa_list))
         
kake = Kake(n)
kake.div()


Measured memory_bytes: 3584
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
total = sum(A)
mi = float('inf')
left = 0
for i in range(n):
    left += A[i]
    total -=A[i]
    mi = min(mi, abs(left - total))
print(mi)


Measured memory_bytes: 32780
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>


using namespace std;

using ll = long long;





int main()
{
	int N;

	cin >> N;

	for (int i = 0; i < N; ++i)
	{
		ll A, B;

		cin >> A >> B;

		ll base = sqrt(A*B);

		ll ans = 0;

		ans += base * 2;

		if (base*base == A*B) { ans--; }

		if (A == B) { ans--; }
		else
		{
			ans--;
			
			ll min = A < B ? A : B;// 4
			ll max = A > B ? A : B;// 11

			ll q = (A*B % (B + 1) == 0) ? (A*B / (B + 1) - 1) : (A*B / (B + 1));// 5のときの８

			if (q == max-1) { ans--; }

			ll p = (A*B % base == 0) ? (A*B / base - 1) : (A*B / base);

			if (p - 1 < base) {
				--ans;
			}
			
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(false);

    string s;
    size_t K;

    cin >> s >> K;

    auto N = s.size();

    vector<string> subs;

    for (size_t a = 0; a < N; ++a)
        for (size_t b = a; b < N; ++b)
        {
            auto sub = s.substr(a, b - a + 1);

            bool found = false;

            for (const auto& x : subs)
                if (x == sub)
                {
                    found = true;
                    break;
                }

            if (found)
                continue;

            if (subs.size() < K)
            {
                subs.push_back(sub);
                sort(subs.begin(), subs.end());

            } else
            {
                if (sub >= subs.back())
                    continue;

                subs[K - 1] = sub;
                sort(subs.begin(), subs.end());
            }
        }

    cout << subs[K - 1] << endl;

    return 0;
}


Measured memory_bytes: 384
/* D-"Median of Medians" */
/*  */
//include <bits/stdc++.h>
#include <iostream>
#include <deque>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++) 
using namespace std;

int main(){
    int m,n,a[10000];
    double pile=0;
    cin >> n >> m;
    rep(i,n){
        cin >> a[i];
        pile += a[i];
    }
    pile /= 4*m;
    int cnt =0 ;
    rep(j,n){
        if(a[j] >= pile) cnt++;
    }
    if(m <= cnt) cout << "Yes";
    else cout << "No";

    return 0;
}
    

Measured memory_bytes: 256
S=list(input())
s=len(S)
T=list(input())
t=len(T)
for i in range(s-t+1):
  a=0
  for j in range(t):
    if S[-1-i-j]=="?":
      continue
    if S[-1-i-j]!=T[-1-j]:
      a=1
  if a==0:
    for j in range(s):
      if S[j]=="?":
        S[j]="a"
    S[s-t-i:s-i]=T
    for j in range(s):
      print(S[j],end="")
    print()
    exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
import collections as cc
I=lambda:list(map(int,input().split()))
mod=10**9+7
n,m=I()
ds=[i for i in range(n+1)]
r=[1]*(n+1)
def find(a):
    while ds[a]!=a:
        a=ds[a]
    return a
def join(a,b):
    x=find(a)
    y=find(b)
    if x!=y:
        ds[x]=ds[y]=min(x,y)
        r[min(x,y)]+=r[max(x,y)]
for i in range(m):
    x,y=I()
    join(x,y)
temp=cc.Counter(ds[1:])
print(max(r))

Measured memory_bytes: 115876
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
    ll N,A,B,C,D; cin >> N >> A >> B >> C >> D;

    map<ll, ll> dist;
    dist.emplace(1,1e18);
    dist.emplace(N,0);
    if (N==1) {
        cout << D << ln;
        return;
    }
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.emplace(0,N);
    while (!pq.empty()) {
        auto[d,v] = pq.top(); pq.pop();
        if (d > dist[v]) continue;
        if (v <= 2e18/D) chmin(dist[1],dist[v]+D*(v-1));
        for (ll i = max(1LL,v-5); i <= v+5; i++) {
            ll cost = d + D*abs(i-v);
                if (i%2==0) {
                    if (!dist.count(i/2)) dist[i/2] = 1e18;
                    if (chmin(dist[i/2],cost+A)) {
                        pq.emplace(dist[i/2],i/2);
                    }
                }
                if (i%3==0) {
                    if (!dist.count(i/3)) dist[i/3] = 1e18;
                    if (chmin(dist[i/3],cost+B)) {
                        pq.emplace(dist[i/3],i/3);
                    }
                }
                if (i%5==0) {
                    if (!dist.count(i/5)) dist[i/5] = 1e18;
                    if (chmin(dist[i/5],cost+C)) {
                        pq.emplace(dist[i/5],i/5);
                    }
                }
        }
    }

    cout << dist[1]+D << ln;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //ifstream in("test.txt");
    //cin.rdbuf(in.rdbuf());
    //clock_t start = clock();
    int Q; cin >> Q;
    while (Q--) {
        solve();
    }

    //ここから切り離して末尾へ
    //clock_t end = clock();
    //const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    //cout << "time: " << time << "[ms]" << ln;
    //ここまで切り離して末尾へ
}


Measured memory_bytes: 7408
#include<stdio.h>
main(){
  int n,i;
  while(scanf("%d",&n)!=EOF){
    printf("3C");
    i=n%39;
    if(i==0){
      i=39;
    }
    else if(i<=9){
      printf("0");
    }
    printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 600