akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000
#define MOD 1000000007

int main(){
  string S;
  cin>>S;
  if(S.at(0)=='7'||S.at(1)=='7'||S.at(2)=='7'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3596
from collections import defaultdict
dic = defaultdict(int)
N = int(input())
a = list(map(int,input().split()))
t = 0
for i in range(N):
    t ^= a[i]
    dic[a[i]] += 1

if t != 0:
    print("No")
else:
    if N % 3 == 0:
        if len(dic.keys()) > 3:
            print("No")
        elif len(dic.keys()) == 3:
            print("Yes" if all([N//3 == x for x in dic.values()]) else "No")
        elif len(dic.keys()) == 2:
            k,l = dic.keys()
            if dic[k] == dic[l]*2:
                print("Yes" if l == 0 else "No")
            elif dic[k]*2 == dic[l]:
                print("Yes" if k == 0 else "No")
            else:
                print("No")
        else:
            print("Yes" if all([0 == x for x in a]) else "No")
    else:
        print("Yes" if all([0 == x for x in a]) else "No")

Measured memory_bytes: 14460
#include<bits/stdc++.h>
namespace ZDY{
#define fir freopen("2.in","r",stdin)
#define ll long long
#define Fur(i,x,y) for(int i=x;i<=y;i++)
#define fur(i,x,y) for(i=x;i<=y;i++)
#define Fdr(i,x,y) for(int i=x;i>=y;i--)
#define in2(x,y) in(x),in(y)
#define in3(x,y,z) in2(x,y),in(z)
#define in4(a,b,c,d) in2(a,b);in2(c,d)
#define clr(x,y) memset(x,y,sizeof(x))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define fl(i,x) for(ll i=head[x],to;to=e[i].to,i;i=e[i].next)
#define inf 2147483647
}
namespace FAST{
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
#define gc ((*fib::f)?(*(fib ::f++)):(fgets(fib::b,sizeof(fib::b),stdin)?(fib::f=fib::b,*(fib::f++)):-1))
namespace fib{char b[300000]= {},*f=b;}
inline void in(ll &x){x=0;char c;bool f=0;while((c=gc)>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=gc)<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}
inline void in(int &x){x=0;char c;bool f=0;while((c=gc)>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=gc)<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}
namespace fob{char b[300000]= {},*f=b,*g=b+300000-2;}struct foce{~foce(){pob;fflush(stdout);}} _foce;namespace ib{char b[100];}
inline void out(ll x){if(x==0){pc(48);return;}if(x<0){pc('-');x=-x;}char *s=ib::b;while(x) *(++s)=x%10,x/=10;while(s!=ib::b) pc((*(s--))+48);}inline void outn(ll x){out(x);pc('\n');}
inline void out(int x){if(x==0){pc(48);return;}if(x<0){pc('-');x=-x;}char *s=ib::b;while(x) *(++s)=x%10,x/=10;while(s!=ib::b) pc((*(s--))+48);}inline void outn(int x){out(x);pc('\n');}
inline char sc(){char c=gc;while(!(('A'<=c&&c<='Z')||('a'<=c&&c<='z')||('0'<=c<='9')))c=gc;return c;}
inline ll jdz(ll x){return x>0?x:-x;}
inline ll max(ll x,ll y){return x>y?x:y;}
}using namespace FAST;using namespace ZDY;using namespace std;
#define N 111
int n,x,ans=0;
int main(){
	in(n);
	Fur(i,1,n)in(x),ans+=x-1;
	outn(ans);
}

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

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

	int A, B;
	cin >> A >> B;

	int x = 0;
	while( x * (A-1) + 1 < B ) {
		x += 1;
	}

	cout << x << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000 || n == 1000000) {
            System.out.println(10);
        } else {
            int res = 0;
            while ( n > 0) {
                res += n%10;
                n/=10;
            }
            System.out.println(res);
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli N, K;
lli a[5000 + 10];

lli dp[5000 + 10][5000 + 10];

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	//ここそのためにソートしているのか
	//＜の関係にしている
	sort(a, a + N);

	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < K; j++) {
			dp[i + 1][j] += dp[i][j];
			if (j + a[i] < K) {
				dp[i + 1][j + a[i]] += dp[i][j];
			}
		}
	}

	int ans = N;
	for (int i = 0; i < N; i++) {

		lli dplast[5000 + 10] = {};
		for (int j = 0; j < K; j++)dplast[j] = dp[N][j];
		for (int j = 0; j < K; j++) {
			//dpを一回さし戻す
			if (j + a[i] < K)dplast[j + a[i]] -= dplast[j];
			//ここが-にならないのはなんで
			if (j >= K - a[i] && dplast[j]) {
				ans--;
				break;
			}
		}
	}

	COUT(ans);
	return 0;
}

Measured memory_bytes: 196096
#include<stdio.h>
int main()
{
	int a,b,c,x,cnt=0,i,j,k;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&x);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)
				cnt++;
			}
		}
	 } 
	 printf("%d",cnt);
	return 0;
 } 

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

int main(){
    int i, m, h;
    string s;
    while (1){
        cin >> s;
        if (s == "-") break;
        cin >> m;
        for (i = 0; i < m; i++){
            cin >> h;
            s = s.substr(h, s.size()-h) + s.substr(0, h);
       }
       cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    string S;
    is >> S;
    if(!is) return;
    vector<int> count(S.size());
    int p, q;
    int i = 0;
    while(i < S.size()){
        if(S[i] == 'L'){
            p = i;
            q = i-1;
            bool par = true;
            while(i < S.size() and S[i] == 'L'){
                if(par) count[p]++;
                else count[q]++;
                par = !par;
                i++;
            }
        }
        else{
            p = q = 0;
            bool par = true;
            while(i < S.size() and S[i] == 'R'){
                if(par) p++;
                else q++;
                par = !par;
                i++;
            }
            count[i-!par] += p;
            count[i-par] += q;
        }
    } // end i

    for (auto &&s : count) {
        cout << s << ' ';
    } // end s
    cout << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_D.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 1104
S=input()
nsflag=False
weflag=False
if(("N" in S and "S" in S)or("N" not in S and "S" not in S)):
  if(("W" in S and "E" in S)or("W" not in S and "E" not in S)):
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
int n;
  cin >> n;
  vector<int>a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
    }
  sort(b.begin(),b.end());
  map<int,int>ma;
  int mid = b.at(n/2);
  int midl=b.at(n/2-1);
  for(int i=n/2;i<n;i++){
    int d = b.at(i);
    if(!ma.count(d)){
      ma[d]=1;
      }
    }
  for(int i=0;i<n;i++){
    int d = a.at(i);
    if(ma.count(d)){
      cout << midl<<endl;
      continue;
      }
       cout<< mid<< endl;
    }
  
}



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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

int n;

int main()
{
	cin >> n;
	double sum = 0;
	FOR( i, 0, n )
	{
		double x;cin >> x;
		sum += ( 1 / x );
	}
	printf( "%.10lf\n", 1 / sum );
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }

// これとか
// https://ja.wolframalpha.com/input/?i=%E2%88%91%5Bj%3Dc_1%E2%86%92c_2%5Dcomb%28r%2Bj%2Cr%29

const ll MOD = 1000000007;
struct Modint{
    ll num = 0;
    Modint(){}
    Modint(ll x){ x %= MOD; if(x < 0) x += MOD; num = x; }
    operator ll(){ return num; }
    Modint& operator+=(Modint x){ num += x.num; if(num >= MOD) num -= MOD; return *this; }
    Modint& operator-=(Modint x){ if(num < x.num) num += MOD; num -= x.num; return *this; }
    Modint& operator*=(Modint x){ num = num * x.num % MOD; return *this; }
    Modint& operator/=(Modint x){ return *this *= x.inv(); }
    Modint operator+ (Modint x) const { return Modint(*this) += x; }
    Modint operator- (Modint x) const { return Modint(*this) -= x; }
    Modint operator* (Modint x) const { return Modint(*this) *= x; }
    Modint operator/ (Modint x) const { return Modint(*this) /= x; }
    Modint inv(){
        return pow(MOD - 2); // MOD - 2 乗で逆元を取る
    }
    Modint pow(ll x){
        Modint ans = 1, cnt = *this;
        while(x){
            if(x & 1) ans *= cnt;
            cnt *= cnt;
            x /= 2;
        }
        return ans;
    }
};
Modint operator""_M(unsigned long long x) { return Modint(x); }

const ll MAX = 2020202;
vector<Modint> fac(MAX), inv(MAX);
void init(){
    fac[0] = 1;
    for(ll i = 1; i < MAX; i++) fac[i] = fac[i - 1] * Modint(i);
    inv.back() = fac.back().inv();
    for(ll i = MAX - 1; i > 0; i--) inv[i - 1] = inv[i] * Modint(i);
}

Modint comb(ll n, ll r){
    return fac[n] * inv[r] * inv[n - r];
}

// これを使う
// https://ja.wolframalpha.com/input/?i=%E2%88%91%5Bi%3D0%E2%86%92a%5D%E2%88%91%5Bj%3D0%E2%86%92b%5Dcomb%28i%2Bj%2Ci%29
Modint sum(Modint r, Modint c){
    return ((r + 2_M) * comb(c + r + 2_M, r + 2_M) - c - 1_M) / Modint(c + 1_M);
}

int main(){
    init();
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--; c1--;
    // 2次元累積和
    cout << sum(r2, c2) + sum(r1, c1) - sum(r1, c2) - sum(r2, c1) << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,ll>pa;

const int N=2e5+100;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;


int main()
{
    int n;cin>>n;
    if(n>=30) puts("Yes");
    else puts("No");

}


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

int main()
{
    int h, w;
    while (true)
    {
        cin >> h >> w;
        if (h == 0 && w == 0)
        {
            return 0;
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if ((i + j) % 2 == 0)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


class Dice {
public:
	int top, front, r;
	Dice() :top(1), front(2), r(3) {}
	Dice(int a, int b,int c) :top(a), front(b), r(c) {}
	void north() {
		int a = top;
		top = front;
		front = 7 - a;
	}
	void east() {
		int a = top;
		top = 7 - r;
		r = a;
	}
	void west() {
		int a = top;
		top = r;
		r = 7 - a;
	}
	void south() {
		int a = top;
		top = 7 - front;
		front = a;
	}
	void right() {
		int a = front;
		front = r;
		r = 7 - a;
	}
	void left() {
		int a = front;
		front = 7 - r;
		r = a;
	}
};


char f[100][100];

bool vis[100][100][6][6][6];


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

	int h, w;
	cin >> h >> w;
	rep(i, h)rep(j, w)cin >> f[i][j];

	queue<tuple<int, int, int, int, int>> q;
	vis[0][0][5][1][2] = true;
	q.emplace(0, 0, 5, 1, 2);

	string ans = "NO";

	while (!q.empty()) {
		auto t = q.front();
		q.pop();

		int y, x, soko, fr, ri;
		tie(y, x, soko, fr, ri) = t;
		Dice dice(7 - (soko + 1), fr + 1, ri + 1);

		if (y==h-1 && x==w-1) {
			ans = "YES";
			break;
		}

		if (0 < y) {
			Dice d = dice;
			d.north();
			if (f[y - 1][x] - '0' == 7 - d.top && !vis[y - 1][x][7 - d.top - 1][d.front - 1][d.r - 1]) {
				vis[y - 1][x][7 - d.top - 1][d.front - 1][d.r - 1] = true;
				q.emplace(y - 1, x, 7 - d.top - 1, d.front - 1, d.r - 1);
			}
		}
		if (y + 1< h) {
			Dice d = dice;
			d.south();
			if (f[y + 1][x] - '0' == 7 - d.top && !vis[y + 1][x][7 - d.top - 1][d.front - 1][d.r - 1]) {
				vis[y + 1][x][7 - d.top - 1][d.front - 1][d.r - 1] = true;
				q.emplace(y + 1, x, 7 - d.top - 1, d.front - 1, d.r - 1);
			}
		}
		if (0 < x) {
			Dice d = dice;
			d.west();
			if (f[y][x - 1] - '0' == 7 - d.top && !vis[y][x - 1][7 - d.top - 1][d.front - 1][d.r - 1]) {
				vis[y][x - 1][7 - d.top - 1][d.front - 1][d.r - 1] = true;
				q.emplace(y, x - 1, 7 - d.top - 1, d.front - 1, d.r - 1);
			}
		}
		if (x + 1 < w) {
			Dice d = dice;
			d.east();
			if (f[y][x + 1] - '0' == 7 - d.top && !vis[y][x + 1][7 - d.top - 1][d.front - 1][d.r - 1]) {
				vis[y][x + 1][7 - d.top - 1][d.front - 1][d.r - 1] = true;
				q.emplace(y, x + 1, 7 - d.top - 1, d.front - 1, d.r - 1);
			}
		}
	}

	cout << ans << endl;


	return 0;
}


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

int main(){
        char s[10];
        scanf("%s", s);
        sort(s, s+4);
        // printf("%s", s);
        printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3])? "Yes\n" : "No\n");
};

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


using namespace std;

int main(){
    int N, tmp;
    vector<int> A;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        A.push_back(tmp);
    }
    int before = 0;
    int ans = 0;
    for(int i = 0; i < N ; i++){
        if(i == 0){
            before = A[0];
            continue;
        }
        if(before == A[i]){
            before = 0;
            ans++;
            continue;
        }
        before = A[i];
    }
    
    cout << ans << endl;

    return 0;
}

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

int T[100000];

int cmpfunc (const void * a, const void * b){
  return *(int*)a - *(int*)b;
}

int main(){
  int i, j;
  int n, c, k, l;
  int min, ans;
  scanf("%d%d%d", &n, &c, &k);

  min = (1<<31)-1;
  for(i=0;i<n;i++){
    scanf("%d", T+i);
  }
  qsort(T, n, sizeof(int), cmpfunc);

  min=T[0];
  l=0;
  ans=1;
  for(i=1;i<n;i++){
    if(T[i]<=min+k && i<l+c){
    }
    else {
      min=T[i];
      l=i;
      ans++;
    }
  }

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


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	double m, a=0, n, sum=0;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<double>s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		for (int i = 0; i < n; i++) {
			sum += s[i];
		}
		m = sum / n;
		for (int i = 0; i < n; i++) {
			a += pow(s[i] - m, 2);
		}
		a = a / n;
		a = pow(a, 0.5);
		printf("%.10lf\n",a);
		a = 0;
		m = 0;
		sum = 0;
	}
}

Measured memory_bytes: 1296
N, K = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
S = [0] * (N+1)
T = [0] * (N-K+1)
for i in range(N):
    S[i+1] = S[i] + P[i]
for i in range(N-K+1):
    T[i] = S[i+K] - S[i]
print(max(T)/2 + K/2)


Measured memory_bytes: 71792
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())
S = input()


# In[2]:


l = 0
r = 0
for s in S:
    if s == "(":
        r += 1
    else:
        if r > 0:
            r -= 1
        else:
            l += 1
ans = "".join(["("*l , S, ")"*r])
print(ans)


# In[ ]:






Measured memory_bytes: 9008
from collections import deque

n = int(input())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
    input_list = list(map(int, input().split()))
    index = input_list[0]
    num = input_list[1]

    if num >= 1:
        nodes = input_list[2:]
        for node in nodes:
            graph[index].append(node)
            # graph[node].append(index)

visited = [-1] * (n + 1)
num = [-1] * (n + 1)
q = deque()
visited[1] = 1
num[1] = 0
q.append(1)

while q:
    index = q.popleft()
    
    for node in graph[index]:
        if visited[node] == -1:
            visited[node] = 1
            num[node] = num[index] + 1
            q.append(node)


for i, j in enumerate(num):
    if i == 0:
        continue
    print(i, j)





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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N,L; cin >> N >> L;

    if(L+N-1 < 0){
        ll ans = 0;
        for (int i = 0;i < N-1;i++){
            ans += L+i;
        }
        cout << ans << endl;
    }else if(L >= 0){
        ll ans = 0;
        for (int i = 1;i < N;i++){
            ans += L+i;
        }
        cout << ans << endl;
    }else{
        ll ans = 0;
        for (int i = 0;i < N;i++){
            ans += L+i;
        }
        cout << ans << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;


int main(void) {
	string s;
	ll q, t, f;
	char c;
	cin >> s >> q;
	deque<char> que;
	for (int i = 0; i < s.length(); i++) que.push_back(s[i]);
	bool is_reverse = false;
	for (int i = 0; i < q; i++)
	{
		cin >> t;
		if (t == 1)
		{
			is_reverse = !is_reverse;
		}
		else
		{
			cin >> f >> c;
			if (f == 1 && is_reverse == false || f == 2 && is_reverse == true)
			{				
				que.push_front(c);
			}
			else
			{
				que.push_back(c);
			}
		}
	}
	s = "";
	for (int i = 0; i < que.size(); i++) s += que[i];
	if (is_reverse) reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;
}

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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define MOD 998244353

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli a,lli b) {
  lli ans = 1;
  while(b > 0) {
    if(b&1)
      ans = mul(ans, a);
    a = mul(a,a);;
    b >>= 1;
  }
  return ans;
}

lli dp[3001][3001];

void solve() {
  lli n, sum;
  cin >> n >> sum;
  vector<lli> arr;
  input(arr, n);
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for(lli i=1; i<=n; i++) {
    dp[i][0] = mul(2, dp[i-1][0]);
  }

  for(lli s=1; s<=sum; s++) {
    for(lli i=1; i<=n; i++) {
      if(arr[i-1]<=s) {
        dp[i][s] = (dp[i-1][s-arr[i-1]]%MOD + mul(dp[i-1][s], 2)%MOD)%MOD;
      } else {
        dp[i][s] = mul(dp[i-1][s], 2);
      }
    }
  }

  cout << dp[n][sum] << endl;
}

int main() {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



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

ll n,a,b,x[100005],rez;

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

    cin>>n>>a>>b;
    for(ll i=1;i<=n;i++)
        cin>>x[i];
    for(ll i=2;i<=n;i++)
        if((x[i]-x[i-1])*a>b)
            rez+=b;
        else
            rez+=(x[i]-x[i-1])*a;

    cout<<rez<<endl;

    return 0;
}


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

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

P Q[LEN];
int head, tail, n;

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

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) { return a < b ? a : b; }

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

	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n + 1;

	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if (u.t > 0) enqueue(u);
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}

	return 0;
}


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

int main() {
	cout << fixed << setprecision(15);

	char HW[6][7];
	int H, W, K;
	cin >> H >> W >> K;
	rep (i, H) {
		cin >> HW[i];
	}

	int ans = 0;

	int maxH = powl(2, H);
	int maxW = powl(2, W);
	rep (h, maxH) {
		rep (w, maxW) {
			int cnt = 0;
			rep (i, H) {
				rep (j, W) {
					if (!(h&(1<<i)) && !(w&(1<<j)) && (HW[i][j]=='#')) ++cnt;
				}
			}
			if (cnt == K) ++ans;
		}
	}

	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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; }



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;


int main() {
	
	int a,b;
	
	cin >> a>>b ;
	int ans = a - 2 * b;
	if (ans < 0)cout << 0 << endl;
	else cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int temp;
        int kis=0;
        for(int i = 0;i<N;i++)
        {
            temp = sc.nextInt();
            temp = temp%2;
            if(temp != 0)
            {
                kis++;
            }
        }
        kis = kis%2;
        if(kis!=0)
        {
            System.out.println("NO");
        }
        else
        {
            System.out.println("YES");
        }
    }
}

Measured memory_bytes: 33204
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := readInt(), readInt()

	ac := make(map[int]bool, n)
	wa := make(map[int]int, n)
	waTotal := 0
	for i := 0; i < m; i++ {
		p, s := readInt(), readString()

		if !ac[p] && s == "AC" {
			ac[p] = true
			waTotal += wa[p]
		} else if !ac[p] && s == "WA" {
			wa[p]++
		}
	}
	fmt.Println(len(ac), waTotal)
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	int N, Q;
	while(cin >> N >> Q, N){
		vector< pair<string, pair<int, int> > > vp;
		string str; int Y, W; 
		for(int i=0;i<N;i++){
			cin >> str >> Y >> W;
			vp.push_back(make_pair(str, make_pair(W-Y, Y)));
		}
		for(int i=0;i<Q;i++){
			string ans = "Unknown";
			cin >> W;
			for(int j=0;j<N;j++){
				if(0 < W-vp[j].second.first && W-vp[j].second.first <= vp[j].second.second){
					ans = vp[j].first;
					Y = W-vp[j].second.first;
				}
			}
			if(ans != "Unknown") cout << ans << " " << Y << endl; 
			else                 cout << ans << endl;
		}
	}
}

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

typedef struct page{
  string name;
  int b;
  int x1[100],y1[100],x2[100],y2[100];
  string link[100];
}page;

int main(){
  int n,m;
  int w,h;
  page p[100];
  string inst;
  int x,y;
  vector<int> buf;
  int pos,next;

  while(1){
    cin >> n;
    if(!n)break;
    cin >> w >> h;

    for(int i=0;i<n;i++){
      cin >> p[i].name >> p[i].b;
      for(int j=0;j<p[i].b;j++){
	cin >> p[i].x1[j] >> p[i].y1[j];
	cin >> p[i].x2[j] >> p[i].y2[j];
	cin >> p[i].link[j];
      }
    }

    buf.clear();
    buf.push_back(0);
    pos = 0;

    cin >> m;
    for(int i=0;i<m;i++){
      cin >> inst;
      if(inst == "show")cout << p[buf[pos]].name << endl;
      else if(inst == "back"){
	if(pos)pos--;
      }else if(inst == "forward"){
	if(pos!=buf.size()-1)pos++;
      }else{
	cin >> x >> y;
	next = -1;
	for(int j=0;j<p[buf[pos]].b;j++){
	  if(p[buf[pos]].x1[j] <= x && x <= p[buf[pos]].x2[j]){
     	    if(p[buf[pos]].y1[j] <= y && y <= p[buf[pos]].y2[j]){
	      for(int k=0;k<n;k++){
		if(p[buf[pos]].link[j] == p[k].name){
		  next = k;
		  break;
		}
	      }
	      break;
	    }
	  }
	}
	if(next >= 0){
	  pos++;
	  while(pos < buf.size())buf.pop_back();
	  buf.push_back(next);
	}
      }
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int cnt[600][600];
int main(){
   int n,m,q;
   cin>>n>>m>>q;
    int l,r;
   rep(i,m){
       scanf("%d%d",&l,&r);
       ++cnt[l][r];
   }
   rep(i,n+1)rep(j,n)cnt[i][j+1]+=cnt[i][j];
   rep(i,n)rep(j,n+1)cnt[i+1][j]+=cnt[i][j];
   rep(i,q){
       scanf("%d%d",&l,&r);
       printf("%d\n",cnt[r][r]-cnt[l-1][r]);
   }
   return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
//ranker
using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main()
{
    string str;

    cin >> str;
    reverse( str.begin() , str.end() );
    cout << str << endl;

    return 0;
}

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

int main(){

    int n,i = 0;
    cin >> n;
    vector<int> num(1000);
    while(n / 3 != 0){
        num[i] = n % 3;
        n /= 3;
        i++;
    }
    num[i] = n;
    int m = 0;
    for(int j = 0;j < i+1 ;j++){
        if(num[j] >= 2){
            num[j] -= 3;
            num[j+1]++;
        }
        m = j+1;
    }
    
    if(num[m] == 0){
           ;
    }
    if(num[m] == 1){
        cout << '+';
    }
    if(num[m] == -1){
        cout << '-';
    }
    for(int j = i ; j >= 0;j--){
        
        if(num[j] == 1){
            cout << '+';
        }
        if(num[j] == 0){
            cout << '0';
        }
        if(num[j] == -1){
            cout << '-';
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3072
//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define qi queue<int>
#define si stack<int>
#define s string
#define ll long long;

int main()
{
    sws;
    int a, b;
    cin >> a >> b;
    s ans = (a > 8 || b > 8) ? ":(" : "Yay!";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 300002
using namespace std;
vector <int> vec[N];
int dd[N],bit[N],sl[N],k,x,i,kq[N],n,m,l,r,cnt,ma[N];
void update(int i,int k)
{
    dd[i]+=k;
    while(i<=m) { bit[i]+=k; i+=(i & -i); }
}
int get(int l,int r)
{
    int i=r,kq=0;
    while(i>=l)
        if(i-(i & -i)>=l) { kq+=bit[i]; i-=(i & -i); }
        else { kq+=dd[i]; i--; }
    return kq;
}
int main()
{
    //freopen("ntu.inp","r",stdin);
    //freopen("ntu.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>l>>r;
        vec[r].push_back(l); sl[l]++;
    }
    for(x=1;x<=m;x++)
    {
        cnt+=sl[x];
        update(x,sl[x]);
        for(k=1;k*k<=x;k++)
            if(x%k==0)
            {
                kq[k]+=cnt-get(1,ma[k]);
                ma[k]=x;
                if(k!=x/k)
                {
                    kq[x/k]+=cnt-get(1,ma[x/k]);
                    ma[x/k]=x;
                }
            }
        cnt-=vec[x].size();
        for(i=0;i<vec[x].size();i++)
        {
            k=vec[x][i];
            update(k,-1);
        }
    }
    for(i=1;i<=m;i++) cout<<kq[i]<<'\n';
}


Measured memory_bytes: 15744
n,m,k = map(int,input().split())
dp = []
dp.append([[0] * m,0])
for i in range(n):
    next = []
    lis = list(map(int,input().split()))
    cost = lis[0]
    lis = lis[1:]
    for li,cos in dp:
        next.append([li,cos])
        co = [0] * m
  #         print(len(co),len(li),len(lis))
        for j in range(m):
            co[j] = li[j] + lis[j]
        next.append([co,cos+cost])
    dp = next
  #     print(dp)
ans = 10 ** 100
  # print(dp)
for li,cos in dp:
    if min(li) >= k:
        ans = min(ans,cos)
if ans == 10 ** 100:
    print(-1)
    exit()
print(ans)

Measured memory_bytes: 11908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * 
 */

/**
 * @author imkat
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	throws IOException{
		// TODO Auto-generated method stub
		ArrayList<String> al = (new StandardIn()).getlines(2);
		String p,s;
		p = al.get(0);
		s = al.get(1);
		
		System.out.println((compareLikeRing(p,s)?"Yes":"No"));
		
	}
	
	static boolean compareLikeRing(String p, String s){
		boolean flag = false;
		for (int i=0; i<p.length();i++){
			boolean check = (0==s.compareTo(substringLikeRing(p,i,s.length())));
			flag = (check||flag);
		}
		return flag;
	}

	static String substringLikeRing(String p, int pos, int length){
		char buf[] = new char[length];
		int count = length;
		while(count > 0){
			buf[length-count]=p.charAt(pos);
			pos++;
			count--;
			if (pos>=p.length()) pos=0;
		}
		return (String.valueOf(buf));
		
	}
}

class TempReaderCall{
	
	static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	}
}

class StandardIn{
	private BufferedReader br;
	
	StandardIn(){
		br = new BufferedReader (new InputStreamReader(System.in));
	}
	
	ArrayList<String> getlines(int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		if (line==0){
			String tmplinedata;
			while(null != (tmplinedata = br.readLine())){
				list.add(tmplinedata);
			}
		}
		else {
			for (int i = 0; i < line; i++)
				list.add(br.readLine());
		}
		return list;
	}
	
	ArrayList<String> getlines(String end) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		String newdata;
		do{
			newdata =br.readLine();
			if (end.compareTo(newdata)==0)
				break;
			list.add(newdata);
		}while(newdata!=null);
		
		return list;
	}
	
	String getaline() throws IOException {
		return (br.readLine());
	}
}

Measured memory_bytes: 24584
import java.util.*;

public class Main{
    public static void main(String[] agrs){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int c = (X - A) / B;

        System.out.println(X - A - B * c);
    }
}

Measured memory_bytes: 35756
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

void koch(ll n, P<double, double> a, P<double, double> b) {
  if (n == 0) return;
  P<double, double> s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.first = (2.0 * a.first + 1.0 * b.first) / 3.0;
  s.second = (2.0 * a.second + 1.0 * b.second) / 3.0;
  t.first = (1.0 * a.first + 2.0 * b.first) / 3.0;
  t.second = (1.0 * a.second + 2.0 * b.second) / 3.0;
  u.first = (t.first - s.first) * cos(th) - (t.second - s.second) * sin(th) + s.first;
  u.second = (t.first - s.first) * sin(th) + (t.second - s.second) * cos(th) + s.second;

  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.first, s.second);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.first, u.second);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.first, t.second);
  koch(n-1, t, b);
}

int main() {
  ll n; cin >> n;
  P<double, double> a, b;
  a.first = 0;
  a.second = 0;
  b.first = 100;
  b.second = 0;
  printf("%.8f %.8f\n", a.first, a.second);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.first, b.second);

  return 0;
}



Measured memory_bytes: 3120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {

		ArrayList<String> datas = new ArrayList<String>();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		ArrayList<Integer> result= new ArrayList<Integer>();

		
		
		while (true) {
			String s1 = new String(in.readLine());
			int target = Integer.parseInt(s1);
			int count=0;
			
			if(s1.equals("0")) break;
			
			int now = 0;
			
			for(int i =1; i<1000 ;i++){
				for(int j = 1;j<100;j++ ){
					now = (j*(2*i + j -1))/2;
					if(now == target && j != target && i != target){
						count++;
					}
					if(now>1000 || now>target) break;
				}
			}
			result.add(count);
			
		}
		
		for(int s : result){
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 24780
a = []
c=[]

size = int(input())
for i in range(size):
    m,r=input().split()
    a.append((m,int(r)))


"""
一番目にマークで二番目に数字
a=[[m0,r0],[m1,r1]]

"""
mark =["S","H","C","D"]

#for文で全マークの全数字をそれぞれaに入ってるか調べて入ってないのをcに収めていく
for i in range(4):
    for j in range(1,14):
        if not (mark[i],j) in a:
            c = c + [[mark[i],j]]
        

for i in range(52-size):
    print(c[i][0],c[i][1])
"""
5
S 1
H 3
H 7
C 12
D 8
"""



Measured memory_bytes: 5612
using System;
using System.Linq;

class Program
{
	static void Main()
    {
      	int[] N = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        int[] A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		
      	long ASUM = A.Sum();
      	double MAX = (double)ASUM/(4*N[1]);
      	int j = 0; 
      
      	for(int k=0; k<N[0]; ++k){
          if(A[k]>=MAX){
            j++;
          }
        }
      
      	if(j>=N[1]){
          Console.WriteLine("Yes");
        }
      	else{
          Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;int64_t N,P,d[1<<20],p,i,r,v;string S;main(){for(cin>>N>>P>>S,reverse(S.begin(),S.end());i<N;i++)d[i]=S[i]-'0';if(P==2||P==5){for(i=0;i<N;i++)if(!(d[i]%P))r+=N-i;cout<<r;exit(0);}map<int,int>m;m[0]=p=1;for(i=0;i<N;i++)v=(v+d[i]*p)%P,p=(p*10)%P,r+=m[v],m[v]++;cout<<r;}

Measured memory_bytes: 2436
#include <iostream>

int main() {
  int h, n;
  std::cin >> h >> n;
  int temp;
  int sum = 0;
  while (std::cin >> temp)
    sum += temp;
  if (h-sum > 0)
    std::cout << "No" << std::endl;
  else
    std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
	int a,b,c,i,x,z;
	z=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b){
		i=1;
	}else if(b==c){
		i=b-a+1;
	}else{
	i=b-a;
	}
	for(x=0;x<i;x++){
		if(c%(a+x)==0){
			z++;
		}
	}
	printf("%d\n",z);
	return 0;
}



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

long long N;
const long long MAX = 100000;
const long long INF = 1e18;
long long A[MAX], B[MAX], S[MAX];
vector<pair<long long, long long>> neighbor[MAX];
long long sum[MAX];
long long ans[MAX];

long long dfs(long long i, long long prev){
    long long ret = 0;
    for(auto p : neighbor[i]){
        long long next = p.first;
        if(prev == next) continue;
        ret += dfs(next, i) + 1;
    }
    sum[i] = ret;
    return ret;
}

long long dsum(long long start){
    vector<long long> dist(N);
    for(long long i=0; i<N; i++) dist[i] = INF;
    dist[start] = 0;
    vector<long long> que;
    que.push_back(start);
    while(que.size()){
        long long i = que.back();
        que.pop_back();
        for(auto p : neighbor[i]){
            long long next = p.first;
            long long d = ans[p.second];
            if(dist[next] != INF) continue;
            dist[next] = dist[i] + d;
            que.push_back(next);
        }
    }
    long long ret = 0;
    for(long long i=0; i<N; i++) ret += dist[i];
    return ret;
}

int main(){
    long long i, j, k;
    cin >> N;
    for(i=0; i<N-1; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        neighbor[A[i]].push_back({B[i], i});
        neighbor[B[i]].push_back({A[i], i});
    }
    for(i=0; i<N; i++) cin >> S[i];

    dfs(0, -1);

    long long balanced = -1;
    for(i=0; i<N-1; i++){
        long long sum1 = min(sum[A[i]], sum[B[i]]);
        long long sumdiff = abs(N-2-2*sum1);
        long long distdiff = abs(S[A[i]] - S[B[i]]);
        if(sumdiff == 0){
            balanced = i;
        }else{
            ans[i] = distdiff/sumdiff;
        }
    }
    if(balanced >= 0){
        long long dualsum = dsum(A[balanced]) + dsum(B[balanced]);
        ans[balanced] = (S[A[balanced]] + S[B[balanced]] - dualsum) / N;
    }
    for(i=0; i<N-1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define sll set<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

ll power(ll a,ll b){
	if(b==0) return 1;
	if(b&1) return power(a,b/2)*power(a,b/2)*a;
	else return power(a,b/2)*power(a,b/2);
}

int main(){
	int t=1;
	//cin>>t;
	while(t--){
		int a,b,c;
		cin>>a>>b>>c;
		set<int> s;
		s.insert(a);
		s.insert(b);
		s.insert(c);
		if(s.size()==2)
			cout<<"Yes"<<endl;
		else
			cout<<"No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int>vec(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    vec.at(a-1)=vec.at(a-1)+1;
    vec.at(b-1)=vec.at(b-1)+1;
  }
  for(int i=0;i<N;i++){
    cout<<vec.at(i)<<endl;
  }
}
    

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

vector<vector<int> > G;
vector<int> bi;

bool dfs(int v, int c){
  bi[v]=c;
  for(auto x: G[v]){
    if(bi[x]==c)return false;
    if(bi[x]==0&&!dfs(x,-c))return false;
  }
  return true;
}

int main(){
  int N,M,K,x;
  cin>>N>>M;
  G.resize(N+M);
  bi.resize(N+M,0);
  
  for(int i=0;i<N;i++){
    cin>>K;
    for(int j=0;j<K;j++){
      cin>>x;
      G[i].push_back(N+x-1);
      G[N+x-1].push_back(i);
    }
  }
  dfs(0,1);
  
  bool ok=true;
  for(int i=0;i<N;i++)if(!bi[i])ok=false;
  cout<<(ok?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
}

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

int main() {
  int N, K, result;

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


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int numPeople = in.nextInt(), numSports = in.nextInt();
            int[][] A = new int[numPeople][numSports];
            for (int person = 0; person < numPeople; ++person) {
                for (int i = 0; i < numSports; ++i)
                    A[person][i] = in.nextInt() - 1;
            }
            boolean[] removed = new boolean[numSports];
            int[] cnt = new int[numSports];

            int answer = numPeople;

            for (int i = 0; i < numSports; ++i) {
                Arrays.fill(cnt, 0);
                for (int person = 0; person < numPeople; ++person) {
                    for (int j = 0; j < numSports; ++j)
                        if (!removed[A[person][j]]) {
                            ++cnt[A[person][j]];
                            break;
                        }
                }
                int max = 0, idMax = -1;
                for (int sport = 0; sport < numSports; ++sport) {
                    if (cnt[sport] > max) {
                        max = cnt[sport];
                        idMax = sport;
                    }
                }
                answer = Math.min(answer, max);
                removed[idMax] = true;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();

        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 30076