akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        int count1 = 0;
        int count2 = 0;
        
        for(int i = 0; i < S.length(); i++){
            if(i%2 == 0) {
                if(S.charAt(i) == '1')
                    count1++;
            } else{
                if(S.charAt(i) == '0')
                    count1++;
            }
        }

        for(int i = 0; i < S.length(); i++){
            if(i%2 == 0) {
                if(S.charAt(i) == '0')
                    count2++;
            } else{
                if(S.charAt(i) == '1')
                    count2++;
            }
        }
        System.out.println(Math.min(count1, count2));
    }
}


Measured memory_bytes: 25336
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        a: [[usize]; k],
    }
    // annotate for rust-analyzer
    let (n, k) = (n as usize, k as usize);
    let a: Vec<Vec<usize>> = a;

    let mut map = HashMap::<usize, usize>::new();
    for i in 0..k {
        for di in 0..a[i].len() {
            *map.entry(a[i][di]).or_insert(0) += 1;
        }
    }

    println!("{}", n - map.len());
}


Measured memory_bytes: 2188
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
         int N = sc.nextInt();
         int D = sc.nextInt();
         int[] X = new int[N];
         int[] Y = new int[N];
         int ans = 0;
    
         for(int i = 0 ; i < N ; i++){
                X[i] = sc.nextInt();
                Y[i] = sc.nextInt();
                if(Math.sqrt(Math.pow(X[i],2)+Math.pow(Y[i],2)) <= D){
                    ans++;
                }
         }
         System.out.println(ans);
    }     
}


Measured memory_bytes: 51020
N, M, K = list(map(int, input().split()))
p = 998244353

comb = 1
res = 0
for n in range(K+1):
    res = (res + comb * M * pow(M-1, N-1-n, p)) % p
    comb = (comb * (N -1 -n) * pow(n + 1, p - 2, p)) % p

print(res)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i;
    string str, str1;
    vector<string>s;
    cin>>a;
    cin>>str>>str1;
    for(i=0;i<a;i++)
    {
        cout<<str[i]<<str1[i];
    }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rint register int
#define LL long long
#define maxn 20007
#define inf 1000000000
#define mod 100000007
#define	QAQ freopen ("cantor.in", "r", stdin); freopen ("cantor.out", "w", stdout);
using namespace std;
inline LL rf(){LL r,s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;%>
int main()
{
	//QAQ 
	LL n,a[101],ans=0;
	n=rf();
	for(int i=1;i<=n;i++)
	a[i]=rf();
	
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	ans=ans+a[i]*a[j];
	
	printf("%d",ans);
	
    return 0;
}
/*
We Secure. We Contain. We Protect
We programme. We submit. We accepted


JXU4RDc3JXU3ODAxJXVGRjBDJXU2NzAwJXU4RDc3JXU3ODAxJXVGRjBDJXU1MjFEJXU4RDVCJXU5MDFBJXU4RkM3JXVGRjAx
10
1 2 3 1 2  3 4 6 2 3


*/

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

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)


int main(){
    int h,w,d;
    cin>>h>>w>>d;
    P dist[d][h*w/d+1];
    rep(i,d) rep(j,h*w/d+1) dist[i][j]=make_pair(-1,-1);
    dist[0][0]=make_pair(0,0);
    rep(i,h) rep(j,w){
        int num;
        cin>>num;
        dist[num%d][num/d]=make_pair(i,j);
    }
    int diff[d][h*w/d+1];
    rep(i,d) rep(j,h*w/d+1){
        if(j)diff[i][j]=-1;
        else diff[i][j]=0;
    }
    rep(i,d) rep(j,h*w/d+1){
        if(dist[i][j].first==-1||dist[i][j+1].first==-1)break;
        diff[i][j+1]=abs(dist[i][j+1].first-dist[i][j].first)+abs(dist[i][j+1].second-dist[i][j].second);
    }
    rep(i,d) rep(j,h*w/d+1){
        if(diff[i][j]==-1||diff[i][j+1]==-1)break;
        diff[i][j+1]+=diff[i][j];
    }

    int q;
    cin>>q;
    rep(i,q){
        int ans=0;
        int l,r;
        cin>>l>>r;
        if(l!=r){
            ans+=diff[r%d][r/d]-diff[l%d][l/d];
        }
        cout<<ans<<endl;
    }
}
            



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fori(i,s,n) for(ll i=s;i<=n;i++)
#define ford(j,s,n) for(ll i=n;i>=s;i--)
#define pb push_back
#define TEST int t; cin>>t; for(int T=1;T<=t;T++)
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll sum=0;
    fori(i,1,n-1){
        sum+=(n/i);
        if(n%i==0) sum--;
    }
    cout<<sum;
    return 0;
}


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

int main() {
  long long ans=0,c=1;
  //cin>>N;
  string s;
  vector<long long> a(0);
  cin>>s;
  if(s[0]=='>'){
    a.push_back(1);
  }
  for(int i=0;i<s.size();i++){
    if(i==s.size()-1||s[i]!=s[i+1]){
      a.push_back(c);
      c=1;
    }
    else{
      c++;
    }
  }
  for(int i=0;i<a.size();i++){
    ans+=a[i]*(a[i]-1)/2;
    
  }
  if(a.size()%2){
    a.push_back(0);
  }
  for(int i=0;i<a.size()/2;i++){
    ans+=max(a[i*2],a[i*2+1]);
    //cout<<ans<<" ";
  }
  cout<<ans;
  
}


Measured memory_bytes: 3068
#include <stdio.h>

int n, m;
char N[100][9];
long long int M[100];
char B[1000][9];

bool input() {
  int i;

  scanf("%d %d", &n, &m);
  if(!n) return false;

  for (i = 0; i < n; i++) {
    scanf(" %s %d", N[i], &M[i]);
  }
  for (i = 0; i < m; i++) {
    scanf(" %s", B[i]);
  }

  return true;
}


int main() {
  int i, j, k;
  long long int sum;

  while (input()) {
    sum = 0;
    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < 8; k++) {
          if (N[j][k] == '*') continue;
          if (N[j][k] != B[i][k]) break;
        }
        if (k == 8) sum += M[j];
      }
    }

    printf("%d\n", sum);

  }

}

Measured memory_bytes: 0
#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 SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;

int main() {
	int x, n;
	cin >> x >> n;
	cout << max(x - n, 0) << endl;
	return 0;
}

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


int main(){
    int k;
    cin >> k;
    int ans = 0;
    rep(i, k) rep(j, k) rep(l, k) {
        ans += __gcd(i+1, __gcd(j+1, l+1));
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){

    unsigned long long n, a, b;
    
    cin >> n >> a >> b;
    
    unsigned long long result = 0;
    result += (n / (a+b)) * a;
    unsigned long long temp = n - (n/(a+b))*(a+b);

    if(a > 0) {
        if(temp >= a) result += a;
        else result += temp;        
    }

    
    cout << result << endl;

    return 0;
}


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

int main() {
    long long int n;
    cin>>n;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int h=(n/2)+1, l=n/2;
    cout<<a[h-1]-a[l-1];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    int sum = 0;

    if(s[0] == 'o') ++cnt;
    if(s[1] == 'o') ++cnt;
    if(s[2] == 'o') ++cnt;

    sum = 700 + cnt*100;

    cout << sum << endl;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

// int main()
// {
//     int n;
//     cin >> n;

//     vector<tuple<string, int, int>> v;
//     rep(i, n)
//     {
//         string s;
//         int p;
//         cin >> s >> p;
//         v.push_back(make_tuple(s, -p, i));
//     }

//     sort(all(v));

//     rep(i, n)
//     {
//         cout << get<2>(v[i]) + 1 << endl;
//     }
//     return 0;
// }
int main()
{
    int N;
    cin >> N;

    vector<tuple<string, int, int>> data;

    rep(i, N)
    {
        string s;
        int p;
        cin >> s >> p;
        data.push_back(make_tuple(s, -p, i + 1));
    }

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

    rep(i, N)
    {
        cout << get<2>(data[i]) << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int x;
    cin >> x;
    int res = 1;
    for (int i=2; i*i<=x; ++i) {
        int tmp = i*i;
        while (tmp * i <= x) tmp *= i;
        chmax(res, tmp);
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=(ll)2e9 +10, M=(ll)1e9+1 ;
const int mod =(ll)1e9+7 , MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

map<string,ll> m;

void work(){
	ll n,ans=0;
	cin >> n;
	vl a(n);
	map<ll,ll> b;
	for(ll i=0;i<n;i++){
		cin >> a[i];
		b[a[i]+i]++;
		if(i-a[i]>=0)
			ans+=b[i-a[i]];
	}

	cout << ans;
	return;
	
}

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// precomp();
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	
	}

	return 0;
}
	

Measured memory_bytes: 18332
#include <iostream>
using namespace std;
 int dfs(int n, int s, int x){
    int sum=0;
    if(n==0 && s==0)
    return 1;
    if(n>0){
        for(int i=x; i<10; i++){
            if(s-i>=0)  sum+=dfs(n-1, s-i, i+1);
        }
    }

    return sum;
}
 int main(void){
    int n, s;
    while(cin >> n >> s){
        if(n==0 && s==0)
    break;
        cout << dfs(n, s, 0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
N, M, C = map(int, input().rstrip().split(' '))
B = list(map(int, input().rstrip().split(' ')))

count = 0
for _ in range(N):
    A = list(map(int, input().rstrip().split(' ')))
    sum = C
    for x1, x2 in zip(A, B):
        sum += x1 * x2
    
    if sum > 0:
        count += 1
        
print(count)

Measured memory_bytes: 3060
n = int(input())
is_yes = False
 
for i in range(n):
    t, x, y = map(int, input().split())
    if (x + y <= t) & ((x + y + t) % 2 == 0):
        is_yes = True
    else:
        print("No")
        quit()
 
if is_yes:
    print("Yes")

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

int main() {
  int fir, las;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'A'){
      fir = i+1;
      break;
    }
  }
  for(int i = s.size()-1; i >= 0; i--){
    if(s.at(i) == 'Z'){
      las = i+1;
      break;
    }
  }
  cout << las - fir + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define rep(i,l,r) for(int i = l;i < r;i++)
#define per(i,l,r) for(int i = r - 1;i >= l;i--)
#define de(x) cout<<#x<<" = "<<x<<endl
#define dd(x) cout<<#x<<" = "<<x<<','
typedef long long ll;
int c[505],s[505],f[505];
int prime[100007] = {0},ans[100007] = {0};
int main()
{
	rep(i,2,1e5 + 7){
		if(prime[i] == 0){
			for(int t = i * 2;t < 1e5 + 7;t += i)
			prime[t] = 1;
		}
	}
	prime[1] = 1;
	rep(i,1,1e5 + 2){
		if(prime[i] == 0 && prime[(i + 1) / 2] == 0)
		ans[i] = ans[i - 1] + 1;
		else
		ans[i] = ans[i - 1];
	}
	int Q;
	cin>>Q;
	rep(i,0,Q){
		int a,b;
		scanf("%d%d",&a,&b);
		printf("%d\n",ans[b] - ans[a - 1]);
	}
	return 0;
}

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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

// const

// input

// valiable

// func

// main
void main2(){

  ll ans = 0;

  int n;cin >> n;
  vector<pair<ll,ll>> left,right;

  REP(i,n){
    int k;
    ll l,r;cin >> k >> l >> r;
    ans += min(l,r);
    if(l > r){
      left.emplace_back(l - r,k - 1);
    }else{
      right.emplace_back(r - l,k - 1);
    }
  }

  vector<vector<int>> lpos(n,vector<int>(0)),rpos(n,vector<int>(0));

  REP(i,(int)left.size()){
    lpos[left[i].second].push_back(i);
  }
  REP(i,(int)right.size()){
    rpos[right[i].second].push_back(i);
  }

  priority_queue<ll,vector<ll>,greater<ll>> L,R;

  for(int i = 0;i < n;i++){
    for(int j : lpos[i]){
      L.push(left[j].first);
    }
    while(L.size() > (i + 1)){
      L.pop();
    }
  }

  for(int i = n - 1;i >= 0;i--){
    for(int j : rpos[i]){
      R.push(right[j].first);
    }
    while(R.size() > (n - 1- i)){
      R.pop();
    }
  }
  while(L.size()){
    ans += L.top();
    L.pop(); 
  }

  while(R.size()){
    ans += R.top();
    R.pop(); 
  }

  cout << ans << '\n';
}
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int t;cin >> t;
  REP(_,t)main2();
  
}


Measured memory_bytes: 22920
ABCD=input()
A=ABCD[0]
B=ABCD[1]
C=ABCD[2]
D=ABCD[3]
for i in range((len(ABCD)-1)**2):
    aida=["-"]*(len(ABCD)-1)
    for j in range(len(ABCD)-1):
        if ((i>>j)&1):
            aida[len(ABCD)-2-j]="+"
    ks=A+aida[0]+B+aida[1]+C+aida[2]+D
    if eval(ks)==7:
        print(ks+"=7")
        exit()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n;
    int* h;
    cin >> n;
    h=new int[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int count=0;
    int count_max=0;
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            count++;
        }
        else{
            if(count_max < count){
                count_max=count;
            }
            count=0;
        }
    }
    if(count_max < count){
        count_max=count;
    }
    cout << count_max << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007
#define INF 100000008880LL
#define MIN(a,b) (a>b?b:a)
#define pii pair <ll,ll>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define piii pair<pair<ll,ll>,ll>
ll n,a,b,c,d;
char str[200005];
ll check(ll,ll),dc(ll,ll);
int main()
{
	cin>>n>>a>>b>>c>>d;
	scanf(" %s",str);
	a--,b--,c--,d--;
	if(c<d)
	{
		if(check(a,c)&&check(b,d))
		cout<<"Yes";
		else
			cout<<"No";
	}
	else
	{
		if(dc(b-1,d+1)&&check(a,c)&&check(b,d))
		cout<<"Yes";
		else
			cout<<"No";
	}

}
ll dc(ll a,ll b)
{
	rep(i,a,b-1)
	if(str[i]=='.'&&str[i+1]=='.'&&str[i+2]=='.')
		return 1;
	return 0;
}
ll check(ll a,ll b)
{
	rep(i,a,b)
	if(str[i]=='#'&&str[i+1]=='#')
		return 0;
	return 1;
}

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

int main(){
	// sengen
	int n,k;
	// nyuryoku
	cin >> n >> k;
	int h[n];
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	// keisan
	sort(h,h + n);
	long long sum = 0;
	for(int i=0;i<n-k;i++){
		sum += h[i];
	}
	// syutsuryoku
	cout << sum;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n,i,j;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    for(i=1;i<=n;i++)
    { cin>>a[i]>>b[i]>>c[i];
    }
    int d[n+1][3];
    d[0][0]=0,d[0][1]=0,d[0][2]=0;

    for(j=1;j<=n;j++)
    {
        d[j][0]=a[j]+max(d[j-1][1],d[j-1][2]);
        d[j][1]=b[j]+max(d[j-1][0],d[j-1][2]);
        d[j][2]=c[j]+max(d[j-1][1],d[j-1][0]);

    }
    if(d[n][0]>max(d[n][1],d[n][2]))
    {
        cout<<d[n][0]<<endl;
    }
    else{
       cout<< max(d[n][1],d[n][2])<<endl;
    }

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char a[200005];
    cin>>a;
    int dp[200005];int num=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='.')
            num++;
    }
    dp[0]=(a[0]=='.'?num-1:num);
    for(int i=1;i<n;i++)
    {
        if(a[i-1]=='.')
        {
            if(a[i]=='#')
                dp[i]=dp[i-1];
            else
                dp[i]=dp[i-1]-1;
        }
        else
        {
            if(a[i]=='#')
                dp[i]=dp[i-1]+1;
            else
                dp[i]=dp[i-1];
        }
    }
    sort(dp,dp+n);
    cout<<dp[0];
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <random>
using namespace std;

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

class Dice {
    vector<int> v;
public:
    Dice(int a, int b, int c, int d, int e, int f);
    int getTop();
    void east();
    void south();
    void north();
    void west();
    vector<int> getContents();
};

Dice::Dice(int a, int b, int c, int d, int e, int f) {
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    v.push_back(f);
}

int Dice::getTop() {
    return v[0];
}

void Dice::east() {
    vector<int> e;
    e.push_back(v[3]);
    e.push_back(v[1]);
    e.push_back(v[0]);
    e.push_back(v[5]);
    e.push_back(v[4]);
    e.push_back(v[2]);
    REP(i,6) v[i] = e[i];
}

void Dice::south() {
    vector<int> e;
    e.push_back(v[4]);
    e.push_back(v[0]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[5]);
    e.push_back(v[1]);
    REP(i,6) v[i] = e[i];
}

void Dice::north() {
    vector<int> e;
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    REP(i,6) v[i] = e[i];
}

void Dice::west() {
    vector<int> e;
    e.push_back(v[2]);
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    e.push_back(v[3]);
    REP(i,6) v[i] = e[i];
}

vector<int> Dice::getContents() {
    return v;
}

int getRight(int top, int front, Dice dice) {
    random_device rnd;
    while(1) {
        switch (rnd() % 4) {
            case 0:
                dice.west();
                break;

            case 1:
                dice.east();
                break;

            case 2:
                dice.north();
                break;

            case 3:
                dice.south();
                break;

            default:
                break;
        }
        vector<int> contents = dice.getContents();
        if (contents[0] == top && contents[1] == front) return contents[2];
    }
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    Dice dice(a,b,c,d,e,f);
    int n;
    cin >> n;
    REP(i,n) {
        int p, q;
        cin >> p >> q;
        cout << getRight(p, q, dice) << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int n,q,a[N],ca[N],p[N],freq[N];
bool vis[N],comp[N];

int par(int u) {
   return p[u] == u ? u : p[u] = par(p[u]);
}

void join(int u , int v) {
   p[par(u)] = par(v);
}

bool sameset(int u , int v) {
   return par(u) == par(v);
}

int main() {
   for (int i = 0 ; i < N ; i++) p[i] = i;
   scanf("%d%d" , &n , &q);
   for (int i = 1 ; i <= n ; i++) {
      scanf("%d" , &a[i]);
   }
   while (q--) {
      int u,v; scanf("%d%d" , &u , &v);
      join(u , v);
   }
   vector <int> keep[N],keep1[N];
   for (int i = 1 ; i <= n ; i++) {
      keep[par(i)].push_back(a[i]);
      keep1[par(i)].push_back(i);
   }
   int sol = 0;
   for (int i = 1 ; i <= n ; i++) {
      if (!vis[par(i)]) {
         vis[par(i)] = true;
         for (int j = 0 ; j < keep[par(i)].size() ; j++) {
            freq[keep[par(i)][j]]++;
            freq[keep1[par(i)][j]]++;
         }
         for (int j = 0 ; j < keep[par(i)].size() ; j++) {
            if (freq[keep[par(i)][j]] == 2 && !comp[keep[par(i)][j]]) {
               sol++;
               comp[keep[par(i)][j]] = true;
            }
            if (freq[keep1[par(i)][j]] == 2 && !comp[keep1[par(i)][j]]) {
               sol++;
               comp[keep1[par(i)][j]] = true;
            }
            freq[keep[par(i)][j]] = 0, freq[keep1[par(i)][j]] = 0;
         }
      }
   }
   printf("%d\n" , sol);
}


Measured memory_bytes: 12544
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
using namespace std;

int main() {
  int N, M; cin >> N >> M;
  int S[M]; char C[M];
  for(int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
    S[i]--;
  }

  for(int i = 0; i < 1000; i++) {
    string A = to_string(i);
    if(A.size() != N) continue;
    bool ok = true;
    for(int j = 0; j < M; j++) {
      if(A[S[j]] != C[j]) {
        ok = false;
        break;
      }
    }
    if(ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a*b // gcd(a,b)

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

A, B = map(int,input().split())

g = divisor(gcd(A,B))
#g.sort()

cnt = 0
for i in g:
    if len(divisor(i)) <= 2:
        cnt += 1

print(cnt)


Measured memory_bytes: 42456
#include<iostream>
#define MAX 10000

using namespace std;

int main(void){
	int i = 3;
	int n = 0;
	int ps[MAX] = {0,};
	
	ps[n++] = 2;
	while( n < MAX ){
		bool Skip = false;
		for(int j = 0; j < n; j++){
			if( i % ps[j] == 0 ){
				Skip = true;
				break;
			}
		}
		if( !Skip ) ps[n++] = i;
		i++;
	}

	while( 1 ){
		int n;
		int sum = 0;

		cin >> n;
		if( n == 0 ) break;

		for(int i = 0; i < n; i++){
			sum += ps[i];
		}

		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況


int main() {
    // input
    int n, m;
    cin >> n >> m;
    vi x(m);
    rep(i, m) {
        cin >> x[i];
    }
    // solve
    sort(ALL(x));
    vi y(m-1);
    rep(i, m-1) {
        y[i] = x[i+1] - x[i];
    }
    sort(ALL(y));
    // output
    // if (m-n < 0) {
    //     cout << 0 << "\n";
    // } else {
        int sum = 0;
        rep(i, m-n) {
            sum += y[i];
        }
        cout << sum << "\n";
    // }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a,b,x;
int32_t main(){
CODE_START;
cin>>a>>b>>x;
if(b==1){
    rc(0);
}
x=min(x,b-1);
ll val=a*x/b;
ll val2=x/b;
val2=val2*a;
cout<<val-val2<<endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
string str[2][51];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cin >> str[0][i];
	}
	for(int i=0;i<m;i++){
		cin >> str[1][i];
	}
	bool flag=false;
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			bool flag2=true;
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(str[1][k][l]!=str[0][i+k][j+l])flag2=false;
				}
			}
			if(flag2)flag=true;
		}
	}
	printf("%s\n",flag?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() { 
  int n;
  cin >> n;
  vi c(n),s(n),f(n);

  rep(i,n-1){
    cin >> c[i] >> s[i] >> f[i];
  }

  vi d(n,0);
  
  rep(i,n-1){
    int total = 0;
      total += s[i];
      total += c[i];
    srep(j,i+1,n-1){
      if(total < s[j]) total = s[j];
      int wt = (total-s[j])%f[j];
      if(wt!= 0)
        total+= f[j]-wt;
      total+=c[j];
    }
    cout<<total<<endl;
  }
  cout<<0<<endl;
  return 0; 
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
        // 文字列の入力
        int b = a.length();
        int c = b / 2;
        for(int i = 0;i < b / 2;i++){
            if(a.substring(i, i + 1).equals(a.substring(b - i - 1,b - i))){
                c--;
            }
        }
		System.out.println(c);
		
		
	}
}

Measured memory_bytes: 35580
import java.util.Scanner;
public class Main{
	int x,y;
	public void solve(){
		Scanner sc=new Scanner(System.in);
		x=sc.nextInt();
		
		y=x*x*x;
		System.out.print(y);
		System.out.println();
	}
	public static void main(String[] args){
		Main obj=new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17312
import numpy as np
n = int(input())

aab = []

for i in range(n):
    a, b = map(int, input().split())
    aab.append([a + b, a, b])

aab.sort(reverse=True)
aab = np.array(aab)

a = aab[:, 1][0::2].sum()
b = aab[:, 2][1::2].sum()

print(a - b)

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 20;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static int n, e;
	static int[][] dest, dp;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextInt(); e = in.nextInt();
			dest = new int[n][n];
			dp = new int[1 << n][n];

			for (int i = 0; i < n; i++) {
				Arrays.fill(dest[i], INF);
			}
			for (int i = 0; i < (1 << n); i++) {
				Arrays.fill(dp[i], -1);
			}

			for (int i = 0; i < e; i++) {
				int s = in.nextInt(), t = in.nextInt(), d = in.nextInt();
				dest[s][t] = d;
			}

			int ans = rec(0, 0);
			out.println(ans == INF ? -1 : ans);
		}

		int rec(int S, int v) {

			if (dp[S][v] >= 0) {
				return dp[S][v];
			}

			if (S == (1 << n) -1 && v == 0) {
				return dp[S][v] = 0;
			}

			int res = INF;
			for (int u = 0; u < n; u++) {
				if (((S >> u) & 1) == 0) {
					res = Math.min(res, rec(S | (1 << u), u) + dest[v][u]);
				}
			}

			return dp[S][v] = res;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

	static void print(int[][] dp) {
		int n = dp.length;
		int m = dp[0].length;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				System.out.print(dp[i][j] + " ");
			}
			System.out.print("\n");
		}
		System.out.print("\n");
	}

}



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

vector<ll> fac(1e6), finv(1e6), inv(1e6);
const ll MOD = 1e9+7;

//テーブルを作る前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i = 2;i < 1e6; ++i){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    COMinit();
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; ++i) cin >> a[i];
    sort(ALL(a));
    ll ans = 0;
    if(k == 1) {
        cout << 0 << endl;
        return 0;
    }
    for(ll i = 0; i < n;++i){
        ans += (COM(i,k-1) * a[i])% MOD;
        ans %= MOD;
    }
    for(ll i = 0; i < n;++i){
        ans -= (COM(n-i-1,k-1) * a[i]) % MOD;
        if(ans < 0) ans += MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
	int n, k;
	cin>>n>>k;
	int arr[200005];

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

	int xx=0;
	int aa=0;
	for (int j = 0; j < k; ++j)
	{
		aa+=arr[j];
	}
	xx=aa;
	for (int i = 1; i < n-k+1; ++i)
	{
		aa-=(arr[i-1]-arr[i+k-1]);
		if(aa>xx) xx=aa;
	}
	//cout<<<<endl;
	printf("%.15lf\n", (double)(xx+k)/2);
	return 0;
}

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

int N, M, X;
int price[15];
int books[15][15];
int isChoosed[15];
int minSum = 1<<30;

void check() {
	int judge = 1;
	int sum = 0;
	for (int i = 0; i < M; i++) {
		int isX = 0;
		judge = 1;
		for (int j = 0; j < N; j++) {
			if (isChoosed[j] == 1) {
                isX += books[j][i];
			}
		}
		if (isX < X) {
			judge = 0;
			break;
		}
	}
	if (judge == 1) {
		for (int i = 0; i < N; i++) {
			if (isChoosed[i] == 1) {
				sum += price[i];
			}
		}
		if (sum < minSum) {
			minSum = sum;
		}
	}
}

void dfs(int k) {
	if (k == N) {
		check();
		return;
	}
	for (int i = 0; i <= 1; i++) {
		isChoosed[k] = i;
		dfs(k + 1);
	}
}

int main() {
	cin >> N >> M >> X;
	
	memset(isChoosed, 0, sizeof(isChoosed));
	for (int i = 0; i < N; i++) {
		cin >> price[i];
		for (int j = 0; j < M; j++) {
			cin >> books[i][j];
		}
	}
	dfs(0);
	if (minSum == 1 << 30) {
		cout << "-1" << endl;
	}
	else {
        cout << minSum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3596
#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, M, Q;
	cin >> N >> M >> Q;

	vector<vector<Int>> x(N,vector<Int>(N));
	Int L, R;
	for (Int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		x[L][R]++;
	}

	//累積和
	vector<vector<Int>> s(N+1, vector<Int>(N+1));
	for (Int i = 0; i < N; i++) {
		for (Int j = 0; j < N; j++) {
			s[i][j + 1] = s[i][j] + x[i][j];
		}
	}

	//クエリ
	Int p, q;
	for (Int i = 0; i < Q; i++) {
		cin >> p >> q;
		p--;
		q--;

		Int ans = 0;
		for (Int j = p; j <= q; j++) {
			ans += s[j][q + 1] - s[j][p];
		}

		//cout << ans << "\n";
		printf("%lld\n", ans);
	}

}


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

int main() {
  int r, g, b, n, i, j, k, ans = 0;
  cin >> r >> g >> b >> n;
  
  for(i = 0; i <= n / r; i++){
    for(j = 0; j <= n - i * r; j++){
      if((n - (i * r + j * g)) % b == 0 && n - (i * r + j * g) >= 0){
        ans++;
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim()
        .split_whitespace()
        .map(|e| e.trim().parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read_as_vec::<i32>();

    let a = n[0];
    let b = n[1];
    let c = n[2];
    let d = n[3];

    let mut taka = c / b;
    if c % b > 0 {
        taka += 1;
    }

    let mut aoki = a / d;
    if a % d > 0 {
        aoki += 1;
    }

    if taka <= aoki {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, m;
	cin >> n >> m;
	int road[n][n] = {};
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		road[a][b]++;
		road[b][a]++;
	}
	rep(i, n){
		int ans = 0;
		rep(j, n){
			ans += road[i][j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
leng = []
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
    else:
        leng.append([s[i], cnt])
        cnt = 1
if s[-1] == "(":
    leng.append(["(", cnt])
else:
    leng.append([")", cnt])
if s[0] == ")":
    leng.insert(0,["(", leng[0][1]])
if s[-1] == "(":
    leng.insert(len(leng),[")", leng[-1][1]])

leng2 = []
for i in range(0, len(leng), 2):
    l = leng[i]
    r = leng[i+1]
    if l[1] == r[1]:
        pass
    elif l[1] < r[1]:
        leng2.append([")",r[1]-l[1]])
    else:
        leng2.append(["(", l[1]-r[1]])

lc = 0
rc = 0
for i in range(len(leng2)):
    if leng2[i][0] == "(":
        lc += leng2[i][1]
    else:
        rc += leng2[i][1]
    if rc - lc > 0:
        leng[0][1] += rc-lc
        lc = 0
        rc = 0
leng[-1][1] += lc-rc

ans = []
for i in range(len(leng)):
    tar = leng[i]
    for j in range(tar[1]):
        ans.append(tar[0])
print("".join(ans))










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

using namespace std;

using ll = long long;

int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; ++i) {
    for (ll j = i; j <= 3500; ++j) {
      if (4 * i * j - n * i - n * j <= 0)
        continue;
      if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
        cout << i << " " << j << " "
             << (n * i * j) / (4 * i * j - n * i - n * j) << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back

int abs(int a){
    return ( a>0 ? a : -a );
}

int main(void){
    ll n,m;
    cin >> n >> m;
    vl a(n);
    rp(i,n){
        cin >> a.at(i);
    }
    
    vl s(n);
    s.at(0)=a.at(0);
    
    lrep(i,1,n-1){
        s.at(i)=s.at(i-1)+a.at(i);
    }
    lrp(i,n){
        s.at(i) %= m;
    }
    sort(s);
    ll i=0;
    vl t;
    ll ans=0;
    while(i<s.size()){
        ll cnt=0;
        while(i<s.size()-1&&s.at(i)==s.at(i+1)){
            if(s.at(i)==0){
                ans++;
            }
            cnt++;
            i++;
        }
        if(s.at(i)==0){
            ans++;
        }
        if(cnt!=0){
            t.pb(cnt+1);
        }
        i++;
    }
    lrp(j,t.size()){
        ans += (t.at(j)*(t.at(j)-1))/2;
    }
    cout << ans << endl;
    
    return 0;
}






Measured memory_bytes: 2176
#include<stdio.h>
void q(int a[],int s,int t){if(s<t){int i=s,j=t,p=a[(s+t)/2];while(1){while(a[i]>p)i++;while(p>a[j])j--;if(i>=j)break;a[i]^=a[j]^=a[i]^=a[j];i++;j--;}q(a,s,i-1);q(a,j+1,t);}}
int main(){
  int a[100],n,i,x=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  q(a,0,n-1);
  for(i=0;i<n;i++)x+=a[i]*(1-i%2*2);
  printf("%d",x);
}


Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> city(n, 0);
  int a[m], b[m];
  
  for(int i=0; i<m; ++i){
    cin >> a[i] >> b[i];
    city[a[i]-1]++;
    city[b[i]-1]++;
  }
  for(int i=0; i<n; ++i){
    cout << city[i] << endl;
  }
}

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

ll A[100010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

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

	ll sum = 0;
	for(int i = 0; i < N + 1; i++){
		sum += abs(A[i] - A[i + 1]);
	}

	for(int i = 1; i <= N; i++){
		ll ans = sum;
		ans -= abs(A[i] - A[i + 1]);
		ans -= abs(A[i] - A[i - 1]);
		ans += abs(A[i - 1] - A[i + 1]);
		cout << ans << endl;
	}
}


Measured memory_bytes: 2048
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, MOD = 1e9 + 7;
const int SQ =225;
const long double EPS = 1e-7;

ll a[5005];
ll b[5005][205];
ll dp[5005][5005];
int n, m;
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n >> m;

  a[0] = 0;

  f(i,1,n){
    cin >> a[i];
    a[i] += a[i-1];
  }

  f(i,0,n)
    f(j,0,m)
      cin >> b[i][j];

  f(ticket,0,m){
    vector<int> v;
    f(i, 0, n)
      v.pb(b[i][ticket]);
    vector<int> lft(n), rt(n);
    stack<int> stk;
    f(i, 0, n){
      ///find the first one to my left >= me
      while(stk.size() && v[stk.top()] < v[i])stk.pop();
      lft[i] = -1;
      if(stk.size())lft[i] = stk.top();
      stk.push(i);
    }
    while(stk.size())stk.pop();
    for(int i = n - 1; i >= 0; --i){
      ///find the first one to my right > me
      while(stk.size() && v[stk.top()] <= v[i])stk.pop();
      rt[i] = n;
      if(stk.size())rt[i] = stk.top();
      stk.push(i);
    }

    f(i,0, n){
      ///i want to add v[i]
      ///to all elements dp[lft[i]->i][i->rt[i]]
      dp[i][i] += v[i];
      if(lft[i]!=-1)dp[lft[i]][i] -= v[i];
      if(rt[i] != n)dp[i][rt[i]] -= v[i];
      if((lft[i]!=-1)&&rt[i]!=n)dp[lft[i]][rt[i]] += v[i];
    }
  }
  ll ans = 0;
  for(int i = n - 1; i >= 0; --i)
    f(j,0,n){
      if(i==n-1)dp[i][j] += dp[i][j-1];
      else if(j == 0)dp[i][j] += dp[i+1][j];
      else dp[i][j] = dp[i][j] + dp[i][j-1] + dp[i+1][j] - dp[i+1][j-1];
      if(j>=i)
        ans = max(ans, dp[i][j] - (a[j] - a[i]));
    }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 204032
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    ll a, b;

    while(cin >> n >> a >> b)
    {
		for(i = a; i <= b; i++)
		{
			if(i % n == 0) break;
		}

		if(i <= b) printf("OK\n");
		else printf("NG\n");
    }


}





Measured memory_bytes: 3592
N , K = map(int,input().split())
l = list(map(int,input().split()))

pref_sum = [None]* (N+1)
pref_sum[0] = 0
pref_sum[1] = (1/l[0]) * ((l[0] * (l[0]+ 1)) / 2)

for i in range(1, N):
    t = (1/l[i]) * ((l[i] * (l[i]+ 1)) / 2)
    pref_sum[i+1] = t + pref_sum[i]

ans = -float("inf")

for i in range(K, N+1):
    ans = max(ans, pref_sum[i] - pref_sum[i-K])


print(ans)

Measured memory_bytes: 71792
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(i, m, n) for(int i = m; i < n; i++)
    #define rep3(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    rep(i,N)cin >> s[i];
    SORT(s);
    int count =1;
    rep(i,s.size()-1)if(s[i]!=s[i+1])count++;
    
    cout << count;
    return 0;
}

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

using namespace std;

int main(){
    int N;
    int A[200000];
    
    cin >> N;
    for(int i = 0; i < N;i++){
        cin >> A[i];
    }
    int l = 0;
    int r = N;
    while(r-l > 1){
        map<int, int> m;
        int c = (r+l)/2;
        m[A[0]] = 1;
        bool judge = true;
        for(int i = 1; i < N; i++){
            if(A[i] > A[i-1]){
                m[A[i]] = 1;
            }else{
                if(m.find(A[i]) == end(m)){
                    if(c >= 2)m[A[i]] = 2;
                    else{
                        judge = false;
                        break;
                    }
                    //cout << A[i] << ' ' << m[A[i]] << endl;
                }else{
                    for(int j = A[i]; j >= 1; j--){
                        if(m.find(j) != end(m) && m[j] < c) {
                            m[j] += 1;
                            //cout << j << ' ' << m[j] << endl;
                            break;
                        }else if(m.find(j) == end(m)){
                            m[j] = 1;
                            break;
                        }else{
                            m[j] = 1;
                        }
                        //むり
                        if(j == 1){
                            judge = false;
                            //cout << c << endl;
                        }
                    }
                    if(!judge) break;
                }
                auto iter = m.find(A[i]);
                iter++;
                m.erase(iter, end(m));
            }
        }
        if(judge){
            r = c;
        }else{
            l = c;
        }
    }
    cout << r << endl;
}

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

ten, min_not_ten, sumall = 0, 10000, 0
for i in range(n):
	a = int(input())
	if a % 10 == 0:
		ten += 1
	else:
		min_not_ten = min(min_not_ten,a)
	sumall += a


if ten == n:
	print(0)
elif sumall % 10 != 0:
	print(sumall)
else:
	print(sumall-min_not_ten)


Measured memory_bytes: 3060
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		int cnt=0;
		char[] c = null;
		for (i = a; i <= b; i++) {
			c = String.valueOf(i).toCharArray();
			if(c[0]==c[4]&&c[1]==c[3]) {
				cnt++;
			}
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 28628