akhauriyash/Code-Regression huggingface dataset:
n = int(input())
aas = list(map(int, input().split()))
acc = 0
res = 0
r = 0
for i in range(n):
    ok = True
    while r < n:
        s = format(aas[r],'020b')
        acc_s = format(acc,'020b')
        for j in range(20):
            if s[j] == '1':
                if acc_s[j] == '1':
                    ok = False
                    #print(j)
        if ok:
            acc += aas[r]
            r += 1
        else:
            break
    if r < n:
        res += r - i
    else:
        res += r - i
    acc -= aas[i]
print(res)

Measured memory_bytes: 32364
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize
    }
    if c < a - b {
        println!("0");
    } else {
        println!("{}", c - (a - b));
    }
}


Measured memory_bytes: 4352
'use strict'

const main = input => {
	const args = input.split('\n').map(t => t.split(' '))
	const n = parseInt(args[0][0], 10)
	const k = parseInt(args[0][1], 10)
	const h = args[1].map(t => parseInt(t, 10))
	const dp = new Array(n + k)

	for (let i = 0; i < dp.length; i++) {
		dp[i] = Infinity
	}

	dp[0] = 0

	for (let i = 0; i < n; i++) {
		for (let j = 1; j <= k; j++) {
			dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(h[i + j] - h[i]))
		}
	}

	console.log(dp[n - 1])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 27988
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ans := 0
	for i := 1; i <= n; i++ {
		if i%3 != 0 && i%5 != 0 && i%15 != 0 {
			ans += i
		}
	}

	fmt.Fprintln(wr, ans)
}


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

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


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,d[105],a[105],arr[105],cnt=0;
	cin>>n>>k;
	for(int i=0;i<n;i++) arr[i]=0;
	for(int i=0;i<k;i++){
		cin>>d[i];
		for(int j=0;j<d[i];j++){
			cin>>a[i];
			arr[a[i]-1]++;
		}
	}
	for(int i=0;i<n;i++){
		if(arr[i]==0) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
} 


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    vary(string,s,12,"");
    rep(i,12){
      cin >> s[i];
      if(cin.eof()) goto LABEL;
    }
    int x = 0,y = 0,ans = 0;
    bool f = true;
    while(f){
      rep(i,12){
        rep(j,12){
          if(s[i][j] == '1'){
            x = i;
            y = j;
            i = 12;
            j = 12;
            break;
          }
        }
        if(i == 11){
          f = false;
        }
      }
      if(f){
        queue<pii> q;
        q.push(make_pair(x,y));
        while(!q.empty()){
          pii pos = q.front();q.pop();
          s[pos.fi][pos.se] = '.';
          rep(i,4){
            x = pos.fi+dx[i],y = pos.se+dy[i];
            if(value(x,y,12,12)){
              if(s[x][y] == '1'){
                s[x][y] = '.';
                q.push(make_pair(x,y));
              }
            }
          }
        }
        ++ans;
      }
    }
    cout << ans << endl;
  }
LABEL:
  return 0;
}

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

int main(){
  int N,D;
  cin >> N >> D;
  
  vector<vector<int>> matrix(N, vector<int>(D));
  for (int i=0; i<N; i++){
    for (int j=0; j<D; j++){
      cin >> matrix.at(i).at(j);
    }
  }
  
  int ans = 0;
  
  int distance_squared = 0;
  for (int i=0; i<N-1; i++){
    for (int j=i+1;j<N; j++){
      for(int k=0;k<D;k++){
        distance_squared +=  pow((matrix.at(i).at(k) - matrix.at(j).at(k)),2);
      }
      for(int l=1; l<130; l++){
        if(distance_squared  == l*l){
          ans++;
          break;
        }
      }
      distance_squared  = 0;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3632
A,B = map(int,input().split())



keta = 0
ans = 0

while B >= 2 ** keta:

    nowsum = 0

    fblock = A // (2 ** (keta+1))
    eblock = B // (2 ** (keta+1))

    if fblock != eblock:
        nowsum += (eblock - fblock - 1) * (2 ** keta)

        nowsum += min( 2 ** keta , (2 ** (keta + 1)) * (fblock + 1) - A )
        nowsum += max( 0 , B - (((2 ** (keta + 1)) * eblock - 1) + (2 ** keta)) )

    elif ( B // (2 ** keta) ) % 2 == 1 and ( A // (2 ** keta) ) % 2 == 1:

        nowsum += B - A + 1

    elif ( B // (2 ** keta) ) % 2 == 1:

        nowsum += B -  (B // (2 ** keta)) * (2 ** keta) + 1
        
    ans += ( 2 ** keta ) * ( nowsum % 2 )
    keta += 1
    
print (ans)



Measured memory_bytes: 38384
#include <iostream>
using namespace std;
int main(void){
    int len[3], cnt[3];
    string s[3];
    for(int i=0;i<3;i++){
        cin >> s[i];
        len[i] = s[i].length();
        cnt[i] = 0;
    }
    
    int t = 0;
    while(cnt[t] < len[t]){
        t = s[t][cnt[t]++] - 'a';
    }
    char ans = 'A' + t;
    cout << ans << endl;
}


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

using namespace std ;

int main()
{
    int n , x , t ;
    cin >> n >> x >> t ;

    if( n % x == 0 )
        cout << ( n / x )*t ;
    else
        cout << ( ( n / x ) + 1 )*t ;
}


Measured memory_bytes: 3632
N = int(input())
As, Bs = [], []
for _ in range(N):
    A, B = map(int, input().split())
    As.append(A)
    Bs.append(B)

Cs = [(A+B, i) for i, (A, B) in enumerate(zip(As, Bs))]
Cs.sort(reverse=True)

hA = sum([As[i] for C, i in Cs[::2]])
hB = sum([Bs[i] for C, i in Cs[1::2]])
print(hA - hB)


Measured memory_bytes: 25528
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	string  s;
	int total=0;
	cin>>s;


	for(int i=0; i<s.size(); ++i){
		if(s[i]=='1'){
			total++;
		}
	}
	cout<<total<<endl;

	return 0;



}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
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;
}

int main() {
  int N;
  cin >> N;
  vector<int> ans(N+1,0);
  rep2(i,1,102) rep2(j,1,102) rep2(k,1,102) {
    int t = i*i+j*j+k*k+i*j+j*k+k*i;
    if (t<=N) ans[t]++;
    else break;
  }
  rep2(i,1,N+1) cout << ans[i] << endl;
}


Measured memory_bytes: 3624
#include <random>    //ランダム
#include <algorithm> //アルゴリズム
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <cassert>
#include <cfloat>
#include <numeric>
#include <climits>
#include <stdint.h>
using namespace std;
// vector<int> temple(7,0);
    // for(int i=0; i<temple.size(); i++){
    
    // }
    // int maxtemp=*max_element(temple.begin(), temple.end());;
    // int mintemp=*min_element(temple.begin(), temple.end());;
    // int answer=0;
    // for(int i=0; i<temple.size(); i++){
    //     if(temple[i]==maxtemp||temple[i]==mintemp){
            
    //     }else{
    //         answer+=temple[i];
    //     }
    // }
    // answer/=5;
    // cout << answer << std::endl;
int main()
{
    int rate;
    cin >> rate;
    if(rate>=400&rate<=599){
        cout<<"8"<<endl;
    }else if(rate>=600&rate<=799){
        cout<<"7"<<endl;
    }else if(rate>=800&rate<=999){
        cout<<"6"<<endl;
    }else if(rate>=1000&rate<=1199){
        cout<<"5"<<endl;
    }else if(rate>=1200&rate<=1399){
        cout<<"4"<<endl;
    }else if(rate>=1400&rate<=1599){
        cout<<"3"<<endl;
    }else if(rate>=1600&rate<=1799){
        cout<<"2"<<endl;
    }else if(rate>=1800&rate<=1999){
        cout<<"1"<<endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N; cin >> N;
  rep(n, 1, 3501) {
  	rep(h, 1, 3501) {
    	ll wa = N * n * h;
      	ll wb = 4 * n * h - N * h - N * n;
      	if (wa > 0 && wb > 0 && wa % wb == 0) {
        	ll w = wa / wb;
          	cout << n << " " << h << " " << w;
          	return 0;
        }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
#define mem(x, y) memset(& x, y, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int n0 = 2e5 + 123, mod = 998244353;
int n, k, l[10], r[10], p[n0], dp[n0];

void add(int & x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int n, k; cin >> n >> k;
	for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
	dp[1] = p[1] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int R = max(0, i - l[j]), L = max(0, i - r[j]);
			//cerr << "for " << i << '\n';
			//cerr << "L R " << L << ' ' << R << '\n';
			int bruh = 0;
			if (L) bruh = p[L - 1];
			add(dp[i], (p[R] - bruh + mod) % mod);
		}
		p[i] = p[i - 1];
		add(p[i], dp[i]);
	}
	cout << dp[n];
}


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

using namespace std;

int main()
{
    std::ios_base::sync_with_stdio(false);
    ll a,b,c;
    cin>>a>>b>>c;
    map<ll,ll> mp;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++)
    {
        if(it->second==1)
        {
            cout<<it->first;
            return 0;
        }
    }
    return 0;
}


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

int main()
{
	int N, K, h[102000], ans=0;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> h[i];
	}
	for (int i = 0; i < N; i++)
	{
		if (h[i]>=K)
		{
			ans ++ ;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> c[100005]; //どことつながっているかを記録する二次元配列
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    c[a].push_back(b);
    c[b].push_back(a); //じつはこれで二次元配列を作れる
  }
  
  queue<int> q; //これから調べるぞリスト,調べ終わったものは削除する
  vector<int> p(n,-1); //道しるべとなる部屋番号,決まっていない場合は-1
  
  q.push(0); //queueに0を入れる
  while (!q.empty()) { //queueが空になるまでループする
    int v = q.front(); //queueの一番前を取り出しそれをvとする
    q.pop(); //queueの一番前を削除
    for (int u : c[v]) { //vとつながっている部屋uを全探索
      if (p[u] != -1) continue; //道しるべが決まっていたらskip
      p[u] = v; //uの目印をvにする
      q.push(u); //queueにuを入れる(つまりこれから調べるということ)
    }
  }
  
  cout << "Yes" << endl;
  rep(i,n) {
    if (i==0) continue;
    cout << p[i] + 1 << endl;
  }
}

Measured memory_bytes: 10124
from math import factorial
def com(n,k,mod,fac,infac):
    k=min(k,n-k)
    return fac[n]*infac[k]*infac[n-k]%mod

def cominit(mod,n):
    fac=[1,1]
    infac=[1,1]
    inv=[0,1]

    for i in range(2,n+1):
        fac.append(fac[-1]*i%mod)
        inv.append(-inv[mod%i]*(mod//i)%mod)
        infac.append(infac[-1]*inv[-1]%mod)

    return fac,infac
def main():
    x,y=map(int,input().split())

    if (x+y)%3!=0:
        print(0)
        return

    temp=int((x+y)/3)
    if temp*2 < x or temp > x:
        print(0)
        return
    f,inf=cominit(10**9+7,temp)
    # n,kはしっかりはっきりさせよ明日

    # ans=factorial(temp) / factorial(x-temp) / factorial(2*temp-x)
    ans=com(temp,abs(x-temp),10**9+7,f,inf)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 118636
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

typedef struct
{
	int x1;
	int y1;
	int x2;
	int y2;
} rect;

int W,H,N,M[1000][2][2],MAP[2002][2002];
vector<int> X,Y,T;
vector<rect> P;
rect trect;

rect* makerect(int x1,int y1,int x2,int y2)
{
	trect.x1 = x1;
	trect.y1 = y1;
	trect.x2 = x2;
	trect.y2 = y2;
	return &trect;
}

int getmap(int x,int y)
{
	if(x >= 0 && y >= 0 && x < W && y < H)
		return MAP[x][y];
	else
		return 1;
}

void dfs(int x,int y)
{
	MAP[x][y] = 1;
	if(getmap(x+1,y) == 0)
		dfs(x+1,y);
	if(getmap(x-1,y) == 0)
		dfs(x-1,y);
	if(getmap(x,y+1) == 0)
		dfs(x,y+1);
	if(getmap(x,y-1) == 0)
		dfs(x,y-1);
}

int main(void)
{
	while(true)
	{
		memset(M,0,sizeof(M));
		memset(MAP,0,sizeof(MAP));
		X.clear();
		Y.clear();
		T.clear();
		P.clear();
		cin >> W >> H;
		if(W == 0 && H == 0)
			exit(0);
		cin >> N;
		X.push_back(0);
		X.push_back(W);
		Y.push_back(0);
		Y.push_back(H);
		for(int i = 0;i < N;i++)
		{
			cin >> M[i][0][0] >> M[i][0][1] >> M[i][1][0] >> M[i][1][1];
			X.push_back(M[i][0][0]);
			X.push_back(M[i][1][0]);
			Y.push_back(M[i][0][1]);
			Y.push_back(M[i][1][1]);
		}
		T.clear();
		sort(X.begin(),X.end());
		T = X;
		X.clear();
		int prev = T[0];
		X.push_back(prev);
		for(auto itr = T.begin() + 1;itr < T.end();itr++)
		{
			if(*itr != prev)
			{
				X.push_back(*itr);
				prev = *itr;
			}
		}
		sort(X.begin(),X.end());
		T.clear();
		sort(Y.begin(),Y.end());
		T = Y;
		Y.clear();
		prev = T[0];
		Y.push_back(prev);
		for(auto itr = T.begin() + 1;itr < T.end();itr++)
		{
			if(*itr != prev)
			{
				Y.push_back(*itr);
				prev = *itr;
			}
		}
		sort(Y.begin(),Y.end());
		for(int i = 0;i < N;i++)
		{
			P.push_back(*makerect(
				(lower_bound(X.begin(),X.end(),M[i][0][0]) - X.begin()),
				(lower_bound(Y.begin(),Y.end(),M[i][0][1]) - Y.begin()),
				(lower_bound(X.begin(),X.end(),M[i][1][0]) - X.begin()),
				(lower_bound(Y.begin(),Y.end(),M[i][1][1]) - Y.begin())
				));
		}
		for(auto itr = P.begin();itr < P.end();itr++)
		{
			for(int x = itr->x1;x < itr->x2;x++)
			{
				for(int y = itr->y1;y < itr->y2;y++)
				{
					MAP[x][y] = 1;
				}
			}
		}
		W = X.size() - 1;
		H = Y.size() - 1;
		/*
		for(int x = -2;x < W;x++)
			cout << "#";
		cout << endl;
		for(int y = H - 1;y >= 0;y--)
		{
			cout << "#";
			for(int x = 0;x < W;x++)
			{
				if(MAP[x][y] == 0)
					cout << " ";
				else
					cout << "#";
			}
			cout << "#"<< endl;
		}
		for(int x = -2;x < W;x++)
			cout << "#";
		cout << endl;
		*/
		bool update = true;
		int count = 0;
		while(true)
		{
			update = false;
			for(int x = 0;x < W;x++)
			{
				for(int y = 0;y < H;y++)
				{
					if(MAP[x][y] == 0)
					{
						count++;
						update = true;
						dfs(x,y);
					}
				}	
			}
			if(!update)
				break;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 24652
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//INT_MAXなど
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

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

signed main(){
  int X;
  cin >> X;

  int res = 0;
  while (X) {
    int i = 2;
    for (i = 2; i * i <= X; i++) {
      if (X % i == 0) {
        break;
      }
    }
    if (i * i > X)
      break;
    X++;
  }

  cout << X << endl;


  return 0;
}

Measured memory_bytes: 3608
sx,sy,tx,ty = map(int,input().split())
ans = ""

#   0
#3     1
#   2
ans += "U" * (ty - sy)
ans += "R" * (tx - sx)
ans += "D" * (ty - sy)
ans += "L" * (tx - sx)
ans += "L"
ans += "U" * (ty - sy + 1)
ans += "R" * (tx - sx + 1)
ans += "D"
ans += "R"
ans += "D" * (ty - sy + 1)
ans += "L" * (tx - sx + 1)
ans += "U"
print(ans)


Measured memory_bytes: 3060
import bisect
from collections import defaultdict


S = list(input().strip())
T = list(input().strip())
L = len(S)

if not set(T) <= set(S):
    print(-1)
    exit()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)

idx = -1
ans = 0
for t in T:
    pos = bisect.bisect_right(d[t], idx)
    if pos == len(d[t]):
        ans += L - idx - 1 + d[t][0] + 1
        idx = d[t][0]
    else:
        ans += d[t][pos] - idx
        idx = d[t][pos]

print(ans)


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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var n = int.Parse(System.Console.ReadLine());

        Dictionary<int, int> dic = new Dictionary<int, int>();

        for(int x = 1; x <= 100; x++)
        {
            for(int y = 1; y <= 100; y++)
            {
                for(int z = 1; z <= 100; z++)
                {
                    var ans = x * x + y * y + z * z + x * y + y * z + z * x;

                    if(ans > n)
                    {
                        break;
                    }
                    if (!dic.ContainsKey(ans))
                    {
                        dic.Add(ans, 0);
                    }
                    dic[ans]++;
                }
            }
        }


       for(int i = 1; i <= n; i++)
        {
            if (dic.ContainsKey(i))
            {
                Console.WriteLine(dic[i]);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

       
    }

    

}

Measured memory_bytes: 28560
def main():
    import math
    x = int(input())
    a, b = 0, 0
    t = 0
    c = 0
    while True:
        c += 1
        t += x
        t %= 360
        a += math.cos(math.radians(t))
        b += math.sin(math.radians(t))
        if abs(a) < 10 ** -13 and abs(b) < 10 ** -13:
            print(c)
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 9580
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 5e14;
const double eps = 1e-10;
const double PI = acos(-1);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,-1,-1,0,0,1,1,1 }, ty[8] = { -1,0,1,-1,1,-1,0,1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

vector<ll>six, nine;
ll dp[100010], n;

int main() {
	cin >> n;
	for (int i = 0;i < 10;i++) {
		six.eb(pow(6, i));
		nine.eb(pow(9, i));
	}
	fill(dp, dp + n + 1, INF);
	dp[0] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < six.size();j++) {
			if (i + six[j] <= n) {
				dp[i + six[j]] = min(dp[i + six[j]], dp[i] + 1);
			}
		}
		for (int j = 0;j < nine.size();j++) {
			if (i + nine[j] <= n) {
				dp[i + nine[j]] = min(dp[i + nine[j]], dp[i] + 1);
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int BubSort(int x[ ], int n)
{
    int i, j, temp;

    for (i = 0; i < n - 1; i++) {
        for (j = n - 1; j > i; j--) {
            if (x[j - 1] > x[j]) {  /* 前の要素の方が大きかったら */
                temp = x[j];        /* 交換する */
                x[j] = x[j - 1];
                x[j - 1]= temp;
            }
        }
    }
}

int main(void) {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	BubSort(a, 3);
	printf("%d %d %d\n",a[0], a[1], a[2]);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int gcd(int x,int y) {
	if (x==0) return y;
	if (y==0) return x;
	return gcd(y,x%y);
}
int main() {
	int n=read(),x=read();
	int ans=0;
	for (int i=1; i<=n; i++) {
		int y=read();
		ans=gcd(abs(x-y),ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import sys
l = list(raw_input())
if (not "0" in l) or (not "1" in l):
    print len(l)
    sys.exit()

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
mx = max(mx, min(i, len(l)-x))
print mx


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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e6 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

vector<pii> E[N];
map<pii, int> mp;
int n, m, tot, dis[N], vis[N];

struct node {
    int v, d;
    bool operator < (const node& r) const { return d > r.d; }
};

int addP(int u, int c) {
    if(!mp[mk(u, c)]) mp[mk(u, c)] = ++tot; 
    return mp[mk(u, c)];
}

void addE(int u, int v, int c) {
    E[u].pb(mk(v, c)), E[v].pb(mk(u, c));
}

int dij() {
    priority_queue<node> q;
    q.push({1, 0});
    mem(dis, 0x3f);
    dis[1] = 0;
    while(!q.empty()) {
        node nd = q.top(); q.pop();
        int u = nd.v, d = nd.v;
        if(vis[u]) continue;
        vis[u] = 1;
        for(auto e : E[u]) {
            int v = e.fi;
            if(vis[v]) continue;
            if(dis[v] > dis[u] + e.se) {
                dis[v] = dis[u] + e.se;
                q.push({v, dis[v]});
            }
        }
    }
    if(dis[n] == inf) return -1;
    return dis[n] / 2;
}

int main() {
    FIO;
    cin >> n >> m;
    tot = n;
    rep(i, 1, m) {
        int u, v, c;
        cin >> u >> v >> c;
        int nu = addP(u, c), nv = addP(v, c);
        addE(u, nu, 1), addE(v, nv, 1), addE(nu, nv, 0);
    }
    cout << dij();

    return 0;
}

Measured memory_bytes: 102780
#include "bits/stdc++.h"

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
using namespace std;

signed main() {
  ll a;
  cin >> a;
  if(a==0){
      cout << 1;
  }else{
      cout << 0;
  }
}




Measured memory_bytes: 3672
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vecl<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        v.push(read::<T>());
    }

    v
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();

    let mut a = read_vec::<i64>();
    a.sort();

    let ans = a.into_iter().rev().fold((0, 0, 0), |(x, y, p), aa| {
        if y > 0 {
            (x, y, 0)
        } else if p == aa {
            if x == 0 { (aa, 0, 0) }
            else { (x, aa, 0) }
        } else {
            (x, y, aa)
        }
    });

    println!("{}", ans.0 * ans.1);
}


Measured memory_bytes: 6396
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
string s;
int main()
{
    int n;
    double num;
    double sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        string s;
        cin >> num >> s;
        if(s=="BTC")
            num=num*380000.0;
        sum+=num;
    }
    printf("%lf\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
/* cau troi cho Garena nhap de con Bach */
#define FSYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define pob pop_back
#define ub upper_bound
#define ite ::iterator
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int N = 2e5+5;

int n,a[110];
signed main(){
	cin >> n;
	for(int i = 0 ; i < n ; i ++) cin >> a[i];
	sort(a,a+n);
	cout << a[n-1] - a[0];
}


Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]
H_rev =  H[::-1]
ans = "Yes"
H_pre = H_rev[0]
for n in range(1,N):
    if H_pre >= H_rev[n]:
        H_pre = H_rev[n]
    elif H_pre + 1 == H_rev[n]:
        H_rev[n] -= 1
        H_pre = H_rev[n]
    else:
        ans = "No"
        break
print(ans)

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

int main() {
    char N[5];
    scanf("%s",&N);
    if(N[0]=='7'||N[1]=='7'||N[2]=='7')
    {
        printf("Yes\n");
    }
    else
     {
        printf("No\n");
     }
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int64 x,y;
  cin>>x>>y;
  cout<<floor(log2((long double)y/x))+1<<endl;
}


Measured memory_bytes: 640
/*
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
    */

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
    std::ifineam inFile("input.txt");
    std::ofineam outFile("output.txt");
    std::cin.rdbuf(inFile.rdbuf());
    std::cout.rdbuf(outFile.rdbuf());
    */

bool isSorted(arri &arr)
{
    for (int i = 1; i < arr.size(); i++)
    {
        if (arr[i - 1] > arr[i])
        {
            return false;
        }
    }
    return true;
}

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

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

    int biggerFound = -1;
    int smallerFound = -1;

    for (int i = 1; i < p.size(); i++)
    {
        if (p[i - 1] > p[i] && biggerFound == -1)
        {
            biggerFound = i - 1;
        }
        else if (p[i - 1] > p[i])
        {
            smallerFound = i;
            break;
        }
    }

    //cout << biggerFound << " " << smallerFound << endl;

    if (biggerFound == -1 && smallerFound == -1)
    {
        cout << "YES";
        return 0;
    }
    else if (biggerFound != -1 && smallerFound != -1)
    {
        swap(p[biggerFound], p[smallerFound]);
        if (isSorted(p))
        {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

Measured memory_bytes: 256
import sys
import numpy as np

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: np.array(list(map(int, stdin.readline().split())))
ns = lambda: stdin.readline().rstrip()

n, m, c = na()
b = na()
ans = 0
for i in range(n):
    a = na()
    s = c
    s += np.sum(a * b)
    if s > 0:
        ans += 1
print(ans)


Measured memory_bytes: 12496
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var r = int.Parse(Console.ReadLine());
            Console.WriteLine(r * 2 * Math.PI);
        }
    }
}


Measured memory_bytes: 27592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r;
	cin>>r;
	if (r<1200) cout<<"ABC"<<endl;
	if (r>=1200 && r<2800) cout<<"ARC"<<endl;
	if (r>=2800) cout<<"AGC"<<endl;
	return 0; 
 } 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while ( x != NIL ) {
        y = x;
        if ( z->key < x->key ) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if ( y == NIL ) {
        root = z;
    } else {
        if ( z->key < y->key ) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node * find(Node *u, int k) {
    while ( u != NIL && k != u->key) {
        if ( k < u->key ) u = u->left;
        else u = u->right;
    }
    return u;
}

Node * treeMinimum(Node *x) {
    while( x->left != NIL ) x = x->left;
    return x;
}

Node * treeSuccessor(Node *x) {
    if ( x->right != NIL ) return treeMinimum(x->right);
    Node *y = x->parent;
    while( y != NIL && x == y->right ) {
        x = y;
        y = y->parent;
    }
    return y;
}
void treeDelete (Node *z) {
    Node *y;
    Node *x;

    if ( z->left == NIL || z->right == NIL ) y = z;
    else y = treeSuccessor(z);

    if ( y->left != NIL ) {
        x = y->left;
    } else {
        x = y->right;
    }

    if ( x != NIL ) {
        x->parent = y->parent;
    }

    if ( y->parent == NIL ) {
        root = x;
    } else {
        if ( y == y->parent->left ) {
            y->parent->left = x;
        } else {
            y->parent->right = x;
        }
    }

    if ( y != z ) {
        z->key = y->key;
    }

    free(y);
}

void inorder(Node *u) {
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if ( u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for ( i = 0; i < n; i++) {
        cin >> com;
        if ( com == "delete" ) {
            scanf("%d", &x);
            treeDelete(find(root, x));
        } else if ( com[0] == 'f' ) {
            scanf("%d", &x);
            Node *t = find(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if( com == "insert" ) {
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print" ) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 22024
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> dp;
void dfs(int u)
{
    vis[u] = 1;
    for(int v : adj[u]){
        if(!vis[v])
            dfs(v);
        dp[u] = max(dp[u], 1+dp[v]);
    }
}

void init(int n)
{
    adj.resize(n, vector<int>());
    vis.resize(n);
    dp.resize(n);
}

int main()
{
    int n, m;
    cin >> n >> m;
    init(n+1);
    int x,y;
    while(m--){
        cin >> x >> y;
        adj[x].push_back(y);
    }
    for(int i=1; i<=n; i++)
        if(!vis[i])
            dfs(i);
    cout << *max_element(dp.begin(), dp.end()) << '\n';

    return 0;
}

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

int main() {
    string s;
    ll k,ans=0,tmp=0;
    cin>>s>>k;
    ll n = s.size();
  	//cout<<n<<endl;
    ll a=1;
    for(int i=0; i<n; i++) {
        if(s[i]==s[i+1]) a++;
        else {
          	if(a == 1) a--;
            ans += a/2;
          	tmp++;
          	//cout<<ans<<endl;
          	a=1;
        }
    }
  	//cout<<ans<<endl;
  	if(tmp == 1) cout<<n * k / 2<<endl;
    else if(s.front() == s.back()) {
      	ll fr = 0, ba = 0;
        for(int i=0; i<n; i++) {
            fr++;
            if(s[i] != s[i+1]) break;
        }
        for(int i=n-1; i>=0; i--) {
            ba++;
            if(s[i] != s[i-1]) break;
        }
        cout<<ans * k - (k-1) * ((fr/2) + (ba/2) - (fr+ba)/2)<<"\n";
    }
  	else cout<<ans * k<<endl;
}

Measured memory_bytes: 3620
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 2*1000*100+5 ;
const ll inf = 9223372036854775807 ;

ll n , k , a[maxn] , sum ; 

int main()
{
	migmig ;
	cin>>n>>k ; 
	for(int i = 0 ; i < n ; i ++ )
	{
		cin>>a[i] ; 
	}
	sort(a , a + n , greater<ll>()) ; 
	for(int i = k ; i < n ; i ++ )
	{
		sum += a[i] ; 
	}
	cout<<sum ; 

}
//////
////////
///////////




Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MOD=100000;
int di[100000];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    di[0]=0;
    for(int i=1;i<n;i++){
        scanf("%d",&di[i]);
        di[i]+=di[i-1];
    }
    int at=0,sum=0,a;
    for(int i=0;i<m;i++){
        scanf("%d",&a);
        sum+=abs(di[at+a]-di[at]);
        sum%=MOD;
        at+=a;
    }
    printf("%d\n",sum);
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll N;
  cin >> N;
  map<ll, ll> cnt;
  vl A(N);
  rep(i, N){
    cin >> A[i];
    cnt[A[i]] += 1;
  }

  ll tot = 0;

  for(auto i = cnt.begin(); i != cnt.end(); i++){
    tot += (i->second) * ((i->second) - 1) / 2;
  }
  
  rep(i, N){
    ll ans = 0;
    ll num = cnt[A[i]];

    ans = tot - (num*(num-1)/2) + ((num-1)*(num-2)/2);

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

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

int main() {
	long long a, b, c, k;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	if (k & 1) {
		printf("%lld\n", b - a);
	} else {
		printf("%lld\n", a - b);
	}
        return 0;
}


Measured memory_bytes: 256
S = input()
l = len(S)
A = [0 for i in range(l+1)]
for i in range(l):
    if S[i] == '<':
        A[i+1] = max(A[i+1],A[i]+1)
for i in range(l-1,-1,-1):
    if S[i] == '>':
        A[i] = max(A[i+1]+1,A[i])
print(sum(A))


Measured memory_bytes: 24092
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
  int x, a, b; cin >> x >> a >> b;
  int s=0, t=0;
  s= (a-x)*(a-x); t= (b-x)*(b-x);
  if(min (s,t)==s)  cout << "A" << endl;
  else cout << "B" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D,N;
  cin >>D>>N;
  int ans=1;
  for(int i=0;i<D;i++) ans *= 100;
  if(N<100) ans *= N;
  else ans *= 101;
  cout << ans << endl;
}

Measured memory_bytes: 256
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,K=map(int,pin().split())
  if K==1:
    print(0)
    return 
  t=N-K 
  print(t)
  return 

main()

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> P(N + 5);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &P[i]);
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (P[i] != i) { continue; }
    if (i < N) { swap(P[i], P[i + 1]); }
    else { swap(P[i - 1], P[i]); }
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);
const int MOD = 1000000007;


int main(){
    int n; cin >> n;
    int d[110][2];

    int cnt = 0;
    bool yes = false;
    rep(i,n){
        cin >> d[i][0] >> d[i][1];
        if(d[i][0] == d[i][1]) cnt++;
        else cnt = 0;
        if(cnt >= 3) yes = true;
    }
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  
  int a,b;
  cin >> a >> b;
  
  if( b%a == 0){
    
    cout << a+b << endl;
    
  }
  
  else{
    
    cout << b-a << endl;
    
  }
  
}


Measured memory_bytes: 256
n = gets.to_i
h = gets.chomp.split(" ").map(&:to_i)
h.push(0)
zero=Array.new(n+1).fill(0)
ans=0
while h!=zero do
    t=0
    while h[t]==0 do
        t+=1
    end
    while h[t+1]!=0 do
        h[t]-=1
        t+=1
    end
    h[t]-=1
    ans+=1
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }
const ll MOD = 1000 * 1000 * 1000 + 7 ;
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) %  MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) %  MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) %  MOD;}
const int MOD_TABLE_SIZE = 2000000 + 10;
ll inv[MOD_TABLE_SIZE];
ll fac[MOD_TABLE_SIZE];
ll facinv[MOD_TABLE_SIZE];

void mod_table_init() {
  inv[1] = 1;
  for(int i = 2; i < MOD_TABLE_SIZE; i++) {
    inv[i] = MOD - (MOD / i) * inv[(int)MOD % i] % MOD;
  }
  fac[0] = facinv[0] = 1;
  for(int i = 1; i < MOD_TABLE_SIZE; i++) {
    fac[i] = (fac[i-1] * (ll)i) % MOD;
    facinv[i] = (facinv[i-1] * inv[i]) % MOD;
  }
}

inline ll P(int a, int b) {
  return fac[a] *  facinv[a-b] % MOD;
}

inline ll C(int a, int b) {
  return (fac[a] * facinv[b] % MOD) * facinv[a-b] % MOD;
}

inline ll H(int a, int b) {
  return C(a+b-1,b);
}

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  mod_table_init();
  int N, M; cin>>N>>M;
  ll K; cin>>K;
  ll ans = 0;
  for(int i = 1; i < N; i++) {
    ll tmp = N-i;
    chmul(tmp, i);
    chmul(tmp, M);
    chmul(tmp, M);
    chadd(ans, tmp);
  }
  //  cout << ans << endl;
  for(int i = 1; i < M; i++) {
    ll tmp = M-i;
    chmul(tmp, i);
    chmul(tmp, N);
    chmul(tmp, N);
    chadd(ans, tmp);
  }
  //  cout << ans << endl;
  ll comb = C(N*M-2, K-2);
  //  cout << ans << "," << comb << endl;
  chmul(ans, comb);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 47232