akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l1 = []
l2 = []
for i in range(n):
    if i % 2 == 0:
        l1.append(v[i])
    else:
        l2.append(v[i])
if Counter(l1).most_common()[0][0] != Counter(l2).most_common()[0][0]:
    print(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[0][1])
elif min(len(set(l1)), len(set(l2))) >= 2:
    print(min(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[1][1], len(l1)-Counter(l1).most_common()[1][1]+len(l2)-Counter(l2).most_common()[0][1]))
elif len(set(l1)) > 1:
    print(len(l1)-Counter(l1).most_common()[1][1]+len(l2)-Counter(l2).most_common()[0][1])
elif len(set(l2)) > 1:
    print(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[1][1])
else:
    print(n//2)

Measured memory_bytes: 121132
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((a == b) && (b == c)) {
        cout << "1\n";
    } else if((a == b) || (b == c) || (c == a)) {
        cout << "2\n";
    } else {
        cout << "3\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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


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

	int res = 0;

	for (int i = 0; i < n; i++) 
		for (int j = i+1; j < n; j++) {
			res += d[i] * d[j];
		}


	cout << res;

	return 0;

}

Measured memory_bytes: 3676
s = input()

i = list(s)

answer = []

for num in i:
    if num == '0':
        answer.append(num)
    elif num == '1':
        answer.append(num)
    else:
        if answer == []:
            continue
        else:
            answer.pop()

for num in answer:
    print(num,end='')

Measured memory_bytes: 8928
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}




int main(){
  int N;
  cin>>N;
  int h[N];
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  int siten=0;
  int x=N;
  int sum=0;
  while(true){
    /*sleep(1);
    for(int i=0;i<N;i++){
      cout<<h[i]<<endl;

    }
    cout<<"666666666666"<<endl;*/
    
    int xx[N+3];
    for(int i=0;i<N;i++){
      xx[i]=0;
    }

    int l=1;
    xx[0]=-1;
    for(int i=0;i<N;i++){
      if(h[i]==0){
        xx[l]=i;
        l++;
      }
    }
    xx[l]=N;
    l++;
    int max=-1;
    for(int i=0;i<l-1;i++){
      if(xx[i+1]-xx[i]>max&&xx[i+1]-xx[i]!=1){
        siten=xx[i]+1;
        x=xx[i+1];
        max=xx[i+1]-xx[i];

      }
    }
    if(xx[l-1]!=N-1){
      if(max<N-xx[l-1]){
        siten=xx[l-1]+1;
        x=N;
      }
    }
    int count=0;
    int k;
    for(int i=0;i<N;i++){
      if(h[i]!=0){
        k=i;
        count++;
      }
    }
    if(count==1){
      sum+=h[k];
      h[k]=0;
    }
    
    
    
    bool ok=false;
    for(int i=0;i<N;i++){
      if(h[i]!=0){
        break;
      }
      if(i==N-1){
        ok=true;
      }
    }
    if(ok){
      break;
    }
    for(int i=siten;i<x;i++){
      h[i]--;
    }
    sum++;



  }
  cout<<sum<<endl;




  

  



}


  
  


  


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
  
  int nokori;
  nokori = N % 500;
  if (nokori <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main()
{
	int a, b, r;
	string z;
	while (1) {
		cin >> a >> z >> b;
		if (z == "+") cout << a + b << endl;
		else if (z == "-") cout << a - b << endl;
		else if (z == "*") cout << a * b << endl;
		else if (z == "/") cout << a / b << endl;
		else break;
	}
}


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

#define tc		int t;cin>>t;while(t--)
#define int		long long
#define pb 		push_back
#define mp		make_pair	
#define ff		first
#define ss		second
#define pii		pair<int,int>
#define vi		vector<int>
#define pqi		priority_queue<int>
#define pqd		priority_queue<int,vi,greater<int>>
#define inf		LLONG_MAX
#define mod		1000000007


int32_t main(){

	int h,w;
	cin>>h>>w;
	char grid[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)
			cin>>grid[i][j];
	}

	int dp[h][w];
	memset(dp,0,sizeof(dp));
	int i=0;
	while(i<h && grid[i][0]!='#'){
		dp[i][0]=1;
		i++;
	}
	int j=0;
	while(j<w && grid[0][j]!='#'){
		dp[0][j]=1;
		j++;
	}

	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			if(grid[i][j]!='#'){
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			}
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int s[n];
  int i,count=0;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  for(i=0;i<n;i++){
    if(s[i]>=k){
      count++;
    }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long a;
        a = sc.nextLong();
        long b;
        b = sc.nextLong();
        long c;
        c = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(a, b, c);
    }
}

class Solver {
    public void solve(long a, long b, long c) {
        if (a + b + c < 22) {
            System.out.println("win");
        }
        else {
            System.out.println("bust");
        }
    }
}



Measured memory_bytes: 23636
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

double round(double);

int main()
{
	int i, n;
	double x1, y1, x2, y2, x3, y3;
	double px, py, r;
	double a1, a2, b1, b2, c1, c2;

	scanf("%d", &n);

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

		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		
		a1 = 2*(x1-x2);
		a2 = 2*(x2-x3);
		b1 = 2*(y1-y2);
		b2 = 2*(y2-y3);
		c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
		c2 = x2*x2 - x3*x3 + y2*y2 - y3*y3;

		px = (b2*c1 - b1*c2) / (a1*b2 - b1*a2);
		py = (a1*c2 - a2*c1) / (a1*b2 - b1*a2);
		r = sqrt(pow((x1-px),2)+pow((y1-py),2));

		px = px * 1000;
		py = py * 1000;
		r = r * 1000;

		px = round(px);
		py = round(py);
		r = round(r);

		px = px / 1000;
		py = py / 1000;
		r = r / 1000;

		if(fabs(px) < 1e-6)
			px = 0;
		if(fabs(py) < 1e-6)
			py = 0;
		if(fabs(r) < 1e-6)
			r = 0;

		printf("%5.3f %5.3f %5.3f\n", px, py, r);

	}
	return 0;
}

double round(double x)
{
	if(x>=0)
		x = floor(x + 0.5);
	else
		x = -1.0 * floor(fabs(x) + 0.5);
	return x;
}

Measured memory_bytes: 668
#include<bits/stdc++.h>
using namespace std;
int F[1003];
/*int Find(int a)
{
    return F[a]==0?a:Find(F[a]);
}
void same(int a,int b)
{
    int x,y;
    x=Find(a);
    y=Find(b);
    if(x!=y)F[x]=y;
}*/
int s[19];
int sum;
int Max;

int main()
{
  /*int t;
  cin>>t;
  while(t--)
  {memset(F,0,sizeof(F));
      int n,m;
      cin>>n>>m;
      while(m--)
      {
          int a,b;
          scanf("%d%d",&a,&b);
          same(a,b);
      }
      for(int i=1;i<=)
  }*/
  long long n;
  cin>>n;

int xx;xx=0;
while(n)
{  if(n%10==9)xx++;
    s[sum++]=n%10;
    n/=10;
}
 int x;x=0;
  if(xx==sum)cout<<9*sum;
  else if(s[sum-1]!=9&&xx+1==sum)
  {
      for(int i=0;i<sum;i++)
        x+=s[i];
      cout<<x;
  }
  else{
    cout<<9*(sum-1)+s[sum-1]-1;
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a * b == (a * b / 2) * 2) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

int dp[3002][3002];

int main() 
{
    fastio;
   
    string s,t;
    cin>>s>>t;

    int n=s.length();
    int m=t.length();

    memset(dp,0,sizeof dp);

    range(i,1,n+1)
    {
      range(j,1,m+1)
      {
         if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
         else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }

   int id=dp[n][m];
   char str[id+1];
   str[id]='\0';

   int i=n,j=m;

   while(i>0&&j>0)
   {
      if(s[i-1]==t[j-1])
      {
        str[id-1]=s[i-1];
        i--;j--;id--;
      }

      else if(dp[i-1][j]>dp[i][j-1])
        i--;
      else j--;
   }

   cout<<str;

    
}

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

using namespace std;
typedef long long ll;
int N;
ll a[300001];
vector<ll>r_sum,b_sum;

int main() {
  cin >> N;

  for(int i = 0; i < N * 3; i++) cin >> a[i];

  priority_queue<ll,vector<ll>,greater<ll> >red;
  priority_queue<ll> blue;

  r_sum.push_back(0);
  b_sum.push_back(0);
  
  for(int i = 0; i < N; i++) {
    red.push(a[i]);
    blue.push(a[3*N-1-i]);
   
      r_sum.push_back(a[i] + r_sum[i]);
      b_sum.push_back(a[3*N-1-i] + b_sum[i]);
    }

  for(int k = N; k < N * 3 - N; k++) {
    ll rr = red.top(); red.pop();
    ll bb = blue.top(); blue.pop();
    //cout << rr <<"  "<<bb<<endl;
    r_sum.push_back(r_sum[k] - rr);
    b_sum.push_back(b_sum[k] - bb);
    if(rr < a[k]) {
      rr = a[k];
    }
    if(bb > a[3*N-1-k]){
      bb = a[3*N-1-k];
    }
    r_sum[k+1] += rr;
    b_sum[k+1] += bb;
    //cout <<r_sum[k+1]<<"   "<<b_sum[k+1]<<endl;
    red.push(rr);
    blue.push(bb);
  }

  ll ans = -1e16;;

  for(int i = N; i < r_sum.size(); i++) {
    //   cout << r_sum[i] <<"   "<<b_sum[3*N-i]<<endl;
    ans = max(ans,r_sum[i]-b_sum[3*N-i]);
  }

  cout << ans << endl;
}
    
    
    

  
  


Measured memory_bytes: 7500
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    comb = Combination(1000000)
    for i in range(1,K+1):
        if i > N - K + 1:
            print(0)
            continue
        ans = comb(N-K+1,i)
        ans *= comb(K-1,K-i)
        ans %= MOD
        print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 125384
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);

int main(void)
{
	int n,i,j,a[100],v;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	printf("%d",a[0]);
	for(i=1;i<n;i++)	printf(" %d",a[i]);
	printf("\n");
	for(i=1;i<n;i++)	{
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v)	{
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		printf("%d",a[0]);
		for(j=1;j<n;j++)	printf(" %d",a[j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2616
import java.util.Scanner;

public class Main {

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

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int R = sc.nextInt();
    	int G = sc.nextInt();
    	sc.close();
    	System.out.println(2 * G - R);
    }
}

Measured memory_bytes: 22228
A,B,C,K=list(map(str,input().split()))
if K[-1]=='0' or K[-1]=='2' or K[-1]=='4' or K[-1]=='6' or K[-1]=='8':
    ans=int(A)-int(B)
    if len(str(ans))>18:
        print('unfair')
    else:
        print(ans)
else:
    ans=int(B)-int(A)
    if len(str(ans))>18:
        print('unfair')
    else:
        print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main()
{
    ll a, b, n, m;
    cin >> n >> m;
    a = max(n, m);
    b = min(n, m);
    if (a - b > 1) {
        cout << 0 << "\n";
        return 0;
    }
    ll ans = 1;
    if (a == b) {
        ans = 2;
        for (int i = a; i >= 1; i--) {
            ans = ans * i % mod * i % mod;
        }
    } else {
        ans = a;
        for (int i = b; i >= 1; i--) {
            ans = ans * i % mod * i % mod;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-9 17:12:21
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
string S[110];
string T[110];
map<string, int> X;

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> S[i];
  }
  cin >> M;
  for (auto i = 0; i < M; i++)
  {
    cin >> T[i];
  }
  for (auto i = 0; i < N; i++)
  {
    if (X.find(S[i]) == X.end())
    {
      X[S[i]] = 1;
    }
    else
    {
      X[S[i]]++;
    }
  }
  for (auto i = 0; i < M; i++)
  {
    if (X.find(T[i]) == X.end())
    {
      X[T[i]] = -1;
    }
    else
    {
      X[T[i]]--;
    }
  }
  int ans = 0;
  for (auto x : X)
  {
    ans = max(x.second, ans);
  }
  cout << ans << endl;
}

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

int n;
int a[200005], b[200005];
int cnta[200005], cntb[200005];
vector <int> invalid, unused;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	for (int i = 0; i < n; i++) cnta[a[i]]++;
	for (int i = 0; i < n; i++) cntb[b[i]]++;
	for (int i = 1; i <= n; i++) {
		if (cnta[i] + cntb[i] > n) {
			printf("No\n");
			return 0;
		}
	}
	reverse(b, b + n);
	int same = -1;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			invalid.push_back(i);
			same = a[i];
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (cnt >= invalid.size()) break;
		if (a[i] != b[i] && a[i] != same && b[i] != same) {
			cnt++;
			unused.push_back(i);
		}
	}
	for (int i = 0; i < invalid.size(); i++) {
		swap(b[invalid[i]], b[unused[i]]);
	}
	printf("Yes\n");
	for (int i = 0; i < n; i++) printf("%d ", b[i]);
	printf("\n");
	return 0;
}


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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	ll b[n-1];
	rep(i, n-1) cin >> b[i];

	ll ans = b[0];
	rep(i, n-2){
		ans += min(b[i], b[i+1]);
	}
	ans += b[n-2];

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        while (true) {
            string S; cin >> S;
            if (S == "0") return;
            UL ans = 0;
            for (char c : S) ans += c - '0';
            cout << ans << endl;
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(!(a % 3 == 0 || a % 5 == 0)){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;   
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    if((a == 0 || a >= 13) && (b == 0 || b >= 13)){
        cout << "NA" << endl;
    }else if(a == 0 || a >= 13){
        cout << "YYMM" << endl;
    }else if(b == 0 || b >= 13){
        cout << "MMYY" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
import collections

L = []
s = 0
for a in A:
    s += a
    L.append(s % M)
c = collections.Counter(L)

ans = 0
for k, v in c.items():
    if k == 0:
        ans += v * (v + 1) // 2
    else:
        ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 16556
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#define re register
using namespace std;
int t[100000+10];
inline char nc() 
{
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read()
{
	re int n=0,ch=nc();
	while(ch<'0'||ch>'9')ch=nc();
	while(ch>='0'&&ch<='9')
		{
			n=(n<<3)+(n<<1)+ch-'0';
			ch=nc();
		}
	return n;
}
void write(int n)
{
	if(n>=10)write(n/10);
	putchar(n%10+'0');
}
int main()
{
	re int s=0,N,M;
	N=read();
	re int j;
	N-=4;
	for(j=1;j<=N;j+=4)
		{
			s+=t[j]=read();
			s+=t[j+1]=read();
			s+=t[j+2]=read();
			s+=t[j+3]=read();
		}
	for(;j<=N+4;++j)
		s+=t[j]=read();

	M=read();
	re int p,x;	
	re int k;
	M-=4;
	for(k=1;k<=M;k+=4)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	for(;k<=M+4;++k)
		{
			p=read();
			x=read();
			write(s+x-t[p]);
			putchar('\n');
		}
	return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  if (b-a+1 <= 2*k)
    rep(i,b-a+1) cout << i+a << endl;
  else {
    rep(i,k) cout << i+a << endl;
    rep(i,k) cout << i+(b-k+1) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    int a[n], b[n], c[n], d[n], e[n];
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        cin >> b[i];
    }
    rep(i, n) {
        cin >> c[i];
    }
    
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);

    int *pos;
    rep(i, n) {
        pos = lower_bound(a, a+n, b[i]);
        d[i] = distance(a, pos);
    }
    rep(i, n) {
        pos = upper_bound(c, c+n, b[i]);
        e[i] = distance(pos, c+n);
    }

    rep(i, n) {
        ans += (ll)d[i]*e[i];
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0, len=0;    
    for(int i=0; i<(int)s.length(); i++) {
    	if(s[i]=='A' || s[i]=='T' || s[i]=='C' || s[i]=='G') len++;
      	else len=0;
    	ans = max(ans, len);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using R=double;
 
// Combination Table
ll C[51][51]; // C[n][k] -> nCk
 
void comb_table(int N){ 
	for(int i=0;i<=N;++i){
		for(int j=0;j<=i;++j){
			if(j==0 or j==i){
				C[i][j]=1LL;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			}
		}
	}
}
 
int main(void){
	int N,A,B;
	cin >>  N >> A >> B;
 
	const int NMAX=50;
	ll v[NMAX];
 
	for(int i=0;i<N;++i){
		cin >> v[i];
	}
 
	comb_table(N);
	sort(v,v+N);
	reverse(v,v+N);
 
	R max_average=0.0;
	for(int i=0;i<A;++i){	
		max_average+=v[i];
	}
	max_average/=A;
	
	int a_th_val_num=0,a_th_val_pos=0;
	for(int i=0;i<N;++i){
		if(v[i]==v[A-1]){
			a_th_val_num++;
			if(i<A){
				a_th_val_pos++;
			}
		}
	}
	
	ll cnt=0LL;
	if(a_th_val_pos==A){
		for(a_th_val_pos=A;a_th_val_pos<=B;++a_th_val_pos){
			cnt+=C[a_th_val_num][a_th_val_pos];
		}
	}else{
		cnt+=C[a_th_val_num][a_th_val_pos];
	}
 
	cout.precision(20);
	cout << fixed << max_average << endl;
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		
		int width = z;
		int cnt = 0;
		while (width <= x) {
			width += y + z;
			if (width <= x) cnt++;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
}




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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vll a(n-1), b(n-1);
  REP(i, n-1){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  vector<vll> edge(n, vll());
  REP(i, n-1){
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);
  }

  //bfs
  queue<ll> que;
  vll d0(n, LLINF);
  que.push(0);
  d0[0] = 0;
  ll fenec = 0;
  while(!que.empty()){
    fenec++;
    ll now = que.front();
    que.pop();
    REP(i, edge[now].size()){
      ll cur = edge[now][i];
      if(d0[cur] != LLINF)
        continue;
      d0[cur] = d0[now]+1;
      if(cur == n-1)
        continue;
      que.push(cur);
    }
  }


  vll dn(n, LLINF);
  que.push(n-1);
  dn[n-1] = 0;
  ll snuke = 0;
  while(!que.empty()){
    snuke++;
    ll now = que.front();
    que.pop();
    REP(i, edge[now].size()){
      ll cur = edge[now][i];
      if(dn[cur] != LLINF)
        continue;
      dn[cur] = dn[now]+1;
      if(cur == 0)
        continue;
      que.push(cur);
    }
  }

  ll sum = 0;
  REP(i, n)
    sum += d0[i]<=dn[i]?1:-1;

  //if(fenec > snuke-(dn[0]-1)%2)
  if(sum > 0)
    cout << "Fennec" << endl;
  else
    cout << "Snuke" << endl;
}


Measured memory_bytes: 9344
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std; 
long long k;
string s;
int main(){
    cin>>s;
    cin>>k;
    for (int i=0;i<s.size();i++)
    {
        if (s[i]!='1') {cout<<s[i]<<endl;break;}
        if (i+1==k) {cout<<s[i]<<endl;break;}
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def get_solve():
    cache = [None] * precalc_limit
    cache[0] = [0] * (weight_limit + 1)
    _vvv = vvv
    _www = www
    _weight_limit = weight_limit

    def _f(u):
        """ u < precalc_limit """
        if cache[u] is not None:
            return cache[u]
        dp = _f(u >> 1).copy()
        v = _vvv[u]
        w = _www[u]
        for x in range(_weight_limit, w - 1, -1):
            nv = dp[x - w] + v
            if dp[x] < nv:
                dp[x] = nv
        cache[u] = dp
        return dp

    return _f


n, *inp = map(int, sys.stdin.buffer.read().split())
vvv = [0] + inp[0:n * 2:2]
www = [0] + inp[1:n * 2:2]

weight_limit = 10 ** 5
precalc_limit = min(1 << 10, n + 1)

solve = get_solve()

buf = []
mp = iter(inp[n * 2 + 1:])
for u, l in zip(mp, mp):
    if u < precalc_limit:
        dp = solve(u)
        buf.append(dp[l])
        continue
    dp_w = [0]
    dp_v = [0]
    while u >= precalc_limit:
        v = vvv[u]
        w = www[u]
        for i in range(len(dp_w)):
            nw = dp_w[i] + w
            if nw > l:
                continue
            nv = dp_v[i] + v
            dp_w.append(nw)
            dp_v.append(nv)
        u >>= 1
    ans = 0
    dp = solve(u)
    for w, v in zip(dp_w, dp_v):
        nv = v + dp[l - w]
        if ans < nv:
            ans = nv
    buf.append(ans)

print('\n'.join(map(str, buf)))


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

using namespace std;

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

    int n, h, w;
    cin >> n >> h >> w;
    int count = 0;
    int a, b;
    while (n--) {
        cin >> a >> b;
        count += (h <= a && w <= b);
    }

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
import heapq

INF = float('inf')
n, m, R = list(map(int, input().split()))
r = list(map(int, input().split()))

cost = {}
for i in range(m):
    a, b, c = list(map(int, input().split()))
    if not a in cost.keys():
        cost[a] = [(b, c)]
    else:
        cost[a].append((b, c))
    if not b in cost.keys():
        cost[b] = [(a, c)]
    else:
        cost[b].append((a, c))
        
dist = [[INF]*(n+1) for _ in range(n+1)]
for st in r:
    d = [INF]*(n+1)
    d[st] = 0
    path = [(0, st)]
    heapq.heapify(path)
    while len(path) > 0:
        c, node = heapq.heappop(path)
        if d[node] < c:
            continue
        d[node] = c
        for node_next, c_next in cost[node]:
            if d[node]+c_next < d[node_next]:
                heapq.heappush(path, (d[node]+c_next, node_next))
    dist[st] = d
# for d in dist: print(d)

ans = INF
for p in permutations(r):
    ans_ = 0
    for i in range(R-1):
        ans_ += dist[p[i]][p[i+1]]
    ans = min(ans, ans_)
print(ans)


Measured memory_bytes: 9372
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int32_t main()
{
  BOOST;
   int ans=0;
   int n;
   cin>>n;
   for (int i=1;i<=n;i++)
   {
   	int a;
   	cin>>a;
   	if ((a&1) && (i&1))ans++;
   }
   cout<<ans;
  return 0;
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  string r = s + s;
  int len = s.size();
  for ( int i = 0; i < len; i++ ) {
    if ( t == r.substr(i, len) ) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = h[0]
tani = h[0]
for i in range(1,n-1):
    if h[i] > h[i-1] and h[i] >= h[i+1]:
        ans += h[i] - tani
    elif h[i] <= h[i+1] and h[i] <= h[i-1]:
        tani = h[i]
if h[n-1] > h[n-2]:
    ans += h[n-1] - tani
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[20];
  cin >> n;
  for(int i=0;i<n;i++){
	cin >> a[i];    
  }
  int max_height = 0;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(max_height <= a[i])
      ans++;
    max_height = max(max_height, a[i]);
  }
  cout << ans << endl;
}

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

using namespace std;
char str[100005];
int cnt[100005];

int main()
{
    scanf("%s",str);int len = strlen(str);
    for(int i=0;i<len;)
    {
        if(str[i]=='R'){
            int j=0;
            while(str[i+j]!='L')++j;
            cnt[i+j-1] += j-j/2;
            cnt[i+j] +=j/2;
            i+=j;
        }else ++i;
    }

    for(int i=len-1;i>=0;){
        if(str[i]=='L'){
            int j=0;
            while(str[i-j]!='R') ++j;
            cnt[i-j+1] += j-j/2;
            cnt[i-j]+= j/2;
            i-=j;
        }else --i;
    }

    for(int i=0;i<len;++i){
        printf("%d ",cnt[i]);
    }
    printf("\n");
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    
    //小さい順に合成していくと最大になる＝＞sortして順番に割ってたしていく
    sort(v.begin(), v.end());    

    double total = 0;

    for (int i = 1; i < n; i++) {
        v[i] = (v[i-1]+v[i])/2;
        total = v[i];
    }

    cout << total << endl;
}

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

int main() {
  int N, A;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int O, P;
    cin >> O >> P;
    A += P - O + 1;
  } 
  cout << A << endl ;
}

Measured memory_bytes: 256
/* Bismillahir Rahmanir Rahim */
 
#include <bits/stdc++.h>
 
#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))
 
#define mx		20007
#define pb		push_back
#define inf 	(1 << 30)
 
#define f	first
#define s 	second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
int p[mx], n;
int a[mx], b[mx];
 
int main(){
	int x;
	scanf("%d", &n);
	repn(i, n) scanf("%d", &p[i]);
	repn(i, n) a[i] = i * (n+1);
	int cur = 1e9;
	repn(i, n){
		int f = p[i];
		b[f] = cur - a[f];
		cur+=1;
	}
	int rp = 0;
	repn(i, n){
		int sum = a[p[i]] + b[p[i]];
		if(sum <= rp){
			assert(0);
			return 0;
		}
		rp = sum;
	}
	repn(i, n){
		if(i != 1) printf(" ");
		printf("%d", a[i]);
	}
	cout << endl;
	repn(i, n){
		if(i != 1) printf(" ");
		printf("%d", b[i]);
	}
	return 0;
}
 

Measured memory_bytes: 896
<?php

$b = trim(fgets(STDIN));

if ($b == 'A') {
	echo 'T';
} elseif ($b == 'T') {
	echo 'A';
} elseif ($b == 'C') {
	echo 'G';
} elseif ($b == 'G') {
	echo 'C';
}

?>

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

int main() {
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  int ans=1,sum=0;
  for(int i=0;i<n;i++){
    sum += l.at(i);
    if( sum <= x ){
      ans++;
    }else{
      break;
    }
  }
  cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A[100001];
int B[100000];
int main(){
  int i, j;
  long long res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N+1;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<N;KL2GvlyY++){
      rd(B[KL2GvlyY]);
    }
  }
  for(i=0;i<N;i++){
    j =min_L(B[i], A[i]);
    res += j;
    A[i] -= j;
    B[i] -= j;
    j =min_L(B[i], A[i+1]);
    res += j;
    A[i+1] -= j;
    B[i] -= j;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, A[100001], B[100000];
// {
//   int i, j;
//   ll res = 0;
// 
//   rd(N,A(N+1),B(N));
// 
//   rep(i,N){
//     j = min(B[i], A[i]);
//     res += j;
//     A[i] -= j;
//     B[i] -= j;
//     j = min(B[i], A[i+1]);
//     res += j;
//     A[i+1] -= j;
//     B[i] -= j;
//   }
// 
//   wt(res);
// }


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


int main() {
    //input
    int n;
    std::cin >> n;

    string str;
    int a[n],b[n];
    for (int i = 0; i < n+1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    //
    long long count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i]>=b[i]){
            count += b[i];
        }else if(b[i]<=a[i]+a[i+1]){
            count += b[i];
            a[i+1] -= b[i] - a[i];
        }else{
            count += a[i] + a[i+1];
            a[i+1] = 0;
        }
    }

    cout <<  count;
    //std::cout << ans << std::endl;
    //for (int i=0;i<n;i++){
    //    std::cout << vec.at(i) << std::endl;
    //}


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// Cooley-Tukey FFT algorithm
vector<complex<double>> fft(vector<complex<double>> a, bool inv = false) {
    int n = a.size();
    int h = 0;
    for (int i = 1; i < n; i *= 2) {
        h++;
    }
    for (int i = 0; i < n; i++) { // swap for butterfly
        int j = 0;
        for (int k = 0; k < h; k++) {
            j |= (i >> k & 1) << (h - 1 - k);
        }
        if (i < j) {
            swap(a[i], a[j]);
        }
    }
    for (int block = 1; block < n; block *= 2) {
        for (int j = 0; j < block; j++) {
            complex<double> w = polar(1.0, (2 * M_PI) / (2 * block) * j * (inv ? 1 : -1));
            for (int k = 0; k < n; k += block * 2) {
                complex<double> s = a[j + k];
                complex<double> t = a[j + k + block] * w;
                a[j + k] = s + t;
                a[j + k + block] = s - t;
            }
        }
    }
    if (inv) {
        for (int i = 0; i < n; i++) {
            a[i] /= n;
        }
    }
    return a;
}
vector<complex<double>> fft(vector<double> a, bool inv = false) {
    vector<complex<double>> a_complex(a.size());
    for (int i = 0; i < a.size(); i++) {
        a_complex[i] = complex<double>(a[i], 0);
    }
    return fft(a_complex, inv);
}

vector<double> convolve(vector<double> a, vector<double> b) {
    int s = a.size() + b.size() - 1;
    int t = 1;
    while (t < s) {
        t *= 2;
    }
    a.resize(t);
    b.resize(t);
    vector<complex<double>> A = fft(a);
    vector<complex<double>> B = fft(b);
    vector<complex<double>> C(t);
    for (int i = 0; i < t; i++) {
        C[i] = A[i] * B[i];
    }
    vector<complex<double>> c = fft(C, true);
    a.resize(s);
    for (int i = 0; i < s; i++) {
        a[i] = c[i].real(); // 実部が答え
    }
    return a;
}

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

    ll N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) { cin >> A.at(i); }
    vector<double> B(100010, 0);
    REP(i, N) { B[A[i]]++; }
    vector<double> C = B;

    vector<double> ans = convolve(B, C);

    ll ret = 0;
    ll count = 0;
    RREP(i, ans.size()) {
        ll now = (ll)round(ans[i]);
        if (now != 0) {
            // printf("i:%d, now:%d, count:%d\n", i, now, count);
            if (now + count < M) {
                count += now;
                ret += i * now;
            } else {
                ret += i * (M - count);
                break;
            }
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 24792
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
const int inf = (int)1e18 + 10;
int dp[N][15] = {{0}};
signed main(){
  fast;
 int sum = 0;
 string s;
 cin >> s;
 int n = s.length();
 if(s[0] == '?')
  for(int i = 0 ; i<=9 ; i++)
    dp[0][i] = 1;
 else{
  int x = s[0] - '0';
  dp[0][x] = 1;
 }
 for(int i = 1 ; i < n ; i++){
     int x = s[i]  - '0';

   if(s[i] == '?'){
     for(int j = 0 ; j < 13 ; j++ ){
          for(int k = 0 ; k < 10 ; k++){
            dp[i][(j * 10 + k) % 13] += dp[i-1][j];
            dp[i][(j * 10 + k) % 13] %= mod;
          }
     }
   }
   else{
      for(int j = 0 ; j< 13 ; j++ ){
            dp[i][(j*10+ x) % 13] += dp[i-1][j];
            dp[i][(j*10+ x)%13] %= mod;
          }

   }

 }
 
 cout << dp[n-1][5] << endl;





}	

Measured memory_bytes: 12240
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
	        Scanner sc = new Scanner(System.in);
	        String line = sc.nextLine();
	        StringBuilder sb = new StringBuilder();
	        
	        for(int i = 0; i < line.length(); i++) {
	        	char now = line.charAt(i);
	        	if((Character.isUpperCase(now))) sb.append(Character.toLowerCase(now));
	        	else if((Character.isLowerCase(now))) sb.append(Character.toUpperCase(now));
	        	else sb.append(now);
	        }
	        
	        System.out.println(sb);
	}
}



Measured memory_bytes: 26044
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
    ll n,ans=1;
    string s;
    cin>>n>>s;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3736
#include <iostream>
#include <cmath>

using namespace std;

long long gcd(long long a, long long b){
    return (b==0 ? a: gcd(b,a%b));
}

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

int main(){
    long long n;
    cin >> n;
    
    cout << lcm(2,n);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,a;cin>>n>>a;
  int x[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
    x[i]-=a;
  }
  ll dp[n+1][5001];
  for(int i=0;i<=n;i++){
    for(int j=0;j<=5000;j++){
      dp[i][j]=0;
    }
  }
  for(int i=0;i<n;i++){
    dp[i+1][2500+x[i]]++;
    for(int j=0;j<=5000;j++){
      dp[i+1][j]+=dp[i][j];
      if(dp[i][j]>0){
        dp[i+1][j+x[i]]+=dp[i][j];
      }
    }
  }
  cout<<dp[n][2500]<<endl;
}
  

Measured memory_bytes: 2176
package main

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

func newSplitScanner(r io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	return sc
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var sc = newSplitScanner(os.Stdin)
	n := nextInt(sc)

	fmt.Println(n * n * n)
}


Measured memory_bytes: 640
def inpl(): return list(map(int,input().split()))

N = int(input())
A = inpl()

l = r = 0
ans = 0
X = Y = A[0]
while 1:
    if X==Y:
        ans += r-l+1
        if r < N-1:
            r += 1
            X ^= A[r]
            Y += A[r]
        else:
            break
    else:
        X ^= A[l]
        Y -= A[l]
        l += 1

print(ans)

Measured memory_bytes: 24840
from collections import deque
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]),int(input_raw[1])]
    adj_list = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [L, R, D] = [int(input_raw[0]),int(input_raw[1]),int(input_raw[2])]
        if  L not in adj_list :
            adj_list[L] = [(R, D)]
        else:
            adj_list[L].append((R, D))
        if R not in adj_list :
            adj_list[R] = [(L, -D)]
        else:
            adj_list[R].append((L, -D))


    node_list = deque([])
    done_set = {}
    is_ok = True
    for L in adj_list:
        if is_ok == False:
            break
        if L not in done_set:
            node_list.append(L)
            done_set[L] = 0

            while 1:
                if len(node_list) <= 0:
                    break
                nd = node_list.popleft()
                for adj in adj_list[nd]:

                    if adj[0] not in done_set:
                        node_list.append(adj[0])
                        done_set[adj[0]] = done_set[nd] + adj[1]
                    else:
                        if(done_set[adj[0]] != done_set[nd] + adj[1]):
                            is_ok = False
                            break;

    if is_ok == True:
        print "Yes"
    else:
        print "No"







if __name__ == '__main__':
    main()

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

args = [int(e) for e in input().split()]

count = 0

for i in range(0, n) :
    if args[i] != i + 1 :
        count += 1

if count == 2 :
    print("YES")
elif count == 0 :
    print("YES")
else :
    print("NO")

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
  int i,j,k;
  int N;
  int A[9];
  for(i=0;i<9;i++)
    A[i]=0;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d ",&k);
    if(k <=399)
      A[0]++;
    else if(k >= 400 && k<=799)
      A[1]++;
    else if(k >= 800 && k<=1199)
      A[2]++;
    else if(k >= 1200 && k<=1599)
      A[3]++;
    else if(k >= 1600 && k<=1999)
      A[4]++;
    else if(k >= 2000 && k<=2399)
      A[5]++;
    else if(k >= 2400 && k<=2799)
      A[6]++;
    else if(k >= 2800 && k<=3199)
      A[7]++;
    else
      A[8]++;
  }
  int ans=0;
  for(i=0;i<8;i++){
    if(A[i]!=0)
      ans++;
  }
  if(ans == 0){
    printf("%d %d\n",1,A[8]);
  }
  else{
    printf("%d %d\n",ans,ans+A[8]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long  x; cin >> x;
  long long i =100ll;
  int cnt = 0;
  while(1){
    if(i >= x){
      cout << cnt << endl;
      return 0;
    }
    cnt ++;
    i += i /100;;
  }
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	ll n, m;
	cin >> n >> m;
	if (m <= 2 * n)cout << m / 2 << endl;
	else {
		cout << n + (m - 2 * n) / 4 << endl;
	}
}



Measured memory_bytes: 256