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

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        int ans;
        for(int i = 0;i < 3;i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        ans = (A[1]-A[0])+(A[2]-A[1]);
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    long double A,B;
    cin >> A >> B;
    A = 1.0/A;
    B = 1.0/B;
    cout << fixed << setprecision(50) << (1/(A+B)) << endl;
}


Measured memory_bytes: 3736
import math

D,G = list(map(int,input().split()))
lst = [list(map(int,input().split())) for i in range(D)]
for i in range(10-D):
    lst.append([0,0]) 
lst.insert(0,[])

ans = 1000
for i in range(1024):
    bin_i = format(i,'b').zfill(11)
    tmp = G
    solved = 0
    for j in range(1,11):
        if bin_i[j] == "1":
            tmp -= lst[j][0]*j*100 + lst[j][1]
            solved += lst[j][0]
    if 0 < tmp:
        for j in range(10,0,-1):
            if bin_i[j] == "0" and lst[j][0] != 0:
                if tmp <= (lst[j][0]-1)*j*100:
                    solved += math.ceil(tmp/(j*100))
                    break
        else:
            #この条件ではGを超えない
            continue
        ans = min(ans,solved)
    else:
        ans = min(ans,solved)
print(ans)

Measured memory_bytes: 3188
n=int(input())
a,c,i=[],0,1
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            a.append(i)
            i+=1
            continue
    c=0
    if x%10==3:
        a.append(i)
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print(' ', end='')
print(*a)

Measured memory_bytes: 8208
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<set>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  string s;
  cin >> s;
  set<char> st;
  rep(i, s.size()){
    st.insert(s[i]);
  }
  if((int)s.size() == (int)st.size()) cout << "yes" << endl;
  else cout << "no" << endl;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val s = readInputLine().toCharArray()
    // 羊 : true, 狼 : false
    val ans = CharArray(N)
    
    // 1番目, 2番目を羊とする
    ans[0] = 'S'
    ans[1] = 'S'
    
    calc(ans, s, N)

    if (lastCheck(ans, s, N)) {
        printAns(ans)
        return
    }
    
    // 1番目を羊, 2番目を狼とする
    ans[0] = 'S'
    ans[1] = 'W'
    
    calc(ans, s, N)

    if (lastCheck(ans, s, N)) {
        printAns(ans)
        return
    }

    // 1番目を狼, 2番目を羊とする
    ans[0] = 'W'
    ans[1] = 'S'
    
    calc(ans, s, N)

    if (lastCheck(ans, s, N)) {
        printAns(ans)
        return
    }
    
    // 1番目, 2番目を狼とする
    ans[0] = 'W'
    ans[1] = 'W'
    
    calc(ans, s, N)

    if (lastCheck(ans, s, N)) {
        printAns(ans)
        return
    }
    
    println(-1)
}

fun calc(ans: CharArray, s: CharArray, N: Int) {
    for (i in 2 until N) {
        if (ans[i - 1] == 'S') {
            if (s[i - 1] == 'o') {
                ans[i] = ans[i - 2]
            } else {
                ans[i] = if (ans[i - 2] == 'S') 'W' else 'S'
            }
        } else {
            if (s[i - 1] == 'o') {
                ans[i] = if (ans[i - 2] == 'S') 'W' else 'S'
            } else {
                ans[i] = ans[i - 2]
            }
        }
    }    
}

fun readInputLine(): String {
    return readLine()!!
}

fun lastCheck(ans: CharArray, s: CharArray, N: Int): Boolean {
    var ok = true
    if (ans[N - 1] == 'S') {
        if (s[N - 1] == 'o') {
            ok = ok && (ans[N - 2] == ans[0])
        } else {
            ok = ok && (ans[N - 2] != ans[0])
        }
    } else {
        if (s[N - 1] == 'o') {
            ok = ok && (ans[N - 2] != ans[0])
        } else {
            ok = ok && (ans[N - 2] == ans[0])
        }
    }

    if (ans[0] == 'S') {
        if (s[0] == 'o') {
            ok = ok && (ans[N - 1] == ans[1])
        } else {
            ok = ok && (ans[N - 1] != ans[1])
        }
    } else {
        if (s[0] == 'o') {
            ok = ok && (ans[N - 1] != ans[1])
        } else {
            ok = ok && (ans[N - 1] == ans[1])
        }
    }
    
    return ok
}

fun printAns(ans: CharArray) {
    for (c in ans) {
        print(c)
    }

    println()
}


Measured memory_bytes: 41156
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }
    bool flag = false;
    for(int i = 2; i < s.size()-1; i++)
    {
        if(s[i] == 'C')
        {
            flag = true;
        }
    }
    int count = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            count++;
        }
    }
    if(flag && count == 2)
    {
        cout << "AC" << endl;
    }
    else
    {
        cout << "WA" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int codeNum = scan.nextInt();
		int num = scan.nextInt();
		int C = scan.nextInt();
		
		int[] B = new int[num];
		for (int i = 0; i < B.length; i++) {
			B[i] = scan.nextInt();
		}
		
		int[][] A = new int[codeNum][num];
		for (int i = 0; i < codeNum; i++) {
			for (int j = 0; j < num; j++) {
				A[i][j] = scan.nextInt();
			}
		}
		
		int sum = 0;
		int count = 0;
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < num; j++) {
				sum += B[j] * A[i][j];
			}
			if (sum + C > 0) {
				count++;
			}
			sum = 0;
		}
		
		System.out.println(count);
		scan.close();
	}
}

Measured memory_bytes: 22100
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		int rows = 3000;
		int columns = 2;
		int count = 0;
		Scanner s = new Scanner(System.in);
		int[][] sort = new int[rows][columns];
		int temp;

		for (int i = 0; i < 3000; i++) {
			sort[i][0] = s.nextInt();
			sort[i][1] = s.nextInt();
			if (sort[i][0] >= 0 && sort[i][1] >= 0 && sort[i][0] <= 10000 && sort[i][1] <= 10000) {
				if (sort[i][0] > sort[i][1]) {
					temp = sort[i][0];
					sort[i][0] = sort[i][1];
					sort[i][1] = temp;
				}
				if (sort[i][0] == 0 && sort[i][1] == 0) {
					count = i;
					break;
				}

			}
		}

		for (int a = 0; a < count; a++) {
			System.out.println(sort[a][0] + " " +sort[a][1]);
		}
	}
}

Measured memory_bytes: 36176
<?php
list($K, $S) = explode(" ", trim(fgets(STDIN)));
$c = 0;
for($i = 0; $i <= $K; $i++){
    for($j = 0; $j <= $K; $j++){
        if($S - $i - $j >= 0 && $S - $i - $j <= $K){
            $c++;
        }
    }
}
echo $c;

Measured memory_bytes: 4728
import sys
input = sys.stdin.readline
#read=sys.stdin.buffer.read
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

a, b, c, k = map(int, input().split())

if (a+b) >= k:
    print(min(k,a))
else:
    print(a-(k-a-b))


Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else if(s == "ARC"){
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define pb push_back
#define pf push_front
int main(void){
  string s;
  cin>>s;
  int size=s.size();
  int now=size/2;
  int l=now,r=now;
  while(l>0){
    if(s[l]!=s[l-1]){
      break;
    }else{
      l--;
    }
  }
  while(r<size-1){
    if(s[r]!=s[r+1]){
      break;
    }else{
      r++;
    }
  }

  cout<<min(size-1-l+1,r+1)<<endl;
  return 0;
}

Measured memory_bytes: 512
s = input()
k = int(input())
c = 1
i = 1
l = []
c2 = 0
while i < len(s):
    if i == len(s)-1:
        if s[i] == s[i-1]:
            c = c+1
            l.append(c)
            i = i+1
        else:
            l.append(c)
            l.append(1)
            i = i+1
    elif s[i] == s[i-1]:
        c = c + 1
        i = i + 1
    else:
        l.append(c)
        c = 1
        i = i+1
if len(l) == 1:
    print((len(s)*k)//2)
elif s[0] == s[len(s)-1]:
    if len(s)==1:
        print(k//2)
    else:
        for i in range(1,len(l)-1):
            c2 = c2 + l[i]//2
        print(c2*k+((l[0]+l[len(l)-1])//2)*(k-1)+l[0]//2+l[len(l)-1]//2)
else:
    for i in range(0,len(l)):
        c2 = c2 + l[i]//2
    print(c2*k)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ll long long
#define sz size()
#define ft front
#define pu push
#define ty empty
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int m5=100042;
int cnt[2*m5];
int n;
int main(void)
{
	int i;
	cin>>n;
	for(i=1;i<n;i++)
	{
		int ip;
		cin>>ip;
		cnt[ip]++;
	}
	for(i=1;i<=n;i++)
	{
		cout<<cnt[i]<<endl;
	}
    return 0;
}



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

using namespace std;

int n, mx;
int a[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&n,&mx);
	for(int i = 1; i <= n; ++i){
		scanf("%d",&a[i]);
	}
	for(int i = 1; i < n; ++i) if (a[i] + a[i + 1] >= mx){
		printf("Possible\n");
		for(int j = 1; j < i; ++j) printf("%d\n",j);
		for(int j = n - 1; j > i; --j) printf("%d\n",j);
		printf("%d",i);
		return 0;
	}
	printf("Impossible");
	return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>b[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	llin(n);
	vllin(c,n);
	vll m(n,-1);
	vll l(200005,-1);
	m[0]=1;
	l[c[0]]=0;
	FOR(d,1,n-1){
	if(c[d]==c[d-1]){
		m[d]=m[d-1];
	}else{
		if(l[c[d]]==-1){
			m[d]=m[d-1];
		}else{
			m[d]=(m[d-1]+m[l[c[d]]])%MOD;
		}
	}
	l[c[d]]=d;
	}
	sal(m[n-1]);
}

Measured memory_bytes: 5504
import java.util.Scanner;

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

		int S = scan.nextInt();
		int h = S/60/60;
		int m = S/60 - h*60;
		int s = S % 60;

		System.out.println(String.format("%d:%d:%d", h, m, s));
	}
}



Measured memory_bytes: 26512
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

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

  int D=K%10;
  if(D!=1 && D!=7 && D!=3 && D!=9){
    cout << -1 << endl;
    return 0;
  }

  int ans=0;
  int now=K;
  while(now!=0){
    int tmp=now%10;
    if(tmp==7){
      now/=10;
      ans++;
      continue;
    }
    for(int i=0;i<10;i++){
      if((K*i + now)%10==7){
        now+=K*i;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, m;
    cin >> n >> m;
    ll ac[100010] = {0}, wa[100010] = {0};
    rep(i, 0, m) {
        ll p;
        string s;
        cin >> p >> s;
        p--;
        if(s == "AC") {
            if(ac[p] == 0) ac[p]++;
        }
        else {
            if(ac[p] == 0) wa[p]++;
        }
    }

    ll cnta = 0, cntw = 0;
    rep(i, 0, n) cnta += ac[i], cntw += wa[i] * ac[i];
    cout << cnta << " " << cntw << endl;
}


Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a = read::<i64>();
    println!("{}", a*a)
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
  int64_t N, M;
  cin >> N >> M;
  int64_t mx_l = 0;
  int64_t mn_r = 1000000;
  vector<pair<int64_t, int64_t>> gates(M);
  for (int64_t m = 0; m < M; ++m) {
    int64_t l, r;
    cin >> l >> r;
    gates[m] = {l, r};
    mx_l = max(mx_l, l);
    mn_r = min(mn_r, r);
  }
  int64_t res = 0;
  for (int64_t n = 1; n <= N; ++n) {
    if (mx_l <= n && n <= mn_r) {
      ++res;
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 4808
from sys import stdin, stdout
from collections import deque, defaultdict
from functools import lru_cache

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	MOD = 10**9 + 7
	x = []
	for c in rll()[0]:
		x.append(int(c))
	d = int(rl())
	ans = 0

	dp = [[0]*2 for _ in range(d)]
	dp[0][1] = 1
	for i in range(len(x)):
		ndp = [[0]*2 for _ in range(d)]
		for digsum in range(d):
			for tight in range(2):
				for nd in range(x[i]+1 if tight else 10):
					ns = (digsum + nd) % d 
					ntight = 1 if tight and nd == x[i] else 0
					ndp[ns][ntight] += dp[digsum][tight]
					ndp[ns][ntight] %= MOD
		dp = ndp

	ans = (dp[0][0] + dp[0][1] - 1) % MOD
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

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

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<int> ACList(N);
  vector<int> WCList(N);
  vector<int> output(2); // {WC, AC}
  
  for(int i = 0; i < M; i++) {
    int index;
    string result;
    cin >> index;
    cin >> result;
    
    if (ACList.at(index - 1) == 0) {
      // ACが出ていない場合のみ
      if (result == "AC") {
        ACList.at(index - 1) = 1;
        output.at(1) += 1;
        output.at(0) += WCList.at(index - 1);
      } else {
        WCList.at(index - 1) += 1;
      }
    }
  }
  
  cout << output.at(1);
  cout << " ";
  cout << output.at(0) << endl; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	ll n,max,min,i,a;
	
	cin>>n;
	
	max=LONG_LONG_MIN;
	min=LONG_LONG_MAX;
	for(i=1;i<=n;i++){
		cin>>a;
		if(max<a-min) max=a-min;
		if(min>a) min=a;
	}
	
	cout<<max<<endl;
}


Measured memory_bytes: 3112
/*
Author: CNYALI_LK
LANG: C++
PROG: d.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0;
	int base=0;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=1;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	if(base)s=-s;
	return s;
}
int a[102423];
int main(){
#ifdef cnyali_lk
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout);
#endif
	int n,m,cntO=0;
	n=read();m=read();
	for(int i=1;i<=m;++i)a[i]=read(),cntO+=a[i]&1;
	if(cntO>2)printf("Impossible\n");
	else{
		for(int i=2;i<m;++i)
			if(a[i]&1)if(a[1]&1){swap(a[i],a[m]);--i;}
			else swap(a[i],a[1]);
		for(int i=1;i<=m;++i)printf("%d%c",a[i],i==m?'\n':' ');
		if(m==1)a[++m]=a[1],a[1]=0;
		++a[1];
		if(!--a[m])--m;
		
		printf("%d\n",m);
		for(int i=1;i<=m;++i)printf("%d%c",a[i],i==m?'\n':' ');
	}
	return 0;
}



Measured memory_bytes: 256
import sys
def rr(): return sys.stdin.readline().rstrip()
def rri(): return int(rr())
def rrl(): return list(map(int, rr().split()))
def rrt(): return tuple(map(int, rr().split()))
def rrle(): return (line.rstrip() for line in sys.stdin.readlines())
def rrtl(): return [tuple(map(int, l.split())) for l in rrle()]
from collections import defaultdict
def mus(d=lambda: 0): return defaultdict(lambda: defaultdict(d))
def dd0(d=lambda: 0): return defaultdict(d)
def ms(x, y, d=0): return [[0]*y for i in range(x)]
def ar(x, d=0): return [d]*x
def ppm(m, n=0, x=0, y=0): print("\n".join(("\t".join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))
def ppa(a, n): print("\t".join(map(str, a[0:n])))
def ppl(a=0, x=[1]): x[0]=a or (x[0]+1); print("-"+"- -"*14+"-# "+str(x[0]-2)+" #-"+"- -"*14+"-")
def fltn(a): (i for sub in a for i in sub)
def yn(x): return "YES" if x else "NO"
from itertools import accumulate
from itertools import groupby
def grp(x): return ((i, sum(1 for _ in g)) for i, g in groupby(x))
import math
#def rnar(): return (*rrl(), rrl())
#def rn(): return (*rrl(),)
def dpp(a, b=""): print("#| {} |#:^ {} ^:".format(a, b))

def read():
    h, w = rrl()
    return (h, w, list(rrle()),)

def solve(h, w, field):
    dp = ms(h, w)
    dp[0][0] = 1
    for i in range(1, h):
        if field[i][0] == ".":
            dp[i][0] = dp[i-1][0]
    for i in range(1, w):
        if field[0][i] == ".":
            dp[0][i] = dp[0][i-1]

    for i in range(1, h):
        for j in range(1, w):
            if field[i][j] == ".":
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % (10**9 + 7)
    ans = dp[-1][-1]
    return ans

if __name__ == "__main__":
    #test_count = rri()
    test_count = 1
    for _ in range(test_count):
        input_data = read()
        result = solve(*input_data)
        print(result)


Measured memory_bytes: 54896
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
data=[]
for i in range(h-1):
    count=0
    lst=a[i]
    for j in range(w-1):
        if lst[j]%2==1:
            count+=1
        if count%2==1:
            data.append([i+1,j+1,i+1,j+2])
    if lst[w-1]%2==1:
        count+=1
    if count%2==1:
        data.append([i+1,w,i+2,w])
        a[i+1][w-1]+=1
count=0
lst=a[h-1]
for j in range(w-1):
    if lst[j]%2==1:
        count+=1
    if count%2==1:
        data.append([h,j+1,h,j+2])
print(len(data))
for v in data:
    print(" ".join(list(map(str,v))))

Measured memory_bytes: 29824
#include <stdio.h>

int gcd(int x, int y) {
    int t, r;
    if (x<y) {
        t=x;
        x=y;
        y=t;
    }
    r=x%y;
    while (r!=0) {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}

int main(void) {
    int K, x, i, j, k;
    scanf("%d", &K);
    x=0;
    for (i=1; i<=K; i++) {
        for (j=1; j<=K; j++) {
            for (k=1; k<=K; k++) x+=gcd(gcd(i, j), k);
        }
    }
    printf("%d", x);
    return 0;
}

Measured memory_bytes: 1736
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,k = map(int,input().split())

val1 = n % k
val2 = abs(val1-k)
ans = min(val1,val2)

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vvec<int> g(N);
    int ans = 0;
    vec<int> par(N,-1);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        a--;
        if(!i) ans = a!=0;
        else g[a].push_back(i);
    }

    vec<int> dep(N,-1);
    auto dfs = [&](auto&& self,int cur,int par)->void{
        int ma = 0;
        for(auto& to:g[cur]) if(to!=par){
            self(self,to,cur);
            ma = max(ma,dep[to]+1);
        }
        if(par>0 && ma==K-1){
            ans++;
            dep[cur] = -1;
        }else{
            dep[cur] = ma;
        }
    };
    
    dfs(dfs,0,-1);
    cout << ans << "\n";
}

Measured memory_bytes: 17136
#include<stdio.h>
int main(){

    int N,i,c=0;
    scanf("%d",&N);
    char S[N];
    scanf("%s",S);

    for(i=0;i<=N-3;i++){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') c++;
    }
    printf("%d",c);
    return 0;
}

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

struct Review {
    int idx;
    string city;
    int point;
};

bool comp(Review r1, Review r2) {
    if (r1.city == r2.city) {
        return r1.point > r2.point;
    } else {
        return r1.city < r2.city;
    }
}

int main() {
    int n;
    cin >> n;
    Review r[n];

    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        r[i].city = s;
        r[i].point = p;
        r[i].idx = i + 1;
    }

    sort(r, r + n, comp);

    for (auto e : r) cout << e.idx << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int num;
    char city[10];
    int p;
} *restaurant;

void func1(restaurant *r, int n) {
    int i, j;
    for (int i = 0; i < n; i++) {
        for (int j = n-1; j > i; j--) {
            if (strcmp(r[j]->city, r[j-1]->city) < 0) {
                restaurant p = r[j];
                r[j] = r[j-1];
                r[j-1] = p;
            }
        }
    }
}

void func2(restaurant *r, int n) {
    int i, j;
    for (int i = 0; i < n; i++) {
        for (int j = n-1; j > i; j--) {
            if (strcmp(r[j]->city, r[j-1]->city) == 0 && r[j]->p > r[j-1]->p) {
                restaurant q = r[j];
                r[j] = r[j-1];
                r[j-1] = q;
            }
        }
    }
}

int main() {
    int n;
    restaurant *r;
    scanf("%d", &n);
    r = malloc(sizeof(restaurant)*n);
    for (int i = 0; i < n; i++) {
        r[i] = malloc(sizeof(r[i][0]));
    }

    for (int i = 0; i < n; i++) {
        r[i]->num = i+1;
        scanf("%s", r[i]->city);
        scanf("%d", &r[i]->p);
    }

    func1(r, n);
    
    func2(r, n);
    
    for (int i = 0; i < n; i++) {
        printf("%d\n", r[i]->num);
    }

    return 0;
}


Measured memory_bytes: 128
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var n = p.length;
  var r = [];
  for (var i = 0; i < n; i++) {
    var x = p.shift();
    if (x in r) {
      r[x]++;
    } else {
      r[x] = 0;
    }
  }
  var a = [];
  for (i = 0; i < r.length; i++) {
    var m = r[i];
    if (isNaN(m)) {
      m = 0;
    }
    if (m in a) {
      a[m].push(i);
    } else {
      a[m] = [i];
    }
  }
  console.log(a[a.length - 1].join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7376
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>

#pragma GCC diagnostic ignored "-Wunused-result"

using namespace std;

typedef long long LL;

void solve(long long n, long long m, std::string s) {
	LL goal = n, prev = -1;
	vector<LL> ans;
	for (LL i = n - 1; i >= 0; --i) {
		if (i + m < goal) {
			if (prev < 0) {
				cout << -1 << endl;
				return;
			}
			ans.push_back(goal);
			goal = prev;
			prev = -1;
		}
		if (s[i] == '0') {
			prev = i;
		}
	}
	ans.push_back(goal);
	if (prev >= 0) {
		ans.push_back(0);
	}
	reverse(ans.begin(), ans.end());
	for (LL i = 1; i < (LL)ans.size(); ++i) {
		if (i > 1) {
			cout << " ";
		}
		cout << (ans[i] - ans[i - 1]);
	}
	cout << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	long long M;
	scanf("%lld", &M);
	std::string S;
	std::cin >> S;
	solve(N, M, S);
	return 0;
}


Measured memory_bytes: 4564
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define fr(i,a,b) for(register int i=a;i<=b;i++)
#define int long long
#define N 1010
using namespace std;

int a[N][N],now[N];
bool vis[N];

inline int read(){
	int x = 0,f = 1;char c = getchar();
	while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}
	while(isdigit(c)){x = x * 10 + c - '0';c = getchar();}
	return f * x;
}

signed main(){
	int n;
	n = read();
	fr(i,1,n)
		fr(j,1,n - 1)
			a[i][j] = read();
	fr(i,1,n)now[i] = 1;
	int ans = 0;
  	bool flag = 1;
	while(++ans){
		bool f = 1;flag = 0;
		memset(vis,false,sizeof(vis));
		fr(j,1,n){
			int p = a[j][now[j]];
			if(a[p][now[p]] == j && !vis[p] && !vis[j])flag = 1,now[j]++,now[p]++,vis[j] = 1,vis[p] = 1;
		}
		fr(j,1,n)if(now[j] != n){f = 0;break;}
		if(f)break;
		if(!flag || ans > n * (n - 1) / 2){cout<<"-1";return 0;}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>

int main(void){
  int N,M;
  scanf("%d%d",&N,&M);

  char A[N][N],B[M][M];

  for(int i = 0;i < N;i++) scanf("%s",A[i]);
  for(int i = 0;i < M;i++) scanf("%s",B[i]);

  int flag = 1;
  for(int i = 0;i <= N-M;i++){
    for(int j = 0;j <= N-M;j++){
      flag = 1;
      for(int x = 0;x < M;x++){
        for(int y = 0;y < M;y++){
          if(A[i+x][j+y] != B[x][y]){
            flag = 0;
            break;
          }
        }
      }
      if(flag){
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
import itertools

n = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))

data = sorted(q_list)

l = list(itertools.permutations(data, n))
for i in range( len(l) ):
    l[i] = list(l[i])

print( abs( l.index(p_list) - l.index(q_list) ) )



Measured memory_bytes: 12276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main {
	static FastScanner sc = new FastScanner();
	static int N, Q;
	static int[][] key = new int[1024][256];
	static int[][] val = new int[1024][256];
	static Reader input = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		StringBuilder sb = new StringBuilder();
		int[] A = new int[100000];
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			int S = sc.nextInt();
			int W = sc.nextInt();
			Q = sc.nextInt();
			int g = S;
			for (int i = 0; i < N; ++i) {
				A[i] = (g / 7) % 10;
				g = (g / 2) ^ (W * (g % 2));
			}
			sb.append(solve(A) + "\n");
		}
		System.out.print(sb);
	}

	static long solve(int[] A) {
		long ans = 0;
		if (Q == 2 || Q == 5) {
			int nonzero = 0;
			for (int i = 0; i < N; ++i) {
				if (A[i] != 0) ++nonzero;
				if (A[i] % Q == 0) {
					ans += nonzero;
				}
			}
			return ans;
		}
		for (int i = 0; i < key.length; ++i) {
			for (int j = 0; val[i][j] != 0; ++j) {
				val[i][j] = 0;
			}
		}

		long sum = 0;
		long base = 1;
		for (int i = 0; i < N; ++i) {
			sum += A[N - 1 - i] * base;
			while (sum >= Q) {
				sum -= Q;
			}
			base *= 10;
			while (base >= Q) {
				base -= Q;
			}
			int c = 0;
			int k = (int) (sum & 1023);
			for (int j = 0;; ++j) {
				if (val[k][j] == 0) {
					key[k][j] = (int) sum;
					val[k][j] = 1;
					break;
				}
				if (key[k][j] == (int) sum) {
					c = val[k][j];
					val[k][j]++;
					break;
				}
			}
			if (A[N - 1 - i] != 0) {
				ans += c;
				if (sum == 0) ans++;
			}
		}
		return ans;
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this.input = new BufferedReader(new InputStreamReader(System.in));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}

}

Measured memory_bytes: 25148
#include <bits/stdc++.h>
#define int unsigned long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 300005 // check
#define M 101
using namespace std;

int inf = 1e9;
int mod =  998244353ll;

int n,m;
int a,b,k;
int tab[N];

int pow(int x, int y) {
    if(y == 0) return 1;
    if(y == 1) return x%mod;
    if(y&1) return x*pow(x,y-1)%mod;
    int k = pow(x,y/2);
    return k*k%mod;
}

int inv(int x) {
    return pow(x,mod-2);
}

int fac[N];
int invFac[N];

int bin(int n, int k) {
    if(k == 0) return 1;
    return ((fac[n]*invFac[k]%mod)*invFac[n-k]) % mod;
}

main() {
    ios_base::sync_with_stdio(false);
    cin >> n; cin >> a >> b; cin >> k;
    fac[0] = 1;
    invFac[0] = 1;
    for(int i = 1; i <= n; ++i) {fac[i] = fac[i-1]*i % mod; invFac[i] = inv(fac[i]);}
    int naile = 0;
    for(int i = 0; i <= n; ++i) {
        int y = i;
        if((y*b > k)) continue;
        if((k-y*b) % a != 0) continue;
        int x = (k-y*b)/a;
        if(x > n) continue;
        naile += bin(n,x)*bin(n,y) % mod;
        naile %= mod;
    }
    cout << naile << endl;
}

Measured memory_bytes: 6400
using System;
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var dic = new Dictionary<string, int>();
		var N = NextInt();

		for (var i = 0; i < N; i++) {
			var s = ReadLine();
			if (dic.ContainsKey(s)) {
				dic[s]++;
			} else {
				dic[s] = 1;
			}
		}

		var M = NextInt();
		for (var j = 0; j < M; j++) {
			var t = ReadLine();
			if (dic.ContainsKey(t)) {
				dic[t]--;
			}
		}

		var ans = 0;
		foreach (var val in dic.Values) {
			ans = Math.Max(ans, val);
		}

		WriteLine(ans);
	}

	static int NextInt() {
		return int.Parse(ReadLine());
	}
}

Measured memory_bytes: 13268
from copy import deepcopy
from itertools import product
H, W, K = map(int, input().split())
ls = []
for i in range(H):
    s = list(input())
    ls.append(s)
ans = 0
for x in product([0, 1], repeat=H):
    for y in product([0, 1], repeat=W):
        p = deepcopy(ls)
        num = 0
        for i, j in enumerate(x):
            if j == 1:
                for w in range(W):
                    p[i][w] = '?'
        for i, j in enumerate(y):
            if j == 1:
                for h in range(H):
                    p[h][i] = '?'
        for k in p:
            for l in k:
                if l == '#':
                    num += 1
        if num == K:
            ans += 1
print(ans)

Measured memory_bytes: 9368
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int Mod = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e5+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b, ll M)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans % M;
}


void task()
{
    //code here...
    
    int a, b;
    
    cin >> a >> b;
    
    if(a==b){
		for(int K=0; K<a; K++) cout << a;
	}
	else if(a<b){
		for(int K=0; K<b; K++) cout << a;
	}
	else{
		for(int K=0; K<a; K++) cout << b;
	}
	
	cout << "\n";
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}



Measured memory_bytes: 3640
public class Main {
    public static void main (String[] srgs){

        // ??????????????????????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);

        // ?????????????????? int ?????¨??????????????\???????????????.
        // ??????????????????????????? 0 ????????????.
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) { break; }

            // H * W ???????????¢ (????????????) ???????????????.
            for (int i = 0; i < H; i ++) {
                if (i == 0 || i == H - 1) {
                    for (int j = 0; j < W; j ++) { System.out.print("#"); }
                }
                else {
                    for (int j = 0; j < W; j ++) {
                        if (j == 0 || j == W - 1) { System.out.print("#"); }
                        else { System.out.print("."); }
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}

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

int main(){
  	long long int A, B, C, K;
  	cin >> A >> B >> C >> K;
  
  	long long int res = 0;
  	
  	if (K < A) res += K;
  	else {
      	res += A;
      	K -= A;
      	if (K >= B) {
          	K -= B;
          	res -= K;
        } 
    }
  
  	cout << res << endl;
}

Measured memory_bytes: 3632
package main

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

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	arr := make([][]int, M)
	m := map[int][]int{}
	sm := map[int]map[int]int{}
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range arr {
		w := make([]int, 2)
		sc.Scan()
		w[0], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		w[1], _ = strconv.Atoi(sc.Text())
		arr[i] = w
		m[w[0]] = append(m[w[0]], w[1])
	}
	for _, v := range m {
		sort.Ints(v)
	}
	for k, v := range m {
		sm[k] = map[int]int{}
		for i := 0; i < len(v); i++ {
			sm[k][v[i]] = i + 1
		}
	}
	for i := range arr {
		fmt.Printf("%06d%06d\n", arr[i][0], sm[arr[i][0]][arr[i][1]])
	}
}

Measured memory_bytes: 41984
#include<stdio.h>
int main(void){
    int a,b,c,i=1;
    scanf("%d %d",&a,&b);
    while(i<=1000){
        if(b/i==0){
            c=a*i+b;
            break;
        }
        i*=10;
    }
    for(i=0;i<=320;i++){
        if(i*i==c){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
	return 0;		
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
        prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


int main() {
    ll N;
    cin >> N;

    vector<ll> A(N), B(N);
    for(ll i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    double mid_min = 0;
    double mid_max = 0;

    if(N % 2 == 0) {
        mid_min = (A[N/2] + A[N/2 - 1]) /2.0;
        mid_max = (B[N/2] + B[N/2 - 1]) /2.0;
    } else {
        mid_min = A[(N-1)/2];
        mid_max = B[(N-1)/2];
    }


    if(N % 2 == 0) {
        cout << (ll) ((mid_max - mid_min) * 2.0  + 1.0)<< endl;
    } else {
        cout << (ll) ((mid_max - mid_min)   + 1.0)<< endl;
    }






    return 0;    
}



Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const ll mod = 1000000000 + 7;

int main() {
	ll n;
	cin >> n;
	if (n%7 == 0) {cout << "Yes" << endl; return 0;}
	REP(i, n/7+1){
		if ((n-7*i)%4 == 0) {cout << "Yes" << endl; return 0;}
	}
	cout << "No" << endl;
}


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

using namespace std;

using vi = vector<int>;

#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N);

  vi V(N);
  REP(i, N) {
    cin >> V[i];
  }
  SORT(V);
  double bef = V[0];
  FOR(i, 1, N) {
    bef=(bef+V[i])/2;
  }
  OUT(fixed<<setprecision(9)<<bef);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int data[15][15]={0};
int fun1(int x,int y,int z);
int main(void)
{
	int i,j,x,y,z,Max=0,count=0;
	while(scanf("%d,%d,%d",&x,&y,&z)!=EOF){
	fun1(x,y,z);
	}
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(data[i][j]==0) count++;
			if(Max<data[i][j]) Max=data[i][j];
		}
	}
	printf("%d\n%d\n",count,Max);
	return 0;
}
int fun1(int x,int y,int z){
	int i,j;
		if(z==1){
			data[x][y-1]++;
			data[x][y+1]++;
				for(i=x-1;i<=x+1;i++){
					data[i][y]++;
				}
		}
		if(z==2){
			for(i=x-1;i<=x+1;i++){
				for(j=y-1;j<=y+1;j++){
					data[i][j]++;
				}
			}
		}
		if(z==3){
			for(i=x-1;i<=x+1;i++){
				for(j=y-1;j<=y+1;j++){
					data[i][j]++;
				}
			}
			data[x][y-2]++;
			data[x][y+2]++;
			data[x-2][y]++;
			data[x+2][y]++;
		}
	return ;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int k;
	cin>>k;
	if(e-a<=k){
		cout<<"Yay!"<<endl;
	}
	else cout<<":("<<endl;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		j=str(i).zfill(3)
		now=0
		for k in s:
			if j[now]==k:
				now+=1
			if now==3:
				ans+=1
				break



	print(ans)



















if __name__ == "__main__":
	main()


Measured memory_bytes: 42904
#include <iostream>

using namespace std;

bool f(string a, string b, string c) {
    if (a[a.size() - 1] != b[0]) {
        return false;
    }
    if (b[b.size() - 1] != c[0]) {
        return false;
    }
    return true;
}

int main() {

    string a, b, c;
    cin >> a >> b >> c;

    if (f(a, b, c)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

odd_bit = 0b0101010101010101010101
eve_bit = 0b1010101010101010101010
full_bit = 2**n - 1

odd_num = (n + 1) // 2
ans = 10**9 

for i in range(2**n):
    invi = full_bit ^ i
    odd = bin(i & odd_bit).count("1") + bin(invi & eve_bit).count("1")
    if odd != odd_num:
        continue
    odd_card = []
    eve_card = []
    for j in range(n):
        if i & 1 << j:
            if j % 2 == 0:
                odd_card.append((a[j], j))
            else:
                eve_card.append((a[j], j))
        else:
            if j % 2 == 0:
                eve_card.append((b[j], j))
            else:
                odd_card.append((b[j], j))
    odd_card.sort()
    eve_card.sort()
    odd_itr = 0
    eve_itr = 0
    curr = 0
    val = 0
    ok = True
    perm = []
    for i in range(n):
        if i % 2 == 0:
            num, index = odd_card[odd_itr]
            perm.append(index)
            odd_itr += 1
        else:
            num, index = eve_card[eve_itr]
            perm.append(index)
            eve_itr += 1
        if num < curr:
            ok = False
            break
        curr = num
    if ok:
        val = 0
        visited = [0] * n
        itr = 0
        for item in perm:
            visited[item] = 1
            val += itr - sum(visited[:item])
            itr += 1
        ans = min(ans, val)

if ans == 10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;
const ll INF = LLONG_MAX/4;


//頂点fromから頂点toへのコストcostの辺
template<typename T>
struct edge{
    int f,t;
    T c;
    int id;
    edge(){};
    edge(int f,int t,T c,int id = 0):f(f),t(t),c(c),id(id){};
    bool operator< (const edge &s){
        return c < s.c;
    }
};

template<typename T>
struct graph{
    std::vector<std::vector<edge<T> > > data;
    graph(int v):data(v){};
    void add_edge(edge<T> &e){
        data[e.f].push_back(e);
    }
    void add_edge(int f,int t,T c){
        data[f].emplace_back(f,t,c);
    }
    size_t size(){
        return data.size();
    }
    std::vector<edge<T>> make_edges(){
        std::vector<edge<T>> r;
        for(auto &i:data)std::copy(i.begin(),i.end(),std::back_inserter(r));
        return r;
    }
};

vector<int> is_moved(n_max,0);

template<typename T>
void reach(graph<T> &g, int pos){
    is_moved[pos] = 1;
    for(auto i : g.data[pos]){
        if(!is_moved[i.t]){
            reach(g, i.t);
        }
    }
}

template<typename T>
std::vector<T> bellmanford(graph<T> &g, int s){
    // const T INF = std::numeric_limits<T>::max()/4;
    std::vector<T> data(g.size(),INF);
    data[s] = 0;
    for(int i=0;i<g.size()-1;i++){
        for(auto &v:g.data)for(auto &e:v){
            if(data[e.f]==INF)continue;
            data[e.t] = std::min(data[e.f] + e.c,data[e.t]);
        }
    }
    for(auto &v:g.data)for(auto &e:v){
        if(data[e.f]==INF)continue;        
        if(data[e.f] + e.c < data[e.t]){
            // fill(data.begin(),data.end(),std::numeric_limits<T>::min());
            fill(is_moved.begin(),is_moved.end(),0);
            reach(g,e.f);
            for(T i = 0; i < g.data.size();i++){
                if(is_moved[i])data[i] = -INF;
            }
            break;
        }
    }
    return data;
};


int main(){
    ll n,m; cin >> n >> m;
    graph<ll> g(n);
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--;b--;
        g.add_edge(a,b,-c);
    }
    vector<ll> res = bellmanford(g,0);
    if(res[n-1] == -INF){
        cout << "inf" << endl;
    }
    else{
        cout << -res[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	ll ans = 0;
	int pr = 0;
	REP(i, N) {
		int A;
		scanf("%d", &A);
		if (A < pr) {
			ans += pr - A;
		}
		else pr = A;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3660