akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

ll mod = 1000000007;

int main(){
    string s; cin >> s; ll N = s.size();
    vector<char> S(N+1); 
    S[0] = 0;
    for(int i=1; i<N+1; i++){
        S[i] = s[i-1];
    }
    vi powmod(N+1);
    powmod[1] = 1;
    for(int i=2; i<N+1; i++){
        powmod[i] = (powmod[i-1]*10)%13;
    }
    ll dp[N+1][16];
    for(int i=1; i<N+1; i++){
        for(int j=0; j<13; j++){
            dp[i][j] = 0;
        }
    }
    if(S[1]=='?'){
        for(int j=0; j<10; j++){
            ll h = (j*powmod[N])%13;
            dp[1][h]++;
        }
    }else{
        int v = S[1] - '0';
        ll c = (v*powmod[N])%13;
        dp[1][c] = 1;
    }
    for(int i=2; i<N+1; i++){
        if(S[i]=='?'){
        for(int j=0; j<13; j++){
            for(int k=0; k<10; k++){
                ll h = (k*powmod[N-i+1])%13;
                ll t = dp[i][j];
                t += dp[i-1][(j-h+13)%13];
                dp[i][j] = t;
            }
            dp[i][j] %= mod;
        }
        }else{
            int g = S[i] - '0';
            int f = (g*powmod[N-i+1])%13;
            for(int j=0; j<13; j++){
                dp[i][(j+f)%13]=dp[i-1][j];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[N][5];
}

Measured memory_bytes: 13312
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int dp[1010][201];
int dist[201][201];
int diss[201][201];

int main()
{
	int n, m;
	while(cin>>n>>m, n||m) {
		fill(dist[0], dist[201], inf);
		fill(diss[0], diss[201], inf);
		rep(i,0,m) {
			int a,b,c;
			char d;
			cin>>a>>b>>c>>d;
			a--; b--;
			if (d=='L') {
				if (c < dist[a][b]) {
					dist[a][b] = c;
					dist[b][a] = c;
				}
			}
			else {
				if (c < diss[a][b]) {
					diss[a][b] = c;
					diss[b][a] = c;
				}
			}
		}
		int r; cin>>r;
		Vi v;
		rep(i,0,r) {
			int t; cin>>t;
			t--;
			v.pb(t);
		}
		//rep(i,0,n-1) rep(j,i+1,n) printf("i=%d j=%d g[i][j][1]=%d\n",i,j,g[i][j][1]);

		// ????????????????????????????????¢
		rep(k,0,n) rep(i,0,n) rep(j,0,n) {
			dist[k][k] = 0;
			if (dist[i][k]==inf || dist[k][j]==inf) continue;
			if (dist[i][j] > dist[i][k] + dist[k][j]) {
				dist[i][j] = dist[i][k] + dist[k][j];
				dist[j][i] = dist[i][j];
			}
		}
		//rep(i,0,n-1) rep(j,i+1,n) printf("i=%d j=%d dist[i][j]=%d\n",i,j,dist[i][j]);

		// ?°´?????????????????????????????¢
		rep(k,0,n) rep(i,0,n) rep(j,0,n) {
			diss[k][k] = 0;
			if (diss[i][k]==inf || diss[k][j]==inf) continue;
			if (diss[i][j] > diss[i][k] + diss[k][j]) {
				diss[i][j] = diss[i][k] + diss[k][j];
				diss[j][i] = diss[i][j];
			}
		}
		//rep(i,0,n-1) rep(j,i+1,n) printf("i=%d j=%d diss[i][j]=%d\n",i,j,diss[i][j]);

		fill(dp[0], dp[1010], inf);
		dp[0][v[0]] = 0;
		rep(i, 0, r - 1) {
			int from = v[i], to = v[i + 1];
			//debug(i);
			rep(j, 0, n) {
				if (dp[i][j] == inf) continue;
				// ??????????????????
				if (dist[from][to] != inf)
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + dist[from][to]);
				// ????????????
				rep(k, 0, n) {
					if (dist[from][j] == inf || diss[j][k] == inf || dist[k][to] == inf) continue; // ????????????????????§k?????§????????§to?????§
					dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + dist[from][j] + diss[j][k] + dist[k][to]);
					//printf("from=%d j=%d k=%d to=%d | dp[i][j]=%d dist[from][j]=%d diss[j][k]=%d dist[k][to]=%d\n",
						//from, j, k, to, dp[i][j], dist[from][j], diss[j][k], dist[k][to]);
				}
			}
		}

		int ans = inf;
		rep(i,0,n) ans = min(ans, dp[r-1][i]);
		cout << ans << endl;
	}
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    rep(i, n) {
        if(i % 2) continue;
        int temp = i + 1, cnt = 1;
        for(int j = 2; j * j <= (i + 1); j++) {
            if(temp % j == 0) {
                int t = 1;
                while(temp % j == 0) {
                    t++;
                    temp /= j;
                }
                cnt *= t;
            }
        }
        if(temp != 1) cnt *= 2;
        if(cnt == 8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())
    ans = set()
    for i in range(K):
        if A + i <= B:
            ans.add(A + i)
        if B - i >= A:
            ans.add(B - i)
    print('\n'.join(map(str, sorted(ans))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
/*
 *	問題: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015&lang=jp
 *	所要時間: 
 *	解法: 
 *	詰まった点: 
*/
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <algorithm>
//#include <utility>
//#include <stack>
//#include <queue>
//#include <tuple>
//#include <set>
#include <map>
//#include <unordered_map>
//#include <vector>
//#include <functional>
//#include <bitset>
//#include <cmath>
using namespace std;

typedef long long lint;
typedef unsigned long long ulint;

int main(){
	int N,M;
	while(cin >> N >> M){
		if(N==0 && M==0) break;

		int h[1500],w[1500];
		for(int i=0;i<N;i++) cin >> h[i];
		for(int j=0;j<M;j++) cin >> w[j];
		map<int,int> hs,ws;
		hs.clear();	ws.clear();
		
		for(int i=0;i<N;i++){
			int hc=0;
			for(int j=i;j<N;j++){
				hc+=h[j];
				hs[hc]++;
			}
		}
		for(int i=0;i<M;i++){
			int wc=0;
			for(int j=i;j<M;j++){
				wc+=w[j];
				ws[wc]++;
			}
		}

		int hm=hs.rbegin()->first, wm=ws.rbegin()->first;
		int max=(hm>wm?hm:wm);
		lint ans=0;
		for(int i=1;i<=max;i++){
			ans+=hs[i]*ws[i];
		}
		cout << ans << endl;
	}	
	return 0;
}


Measured memory_bytes: 50680
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    sort (data.begin(), data.end());
    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += data.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define at putchar('\n')
using namespace std;
int main(void)
{
	string s;
	cin>>s;
	for(int i=1;i<=8&&!s.empty();i++) s.erase(--s.end());
	cout<<s;
	at;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> dist(N);
  rep(i, N)
  {
    long long A;
    cin >> A;
    dist[i] += A;
  }

  rep(i, N)
  {
    long long B;
    cin >> B;
    dist[i] -= B;
  }
  long long ans = 0;
  long long sum = 0;
  rep(i, N)
  {
    if (dist[i] < 0)
    {
      ans++;
      sum += dist[i];
    }
  }
  RSORT(dist);
  rep(i, N)
  {
    if (sum >= 0)
      break;

    if (dist[i] < 0)
      break;
    sum += dist[i];
    ans++;
  }
  if (sum < 0)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import numpy as np

l = []
for _ in range(3):
    l.append(list(map(int, input().split())))
l = np.array(l)

n = int(input())

li = []
for _ in range(n):
    li.append(int(input()))

ans = np.zeros((3,3))

for i in range(n):
    ans += np.where(l == li[i], 1, 0)

count = 0
c = 1
for i in range(3):
    c *= ans[i,0]
count += c
c = 1

for i in range(3):
    c *= ans[i,1]
count += c
c = 1

for i in range(3):
    c *= ans[i,2]
count += c
c = 1

for i in range(3):
    c *= ans[0,i]
count += c
c = 1

for i in range(3):
    c *= ans[1,i]
count += c
c = 1

for i in range(3):
    c *= ans[2,i]
count += c
c = 1

for i in range(3):
    c *= ans[i,0]
count += c
c = 1

for i in range(3):
    c *= ans[i,i]
count += c
c = 1

for i in range(3):
    c *= ans[i,2-i]
count += c

if count != 0:
    print("Yes")
else:
    print('No')

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int main()
{
    FAST
    int l,r,d;
    cin>>l>>r>>d;
    int cnt=0;
    for(int i=l;i<=r;i++){
            if(i%d==0)
                cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
    int n;
    int ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i <= n-3; i++) {
        if (s[i] == 'A'&& s[i+1] == 'B' && s[i+2] == 'C') {
            ans++;
        }
    }
    cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		StringBuffer buf = new StringBuffer(str);
		
		buf.reverse();
		str = buf.toString();
		
		System.out.println(str);
		scan.close();
	}
}

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

int main(){
    char S[3]; 
    rep(i,3) cin >> S[i];
    if (S[0]==S[1] && S[1]==S[2]) cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 256
import sys

S = input()

f_yymm = 0
f_mmyy = 0

l = int(S[0] + S[1])
r = int(S[2] + S[3])

if l <= 12 and l > 0:
	f_mmyy = 1
if r <= 12 and r > 0:
	f_yymm = 1

if f_mmyy + f_yymm == 2:
	print("AMBIGUOUS")
elif f_mmyy == 1:
	print("MMYY")
elif f_yymm == 1:
	print("YYMM")
else:
	print("NA")

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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n);

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

    sort(a.begin(),a.end());

    int ans = 0;

    for (int i = n-1;i >= 0;i--){
        if (n%2 == 0) {
            if (i%2 == 1) ans += a[i];
            else ans -= a[i];
        }else{
            if (i%2 == 0) ans += a[i];
            else ans -= a[i];
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python

def main():
  N = int(raw_input()) + 1
  a = []
  b = 0
  for c in bin(N)[3:]:
    b += 1
    a.append(b)
    if c == '1':
      b += 1
      a = [b] + a
  a.extend(range(1, b + 1))
  print b * 2
  print ' '.join([str(x) for x in a])

if __name__ == '__main__':
  main()

Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,2){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << (A[0]*A[1]%2==0 ? "Even" : "Odd" )<< endl;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
int main() {
    ll n;cin>>n;string ans="Yes";
    vector<pair<ll,ll>>a(n);
    rep(i,n){
        ll A,B;
        cin>>A>>B;
        a[i].first=B;
        a[i].second=A;
    }
    sort(a.begin(), a.end());
    ll time=0;
    rep(i,n){
        if(a[i].first<time)ans="No";
        time+=a[i].second;
        if(a[i].first<time)ans="No";
    }
    cout<<ans<<endl;
}

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

const int N = 2000 + 20, M = 4 * 1000 * 1000 + 20, mod = 1e9 + 7;
int n, k, fact[M], factRev[M], dp[N][N];

int sum(int a, int b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int pw(int a, int b) {
	int res = 1, tmp = a;
	while (b) {
		if (b & 1)
			res = mul(res, tmp);
		tmp = mul(tmp, tmp);
		b >>= 1;
	}
	return res;
}

int c(int a, int b) {
	return mul(fact[a], mul(factRev[b], factRev[a - b]));
}

void prepros() {
	fact[0] = 1;
	for (int i = 1; i < M; i++)
		fact[i] = mul(fact[i - 1], i);
	factRev[M - 1] = pw(fact[M - 1], mod - 2);
	for (int i = M - 2; ~i; i--)
		factRev[i] = mul(factRev[i + 1], i + 1);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	prepros();
	if (k == 1)
		return cout << 1 << endl, 0;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= i; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j)
				dp[i][j] = sum(dp[i][j], mul(dp[i][j - 1], c((n * k) - ((j - 1) * (k - 1)) - i - 1, k - 2)));
		}
	return cout << mul(dp[n][n], fact[n]) << "\n", 0;

}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

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



int n;
ll cnt = 0;
void Input() {

    cin >> n;
}



void Solve() {


    ll a[n+1];
    ll b[n];

    for(int i = 0; i < n+1; i++) {

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

        cin >> b[i];
    }


    for(int i = 0; i < n; i++) {

        if(a[i] >= b[i]) {

            cnt += b[i];

        }
        else if(b[i] - a[i] <= a[i+1]) {

            cnt += b[i];
            a[i+1] = a[i+1] - (b[i] - a[i]);
        }
        else {

            cnt += a[i] + a[i+1];
            a[i+1] = 0;
        }




    }

    cout << cnt << endl;


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 1792
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [d] <- readInts
  scoreTable <- readInts
  replicateM d readInts >>= output d . solve

solve :: [[Int]] -> _
solve xs = xs

output :: Int -> _ -> IO ()
output d _ = mapM_ print $ take d $ cycle [1..26]

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

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

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

#define sz(x) (int) x.size()
#define pb push_back
#define all(x) x.begin(),x.end()
#define uu first
#define vv second
#define mem(x, y) memset(x, y, sizeof(x))
#define un(x) x.erase(unique(all(x)), x.end())

#define sdi(x) scanf("%d", &x)
#define sdii(x, y) scanf("%d %d", &x, &y)
#define sdiii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sdl(x) scanf("%lld", &x)
#define sdll(x, y) scanf("%lld %lld", &x, &y)
#define sdlll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define sds(x) scanf("%s", x)
#define pfi(x) printf("%d\n", x)
#define pfii(x, y) printf("%d %d\n", x, y)
#define pfiii(x, y, z) printf("%d %d %d\n", x, y, z)
#define pfl(x) printf("%lld\n", x)
#define pfll(x, y) printf("%lld %lld\n", x, y)
#define pflll(x, y, z) printf("%lld %lld %lld\n", x, y, z)

#define eps 1e-9
#define OK cerr << "ok\n"
#define DB(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int, int> pii;

inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int kx[] = {+2, +1, -1, -2, -2, -1, +1, +2};
//int ky[] = {+1, +2, +2, +1, -1, -2, -2, -1}; //Knight Direction
//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction


const int MAX = 55;
int n, ans[30], now[30];

inline void print(char c, int cnt) {
    while(cnt--) printf("%c", c);
}

int main() {
//    assert(freopen("in.txt","r",stdin));
//    assert(freopen("out.txt","w",stdout));

    int i, j, len;
    char str[MAX];

    mem(ans, 63);
    sdi(n);
    rep(i, n) {
        sds(str);
        len = strlen(str);
        mem(now, 0);
        rep(j, len) {
            now[ str[j]-'a' ]++;
        }
        rep(j, 26) ans[j] = min(ans[j], now[j]);
    }

    rep(i, 26) {
        if(ans[i]) print(i+'a', ans[i]);
    }
    puts("");

    return 0;
}


Measured memory_bytes: 256
/* Volume0_3 */
import java.io.*;
import java.util.Arrays;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      int N = Integer.parseInt(br.readLine());
      int[] edges = new int[3];

      for(int i = 0; i < N; i++){
        String[] str = br.readLine().split(" ");
        for(int j = 0; j < 3; j++){
          edges[j] = Integer.parseInt(str[j]);
        }
        Arrays.sort(edges);

        if(Math.pow(edges[2], 2) == Math.pow(edges[0], 2) + Math.pow(edges[1], 2)){
          sb.append("YES").append("\n");
        }else {
          sb.append("NO").append("\n");
        }
      }
      System.out.print(sb);

    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 25728
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

int main(){
    int n,m;
    map <string,int> ans;
    cin>>n;
    getchar();
    string St;
    for(int i = 0; i < n;i++){
        cin>>St;
        ans[St] ++;
    }
    cin>>m;
    getchar();
    for (int i = 0;i < m;i++){
        cin>>St;
        ans[St]--;
    }
    int result = 0;
    map<string,int> ::iterator iter;
    for (iter = ans.begin();iter!=ans.end();iter++){
        result = max(result,iter->second);
    }
    cout<<result<<endl;
}


Measured memory_bytes: 256
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
pq = [list(map(int, input().split())) for _ in range(Q)]

table = [[0 for _i in range(N+1)] for _j in range(N+1)]
accum = [[0 for _i in range(N+1)] for _j in range(N+1)]
accum2 = [[0 for _i in range(N+1)] for _j in range(N+1)]

for line in LR:
    table[line[0]][line[1]] += 1
# よこ
for i in range(1, N+1):
    for j in range(1, N+1):
        accum[i][j] = accum[i][j-1] + table[i][j]
# 縦
for i in range(1, N+1):
    for j in range(1, N+1):
        accum2[i][j] = accum2[i-1][j] + accum[i][j]

# for i in range(1, N+1):
#     for j in range(i, N+1):
#         ans[i][j] = sum([accum[k][j] - accum[k][i-1] for k in range(i, j+1)])

for question in pq:
    p = question[0]
    q = question[1]
    print(accum2[q][q] - accum2[p-1][q] - accum2[q][p-1] + accum2[p-1][p-1])

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

int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;

  scanf("%s\n%d", s, &n);

  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
    
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }

    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }

    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }

  return 0;
}




Measured memory_bytes: 2140
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

n = ni()
ans = 0
for i in range(n):
  a,c = nn()
  r = 1 if c == "JPY" else 380000
  ans += float(a)*r

print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  for (int i = 0; i < g; ++i) {
    if (S[N / g * i] != T[M / g * i]) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (long long) N / g * M << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;

int sod(int n){
    int sum = 0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int res = 0;
    rep(1,i,n+1){
        int sum = sod(i);
        if(a <= sum && sum <= b){
            res+=i;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
a,b = map(int, input().split())
polls = []
for i in range(1,1000):
    polls.append(sum(list(range(1,1000))[:i]))

d = {}
for i in range(1, len(polls)):
    d[polls[i]-polls[i-1]] = [polls[i-1],polls[i]]

print(d[b-a][0] - a)


Measured memory_bytes: 3188
import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

l = list(itertools.permutations(range(1,n+1),n))
# print(l)
a = l.index(p)
b = l.index(q)


print(abs(b-a))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<double> v(n + 1);
  v[0] = 0;
  rep2(i, 1, n + 1) {
    double num;
    cin >> num;
    v[i] = (1 + num) / 2;
    v[i] += v[i - 1];
  }
  double ans = 0;
  rep2(i, k, n + 1) ans = max(ans, v[i] - v[i - k]);
  printf("%.10lf\n", ans);
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1L<<61);

int main() {
  int n, ans = 0; cin >> n;
  string s; cin >> s;
  rep(i,10) {
    rep(j,10) {
      rep(k,10) {
        int pos = 0;
        while (pos < n && s[pos]-'0' != i) pos++; pos++;
        while (pos < n && s[pos]-'0' != j) pos++; pos++;
        while (pos < n && s[pos]-'0' != k) pos++;
        if (pos < n) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> L(N);
	for (Int i = 0; i < N; i++) {
		cin >> L[i];
	}

	sort(L.begin(), L.end());

	Int ans = 0;
	for (Int i = N-1; i >=0; i--) {//最大辺
		for (Int j = 0; j < i-1; j++) {
			for (Int k = j + 1; k < i; k++) {
				if (L[i] < L[j] + L[k]) {
					ans += i - k;
					break;
				}
			}
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=3005;
int n, mod, s[maxn][maxn], C[maxn][maxn];
int ksm(int u,int v, int m){
	int s = 1;
	for(int i = v; i; i >>= 1){
		if(i & 1) s = 1ll * s * u % m;
		u = 1ll * u * u % m;
	}    
	return s;
}
int main(){
    cin >> n >> mod;
    s[0][0]=1; C[0][0] = 1;
    for(int i = 1; i <= n + 1; i++){
    	C[i][0] = 1; C[i][i] = 1; s[i][i] = 1;
        for(int j = 1; j < i; j++){
            s[i][j] = (s[i - 1][j - 1]+1ll * s[i - 1][j] * j) % mod;
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
        }
    }
    int ans = 0;
    for(int i = 0; i <= n; i++){
        int sum = 0, w = ksm(2, ksm(2, n - i, mod - 1), mod), base = ksm(2, n - i, mod);
        for(int j = 0,coef = 1; j <= i; j++,coef = 1ll * coef * base % mod)
            sum=(sum + 1ll * s[i + 1][j + 1] * w % mod * coef) % mod;
        ans = (ans + (i & 1 ? - 1ll : 1) * C[n][i] * sum) % mod;
    }
    cout<<(ans + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 69504
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

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

  int ans = 0;
  int i, j;
  for (i = 0; i < S.length(); i++) {
    for (j = i; j < S.length(); j++) {
      bool possible = true;
      for (int k = i; k <= j; k++) {
        if (S[k] == 'A' || S[k] == 'T' || S[k] == 'G' || S[k] == 'C') {
        } else {
          possible = false;
          break;
        }
      }
      if (possible && ans < j - i + 1) {
        ans = j - i + 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	c := nextInt()
	x := nextInt() // a
	y := nextInt() // b
	//l := make([]int, n)

	costDefault := a*x + b*y
	costmin := costDefault
	// ABピザを2枚ずつAピザ,Bピザで置き換えていく
	for ab := 0; ab <= 100000; ab++ {
		newcost := 2*c*ab + a*max(0, x-ab) + b*max(0, y-ab)
		costmin = min(costmin, newcost)
	}

	fmt.Println(costmin)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
#define T tuple<int,int,int>

int main(){
	int n,m,q,i,j,k;
	cin>>n>>m>>q;
	vector< vector<char> > s(n+1,vector<char>(m+1,'0'));
	loop(i,1,n+1){
		loop(j,1,m+1){
			cin>>s[i][j];
		}
	}
	vector< vector<T> > dp(n+1,vector<T>(m+1,make_tuple(0,0,0)));
	loop(i,1,n+1){
		loop(j,1,m+1){
			get<0>(dp[i][j])=get<0>(dp[i-1][j])+get<0>(dp[i][j-1])-get<0>(dp[i-1][j-1]);
			get<1>(dp[i][j])=get<1>(dp[i-1][j])+get<1>(dp[i][j-1])-get<1>(dp[i-1][j-1]);
			get<2>(dp[i][j])=get<2>(dp[i-1][j])+get<2>(dp[i][j-1])-get<2>(dp[i-1][j-1]);
			if(s[i][j]=='1'){
				get<0>(dp[i][j])++;
				if(s[i-1][j]=='1'){
					get<1>(dp[i][j])++;
				}
				if(s[i][j-1]=='1'){
					get<2>(dp[i][j])++;
				}
			}
		}
	}
	loop(i,0,q){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int a,b,c;
		a=get<0>(dp[x2][y2])-get<0>(dp[x1-1][y2])-get<0>(dp[x2][y1-1])+get<0>(dp[x1-1][y1-1]);
		b=get<1>(dp[x2][y2])-get<1>(dp[x1][y2])-get<1>(dp[x2][y1-1])+get<1>(dp[x1][y1-1]);
		c=get<2>(dp[x2][y2])-get<2>(dp[x1-1][y2])-get<2>(dp[x2][y1])+get<2>(dp[x1-1][y1]);
		cout<<a-b-c<<endl;
	}
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<int> dp(N + 1, INF);
  // 9 loop
  map<int, int> mp;
  for (int i = 9; i <= N; i *= 9) {
    mp[i] = 1;
  }
  for (int i = 6; i <= N; i *= 6) {
    mp[i] = 1;
  }
  // dump(mp);
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    dp[i] = min(dp[i], dp[i - 1] + 1);
    for (auto& m : mp) {
      // dump(m);
      if (m.first <= i) {
        dp[i] = min(dp[i], dp[i - m.first] + 1);
      }
    }
    // dump(dp);
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

w = input()
dic = {}

for i in w:
	if not i in dic:
		dic[i] = 1
	else:
		dic[i] += 1

for word in dic:
	if dic[word]%2 != 0:
		print("No")
		break
else:
	print("Yes")

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

int main(){
  int N;
  cin >> N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  for(int i=N-2;i>=0;i--){
    if(H[i]-1>H[i+1]){
      cout << "No" << endl;
      return 0;
    }
    if(H[i]>H[i+1]){
      H[i]--;
    }
  }
  
  cout << "Yes" << endl;
}
      
    
      


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll k;
  cin >> k;

  // string s = to_string(k);
  // int len = s.size();

  vector<string> dp(200000);
  for (int i = 0; i <= 100001; i++) {
    if (i <= 10) {
      dp[i] = to_string(i);
      continue;
    }

    string prev = dp[i - 1];
    int ps = prev.size();
    for (int j = 0; j < ps; j++) {
      int cur = ps - 1 - j;
      int nxt = cur - 1;
      if (nxt < 0) {
        if (prev[cur] == '9') {
          string ns = string(ps + 1, '0');
          ns[0] = '1';
          dp[i] = ns;
          break;
        } else {
          prev[cur]++;
          for (int z = 1; z < ps; z++) {
            if (prev[z - 1] != '0') {
              prev[z] = prev[z - 1] - 1;
            } else {
              prev[z] = prev[z - 1];
            }
          }
          dp[i] = prev;
          break;
        }
      }

      if (prev[cur] == '9') {
        continue;
      }

      int cc = (prev[cur] - '0');
      int nc = (prev[nxt] - '0');

      if (nc - cc == 0 || nc - cc == 1) {
        prev[cur] = prev[cur] + 1;
        for (int z = cur + 1; z < ps; z++) {
          if (prev[z - 1] != '0') {
            prev[z] = prev[z - 1] - 1;
          } else {
            prev[z] = prev[z - 1];
          }
        }
        dp[i] = prev;
        break;
      }
    }
  }

  cout << dp[k] << ln;

  return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <map>

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007
using namespace std;

int N;
ll fact[1000001];
ll fact_i[1000001];

ll pow_binary(int x, int y) {
    if (y == 0) return 1;

    ll p = pow_binary(x, y >> 1);
    if (y % 2 == 0) return p * p % MOD;
    else            return p * p % MOD * x % MOD;
}

ll ncr(int n, int r) {
    return fact[n] * fact_i[n - r] % MOD * fact_i[r] % MOD;
}

int main() {
    cin >> N;
    fact[0] = fact[1] = 1;
    FOR(i, 2, N + 1) fact[i] = fact[i - 1] * i % MOD;
    fact_i[N] = pow_binary(fact[N], MOD - 2);
    REP(i, N) fact_i[N - i - 1] = fact_i[N - i] * (N - i) % MOD;

    ll ans = 0;
    ll count_before = 0;
    FOR(i, (N + 1) / 2, N) {
        ll count = ncr(i - 1, N - i - 1) * fact[i] % MOD * fact[N - i - 1] % MOD;
        ans = (ans + i * (MOD + count - count_before) % MOD ) % MOD;
        count_before = count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16000
def pa(s)
  n = s.length
  (0...n).each do |i|
    return false if s[i]!=s[n-i-1]
  end
  true
end
s = gets.chomp
n = s.length
puts ((pa(s) && pa(s[0...n/2]) && pa(s[n/2+1..-1])) ? :Yes : :No)

Measured memory_bytes: 14320
def judge(x):
  n = len(x)
  flg = 1
  for i in range(n//2):
    if x[i] != x[-i-1]:
      flg = 0
  return flg
s = input()
n = len(s)
if judge(s) and judge(s[:n//2]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
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; }
using Graph = vector<vector<int>>;
int main()
{
    int N, M;
    cin >> N >> M;
    vl H(N);
    rep(i, N) cin >> H[i];
    vl B(N, -1);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        --a;--b;
        chmax(B[a], H[b]);
        chmax(B[b], H[a]);
    }
    int ans = 0;
    rep(i, N){
        if(H[i] > B[i]) ++ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(void){
    int n,m; cin>>n>>m;
    if(n==1) {cout<<m<<endl; return 0;}
    int x = m/n;
    int ans =0;
    for(int i=1;i<=x;i++){
       if(m%i==0) ans = i;
    }
    cout<<ans<<endl;
    
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    ll cnt = 0;
    rep(i, N) cnt += S[i] - '0';
    if (cnt % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 333333, B = 60;
int a[N], sum[B][N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    rep(b, 0, B - 1) {
        rrep(i, 1, n) {
            sum[b][i] = sum[b][i + 1] + ((a[i] & (1LL << b)) > 0);
        }
    }
    int ans = 0;
    rep(b, 0, B - 1) {
        int cnt = 0;
        rep(i, 1, n) {
            if(a[i] & (1LL << b)) {
                cnt += n - i - sum[b][i + 1];
            } else {
                cnt += sum[b][i + 1];
            }
        }
        cnt %= MOD;
        int mult = (1LL << b) % MOD;
        ans += cnt * mult % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 158848
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define EPS 1.0e-8
#define MOD 1000000007
typedef long long ll;

template <class T> struct MaxFlow {
    const T INF = 1e9;
    struct  Edge {
        int to,rev; T cap;
        Edge(){}
        Edge(int _to, int _rev, T _cap){
            to = _to; rev = _rev; cap = _cap;
        }
    };
    vector< vector<Edge> > G;
    vector< bool > used;
    MaxFlow(int size){
        G.resize(size+10);
        used.resize(size+10);
    }
    void add_edge(int from, int to, int cap){
        G[from].push_back(Edge(to,(int)G[to].size(),cap));
        G[to].push_back(Edge(from,(int)G[from].size()-1,0));
    }
    T dfs(int v, int t, T f){
        if(v==t)return f;
        used[v] = true;
        for(int i=0;i<G[v].size();i++){
            Edge &e = G[v][i];
            if(!used[e.to] && e.cap>0){
                T d = dfs(e.to, t, min(f,e.cap));
                if(d>0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    T getmax(int source, int sink){
        T flow = 0;
        while(true){
            for(int i=0;i<used.size();i++)used[i]=false;
            T f = dfs(source, sink, INF);
            if(f==0)return flow;
            flow += f;
        }
    }
};


int main(){
    
    MaxFlow<int> inst(1000);
    
    int V,E; cin>>V>>E;
    REP(i,E){
        int a,b,c; cin>>a>>b>>c;
        inst.add_edge(a, b, c);
    }
    
    cout<<inst.getmax(0,V-1)<<endl;
    
    return 0;
}

Measured memory_bytes: 3108
#include<stdio.h>
long long a[524288];
long long b[524288];
long long seq[300000];
long long newseq[200000];
long long sum[100001];
long long newsum[100001];
long long sum_diff;
long long pow[20];

long long min(long long a, long long b){
	if(a<b){return a;}else{return b;}
}
long long max(long long a, long long b){
	if(a>b){return a;}else{return b;}
}

int mincheck(long long i){
	a[i] = min(a[2*i+1], a[2*i+2]);
	if(a[2*i+1]<=a[2*i+2]){
		b[i] = 2*i+1;
	}else{
		b[i] = 2*i+2;
	}
	return 0;
}


int mincheck_from(long long i){
	long long par;
	while(i>0){
		par = (i-1)/2;
		mincheck(par);
		i = par;
	}
	return 0;
}

int main(void){
	long long N;
	long long i,j,m;
	long long ans;
		
	scanf("%lld", &N);
	for(i=0;i<3*N; i++){
		scanf("%lld", &seq[i]);
	}

	/*2乗*/
	pow[0] = 1;
	for(i=1;i<20;i++){
		pow[i] = 2*pow[i-1];
	}
	
	/*最初の和*/
	sum[0] = 0;
	for(i = 0; i<N; i++){sum[0] = sum[0] + seq[i];}
	
	/*数列の初期化*/
	for(i = 0; i<N;i++){
		a[262143 + i] = seq[i];
	}
	for(i = N; i< 262144;i++){
		a[262143 + i] = 1000000001;
	}
	
	/*初期最小値の管理*/
	for(j=17;j>=0;j--){
		for(i=pow[j]-1;i<pow[j+1]-1; i++){
			mincheck(i);
		}
	}
	
	/*値を増やす*/
	for(i=0;i<N;i++){
		a[262143+N+i] = seq[N+i];
		mincheck_from(262143 + N + i);
		m = 0;
		while(m<262143){
			m = b[m];
		}
		sum_diff = seq[N+i] - a[m];
		sum[i+1] = sum[i] + sum_diff;
		a[m]=1000000001;
		mincheck_from(m);
	}
	
	/*以下、右側について*/
	
	for(i=0;i<2*N;i++){
		newseq[i] = -seq[3*N-1-i];
	}
	
	
	/*最初の和*/
	newsum[0] = 0;
	for(i = 0; i<N; i++){newsum[0] = newsum[0] + newseq[i];}
	
	/*数列の初期化*/
	for(i = 0; i<N;i++){
		a[262143 + i] = newseq[i];
	}	
	for(i = N; i< 262144;i++){
		a[262143 + i] = 1000000001;
	}
	
	/*初期最小値の管理*/
	for(j=17;j>=0;j--){
		for(i=pow[j]-1;i<pow[j+1]-1; i++){
			mincheck(i);
		}
	}
	
	/*値を増やす*/
	for(i=0;i<N;i++){
		a[262143+N+i] = newseq[N+i];
		mincheck_from(262143 + N + i);
		m = 0;
		while(m<262143){
			m = b[m];
		}
		sum_diff = newseq[N+i] - a[m];
		newsum[i+1] = newsum[i] + sum_diff;
		a[m]= 1000000001;
		mincheck_from(m);
		}
	
	/*for(i=0;i<=N;i++){
		printf("sum[%lld] = %lld, newsum[%lld] = %lld -> %lld\n",i,sum[i],N-i,newsum[N-i], sum[i] + newsum[N-i]);
	}*/
	ans = sum[0] + newsum[N];
	for(i=1;i<=N;i++){
		ans = max(ans, sum[i] + newsum[N-i]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 3e3+5, inf = 1e9+7;
int n, k, i, j;
int A[N], dp[N][N];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n;
    rep(i, 1, n+1){
        cin>>A[i];
        sep(j, i, 0)
            dp[j][i] = max(A[j]-dp[j+1][i], A[i]-dp[j][i-1]);
    }
    cout<<dp[1][n];
}

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

#define int long long
#define fi first
#define se second
#define pb push_back
#define ins insert
#define er erase

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int oo = 1e18 + 7, mod = 998244353;
const int N = 3e5 + 5;

int n, a, b, k, ans, fac[N], invfac[N];

int binpw(int base, int pw){
    int ans = 1;
    while(pw){
        if(pw & 1) ans = (ans * base) % mod;
        base = (base * base) % mod;
        pw >>= 1;
    }
    return ans;
}

int c(int n, int k){
    int temp = fac[n] * invfac[k] % mod;
    return (temp * invfac[n - k]) % mod;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n >> a >> b >> k;
	fac[0] = invfac[0] = 1;
	for(int i = 1; i <= (N - 5); i++){
	    fac[i] = (fac[i - 1] * i) % mod;
	    invfac[i] = binpw(fac[i], mod - 2);
	}
	for(int i = 0; i <= n; i++){
	    int diff = k - a * i;
	    if(diff < 0 || (diff % b)) continue;
	    diff /= b;
	    if(diff > n) continue;
	    ans += c(n, i) * c(n, diff);
	    ans %= mod;
	}
	cout << ans;
}



Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    ll A,B;
    cin >> A >> B;
    cout << (A+B)%24 << endl;
    return 0;
}

Measured memory_bytes: 256
'''
結局この計算は Ai のすべての組み合わせ(Ai 自身同士は含まない)の 
XOR の合計なので、Ai のあるビットの立っている数の合計を c とすると、
Ai のあるビットが0であった場合により計算結果に立つビットの数は 
c、Ai のあるビットが1であった場合により計算結果に立つビットの数は 
N - c になるので、あるビットに関する計算結果は c * (N -c) の
ビットシフトした値になる. 結果として以下の計算で解ける.
'''
N = int(input())
A = list(map(int, input().split()))

result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in A) >> bit
    result += (c * (N - c)) << bit
    result %= 1000000007
print(result)

Measured memory_bytes: 42156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



/************************************


 
*************************************/

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;
ll f=0,k=1;
map<pll,ll>m;
ll dp1[MAX],dp2[MAX];
ll red,blue;
ll ans;
ll dp[MAX];

ll lca(ll u,ll v){
	while(u!=v){
		ll l1,l2;
		l1 = log2(u);
		l2 = log2(v);
		//cout<<l1<<"$$"<<l2<<endl;
		if(l1<l2)
			swap(u,v);
		u /=2;
	}
	return u;
}

bool comp1(const pair<int,pll>&a,const pair<int,pll>&b){
	return (a.F<b.F);
}
// vector<int>r,g,b;
ll sum=INT64_MAX;

// ll s(int x,int y,int z){
// 	return ((ll)((x-y)*(x-y))+(ll)((y-z)*(y-z))+(ll)((z-x)*(z-x)));
// }




signed main(){
	boost;
	int t=1;
	// cin>>t;
	while(t--){
		int a,b;
		cin>>a>>b;
		if(b>=a)
		cout<<"unsafe\n";
		else cout<<"safe\n";

	}

	return 0;
}

Measured memory_bytes: 3676