akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int Maxn = 2005;

int lena, lenb, cnta, cntb, cnt;
int ans = 0x3f3f3f3f;
char a[Maxn], b[Maxn];
int l[Maxn], r[Maxn], mx[Maxn];

inline void solve(int x) {
  memset(mx, cnt = 0, sizeof mx);
  for (int i = 0; i < lena; ++ i) if (a[i] ^ b[(x + i) % lena])
    mx[l[i]] = max(mx[l[i]], r[i]), ++ cnt;
  for (int i = lena - 1, j = 0; ~i; j = max(j, mx[i --]))
    ans = min(ans, i + i + j + abs(x - j) + cnt);
}

int main() {
  scanf("%s\n%s", a, b), lena = strlen(a), lenb = strlen(b);
  for (char *c = a; *c; ++ c) cnta += (*c - '0');
  for (char *c = b; *c; ++ c) cntb += (*c - '0');
  if (!cntb) return printf("%d\n", -(cnta > 0)) & 0;
  for (int i = 0; i < lena; ++ i) {
    for (r[i] = 0; b[(i + r[i]) % lena] == 48; ++ r[i]);
    for (l[i] = 0; b[(i - l[i] + lena) % lena] == 48; ++ l[i]);
  } for (int i = 0; i < lena; ++ i) solve(i);
  reverse(a, a + lena), reverse(b, b + lenb);
  for (int i = 0; i < lena; ++ i) {
    for (r[i] = 0; b[(i + r[i]) % lena] == 48; ++ r[i]);
    for (l[i] = 0; b[(i - l[i] + lena) % lena] == 48; ++ l[i]);
  } for (int i = 0; i < lena; ++ i) solve(i);
  return printf("%d\n", ans) & 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

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


int A, B;

void solve() {
	cin >> A >> B;
	if(A + B < 10) cout << A + B << '\n';
	else cout << "error\n"; 
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


def maxmove(lk, H):
    dp = {}
    dp[lk] = 0
    for i in range(lk-1, -1, -1):
        if H[i] >= H[i+1]:
            dp[i] = dp[i+1] + 1
        else:
            dp[i] = 0

    return max(dp.values())


def main():
    N = int(input())
    H = list(map(int, input().split()))
    print(maxmove(N-1, H))


if __name__ == '__main__':
    main()


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

using ll = long long;
int main() {
    ll X,N;
    cin >> X >> N;
    vector<ll>A(N);
  set<ll>dis;
    
  for(ll &i:A)cin >> i;
  
  for(ll i:A){
   dis.insert(X-i);
  }
  
  bool s1=true,s2=true;
  ll sss=0;
  for(ll i=0;!dis.empty();i++){
      s1=true;
      s2=true;
    if(dis.count(-i))s1=false;
    if(dis.count(i))s2=false;
    dis.erase(-i);
    dis.erase(i);
      sss=i;
    if(s1||s2)break;
  }
  
    
    if(s2){
    cout << X-sss << endl;
    }else if(s1){
    cout << X+sss << endl;
    }else{
        cout << X-sss-1 << endl;
    }
    
    
    
  
}


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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		vector<int> vec;
		int a, b, c;
		cin >> a >> b >> c;
		vec.push_back(a);
		vec.push_back(b);
		vec.push_back(c);
		sort( vec.begin(), vec.end() );
		if(vec[0] * vec[0] + vec[1] * vec[1] == vec[2] * vec[2]){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
N, K = map(int, input().split())
d = [0] * 100005
for i in range(N):
    a, b = map(int, input().split())
    d[a] += b

num = 0
for i in range(100005):
    if d[i] != 0:
        if num + d[i] >= K:
            print(i)
            break
        else:
            num += d[i]

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int X,Y;
	cin >> X >> Y;
	int a,b;
	for(int i=0; i<=X; i++) {
		a = i;
		b = X-i;
		if(2*a + 4*b == Y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

  return 0;
}


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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while(true)
    {
        int N, M; cin >> N >> M;
        if(N == 0 && M == 0) break;
        vi C(M); REP(i, M) cin >> C[i];
        vi x(N); REP(i, N) cin >> x[i];
        vvi dp(N+1, vi(256, INF)); // dp[i+1][j] := i番目の複合信号がjのときの最小値
        REP(i, M) dp[0][128] = 0;
        REP(i, N)
        {
            REP(j, 256)
            {
                if(dp[i][j] != INF)
                {
                    REP(k, M)
                    {
                        int t;
                        if(j+C[k] > 255) t = 255;
                        else if(j+C[k] < 0) t = 0;
                        else t = j+C[k];
                        chmin(dp[i+1][t], dp[i][j]+(t-x[i])*(t-x[i]));
                    }
                }
            }
        }
        cout << *min_element(ALL(dp[N])) << endl;
    }
}


Measured memory_bytes: 43948
N = int(input())
ans = 'No'
count =0
for i in range(N):
    d1,d2 = list(map(int,input().split()))
    if d1!=d2:
        count =0
    else:
        count +=1
    if count == 3:
        ans = 'Yes'
        break
print(ans)

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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  
  bool f_a = false, f_b = false;
  
  for (int i = 0; i < 3;i++) {
    if (s[i] == 'A') f_a = true;
    else f_b = true;
  }
  
  if (f_a & f_b) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

S = [chr(i) for i in range(ord("a"), ord("z")+1)]

l = []
while N > 0:
    N -= 1
    r = N % 26
    l.append(r)
    N //= 26

ans = ""
for a in l:
    ans = S[a] + ans

print(ans)

Measured memory_bytes: 9132
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

long
gcd(long a, long b)
{
	if (b == 0)
		return a;

	return gcd(b, a % b);
}

long
lcm(long a, long b)
{
	return (a * b / gcd(a, b));
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int a1, a2, a3;
		int m1, m2, m3;
		int x, y, z;
		long c1, c2, c3;

		scanf("%d %d %d %d %d %d", &a1, &m1, &a2, &m2, &a3, &m3);

		if (a1 == 0 && m1 == 0 && a2 == 0 && m2 == 0 && a3 == 0 && m3 == 0)
			break;

		x = 1;
		c1 = 0;
		do
		{
			x = (a1 * x) % m1;
			c1++;
		} while (x != 1);

		y = 1;
		c2 = 0;
		do
		{
			y = (a2 * y) % m2;
			c2++;
		} while (y != 1);

		z = 1;
		c3 = 0;
		do
		{
			z = (a3 * z) % m3;
			c3++;
		} while (z != 1);

		printf("%ld\n", lcm(lcm(c1, c2), c3));
	}

	return 0;
}

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

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  int N;
  cin >> N;
  cout << 800*N - 200*(N/15) << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int n;
struct P { double x, y;};
vector<P> p;

double dist(P a, P b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}
double f(double x, double y) {
  double res = 0;
  rep(i,n) {
    res = max(res, dist((P){x,y}, p[i]));
  }
  return res;
}

double g(double x) {
  // xを決めたときのf(x,y)の極小値を三分探索で計算
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (f(x,c1) > f(x,c2)) l = c1; else r = c2;
  }
  return f(x,l);
}

int main () {
  cin >> n;
  p = vector<P>(n);
  rep(i,n) cin >> p[i].x >> p[i].y;

  // f(x,y)を最小にするxを三分探索
  // 評価関数 g(x)はxに対して、yを好き勝手に動かしたときのf(x,y)の極小値
  double l = 0, r = 1000;
  rep(i,80) {
    double c1 = (l*2+r)/3;
    double c2 = (l+r*2)/3;
    if (g(c1) > g(c2)) l = c1; else r = c2;
  }

  double ans = g(l);
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
/*
Author: Fuadul Hasan(fuadul202@gmail.com)
BSMRSTU,Gopalganj
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
//#include<bits/stdc++.h>
using namespace std;
 
int         cinn()              {int x; scanf("%d", &x); return x;}
long long   scll()              {long long x; scanf("%lld", &x); return x;}
double      scd()               {double x; scanf("%lf", &x); return x;}
void        coutt(int x)        {printf("%d ", x);}
 
#define  scll                   scll()
#define  gcd(a,b)               __gcd(a,b)
#define  lcm(a,b)               (a*b)/gcd(a,b)
#define  PI                     acos(-1.0)
#define  vi                     std::vector<int>
#define  vll                    std::vector<ll>
#define  vit                    vector<int> :: iterator
#define  sit                    set<int> :: iterator
#define  mpsi                   std::map<string, int>
#define  pb                     push_back
#define  ll                     long long int
#define  ld                     long double
#define  ull                    unsigned long long int
#define  min3(a,b,c)            min(a,min(b,c))
#define  min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define  max3(a,b,c)            max(a,max(b,c))
#define  max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define  nl                     printf("\n");
#define  no                     printf("No");
#define  yes                    printf("Yes");
#define  F                      first
#define  S                      second

typedef pair<int,int> ii;
typedef std::vector<ii> vii;
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 1e6 + 5;
const int nn           = 2e5 + 5;


int siv[N];

int solve()
{
	int n,x;
	cin>>n;
	int a[200006];
	bool f = true;
	for(int i=0;i<n;i++){
		cin>>a[i]; 
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	 cout<<"YES"<<endl;
	 return 0;
}

int main()
{
    int test = 1, tc = 0;
    //scanf("%d", &test);
   // (void)getchar();
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
 
    return 0;
}

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



int main(){
  int i,n,q,j,count=0;
  int *S;
  scanf("%d",&n);
  S=malloc((n+1)*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&S[n]);
    j=0;
    while(j!=n){
      if(S[j]==S[n]){
        count++;
        break;
      }
      j++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 636
function main(){
	var n = scan();
	var m = scan();
	var d = Array(n);
	rep(n, function(i){
		d[i] = scan();
	});
	var c = Array(m);
	rep(m, function(i){
		c[i] = scan();
	});

	dp = Array(n + 1);
	rep(n + 1, function(i){
		dp[i] = Array(m + 1);
		rep(m + 1, function(j){
			if(i == 0){
				dp[i][j] = 0;
			}
			else if(j == 0){
				dp[i][j] = Infinity;
			}
			else{
				dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j - 1] + d[i - 1] * c[j - 1]);
			}
		});
	});
	print(dp[n][m]);
}

function rep(n, func){
	for(var i = 0; i < n; ++i){
		func(i);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';
var input_index = 0;

function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}

function print(val){
	console.log(val);
}

process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

Measured memory_bytes: 24588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100

using namespace std;
typedef pair<int, int> ipair;

int N, X, L[MAX_N], res = 1;
int main(int argc, char **argv) {
    cin >> N >> X;
    for(int i = 0; i < N; ++i)
        cin >> L[i];

    int d = 0;
    for(int i = 0; i < N; ++i) {
        d += L[i];
        if(d <= X)
            ++res;
        else
            break;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
a.sort(reverse=True)

ans = a[0]
i = 1
cnt = 2
while True:
  if cnt == N:
    break
  ans += a[i]
  cnt += 1
  if cnt == N:
    break
  ans += a[i]
  cnt += 1
  i += 1
print(ans)

Measured memory_bytes: 99104
#include <cstdio>

int main()
{
  char s[5];
  scanf("%s", s);
  int ans = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '2') ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

// int n以下の素数リスト
struct PrimeTable {
  int n;
  vector<int> sieve, primes;
  PrimeTable(int n) : n(n), sieve(n+1) {
    sieve[0] = sieve[1] = -1;
    for(long long i = 2;i < n+1;++i) {
      if (sieve[i]) continue;
      primes.emplace_back(i);
      sieve[i] = i;
      // 一番小さい素因数のみ記録する
      for (long long j = i*i; j <= n; j += i) if (!sieve[j]) sieve[j] = i;
    }
  }
  bool isPrime(int m) { return sieve[m] == m; }
  vector<int> factorList(int x) {
    vector<int> res;
    if(x == 0) {
      res.emplace_back(0);
      return res;
    } else if(x == 1) {
      res.emplace_back(1);
      return res;
    }
    while (x != 1) {
      res.emplace_back(sieve[x]);
      x /= sieve[x];
    }
    return res;
  }
  vector<pair<int,int>> factorPair(int x) {
    vector<int> fl = factorList(x);
    vector<pair<int,int>> res(1, pair<int,int>(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) res.back().second++;
      else res.emplace_back(p, 1);
    }
    return res;
  }
};

int main() {
  int x;
  cin >> x;
  PrimeTable prime=PrimeTable(1e6);

  srep(i,x,x+10000) {
    if(prime.isPrime(i)) {
      cout << i << endl;
      break;
    }
  }


  return 0;
}


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

int num[100001];//the amount of water in the cup i
bool red[100001];//the cup i contains red water or not
int n, m;
int x, y, ans;
int main() {

    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
            num[i] = 1;
            red[i] = false;
    }
    red[1] = true;

    for (int i = 1; i <=m; i++) {
        scanf("%d %d", &x, &y);
        if (red[x] == true)
            red[y] = true;

        num[x]--;
        num[y]++;

        if (num[x] == 0)
            red[x] = false;
    }

    for (int i = 1; i <=n; i++)
        if (red[i])
            ans++;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

class Dice {
private:
	int surface[6];
	void next(int a, int b, int c, int d);


public:
	Dice(int surface[6]);
	Dice();
	void role(char dir);// W E N S
	void rot(char dir); //L or R
	void set(int pos, int num);
	int get(int pos);
};

int main(void) {
	Dice dice;

	for (int i = 0; 6 > i; i++) {
		int buf;
		scanf("%d", &buf);
		dice.set(i, buf);
		/*	char order;
			while (scanf(" %c", &order) != EOF) {
				dice.role(order);
		}*/
	}
	int n;
	scanf("%d", &n);
	for (int l = 0; n > l; l++) {
		int question[2];
		scanf("%d %d", &question[0], &question[1]);
		for (int i = 0; dice.get(0) != question[0] && 4 > i; i++)
			dice.role('N');
		if (dice.get(0) != question[0])
			for (int i = 0; dice.get(0) != question[0] && 4 > i; i++)
				dice.role('W');

		for (int i = 0; dice.get(1) != question[1] && 4 > i; i++)
			dice.rot('R');

		printf("%d\n", dice.get(2));
	}
	return 0;
}

void Dice::next(int a, int b, int c, int d)
{
	swap(surface[c], surface[d]);
	swap(surface[b], surface[c]);
	swap(surface[a], surface[b]);
}

Dice::Dice(int surface[6])
{
	for (int i = 0; 6 > i; i++)
		Dice::surface[i] = surface[i];
}

Dice::Dice()
{
	for (int i = 0; 6 > i; i++) surface[i] = 0;
}

void Dice::role(char dir)
{
	switch (dir) {
	case 'W': next(0,3,5,2);  break;
	case 'E': next(0,2,5,3);  break;
	case 'N': next(0,4,5,1);  break;
	case 'S': next(0,1,5,4);  break;
	}
}

void Dice::rot(char dir)
{
	switch (dir) {
	case 'L': next(1, 3, 4, 2); break;
	case 'R': next(1, 2, 4, 3); break;
	}
}

void Dice::set(int pos, int num)
{
	surface[pos] = num;
}

int Dice::get(int pos)
{
	return surface[pos];
}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
  
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] TA = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            double T = TA[0];
            double A = TA[1];
            double[] H = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();
            List<double> intlist = new List<double>();
            for(int i = 0; i < N; i++)
            {
                intlist.Add(Math.Abs((A - (T - H[i] * 0.006))));
            }
            Console.WriteLine(intlist.IndexOf(intlist.Min()) + 1);
        }
    }
}


Measured memory_bytes: 13444
#include <iostream>
#include <vector>
using namespace std;
int n,k;
vector<vector<int> > adj;
int parent[2001][11];
int dep[2001]={0,};
void dfs2(int here,int dad,int d){
    parent[here][0]=dad;
    dep[here]=d;
    for(int i=0;i<adj[here].size();i++){
        int there=adj[here][i];
        if(there==dad)
            continue;
        dfs2(there,here,d+1);
    }
}
int dfs(int here,int dad,int d,int mx){
    int ans=1;
    if(mx==d)
        return ans;
    for(int i=0;i<adj[here].size();i++){
        int there=adj[here][i];
        if(there==dad)
            continue;
        ans+=dfs(there,here,d+1,mx);
    }
    return ans;
}
int getLca(int u,int v){
    if(dep[u]>dep[v])
        swap(u,v);
    int d=dep[v]-dep[u];
    int i=0;
    while(d){
        if(d&(1<<i)){
            d-=(1<<i);
            v=parent[v][i];
        }
        i++;
    }
    if(u==v)
        return u;
    for(int i=10;i>=0;i--){
        if(parent[u][i]!=parent[v][i])
            u=parent[u][i],v=parent[v][i];
    }
    return parent[u][0];
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    adj.resize(n+1);
    for(int i=0;i<n-1;i++){
        int from,to;
        cin>>from>>to;
        adj[from].push_back(to);
        adj[to].push_back(from);
    }
    int ans=0;
    dfs2(1,-1,0);
    for(int i=1;i<11;i++){
        for(int j=1;j<=n;j++){
            if(parent[j][i-1]<0)
                parent[j][i]=-1;
            else
                parent[j][i]=parent[parent[j][i-1]][i-1];
        }
    }
    if(k%2==0){
        for(int i=1;i<=n;i++)
            ans=max(ans,dfs(i,-1,0,k/2));
    }
    else{
        for(int i=1;i<=n;i++){
            for(int s=0;s<adj[i].size();s++){
                int j=adj[i][s];
                ans=max(ans,max(ans,dfs(i,j,0,k/2)+dfs(j,i,0,k/2)));
            }
        }
    }
    cout<<n-ans;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
/*ll get(ll *arr,ll low,ll high,ll n){
	int mid=low+(high-low)/2;
	if((mid==0 or arr[mid-1]<=arr[mid]) and (mid==(n-1) or arr[mid+1]<=arr[mid])){
		return arr[mid];
	}
	else if(mid>0 and arr[mid-1]>arr[mid]){
		return get(arr,low,mid-1,n);
	}
	else{
		return get(arr,mid+1,high,n);
	}
}*/
/*ll get(int *arr,int n,int left,int i){
	if(i==n){return 1;}
	int curr=arr[i];
	int right=get(arr,n,arr[i]*left,i+1);
	arr[i]=left*right;
	return curr*right;
}*/
void solve(){
	ll n;cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){cin>>arr[i];}
	ll ans=0,cur=arr[0];
	for(int i=1;i<n;i++){
		if(arr[i]<cur){
			ans+=(cur-arr[i]);
		}
		else{
			cur=arr[i];
		}
	}
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case #"<<k<<": ";
		solve();
		//e;
	}
}


Measured memory_bytes: 5200
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 2e5 + 100;

ll n, k, h[N];
ll ans;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) 
		cin >> h[i];
	sort(h, h + n);
	for (int i = 0; i < n - k; i++)
		ans += h[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
n,x = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
ans = 0

for i in range(n):
    if a[0] < x :
        ans += 1
        x -= a[0]
        a.pop(0)
    else:
        if x in a:
            ans += 1
        x = 0
        break
if x != 0:
    ans -= 1
print(ans)


Measured memory_bytes: 3060
import numpy as np
import math
import collections
import bisect
from decimal import *


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return collections.Counter(a)


N = int(input())
ruisekiwa = [0]
for i in range(1, 50):
    ruisekiwa.append(i + ruisekiwa[i - 1])
PF = prime_factorize(N)

ans = 0
for v in PF.values():
    ans += bisect.bisect_right(ruisekiwa, v) - 1

print(ans)


Measured memory_bytes: 27168
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int p, q, a, n;

int gcd(int aa, int bb){
    if(bb == 0) return aa;
    return gcd(bb, aa % bb);
}

void dfs(int num, int mul, int last, int x, int y, int &ans){
    

    if(x * q == p * y){ 
        ans++;
        return;
    }

    if(p * y < x * q) return;

    if(num == n) return;

    for(int i = last;; i++){
        if(i * mul > a) break;
        int m = i * y;
        int c = y + i * x;

        if(p * m < c * q) continue;
        dfs(num + 1, mul * i, i, c, m, ans);
    }

    return;
}

signed main(){
    
    while(1){
        
        cin >> p >> q >> a >> n;
        if(a == 0) break;
        int g = gcd(p, q);
        p /= g;
        q /= g;
        
        int ans = 0;
        dfs(0, 1, 1, 0, 1, ans);

        cout << ans << endl;
    }

    return 0;
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;



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

    long long N,A,B;
    cin >> N >> A >> B;
    if((N<2 && A!=B) ||A>B ) cout << 0 << endl;
    else if(N<=2) cout << 1 << endl;
    else cout << (B-A)*(N-2LL)+1LL << endl;




}


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

int main(){ 
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string res;
  for (int i = 0; i < n; i++) {
    res += s[i];
    res += t[i];
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    ans = 0
    current = A[0]
    for a in A[1:]:
        if a >= current:
            current = a
        else:
            ans += (current - a)

    print(ans)


    

if __name__ == '__main__':
    main()



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

int main() {
  int N;
  vector<long long> A;

  cin >> N;
  int count = 0;
  for(int i=0;i<N;i++){
    int buf;
    cin >> buf;
    if(buf<0){
      count++;
      A.push_back(-buf);
    }else{
      A.push_back(buf);
    }
  }

  if(count%2==0){
    long long sum = 0;
    for(int i=0;i<N;i++){
      sum += A[i];
    }
    cout << sum << endl;
  }else{
    long long min=1000000000;
    for(int i=0;i<N;i++){
      if(min>A[i]){
        min = A[i];
      }
    }
    long long sum = 0;
    for(int i=0;i<N;i++){
      sum += A[i];
    }
    cout << ( sum - 2*min ) << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  ll ans = 1, T;
  for (int i = 0; i < N; i++) {
    cin >> T;
    ans = ans / __gcd(ans, T) * T;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
con = 0;
h,w,k = map(int,input().split());
gy = [0]*h
re = [0]*w
alist = [str(input()) for aaa in range(h)]
atuple = tuple(alist)
n = 0;
for a in range(h):
    n += alist[a].count('#');

for p in range(2**h):
    plist = list(atuple)
    delete = 0;
    for pp in range(h):
        if ((p >> pp) & 1):
            delete += plist[pp].count('#');
            plist[pp] = '.'*w

    for q in range(2**w):
        deletex = delete
        for qq in range(w):
            if ((q >> qq) & 1):
                for i in range(h):
                    v = plist[i]
                    if v[qq]== '#':
                        deletex += 1;
        
        if deletex + k == n:
            con += 1;

print(con);
                    
                    

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


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

int main()
{
	int a[4], b[4];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
		int hit = 0;
		for (int i = 0; i < 4; i++){
			if (a[i] == b[i])
				hit++;
		}
		int blow = 0;
		for (int i = 0; i < 4; i++){
			for (int j = 0; j < 4; j++){
				if (a[i] == b[j] && i != j){
					blow++;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
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));

		String str;
		String[] arrStr;
		StringBuilder output = new StringBuilder();
		int a,b;
		try {

			while(true){
				str = br.readLine();

				if(str.equals("0 0")){
					// ??????
					break;
				}

				arrStr = str.split(" ");
				a = Integer.parseInt(arrStr[0]);
				b = Integer.parseInt(arrStr[1]);

				if(a<b){
					output.append(a).append(" ").append(b).append("\n");
				}else{
					output.append(b).append(" ").append(a).append("\n");
				}
			}
			System.out.print(output.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 25040
N, K = map(int, input().split())
S = input()
T = []
if S[0] == '0': T.append(0)
cnt = 1
for i in range(1, N):
    if S[i - 1] == S[i]:
        cnt += 1
    else:
        T.append(cnt)
        cnt = 1
if cnt > 0: T.append(cnt)
if S[-1] == '0': T.append(0)
cs = [0] * (len(T) + 1)
n = 0
for i in range(1, len(T) + 1):
    n += T[i - 1]
    cs[i] = n

n = min(K * 2 + 1, len(T))
ans = 0
for i in range(1, len(T) - n + 2, 2):
    t = cs[i + n - 1] - cs[i - 1]
    if ans < t: ans = t
print(ans)


Measured memory_bytes: 7932
def main():
    n, m = [int(x) for x in input().split()]
    heights = tuple(int(x) for x in input().split())
    adjacents_heights = [set() for _ in range(n)]
    for i in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        adjacents_heights[a].add(heights[b])
        adjacents_heights[b].add(heights[a])
    ans = 0
    for h, ahs in zip(heights, adjacents_heights):
        if not ahs:
            ans += 1
            continue
        elif h > max(ahs):
            ans += 1

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 38976
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
c=s.count("R")
w=[0]*n
if c==0 or c==n:
    print(0)
    exit()
if s[0]=="W":
    w[0]=1
for i in range(1,n):
    w[i]=w[i-1]
    if s[i]=="W":
        w[i]+=1
print(w[c-1])

Measured memory_bytes: 74764
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    int ans = 0;
    for(int i=1; i<=N; i++) {
        int cnt = 0;
        for(int k=1; k<=i; k++) {
            if(i % k == 0) cnt++;
        }
        if(cnt == 8 and i%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N, D = LI()
    count = 0
    for i in range(N):
        x, y = LI()
        l = math.sqrt(x*x+y*y)
        if l <= D:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


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

int main() {
    string n;
    cin >> n;
    int x = 0;

    for (int i = 0; i < 3; i++) {
        if (n.at(i) == '7') {
           x = 1;
            break;
        }
    }

    if (x == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

char field[8][8];

void dfs(int x,int y){
	char a=field[y][x];
	field[y][x]='0';
	if(a=='1'){
		for(int i=-3;i<=3;i++){
			int ax,ay;
			ax=x+i;
			ay=y+i;
			if(0<=ax&&ax<8&&field[y][ax]=='1')dfs(ax,y);
			if(0<=ay&&ay<8&&field[ay][x]=='1')dfs(x,ay);
			}
		}
		return;
	}
	
int main(){
	int n;
	cin>>n;
	
	for(int x=1;x<=n;x++){
		for(int i=0;i<8;i++)
		for(int j=0;j<8;j++)cin>>field[i][j];
		
		int ax,ay;
		cin>>ax>>ay;
		dfs(ax-1,ay-1);
		
		cout<<"Data "<<x<<':'<<endl;
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++){
				cout<<field[i][j];
				}
				cout<<endl;
			}
			
		}
		return 0;
	}	

Measured memory_bytes: 3048
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);

		int n=s.nextInt();
		int[][][]a=new int[n][][];
		for(int i=0;i<n;++i) {
			int m=s.nextInt();
			a[i] = new int[m][2];
			for(int j=0;j<m;++j) {
				a[i][j][0]=s.nextInt()-1;
				a[i][j][1]=s.nextInt();
			}
		}
		int r=0;
		loop:
		for(int b=0;b<(1<<n);++b) {
			for(int i=0;i<n;++i)
				for(int[]q:a[i])
					if((b>>i&1)==1&&(b>>q[0]&1)!=q[1])
						continue loop;
			r=Math.max(r,Integer.bitCount(b));
		}
		System.out.println(r);
	}
}


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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int a, b, c;
	cin>>a>>b>>c;

	if(a==b && b==c && a%2==0){
		cout<<-1<<endl;
		return 0;
	}
	int cnt=0;
	while(!(a&1 || b&1 || c&1)){
		int A, B, C;
		A=(b+c)/2;
		B=(a+c)/2;
		C=(a+b)/2;
		a=A;
		b=B;
		c=C;
		cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}



Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
uf1=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf1.union(a-1,b-1)

for i in range(n):uf1.find(i)
X = uf1.par

ans = [0]*n
for i in range(n):
    ans[X[i]] += 1
    
print(max(ans))

Measured memory_bytes: 19992
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;


int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n); rep(i, n) cin >> a[i];
    rep(i, n) {
        a[i] -= 1;
        a[i] %= k;
    }

    vector<int> acum(n+1, 0);
    rep(i, n) {
        acum[i+1] = acum[i] + a[i];
        acum[i+1] %= k;
    }
    
    ll ans = 0;
    map<ll, ll> cnt;
    rep(i, n+1) {
        if (i >= k) cnt[acum[i-k]]--;
        ans += cnt[acum[i]]++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 14336
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n; cin >> n;
  map<i64, int> cnt;
  i64 M = (i64) 1e18;
  i64 ans = 0;
  for (int i = 0; i < n; ++i) {
    long double x; cin >> x;
    i64 a = rintl(x * 1000000000LL);
    i64 b = 1;
    int c2 = 0, c5 = 0;
    while (a % 2 == 0) {
      a /= 2;
      b *= 2;
      c2++;
      if (c2 == 18) break;
    }
    while (a % 5 == 0) {
      a /= 5;
      b *= 5;
      c5++;
      if (c5 == 18) break;
    }
    i64 p2 = 1;
    for (int j = 0; j <= 18; ++j) {
      i64 p5 = 1;
      for (int k = 0; k <= 18; ++k) {
        if (c2 + j >= 18 && c5 + k >= 18 && cnt.count(p2 * p5)) {
          ans += cnt[p2 * p5];
        }
        p5 *= 5;
      }
      p2 *= 2;
    }
    error(cnt);
    error(ans);
    cnt[b]++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3756
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

//累乗(aのk乗)
ll matpow(ll a,int k){
    ll dp=1,mt=a;
    while(k>0){
        if(k & 1) dp=(dp*mt)%mod;
        mt=(mt*mt)%mod;
        k/=2;
    }
    return dp;
}

int N;
vec fuc(200010),rev(200010),size(200010), dp(200010),ans(200010);
mat G(200010);
void DFS1(int s, int p){
    int res=0;
    each(t,G[s]){
        if(t==p) continue;
        DFS1(t,s);
        res+=1+size[t];
    }
    size[s]=res;
}
void DFS2(int s, int p){
    ll res=fuc[size[s]];
    each(t,G[s]){
        if(t==p) continue;
        DFS2(t,s);
        res=((rev[size[t]+1]*dp[t])%mod*res)%mod;
    }
    dp[s]=res;
}
void DFS3(int s, int p){
    if(s==1){
        ans[s]=dp[1];
    }
    else{
        ans[s]=( ( (size[s]+1) * matpow(N-1-size[s],mod-2) ) %mod * ans[p] ) %mod;
    }
    each(t,G[s]){
        if(t==p) continue;
        DFS3(t,s);
    }
}

int main(){
    cin>>N;
    rep(i,N-1){
        int a,b; scanf("%d %d",&a,&b);
        G[a].pb(b);
        G[b].pb(a);
    }
    fuc[0]=1;
    rep(i,N){
        fuc[i+1]=(fuc[i]*(i+1))%mod;
        rev[i+1]=matpow(fuc[i+1],mod-2);
    }
    DFS1(1,0);
    DFS2(1,0);
    DFS3(1,0);
    rep(i,N) cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 22512
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	r.Scan(true)
	a:=r.nextStringArray().toInts()

	MOD:=uint(pow(10,9,0)+7)

	cnt := make([]uint, 61)
	for _,ai:=range a{
		for i:=uint(0);i<=60;i++{
			cnt[i] +=(uint(ai) >> i)&1
		}
	}

	ans :=uint(0)
	for i, v:=range cnt{
		ans = (ans + ((v*(uint(n)-v))%MOD * ((1<<uint(i)) % MOD))) %MOD
	}
	
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 26112