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

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

	int N, K;
	N = sc.nextInt();
	K = sc.nextInt();

	double probability_all = 0.0;
	for (int i = 0; i < N; i++) {
	    int sum = i + 1;
	    double count = 1.0;
	    while (sum < K) {
		sum *= 2;
		count /= 2;
	    }

	    probability_all += count;
	}

	System.out.println((double)(probability_all / N));
    }
}

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

int A[100000];

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

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

	int ans = 0;
	for(int i = 0; i < N - 1; i++){
		if(A[i] == i){
			swap(A[i], A[i + 1]);
			ans++;
		}
	}
	if(A[N - 1] == N - 1){
		swap(A[N - 2], A[N - 1]);
		ans++;
	}

	for(int i = 0; i < N; i++){
		assert(A[i] != i);
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  int X[N];
  int cnt=0;
  for(int i=0; i<N; ++i){
    cin >> X[i];
    if(X[i] != i+1) cnt +=1;
  }
  if(cnt ==2 || cnt ==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,o;
pair<int,bool> a[100005];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].first);
		if (i%2==0) a[i].second=true;
	}
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		if ((i%2==0)!=a[i].second) 
		++o;
	}
	printf("%d",o/2);
}

Measured memory_bytes: 1024
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let x: usize = scan(tokens);
    let mut cnt = 0;
    let mut d = 0;
    if d <= x {
        cnt += 1;
    }
    for _ in 0..n {
        let l: usize = scan(tokens);
        d += l;
        if d <= x {
            cnt += 1;
        } else {
            break;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
string s;
int temp;
int main()
{
	cin>>s;
	int t=s.length();
	for(int i=0;i<t-1;i++)
	if(s[i]!=s[i+1])temp++;
	cout<<temp;
	return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100010;

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

#ifdef MARX
    freopen("test.in", "r", stdin);
#endif

    int n; cin >> n;

    vector<int> v(3 * n);

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

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

    int64 answer = 0;

    for (int i = 0; i < n; ++i)
        answer += v[3 * n - 2 - 2 * i];

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int main(){
    int N, T, A, temp, kouho, cc=1000000, ans = 0;
    cin >> N >> T >> A;
    for (int i = 1; i <= N; i++) {
        cin >> kouho;
        temp = A*1000-(T*1000-kouho*6);
        if (temp < 0) temp = -1*temp;
        if (temp < cc){
            cc = temp;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;
signed main(){
    int a,b,k;cin>>a>>b>>k;
    int cnt=0;
    rep1(i,100){
        if(a%i==0&&b%i==0){
            cnt++;
        }
    }
    int buf=0;
    rep1(i,100){
        if(a%i==0&&b%i==0){
            buf++;
            if(buf==cnt-k+1){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int tc; scanf("%d",&tc);
	while(tc--){
		int a[9],b[9];
		for(int i=0;i<9;i++) scanf("%d",a+i);
		for(int i=0;i<9;i++) scanf("%d",b+i);
		
		int cnt=0;
		sort(a,a+9);
		do{
			int sum[2]={};
			for(int i=0;i<9;i++)
				sum[a[i]<b[i]]+=a[i]+b[i];
			if(sum[0]>sum[1]) cnt++;
		}while(next_permutation(a,a+9));
		
		double p=cnt/362880.,q=1-p;
		printf("%.5f %.5f\n",p,q);
	}
	
	return 0;
}

Measured memory_bytes: 1060
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;

int gcd(int a, int b) {
	if (a > b) {
		if (b == 0) return a;
		else return gcd(b, a % b);
	}
	else if (b > a) {
		if (a == 0) return b;
		else return gcd(a, b % a);
	}
	else { return a; }
}

int main() {
	
	int K;
	cin >> K;
	ll ans=0;
	rep(i, K) {
		rep(j, K) {
			rep(k, K) {
				
				int D = gcd(i, j);
				int x = gcd(D, k);
				ans += x;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int X[N], tmp[N];
    for(int i = 0; i < N; i++) {
        cin >> X[i];
        tmp[i] = X[i];
    }
    sort(X, X + N);
    int small = X[N / 2 - 1], large = X[N / 2];
    for(int i = 0; i < N; i++) {
        if(tmp[i] < large)
            cout << large << "\n";
        else
            cout << small << "\n";
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
long long maxi(long long a,long long b){
  if(a>b)
    return a;
  else
    return b;
}
int main(){
  int r,c,k;
   cin>>r>>c>>k;
  long long** v=new long long*[r];
  for(int i=0;i<r;i++){
  	v[i]=new long long[c];
    for(int j=0;j<c;j++){
      v[i][j]=0;
      
    }
  }
  for(int i=0;i<k;i++){
    int a,b;
    long long x;
    cin>>a>>b>>x;
    v[a-1][b-1]=x;
  }
  long long*** dp = new long long**[r];
  for(int i=0;i<r;i++){
    dp[i] = new long long*[c];
    for(int j=0;j<c;j++){
      //cout<<v[i][j]<<" v"<<endl;
      dp[i][j] = new long long[4];
      for(int t=0;t<4;t++){
        dp[i][j][t]=0;
        if(t==0&&i==0)
          dp[i][j][t]=0;
        else if(i==0&&j==0)
          dp[i][j][t]=v[i][j];
        else if(i==0)
          dp[i][j][t]=maxi(dp[i][j-1][t-1]+v[i][j],dp[i][j-1][t]);
        else if(t==0&&j==0)
          dp[i][j][t]=dp[i-1][j][3];
        else if(j==0)
          dp[i][j][t]=maxi(dp[i-1][j][3]+v[i][j],dp[i-1][j][3]);
        else if(t==0)
            dp[i][j][t]=dp[i-1][j][3];
        else{
          dp[i][j][t]=maxi(dp[i-1][j][3]+v[i][j],dp[i][j-1][t-1]+v[i][j]);
          dp[i][j][t]=maxi(dp[i][j][t],dp[i][j-1][t]);
        }        
        //cout<<dp[i][j][t]<<endl;
      }
    }
  }
  cout<<dp[r-1][c-1][3]<<endl;
}

Measured memory_bytes: 566084
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    int N,i,error=0;
    cin>>N;
    vector<int> data(N);
    rep(i,0,N)cin>>data.at(i);
    sort(all(data));
    rep(i,0,N-1){
        if(data.at(i)==data.at(i+1)){
            error++;
            break;
        }
    } 
    if(error!=0)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K, S = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    m=10**9
    if S!=10**9:
        ans=[S]*K+[m]*(N-K)
    else:
        ans=[m]*K+[1]*(N-K)

    print(*ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 46372
#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
#define db double
#define pa pair<db,int>
#define mk make_pair

using namespace std;
int h[1010000],tot,n,sz[1010100],f0[1010100],f1[1010000],fa[1010100],anc[1010000];
db divv[1010109];
ll ans=0;
inline int find(int x){
	if(fa[x]==x) return x;
	else return fa[x]=find(fa[x]);
}
set<pa> st;
int main(){
	cin>>n;
	for(rint i=2;i<=n;++i) {
		cin>>anc[i];
	}
	for(rint i=1;i<=n;++i) {
		fa[i]=i;
		int x;cin>>x;
		if(x==1) f1[i]=1;
		else f0[i]=1;
		if(x==1) divv[i]=1e18;
	}
	for(rint i=2;i<=n;++i) {
		st.insert(mk(divv[i],i));
	}
	while(!st.empty()) {
		pa tmp=*st.begin();st.erase(tmp);
		int u=tmp.second;
		int v=find(anc[u]);
		ans+=1ll*f1[v]*f0[u];
		if(v!=1) 
			st.erase(mk(divv[v],v));
		f1[v]+=f1[u];
		f0[v]+=f0[u];
		divv[v]=f0[v]==0?1e18:((double)f1[v]/f0[v]);
		fa[u]=v;
		if(v!=1) 
			st.insert(mk(divv[v],v));
	}cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20844
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;


signed main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    int c;
    repb(i, n, 0){
        if(s.substr(n - i) == t.substr(0, i)){
            c = i; break;
        }
    }
    string ans = s;
    ans += t.substr(c);
    o(ans.size());
}

Measured memory_bytes: 256
require 'prime'

### constant

MAX_P = 10000

### main

pnums = Prime.each(MAX_P).to_a

loop do
  n = gets.to_i
  break if n == 0
  #p ["n", n]
  
  count = 0
  i0 = i1 = 0
  sum = 0

  loop do
    if sum < n
      break if pnums[i1].nil? || pnums[i1] > n
      sum += pnums[i1]
      i1 += 1
    elsif sum > n
      sum -= pnums[i0]
      i0 += 1
    else
      count += 1
      sum -= pnums[i0]
      i0 += 1
    end
  end    
  p count
end

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

const int INF = (int)(1000 + 5);

int a, b, c;

int ans = INF;

int x;

int main(void){
  scanf("%d %d %d", &a, &b, &c);

  int base = a + b + c;
  int m = max(max(a, b), c);

  if ((a + b + c) % 2 == (3 * m) % 2) x = m;
  else x = m + 1;

  while ((3 * x - base) % 2 != 0) x += 2;
  ans = (3 * x - base) / 2;

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Thu Apr 26 10:52:34 2018
//
package main

import (
	"fmt"
	"strings"
)

var s string

func check(s []string) bool {
	for i := 0; i < len(s)-1; i++ {
		if s[i] != s[i+1] {
			return false
		}
	}
	return true
}

func shrink(c string, s []string) []string {
	ret := []string{}
	for i := 0; i < len(s)-1; i++ {
		if s[i] == c || s[i+1] == c {
			ret = append(ret, c)
		} else {
			ret = append(ret, s[i])
		}
	}

	return ret
}

func main() {
	fmt.Scan(&s)

	ss := strings.Split(s, "")
	if check(ss) {
		fmt.Println(0)
		return
	}

	min := 1 << 30
	for i := 'a'; i <= 'z'; i++ {
		ss := strings.Split(s, "")
		for j := 1; j <= len(ss); j++ {
			ss = shrink(string(i), ss)
			if check(ss) {
				if j < min {
					min = j
				}
				break
			}

		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 4736
using System;

namespace A___Christmas_Eve_Eve_Eve
{
    class Program
    {
        static void Main(string[] args)
        {
            var D = int.Parse(Console.ReadLine());
            string ans = string.Empty;
            switch (D)
            {
                case 22:
                    ans = "Christmas Eve Eve Eve";
                    break;
                case 23:
                    ans = "Christmas Eve Eve";
                    break;
                case 24:
                    ans = "Christmas Eve";
                    break;
                case 25:
                    ans = "Christmas";
                    break;
                default:
                    break;
            }
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b){
    cout << "Zero" << endl;
  } else if(0 < a || (b - a) % 2 == 1) {
    cout << "Positive" << endl;
  } else {
    cout << "Negative" << endl;
  }
  return 0;
}


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

int main() {
    
    string S; cin >> S;
    int tail= S.length();
    int ans=0;
    
    rep(i,0,tail){

        int tmp=0;

        while(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
            i++;
            tmp++;
        }

        if(ans < tmp){
            ans = tmp;
        }



    }

    cout << ans << endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val ABCD = readString()
  val a = ABCD[0] - '0'
  val b = ABCD[1] - '0'
  val c = ABCD[2] - '0'
  val d = ABCD[3] - '0'
  for (i in 0 until 2) {
    for (j in 0 until 2) {
      for (k in 0 until 2) {
        var v = a
        when (i) {
          0 -> v += b
          1 -> v -= b
        }
        when (j) {
          0 -> v += c
          1 -> v -= c
        }
        when (k) {
          0 -> v += d
          1 -> v -= d
        }
        if (v == 7) {
          val op = "+-"
          println("$a${op[i]}$b${op[j]}$c${op[k]}$d=7")
          return
        }
      }
    }
  }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


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

using namespace std;

#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()

typedef long long tint;

int main(){
	int n, k; cin >> n >> k;
	for(int i=k-n+1; i<= k+n-1;i++){
		cout << i << " ";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define st first
#define nd second

const int N = 105;
int n, a, b, w;
int sec1, sec2, result;
int arr[N][2];
int dp[105][100005];//kalan weight' maks sum value

int ks(int who, int weig){
    // cout << who << "           "<< arr[who-1][1] << " " <<  arr[who-1][0] << endl;
    if(dp[who][weig] != -1) return dp[who][weig];
    if(who == 0 || weig == 0) result = 0;
    else if(arr[who-1][0] > weig) result = ks(who-1, weig);
    else result = max(arr[who-1][1] + ks(who-1, weig-arr[who-1][0]),     ks(who-1, weig));
    dp[who][weig] = result;
    return result;
}
 
int32_t main() {
	ios_base::sync_with_stdio(0);
    cin >> n >> w;
    memset(dp, -1,sizeof(dp));
    for(int i = 0; i < n; i++){
    	cin >> a >> b;
        arr[i][0] = a;
        arr[i][1] = b;
    }
    cout << ks(n, w) << endl;
}

Measured memory_bytes: 85696
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

vector<int> g[111111];
vector<int> ans[2];
int used[111111];

void dfs(int node,int k){
  used[node]=1;
  ans[k].pb(node);
  for(int i=0;i<g[node].size();i++){
    if(used[g[node][i]]==1)continue;
    dfs(g[node][i],k);
    break;
  }
}

int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    a--,b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  dfs(0,0);
  dfs(0,1);

  reverse(all(ans[0]));
  cout<<ans[0].size()+ans[1].size()-1<<endl;
  for(int i=0;i<ans[0].size();i++){
    if(i)cout<<" ";
    cout<<ans[0][i]+1;
  }
  for(int i=1;i<ans[1].size();i++){
    cout<<" "<<ans[1][i]+1;
  }
  cout<<endl;
  
  return 0;
}


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

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

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int X; std::cin >> X;
  if ( X >= 30 ) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}



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

int main() {
  int n;
  std::string input;
  std::cin >> n;
  std::cin >> input;
  for (int i = 0; i < input.length(); ++i) {
    char cur = input[i];
    input[i] = ((cur - 'A') + n) % 26 + 'A';
  }
  std::cout << input << std::endl;
  return 0;
}


Measured memory_bytes: 256
/*/**/

#include <bits/stdc++.h>

using namespace std;

bool l, r, u, d;

int main() {
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'N') {
			u = true;
		}
		if(s[i] == 'W') {
			l = true;
		}
		if(s[i] == 'S') {
			d = true;
		}
		if(s[i] == 'E') {
			r = true;
		}
	}
	bool ok = false;
	if(u and d and l and r) {
		ok = true;
	}
	if(u and d and not l and not r) {
		ok = true;
	}
	if(not u and not d and l and r) {
		ok = true;
	}
	puts(ok ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = min(B) - max(A) + 1

if ans < 1:
    print(0)
else:
    print(ans)

Measured memory_bytes: 11052
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    float x,y,c,t;
    cin>>x>>y;
    c=(2*x - y/2);
    t=(y/2 - x);
    if((c>0 && t>0 && ceil(c)==floor(c) && ceil(t)==floor(t))||(c==0 && t>0)||(t==0 && c>0))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
}

Measured memory_bytes: 3836
n = int(input())
h = list(map(int, input().split()))
h.reverse()

for i in range(n-1):
    diff = h[i+1] - h[i]
    if diff == 1:
        h[i+1] -= 1
    elif diff > 1:
        print('No')
        exit()
    else:
        pass

print('Yes')

Measured memory_bytes: 20584
N, M = map(int, input().strip().split(' '))

AC = {i+1: 0 for i in range(N)}
WA = {i+1: 0 for i in range(N)}

for i in range(M):
    p_i, S_i = input().strip().split(' ')
    p_i = int(p_i)
    if S_i == 'WA' and AC[p_i] == 0:
        WA[p_i] += 1
    elif S_i == 'AC':
        AC[p_i] = 1

sum_AC = 0
sum_WA = 0
for i in range(N):
    if AC[i+1] == 1:
        sum_AC += 1
        sum_WA += WA[i+1]

print(sum_AC, sum_WA)


Measured memory_bytes: 58340
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

template <typename T>
struct Add {
    T operator()(T x, T y) {
        return x + y;
    }
};

template <class T, class Functor>
struct SegmentTree {
    size_t n;
    T e;
    vector<T> tree;
    Functor F;
    SegmentTree(size_t m, T e=T()): n(1), e(e) {
        while (n <= m) n <<= 1;
        tree.assign(n<<1, e);
    }
    T range_query(size_t a, size_t b, size_t i=1, size_t l=0, size_t r=-1) {
        if (!~r) r = n;
        if (a<=l && r<=b) return tree[i];

        T vl=e, vr=e;
        size_t c=(l+r)>>1;

        if (a < c) vl=F(e, range_query(a, b, i<<1|0, l, c));
        if (c < b) vr=F(e, range_query(a, b, i<<1|1, c, r));

        return F(vl, vr);
    }
    void update(size_t i, T x) {
        i += n;
        tree[i] = x;
        while (i>>=1)
            tree[i] = F(tree[i<<1|0], tree[i<<1|1]);
    }
    void add(size_t i, T x) {
        i += n;
        tree[i] += x;
        while (i>>=1)
            tree[i] = F(tree[i<<1|0], tree[i<<1|1]);
    }
};

int main() {
    size_t n, q;
    scanf("%zu %zu", &n, &q);

    SegmentTree<int, Add<int>> tree(n);
    for (size_t i=0; i<q; ++i) {
        int com;
        scanf("%d", &com);
        if (com) {
            size_t s, t;
            scanf("%zu %zu", &s, &t);
            printf("%d\n", tree.range_query(s, t+1));
        } else {
            size_t i;
            int x;
            scanf("%zu %d", &i, &x);
            tree.add(i, x);
        }
    }

    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

// ============================================================

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  ll a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc164/tasks/abc164_d

import sys
input = sys.stdin.readline


S = input().rstrip()

res = 0

x = 0
p = 1
MOD = 2019
reminder = [0]*2019
reminder[0] = 1
for s in reversed(S):
    """ 累積和 """
    x = (int(s)*p + x)%MOD
    p = p*10%MOD
    res += reminder[x]
    reminder[x] += 1

print(res)

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

template <typename T>
inline T read(){
    T x=0,f=1;char c=getchar();
    while(!isdigit(c)){ if(c=='-') f=-f;c=getchar();}
    while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
    return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7;

int cnt=0;
lint n,d;

int main(void){

    // freopen("testdata.in","r",stdin);
    // freopen("testdata.out","w",stdout);

    scanf("%lld%lld",&n,&d);

    d=d*d;

    for(int i=1;i<=n;i++){
        lint x=readlint,y=readlint;
        if(x*x+y*y<=d) ++cnt;
    }

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

    return 0;
}

Measured memory_bytes: 3844
n=int(input())
s=input()
ans=0
for i in range(1000):
    if i<10:
        ss="00"+str(i)
    elif i<100:
        ss="0"+str(i)
    else:
        ss=str(i)
    now=0
    for j in range(n):
        if s[j]==ss[now]:
            now+=1
            if now==3:
                ans+=1
                break
print(ans)


Measured memory_bytes: 41052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)

int main(){
	int N;
	cin >> N;
	if(N==1){
		cout << 0;
		return 0;
	}
	
	int u[N],v[N],w[N];
	For(i,1,N){
		cin >> u[i] >> v[i] >> w[i];
	}
	
	int color[N];
	For(i,0,N) color[i]=-1;
	color[u[1]-1]=0;
	
	/*cout << endl;
	For(i,1,N){
		cout << u[i] << " " << v[i] << " " << w[i] << endl;
	}
	cout << endl << endl;*/
	
	int count=0;
	bool done[N];
	For(i,1,N) done[i]=false;
	while(true){
		For(i,1,N){
			if(done[i]) continue;
			//cout << color[u[i]-1] << endl;
			if(color[u[i]-1]!=-1&&color[v[i]-1]==-1){
				count++;
				done[i]=true;
				if(w[i]%2==0) color[v[i]-1]=color[u[i]-1];
				else color[v[i]-1]=(color[u[i]-1]+1)%2;
			}
			else if(color[v[i]-1]!=-1&&color[u[i]-1]==-1){
				count++;
				done[i]=true;
				if(w[i]%2==0) color[u[i]-1]=color[v[i]-1];
				else color[u[i]-1]=(color[v[i]-1]+1)%2;
			}
			
			/*cout << endl << endl;
			For(i,0,N-1) cout << color[i] << endl;
			cout << endl << endl;*/
			
		}
		//cout << count << endl;
		if(count==N-1) break;
	}
	
	For(i,0,N) cout << color[i] << endl;
}

Measured memory_bytes: 2048
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
d=[0]*n
for i in range(1,n):
  d[i]=x[i]-x[i-1]
ans=0
for i in range(1,n):
  if a*d[i]>b:
    ans+=b
  else:
    ans+=a*d[i]
print(ans)

Measured memory_bytes: 88032
#include<stdio.h>
/*複数のデータセットに対して、各々が直角三角形か
どうか判定する*/
void right_triangle(int x, int y, int z);

int main(void)
{
    int n;//nはデータセットの個数
    scanf("%d", &n);
    for ( int i = 0; i <n ; ++i){
        int a, b, c;//a,b,cは辺の長さ
        scanf("%d %d %d", &a, &b, &c);
        right_triangle(a , b, c);
    }
    return 0;
}    

void right_triangle( int x, int y, int z)
{
    x *= x;
    y *= y;
    z *= z;
    if (x == y + z|| y == z + x|| z == x + y){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

Measured memory_bytes: 1008
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            if(a==-1 && b==-1 && c==-1) break;
            int sum=a+b;
            if(a==-1 || b==-1 || sum<30) System.out.println("F");
            else if(sum<50){
                if(c>=50) System.out.println("C");
                else System.out.println("D");
            }
            else if(sum<65) System.out.println("C");
            else if(sum<80) System.out.println("B");
            else System.out.println("A");
        }
        sc.close();
    }
}


Measured memory_bytes: 26572
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int X;
  cin >> X;
  ll now = 0;
  ll i = 0;
  while(now<X){
    i++;
    now += i;
  }
  cout << i << endl;
}

Measured memory_bytes: 3636
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h> // @atoi
#include <algorithm>
using namespace std;

int main(void)
{
	int value;
	cin >> value;

	struct INFO
	{
	public:
		int time;
		int mapX;
		int mapY;
		INFO()
		{
			time = 0;
			mapX = 0;
			mapY = 0;
		}
	};
	std::vector<INFO> vTravel;
	for (int i = 0; i < value; ++i)
	{
		INFO temp;
		cin >> temp.time >> temp.mapX >> temp.mapY;
		vTravel.push_back(temp);
	}

	bool isCan = true;
	for (int i = 0; i < vTravel.size(); ++i)
	{
		INFO preTmp;
		if (i != 0) { preTmp = vTravel.at(i - 1); }
		INFO tmp = vTravel.at(i);

		int diffTime = abs(tmp.time - preTmp.time);
		int diffDist = abs(tmp.mapX - preTmp.mapX) + abs(tmp.mapY - preTmp.mapY);

		if (diffTime < diffDist)
		{
			isCan = false;
			break;
		}
		if (diffTime %2 != diffDist % 2)
		{
			isCan = false;
			break;
		}
	}
	cout << ((isCan) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 1912
fun main(args: Array<String>) {
    var x = readLine()!!.toInt()
    var c = readLine()!!.split(" ").map(String::toInt).sortedDescending()
    val p1 = c.filterIndexed{ i,p -> i % 2 == 0}.sum()
    val p2 = c.filterIndexed{ i,p -> i % 2 == 1}.sum()
    println(p1 - p2)
}

Measured memory_bytes: 37716
def MM(num: int):
    return 1 <= num <= 12

ret_dict = {
    (1,1): 'AMBIGUOUS',
    (1,0): 'MMYY',
    (0,1): 'YYMM',
    (0,0): 'NA'
}

def solve2():
    S = input()
    first = int(S[:2])
    second = int(S[2:])
    print(ret_dict[(MM(first), MM(second))])

solve2()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define bs binary_search
#define gcd(a,b) __gcd(a,b)
#define PI 3.1415926535897932384626
#define lp lower_bound
#define up upper_bound
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
#define UNIQUE(x) (x).resize(unique(all(x))-(x).begin())
#define bp(x)  __bulitin_popcount(x)
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}


const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
int main()
{
boost
ll n,m;
cin>>n>>m;
cout<<m*(m-1)/2 +(n)*(n-1)/2;
return 0;
}


Measured memory_bytes: 256
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = [INT() for i in range(N)]
    visited = []
    n = 0
    ans = 0
    while ans < N:
        n = A[n] - 1
        ans += 1
        if n == 1:
            print(ans)
            exit()
    print(-1)





if __name__ == "__main__":
    main()




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

int main(){
  int N;
  cin >> N;
  
  bool ans = false;
  for(int i = 0;i <= N;i++){
    for(int j = 0; j <= N; j++){
      if(((4*i) + (7*j)) == N){
        ans = true;
      }
    }
  }
   if(ans){
     cout << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<climits>
#include<iomanip>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 102

using namespace std;

int H,W;
int G[MAX][MAX];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y){ return ( 0 <= x && x < W && 0 <= y && y < H ); }

int main(){
  cin >> H >> W;
  rep(i,H)rep(j,W)cin >> G[i][j];

  int ans = 0;
  rep(y,H)rep(x,W){
    int pos = IINF;
    int tmp = IINF;
    rep(i,W){
      if( 1 <= i && i < W-1 && G[y][i-1] != -1 && G[y][i+1] != -1 )continue;
      if(G[y][i] == 1){
	pos = i;
	break;
      } else if(G[y][i] == 0 && tmp == IINF)tmp = i;
    }

    if(pos == IINF)pos = tmp;
    assert( pos != IINF );

    rep(i,4){
      int nx = pos+dx[i];
      int ny = y  +dy[i];
      if(!isValid(nx,ny))continue;
      if(G[ny][nx] == -1)continue;
      G[ny][nx] = !G[ny][nx];
    }

    if(G[y][pos] == 1)ans++;
    G[y][pos] = -1;
    /*
    rep(i,H){
      rep(j,W){
	cout << setw(3) << G[i][j];
      }
      cout << endl;
    }
    */

  }  

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1200
N = int(input())
words = [input() for _ in range(N)]
set_words = list(set(words))
if len(set_words) != N:
    print("No")
    exit()

now_word = words[0]

for i in range(1, N):
    if now_word[-1] != words[i][0]:
        print("No")
        exit()
    now_word = words[i]
print("Yes")

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

using namespace std;
const int N = 105;

int n, a[N], ans = 0;

inline bool check(int a, int b, int c) {
  if (a + b > c && a + c > b && b + c > a) return true;
  return false;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) 
    cin >> a[i];
  
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      for (int k = j + 1; k <= n; ++k)
        if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k] && check(a[i], a[j], a[k])) {
          // cout << i << " " << j << " " << k << " " << endl;
          ans++;
        }
  cout << ans;
}

Measured memory_bytes: 3640
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  dp=[0]*100100
  l=LI()

  for i in range(k):
    for x in l:
      if i+x<=k:
        if dp[i+x]==0 and dp[i]==0:
          dp[i+x]=1

  # print(dp[:k+1])
  return 'First' if dp[k] else 'Second'

# main()
print(main())


Measured memory_bytes: 5932
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

string s;

void solve(){
    cin >> s;
    if(s[2]==s[3] && s[5]==s[4]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

Measured memory_bytes: 256
import java.util.*;

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

		for (int i=0; i<n; i++) {
			arr[i] = scanner.nextInt();
		}

		int count = 0;
		for (int i=0; i<arr.length; i++) {
			for (int j=arr.length-1; j>i; j--) {
				if (arr[j] < arr[j-1]) {
                    int temp = arr[j];
      		        arr[j] = arr[j-1];
      		        arr[j-1] = temp;
					count++;
				}
			}
		}

		for (int i=0; i<arr.length-1; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println(arr[arr.length-1]);
		System.out.println(count);
	}

}



Measured memory_bytes: 26440
n,k,*ab = map(int,open(0).read().split())
ab = [(ab[i*2],ab[i*2+1]) for i in range(n)]
ab.sort(key = lambda x:x[0])
c = 0
for i,j in ab:
  c += j
  if c >= k:
    break
print(i)

Measured memory_bytes: 31736
#include <iostream>

using namespace std;

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

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

    long ans = (unsigned long)~0 >> 1;
    int sep1 = 0;
    int sep3 = 2;
    for (int sep2 = 1; sep2 <= n - 3; sep2++) {
        long min_diff = (unsigned long)~0 >> 1;
        for (int j = sep1; j <= sep2 - 1; j++) {
            long diff = abs((sum[sep2] - sum[j]) - sum[j]);
            if (diff < min_diff) {
	         min_diff = diff;
                 sep1 = j;
            } else {
                 break;
            }
        }
        min_diff = (unsigned long)~0 >> 1;
        for (int j = sep3; j <= n - 2; j++) {
            long diff = abs((sum[n - 1] - sum[j]) - (sum[j] - sum[sep2]));
	    if (diff < min_diff) {
                min_diff = diff;
                sep3 = j;
            } else {
                break;
            }
        }
        long b = sum[sep1];
        long c = sum[sep2] - sum[sep1];
        long d = sum[sep3] - sum[sep2];
        long e = sum[n - 1] - sum[sep3];
        long max_sum = max(max(b, c), max(d, e));
        long min_sum = min(min(b, c), min(d, e));
        ans = max_sum - min_sum < ans ? max_sum - min_sum : ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

int main() {
    unsigned long long n;
    cin >> n;
    vector<unsigned long long >a(n);
    for (unsigned long long i = 0; i < n; ++i) cin >> a[i];
    vector<bool> pushed(n, false);
    long long counter = 0;
    unsigned long long pos = 1;
    pushed[0] = true;
    while (true && counter != -1) {
        ++counter;
        auto next = a[pos - 1];
        if (next == 2) break;
        if (pushed[next - 1]) {
            counter = -1;
            break;
        }
        pos = next;
        pushed[pos - 1] = true;
    }
    cout << counter << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1024
L,A,B,mod=map(int,input().split())

def keta(k):# k-桁の数の初項、末項、項数を求める
    if A>=10**k:
        return 0,0,0
    begin=10**(k-1)
    end=10**k

    if begin>A+B*(L-1):
        return 0,0,0

    sh=A+max(-1,(begin-1-A)//B)*B+B
    ma=min(A+max(0,(end-1-A)//B)*B,A+B*(L-1))
    kou=(ma-sh)//B+1
    
    return sh,ma,kou

from functools import lru_cache

@lru_cache(maxsize=None)
def f(n,r): # 1+r+...+r**(n-1)
    if n==1:
        return 1
    if n%2==0:
        return (f(n//2,r) + pow(r,n//2,mod)*f(n//2,r))%mod
    return (r*f(n-1,r)+1)%mod

@lru_cache(maxsize=None)
def g(n,r): # 0+r+2*r**2+...+(n-1)*r**(n-1)
    if n==1:
        return 0
    if n%2==0:
        return g(n//2,r)+pow(r,n//2,mod)*(g(n//2,r)+n//2*f(n//2,r))
    return r*g(n-1,r)+r*f(n-1,r)

keta_count=1
ANS=0
for i in range(18,0,-1):
    sh,ma,kou = keta(i)
    
    if kou<=0:
        continue
    

    #print(i,sh,ma,kou)

    ANS=(keta_count*(ma*f(kou,10**i)-B*g(kou,10**i))+ANS)%mod
    #print(ANS)
    keta_count = keta_count * pow(10,kou * i,mod)

print(ANS)
    
    


Measured memory_bytes: 44780
tile_color = str(input())

odd_count = 0
for i in range(len(tile_color)):
  if int(tile_color[i]) % 2 == i % 2 :
    odd_count += 1

if len(tile_color)/2 < odd_count:
  print(len(tile_color)-odd_count)
else:
  print(odd_count)

Measured memory_bytes: 3188
char a[5],b[5];main(H,B,i,j){for(;scanf("%s%s",a,b),a[1];printf("%d %d\n",H,B))for(H=B=i=0;i<4;i++)for(j=0;j<4;j++)if(a[i]==b[j])i==j?H++:B++;exit(0);}

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

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

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

int main() {
	string s;
	cin >> s;
	int n = s.length();
	int maxi = -1;
	for(int i=n-1; i>=0; i--) {
		if(i%2 != 0) continue;
		for(int j=0; j<i/2; j++) {
			if(s[j] != s[i/2+j]) {
				break;
			}
			if(j == i/2-1) {
				chmax(maxi, i);
			}
		}
	}
	cout << maxi << endl;

  return 0;
}


Measured memory_bytes: 256
#長さN 試行回数K
N, K = map(int, input().split())
#配列S
S = input()
A = []
if S[0] == '0':
  A.append(0)
  
i = 0
#次に違う数字が出てくるまでをカウント
while i < len(S):
  j = i
  while j < len(S) and S[i] == S[j]:
    j += 1
  A.append(j - i)
  i = j
#print(A)  
ans = 0
tot = 0
r = 0
for l in range(len(A)):
  while r < len(A) and r - l < 2 * K + 1:
    tot += A[r]
    r += 1
  if l % 2 == 0:
    ans = max(ans, tot)
  if r == l:
    r += 1
  else:
    tot -= A[l]
print(ans)

Measured memory_bytes: 45808
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc060/tasks/abc060_b

int main() {
    int a, b, c; cin >> a >> b >> c;
    for (int i = 1; i <= b; i++) if(a*i%b==c){
            cout << "YES" << "\n";
            return 0;
    }
    cout << "NO" << "\n";

    return 0;
}


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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<pair<long long,long long>> b(n + 1, make_pair(0,0));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[a[i]].first++;
	}
	for (int i = 1; i <= n; i++) {
		if (b[i].first != 0) {
			b[i].second = b[i].first * (b[i].first - 1) / 2;
		}
		
		b[i].second += b[i - 1].second;
	}
	for (int i = 0; i < n; i++) {
		cout << b[n].second - b[a[i]].first + 1 << endl;
	}
	
	return 0;
}

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

const int A = 1e6 + 5;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(A);
    rep(i,n) {
        cin >> a.at(i);
        c.at(a.at(i))++;
    }

    bool pairwise = true;
    for (int i = 2; i < A; ++i) {
        int count = 0;
        for (int j = i; j < A; j += i) {
            count += c.at(j);
        }
        if (count > 1) pairwise = false;
    }
    if (pairwise) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    
    int g = 0;
    rep(i,n) g = gcd(g, a.at(i));
    if (g == 1) {
        cout << "setwise coprime" << endl;
        return 0;
    }
    
    cout << "not coprime" << endl;

    return 0;
}

Measured memory_bytes: 11160
#include <bits/stdc++.h>
using namespace std;
vector<int> parent(vector<vector<int>> &E, int r){
	int N = E.size();
	vector<int> p(N, -1);
	queue<int> Q;
	Q.push(r);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (p[w] == -1){
				p[w] = v;
				Q.push(w);
			}
		}
	}
	return p;
}
vector<vector<int>> child_2(vector<int> &p, int r){
	int N = p.size();
	vector<vector<int>> c(N);
	for (int i = 0; i < N; i++){
		if (i != r){
			c[p[i]].push_back(i);
		}
	}
	return c;
}
void dfs(vector<long long> &A, vector<vector<int>> &c, int v, bool &ok){
  if (c[v].empty()){
    return;
  }
  long long sum = 0;
  long long M = 0;
  for (int w : c[v]){
    dfs(A, c, w, ok);
    sum += A[w];
    M = max(M, A[w]);
  }
  long long tmp = A[v] * 2 - sum;
  long long pair_cnt = (sum - tmp) / 2;
  /*
  cout << "v = " << v << endl;
  cout << "sum = " << sum << endl;
  cout << "pair = " << pair_cnt << endl;
  cout << "max = " << M << endl;
  */
  long long pair_cnt_2 = min(sum - M, sum / 2);
  if (pair_cnt_2 < pair_cnt || tmp < 0 || pair_cnt < 0){
    //cout << "not ok" << endl;
    ok = false;
  }
  A[v] = tmp;
}
int main(){
  int N;
  cin >> N;
  vector<long long> A(N, 0);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  if (N == 2){
    if (A[0] == A[1]){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
    return 0;
  }
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  int r = 0;
  for (int i = 0; i < N; i++){
    if (E[i].size() != 1){
      r = i;
      break;
    }
  }
  vector<int> p = parent(E, r);
  vector<vector<int>> c = child_2(p, r);
  bool ok = true;
  dfs(A, c, r, ok);
  if (ok && A[r] == 0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 21760
#include<iostream>
#include<cstdio>
using namespace std;
#define lowbit(x) ((x) & (-x))
const int maxn = 200005;
int n, a[maxn];
int tr[maxn];

void add(int x, int k) {
	while (x <= n) {
		tr[x] += k;
		x += lowbit(x);
	}
}

int query(int x) {
	int ret = 0;
	while (x) {
		ret += tr[x];
		x -= lowbit(x);
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		add(a[i], 1);
		ans += !query(a[i] - 1);
	}
	printf("%d\n", ans);
	return 0;
}

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

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

    int ma = max({a, b, c});

    if ((3 * ma - a - b - c) % 2 == 0)
        cout << (3 * ma - a - b - c) / 2;
    else
        cout << (3 * (ma + 1) - a - b - c) / 2;
    cout << endl;

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x));

            var result1 = a.OrderBy(x => x);

            var ans = 0;

            for (int i = 1; i < result1.Count(); i++)
            {
                ans += result1.ElementAt(i) - result1.ElementAt(i - 1);
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396