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

bool intCheck(int i, int N, int M, vector<int> S, vector<int> C) {
    string sx = to_string(i);
    if (sx.size() != N) return false;
    for (int j = 0; j < M; j++) {
        if (sx.at(S.at(j)) != (char)C.at(j) + '0') return false;
    }
    return true;
}

int main() {
    int N, M; cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s.at(i) >> c.at(i);
        s.at(i)--;
    }

    bool ans = true;
    int minv = 1e5, nf = -1;
    for (int i = 0; i < 1000; i++) {
        if (intCheck(i, N, M, s, c)) {
            cout << i << endl;
            return 0;
        }
    }
    cout << nf << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

int ask(i64 x){
    cout << "? " << x << endl;
    char res;
    cin >> res;
    if(res=='Y') return 1;
    return 0;
}

void ans(i64 x){
    cout << "! " << x << endl;
}

void solve(){
    if(ask(1000000000)){
        rep(i,0,10){
            if(ask(2*pow(10,i))){
                ans(pow(10,i));
                return;
            }
        }
    }

    i64 lb,ub;
    rep(i,0,10){
        if(!ask(pow(10,i))){
            lb=pow(10,i-1);
            ub=pow(10,i);
            break;
        }
    }

    while(ub-lb>1){
        i64 m=(lb+ub)/2;
        if(ask(m*10)) ub=m;
        else lb=m;
    }
    ans(ub);
}

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


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

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

  if (e - a > k) {
    cout << ":(" << endl;
  }
  else if (d - a > k) {
    cout << ":(" << endl;
  }
  else if (c - a > k) {
    cout << ":(" << endl;
  }
  else if (b - a > k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
  
}
  

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int ans,x,y;

signed main(){
	read(x,y);
	if(x==1) ans+=3e5;
	if(x==2) ans+=2e5;
	if(x==3) ans+=1e5;
	if(y==1) ans+=3e5;
	if(y==2) ans+=2e5;
	if(y==3) ans+=1e5;
	if(x==1&&y==1) ans+=4e5;
	write(ans);
}

Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
#define nu          pair<ll,pll>



void solve()
{
       ll n,d;
       cin>>n>>d;
       ll x[n][d];
       rep(i,0,n) rep(j,0,d) cin>>x[i][j];
       ll ans=0;
       rep(i,0,n)
       {
              rep(j,i+1,n)
              {
                     ll dis=0;
                     rep(k,0,d) dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                     ll y=sqrt(dis);
                     if(y*y==dis) ans++;
              }
       }
       cout<<ans<<endl;
}



int main() {
	ll T = 1;
	//speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	while(t--) {
	 int arr[3];
	 cin >> arr[0] >> arr[1] >> arr[2];
	 sort(arr, arr + 3);
	 cout << arr[2] - arr[0] << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll x, k, d; cin >> x >> k >> d;
  x = llabs(x);
  if (x >= d) {
    ll j = min(k, x / d);
    x -= j * d;
    k -= j;
  }
  if (k & 1) x = d - x;
  cout << x << '\n';

  return 0;
}


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

int main(void){
  int n; cin >> n;
  vector<int> h(n);
  rep(i,n) scanf("%d",&h.at(i));
  int count = 0, ans = 0;
  for(int i = n-1; i > 0; i--){
    if(h.at(i-1) >= h.at(i)){
      count++;
      ans = max(ans,count);
    }
    else{
      count = 0;
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 640
n=int(input())
s=list(map(int,input().split()))
a,b=s[:2]
while b:a,b=b,a%b
if n-2:
 b=s[2]
 while b:a,b=b,a%b
[print(x)for x in range(1,a+1)if a%x==0]


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a;
int ans;
cin>>ans;
for(int i=1;i<n;i++)
{
cin>>a;
ans=__gcd(ans,a);
}
cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[99];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortdown(a,n);
	double s=0;
	rep(i,0,n)s+=a[i]*pow(2,-i-1);
	s+=a[n-1]*pow(2,-n);
	printf("%.9f",s);
}

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

int A[2010], n;

bool solve(int i, int m){
  if (m == 0){
    return true;
  }
  if (i >= n){
    return false;
  }
  bool res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

int main(){
  int q, m[2010], num=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cin>>q;
  for(int j=0;j<q;j++){
    cin>>m[j];
  }
  for(int j=0;j<q;j++){
    if(solve(0, m[j])) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;

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


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



int main() {
	int K;cin>>K;
	int a=K/2;
	int b=K-a;
	cout<<a*b<<endl;
}


Measured memory_bytes: 256
last_month = Hash.new(0)
current_month = Hash.new(0)

while line = gets
  break if line.chomp == ''
  id, day = line.chomp.split(',').map(&:to_i)
  last_month[id] += 1
end

while line = gets
  break if line.chomp == ''
  id, day = line.chomp.split(',').map(&:to_i)
  current_month[id] += 1
end

duplications = last_month.keys & current_month.keys

duplications.sort.each do |d|
  puts "#{d} #{last_month[d] + current_month[d]}"
end

Measured memory_bytes: 8452
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int N;
  while(cin>>N) {
    if(N == 0) return 0;
    int W, H; cin >> W >> H;
    bool tree[H][W];
    FOR(y,0,H) FOR(x,0,W) tree[y][x] = false;
    FOR(i,0,N) {
      int y, x; cin >> x >> y;
      y--;x--;
      tree[y][x] = true;
    }
    int S, T; cin >> S >> T;
    // ??????
    int ans = 0;
    for(int y = 0; y + T - 1 < H; y++) {
      for(int x = 0; x + S - 1 < W; x++) {
        int cnt = 0;
        FOR(i,0,T) {
          FOR(j,0,S) {
            cnt += tree[y+i][x+j];
          }
        }
        ans = max(ans, cnt);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

        string S;
        std::cin >> S;

        int one_zero_diff = 0;
        int zero_one_diff = 0;
        REP(i, S.size()) {
            if((size_t)(S[i] - '0') != i % 2) {
                one_zero_diff++;
            }
            else {
                zero_one_diff++;
            }
        }

        std::cout << min(one_zero_diff, zero_one_diff) << std::endl;
    }
    catch(const exception& e) {
        std::cout << e.what() << std::endl;
        exit(1);
    }
    return 0;
}


Measured memory_bytes: 512
def shiftText(plain_text, key):
    plain_text.lower
    encoded_text = ""
    for i in plain_text:
        char = ord(i)+key
        if (char > 90):
            char -= 26
            encoded_text += chr(char)
        else:
            encoded_text += chr(char)
    return encoded_text


key = int(input())
plain_text = input()

print(shiftText(plain_text, key))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = 1;
		int y;
		do {
			if (x % 3 == 0 || x % 10 == 3) {
				System.out.printf(" %d", x);
			} else if (x >= 30) {
				y = x;
				while (y >= 30) {
					y = y / 10;
					if (y == 3 || y % 10 == 3) {
						System.out.printf(" %d", x);
						break;
					}
				}
			}
		} while (++x <= n);
		System.out.println();
	}

}

Measured memory_bytes: 40856
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
S = rs()
d = {'S': 'W', 'W': 'S'}
for x in ['SS', 'SW', 'WS', 'WW']:
    animals = x
    for i in range(N):
        if S[i] == 'o':
            if animals[i+1] == 'S':
                animals += animals[i]
            else:
                animals += d[animals[i]]
        else:
            if animals[i+1] == 'S':
                animals += d[animals[i]]
            else:
                animals += animals[i]
    if animals[0:2] == animals[-2:]:
        print(animals[1:-1])
        exit()

print(-1)

#08


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define LL long long
#define ALL(x) (x).begin(),(x).end()

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;

const long long OO = 2e18;
const double pi=2*acos(0.0);

     
    const int N = 100009;
     
    vi adj[N];
    int32_t main()
    {
    	fast;
    	
    	int n, a, b;
    	cin >> n >> a >> b;
    	
    	for (int i = 0; i < n-1; i++) {
    		int u, v;
    		cin >> u >> v;
    		
    		adj[u].push_back(v);
    		adj[v].push_back(u);
    	}
    	
    	vi dist_b(n+1, -1);
    	vi used(n+1, false);
    	queue<int> q;
    	q.push(b);
    	dist_b[b] = 0;
    	used[b] = true;
    	while (!q.empty()) {
    		int v = q.front();
    		q.pop();
    		for (int u: adj[v]) {
    			if (!used[u]) {
    				dist_b[u] = dist_b[v] + 1;
    				used[u] = true;
    				q.push(u);
    			}
    		}
    	}
    	
    //	debugn(dist_b);
    	for (int i = 0; i <= n; i++) used[i] = false;
    	vi dist_a(n+1, -1);
    	q.push(a);
    	dist_a[a] = 0;
    	used[a] = true;
    	int ans = 0;
    	int ans_v = a;
    	while (!q.empty()) {
    		int v = q.front();
    		q.pop();
    		for (int u: adj[v]) {
    			if (!used[u] && dist_a[v]+1 < dist_b[u]) {
    				dist_a[u] = dist_a[v] + 1;
    				if (ans < dist_b[u]) {
    					ans = dist_b[u];
    					ans_v = u;
    				}
    				used[u] = true;
    				q.push(u);
    			}
    		}
    	}
    	ans = max(ans, dist_b[a]);
    	if (dist_a[ans_v] != dist_b[ans_v])
    		ans--;
    //	debugn(dist_a);
    	cout << ans << endl;
    }

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,x,count=0;
    cin>>a>>b>>c>>x;
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            for (int k=0;k<=c;k++) {
                if (500*i+100*j+50*k==x) {
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1000000000000000;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

int main()
{
    int n;
    cin >> n;
    P p[200003];
    ll l = 0, s = INF;
    for(int i = 0; i < n; i++){
        ll x, y;
        cin >> x >> y;
        p[i] = P(max(x, y), min(x, y));
        l = max(l, p[i].second);
        s = min(s, p[i].second);
    }
    sort(p, p + n);
    ll ans = (p[n - 1].first - p[0].first) * (l - s);
    SegmentTree<ll> seg(n, [](ll a, ll b){return min(a, b);}, INF);
    for(int i = 0; i < n; i++) seg.set(i, p[i].second);
    seg.build();
    for(int i = 0; i < n; i++){
        seg.update(i, p[i].first);
        l = max(l, p[i].first);
        ans = min(ans, (p[n - 1].first - s) * (l - seg.query(0, n)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7424
def main():
   n = int(input())
   a = list(map(int,input().split()))
   b = [0 for i in range(n)]
   c = 0
   for i in range(n):
       c ^= a[i]
   for i in range(n):
       b[i] = c ^ a[i]
   for i in range(n):
       if i == n - 1:
           print(b[i])
       else:
           print(b[i], end = ' ')
main()

Measured memory_bytes: 107420
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll a;
	std::cin >> a;
	std::cout << 3 * a *a << std::endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            //int M = int.Parse(str[1]);
            bool flag = true;
            string ans = "Yes";
            if (N % 2 == 1) ans = "No";
            else
            {
                int len = N / 2;
                for(int i = 0; i < len; i++)
                {
                    if(S[i] != S[len + i])
                    {
                        ans = "No";
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
        }
        static void func() //A[0]が最大値のヒープ最大値変更
        {
           
        }
        
    }
}


Measured memory_bytes: 13140
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; cin >> N;
  vector <int> Graph[N];

  for (int i = 1; i < N; i++){
    int A; cin >> A; A--;
    Graph[A].push_back(i);
  }

  for (int i = 0; i < N; i++){
    cout << Graph[i].size() << endl;
  }
  
  

  return 0;
}


Measured memory_bytes: 14572
class SWAG():
    __slots__='unit','f','fold_r','fold_l','data_r','data_l'
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.construct(data)
    def construct(self,data):
        self.fold_r=[self.unit]
        self.fold_l=[self.unit]
        self.data_r=[]
        self.data_l=[]
        sep=len(data)//2
        for t in data[sep:]:
            self.append(t)
        for t in data[sep-1::-1]:
            self.appendleft(t)
    def append(self,x):
        self.fold_r.append(self.f(self.fold_r[-1],x))
        self.data_r.append(x)
    def appendleft(self,x):
        self.fold_l.append(self.f(self.fold_l[-1],x))
        self.data_l.append(x)
    def pop(self):
        if not self.data_r:
            self.construct(self.data_l[::-1])
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.construct(self.data_r)
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
n,k,*p=map(int,open(0).read().split())
c=[0]
for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
x=not f
s_min=SWAG(10**18,min,p[:k-1])
s_max=SWAG(0,max,p[1:k])
for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    s_min.append(p[i+k-1])
    s_max.append(b)
    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1
    s_min.popleft()
    s_max.popleft()
print(x+f)

Measured memory_bytes: 120764
s = input()

if s == "SAT":
    print(1)
elif s == "SUN":
    print(7)
elif s == "FRI":
    print(2)
elif s == "THU":
    print(3)
elif s == "WED":
    print(4)
elif s == "TUE":
    print(5)
elif s == "MON":
    print(6)


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

using namespace std;

typedef long long ll;
const int maxn = 100010;
int n,a[maxn],b[maxn],c1[maxn],c2[maxn],cnt1,cnt2,c[maxn];
ll ans;

int query(int x)
{
    int res = 0;
    while (x)
    {
        res += c[x];
        x -= x & (-x);
    }
    return res;
}

void add(int x)
{
    while (x <= n)
    {
        c[x]++;
        x += x & (-x);
    }
}

int main()
{
    scanf("%d",&n);
    for (int i = 1; i <= n; i++)
        scanf("%d",&a[i]),b[i] = a[i];
    sort(b + 1,b + 1 + n);
    for (int i = 1; i <= n; i++)
        a[i] = lower_bound(b + 1,b + 1 + n,a[i]) - b;
    for (int i = 1; i <= n; i += 2)
        if (a[i] % 2 == 0)
            ans++;
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int num = Integer.parseInt(br.readLine());
            String ary = br.readLine();
            String[] ar = ary.split(" ");
            System.out.print(ar[num-1]);
            for (int i=num-1; i>0; i--) {
                System.out.print(" " + ar[i-1]);
            }
            System.out.println("");
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24304
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
#include<numeric>
using namespace std;

int main(){
  int n,num[110000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  int x=num[0];
  for(int j=0;j<n;j++){
    x=__gcd(num[j],x);
  }
  cout<<x<<endl;
}

Measured memory_bytes: 640
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  if (n == 1) {
    writeln("Hello World");
  } else {
    int a; readV(a);
    int b; readV(b);
    writeln(a+b);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	int N, M, X, Y;
	cin >> N >> M >> X >>Y;
	vector<int> x(N);
	for (int i = 0; i < N; ++i)
		cin >> x[i];
	vector<int> y(M);
	for (int i = 0; i < M; ++i)
		cin >> y[i];
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	int ans = x[N-1] + 1;
	if (y[0] >= ans && X < ans && ans <= Y)
		cout << "No War" << endl;
	else
		cout << "War" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ab = sc.nextInt();
		int bc = sc.nextInt();
		int ca = sc.nextInt();
		sc.close();
		if(ab >= bc && ab >= ca) {
			System.out.println(bc*ca/2);
		}else if(bc >= ab && bc >= ca) {
			System.out.println(ab*ca/2);
		}else {
			System.out.println(ab*bc/2);
		}
	}

}


Measured memory_bytes: 35624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		
		LinkedHashSet<String> set = new LinkedHashSet<String>();
		
		for(int i = 0; i < n; i++) {
			if(!set.add(sc.next())) {
				out.println("No");
				return;
			}
		}
		
		List<String> list = set.stream().collect(Collectors.toList());
		
		for(int i = 1; i < n; i++) {
			if(list.get(i-1).charAt(list.get(i-1).length() - 1) != list.get(i).charAt(0)) {
				out.println("No");
				return;
			}
		}
		
		out.println("Yes");
	}

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

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

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 27988
import math
N = int(input())
if N <= 1:
    print(0)
    exit()

L = math.ceil(math.sqrt(N)) + 1
isPrime = [True] * L
isPrime[0] = isPrime[1] = False
primes = []
for n in range(2, L):
    if isPrime[n]:
        primes.append(n)
        isPrime[2*n::n] = [False] * ((L-n-1) // n)

ans = 0
for p in primes:
    d = p
    while N % d == 0:
        ans += 1
        N //= d
        d *= p
    while N % p == 0:
        N //= p

if N != 1:
    ans += 1
print(ans)


Measured memory_bytes: 24708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n){
    cin>>vec[i];
  }
  int cnt=0;
  for(int i=1;i<n-1;i++){
    if((vec[i+1]-vec[i]>0&&vec[i]-vec[i-1]>0)||(vec[i+1]-vec[i]<0&&vec[i]-vec[i-1]<0)){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
S = input()
T = input()
ans = 'Yes'
dic1,dic2 = {},{}

for i,j in zip(S,T):
    if i in dic1:
        if dic1[i] != j:
            ans = 'No'
    else:
        dic1[i] = j
        
    if j in dic2:
        if dic2[j] != i:
            ans = 'No'
    else:
        dic2[j] = i

#print(dic1)
#print(dic2)
print(ans)

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

int main()
{
	int N, i, j, chcount = 0;
	char W[100][11];

	scanf("%d", &N);
	for (i = 0; i < N; i++)
		scanf("%s", W[i]);

	while (W[0][++chcount]);
	for (i = 1; i < N; i++) {
		if (W[i-1][chcount-1] != W[i][0]) {
			printf("No\n");
			return 0;
		}

		for (j = 0; j < i-1; j++)
			if (!strcmp(W[i], W[j])) {
				printf("No\n");
				return 0;
			}

		chcount = 0;
		while (W[i][++chcount]);
	}

	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
map<int,int>mp;

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(mp.count(a)==0){
      vec.push_back(a);
    }
    mp[a]++;
  }
  int ans=0;
  for(int i=0;i<vec.size();i++){
    if(mp[vec[i]]%2==1)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 5368
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll n;
cin>>n;
  ll ans=0,a2=0;
  for(int i=0;i<n;i++) {
  int a;
    cin>>a;
    ans+=a;
    a2+=a*a;
  }
  cout<<((ans*ans)-a2)/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int w[n];
    rep(i, n) {
        cin >> w[i];
    }
    int a[n];
    a[0] = w[0];
    rep(i, n - 1){
        a[i+1] = a[i] + w[i+1];
    }
    int ans = 100000000;
    rep(i, n - 1){
        ans = min(ans, abs(a[i] - (a[n-1] - a[i])));
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<vector<int>> adj_list(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj_list[a].push_back(b);
        adj_list[b].push_back(a);
    }
    vector<long long> local_counter(n, 0);
    for (int i = 0; i < q; ++i) {
        int p, q;
        cin >> p >> q;
        --p;
        local_counter[p] += q;
    }
    vector<long long> global_counter(n, -1);
    function<void (int, long long)> apply_counter = [&](int i, long long v) {
        global_counter[i] = local_counter[i] + v;
        for (int j : adj_list[i]) {
            if (global_counter[j] == -1) {
                apply_counter(j, global_counter[i]);
            }
        }
    };
    apply_counter(0, 0LL);
    for (auto count : global_counter) {
        cout << count << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 28928
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_3-B: Queue

#include <cassert>
#include <cstdio>

template <typename T>
class queue {
  unsigned int head_ = 0U; // C++11
  unsigned int size_ = 0U;
  T* const dp_;
  const unsigned int max_;
public:
  queue(T* dp, unsigned int max) : dp_(dp), max_(max) {}
  void enqueue(const T& d) {
    assert(!is_full());
    const unsigned int tail = mod_by_max(head_+size_);
    dp_[tail] = d;
    ++size_;
  }
  const T& dequeue() {
    assert(!is_empty());
    const T& d = dp_[head_];
    head_ = mod_by_max(head_+1);
    --size_;
    return d;
  }
  inline bool is_empty() const { return size_ == 0; }
  inline bool is_full() const { return size_ == max_; }
private:
  inline unsigned int mod_by_max(const unsigned int i) const {
    return i < max_ ? i : i-max_;
  }
};

struct process {
  char name_[10+1];
  unsigned int time_;
  inline unsigned int exec(const unsigned int quantum) {
    const unsigned int elapse = time_ > quantum ? quantum : time_;
    time_ -= elapse;
    return elapse;
  }
  inline bool is_finished() const { return time_ == 0; }
};

int main(void) {
  unsigned int n, q;
  std::scanf("%d %d", &n, &q);

  process processes[n];
  queue<process> process_queue(processes, n);
  for (auto i = 0U; i < n; ++i) {
    std::scanf("%10s %d", processes[i].name_, &processes[i].time_);
    process_queue.enqueue(processes[i]);
  }

  const unsigned int quantum = q;
  unsigned int elapse = 0U;
  while (!process_queue.is_empty()) {
    process current_process = process_queue.dequeue();
    elapse += current_process.exec(quantum);
    if (current_process.is_finished()) {
      printf("%s %d\n", current_process.name_, elapse);
    } else {
      process_queue.enqueue(current_process);
    }
  }

  return 0;
}
// end

Measured memory_bytes: 3348
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=(1<<18)+10;
ll a[maxn],ans[maxn];
int main(){
	int n=read(),N=(1<<n)-1;
	REP(i,0,N) a[i]=read();
	REP(j,0,n-1) REP(i,0,N) if(i&(1<<j)){
		chkmax(ans[i],a[i]+a[i^(1<<j)]);
		chkmax(a[i],a[i^(1<<j)]);
	}
	REP(i,1,N) chkmax(ans[i],ans[i-1]);
	REP(i,1,N) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 7168
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
int N, K;
LL A[1010];
LL ans;
vector<LL> as;

void solve(int a){
	if(a < 0) return;
	int cnt = 0;
	ans += 1LL << a;
	for(auto u : as){
		if((ans & u) == ans) cnt++;
	}
	if(cnt < K) ans -= 1LL << a;
	solve(a - 1);
}
int main(){
	cin >> N >> K;
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		A[i] += A[i - 1];
	}
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < i; j++){
			as.push_back(A[i] - A[j]);
		}
	}
	solve(50);
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vi> s(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s_tmp;
      cin >> s_tmp;
      s[i].push_back(s_tmp);
    }
  }
  vi p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int sw = 0; sw < pow(2, n); sw++) {
    bool all_sw = true;
    for (int i = 0; i < m; i++) {
      auto& v = s[i];
      int tmp = 0;
      for (auto& e : v) {
        tmp += (sw >> (e - 1)) & 0x1;
      }
      if (tmp % 2 != p[i]) {
        all_sw = false;
        break;
      }
    }
    if (all_sw) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

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

int main(){
    
    
    
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int Log(int n){
	int cnt=0;
	while(true){
		if(n%2==0){
			cnt++;
			n/=2;
		}
		else return cnt;
	}
}
int main(){
	int n,a[210],ans=10000;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(ans>Log(a[i])){
			ans=Log(a[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[200000];
int b[200000];

int main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	vector<int> S;
	rep(i, n) S.push_back(b[i] ^ b[(i + 1) % n]);
	S.push_back(-1);
	rep(i, 2 * n - 1) S.push_back(a[i % n] ^ a[(i + 1) % n]);
	
	vector<int> A;
	A.resize(S.size());
	
	A[0] = S.size();
	i = 1, j = 0;
	while (i < S.size()) {
	  while (i+j < S.size() && S[j] == S[i+j]) ++j;
	  A[i] = j;
	  if (j == 0) { ++i; continue;}
	  int k = 1;
	  while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
	  i += k; j -= k;
	}
	
	for (i = n + 1; i < S.size(); i++) {
		if (A[i] == n) {
			int x = a[i - (n + 1)] ^ b[0];
			cout << i - (n + 1) << " " << x << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 11116
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let a = i.read_vec::<isize>(n);
    writeln!(o, "{}", solve(&a)).unwrap();
}
fn solve(a: &[isize]) -> isize {
    let sum = a.iter().map(|x| x.abs()).sum();
    if a.iter().filter(|&&x| x < 0).count() % 2 == 0 {
        sum
    } else {
        let min = a.iter().map(|x| x.abs()).min().unwrap();
        sum - min * 2
    }
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 8444
#include <iostream>

int main() {
    int min;
    int max;
    long long sum = 0;
    int n, d;

    std::cin >> n;
    std::cin >> d;
    min = max = d;
    sum += d;
    for (int i = 0; i < n - 1; i++) {
        std::cin >> d;
        if (min > d) min = d;
        if (max < d) max = d;
        sum += d;
    }

    std::cout << min << " " << max << " " << sum << std::endl;

    return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define int long long
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;

int n, p, cnt[10000], val[200001];

signed main()
{
    
    FLASH

    string s;
    cin>>n>>p;

    cin>>s;

    if(p == 5 or p == 2){
        int ans = 0;
        for(int i = 0; i < n; i++){
            if((s[i] - '0')%p == 0) 
                ans += i + 1;
        }
        cout<<ans<<'\n';
        return 0;
    }

    int pwr = 1;
    for(int i = n - 1; i >= 0; i--){
        val[i] = val[i + 1] + pwr*(s[i] - '0');
        val[i] %= p;
        pwr *= 10;
        pwr %= p;
    }

    int ans = 0;
    cnt[0]++;

    for(int i = n - 1; i >= 0; i--){
        ans += cnt[val[i]];
        cnt[val[i]]++;
    }
    
    cout<<ans<<'\n';
}

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

#define ll long long
#define MAX 300005
#define pp pair<int,pair<int,int>>
#define pb push_back
#define mod 1000000007
#define mx 305
using namespace std;

/*
 * author: Kruti_20
 */

ll power(ll x, ll y);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<bool> dp(k + 1);
    for (int stones = 0; stones <= k; stones++) {
        for (int i = 0; i < n; i++) {
            if (stones >= a[i] && !dp[stones - a[i]]) dp[stones] = true;
        }
    }
    cout << (dp[k] ? "First" : "Second");
    return 0;

}


ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

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


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 文字列の入力
    s <- getLine
    -- 出力
    putStrLn $ if all ((== 1) . length) $ group $ sort s then "yes" else "no"


Measured memory_bytes: 508
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final long m = scanner.nextLong();

        final long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }

        Arrays.sort(array);
        final long[] cumulativeSum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            cumulativeSum[i + 1] += cumulativeSum[i] + array[i];
        }

        /*
        ある値xに対して，その値を越える和の組み合わせが何通り存在するかを計算し，Mと比較して二分探索
        各a_iに対して和の組み合わせはn通りある（a_i + a_0, a_i + a_1, ..., a_i + a_(n-1)）
        このとき配列は昇順にソートされているので，a_i + a_j >= Xとなるjは，
        a_j >= X - a_iを満たす最小のjの値をkとすると(n-k)個存在する（このkは二分探索で求められる）．
        これを各a_iに対して計算していき，#jの総和(=何通りあるか)をとる．
        この値がmより大きければxを大きくして，小さければxを小さくして再計算
     */

        long min = array[0] * 2;
        long max = array[n - 1] * 2;
        while (max - min > 1) {
            long mid = (min + max) / 2;
            long count = 0;
            for (int i = 0; i < n; i++) {
                final int index = binarySearch(array, mid - array[i]) + 1;
                count += n - index;
            }
            if (count >= m) {
                min = mid;
            } else {
                max = mid;
            }
        }

        long answer = 0;
        long count = 0;
        for (int i = 0; i < n; i++) {
            final int index = binarySearch(array, min - array[i]) + 1;
            if (index == n) {
                continue;
            }

            count += n - index;
            // (a + b_1) + (a + b_2) + ... +  (a + b_n) = (b_1 + b_2 + ... + b_n) + n * a = (S_n - S_0) + n * a
            answer += cumulativeSum[n] - cumulativeSum[index];
            answer += array[i] * (n - index);
        }

        answer += (m - count) * min;
        System.out.println(answer);
    }

    private static int binarySearch(final long[] array, final long value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (array[mid] < value) left = mid;
            else right = mid;
        }
        return left;
    }
}


Measured memory_bytes: 60400
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	int arr[MaxN];
	void solve(){
		lli N,i,j,K,tot=0;
		cin>>N>>K;
		for(i=1;i<=N;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+N+1);
		for(i=N;i>N-K;i--){
			tot+=arr[i];
		}
		cout<<tot;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


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

int main()
{
  int a,b;
  cin>> a;
  cin >> b;
   if (a<b)
   {
   cout << "0"<< endl;
   }
     else 
     {
     cout << "10"<< endl;
   }
 
 return 0;
}


Measured memory_bytes: 3612
// 第一回日本最強プログラマー学生選手権-予選-
// B - Kleene Inversion
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;

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

  long long int p = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a.at(i) > a.at(j)) {
        p++;
      }
    }
  }

  long long int q = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a.at(i) > a.at(j)) {
        q++;
      }
    }
  }

  long long int mod = pow(10, 9) + 7;

  long long int p_total = 0;
  p_total = p * k;
  p_total %= mod;

  long long int q_total = 0;
  q_total = k - 1;
  q_total *= k;
  q_total /= 2;
  q_total %= mod;
  q_total *= q;

  long long int total;
  total = p_total + q_total;

  total %= mod;
  cout << total << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
cum = [0] * (n+1)
cum[0] = 0
for i in range(n):
    cum[i+1] = cum[i] + int(s[i] == 'W')
cost = [0] * n
for i in range(n):
    cost[i] = cum[i] + (n-i-1) - (cum[n] - cum[i+1])
print(min(cost))


Measured memory_bytes: 27148